mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: open list <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Kernel Team <Kernel-team@fb.com>,
	David Carrillo Cisneros <davidca@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 v7] perf: Sharing PMU counters across compatible events
Date: Tue, 19 Nov 2019 15:28:39 +0000	[thread overview]
Message-ID: <AB684919-5C5D-4228-BA78-54FE8F609D8E@fb.com> (raw)
In-Reply-To: <20191115235504.4034879-1-songliubraving@fb.com>

+ Alexander

On Nov 15, 2019, at 3:55 PM, Song Liu <songliubraving@fb.com> wrote:
> 
> This patch tries to enable PMU sharing. When multiple perf_events are
> counting the same metric, they can share the hardware PMU counter. We
> call these events as "compatible events".
> 
> The PMU sharing are limited to events within the same perf_event_context
> (ctx). When a event is installed or enabled, search the ctx for compatible
> events. This is implemented in perf_event_setup_dup(). One of these
> compatible events are picked as the master (stored in event->dup_master).
> Similarly, when the event is removed or disabled, perf_event_remove_dup()
> is used to clean up sharing.
> 
> A new state PERF_EVENT_STATE_ENABLED is introduced for the master event.
> This state is used when the slave event is ACTIVE, but the master event
> is not.
> 
> On the critical paths (add, del read), sharing PMU counters doesn't
> increase the complexity. Helper functions event_pmu_[add|del|read]() are
> introduced to cover these cases. All these functions have O(1) time
> complexity.
> 

[...]

> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index aec8dba2bea4..00b1e19e70fd 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -1657,6 +1657,139 @@ perf_event_groups_next(struct perf_event *event)
> 		event = rb_entry_safe(rb_next(&event->group_node),	\
> 				typeof(*event), group_node))
> 
> +static inline bool perf_event_can_share(struct perf_event *event)
> +{
> +	/* only share hardware counting events */
> +	return !is_software_event(event) && !is_sampling_event(event);
> +}
> +
> +/*
> + * Returns whether the two events can share a PMU counter.
> + *
> + * Note: This function does NOT check perf_event_can_share() for
> + * the two events, they should be checked before this function
> + */
> +static inline bool perf_event_compatible(struct perf_event *event_a,
> +					 struct perf_event *event_b)
> +{
> +	return event_a->attr.type == event_b->attr.type &&
> +		event_a->attr.config == event_b->attr.config &&
> +		event_a->attr.config1 == event_b->attr.config1 &&
> +		event_a->attr.config2 == event_b->attr.config2;

In a discussion on the IRC, Alexander highlighted that we need to 
compare event->hw.config as well (or something equivalent). I will 
fix this in the next version (will need cover a few different 
cases). 

Hi Peter, could you please share your feedback on this? Does the 
overall direction look right?

Thanks,
Song


  reply	other threads:[~2019-11-19 15:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-15 23:55 Song Liu
2019-11-19 15:28 ` Song Liu [this message]
2019-11-22 19:33 ` Jiri Olsa
2019-11-22 19:50   ` Song Liu
2019-11-25  9:22     ` Jiri Olsa
2019-11-25  9:39       ` Song Liu
2019-12-06  0:47     ` [perf] 9dc510db74: perf-sanity-tests.Read_samples_using_the_mmap_interface.fail kernel test robot
2019-11-28  8:30 ` [PATCH v7] perf: Sharing PMU counters across compatible events Jiri Olsa
2019-12-04 22:16   ` 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=AB684919-5C5D-4228-BA78-54FE8F609D8E@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexey.budankov@linux.intel.com \
    --cc=davidca@fb.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®