workqueues: microoptimize set_wq_data()
PATCH 2/3 workqueues: microoptimize set_wq_data()
The comment correctly states that the _PENDING bit must be set and we even have the BUG_ON() check. But this means there is no need to set WORK_STRUCT_PENDING explicitely and load work_data_bits() twice, we can rely on WORK_STRUCT_FLAG_MASK which contains _PENDING.
Shaves 32 bytes from workqueue.o.
---
kernel/workqueue.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
kernel/workqueue.c renamed from kernel/workqueue.c~2_CLEANUP_SET_DATA +2 -5
@@ -220,12 +220,9 @@ struct cpu_workqueue_struct *wq_per_cpu(static inline void set_wq_data (struct work_struct *work,struct cpu_workqueue_struct *cwq) { -unsigned long new; - -BUG_ON (!work_pending (work)); - - new = (unsigned long ) cwq | (1UL <<WORK_STRUCT_PENDING ); +unsigned long new = (unsigned long )cwq; new |=WORK_STRUCT_FLAG_MASK & *work_data_bits (work); +BUG_ON (!(new & (1UL <<WORK_STRUCT_PENDING )));atomic_long_set (&work->data, new); }
Tejun Heo
maintainerQuoted 18 lines · Oleg Nesterov
The comment correctly states that the
_PENDINGbit must be set and we even have theBUG_ON()check. But this means there is no need to setWORK_STRUCT_PENDINGexplicitely and loadwork_data_bits()twice, we can rely onWORK_STRUCT_FLAG_MASKwhich contains_PENDING.Shaves 32 bytes from workqueue.o.
Signed-off-by Oleg Nesterov <[email protected]>---
kernel/workqueue.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)kernel/workqueue.c renamed from kernel/workqueue.c~2_CLEANUP_SET_DATA +0
-0@@ -220,12 +220,9 @@ struct cpu_workqueue_struct *wq_per_cpu(static inline void set_wq_data (struct work_struct *work,struct cpu_workqueue_struct *cwq)
kernel/workqueue.c struct cpu_workqueue_struct *wq_per_cpu( · line 226
Quoted 10 lines
kernel/workqueue.c renamed from kernel/workqueue.c~2_CLEANUP_SET_DATA +2
-5{ -unsigned long new; - -BUG_ON (!work_pending (work)); - - new = (unsigned long ) cwq | (1UL <<WORK_STRUCT_PENDING ); +unsigned long new = (unsigned long )cwq; new |=WORK_STRUCT_FLAG_MASK & *work_data_bits (work); +BUG_ON (!(new & (1UL <<WORK_STRUCT_PENDING )));atomic_long_set (&work->data, new);
Will apply under cmwq patches for the next merge window.
Thanks.
Signature · 1 line
tejun
Hello, again.
Quoted 7 lines · Tejun Heo
Quoted 7 lines
kernel/workqueue.c renamed from kernel/workqueue.c~2_CLEANUP_SET_DATA +0
-3@@ -220,12 +220,9 @@ struct cpu_workqueue_struct *wq_per_cpu(static inline void set_wq_data (struct work_struct *work,struct cpu_workqueue_struct *cwq) { -unsigned long new; - -BUG_ON (!work_pending (work));
Quoted 8 lines
kernel/workqueue.c struct cpu_workqueue_struct *wq_per_cpu( · line 226
Quoted 6 lines
kernel/workqueue.c renamed from kernel/workqueue.c~2_CLEANUP_SET_DATA +2
-2- - new = (unsigned long ) cwq | (1UL <<WORK_STRUCT_PENDING ); +unsigned long new = (unsigned long )cwq; new |=WORK_STRUCT_FLAG_MASK & *work_data_bits (work); +BUG_ON (!(new & (1UL <<WORK_STRUCT_PENDING )));atomic_long_set (&work->data, new);Will apply under cmwq patches for the next merge window.
Turns out I already have a patch which kills the second work_data_bits() dereferencing in the series. The first one is now in the cmwq series which is about to be posted again.
Thanks.
Signature · 1 line
tejun
Hi,
Quoted 20 lines · Tejun Heo
Hello, again.
Quoted 7 lines · Tejun Heo
Quoted 7 lines
kernel/workqueue.c renamed from kernel/workqueue.c~2_CLEANUP_SET_DATA +0
-3@@ -220,12 +220,9 @@ struct cpu_workqueue_struct *wq_per_cpu(static inline void set_wq_data (struct work_struct *work,struct cpu_workqueue_struct *cwq) { -unsigned long new; - -BUG_ON (!work_pending (work));Quoted 8 lines
kernel/workqueue.c struct cpu_workqueue_struct *wq_per_cpu( · line 226
Quoted 6 lines
kernel/workqueue.c renamed from kernel/workqueue.c~2_CLEANUP_SET_DATA +2
-2- - new = (unsigned long ) cwq | (1UL <<WORK_STRUCT_PENDING ); +unsigned long new = (unsigned long )cwq; new |=WORK_STRUCT_FLAG_MASK & *work_data_bits (work); +BUG_ON (!(new & (1UL <<WORK_STRUCT_PENDING )));atomic_long_set (&work->data, new);Will apply under cmwq patches for the next merge window.
Quoted 3 lines
Turns out I already have a patch which kills the second
work_data_bits()dereferencing in the series. The first one is now in the cmwq series which is about to be posted again.
OK, good.
Tejun, where can I find your cmwq patches? I'd like to take a look.
Thanks,
Oleg.
Hello,
Quoted 7 lines · Oleg Nesterov
Quoted 3 lines
Turns out I already have a patch which kills the second
work_data_bits()dereferencing in the series. The first one is now in the cmwq series which is about to be posted again.OK, good.
Tejun, where can I find your cmwq patches? I'd like to take a look.
The third take was about a month ago.
http://thread.gmane.org/gmane.linux.kernel/939353
The fourth take is just around the corner.
Thanks.
Signature · 1 line
tejun