[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c62a9f8a-312d-4f9e-9022-265e53564101@arm.com>
Date: Fri, 7 Mar 2025 20:28:13 +0000
From: Mark Barnett <mark.barnett@....com>
To: Leo Yan <leo.yan@....com>
Cc: peterz@...radead.org, mingo@...hat.com, acme@...nel.org,
namhyung@...nel.org, irogers@...gle.com, ben.gainey@....com,
deepak.surti@....com, ak@...ux.intel.com, will@...nel.org,
james.clark@....com, mark.rutland@....com,
alexander.shishkin@...ux.intel.com, jolsa@...nel.org,
adrian.hunter@...el.com, linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org
Subject: Re: [PATCH v2 1/5] perf: Allow periodic events to alternate between
two sample periods
On 1/21/25 13:01, Leo Yan wrote:
>> local64_set(&hwc->period_left, hwc->sample_period);
>>
>> + if (attr->alt_sample_period) {
>> + hwc->sample_period = attr->alt_sample_period;
>> + hwc->using_alt_sample_period = true;
>> + }
>
> My understanding it sets a short sample window for the first period.
> Would it initialize the `hwc->period_left` with the updated sample
> period?
>
It sets the long period first: hwc->period_left is used to program the
PMU when setting up the event, and hwc->sample_period is queued up as
the next period to switch to.
>> +
>> + /*
>> + * alt_sample_period cannot be used with freq
>> + */
>> + if (attr->freq && attr->alt_sample_period)
>> + goto err_ns;
>> +
>
> It is good to validate parameters first. So move the checking before
> the adjustment for the alt sample period.
>
Ack. Done.
>> /*
>> * We do not support PERF_SAMPLE_READ on inherited events unless
>> * PERF_SAMPLE_TID is also selected, which allows inherited events to
>> @@ -12763,9 +12788,19 @@ SYSCALL_DEFINE5(perf_event_open,
>> if (attr.freq) {
>> if (attr.sample_freq > sysctl_perf_event_sample_rate)
>> return -EINVAL;
>> + if (attr.alt_sample_period)
>> + return -EINVAL;
>> } else {
>> if (attr.sample_period & (1ULL << 63))
>> return -EINVAL;
>> + if (attr.alt_sample_period) {
>> + if (!attr.sample_period)
>> + return -EINVAL;
>> + if (attr.alt_sample_period & (1ULL << 63))
>> + return -EINVAL;
>> + if (attr.alt_sample_period == attr.sample_period)
>> + attr.alt_sample_period = 0;
>
> In theory, the attr.alt_sample_period should be less than
> attr.sample_period, right?
>
Added some validation for this.
Powered by blists - more mailing lists