打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
delay work and hrtimer

delay work and hrtimer  

2010-11-30 23:05:22|  分类: 技术 |  标签:workqueue  hrtimer   |举报 |字号 订阅

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]
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
内核工作队列(workqueue)
Linux工作队列实现机制
linux设备驱动归纳总结(六):3.中断下半部之工作队列
工作队列分析
Linux kernel 中的work queue原理
Linux中Workqueue 机制分析
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服