public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Michael Ellerman <mpe@ellerman.id.au>,
	linuxppc-dev@lists.ozlabs.org, Anjali K <anjalik@linux.ibm.com>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Kan Liang <kan.liang@linux.intel.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Naveen N Rao <naveen@kernel.org>,
	Nicholas Piggin <npiggin@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Julia Lawall <julia.lawall@inria.fr>
Subject: Re: [PATCH] powerpc/perf: Use guard(irqsave)() in eight functions
Date: Fri, 20 Sep 2024 08:52:38 +0200	[thread overview]
Message-ID: <db53c8d1-2eef-48c9-9580-ba31bfb03e1f@web.de> (raw)
In-Reply-To: <871q1eoqya.fsf@mail.lhotse>

>> Scope-based resource management became supported for some
>> programming interfaces by contributions of Peter Zijlstra on 2023-05-26.
>> See also the commit 54da6a0924311c7cf5015533991e44fb8eb12773 ("locking:
>> Introduce __cleanup() based infrastructure").
>>
>> * Thus replace local_irq_save() and local_irq_restore() calls by calls
>>   of the macro “guard(irqsave)”.
>> ---
>>  arch/powerpc/perf/core-book3s.c | 102 +++++++++++++-------------------
>>  1 file changed, 42 insertions(+), 60 deletions(-)
>
> These mostly look good.

Thanks for this positive feedback.


> I don't think the change to power_pmu_event_init() is an improvement.

I presented an other development opinion.


> I'll drop that hunk when applying,

I guess that there are further opportunities to clarify remaining change resistance.


> or you can send a v2 without that change if you prefer.

Not yet.

…
>> @@ -1996,7 +1980,7 @@ static bool is_event_blacklisted(u64 ev)
>>  static int power_pmu_event_init(struct perf_event *event)
>>  {
>>  	u64 ev;
>> -	unsigned long flags, irq_flags;
>> +	unsigned long flags;
>>  	struct perf_event *ctrs[MAX_HWEVENTS];
>>  	u64 events[MAX_HWEVENTS];
>>  	unsigned int cflags[MAX_HWEVENTS];
>> @@ -2115,43 +2099,41 @@ static int power_pmu_event_init(struct perf_event *event)
>>  	if (check_excludes(ctrs, cflags, n, 1))
>>  		return -EINVAL;
>>
>> -	local_irq_save(irq_flags);
>> -	cpuhw = this_cpu_ptr(&cpu_hw_events);
>> +	{
>> +		guard(irqsave)();
>> +		cpuhw = this_cpu_ptr(&cpu_hw_events);
>>
>> -	err = power_check_constraints(cpuhw, events, cflags, n + 1, ctrs);
>> +		err = power_check_constraints(cpuhw, events, cflags, n + 1, ctrs);
>>
>> -	if (has_branch_stack(event)) {
>> -		u64 bhrb_filter = -1;
>> +		if (has_branch_stack(event)) {
>> +			u64 bhrb_filter = -1;
>>
>> -		/*
>> -		 * Currently no PMU supports having multiple branch filters
>> -		 * at the same time. Branch filters are set via MMCRA IFM[32:33]
>> -		 * bits for Power8 and above. Return EOPNOTSUPP when multiple
>> -		 * branch filters are requested in the event attr.
>> -		 *
>> -		 * When opening event via perf_event_open(), branch_sample_type
>> -		 * gets adjusted in perf_copy_attr(). Kernel will automatically
>> -		 * adjust the branch_sample_type based on the event modifier
>> -		 * settings to include PERF_SAMPLE_BRANCH_PLM_ALL. Hence drop
>> -		 * the check for PERF_SAMPLE_BRANCH_PLM_ALL.
>> -		 */
>> -		if (hweight64(event->attr.branch_sample_type & ~PERF_SAMPLE_BRANCH_PLM_ALL) > 1) {
>> -			local_irq_restore(irq_flags);
>> -			return -EOPNOTSUPP;
>> -		}
>> +			/*
>> +			 * Currently no PMU supports having multiple branch filters
>> +			 * at the same time. Branch filters are set via MMCRA IFM[32:33]
>> +			 * bits for Power8 and above. Return EOPNOTSUPP when multiple
>> +			 * branch filters are requested in the event attr.
>> +			 *
>> +			 * When opening event via perf_event_open(), branch_sample_type
>> +			 * gets adjusted in perf_copy_attr(). Kernel will automatically
>> +			 * adjust the branch_sample_type based on the event modifier
>> +			 * settings to include PERF_SAMPLE_BRANCH_PLM_ALL. Hence drop
>> +			 * the check for PERF_SAMPLE_BRANCH_PLM_ALL.
>> +			 */
>> +			if (hweight64(event->attr.branch_sample_type & ~PERF_SAMPLE_BRANCH_PLM_ALL)
>> +			    > 1)
>> +				return -EOPNOTSUPP;
>>
>> -		if (ppmu->bhrb_filter_map)
>> -			bhrb_filter = ppmu->bhrb_filter_map(
>> -					event->attr.branch_sample_type);
>> +			if (ppmu->bhrb_filter_map)
>> +				bhrb_filter = ppmu->bhrb_filter_map(event->attr.branch_sample_type);
>>
>> -		if (bhrb_filter == -1) {
>> -			local_irq_restore(irq_flags);
>> -			return -EOPNOTSUPP;
>> +			if (bhrb_filter == -1)
>> +				return -EOPNOTSUPP;
>> +
>> +			cpuhw->bhrb_filter = bhrb_filter;
>>  		}
>> -		cpuhw->bhrb_filter = bhrb_filter;
>>  	}
>>
>> -	local_irq_restore(irq_flags);
>>  	if (err)
>>  		return -EINVAL;
>>
>> --
>> 2.46.0

* Under which circumstances would you find it acceptable to use
  the proposed compound statement?

* Would you eventually prefer to apply a macro like “scoped_guard” here?
  https://elixir.bootlin.com/linux/v6.11/source/include/linux/cleanup.h#L140


Regards,
Markus

      reply	other threads:[~2024-09-20  6:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-16 17:40 [PATCH] powerpc/perf: Use guard(irqsave)() in eight functions Markus Elfring
2024-09-20  5:05 ` Michael Ellerman
2024-09-20  6:52   ` Markus Elfring [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=db53c8d1-2eef-48c9-9580-ba31bfb03e1f@web.de \
    --to=markus.elfring@web.de \
    --cc=anjalik@linux.ibm.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=julia.lawall@inria.fr \
    --cc=kan.liang@linux.intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=naveen@kernel.org \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox