Re: workqueue question.

From: Tejun Heo
Date: Fri Jul 01 2011 - 12:37:41 EST


Hello,

On Thu, Jun 30, 2011 at 10:18:52AM -0700, Ben Greear wrote:
> >>Is there a method that can be called from a workqueue callback
> >>to verify that the item has not been re-added to the work-queue?
> >
> >Can you be a bit more specific? Are you saying that queue_work() and
> >INIT_WORK() may race?
>
> No, I don't think that is racing. Basically, when I'm about
> to logically free (put back into mempool) the task struct, I
> would like to add a sanity check to make sure it's not currently
> scheduled on a work queue. If it were, that would explain the
> backtraces I was seeing from slub memory debugging logic and
> I'd be closer to understanding the problem.

Ah, okay. When a work is in pending state, work_pending() is always
true; however, whether a work item is currently being executed is a
bit more complicated. You'll need to implement a function which looks
similar to the following.

bool is_work_executing(work)
{
for_each_gcwq_cpu(cpu) {
gcwq = get_gcwq(cpu);
lock gcwq;
if (find_worker_executing_work(gcwq, work)) {
unlock gcwq;
return true;
}
unlock gcwq;
}
return false;
}

But I would recommend watching workqueue tracing points first.

$ grep workqueue /sys/kernel/debug/tracing/available_events
workqueue:workqueue_queue_work
workqueue:workqueue_activate_work
workqueue:workqueue_execute_start
workqueue:workqueue_execute_end

You should be able to tell which work is doing what on which CPU.

Thanks.

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/