History

workqueue: factor out __queue_delayed_work() from queue_delayed_work_on()

This is to prepare for mod_delayed_work[_on]() and doesn't cause any functional difference.

Tejun Heo committed 14 years ago

Commit 7beb2ed1 parent b5490071 file · +41 −33Browse files

Showing the changes to kernel/workqueue.c (1 of 1 file). Show all

Unified · Split

kernel/workqueue.c+41−33
@@ -1261,6 +1261,46 @@ void delayed_work_timer_fn(unsigned long __data) · 1260 unmodified lines
1261}1261}
1262EXPORT_SYMBOL_GPL(delayed_work_timer_fn);1262EXPORT_SYMBOL_GPL(delayed_work_timer_fn);
1263 1263
1264static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
1265 struct delayed_work *dwork, unsigned long delay)
1266{
1267 struct timer_list *timer = &dwork->timer;
1268 struct work_struct *work = &dwork->work;
1269 unsigned int lcpu;
1270
1271 WARN_ON_ONCE(timer->function != delayed_work_timer_fn ||
1272 timer->data != (unsigned long)dwork);
1273 BUG_ON(timer_pending(timer));
1274 BUG_ON(!list_empty(&work->entry));
1275
1276 timer_stats_timer_set_start_info(&dwork->timer);
1277
1278 /*
1279 * This stores cwq for the moment, for the timer_fn. Note that the
1280 * work's gcwq is preserved to allow reentrance detection for
1281 * delayed works.
1282 */
1283 if (!(wq->flags & WQ_UNBOUND)) {
1284 struct global_cwq *gcwq = get_work_gcwq(work);
1285
1286 if (gcwq && gcwq->cpu != WORK_CPU_UNBOUND)
1287 lcpu = gcwq->cpu;
1288 else
1289 lcpu = raw_smp_processor_id();
1290 } else {
1291 lcpu = WORK_CPU_UNBOUND;
1292 }
1293
1294 set_work_cwq(work, get_cwq(lcpu, wq), 0);
1295
1296 timer->expires = jiffies + delay;
1297
1298 if (unlikely(cpu != WORK_CPU_UNBOUND))
1299 add_timer_on(timer, cpu);
1300 else
1301 add_timer(timer);
1302}
1303
1264/**1304/**
1265 * queue_delayed_work_on - queue work on specific CPU after delay1305 * queue_delayed_work_on - queue work on specific CPU after delay
1266 * @cpu: CPU number to execute work on1306 * @cpu: CPU number to execute work on
@@ -1275,7 +1315,6 @@ EXPORT_SYMBOL_GPL(delayed_work_timer_fn); · 8 unmodified lines
1275bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,1315bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
1276 struct delayed_work *dwork, unsigned long delay)1316 struct delayed_work *dwork, unsigned long delay)
1277{1317{
1278 struct timer_list *timer = &dwork->timer;
1279 struct work_struct *work = &dwork->work;1318 struct work_struct *work = &dwork->work;
1280 bool ret = false;1319 bool ret = false;
1281 unsigned long flags;1320 unsigned long flags;
@@ -1287,38 +1326,7 @@ bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq, · 5 unmodified lines
1287 local_irq_save(flags);1326 local_irq_save(flags);
1288 1327
1289 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {1328 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
1290 unsigned int lcpu;1329 __queue_delayed_work(cpu, wq, dwork, delay);
1291
1292 WARN_ON_ONCE(timer->function != delayed_work_timer_fn ||
1293 timer->data != (unsigned long)dwork);
1294 BUG_ON(timer_pending(timer));
1295 BUG_ON(!list_empty(&work->entry));
1296
1297 timer_stats_timer_set_start_info(&dwork->timer);
1298
1299 /*
1300 * This stores cwq for the moment, for the timer_fn.
1301 * Note that the work's gcwq is preserved to allow
1302 * reentrance detection for delayed works.
1303 */
1304 if (!(wq->flags & WQ_UNBOUND)) {
1305 struct global_cwq *gcwq = get_work_gcwq(work);
1306
1307 if (gcwq && gcwq->cpu != WORK_CPU_UNBOUND)
1308 lcpu = gcwq->cpu;
1309 else
1310 lcpu = raw_smp_processor_id();
1311 } else
1312 lcpu = WORK_CPU_UNBOUND;
1313
1314 set_work_cwq(work, get_cwq(lcpu, wq), 0);
1315
1316 timer->expires = jiffies + delay;
1317
1318 if (unlikely(cpu != WORK_CPU_UNBOUND))
1319 add_timer_on(timer, cpu);
1320 else
1321 add_timer(timer);
1322 ret = true;1330 ret = true;
1323 }1331 }
1324 1332