RT: Checks for cmpxchg in get_task_struct_rcu()
PATCH 1/1 RT: Checks for cmpxchg in get_task_struct_rcu()
Adds a check for cmpxchg in get_task_struct_rcu(), and implements the case when it doesn't exist.
include/linux/sched.h +9 -1
@@ -1026,13 +1026,21 @@ static inline int get_task_struct_rcu(st {int oldusage; +#ifdef __HAVE_ARCH_CMPXCHGdo { oldusage =atomic_read (&t->usage);if (oldusage ==0 ) {return 0 ; } }while (cmpxchg (&t->usage.counter, - oldusage, oldusage +1 ) != oldusage); + oldusage, oldusage +1 ) != oldusage); +#else + oldusage =atomic_read (&t->usage); +if (oldusage ==0 ) { +return 0 ; + } +atomic_inc (&t->usage); +#endif return 1 ; }
Quoted 3 lines · Daniel Walker
Adds a check for cmpxchg in
get_task_struct_rcu(), and implements the case when it doesn't exist.
I believe this is racy.
Quoted 14 lines
Signed-off-by Daniel Walker <[email protected]>Index:
linux-2.6.13/include/linux/sched.h
===================================================================include/linux/sched.h +1
-0@@ -1026,13 +1026,21 @@ static inline int get_task_struct_rcu(st {int oldusage; +#ifdef __HAVE_ARCH_CMPXCHG do { oldusage = atomic_read(&t->usage); if (oldusage == 0) {
include/linux/sched.h static inline int get_task_struct_rcu(st · line 1041
Quoted 10 lines
include/linux/sched.h +6
-1return 0; } }while (cmpxchg (&t->usage.counter, - oldusage, oldusage +1 ) != oldusage); + oldusage, oldusage +1 ) != oldusage); +#else + oldusage =atomic_read (&t->usage); +if (oldusage ==0 ) { +return 0 ; + }
What if t->usage becomes 0 here?
include/linux/sched.h static inline int get_task_struct_rcu(st · line 1046
Quoted 5 lines
include/linux/sched.h +2
-0+atomic_inc (&t->usage); +#endif return 1 ; }
You need my atomic_cmpxchg patches that provide an atomic_cmpxchg (and atomic_inc_not_zero) for all architectures.
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 3 lines · Nick Piggin
You need my
atomic_cmpxchgpatches that provide anatomic_cmpxchg(andatomic_inc_not_zero) for all architectures.
It is racy, but why not just disable preemption ..
Daniel
Quoted 10 lines · Daniel Walker
Quoted 3 lines · Nick Piggin
You need my
atomic_cmpxchgpatches that provide anatomic_cmpxchg(andatomic_inc_not_zero) for all architectures.It is racy, but why not just disable preemption ..
Well you haven't, that's the point. You *introduce* racy operation.
Anyway, no matter, atomic_cmpxchg will take care of this nicely.
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Checks for cmpxchg in get_task_struct_rcu() . No race version.
include/linux/sched.h +12 -1
@@ -1026,13 +1026,24 @@ static inline int get_task_struct_rcu(st {int oldusage; +#ifdef __HAVE_ARCH_CMPXCHGdo { oldusage =atomic_read (&t->usage);if (oldusage ==0 ) {return 0 ; } }while (cmpxchg (&t->usage.counter, - oldusage, oldusage +1 ) != oldusage); + oldusage, oldusage +1 ) != oldusage); +#else +raw_local_irq_disable (); + oldusage =atomic_read (&t->usage); +if (oldusage ==0 ) { +raw_local_irq_enable (); +return 0 ; + } +atomic_inc (&t->usage); +raw_local_irq_enable (); +#endif return 1 ; }
include/linux/sched.h static inline int get_task_struct_rcu(st · line 1043
Quoted 7 lines · Daniel Walker
include/linux/sched.h +7
-0+#else +raw_local_irq_disable (); + oldusage =atomic_read (&t->usage); +if (oldusage ==0 ) { +raw_local_irq_enable (); +return 0 ; + }
Isn't this still racy if another cpu drops the last reference to task struct here? Or can't that happen?
When you said "disable preempt", I had some silly idea that this function was only used in PREEMPT_RT mode, and that you would simply disallow architectures without cmpxchg from configuring PREEMPT_RT.
Quoted 3 lines
include/linux/sched.h +3
-0+atomic_inc (&t->usage); +raw_local_irq_enable (); +#endif
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 1 line · Daniel Walker
Checks for cmpxchg in
get_task_struct_rcu(). No race version.
shouldnt we actually define a global, default cmpxchg() function, based on IRQ-disable - instead of open-coding one?
Ingo
Quoted 6 lines · Ingo Molnar
Quoted 1 line · Daniel Walker
Checks for cmpxchg in
get_task_struct_rcu(). No race version.shouldnt we actually define a global, default
cmpxchg()function, based on IRQ-disable - instead of open-coding one?
I was thinking it should be restructures so it just needs an atomic_inc in this case. Considering that without cmpxchg() you must be on a UP machine .
Daniel
Quoted 2 lines · Nick Piggin
You need my
atomic_cmpxchgpatches that provide anatomic_cmpxchg(andatomic_inc_not_zero) for all architectures.
yeah. When will they be merged upstream?
Ingo
Quoted 7 lines · Ingo Molnar
Quoted 2 lines · Nick Piggin
You need my
atomic_cmpxchgpatches that provide anatomic_cmpxchg(andatomic_inc_not_zero) for all architectures.yeah. When will they be merged upstream?
Well they're in -mm now, you can put them in your RT tree until they're in mainline... I guess realistically, 2.6.15. They should blow up fairly quickly if there are any problems with them, but they simply need a bit of testing on all architectures which I cannot do and I suspect even -mm isn't tested on at least half of them.
Signature · 5 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 6 lines · Nick Piggin
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Nick Piggin
You need my
atomic_cmpxchgpatches that provide anatomic_cmpxchg(andatomic_inc_not_zero) for all architectures.
Quoted 8 lines
Quoted 2 lines
yeah. When will they be merged upstream?
Well they're in -mm now, you can put them in your RT tree until they're in mainline... I guess realistically, 2.6.15. They should blow up fairly quickly if there are any problems with them, but they simply need a bit of testing on all architectures which I cannot do and I suspect even -mm isn't tested on at least half of them.
very good - i'll put them into -rt.
Ingo