John Levon wrote:
> Here's what's in my tree now. I need to split it up before sending to
> Linus, and it's entirely untested as of yet. It does :
> o move timer_int.c into one independent file (also fixing a parisc bug)
> o fix the deadlock issue by scheduling the work for non-mmap_sem context
> o make sure to finish scheduled work (shutdown race fix)
> o take task_lock()
> o some doc fixes in buffer_sync.c
> o prevent against racing threads in event_buffer_read()
> o remove the wrong/pointless buffer_sem taking in shutdown
> o cleanup usage of start_sem to be clear
> Any comments ?
I looked only mmap sem deadlock and timer_int move.
> On top of this there will be Will's force timer patch, and possibly the
> interrupt-marking patch for --separate=kernel
> --- linux-cvs/drivers/oprofile/buffer_sync.c 2003-04-05 18:44:49.000000000 +0100
> +++ linux-me/drivers/oprofile/buffer_sync.c 2003-04-29 01:58:49.000000000 +0100
> +static int munmap_notify(struct notifier_block * self, unsigned long val, void * data)
> + /* Note that we cannot sync the buffers directly, because we might end up
> + * taking the the mmap_sem that we hold now inside of event_buffer_read()
> + * on a page fault, whilst holding buffer_sem - deadlock.
> + *
> + * This would mean a threaded reader of the event buffer, but we should
> + * prevent it anyway.
> + */
if (current != current at event_buffer_open() time)
we can safely do sync_cpu_buffers(). We just need
to record current at event_buffer_open().
Without this all sample in cpu_buffer and credited
to this mapping are lost or miscredited. This can
be meaningfull for all short time task which dynamic
load a lib and unload it explicitely rather to let
exit() do the cleanup.
I insist, after the previous discussion, because
to fix a highly theorical case (threaded reader
which unmap code) you open a hole for samples lost
or miscredited w/o the ability to know, even roughly,
by how many we will lost or miscredit samples.
> + schedule_work(&sync_wq);
> + return 0;
> --- linux-cvs/drivers/oprofile/timer_int.c 1970-01-01 01:00:00.000000000 +0100
> +++ linux-me/drivers/oprofile/timer_int.c 2003-04-29 01:25:24.000000000 +0100
> @@ -0,0 +1,56 @@
> +#include <linux/oprofile.h>
> +#include <asm/ptrace.h>
Look the attached patch, fix miscounting lost sample
due to mm->mmap_sem taken. diff against vanilla 2.5.68