public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Andy Lutomirski <luto@kernel.org>
Cc: Len Brown <len.brown@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: Re: [RFC] x86, perf: Add an aperfmperf driver
Date: Wed, 29 Apr 2015 11:09:41 +0200	[thread overview]
Message-ID: <20150429090941.GO5029@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <2c37309d20afadf88ad4a82cf0ce02b9152801e2.1430256154.git.luto@kernel.org>

On Tue, Apr 28, 2015 at 02:25:37PM -0700, Andy Lutomirski wrote:
> diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
> index 80091ae54c2b..fadc822efc90 100644
> --- a/arch/x86/kernel/cpu/Makefile
> +++ b/arch/x86/kernel/cpu/Makefile
> @@ -45,6 +45,8 @@ obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE)	+= perf_event_intel_uncore.o \
>  					   perf_event_intel_uncore_snb.o \
>  					   perf_event_intel_uncore_snbep.o \
>  					   perf_event_intel_uncore_nhmex.o
> +obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_aperf_mperf.o
> +obj-$(CONFIG_CPU_SUP_AMD)		+= perf_event_aperf_mperf.o

Does this actually work? I would expect it to go complain about having
to build it twice if you have both set.

> diff --git a/arch/x86/kernel/cpu/perf_event_aperfmperf.c b/arch/x86/kernel/cpu/perf_event_aperfmperf.c
> new file mode 100644
> index 000000000000..6e6d113bd9ce
> --- /dev/null
> +++ b/arch/x86/kernel/cpu/perf_event_aperfmperf.c
> @@ -0,0 +1,119 @@
> +#include <linux/perf_event.h>
> +
> +#define APERFMPERF_EVENT_APERF 0
> +#define APERFMPERF_EVENT_MPERF 1
> +

> +static int aperfmperf_event_init(struct perf_event *event)
> +{
> +	if (event->attr.type != event->pmu->type)
> +		return -ENOENT;
> +
> +	if (event->attr.config != APERFMPERF_EVENT_APERF &&
> +	    event->attr.config != APERFMPERF_EVENT_MPERF)
> +		return -ENOENT;

Once we pass the type test we know its 'our' event, and we can go return
fatal errors. No other PMU will pick this up.

This could therefore turn into an -EINVAL.

> +
> +	if (event->attr.config1 != 0)
> +		return -ENOENT;

Idem.

> +	/* no sampling */
> +	if (event->hw.sample_period)
> +		return -EINVAL;

You could have set pmu::capabilities =
PERF_PMU_CAP_NO_INTERRUPT which would also have killed that dead.

> +	/* unsupported modes and filters */
> +	if (event->attr.exclude_user   ||
> +	    event->attr.exclude_kernel ||
> +	    event->attr.exclude_hv     ||
> +	    event->attr.exclude_idle   ||
> +	    event->attr.exclude_host   ||
> +	    event->attr.exclude_guest  ||
> +	    event->attr.freq           ||
> +	    event->attr.sample_period) /* no sampling */
> +		return -EINVAL;
> +
> +	event->hw.idx = -1;
> +	event->hw.event_base = (event->attr.config == APERFMPERF_EVENT_APERF ?
> +				MSR_IA32_APERF : MSR_IA32_MPERF);
> +
> +	return 0;
> +}

The rest looks about right. Very simple thing indeed ;-)

  parent reply	other threads:[~2015-04-29  9:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-28 21:25 [RFC] x86, perf: Add an aperfmperf driver Andy Lutomirski
2015-04-28 22:29 ` Brown, Len
2015-04-28 22:43   ` Andy Lutomirski
2015-04-29  9:13     ` Peter Zijlstra
2015-04-29  9:09 ` Peter Zijlstra [this message]
2015-04-29 18:50   ` Andy Lutomirski
2015-04-30  1:17     ` Andy Lutomirski
2015-04-30  8:51       ` Peter Zijlstra
2015-04-30 22:09         ` Andy Lutomirski
2015-04-29  9:14 ` Peter Zijlstra
2015-05-11  9:48 ` Ingo Molnar

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=20150429090941.GO5029@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.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