mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: open list <linux-kernel@vger.kernel.org>,
	Kernel Team <Kernel-team@fb.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Alexey Budankov <alexey.budankov@linux.intel.com>,
	Namhyung Kim <namhyung@kernel.org>, Tejun Heo <tj@kernel.org>
Subject: Re: [PATCH v8] perf: Sharing PMU counters across compatible events
Date: Thu, 12 Dec 2019 16:00:24 +0000	[thread overview]
Message-ID: <E8B60E4B-AC39-4D53-9B37-08A7D4903CE2@fb.com> (raw)
In-Reply-To: <990C21F3-A93B-414A-9DB7-C17AADF037C7@fb.com>



> On Dec 12, 2019, at 7:45 AM, Song Liu <songliubraving@fb.com> wrote:
> 
> 
> 
>> On Dec 12, 2019, at 7:39 AM, Peter Zijlstra <peterz@infradead.org> wrote:
>> 
>> On Fri, Dec 06, 2019 at 04:24:47PM -0800, Song Liu wrote:
>> 
>>> @@ -2174,6 +2410,14 @@ __perf_remove_from_context(struct perf_event *event,
>>> 		update_cgrp_time_from_cpuctx(cpuctx);
>>> 	}
>>> 
>>> +	if (event->dup_master == event) {
>>> +		if (ctx->is_active)
>>> +			ctx_resched(cpuctx, cpuctx->task_ctx,
>>> +				    get_event_type(event), NULL, event);
>>> +		else
>>> +			perf_event_remove_dup(event, ctx);
>>> +	}
>>> +
>>> 	event_sched_out(event, cpuctx, ctx);
>>> 	if (flags & DETACH_GROUP)
>>> 		perf_group_detach(event);
>>> @@ -2241,6 +2485,14 @@ static void __perf_event_disable(struct perf_event *event,
>>> 		update_cgrp_time_from_event(event);
>>> 	}
>>> 
>>> +	if (event->dup_master == event) {
>>> +		if (ctx->is_active)
>>> +			ctx_resched(cpuctx, cpuctx->task_ctx,
>>> +				    get_event_type(event), NULL, event);
>>> +		else
>>> +			perf_event_remove_dup(event, ctx);
>>> +	}
>>> +
>>> 	if (event == event->group_leader)
>>> 		group_sched_out(event, cpuctx, ctx);
>>> 	else
>> 
>>> @@ -2544,7 +2793,9 @@ static void perf_event_sched_in(struct perf_cpu_context *cpuctx,
>>> */
>>> static void ctx_resched(struct perf_cpu_context *cpuctx,
>>> 			struct perf_event_context *task_ctx,
>>> -			enum event_type_t event_type)
>>> +			enum event_type_t event_type,
>>> +			struct perf_event *event_add_dup,
>>> +			struct perf_event *event_del_dup)
>>> {
>>> 	enum event_type_t ctx_event_type;
>>> 	bool cpu_event = !!(event_type & EVENT_CPU);
>>> @@ -2574,6 +2825,18 @@ static void ctx_resched(struct perf_cpu_context *cpuctx,
>>> 	else if (ctx_event_type & EVENT_PINNED)
>>> 		cpu_ctx_sched_out(cpuctx, EVENT_FLEXIBLE);
>>> 
>>> +	if (event_add_dup) {
>>> +		if (event_add_dup->ctx->is_active)
>>> +			ctx_sched_out(event_add_dup->ctx, cpuctx, EVENT_ALL);
>>> +		perf_event_setup_dup(event_add_dup, event_add_dup->ctx);
>>> +	}
>>> +
>>> +	if (event_del_dup) {
>>> +		if (event_del_dup->ctx->is_active)
>>> +			ctx_sched_out(event_del_dup->ctx, cpuctx, EVENT_ALL);
>>> +		perf_event_remove_dup(event_del_dup, event_del_dup->ctx);
>>> +	}
>>> +
>>> 	perf_event_sched_in(cpuctx, task_ctx, current);
>>> 	perf_pmu_enable(cpuctx->ctx.pmu);
>>> }
>> 
>> Yuck!
>> 
>> Why do you do a full reschedule when you take out a master?
> 
> If there is active slave using this master, we need to schedule out
> them before removing the master. 
> 
> We can improve the check though. We only need to do it if the master
> is in state PERF_EVENT_STATE_ENABLED. 
> 
> Or we can add a different function to only schedule out slaves. 

It is tricky to only schedule out slaves, because the slave could be in
a group. If we don't reschedule all events, we need to make sure that
"swapping master" always succeed. 

Song

  reply	other threads:[~2019-12-12 16:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-07  0:24 Song Liu
2019-12-11 18:50 ` Song Liu
2019-12-12 13:42 ` Peter Zijlstra
2019-12-12 15:18   ` Song Liu
2019-12-12 13:49 ` Peter Zijlstra
2019-12-12 15:37   ` Song Liu
2019-12-12 15:44     ` Peter Zijlstra
2019-12-12 15:47       ` Song Liu
2019-12-12 15:39 ` Peter Zijlstra
2019-12-12 15:45   ` Song Liu
2019-12-12 16:00     ` Song Liu [this message]
2019-12-12 18:01       ` Song Liu
2019-12-12 18:52     ` Peter Zijlstra
2019-12-12 23:49       ` Song Liu

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=E8B60E4B-AC39-4D53-9B37-08A7D4903CE2@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=acme@redhat.com \
    --cc=alexey.budankov@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tj@kernel.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

all inboxes | Powered by JetHome®