perf: Intel uncore pmu counting support
Subsystems (2)
cover perf: Intel uncore pmu counting support
Hi, all
I posted uncore patches months ago, but it was pended due to an uncore interrupt problem.
This series are cut to support uncore pmu counting only. So uncore interrupt handling is not needed.
The uncore pmu type is allocated dynamically and exported via sysfs.
$ cat /sys/bus/event_source/devices/uncore/type 6
You can count uncore raw events as below,
$ perf stat -e uncore:r0101 ls
It reads uncore pmu type id from sysfs to setup perf_event_attr::type.
Comments are appreciated.
Thanks,
Lin Ming
PATCH 4/4 perf tool: Get PMU type id from sysfs
PMU type id can be allocated dynamically, for example
$ perf stat -e uncore:r0101 ls
$ cat /sys/bus/event_source/devices/uncore/type 6
Uncore pmu type is read from sysfs and set into attr->type.
--- tools/perf/util/parse-events.c | 55 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 53 insertions(+), 2 deletions(-)
tools/perf/util/parse-events.c +53 -2
@@ -684,7 +684,7 @@ parse_symbolic_event(const char **strp, struct perf_event_attr *attr) }static enum event_result -parse_raw_event (const char **strp,struct perf_event_attr *attr) +parse_raw_config (const char **strp,struct perf_event_attr *attr) {const char *str = *strp;u64 config;
@@ -695,7 +695,6 @@ parse_raw_event(const char **strp, struct perf_event_attr *attr) n =hex2u64 (str +1 , &config);if (n >0 ) { *strp = str + n +1 ; - attr->type =PERF_TYPE_RAW ; attr->config = config;return EVT_HANDLED ; }
@@ -703,6 +702,54 @@ parse_raw_event(const char **strp, struct perf_event_attr *attr) }static enum event_result +parse_raw_event (const char **strp,struct perf_event_attr *attr) +{ +if (parse_raw_config (strp, attr) !=EVT_HANDLED ) +return EVT_FAILED ; + + attr->type =PERF_TYPE_RAW ; +return EVT_HANDLED ; +} + +#define EVENT_SOURCE_DIR "/sys/bus/event_source/devices" + +static enum event_result +parse_sysfs_event (const char **strp,struct perf_event_attr *attr) +{ +char *pmu_name; +char evt_path[MAXPATHLEN ]; +char type_buf[4 ]; +u64 type; +int fd; + + pmu_name =strchr (*strp,':' ); +if (!pmu_name) +return EVT_FAILED ; + + pmu_name =strndup (*strp, pmu_name - *strp); + +snprintf (evt_path,MAXPATHLEN ,"%s/%s/type" ,EVENT_SOURCE_DIR , + pmu_name); + + fd =open (evt_path,O_RDONLY ); +if (fd <0 ) +return EVT_FAILED ; + +if (read (fd, type_buf,sizeof (type_buf)) <0 ) { +close (fd); +return EVT_FAILED ; + } + +close (fd); + type =atoll (type_buf); + attr->type = type; + *strp +=strlen (pmu_name) +1 ;/* + 1 for the ':' */ +free (pmu_name); + +return parse_raw_config (strp, attr); +} + +static enum event_result parse_numeric_event (const char **strp,struct perf_event_attr *attr) {const char *str = *strp;
@@ -783,6 +830,10 @@ parse_event_symbols(const struct option *opt, const char **str, {enum event_result ret; + ret =parse_sysfs_event (str, attr); +if (ret !=EVT_FAILED ) + goto modifier; + ret =parse_tracepoint_event (opt, str, attr);if (ret !=EVT_FAILED ) goto modifier;
Signature · 1 line
1.7.5.1
PATCH 2/4 perf, x86: Add Intel SandyBridge uncore pmu
In reply to Lin MingAdd Intel SandyBridge uncore pmu support.
--- arch/x86/kernel/cpu/perf_event_intel_uncore.c | 49 +++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_intel_uncore.h | 40 ++++++++++++++++++++ 2 files changed, 89 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/perf_event_intel_uncore.c +49 -0
@@ -57,6 +57,51 @@ static __initconst const struct intel_uncore_pmu nhm_uncore_pmu = { .cntval_bits = 48, }; +/* SandyBridge uncore pmu */ + +static struct uncore_config { +unsigned long config_base; +unsigned long event_base; +} snb_uncore_configs[SNB_UNCORE_NUM_COUNTERS ] = { + {SNB_MSR_UNC_CBO_0_PERFEVTSEL0 ,SNB_MSR_UNC_CBO_0_PER_CTR0 }, + {SNB_MSR_UNC_CBO_0_PERFEVTSEL1 ,SNB_MSR_UNC_CBO_0_PER_CTR1 }, + {SNB_MSR_UNC_CBO_1_PERFEVTSEL0 ,SNB_MSR_UNC_CBO_1_PER_CTR0 }, + {SNB_MSR_UNC_CBO_1_PERFEVTSEL1 ,SNB_MSR_UNC_CBO_1_PER_CTR1 }, + {SNB_MSR_UNC_CBO_2_PERFEVTSEL0 ,SNB_MSR_UNC_CBO_2_PER_CTR0 }, + {SNB_MSR_UNC_CBO_2_PERFEVTSEL1 ,SNB_MSR_UNC_CBO_2_PER_CTR1 }, + {SNB_MSR_UNC_CBO_3_PERFEVTSEL0 ,SNB_MSR_UNC_CBO_3_PER_CTR0 }, + {SNB_MSR_UNC_CBO_3_PERFEVTSEL1 ,SNB_MSR_UNC_CBO_3_PER_CTR1 }, +}; + +static void snb_uncore_pmu_enable_all (void ) +{ +wrmsrl (SNB_MSR_UNCORE_PERF_GLOBAL_CTRL , +SNB_MSR_UNCORE_PERF_GLOBAL_CTRL_EN ); +} + +static int snb_uncore_pmu_hw_config (struct perf_event *event) +{ +struct hw_perf_event *hwc = &event->hw; +int i = hwc->idx; + + hwc->config = event->attr.config &SNB_UNCORE_RAW_EVENT_MASK ; + hwc->config_base = snb_uncore_configs[i].config_base; + hwc->event_base = snb_uncore_configs[i].event_base; + +return 0 ; +} + +static __initconst const struct intel_uncore_pmu snb_uncore_pmu = { + .name ="SandyBridge" , + .disable_all = nhm_uncore_pmu_disable_all, + .enable_all = snb_uncore_pmu_enable_all, + .enable = nhm_uncore_pmu_enable_event, + .disable = nhm_uncore_pmu_disable_event, + .hw_config = snb_uncore_pmu_hw_config, + .num_counters =8 , + .cntval_bits =48 , +}; +static u64 uncore_perf_event_update (struct perf_event *event) {struct hw_perf_event *hwc = &event->hw;
@@ -337,6 +382,10 @@ static int __init uncore_pmu_init(void) intel_uncore_pmu = nhm_uncore_pmu;break ; +case 42 :/* SandyBridge */ + intel_uncore_pmu = snb_uncore_pmu; +break ; +default :return 0 ; }
arch/x86/kernel/cpu/perf_event_intel_uncore.h +40 -0
@@ -23,6 +23,46 @@ NHM_UNCORE_EVENTSEL_INV | \ NHM_UNCORE_EVENTSEL_CMASK) +/* SandyBridge uncore MSR */ + +#define SNB_MSR_UNC_CBO_0_PERFEVTSEL0 0x700 +#define SNB_MSR_UNC_CBO_0_PERFEVTSEL1 0x701 +#define SNB_MSR_UNC_CBO_0_UNIT_STATUS 0x705 +#define SNB_MSR_UNC_CBO_0_PER_CTR0 0x706 +#define SNB_MSR_UNC_CBO_0_PER_CTR1 0x707 + +#define SNB_MSR_UNC_CBO_1_PERFEVTSEL0 0x710 +#define SNB_MSR_UNC_CBO_1_PERFEVTSEL1 0x711 +#define SNB_MSR_UNC_CBO_1_UNIT_STATUS 0x715 +#define SNB_MSR_UNC_CBO_1_PER_CTR0 0x716 +#define SNB_MSR_UNC_CBO_1_PER_CTR1 0x717 + +#define SNB_MSR_UNC_CBO_2_PERFEVTSEL0 0x720 +#define SNB_MSR_UNC_CBO_2_PERFEVTSEL1 0x721 +#define SNB_MSR_UNC_CBO_2_UNIT_STATUS 0x725 +#define SNB_MSR_UNC_CBO_2_PER_CTR0 0x726 +#define SNB_MSR_UNC_CBO_2_PER_CTR1 0x727 + +#define SNB_MSR_UNC_CBO_3_PERFEVTSEL0 0x730 +#define SNB_MSR_UNC_CBO_3_PERFEVTSEL1 0x731 +#define SNB_MSR_UNC_CBO_3_UNIT_STATUS 0x735 +#define SNB_MSR_UNC_CBO_3_PER_CTR0 0x736 +#define SNB_MSR_UNC_CBO_3_PER_CTR1 0x737 + +#define SNB_MSR_UNCORE_PERF_GLOBAL_CTRL 0x391 +#define SNB_MSR_UNCORE_PERF_GLOBAL_CTRL_EN (1ULL << 29) + +#define SNB_UNCORE_EVENTSEL_CMASK 0x1F000000ULL + +#define SNB_UNCORE_RAW_EVENT_MASK \ + (NHM_UNCORE_EVENTSEL_EVENT | \ + NHM_UNCORE_EVENTSEL_UMASK | \ + NHM_UNCORE_EVENTSEL_EDGE | \ + NHM_UNCORE_EVENTSEL_INV | \ + SNB_UNCORE_EVENTSEL_CMASK) + +#define SNB_UNCORE_NUM_COUNTERS 8 +struct intel_uncore {int id;/* uncore id */ int refcnt;/* reference count */
Signature · 1 line
1.7.5.1
PATCH 3/4 perf: Remove perf_event_attr::type check
In reply to Lin MingPMU type id can be allocated dynamically, so perf_event_attr::type check when copying attribute from userspace to kernel is not valid.
--- kernel/events/core.c | 7 ------- 1 files changed, 0 insertions(+), 7 deletions(-)
kernel/events/core.c +0 -7
@@ -5892,13 +5892,6 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,if (ret)return -EFAULT ; -/* -* If the type exists, the corresponding creation will verify -* the attr->config. -*/ -if (attr->type >=PERF_TYPE_MAX ) -return -EINVAL ; -if (attr->__reserved_1)return -EINVAL ;
Signature · 1 line
1.7.5.1
PATCH 1/4 perf, x86: Add Intel Nehalem/Westmere uncore pmu
In reply to Lin MingAdd Intel Nehalem/Westmere uncore pmu support. And also the generic data structure to support uncore pmu.
--- arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/perf_event_intel_uncore.c | 351 +++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_intel_uncore.h | 48 ++++ 3 files changed, 400 insertions(+), 0 deletions(-) create mode 100644 arch/x86/kernel/cpu/perf_event_intel_uncore.c create mode 100644 arch/x86/kernel/cpu/perf_event_intel_uncore.h
arch/x86/kernel/cpu/Makefile +1 -0
@@ -27,6 +27,7 @@ obj-$(CONFIG_CPU_SUP_TRANSMETA_32) += transmeta.o obj-$(CONFIG_CPU_SUP_UMC_32) += umc.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o +obj-$(CONFIG_PERF_EVENTS) += perf_event_intel_uncore.o obj-$(CONFIG_X86_MCE) += mcheck/ obj-$(CONFIG_MTRR) += mtrr/
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +351 -0
351 lines not on this page · raw message
arch/x86/kernel/cpu/perf_event_intel_uncore.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.7.5.1
Quoted 8 lines · Lin Ming
Hi, all
I posted uncore patches months ago, but it was pended due to an uncore interrupt problem.
This series are cut to support uncore pmu counting only. So uncore interrupt handling is not needed.
You're making the assumption that when counting, you can never construct a measurement that will cause a counter to overflow the 39 bits. If not, then you need interrupt handling even when counting.
Quoted 15 lines
The uncore pmu type is allocated dynamically and exported via sysfs.
$ cat /sys/bus/event_source/devices/uncore/type 6You can count uncore raw events as below,
$ perf stat -e uncore:r0101 lsIt reads uncore pmu type id from sysfs to setup
perf_event_attr::type.Comments are appreciated.
Thanks,
Lin Ming
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
In reply to Lin MingQuoted 1 line · Lin Ming
+static struct pmu
uncore_pmu= {
.task_ctx_nr = perf_invalid_context,
Quoted 7 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +7
-0+ .event_init = uncore_pmu_event_init, + .add = uncore_pmu_add, + .del = uncore_pmu_del, + .start = uncore_pmu_start, + .stop = uncore_pmu_stop, + .read = uncore_pmu_read, +};
Quoted 7 lines · Stephane Eranian
Quoted 3 lines
This series are cut to support uncore pmu counting only. So uncore interrupt handling is not needed.
You're making the assumption that when counting, you can never construct a measurement that will cause a counter to overflow the 39 bits. If not, then you need interrupt handling even when counting.
Also, I'm missing the stuff that maps everything to one active cpu in the uncore mask. IIRC your previous postings had stuff like that.
Quoted 6 lines · Stephane Eranian
Quoted 5 lines · Lin Ming
Hi, all
I posted uncore patches months ago, but it was pended due to an uncore interrupt problem.
Quoted 7 lines
Quoted 3 lines
This series are cut to support uncore pmu counting only. So uncore interrupt handling is not needed.
You're making the assumption that when counting, you can never construct a measurement that will cause a counter to overflow the 39 bits. If not, then you need interrupt handling even when counting.
The actual counter width is 48. But wrmsrl() can only write the bottom 32 bits of a register. I think Intel fixed that only with SandyBridge (see Vol3b). Thus, the risk of 'silent' wrap around is much higher now as you have only 31 bits to play with.
But if I read your patch correctly, it seems you are avoiding wrmsrl() on the counter. Instead, you are reading it when you start (prev_count) and using that value to compute the delta on stop.
Am I understanding your workaround correctly?
Quoted 17 lines
Quoted 16 lines
The uncore pmu type is allocated dynamically and exported via sysfs.
$ cat /sys/bus/event_source/devices/uncore/type 6You can count uncore raw events as below,
$ perf stat -e uncore:r0101 lsIt reads uncore pmu type id from sysfs to setup
perf_event_attr::type.Comments are appreciated.
Thanks,
Lin Ming
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
In reply to Lin Mingarch/x86/kernel/cpu/perf_event_intel_uncore.c line 68
Quoted 9 lines · Lin Ming
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +9
-0+static u64 uncore_perf_event_update (struct perf_event *event) +{ +struct hw_perf_event *hwc = &event->hw; +int shift =64 - intel_uncore_pmu.cntval_bits; +u64 prev_raw_count, new_raw_count; +s64 delta; + +/* +* Careful: an NMI might modify the previous event value.
There are no NMIs without sampling, so at least the comment seems bogus. Perhaps the code could be a bit simplified now without atomics.
Quoted 11 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +11
-0+static int uncore_pmu_event_init (struct perf_event *event) +{ +struct hw_perf_event *hwc = &event->hw; + +if (!uncore_pmu_initialized) +return -ENOENT ; + +if (event->attr.type != uncore_pmu.type) +return -ENOENT ; + +/*
arch/x86/kernel/cpu/perf_event_intel_uncore.c line 120
Quoted 10 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +10
-0+* Uncore PMU does measure at all privilege level all the time. +* So it doesn't make sense to specify any exclude bits. +*/ +if (event->attr.exclude_user || event->attr.exclude_kernel + || event->attr.exclude_hv || event->attr.exclude_idle) +return -ENOENT ; + +/* Sampling not supported yet */ +if (hwc->sample_period) +return -EINVAL ;
Don't we need a "is root" check here? uncore counts everything, so it cannot be limited to a single process.
arch/x86/kernel/cpu/perf_event_intel_uncore.c line 251
Quoted 8 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +8
-0+static void uncore_pmu_cpu_starting (int cpu) +{ +struct cpu_uncore_events *cpuc = &per_cpu (cpu_uncore_events, cpu); +struct intel_uncore *uncore; +int i, uncore_id; + +if (boot_cpu_data.x86_max_cores <2 ) +return ;
Why that check? uncore counting should work on a single core system too.
I think you should remove all of those.
arch/x86/kernel/cpu/perf_event_intel_uncore.c line 256
Quoted 5 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +5
-0+ + uncore_id =topology_physical_package_id (cpu); +WARN_ON_ONCE (uncore_id ==BAD_APICID ); + +raw_spin_lock (&intel_uncore_lock);
Does this really need to be a raw spinlock?
arch/x86/kernel/cpu/perf_event_intel_uncore.h line 10
Quoted 3 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.h new file +3
-0+#define NHM_MSR_UNCORE_PERF_GLOBAL_CTRL 0x391 +#define NHM_MSR_UNCORE_PMC0 0x3b0 +#define NHM_MSR_UNCORE_PERFEVTSEL0 0x3c0
These should be in msr-index.h
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 2/4] perf, x86: Add Intel SandyBridge uncore pmu
In reply to Lin MingQuoted 11 lines · Lin Ming
arch/x86/kernel/cpu/perf_event_intel_uncore.c +11
-0+static struct uncore_config { +unsigned long config_base; +unsigned long event_base; +} snb_uncore_configs[SNB_UNCORE_NUM_COUNTERS ] = { + {SNB_MSR_UNC_CBO_0_PERFEVTSEL0 ,SNB_MSR_UNC_CBO_0_PER_CTR0 }, + {SNB_MSR_UNC_CBO_0_PERFEVTSEL1 ,SNB_MSR_UNC_CBO_0_PER_CTR1 }, + {SNB_MSR_UNC_CBO_1_PERFEVTSEL0 ,SNB_MSR_UNC_CBO_1_PER_CTR0 }, + {SNB_MSR_UNC_CBO_1_PERFEVTSEL1 ,SNB_MSR_UNC_CBO_1_PER_CTR1 }, + {SNB_MSR_UNC_CBO_2_PERFEVTSEL0 ,SNB_MSR_UNC_CBO_2_PER_CTR0 }, + {SNB_MSR_UNC_CBO_2_PERFEVTSEL1 ,SNB_MSR_UNC_CBO_2_PER_CTR1 }, + {SNB_MSR_UNC_CBO_3_PERFEVTSEL0 ,SNB_MSR_UNC_CBO_3_PER_CTR0 },
arch/x86/kernel/cpu/perf_event_intel_uncore.c static __initconst const struct intel_uncore_pmu nhm_uncore_pmu = { · line 88
Quoted 10 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c +9
-0+ {SNB_MSR_UNC_CBO_3_PERFEVTSEL1, SNB_MSR_UNC_CBO_3_PER_CTR1}, +}; +static int snb_uncore_pmu_hw_config (struct perf_event *event) +{ +struct hw_perf_event *hwc = &event->hw; +int i = hwc->idx; + + hwc->config = event->attr.config &SNB_UNCORE_RAW_EVENT_MASK ; + hwc->config_base = snb_uncore_configs[i].config_base;
hwc->config_base = SNB_MSR_UNC_CBO_0_PERFEVTSEL0 + 0x10 * (i >> 1) + 0x6 * (i & 1);
Saves a memory lookup, might or might not be worth it.
What the heck did Intel mess those MSRs up for anyway?
Quoted 4 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c +4
-0+ hwc->event_base = snb_uncore_configs[i].event_base; + +return 0 ; +}
Quoted 10 lines · Stephane Eranian
Quoted 9 lines · Stephane Eranian
Quoted 8 lines · Lin Ming
Hi, all
I posted uncore patches months ago, but it was pended due to an uncore interrupt problem.
This series are cut to support uncore pmu counting only. So uncore interrupt handling is not needed.
Quoted 8 lines
Quoted 4 lines
You're making the assumption that when counting, you can never construct a measurement that will cause a counter to overflow the 39 bits. If not, then you need interrupt handling even when counting.
The actual counter width is 48. But
wrmsrl()can only write the bottom 32 bits of a register. I think Intel fixed that only with SandyBridge (see Vol3b). Thus, the risk of 'silent' wrap around is much higher now as you have only 31 bits to play with.
I just tested wrmsrl on uncore counters and it's surprised to me that it supports full write.
val64.low = 0xFFFFEEEE; val64.high = 0x12345678;
On Nehalem/Westmere:
msr = 0x3b0; //NHM_MSR_UNCORE_PMC0
wrmsrl(msr, val64.full & 0xfffffffffff); //48 bits counter
rdmsrl(msr, val64.full);
printfk("counter value: 0x%llx\n", val64.full);I got:
counter value: 0x5678ffffeeee
On SandyBridge:
msr = 0x716; //SNB_MSR_UNC_CBO_1_PER_CTR0
wrmsrl(msr, val64.full & 0xfffffffffff); //44 bits counter
rdmsrl(msr, val64.full);
printfk("counter value: 0x%llx\n", val64.full);I got:
counter value: 0x678ffffeeee
Quoted 6 lines
But if I read your patch correctly, it seems you are avoiding
wrmsrl()on the counter. Instead, you are reading it when you start (prev_count) and using that value to compute the delta on stop.Am I understanding your workaround correctly?
Yes, but I didn't realize that it's a workaround.
Lin Ming
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
The uncore pmu type is allocated dynamically and exported via sysfs.
$ cat /sys/bus/event_source/devices/uncore/type 6You can count uncore raw events as below,
$ perf stat -e uncore:r0101 lsIt reads uncore pmu type id from sysfs to setup
perf_event_attr::type.Comments are appreciated.
Thanks,
Lin Ming
Quoted 6 lines · Stephane Eranian
Quoted 5 lines · Lin Ming
Hi, all
I posted uncore patches months ago, but it was pended due to an uncore interrupt problem.
Quoted 6 lines
Quoted 3 lines
This series are cut to support uncore pmu counting only. So uncore interrupt handling is not needed.
You're making the assumption that when counting, you can never construct a measurement that will cause a counter to overflow the 39 bits. If not, then you need interrupt handling even when counting.
Is it enough to get the delta when overflow like below?
unsigned int a = 0xfffffffe;
unsigned int b = 10;
unsigned int delta = (int)b - (int)a;Quoted 17 lines
Quoted 17 lines
The uncore pmu type is allocated dynamically and exported via sysfs.
$ cat /sys/bus/event_source/devices/uncore/type 6You can count uncore raw events as below,
$ perf stat -e uncore:r0101 lsIt reads uncore pmu type id from sysfs to setup
perf_event_attr::type.Comments are appreciated.
Thanks,
Lin Ming
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
In reply to Peter ZijlstraQuoted 4 lines · Peter Zijlstra
Quoted 1 line · Lin Ming
+static struct pmu
uncore_pmu= {.task_ctx_nr =
perf_invalid_context,
OK.
usage: perf stat [<options>] [<command>]
Currently, "perf stat" always need a <command> to do counting. Need to change it to be optional.
So I may add a "P" option to specify which physical processor to count.
perf stat -P 3 -e uncore:rXXXX
Quoted 10 lines
Quoted 8 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +7
-0+ .event_init = uncore_pmu_event_init, + .add = uncore_pmu_add, + .del = uncore_pmu_del, + .start = uncore_pmu_start, + .stop = uncore_pmu_stop, + .read = uncore_pmu_read, +};
Quoted 38 lines · Lin Ming
Quoted 10 lines · Stephane Eranian
Quoted 9 lines · Stephane Eranian
Quoted 8 lines · Lin Ming
Hi, all
I posted uncore patches months ago, but it was pended due to an uncore interrupt problem.
This series are cut to support uncore pmu counting only. So uncore interrupt handling is not needed.
Quoted 8 lines
Quoted 4 lines
You're making the assumption that when counting, you can never construct a measurement that will cause a counter to overflow the 39 bits. If not, then you need interrupt handling even when counting.
The actual counter width is 48. But
wrmsrl()can only write the bottom 32 bits of a register. I think Intel fixed that only with SandyBridge (see Vol3b). Thus, the risk of 'silent' wrap around is much higher now as you have only 31 bits to play with.I just tested wrmsrl on uncore counters and it's surprised to me that it supports full write.
val64.low =
0xFFFFEEEE;
val64.high =0x12345678;On Nehalem/Westmere:
msr =
0x3b0; //NHM_MSR_UNCORE_PMC0
wrmsrl(msr, val64.full &0xfffffffffff); //48 bits counterrdmsrl(msr, val64.full);
printfk("counter value: 0x%llx\n", val64.full);I got:
counter value:0x5678ffffeeeeOn SandyBridge:
Quoted 8 lines
msr =
0x716; //SNB_MSR_UNC_CBO_1_PER_CTR0wrmsrl(msr, val64.full & 0xfffffffffff); //44 bits counterrdmsrl(msr, val64.full);
printfk("counter value: 0x%llx\n", val64.full);I got:
counter value:0x678ffffeeee
I tried on my Nehalem and SandyBridge (model 42) and I get the same results. The restriction applies only to core PMU counters then.
But what's so weird is that on SandyBridge the counter counters are still limited:
uncore counter value: 0x678ffffeeee
core counter value: 0xffffffffeeee
Yet, IA32_PERF_CAPABILITIES.FW_WIDTH (bit13) is set, thus wrmsrl() should write the full 48-bit width (see Vol3b 30.2.2.3).
Further testing revealed that you get full width ONLY with the fixed counter counters:
FW_WIDTH=1
uncore counter value: 0x678ffffeeee
core counter value: 0xffffffffeeee
fixed counter value: 0x678ffffeeee
I suspect there is a bug in the HW or a bogus description in the SDM. I will check on that with Intel.
Quoted 32 lines
Quoted 5 lines
But if I read your patch correctly, it seems you are avoiding
wrmsrl()on the counter. Instead, you are reading it when you start (prev_count) and using that value to compute the delta on stop.Am I understanding your workaround correctly?
Yes, but I didn't realize that it's a workaround.
Lin Ming
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
The uncore pmu type is allocated dynamically and exported via sysfs.
$ cat /sys/bus/event_source/devices/uncore/type 6You can count uncore raw events as below,
$ perf stat -e uncore:r0101 lsIt reads uncore pmu type id from sysfs to setup
perf_event_attr::type.Comments are appreciated.
Thanks,
Lin Ming
Quoted 12 lines · Lin Ming
Hi, all
I posted uncore patches months ago, but it was pended due to an uncore interrupt problem.
This series are cut to support uncore pmu counting only. So uncore interrupt handling is not needed.
The uncore pmu type is allocated dynamically and exported via sysfs.
$ cat /sys/bus/event_source/devices/uncore/type 6
Quoted 6 lines
You can count uncore raw events as below,
$ perf stat -e uncore:r0101 lsIt reads uncore pmu type id from sysfs to setup
perf_event_attr::type.Comments are appreciated.
Could you please list the most useful hw events that Intel would like users to be able to measure via the uncore PMU, and which are not available via the offcore PMU?
Thanks,
Ingo
Lin,
Ok, false alarm. Vol3b is correct. I missed the fact that if you want wrmsrl() to write full width generic counters, you have to use the alternate MSR alias. I guess that's for backward compatibility. So for full width wrmsrl on PERFCTR0 -> use 0x41c
uncore counter value: 0x678ffffeeee
core fixed counter value: 0x678ffffeeee
core generic counter value: 0xffffffffeeee
wide core generic counter value: 0x678ffffeeee
I think full width write to fixed counters has been there for a long time. Looks like the problem was only present for core generic counters until SNB.
Quoted 104 lines · Stephane Eranian
Quoted 38 lines · Lin Ming
Quoted 10 lines · Stephane Eranian
Quoted 9 lines · Stephane Eranian
Quoted 8 lines · Lin Ming
Hi, all
I posted uncore patches months ago, but it was pended due to an uncore interrupt problem.
This series are cut to support uncore pmu counting only. So uncore interrupt handling is not needed.
Quoted 8 lines
Quoted 4 lines
You're making the assumption that when counting, you can never construct a measurement that will cause a counter to overflow the 39 bits. If not, then you need interrupt handling even when counting.
The actual counter width is 48. But
wrmsrl()can only write the bottom 32 bits of a register. I think Intel fixed that only with SandyBridge (see Vol3b). Thus, the risk of 'silent' wrap around is much higher now as you have only 31 bits to play with.I just tested wrmsrl on uncore counters and it's surprised to me that it supports full write.
val64.low =
0xFFFFEEEE;
val64.high =0x12345678;On Nehalem/Westmere:
msr =
0x3b0; //NHM_MSR_UNCORE_PMC0
wrmsrl(msr, val64.full &0xfffffffffff); //48 bits counterrdmsrl(msr, val64.full);
printfk("counter value: 0x%llx\n", val64.full);I got:
counter value:0x5678ffffeeeeOn SandyBridge:
Quoted 8 lines
msr =
0x716; //SNB_MSR_UNC_CBO_1_PER_CTR0wrmsrl(msr, val64.full & 0xfffffffffff); //44 bits counterrdmsrl(msr, val64.full);
printfk("counter value: 0x%llx\n", val64.full);I got:
counter value:0x678ffffeeeeI tried on my Nehalem and SandyBridge (model 42) and I get the same results. The restriction applies only to core PMU counters then.
But what's so weird is that on SandyBridge the counter counters are still limited:
uncore counter value:
0x678ffffeeee
core counter value:0xffffffffeeeeYet, IA32_PERF_CAPABILITIES.FW_WIDTH (bit13) is set, thus
wrmsrl()should write the full 48-bit width (see Vol3b 30.2.2.3).Further testing revealed that you get full width ONLY with the fixed counter counters:
FW_WIDTH=1
uncore counter value:0x678ffffeeee
core counter value:0xffffffffeeee
fixed counter value:0x678ffffeeeeI suspect there is a bug in the HW or a bogus description in the SDM. I will check on that with Intel.
Quoted 32 lines
Quoted 5 lines
But if I read your patch correctly, it seems you are avoiding
wrmsrl()on the counter. Instead, you are reading it when you start (prev_count) and using that value to compute the delta on stop.Am I understanding your workaround correctly?
Yes, but I didn't realize that it's a workaround.
Lin Ming
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
The uncore pmu type is allocated dynamically and exported via sysfs.
$ cat /sys/bus/event_source/devices/uncore/type 6You can count uncore raw events as below,
$ perf stat -e uncore:r0101 lsIt reads uncore pmu type id from sysfs to setup
perf_event_attr::type.Comments are appreciated.
Thanks,
Lin Ming
Quoted 7 lines · Stephane Eranian
Lin,
Ok, false alarm. Vol3b is correct. I missed the fact that if you want
wrmsrl()to write full width generic counters, you have to use the alternate MSR alias. I guess that's for backward compatibility. So for full width wrmsrl on PERFCTR0 -> use0x41c
Quoted 9 lines
uncore counter value:
0x678ffffeeee
core fixed counter value:0x678ffffeeee
core generic counter value:0xffffffffeeee
wide core generic counter value:0x678ffffeeeeI think full width write to fixed counters has been there for a long time. Looks like the problem was only present for core generic counters until SNB.
Forgot to say, that we could adapt the code to use the alternate registers if full width wrmsrl() is supported. That would mitigate a bit the overhead of sampling and counting by simply not interrupting that often to accumulate counts in the SW counter.
Quoted 50 lines · Stephane Eranian
Quoted 38 lines · Lin Ming
Quoted 10 lines · Stephane Eranian
Quoted 9 lines · Stephane Eranian
Quoted 8 lines · Lin Ming
Hi, all
I posted uncore patches months ago, but it was pended due to an uncore interrupt problem.
This series are cut to support uncore pmu counting only. So uncore interrupt handling is not needed.
Quoted 8 lines
Quoted 4 lines
You're making the assumption that when counting, you can never construct a measurement that will cause a counter to overflow the 39 bits. If not, then you need interrupt handling even when counting.
The actual counter width is 48. But
wrmsrl()can only write the bottom 32 bits of a register. I think Intel fixed that only with SandyBridge (see Vol3b). Thus, the risk of 'silent' wrap around is much higher now as you have only 31 bits to play with.I just tested wrmsrl on uncore counters and it's surprised to me that it supports full write.
val64.low = 0xFFFFEEEE; val64.high = 0x12345678;On Nehalem/Westmere:
msr = 0x3b0; //NHM_MSR_UNCORE_PMC0 wrmsrl(msr, val64.full & 0xfffffffffff); //48 bits counter rdmsrl(msr, val64.full); printfk("counter value: 0x%llx\n", val64.full);I got:
counter value: 0x5678ffffeeeeOn SandyBridge:
Quoted 8 lines
msr = 0x716; //SNB_MSR_UNC_CBO_1_PER_CTR0 wrmsrl(msr, val64.full & 0xfffffffffff); //44 bits counter rdmsrl(msr, val64.full); printfk("counter value: 0x%llx\n", val64.full);I got:
counter value: 0x678ffffeeeeI tried on my Nehalem and SandyBridge (model 42) and I get the same results. The restriction applies only to core PMU counters then.
Quoted 8 lines
But what's so weird is that on SandyBridge the counter counters are still limited:
uncore counter value:
0x678ffffeeee
core counter value:0xffffffffeeeeYet, IA32_PERF_CAPABILITIES.FW_WIDTH (bit13) is set, thus
wrmsrl()should write the full 48-bit width (see Vol3b 30.2.2.3).
No.
The SandyBridge uncore generic counters are 44 bits width and the fixed counter is 48 bit width.
Lin Ming
Quoted 45 lines
Further testing revealed that you get full width ONLY with the fixed counter counters:
FW_WIDTH=1
uncore counter value:0x678ffffeeee
core counter value:0xffffffffeeee
fixed counter value:0x678ffffeeeeI suspect there is a bug in the HW or a bogus description in the SDM. I will check on that with Intel.
Quoted 32 lines
Quoted 5 lines
But if I read your patch correctly, it seems you are avoiding
wrmsrl()on the counter. Instead, you are reading it when you start (prev_count) and using that value to compute the delta on stop.Am I understanding your workaround correctly?
Yes, but I didn't realize that it's a workaround.
Lin Ming
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
The uncore pmu type is allocated dynamically and exported via sysfs.
$ cat /sys/bus/event_source/devices/uncore/type 6You can count uncore raw events as below,
$ perf stat -e uncore:r0101 lsIt reads uncore pmu type id from sysfs to setup
perf_event_attr::type.Comments are appreciated.
Thanks,
Lin Ming
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
In reply to Andi KleenQuoted 13 lines · Andi Kleen
arch/x86/kernel/cpu/perf_event_intel_uncore.c line 68
Quoted 9 lines · Lin Ming
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +9
-0+static u64 uncore_perf_event_update (struct perf_event *event) +{ +struct hw_perf_event *hwc = &event->hw; +int shift =64 - intel_uncore_pmu.cntval_bits; +u64 prev_raw_count, new_raw_count; +s64 delta; + +/* +* Careful: an NMI might modify the previous event value. There are no NMIs without sampling, so at least the comment seems bogus. Perhaps the code could be a bit simplified now without atomics.
I'm not sure if uncore PMU interrupt need to be enabled for counting only. What do you think?
Quoted 17 lines
Quoted 17 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +16
-0+static int uncore_pmu_event_init (struct perf_event *event) +{ +struct hw_perf_event *hwc = &event->hw; + +if (!uncore_pmu_initialized) +return -ENOENT ; + +if (event->attr.type != uncore_pmu.type) +return -ENOENT ; + +/* +* Uncore PMU does measure at all privilege level all the time. +* So it doesn't make sense to specify any exclude bits. +*/ +if (event->attr.exclude_user || event->attr.exclude_kernel + || event->attr.exclude_hv || event->attr.exclude_idle)
Quoted 8 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c line 120
Quoted 5 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +5
-0+return -ENOENT ; + +/* Sampling not supported yet */ +if (hwc->sample_period) +return -EINVAL ;Don't we need a "is root" check here? uncore counts everything, so it cannot be limited to a single process.
Yes, will add a "is root" check.
Will add .task_ctx_nr = perf_invalid_context to disallow per-process counting.
Quoted 12 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c line 251
Quoted 9 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +8
-0+static void uncore_pmu_cpu_starting (int cpu) +{ +struct cpu_uncore_events *cpuc = &per_cpu (cpu_uncore_events, cpu); +struct intel_uncore *uncore; +int i, uncore_id; + +if (boot_cpu_data.x86_max_cores <2 ) +return ;Why that check? uncore counting should work on a single core system too.
Quoted 1 line
I think you should remove all of those.
Agree, will remove it.
Quoted 8 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c line 256
Quoted 6 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.c new file +5
-0+ + uncore_id =topology_physical_package_id (cpu); +WARN_ON_ONCE (uncore_id ==BAD_APICID ); + +raw_spin_lock (&intel_uncore_lock);Does this really need to be a raw spinlock?
I think spinlock is enough.
Quoted 6 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.h line 10
Quoted 4 lines
arch/x86/kernel/cpu/perf_event_intel_uncore.h new file +3
-0+#define NHM_MSR_UNCORE_PERF_GLOBAL_CTRL 0x391 +#define NHM_MSR_UNCORE_PMC0 0x3b0 +#define NHM_MSR_UNCORE_PERFEVTSEL0 0x3c0These should be in
msr-index.h
Will move these.
Thanks,
Lin Ming
Quoted 3 lines
-Andi
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
Quoted 3 lines · Lin Ming
Quoted 1 line
Does this really need to be a raw spinlock?
I think spinlock is enough.
No, raw_spinlock_t was correct.
Talking of which:
+ struct spinlock lock;
That too should be a raw_spinlock_t.
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
In reply to Lin MingQuoted 5 lines
Quoted 2 lines
There are no NMIs without sampling, so at least the comment seems bogus. Perhaps the code could be a bit simplified now without atomics.
I'm not sure if uncore PMU interrupt need to be enabled for counting only. What do you think?
Only for overflow handling to accumulate into a larger counter, but it doesn't need to be an NMI for that. But it's not strictly required I would say, 44(?) bits are probably enough for near all use cases.
At least initially not having one is fine I think.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
Quoted 8 lines · Andi Kleen
Quoted 5 lines
Quoted 2 lines
There are no NMIs without sampling, so at least the comment seems bogus. Perhaps the code could be a bit simplified now without atomics.
I'm not sure if uncore PMU interrupt need to be enabled for counting only. What do you think?
Only for overflow handling to accumulate into a larger counter, but it doesn't need to be an NMI for that.
Uncore is hooked into the regular PMI, and since we wire that to the NMI the uncore will always be NMI too.
Quoted 2 lines
But it's not strictly required I would say,
44(?) bits are probably enough for near all use cases.
44bits is in the hours range for pure cycle counts, which is so-so. I bet you're going to be very annoyed when you find your counters are wrecked after your 5 hour test run finishes.
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
Quoted 13 lines · Peter Zijlstra
Quoted 8 lines · Andi Kleen
Quoted 5 lines
Quoted 2 lines
There are no NMIs without sampling, so at least the comment seems bogus. Perhaps the code could be a bit simplified now without atomics.
I'm not sure if uncore PMU interrupt need to be enabled for counting only. What do you think?
Only for overflow handling to accumulate into a larger counter, but it doesn't need to be an NMI for that.
Uncore is hooked into the regular PMI, and since we wire that to the NMI the uncore will always be NMI too.
Quoted 6 lines
Quoted 2 lines
But it's not strictly required I would say,
44(?) bits are probably enough for near all use cases.44bits is in the hours range for pure cycle counts, which is so-so. I bet you're going to be very annoyed when you find your counters are wrecked after your 5 hour test run finishes.
I'll add the interrupt handling code back.
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
Quoted 14 lines · Lin Ming
Quoted 13 lines · Peter Zijlstra
Quoted 8 lines · Andi Kleen
Quoted 5 lines
Quoted 2 lines
There are no NMIs without sampling, so at least the comment seems bogus. Perhaps the code could be a bit simplified now without atomics.
I'm not sure if uncore PMU interrupt need to be enabled for counting only. What do you think?
Only for overflow handling to accumulate into a larger counter, but it doesn't need to be an NMI for that.
Uncore is hooked into the regular PMI, and since we wire that to the NMI the uncore will always be NMI too.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
But it's not strictly required I would say,
44(?) bits are probably enough for near all use cases.44bits is in the hours range for pure cycle counts, which is so-so. I bet you're going to be very annoyed when you find your counters are wrecked after your 5 hour test run finishes.
I'll add the interrupt handling code back.
Does it work? The problem was with the hardware being iffy.
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
Quoted 18 lines · Peter Zijlstra
Quoted 17 lines · Lin Ming
Quoted 16 lines · Peter Zijlstra
Quoted 8 lines · Andi Kleen
Quoted 5 lines
Quoted 2 lines
There are no NMIs without sampling, so at least the comment seems bogus. Perhaps the code could be a bit simplified now without atomics.
I'm not sure if uncore PMU interrupt need to be enabled for counting only. What do you think?
Only for overflow handling to accumulate into a larger counter, but it doesn't need to be an NMI for that.
Uncore is hooked into the regular PMI, and since we wire that to the NMI the uncore will always be NMI too.
Quoted 2 lines
But it's not strictly required I would say,
44(?) bits are probably enough for near all use cases.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
44bits is in the hours range for pure cycle counts, which is so-so. I bet you're going to be very annoyed when you find your counters are wrecked after your 5 hour test run finishes.
I'll add the interrupt handling code back.
Does it work? The problem was with the hardware being iffy.
It may work on SandyBridge.
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
In reply to Peter ZijlstraQuoted 8 lines
Quoted 4 lines
But it's not strictly required I would say,
44(?) bits are probably enough for near all use cases.44bits is in the hours range for pure cycle counts, which is so-so. I bet you're going to be very annoyed when you find your counters are wrecked after your 5 hour test run finishes.
For these kinds of long running measurements you usually care about ratios, not absolutes. Some infrequent wrapping should not substantially change.
those.
-Andi
Re: [PATCH 1/4] perf, x86: Add Intel Nehalem/Westmere uncore pmu
Quoted 5 lines · Andi Kleen
Quoted 5 lines
Quoted 4 lines
But it's not strictly required I would say,
44(?) bits are probably enough for near all use cases.
Quoted 7 lines
Quoted 3 lines
44bits is in the hours range for pure cycle counts, which is so-so. I bet you're going to be very annoyed when you find your counters are wrecked after your 5 hour test run finishes.
For these kinds of long running measurements you usually care about ratios, not absolutes. Some infrequent wrapping should not substantially change. those.
That's just empty blathering - those who *do* take a look at long-running absolute values obviously care.
There's absolutely no reason to be sloppy here - this needs to be implemented correctly.
Thanks,
Ingo
[tip:perf/core] perf: Remove perf_event_attr::type check
In reply to Lin MingCommit-ID: 9985c20f9e4aee6857c08246b273a3695a52b929 Gitweb: http://git.kernel.org/tip/9985c20f9e4aee6857c08246b273a3695a52b929 Author: Lin Ming <[email protected]> AuthorDate: Thu, 30 Jun 2011 08:09:55 +0000 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 21 Jul 2011 20:41:55 +0200
perf: Remove perf_event_attr::type check
PMU type id can be allocated dynamically, so perf_event_attr::type check when copying attribute from userspace to kernel is not valid.
--- kernel/events/core.c | 7 ------- 1 files changed, 0 insertions(+), 7 deletions(-)
kernel/events/core.c +0 -7
@@ -5926,13 +5926,6 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,if (ret)return -EFAULT ; -/* -* If the type exists, the corresponding creation will verify -* the attr->config. -*/ -if (attr->type >=PERF_TYPE_MAX ) -return -EINVAL ; -if (attr->__reserved_1)return -EINVAL ;