1. single thread wq
struct workqueue_struct *IT7260_wq;
create wq:
IT7260_wq = create_singlethread_workqueue("IT7260_wq");
INIT_WORK(&work, IT7260_ts_work_func);
- struct work_struct work;
- static void IT7260_ts_work_func(struct work_struct *work)
add delay work:
queue_work(IT7260_wq, &work);
delete wq:
destroy_workqueue(IT7260_wq);
2. system wq
struct delayed_work delayed_work;
INIT_DELAYED_WORK(&delayed_work, touch_delayed_work);
- void touch_delayed_work(struct work_struct* work)
schedule_delayed_work(&delayed_work, msecs_to_jiffies(1));
cancel_delayed_work_sync(&touch_delayed_work);
3. hrtimer
enum hrtimer_restart IT7260_ts_timer_func(struct hrtimer *timer)
{
/* ... */
return HRTIMER_NORESTART; /* one time */
}
struct hrtimer timer;
/* init and start */
hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
timer.function = IT7260_ts_timer_func;
hrtimer_start(&timer, ktime_set(1, 0), HRTIMER_MODE_REL);
/* cancel */
hrtimer_cancel(&ts->timer);
4. workqueue由谁调度?
*** kernel wq dump ****
[<c00ae490>] (unwind_backtrace+0x0/0xf0) from [<bf08236c>] (touch_delayed_work+0xc/0x20 [touchpanel])
[<bf08236c>] (touch_delayed_work+0xc/0x20 [touchpanel]) from [<c00d98c8>] (worker_thread+0x154/0x1d8)
[<c00d98c8>] (worker_thread+0x154/0x1d8) from [<c00dc5d4>] (kthread+0x78/0x80)
[<c00dc5d4>] (kthread+0x78/0x80) from [<c00a9e10>] (kernel_thread_exit+0x0/0x8)
call stack:
init_workqueues(void), kernel/workqueue.c
create_workqueue("events");
create_workqueue_thread(cwq, cpu);
kthread_create(worker_thread, cwq, fmt, wq->name, cpu);
因此,workqueue由内核进程events/X管理调度:
# ps
PID USER VSZ STAT COMMAND
1 root 360 S /init
2 root 0 SW [kthreadd]
3 root 0 SW [ksoftirqd/0]
4 root 0 SW [watchdog/0]
5 root 0 SW [events/0]
6 root 0 SW [khelper]
10 root 0 SW [async/mgr]
13 root 0 SW [suspend]
213 root 0 SW [sync_supers]
215 root 0 SW [bdi-default]
216 root 0 SW [kblockd/0]
226 root 0 SW [khubd]
229 root 0 SW [kseriod]
241 root 0 SW [kmmcd]
248 root 0 SW [bluetooth]
263 root 0 SW [rpciod/0]
271 root 0 SW [khungtaskd]
272 root 0 SW [kswapd0]
274 root 0 SW [aio/0]
275 root 0 SW [nfsiod]
277 root 0 SW [crypto/0]
427 root 0 SW [mtdblockd]
467 root 0 SW [ubi_bgt0d]
470 root 0 SW [ubi_bgt1d]
473 root 0 SW [ubi_bgt2d]
476 root 0 SW [ubi_bgt3d]
479 root 0 SW [ubi_bgt4d]
502 root 0 SW [file-storage]
535 root 0 SW [w1_bus_master1]
543 root 0 SW [power]
559 root 0 SW [usbhid_resumer]
562 root 0 SW [binder]
571 root 0 SW< [krfcommd]
872 root 0 SW [ubifs_bgt1_0]
874 root 0 SW [ubifs_bgt2_0]
876 root 0 SW [ubifs_bgt4_0]
879 root 0 SW [galcore daemon ]
887 root 0 SW [ipolldevd]