mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* BUG: sched:sched_migrate_task event tracing returns incorrect events
@ 2010-06-10 14:56 Ronny Tschüter
  2010-06-10 15:11 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Ronny Tschüter @ 2010-06-10 14:56 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner, Peter Zijlstra; +Cc: Linux Kernel Mailing List

Hi,

I want to know a little bit more about the execution of my program. 
Especially I'm interested in cpu migrations of my process. Therefore I 
use the Linux performance counter infrastructure, set appropriate 
perf_event attributes and setup the sched:sched_migrate_task event with 
a system call:
...
attr.type = PERF_TYPE_TRACEPOINT;
attr.size = sizeof( struct perf_event_attr );
attr.config = event_id; // id of sched:sched_migrate_task event
attr.sample_type = PERF_SAMPLE_TIME|PERF_SAMPLE_CPU|PERF_SAMPLE_RAW;
attr.freq = 0;
attr.sample_freq = 1;
fd = syscall( __NR_perf_counter_open, &attr, getpid(), -1, -1, 0 );
...
Finally to read the events I map the kernel event buffer via mmap and 
process every event in this buffer. However I run into two problems:

(1) I need root privileges to open the counter successfully. Without 
root privileges syscall returns -1. I think that is not OK because users 
should be allowed to create per task counters.

(2) The buffer contains events that aren't caused by my process (i.e. 
the COMM field does not contain the name of my process and the PID field 
is not equal to the pid of my process).

Some information about my system:
Processor: Core 2 Duo E6750
Kernel information: Linux version 2.6.34-100610-1530 (gcc version 4.4.3 
(Ubuntu 4.4.3-4ubuntu5) ) #1 SMP

This behaviour could also be observed in tests with
- Linux version 2.6.33.3 (gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9) ) #1 SMP
- Linux version 2.6.32-22-generic (buildd@yellow) (gcc version 4.4.3 
(Ubuntu 4.4.3-4ubuntu5) ) #36-Ubuntu SMP (Ubuntu 10.04)


Bye, Ronny Tschueter


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: BUG: sched:sched_migrate_task event tracing returns incorrect events
  2010-06-10 14:56 BUG: sched:sched_migrate_task event tracing returns incorrect events Ronny Tschüter
@ 2010-06-10 15:11 ` Peter Zijlstra
  2010-06-14  7:44   ` Ronny Tschüter
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2010-06-10 15:11 UTC (permalink / raw)
  To: Ronny Tschüter
  Cc: Ingo Molnar, Thomas Gleixner, Linux Kernel Mailing List

On Thu, 2010-06-10 at 16:56 +0200, Ronny Tschüter wrote:
> Hi,
> 
> I want to know a little bit more about the execution of my program. 
> Especially I'm interested in cpu migrations of my process. Therefore I 
> use the Linux performance counter infrastructure, set appropriate 
> perf_event attributes and setup the sched:sched_migrate_task event with 
> a system call:
> ...
> attr.type = PERF_TYPE_TRACEPOINT;
> attr.size = sizeof( struct perf_event_attr );
> attr.config = event_id; // id of sched:sched_migrate_task event
> attr.sample_type = PERF_SAMPLE_TIME|PERF_SAMPLE_CPU|PERF_SAMPLE_RAW;
> attr.freq = 0;
> attr.sample_freq = 1;
> fd = syscall( __NR_perf_counter_open, &attr, getpid(), -1, -1, 0 );
> ...
> Finally to read the events I map the kernel event buffer via mmap and 
> process every event in this buffer. However I run into two problems:
> 
> (1) I need root privileges to open the counter successfully. Without 
> root privileges syscall returns -1. I think that is not OK because users 
> should be allowed to create per task counters.

It is, because you specify PERF_SAMPLE_RAW, which is considered a data
leak for unpriv users.

> (2) The buffer contains events that aren't caused by my process (i.e. 
> the COMM field does not contain the name of my process and the PID field 
> is not equal to the pid of my process).

I think that could happen if the migration happens from interrupt
context while your task is running. Also wakeups your process does can
result in migrations of the woken task from the context of your task.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: BUG: sched:sched_migrate_task event tracing returns incorrect events
  2010-06-10 15:11 ` Peter Zijlstra
@ 2010-06-14  7:44   ` Ronny Tschüter
  0 siblings, 0 replies; 3+ messages in thread
From: Ronny Tschüter @ 2010-06-14  7:44 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: Ingo Molnar, Thomas Gleixner, Linux Kernel Mailing List

Am 10.06.2010 17:11, schrieb Peter Zijlstra:
> On Thu, 2010-06-10 at 16:56 +0200, Ronny Tschüter wrote:
>    
>> Hi,
>>
>> I want to know a little bit more about the execution of my program.
>> Especially I'm interested in cpu migrations of my process. Therefore I
>> use the Linux performance counter infrastructure, set appropriate
>> perf_event attributes and setup the sched:sched_migrate_task event with
>> a system call:
>> ...
>> attr.type = PERF_TYPE_TRACEPOINT;
>> attr.size = sizeof( struct perf_event_attr );
>> attr.config = event_id; // id of sched:sched_migrate_task event
>> attr.sample_type = PERF_SAMPLE_TIME|PERF_SAMPLE_CPU|PERF_SAMPLE_RAW;
>> attr.freq = 0;
>> attr.sample_freq = 1;
>> fd = syscall( __NR_perf_counter_open,&attr, getpid(), -1, -1, 0 );
>> ...
>> Finally to read the events I map the kernel event buffer via mmap and
>> process every event in this buffer. However I run into two problems:
>>
>> (1) I need root privileges to open the counter successfully. Without
>> root privileges syscall returns -1. I think that is not OK because users
>> should be allowed to create per task counters.
>>      
> It is, because you specify PERF_SAMPLE_RAW, which is considered a data
> leak for unpriv users.
>
>    
>> (2) The buffer contains events that aren't caused by my process (i.e.
>> the COMM field does not contain the name of my process and the PID field
>> is not equal to the pid of my process).
>>      
> I think that could happen if the migration happens from interrupt
> context while your task is running. Also wakeups your process does can
> result in migrations of the woken task from the context of your task.
>    
What I need is a counter that trace every scheduling event (at least 
every cpu migration event) of a given process. Is there such a counter 
in the perf_events or does all counters come with this weakness? At the 
moment I open one counter per cpu, trace all scheduling events on this 
cpu and filter the events manually. But this approach is not feasible 
for MPI programs, because the number of required counters will increase 
enormously ( #processes * #cpus counters are needed ).



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-06-14  7:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-10 14:56 BUG: sched:sched_migrate_task event tracing returns incorrect events Ronny Tschüter
2010-06-10 15:11 ` Peter Zijlstra
2010-06-14  7:44   ` Ronny Tschüter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome