开发板Linux内核,芯灵思SinlinxA33开发板Linux内核workqueue(附实测代码)

具体定义如下:

struct workqueue_struct {

unsigned int        flags;      /* W: WQ_* flags */

union {

struct cpu_workqueue_struct __percpu    *pcpu;

struct cpu_workqueue_struct     *single;

unsigned long               v;

} cpu_wq;               /* I: cwq's */

struct list_head    list;       /* W: list of all workqueues */

struct mutex        flush_mutex;    /* protects wq flushing */

int         work_color; /* F: current work color */

int         flush_color;    /* F: current flush color */

atomic_t        nr_cwqs_to_flush; /* flush in progress */

struct wq_flusher   *first_flusher; /* F: first flusher */

struct list_head    flusher_queue;  /* F: flush waiters */

struct list_head    flusher_overflow; /* F: flush overflow list */

mayday_mask_t       mayday_mask;    /* cpus requesting rescue */

struct worker       *rescuer;   /* I: rescue worker */int         nr_drainers;    /* W: drain in progress */

int         saved_max_active; /* W: saved cwq max_active */

#ifdef CONFIG_LOCKDEP

struct lockdep_map  lockdep_map;

#endif

char            name[];     /* I: workqueue name */

};

注意:这个结构表示一个工作队列,一般情况下驱动开发者不需要接触太多这个结构成员,关于队列操作,内核都提供了相应的API函数

cpu_workqueue_struct

struct cpu_workqueue_struct {

struct global_cwq   *gcwq;      /* I: the associated gcwq */

struct workqueue_struct *wq;        /* I: the owning workqueue */

int         work_color; /* L: current color */

int         flush_color;    /* L: flushing color */

int         nr_in_flight[WORK_NR_COLORS];

/* L: nr of in_flight works */

int         nr_active;  /* L: nr of active works */

int         max_active; /* L: max active works */

struct list_head    delayed_works;  /* L: delayed works */

};

内核通过delayed_works成员把第一个 work_struct 连接起来,后面work_struct通过本身的entry成员把自己连接在链表上。

内核工作队列分类

内核工作队列分成共享工作队列和自定义工作队列两种

共享工作队列

系统在启动时候自动创建一个工作队列驱动开发者如果想使用这个队列,则不需要自己创建工作队列,只需要把自己的work添加到这个工作队列上即可。

使用schedule_work这个函数可以把work_struct添加到工作队列中

自定义工作队列

由于共享工作队列是大家共同使用的,如果上面的工作函数有存在睡眠的情况,阻塞了,则会影响到后面挂接上去的工作执行时间,当你的动作需要尽快执行,不想受其它工作函数的影响,则自己创建一个工作队列,然后把自己的工作添加到这个自定义工作队列上去。

使用自定义工作队列分为两步:

创建工作队列:使用creat_workqueue(name)创建一个名为name的工作队列

把工作添加到上面创建的工作队列上:使用queue_work函数把一个工作结构work_struc添加到指定的工作队列上

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值