Scheduling new work during a context switch

From: Adrien VergÃ
Date: Thu Sep 26 2013 - 17:38:19 EST


Hi,

I am modifying the perf internals to avoid the overhead due to a
second copy, when using Intel's BTS (execution tracing). Mainly, I
have a buffer that fills during the execution of the traced process,
and I sometimes need to save its contents.

When my buffer should be emptied, I schedule a task to copy the buffer
contents to disk later. This action should be performed:
- Whenether the buffer is full (in a IRQ handler).
- Whenether the traced task is scheduled out. This is when it blocks.

The problem is, deferring work in a work queue with schedule_work()
during a context switch (in schedule()) leads to a deadlock, because
both want to hold the same lock (&(&pool->lock)->rlock).
I also tried to pre-schedule the task, make it
wait_event_interruptible(), and wake_up() it during the context
switch, but there is also a deadlock due to already-held &p->pi_lock
in try_to_wake_up().

I am certainly doing something not the way it should be done. Is there
a correct way to defer work during a context switch?

Thanks!

Adrien
--
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/