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 15:37:05 +0000	[thread overview]
Message-ID: <5D5BC3C8-427D-4983-AAEB-0E8001751BA0@fb.com> (raw)
In-Reply-To: <20191212134951.GX2844@hirez.programming.kicks-ass.net>



> On Dec 12, 2019, at 5:49 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> 
> On Fri, Dec 06, 2019 at 04:24:47PM -0800, Song Liu wrote:
> 
>> @@ -750,6 +752,16 @@ struct perf_event {
>> 	void *security;
>> #endif
>> 	struct list_head		sb_list;
>> +
>> +	/* for PMU sharing */
>> +	struct perf_event		*dup_master;
>> +	/* check event_sync_dup_count() for the use of dup_base_* */
>> +	u64				dup_base_count;
>> +	u64				dup_base_child_count;
>> +	/* when this event is master,  read from master*count */
>> +	local64_t			master_count;
>> +	atomic64_t			master_child_count;
>> +	int				dup_active_count;
>> #endif /* CONFIG_PERF_EVENTS */
>> };
> 
>> +/* PMU sharing aware version of event->pmu->add() */
>> +static int event_pmu_add(struct perf_event *event,
>> +			 struct perf_event_context *ctx)
>> +{
>> +	struct perf_event *master;
>> +	int ret;
>> +
>> +	/* no sharing, just do event->pmu->add() */
>> +	if (!event->dup_master)
>> +		return event->pmu->add(event, PERF_EF_START);
> 
> Possibly we should look at the location of perf_event::dup_master to be
> in a hot cacheline. Because I'm thinking you just added a guaranteed
> miss here.

I am not quite sure the best location for these. How about:

diff --git i/include/linux/perf_event.h w/include/linux/perf_event.h
index 7d49f9251621..218cc7f75775 100644
--- i/include/linux/perf_event.h
+++ w/include/linux/perf_event.h
@@ -643,6 +643,16 @@ struct perf_event {
        local64_t                       count;
        atomic64_t                      child_count;

+       /* for PMU sharing */
+       struct perf_event               *dup_master;
+       /* check event_sync_dup_count() for the use of dup_base_* */
+       u64                             dup_base_count;
+       u64                             dup_base_child_count;
+       /* when this event is master,  read from master*count */
+       local64_t                       master_count;
+       atomic64_t                      master_child_count;
+       int                             dup_active_count;
+
        /*
         * These are the total time in nanoseconds that the event
         * has been enabled (i.e. eligible to run, and the task has

?

> 
>> +
>> +	master = event->dup_master;
>> +
>> +	if (!master->dup_active_count) {
>> +		ret = event->pmu->add(master, PERF_EF_START);
>> +		if (ret)
>> +			return ret;
>> +
>> +		if (master != event)
>> +			perf_event_set_state(master, PERF_EVENT_STATE_ENABLED);
>> +	}
>> +
>> +	master->dup_active_count++;
>> +	master->pmu->read(master);
>> +	event->dup_base_count = local64_read(&master->count);
>> +	event->dup_base_child_count = atomic64_read(&master->child_count);
>> +	return 0;
>> +}
> 
>> +/* PMU sharing aware version of event->pmu->del() */
>> +static void event_pmu_del(struct perf_event *event,
>> +			  struct perf_event_context *ctx)
>> +{
>> +	struct perf_event *master;
>> +
>> +	if (event->dup_master == NULL) {
>> +		event->pmu->del(event, 0);
>> +		return;
>> +	}
> 
> How about you write it exactly like the add version:
> 
> 	if (!event->dup_master)
> 		return event->pmu->del(event, 0);
> 
> ?

Sure, will fix in v9. 

Thanks,
Song
> 
>> +
>> +	master = event->dup_master;
>> +	event_sync_dup_count(event, master);
>> +	if (--master->dup_active_count == 0) {
>> +		event->pmu->del(master, 0);
>> +		perf_event_set_state(master, PERF_EVENT_STATE_INACTIVE);
>> +	} else if (master == event) {
>> +		perf_event_set_state(master, PERF_EVENT_STATE_ENABLED);
>> +	}
>> +}
>> +
>> +/* PMU sharing aware version of event->pmu->read() */
>> +static void event_pmu_read(struct perf_event *event)
>> +{
>> +	if (event->dup_master == NULL) {
>> +		event->pmu->read(event);
>> +		return;
>> +	}
> 
> And here too.
> 
>> +	event_sync_dup_count(event, event->dup_master);
>> +}


  reply	other threads:[~2019-12-12 15:37 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 [this message]
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
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=5D5BC3C8-427D-4983-AAEB-0E8001751BA0@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®