mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Ravi Bangoria <ravi.bangoria@amd.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Stephane Eranian <eranian@google.com>,
	Ian Rogers <irogers@google.com>,
	Mingwei Zhang <mizhang@google.com>
Subject: Re: [PATCH] perf/core: Optimize event reschedule for a PMU
Date: Tue, 30 Jul 2024 22:40:48 +0200	[thread overview]
Message-ID: <20240730204048.GU33588@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20240730191925.469649-1-namhyung@kernel.org>

On Tue, Jul 30, 2024 at 12:19:25PM -0700, Namhyung Kim wrote:
> @@ -2728,13 +2727,62 @@ static void ctx_resched(struct perf_cpu_context *cpuctx,
>  		perf_ctx_enable(task_ctx, false);
>  }
>  
> +static void __perf_pmu_resched(struct pmu *pmu,
> +			       struct perf_event_context *task_ctx,
> +			       enum event_type_t event_type)
> +{
> +	bool cpu_event = !!(event_type & EVENT_CPU);
> +	struct perf_event_pmu_context *epc = NULL;
> +	struct perf_cpu_pmu_context *cpc = this_cpu_ptr(pmu->cpu_pmu_context);
> +
> +	/*
> +	 * If pinned groups are involved, flexible groups also need to be
> +	 * scheduled out.
> +	 */
> +	if (event_type & EVENT_PINNED)
> +		event_type |= EVENT_FLEXIBLE;
> +
> +	event_type &= EVENT_ALL;
> +
> +	perf_pmu_disable(pmu);
> +	if (task_ctx) {
> +		if (WARN_ON_ONCE(!cpc->task_epc || cpc->task_epc->ctx != task_ctx))
> +			goto out;
> +
> +		epc = cpc->task_epc;
> +		__pmu_ctx_sched_out(epc, event_type);
> +	}
> +
> +	/*
> +	 * Decide which cpu ctx groups to schedule out based on the types
> +	 * of events that caused rescheduling:
> +	 *  - EVENT_CPU: schedule out corresponding groups;
> +	 *  - EVENT_PINNED task events: schedule out EVENT_FLEXIBLE groups;
> +	 *  - otherwise, do nothing more.
> +	 */
> +	if (cpu_event)
> +		__pmu_ctx_sched_out(&cpc->epc, event_type);
> +	else if (event_type & EVENT_PINNED)
> +		__pmu_ctx_sched_out(&cpc->epc, EVENT_FLEXIBLE);
> +
> +	__pmu_ctx_sched_in(&cpc->epc, EVENT_PINNED);
> +	if (task_ctx)
> +		 __pmu_ctx_sched_in(epc, EVENT_PINNED);
> +	__pmu_ctx_sched_in(&cpc->epc, EVENT_FLEXIBLE);
> +	if (task_ctx)
> +		 __pmu_ctx_sched_in(epc, EVENT_FLEXIBLE);
> +
> +out:
> +	perf_pmu_enable(pmu);
> +}

I so dislike duplication...

So lets see, ctx_resched() has pmu_ctx iterations in:

  perf_ctx_{en,dis}able()
  ctx_sched_{in,out}()

Can't we punch a 'struct pmu *pmu' argument through those callchains and
short-circuit the iteration when !NULL?

The alternative would be to lift the iteration I suppose.

  reply	other threads:[~2024-07-30 20:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-30 19:19 Namhyung Kim
2024-07-30 20:40 ` Peter Zijlstra [this message]
2024-07-30 21:18   ` Namhyung Kim
2024-08-05 16:57 ` Mingwei Zhang
2024-08-06  6:25   ` Namhyung Kim

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=20240730204048.GU33588@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=mizhang@google.com \
    --cc=namhyung@kernel.org \
    --cc=ravi.bangoria@amd.com \
    /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

all inboxes | Powered by JetHome®