From: Peter Zijlstra <peterz@infradead.org>
To: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: acme@kernel.org, alexander.shishkin@linux.intel.com,
jolsa@redhat.com, namhyung@kernel.org, songliubraving@fb.com,
eranian@google.com, alexey.budankov@linux.intel.com,
ak@linux.intel.com, mark.rutland@arm.com, megha.dey@intel.com,
frederic@kernel.org, maddy@linux.ibm.com, irogers@google.com,
kim.phillips@amd.com, linux-kernel@vger.kernel.org,
santosh.shukla@amd.com
Subject: Re: [RFC v2] perf: Rewrite core context handling
Date: Mon, 13 Jun 2022 16:41:28 +0200 [thread overview]
Message-ID: <YqdMmLqFS9cX4jRb@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <YqdLH+ZU/sf4n0pa@hirez.programming.kicks-ass.net>
On Mon, Jun 13, 2022 at 04:35:11PM +0200, Peter Zijlstra wrote:
> @@ -3196,11 +3187,52 @@ static int perf_event_modify_attr(struct
> return err;
> }
>
> -static void ctx_sched_out(struct perf_event_context *ctx,
> - struct perf_cpu_context *cpuctx,
> - enum event_type_t event_type)
> +static void __pmu_ctx_sched_out(struct perf_event_pmu_context *pmu_ctx,
> + enum event_type_t event_type)
> {
> + struct perf_event_context *ctx = pmu_ctx->ctx;
> struct perf_event *event, *tmp;
> + struct pmu *pmu = pmu_ctx->pmu;
> +
> + if (ctx->task && !ctx->is_active) {
> + struct perf_cpu_pmu_context *cpc;
> +
> + cpc = this_cpu_ptr(pmu->cpu_pmu_context);
> + WARN_ON_ONCE(cpc->task_epc != pmu_ctx);
> + cpc->task_epc = NULL;
> + }
> +
> + if (!event_type)
> + return;
> +
> + perf_pmu_disable(pmu);
> + if (event_type & EVENT_PINNED) {
> + list_for_each_entry_safe(event, tmp,
> + &pmu_ctx->pinned_active,
> + active_list)
> + group_sched_out(event, ctx);
> + }
> +
> + if (event_type & EVENT_FLEXIBLE) {
> + list_for_each_entry_safe(event, tmp,
> + &pmu_ctx->flexible_active,
> + active_list)
> + group_sched_out(event, ctx);
> + /*
> + * Since we cleared EVENT_FLEXIBLE, also clear
> + * rotate_necessary, is will be reset by
> + * ctx_flexible_sched_in() when needed.
> + */
> + pmu_ctx->rotate_necessary = 0;
> + }
> + perf_pmu_enable(pmu);
> +}
> +
> +static void
> +ctx_sched_out(struct perf_event_context *ctx, enum event_type_t event_type)
> +{
> + struct perf_cpu_context *cpuctx = this_cpu_ptr(&cpu_context);
> + struct perf_event_pmu_context *pmu_ctx;
> int is_active = ctx->is_active;
>
> lockdep_assert_held(&ctx->lock);
> @@ -3251,24 +3283,8 @@ static void ctx_sched_out(struct perf_ev
> if (!ctx->nr_active || !(is_active & EVENT_ALL))
> return;
>
> - perf_pmu_disable(ctx->pmu);
> - if (is_active & EVENT_PINNED) {
> - list_for_each_entry_safe(event, tmp, &ctx->pinned_active, active_list)
> - group_sched_out(event, cpuctx, ctx);
> - }
> -
> - if (is_active & EVENT_FLEXIBLE) {
> - list_for_each_entry_safe(event, tmp, &ctx->flexible_active, active_list)
> - group_sched_out(event, cpuctx, ctx);
> -
> - /*
> - * Since we cleared EVENT_FLEXIBLE, also clear
> - * rotate_necessary, is will be reset by
> - * ctx_flexible_sched_in() when needed.
> - */
> - ctx->rotate_necessary = 0;
> - }
> - perf_pmu_enable(ctx->pmu);
> + list_for_each_entry(pmu_ctx, &ctx->pmu_ctx_list, pmu_ctx_entry)
> + __pmu_ctx_sched_out(pmu_ctx, is_active);
> }
You mentioned trouble with cpc->task_epc, there's one rebase mistake
from you and an original bug from me.
You lost the last hunk, I forgot to clear cpc on
perf_remove_from_context().
With these fixes I can run: 'perf test' without things going
insta-splat.
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2311,6 +2311,7 @@ __perf_remove_from_context(struct perf_e
struct perf_event_context *ctx,
void *info)
{
+ struct perf_event_pmu_context *pmu_ctx = event->pmu_ctx;
unsigned long flags = (unsigned long)info;
if (ctx->is_active & EVENT_TIME) {
@@ -2325,8 +2326,17 @@ __perf_remove_from_context(struct perf_e
perf_child_detach(event);
list_del_event(event, ctx);
- if (!event->pmu_ctx->nr_events)
- event->pmu_ctx->rotate_necessary = 0;
+ if (!pmu_ctx->nr_events) {
+ pmu_ctx->rotate_necessary = 0;
+
+ if (ctx->task) {
+ struct perf_cpu_pmu_context *cpc;
+
+ cpc = this_cpu_ptr(pmu_ctx->pmu->cpu_pmu_context);
+ WARN_ON_ONCE(cpc->task_epc && cpc->task_epc != pmu_ctx);
+ cpc->task_epc = NULL;
+ }
+ }
if (!ctx->nr_events && ctx->is_active) {
if (ctx == &cpuctx->ctx)
@@ -3198,7 +3208,7 @@ static void __pmu_ctx_sched_out(struct p
struct perf_cpu_pmu_context *cpc;
cpc = this_cpu_ptr(pmu->cpu_pmu_context);
- WARN_ON_ONCE(cpc->task_epc != pmu_ctx);
+ WARN_ON_ONCE(cpc->task_epc && cpc->task_epc != pmu_ctx);
cpc->task_epc = NULL;
}
@@ -3280,9 +3290,6 @@ ctx_sched_out(struct perf_event_context
is_active ^= ctx->is_active; /* changed bits */
- if (!ctx->nr_active || !(is_active & EVENT_ALL))
- return;
-
list_for_each_entry(pmu_ctx, &ctx->pmu_ctx_list, pmu_ctx_entry)
__pmu_ctx_sched_out(pmu_ctx, is_active);
}
next prev parent reply other threads:[~2022-06-13 18:27 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-13 13:47 [RFC v2] perf: Rewrite core context handling Ravi Bangoria
2022-01-17 7:18 ` [perf] f7cf7134e4: WARNING:at_kernel/events/core.c:#__pmu_ctx_sched_out kernel test robot
2022-01-31 4:43 ` [RFC v2] perf: Rewrite core context handling Ravi Bangoria
2022-06-13 14:35 ` Peter Zijlstra
2022-06-13 14:36 ` Peter Zijlstra
2022-06-13 14:38 ` Peter Zijlstra
2022-08-02 6:11 ` Ravi Bangoria
2022-08-22 15:29 ` Peter Zijlstra
2022-08-22 15:43 ` Peter Zijlstra
2022-08-22 16:37 ` Ravi Bangoria
2022-08-23 4:20 ` Ravi Bangoria
2022-08-29 3:54 ` Ravi Bangoria
2022-08-23 6:30 ` Peter Zijlstra
2022-08-29 4:00 ` Ravi Bangoria
2022-08-29 11:58 ` Peter Zijlstra
2022-08-22 16:52 ` Peter Zijlstra
2022-08-23 4:57 ` Ravi Bangoria
2022-06-13 14:41 ` Peter Zijlstra [this message]
2022-08-22 14:38 ` Ravi Bangoria
2022-06-13 14:43 ` Peter Zijlstra
2022-08-02 6:16 ` Ravi Bangoria
2022-08-23 8:57 ` Peter Zijlstra
2022-08-24 5:07 ` Ravi Bangoria
2022-08-24 7:27 ` Peter Zijlstra
2022-08-24 7:53 ` Ravi Bangoria
2022-06-13 14:55 ` Peter Zijlstra
2022-08-02 6:10 ` Ravi Bangoria
2022-08-22 16:44 ` Peter Zijlstra
2022-08-23 4:46 ` Ravi Bangoria
2022-06-17 13:36 ` Peter Zijlstra
2022-08-24 10:13 ` Peter Zijlstra
2022-06-27 4:18 ` Ravi Bangoria
2022-08-02 6:06 ` Ravi Bangoria
2022-08-24 12:15 ` Peter Zijlstra
2022-08-24 14:59 ` Peter Zijlstra
2022-08-25 5:39 ` Ravi Bangoria
2022-08-25 9:17 ` Peter Zijlstra
2022-08-25 11:03 ` Ravi Bangoria
2022-08-02 6:13 ` Ravi Bangoria
2022-08-23 7:10 ` Peter Zijlstra
2022-08-02 6:17 ` Ravi Bangoria
2022-08-23 7:26 ` Peter Zijlstra
2022-08-23 15:14 ` Ravi Bangoria
2022-08-22 14:40 ` Ravi Bangoria
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=YqdMmLqFS9cX4jRb@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexey.budankov@linux.intel.com \
--cc=eranian@google.com \
--cc=frederic@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=kim.phillips@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maddy@linux.ibm.com \
--cc=mark.rutland@arm.com \
--cc=megha.dey@intel.com \
--cc=namhyung@kernel.org \
--cc=ravi.bangoria@amd.com \
--cc=santosh.shukla@amd.com \
--cc=songliubraving@fb.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