linux kernel 工程师
全部博文(99)
分类: LINUX
2014-02-05 17:56:24
2.6.36 开始, workqueue进行大的改变
1. 每个cpu上至少有一个idle的worker
2. 当一个cpu上running的worker不够时(running 的worker数==0, 或者有GCWQ_HIGHPRI_PENDING的work),idle的worker数等于0,这时会创建出一个新的worker
3. 如果cpu上有一个或者多个running的workers(不考虑GCWQ_HIGHPRI_PENDING),这时不需要创建更多的worker,这样可以使批处理任务快速得以处理,而没有任务上下文切换的开销
有一个问题:假如一个running的worker被阻塞,那么后面其他的work都会被耽误掉,这时为什么不创建一个新的worker呢?
/*
* Policy functions. These define the policies on how the global
* worker pool is managed. Unless noted otherwise, these functions
* assume that they're being called with gcwq->lock held.
*/
static bool __need_more_worker(struct global_cwq *gcwq)
{
return !atomic_read(get_gcwq_nr_running(gcwq->cpu)) ||
gcwq->flags & GCWQ_HIGHPRI_PENDING;
}
/*
* Need to wake up a worker? Called from anything but currently
* running workers.
*/
static bool need_more_worker(struct global_cwq *gcwq)
{
return !list_empty(&gcwq->worklist) && __need_more_worker(gcwq);
}