From: Gregory Haskins <ghaskins@novell.com>
To: mingo@elte.hu, paulmck@linux.vnet.ibm.com, peterz@infradead.org,
tglx@linutronix.de, rostedt@goodmis.org
Cc: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org,
gregory.haskins@gmail.com, David.Holmes@sun.com
Subject: [PATCH RT RFC v2 3/8] sched: rework task reference counting to work with the pi infrastructure
Date: Fri, 15 Aug 2008 08:08:26 -0400 [thread overview]
Message-ID: <20080815120825.24722.53600.stgit@dev.haskins.net> (raw)
In-Reply-To: <20080815120722.24722.66516.stgit@dev.haskins.net>
Signed-off-by: Gregory Haskins <ghaskins@novell.com>
---
include/linux/sched.h | 5 +++--
kernel/fork.c | 32 +++++++++++++++-----------------
kernel/sched.c | 23 +++++++++++++++++++++++
3 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 63ddd1f..9132b42 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1305,6 +1305,8 @@ struct task_struct {
struct pi_node node;
struct pi_sink snk; /* registered to 'this' to get updates */
int prio;
+ struct rcu_head rcu; /* for destruction cleanup */
+
} pi;
#ifdef CONFIG_RT_MUTEXES
@@ -1633,12 +1635,11 @@ static inline void put_task_struct(struct task_struct *t)
call_rcu(&t->rcu, __put_task_struct_cb);
}
#else
-extern void __put_task_struct(struct task_struct *t);
static inline void put_task_struct(struct task_struct *t)
{
if (atomic_dec_and_test(&t->usage))
- __put_task_struct(t);
+ pi_dropref(&t->pi.node, 0);
}
#endif
diff --git a/kernel/fork.c b/kernel/fork.c
index 399a0d0..399a0a9 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -130,39 +130,37 @@ void free_task(struct task_struct *tsk)
}
EXPORT_SYMBOL(free_task);
-#ifdef CONFIG_PREEMPT_RT
-void __put_task_struct_cb(struct rcu_head *rhp)
+void prepare_free_task(struct task_struct *tsk)
{
- struct task_struct *tsk = container_of(rhp, struct task_struct, rcu);
-
BUG_ON(atomic_read(&tsk->usage));
- WARN_ON(!tsk->exit_state);
WARN_ON(tsk == current);
+#ifdef CONFIG_PREEMPT_RT
+ WARN_ON(!tsk->exit_state);
+#else
+ WARN_ON(!(tsk->exit_state & (EXIT_DEAD | EXIT_ZOMBIE)));
+#endif
+
security_task_free(tsk);
free_uid(tsk->user);
put_group_info(tsk->group_info);
+
+#ifdef CONFIG_PREEMPT_RT
delayacct_tsk_free(tsk);
+#endif
if (!profile_handoff_task(tsk))
free_task(tsk);
}
-#else
-
-void __put_task_struct(struct task_struct *tsk)
+#ifdef CONFIG_PREEMPT_RT
+void __put_task_struct_cb(struct rcu_head *rhp)
{
- WARN_ON(!(tsk->exit_state & (EXIT_DEAD | EXIT_ZOMBIE)));
- BUG_ON(atomic_read(&tsk->usage));
- WARN_ON(tsk == current);
-
- security_task_free(tsk);
- free_uid(tsk->user);
- put_group_info(tsk->group_info);
+ struct task_struct *tsk = container_of(rhp, struct task_struct, rcu);
- if (!profile_handoff_task(tsk))
- free_task(tsk);
+ pi_dropref(&tsk->pi.node, 0);
}
+
#endif
/*
diff --git a/kernel/sched.c b/kernel/sched.c
index c129b10..729139d 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2370,11 +2370,34 @@ task_pi_boost_cb(struct pi_sink *snk, struct pi_source *src,
return 0;
}
+extern void prepare_free_task(struct task_struct *tsk);
+
+static void task_pi_free_rcu(struct rcu_head *rhp)
+{
+ struct task_struct *tsk = container_of(rhp, struct task_struct, pi.rcu);
+
+ prepare_free_task(tsk);
+}
+
+/*
+ * This function is invoked whenever the last references to a task have
+ * been dropped, and we should free the memory on the next rcu grace period
+ */
+static int task_pi_free_cb(struct pi_sink *snk, unsigned int flags)
+{
+ struct task_struct *p = container_of(snk, struct task_struct, pi.snk);
+
+ call_rcu(&p->pi.rcu, task_pi_free_rcu);
+
+ return 0;
+}
+
static int task_pi_update_cb(struct pi_sink *snk, unsigned int flags);
static struct pi_sink task_pi_sink = {
.boost = task_pi_boost_cb,
.update = task_pi_update_cb,
+ .free = task_pi_free_cb,
};
static inline void
next prev parent reply other threads:[~2008-08-15 12:18 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-01 21:16 [PATCH RT RFC 0/7] Priority Inheritance enhancements Gregory Haskins
2008-08-01 21:16 ` [PATCH RT RFC 1/7] add generalized priority-inheritance interface Gregory Haskins
2008-08-01 21:16 ` [PATCH RT RFC 2/7] sched: add the basic PI infrastructure to the task_struct Gregory Haskins
2008-08-01 21:17 ` [PATCH RT RFC 3/7] rtmutex: formally initialize the rt_mutex_waiters Gregory Haskins
2008-08-01 21:17 ` [PATCH RT RFC 4/7] RT: wrap the rt_rwlock "add reader" logic Gregory Haskins
2008-08-01 21:17 ` [PATCH RT RFC 5/7] rtmutex: use runtime init for rtmutexes Gregory Haskins
2008-08-01 21:17 ` [PATCH RT RFC 6/7] rtmutex: convert rtmutexes to fully use the PI library Gregory Haskins
2008-08-01 21:17 ` [PATCH RT RFC 7/7] rtmutex: pi-boost locks as late as possible Gregory Haskins
2008-08-04 13:21 ` Gregory Haskins
2008-08-05 3:01 ` Gregory Haskins
2008-08-15 12:08 ` [PATCH RT RFC v2 0/8] Priority Inheritance enhancements Gregory Haskins
2008-08-15 12:08 ` [PATCH RT RFC v2 1/8] add generalized priority-inheritance interface Gregory Haskins
2008-08-15 13:16 ` [PATCH RT RFC v3] " Gregory Haskins
2008-08-15 12:08 ` [PATCH RT RFC v2 2/8] sched: add the basic PI infrastructure to the task_struct Gregory Haskins
2008-08-15 12:08 ` Gregory Haskins [this message]
2008-08-15 12:08 ` [PATCH RT RFC v2 4/8] rtmutex: formally initialize the rt_mutex_waiters Gregory Haskins
2008-08-15 12:08 ` [PATCH RT RFC v2 5/8] RT: wrap the rt_rwlock "add reader" logic Gregory Haskins
2008-08-15 12:08 ` [PATCH RT RFC v2 6/8] rtmutex: use runtime init for rtmutexes Gregory Haskins
2008-08-15 12:08 ` [PATCH RT RFC v2 7/8] rtmutex: convert rtmutexes to fully use the PI library Gregory Haskins
2008-08-15 12:08 ` [PATCH RT RFC v2 8/8] rtmutex: pi-boost locks as late as possible Gregory Haskins
2008-08-15 20:28 ` [PATCH RT RFC v4 0/8] Priority Inheritance enhancements Gregory Haskins
2008-08-15 20:28 ` [PATCH RT RFC v4 1/8] add generalized priority-inheritance interface Gregory Haskins
2008-08-15 20:32 ` Gregory Haskins
2008-08-16 15:32 ` AW: " Matthias Behr
2008-08-19 8:34 ` Gregory Haskins
2008-08-16 19:56 ` Peter Zijlstra
2008-08-19 8:40 ` Gregory Haskins
2008-08-22 12:55 ` Esben Nielsen
2008-08-22 13:15 ` Gregory Haskins
2008-08-22 16:08 ` Gregory Haskins
2008-08-22 13:17 ` Steven Rostedt
2008-08-15 20:28 ` [PATCH RT RFC v4 2/8] sched: add the basic PI infrastructure to the task_struct Gregory Haskins
2008-08-15 20:28 ` [PATCH RT RFC v4 3/8] sched: rework task reference counting to work with the pi infrastructure Gregory Haskins
2008-08-15 20:28 ` [PATCH RT RFC v4 4/8] rtmutex: formally initialize the rt_mutex_waiters Gregory Haskins
2008-08-15 20:28 ` [PATCH RT RFC v4 5/8] RT: wrap the rt_rwlock "add reader" logic Gregory Haskins
2008-08-15 20:28 ` [PATCH RT RFC v4 6/8] rtmutex: use runtime init for rtmutexes Gregory Haskins
2008-08-15 20:28 ` [PATCH RT RFC v4 7/8] rtmutex: convert rtmutexes to fully use the PI library Gregory Haskins
2008-08-15 20:29 ` [PATCH RT RFC v4 8/8] rtmutex: pi-boost locks as late as possible Gregory Haskins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080815120825.24722.53600.stgit@dev.haskins.net \
--to=ghaskins@novell.com \
--cc=David.Holmes@sun.com \
--cc=gregory.haskins@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).