diff options
author | David Howells <dhowells@redhat.com> | 2006-11-22 09:54:49 -0500 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2006-11-22 09:54:49 -0500 |
commit | 365970a1ea76d81cb1ad2f652acb605f06dae256 (patch) | |
tree | d2a34e397a4c2d9d0c27ceb0854752afe143c100 | |
parent | 6bb49e5965c1fc399b4d3cd2b5cf2da535b330c0 (diff) |
WorkStruct: Merge the pending bit into the wq_data pointer
Reclaim a word from the size of the work_struct by folding the pending bit and
the wq_data pointer together. This shouldn't cause misalignment problems as
all pointers should be at least 4-byte aligned.
Signed-Off-By: David Howells <dhowells@redhat.com>
-rw-r--r-- | drivers/block/floppy.c | 4 | ||||
-rw-r--r-- | include/linux/workqueue.h | 27 | ||||
-rw-r--r-- | kernel/workqueue.c | 41 |
3 files changed, 57 insertions, 15 deletions
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 5a14fac13b12..aa1eb4466f9d 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c | |||
@@ -1868,7 +1868,7 @@ static void show_floppy(void) | |||
1868 | printk("fdc_busy=%lu\n", fdc_busy); | 1868 | printk("fdc_busy=%lu\n", fdc_busy); |
1869 | if (do_floppy) | 1869 | if (do_floppy) |
1870 | printk("do_floppy=%p\n", do_floppy); | 1870 | printk("do_floppy=%p\n", do_floppy); |
1871 | if (floppy_work.pending) | 1871 | if (work_pending(&floppy_work)) |
1872 | printk("floppy_work.func=%p\n", floppy_work.func); | 1872 | printk("floppy_work.func=%p\n", floppy_work.func); |
1873 | if (timer_pending(&fd_timer)) | 1873 | if (timer_pending(&fd_timer)) |
1874 | printk("fd_timer.function=%p\n", fd_timer.function); | 1874 | printk("fd_timer.function=%p\n", fd_timer.function); |
@@ -4498,7 +4498,7 @@ static void floppy_release_irq_and_dma(void) | |||
4498 | printk("floppy timer still active:%s\n", timeout_message); | 4498 | printk("floppy timer still active:%s\n", timeout_message); |
4499 | if (timer_pending(&fd_timer)) | 4499 | if (timer_pending(&fd_timer)) |
4500 | printk("auxiliary floppy timer still active\n"); | 4500 | printk("auxiliary floppy timer still active\n"); |
4501 | if (floppy_work.pending) | 4501 | if (work_pending(&floppy_work)) |
4502 | printk("work still pending\n"); | 4502 | printk("work still pending\n"); |
4503 | #endif | 4503 | #endif |
4504 | old_fdc = fdc; | 4504 | old_fdc = fdc; |
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index cef40b22ff9a..ecc017d24cf3 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h | |||
@@ -14,11 +14,15 @@ struct workqueue_struct; | |||
14 | typedef void (*work_func_t)(void *data); | 14 | typedef void (*work_func_t)(void *data); |
15 | 15 | ||
16 | struct work_struct { | 16 | struct work_struct { |
17 | unsigned long pending; | 17 | /* the first word is the work queue pointer and the pending flag |
18 | * rolled into one */ | ||
19 | unsigned long management; | ||
20 | #define WORK_STRUCT_PENDING 0 /* T if work item pending execution */ | ||
21 | #define WORK_STRUCT_FLAG_MASK (3UL) | ||
22 | #define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK) | ||
18 | struct list_head entry; | 23 | struct list_head entry; |
19 | work_func_t func; | 24 | work_func_t func; |
20 | void *data; | 25 | void *data; |
21 | void *wq_data; | ||
22 | }; | 26 | }; |
23 | 27 | ||
24 | struct delayed_work { | 28 | struct delayed_work { |
@@ -65,7 +69,7 @@ struct execute_work { | |||
65 | #define INIT_WORK(_work, _func, _data) \ | 69 | #define INIT_WORK(_work, _func, _data) \ |
66 | do { \ | 70 | do { \ |
67 | INIT_LIST_HEAD(&(_work)->entry); \ | 71 | INIT_LIST_HEAD(&(_work)->entry); \ |
68 | (_work)->pending = 0; \ | 72 | (_work)->management = 0; \ |
69 | PREPARE_WORK((_work), (_func), (_data)); \ | 73 | PREPARE_WORK((_work), (_func), (_data)); \ |
70 | } while (0) | 74 | } while (0) |
71 | 75 | ||
@@ -75,6 +79,21 @@ struct execute_work { | |||
75 | init_timer(&(_work)->timer); \ | 79 | init_timer(&(_work)->timer); \ |
76 | } while (0) | 80 | } while (0) |
77 | 81 | ||
82 | /** | ||
83 | * work_pending - Find out whether a work item is currently pending | ||
84 | * @work: The work item in question | ||
85 | */ | ||
86 | #define work_pending(work) \ | ||
87 | test_bit(WORK_STRUCT_PENDING, &(work)->management) | ||
88 | |||
89 | /** | ||
90 | * delayed_work_pending - Find out whether a delayable work item is currently | ||
91 | * pending | ||
92 | * @work: The work item in question | ||
93 | */ | ||
94 | #define delayed_work_pending(work) \ | ||
95 | test_bit(WORK_STRUCT_PENDING, &(work)->work.management) | ||
96 | |||
78 | 97 | ||
79 | extern struct workqueue_struct *__create_workqueue(const char *name, | 98 | extern struct workqueue_struct *__create_workqueue(const char *name, |
80 | int singlethread); | 99 | int singlethread); |
@@ -115,7 +134,7 @@ static inline int cancel_delayed_work(struct delayed_work *work) | |||
115 | 134 | ||
116 | ret = del_timer_sync(&work->timer); | 135 | ret = del_timer_sync(&work->timer); |
117 | if (ret) | 136 | if (ret) |
118 | clear_bit(0, &work->work.pending); | 137 | clear_bit(WORK_STRUCT_PENDING, &work->work.management); |
119 | return ret; | 138 | return ret; |
120 | } | 139 | } |
121 | 140 | ||
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 1e9d61ecf762..967479756511 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -80,6 +80,29 @@ static inline int is_single_threaded(struct workqueue_struct *wq) | |||
80 | return list_empty(&wq->list); | 80 | return list_empty(&wq->list); |
81 | } | 81 | } |
82 | 82 | ||
83 | static inline void set_wq_data(struct work_struct *work, void *wq) | ||
84 | { | ||
85 | unsigned long new, old, res; | ||
86 | |||
87 | /* assume the pending flag is already set and that the task has already | ||
88 | * been queued on this workqueue */ | ||
89 | new = (unsigned long) wq | (1UL << WORK_STRUCT_PENDING); | ||
90 | res = work->management; | ||
91 | if (res != new) { | ||
92 | do { | ||
93 | old = res; | ||
94 | new = (unsigned long) wq; | ||
95 | new |= (old & WORK_STRUCT_FLAG_MASK); | ||
96 | res = cmpxchg(&work->management, old, new); | ||
97 | } while (res != old); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | static inline void *get_wq_data(struct work_struct *work) | ||
102 | { | ||
103 | return (void *) (work->management & WORK_STRUCT_WQ_DATA_MASK); | ||
104 | } | ||
105 | |||
83 | /* Preempt must be disabled. */ | 106 | /* Preempt must be disabled. */ |
84 | static void __queue_work(struct cpu_workqueue_struct *cwq, | 107 | static void __queue_work(struct cpu_workqueue_struct *cwq, |
85 | struct work_struct *work) | 108 | struct work_struct *work) |
@@ -87,7 +110,7 @@ static void __queue_work(struct cpu_workqueue_struct *cwq, | |||
87 | unsigned long flags; | 110 | unsigned long flags; |
88 | 111 | ||
89 | spin_lock_irqsave(&cwq->lock, flags); | 112 | spin_lock_irqsave(&cwq->lock, flags); |
90 | work->wq_data = cwq; | 113 | set_wq_data(work, cwq); |
91 | list_add_tail(&work->entry, &cwq->worklist); | 114 | list_add_tail(&work->entry, &cwq->worklist); |
92 | cwq->insert_sequence++; | 115 | cwq->insert_sequence++; |
93 | wake_up(&cwq->more_work); | 116 | wake_up(&cwq->more_work); |
@@ -108,7 +131,7 @@ int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work) | |||
108 | { | 131 | { |
109 | int ret = 0, cpu = get_cpu(); | 132 | int ret = 0, cpu = get_cpu(); |
110 | 133 | ||
111 | if (!test_and_set_bit(0, &work->pending)) { | 134 | if (!test_and_set_bit(WORK_STRUCT_PENDING, &work->management)) { |
112 | if (unlikely(is_single_threaded(wq))) | 135 | if (unlikely(is_single_threaded(wq))) |
113 | cpu = singlethread_cpu; | 136 | cpu = singlethread_cpu; |
114 | BUG_ON(!list_empty(&work->entry)); | 137 | BUG_ON(!list_empty(&work->entry)); |
@@ -123,7 +146,7 @@ EXPORT_SYMBOL_GPL(queue_work); | |||
123 | static void delayed_work_timer_fn(unsigned long __data) | 146 | static void delayed_work_timer_fn(unsigned long __data) |
124 | { | 147 | { |
125 | struct delayed_work *dwork = (struct delayed_work *)__data; | 148 | struct delayed_work *dwork = (struct delayed_work *)__data; |
126 | struct workqueue_struct *wq = dwork->work.wq_data; | 149 | struct workqueue_struct *wq = get_wq_data(&dwork->work); |
127 | int cpu = smp_processor_id(); | 150 | int cpu = smp_processor_id(); |
128 | 151 | ||
129 | if (unlikely(is_single_threaded(wq))) | 152 | if (unlikely(is_single_threaded(wq))) |
@@ -150,12 +173,12 @@ int fastcall queue_delayed_work(struct workqueue_struct *wq, | |||
150 | if (delay == 0) | 173 | if (delay == 0) |
151 | return queue_work(wq, work); | 174 | return queue_work(wq, work); |
152 | 175 | ||
153 | if (!test_and_set_bit(0, &work->pending)) { | 176 | if (!test_and_set_bit(WORK_STRUCT_PENDING, &work->management)) { |
154 | BUG_ON(timer_pending(timer)); | 177 | BUG_ON(timer_pending(timer)); |
155 | BUG_ON(!list_empty(&work->entry)); | 178 | BUG_ON(!list_empty(&work->entry)); |
156 | 179 | ||
157 | /* This stores wq for the moment, for the timer_fn */ | 180 | /* This stores wq for the moment, for the timer_fn */ |
158 | work->wq_data = wq; | 181 | set_wq_data(work, wq); |
159 | timer->expires = jiffies + delay; | 182 | timer->expires = jiffies + delay; |
160 | timer->data = (unsigned long)dwork; | 183 | timer->data = (unsigned long)dwork; |
161 | timer->function = delayed_work_timer_fn; | 184 | timer->function = delayed_work_timer_fn; |
@@ -182,12 +205,12 @@ int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, | |||
182 | struct timer_list *timer = &dwork->timer; | 205 | struct timer_list *timer = &dwork->timer; |
183 | struct work_struct *work = &dwork->work; | 206 | struct work_struct *work = &dwork->work; |
184 | 207 | ||
185 | if (!test_and_set_bit(0, &work->pending)) { | 208 | if (!test_and_set_bit(WORK_STRUCT_PENDING, &work->management)) { |
186 | BUG_ON(timer_pending(timer)); | 209 | BUG_ON(timer_pending(timer)); |
187 | BUG_ON(!list_empty(&work->entry)); | 210 | BUG_ON(!list_empty(&work->entry)); |
188 | 211 | ||
189 | /* This stores wq for the moment, for the timer_fn */ | 212 | /* This stores wq for the moment, for the timer_fn */ |
190 | work->wq_data = wq; | 213 | set_wq_data(work, wq); |
191 | timer->expires = jiffies + delay; | 214 | timer->expires = jiffies + delay; |
192 | timer->data = (unsigned long)dwork; | 215 | timer->data = (unsigned long)dwork; |
193 | timer->function = delayed_work_timer_fn; | 216 | timer->function = delayed_work_timer_fn; |
@@ -223,8 +246,8 @@ static void run_workqueue(struct cpu_workqueue_struct *cwq) | |||
223 | list_del_init(cwq->worklist.next); | 246 | list_del_init(cwq->worklist.next); |
224 | spin_unlock_irqrestore(&cwq->lock, flags); | 247 | spin_unlock_irqrestore(&cwq->lock, flags); |
225 | 248 | ||
226 | BUG_ON(work->wq_data != cwq); | 249 | BUG_ON(get_wq_data(work) != cwq); |
227 | clear_bit(0, &work->pending); | 250 | clear_bit(WORK_STRUCT_PENDING, &work->management); |
228 | f(data); | 251 | f(data); |
229 | 252 | ||
230 | spin_lock_irqsave(&cwq->lock, flags); | 253 | spin_lock_irqsave(&cwq->lock, flags); |