2010-11-23 13:01:29

by Franck Bui-Huu

[permalink] [raw]
Subject: How about limiting refresh ioctl to sampling events ?

Hello Peter,

I'm looking at the perf event stuff and wondering if
perf_event_refresh() should be limited to sampling events.

Does the following make sense ?

diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 3b105e0..1a90a6c 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -1072,7 +1072,7 @@ static int perf_event_refresh(struct perf_event *event, int refresh)
/*
* not supported on inherited events
*/
- if (event->attr.inherit)
+ if (event->attr.inherit || !event->attr.sample_period)
return -EINVAL;

atomic_add(refresh, &event->event_limit);

Thanks
--
Franck


2010-11-23 13:07:08

by Peter Zijlstra

[permalink] [raw]
Subject: Re: How about limiting refresh ioctl to sampling events ?

On Tue, 2010-11-23 at 14:01 +0100, Franck Bui-Huu wrote:
> Hello Peter,
>
> I'm looking at the perf event stuff and wondering if
> perf_event_refresh() should be limited to sampling events.
>
> Does the following make sense ?
>
> diff --git a/kernel/perf_event.c b/kernel/perf_event.c
> index 3b105e0..1a90a6c 100644
> --- a/kernel/perf_event.c
> +++ b/kernel/perf_event.c
> @@ -1072,7 +1072,7 @@ static int perf_event_refresh(struct perf_event *event, int refresh)
> /*
> * not supported on inherited events
> */
> - if (event->attr.inherit)
> + if (event->attr.inherit || !event->attr.sample_period)
> return -EINVAL;
>
> atomic_add(refresh, &event->event_limit);

Yes it does, please submit as a proper patch.

2010-11-23 13:19:33

by Franck Bui-Huu

[permalink] [raw]
Subject: Re: How about limiting refresh ioctl to sampling events ?

Peter Zijlstra <[email protected]> writes:

> On Tue, 2010-11-23 at 14:01 +0100, Franck Bui-Huu wrote:
>> Hello Peter,
>>
>> I'm looking at the perf event stuff and wondering if
>
>> perf_event_refresh() should be limited to sampling events.
>>
>> Does the following make sense ?
>>
>> diff --git a/kernel/perf_event.c b/kernel/perf_event.c
>> index 3b105e0..1a90a6c 100644
>> --- a/kernel/perf_event.c
>> +++ b/kernel/perf_event.c
>> @@ -1072,7 +1072,7 @@ static int perf_event_refresh(struct perf_event *event, int refresh)
>> /*
>> * not supported on inherited events
>> */
>> - if (event->attr.inherit)
>> + if (event->attr.inherit || !event->attr.sample_period)
>> return -EINVAL;
>>
>> atomic_add(refresh, &event->event_limit);
>
> Yes it does, please submit as a proper patch.

Ok.

I'm also wondering if you would accept a second patch which will
introduce:

static inline bool is_sampling_event(struct perf_event *event)
{
return event->attr.sample_period != 0;
}

That would make the code slighlty easier to read IMHO.

--
Franck

2010-11-23 13:46:05

by Peter Zijlstra

[permalink] [raw]
Subject: Re: How about limiting refresh ioctl to sampling events ?

On Tue, 2010-11-23 at 14:19 +0100, Franck Bui-Huu wrote:
> Peter Zijlstra <[email protected]> writes:
>
> > On Tue, 2010-11-23 at 14:01 +0100, Franck Bui-Huu wrote:
> >> Hello Peter,
> >>
> >> I'm looking at the perf event stuff and wondering if
> >
> >> perf_event_refresh() should be limited to sampling events.
> >>
> >> Does the following make sense ?
> >>
> >> diff --git a/kernel/perf_event.c b/kernel/perf_event.c
> >> index 3b105e0..1a90a6c 100644
> >> --- a/kernel/perf_event.c
> >> +++ b/kernel/perf_event.c
> >> @@ -1072,7 +1072,7 @@ static int perf_event_refresh(struct perf_event *event, int refresh)
> >> /*
> >> * not supported on inherited events
> >> */
> >> - if (event->attr.inherit)
> >> + if (event->attr.inherit || !event->attr.sample_period)
> >> return -EINVAL;
> >>
> >> atomic_add(refresh, &event->event_limit);
> >
> > Yes it does, please submit as a proper patch.
>
> Ok.
>
> I'm also wondering if you would accept a second patch which will
> introduce:
>
> static inline bool is_sampling_event(struct perf_event *event)
> {
> return event->attr.sample_period != 0;
> }
>
> That would make the code slighlty easier to read IMHO.
>

Sure, Francis might want that too, he found another something like this.

2010-11-24 10:19:17

by Francis Moreau

[permalink] [raw]
Subject: Re: How about limiting refresh ioctl to sampling events ?

Peter Zijlstra <[email protected]> writes:

[...]

>> I'm also wondering if you would accept a second patch which will
>> introduce:
>>
>> static inline bool is_sampling_event(struct perf_event *event)
>> {
>> return event->attr.sample_period != 0;
>> }
>>
>> That would make the code slighlty easier to read IMHO.
>>
>
> Sure, Francis might want that too, he found another something like this.

Yes there's another issue when counting events are used: they call
perf_event_output() when 'period_left' gets 0 where as they should not.

--
Francis