public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Song Liu <songliubraving@fb.com>
Cc: linux-kernel@vger.kernel.org, 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 14:42:31 +0100	[thread overview]
Message-ID: <20191212134231.GW2844@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20191207002447.2976319-1-songliubraving@fb.com>

On Fri, Dec 06, 2019 at 04:24:47PM -0800, Song Liu wrote:
> +/* Remove dup_master for the event */
> +static void perf_event_remove_dup(struct perf_event *event,
> +				  struct perf_event_context *ctx)
> +
> +{
> +	struct perf_event *tmp, *new_master;
> +	int count;
> +
> +	/* no sharing */
> +	if (!event->dup_master)
> +		return;
> +
> +	WARN_ON_ONCE(event->state != PERF_EVENT_STATE_INACTIVE &&
> +		     event->state != PERF_EVENT_STATE_OFF);
> +
> +	/* this event is not the master */
> +	if (event->dup_master != event) {
> +		event->dup_master = NULL;
> +		return;
> +	}
> +
> +	/* this event is the master */
> +	perf_event_exit_dup_master(event);
> +
> +	count = 0;
> +	new_master = NULL;
> +	list_for_each_entry(tmp, &ctx->event_list, event_entry) {
> +		WARN_ON_ONCE(tmp->state > PERF_EVENT_STATE_INACTIVE);
> +		if (tmp->dup_master == event) {
> +			count++;
> +			if (!new_master)
> +				new_master = tmp;
> +		}
> +	}
> +
> +	if (!count)
> +		return;
> +
> +	if (count == 1) {
> +		/* no more sharing */
> +		new_master->dup_master = NULL;
> +		return;
> +	}
> +
> +	perf_event_init_dup_master(new_master);
> +
> +	/* switch to new_master */
> +	list_for_each_entry(tmp, &ctx->event_list, event_entry)
> +		if (tmp->dup_master == event)
> +			tmp->dup_master = new_master;
> +}

I'm thinking you can do that in a single iteration:

	list_for_each_entry(tmp, &ctx->event_list, event_entry) {
		if (tmp->dup_master != event)
			continue;

		if (!new_master)
			new_master = tmp;

		tmp->dup_master = new_master;
		count++;
	}

	if (count == 1)
		new_master->dup_master = NULL;
	else
		perf_event_init_dup_master(new_master);

Hmm?

  parent reply	other threads:[~2019-12-12 13:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-07  0:24 [PATCH v8] perf: Sharing PMU counters across compatible events Song Liu
2019-12-11 18:50 ` Song Liu
2019-12-12 13:42 ` Peter Zijlstra [this message]
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
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=20191212134231.GW2844@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@redhat.com \
    --cc=alexey.budankov@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=songliubraving@fb.com \
    --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