perf: offcore event monitoring patches
Subsystems (2)
v3 cover perf: offcore event monitoring patches
Hi,
v2 -> v3:
- Remove redundant "c = NULL" in intel_percore_constraints
- Fix comment of perf_event_attr::config1
v2:
Here is the updated offcore patches. I merged small changes and fixes into the first patch, see the change logs.
Change logs against Andi's original version:
- Extends perf_event_attr:config to config{,1,2} (Peter Zijlstra)
- Fixed a major event scheduling issue. There cannot be a ref++ on an event that has already done ref++ once and without calling put_constraint() in between. (Stephane Eranian)
- Use thread_cpumask for percore allocation. (Lin Ming)
- Use MSR names in the extra reg lists. (Lin Ming)
Peter,
The event scheduling issue was fixed, could you please consider merging this series?
Thanks,
Lin Ming
PATCH v3 1/4 perf: Add support for supplementary event registers
From: Andi Kleen <[email protected]>
Change logs against Andi's original version:
- Extends perf_event_attr:config to config{,1,2} (Peter Zijlstra)
- Fixed a major event scheduling issue. There cannot be a ref++ on an event that has already done ref++ once and without calling put_constraint() in between. (Stephane Eranian)
- Use thread_cpumask for percore allocation. (Lin Ming)
- Use MSR names in the extra reg lists. (Lin Ming)
- Remove redundant "c = NULL" in intel_percore_constraints
- Fix comment of perf_event_attr::config1
Intel Nehalem/Westmere have a special OFFCORE_RESPONSE event that can be used to monitor any offcore accesses from a core. This is a very useful event for various tunings, and it's also needed to implement the generic LLC-* events correctly.
Unfortunately this event requires programming a mask in a separate register. And worse this separate register is per core, not per CPU thread.
This patch adds:
- Teaches perf_events that OFFCORE_RESPONSE needs extra parameters. The extra parameters are passed by user space in the perf_event_attr::config1 field.
- Add support to the Intel perf_event core to schedule per core resources. This adds fairly generic infrastructure that can be also used for other per core resources.
The basic code has is patterned after the similar AMD northbridge constraints code.
Thanks to Stephane Eranian who pointed out some problems in the original version and suggested improvements.
--- arch/x86/include/asm/msr-index.h | 3 + arch/x86/kernel/cpu/perf_event.c | 64 ++++++++++ arch/x86/kernel/cpu/perf_event_intel.c | 200 ++++++++++++++++++++++++++++++++ include/linux/perf_event.h | 13 ++- 4 files changed, 278 insertions(+), 2 deletions(-)
arch/x86/include/asm/msr-index.h +3 -0
@@ -47,6 +47,9 @@#define MSR_IA32_MCG_STATUS 0x0000017a#define MSR_IA32_MCG_CTL 0x0000017b +#define MSR_OFFCORE_RSP_0 0x000001a6 +#define MSR_OFFCORE_RSP_1 0x000001a7 +#define MSR_IA32_PEBS_ENABLE 0x000003f1#define MSR_IA32_DS_AREA 0x00000600#define MSR_IA32_PERF_CAPABILITIES 0x00000345
arch/x86/kernel/cpu/perf_event.c +64 -0
106 lines not on this page · raw message
arch/x86/kernel/cpu/perf_event_intel.c +200 -0
270 lines not on this page · raw message
include/linux/perf_event.h +11 -2
@@ -225,8 +225,14 @@ struct perf_event_attr { };__u32 bp_type; -__u64 bp_addr; -__u64 bp_len; +union { +__u64 bp_addr; +__u64 config1;/* extension of config */ + }; +union { +__u64 bp_len; +__u64 config2;/* extension of config1 */ + }; };/*
@@ -541,6 +547,9 @@ struct hw_perf_event {unsigned long event_base;int idx;int last_cpu; +unsigned int extra_reg; +u64 extra_config; +int extra_alloc; };struct {/* software */ struct hrtimer hrtimer;
Signature · 1 line
1.7.3
PATCH v3 3/4 perf: Add support to the perf tool to specify extra values
In reply to Lin MingFrom: Andi Kleen <[email protected]>
Change logs:
- Use ":" to specify extra value since "," was already used for multiple events.
Add support to the perf tool to specify extra values for raw events and pass them to the kernel.
The new format is -e rXXXX[:YYYY]
--- tools/perf/builtin-report.c | 7 ++++--- tools/perf/util/parse-events.c | 24 +++++++++++++++++++----- tools/perf/util/parse-events.h | 2 +- tools/perf/util/ui/browsers/hists.c | 3 ++- 4 files changed, 26 insertions(+), 10 deletions(-)
tools/perf/builtin-report.c +4 -3
@@ -201,7 +201,8 @@ static int process_read_event(union perf_event *event, attr =perf_header__find_attr (event->read.id, &session->header);if (show_threads) { -const char *name = attr ?__event_name (attr->type, attr->config) +const char *name = attr ?__event_name (attr->type, attr->config, +0 ) :"unknown" ; perf_read_values_add_value(&show_threads_values, event->read.pid, event->read.tid,
@@ -211,7 +212,7 @@ static int process_read_event(union perf_event *event, }dump_printf (": %d %d %s %" PRIu64"\n" , event->read.pid, event->read.tid, - attr ?__event_name (attr->type, attr->config) :"FAIL" , + attr ?__event_name (attr->type, attr->config,0 ) :"FAIL" , event->read.value);return 0 ;
@@ -291,7 +292,7 @@ static int hists__tty_browse_tree(struct rb_root *tree, const char *help)const char *evname =NULL ;if (rb_first (&hists->entries) !=rb_last (&hists->entries)) - evname =__event_name (hists->type, hists->config); + evname =__event_name (hists->type, hists->config,0 );hists__fprintf_nr_sample_events (hists, evname, stdout);hists__fprintf (hists,NULL , false, stdout);
tools/perf/util/parse-events.c +19 -5
@@ -271,15 +271,18 @@ const char *event_name(struct perf_evsel *evsel)if (evsel->name)return evsel->name; -return __event_name (type, config); +return __event_name (type, config, evsel->attr.config1); } -const char *__event_name (int type,u64 config) +const char *__event_name (int type,u64 config,u64 extra) {static char buf[32 ]; +int n;if (type ==PERF_TYPE_RAW ) { -sprintf (buf,"raw 0x%" PRIx64, config); + n =sprintf (buf,"raw 0x%" PRIx64, config); +if (extra) +sprintf (buf + n,":%#" PRIx64, extra);return buf; }
@@ -666,9 +669,20 @@ parse_raw_event(const char **strp, struct perf_event_attr *attr)return EVT_FAILED ; n =hex2u64 (str +1 , &config);if (n >0 ) { - *strp = str + n +1 ; + str += n +1 ; + *strp = str; attr->type =PERF_TYPE_RAW ; attr->config = config; + +if (*str++ ==':' ) { + n =hex2u64 (str +1 , &config); +if (n >0 ) { + attr->config1 = config; + str += n +1 ; + *strp = str; + } + } +return EVT_HANDLED ; }return EVT_FAILED ;
@@ -1035,7 +1049,7 @@ void print_events(const char *event_glob)printf ("\n" );printf (" %-42s [%s]\n" , -"rNNN (see 'perf list --help' on how to encode it)" , +"rNNN[:EEE] (see 'perf list --help' on how to encode it)" , event_type_descriptors[PERF_TYPE_RAW ]);printf ("\n" );
tools/perf/util/parse-events.h +1 -1
@@ -21,7 +21,7 @@ extern struct tracepoint_path *tracepoint_id_to_path(u64 config);extern bool have_tracepoints (struct list_head *evlist);const char *event_name (struct perf_evsel *event); -extern const char *__event_name (int type,u64 config); +extern const char *__event_name (int type,u64 config,u64 extra);extern int parse_events (const struct option *opt,const char *str,int unset);extern int parse_filter (const struct option *opt,const char *str,int unset);
tools/perf/util/ui/browsers/hists.c +2 -1
@@ -984,7 +984,8 @@ int hists__tui_browse_tree(struct rb_root *self, const char *help, int evidx)while (nd) { struct hists *hists = rb_entry(nd, struct hists, rb_node); -const char *ev_name =__event_name (hists->type, hists->config); +const char *ev_name =__event_name (hists->type, hists->config, +0 ); key =hists__browse (hists, help, ev_name, evidx);switch (key) {
Signature · 1 line
1.7.3
PATCH v3 4/4 perf: Avoid the percore allocations if HT is not capable
No need to do percore allocations if HT is not capable
--- arch/x86/kernel/cpu/perf_event_intel.c | 23 +++++++++++++++++------ 1 files changed, 17 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/perf_event_intel.c +17 -6
@@ -1201,10 +1201,18 @@ static __initconst const struct x86_pmu core_pmu = { .event_constraints = intel_core_event_constraints, }; +static bool ht_capable (void ) +{ +return boot_cpu_has (X86_FEATURE_HT ) && smp_num_siblings >1 ; +} +static int intel_pmu_cpu_prepare (int cpu) {struct cpu_hw_events *cpuc = &per_cpu (cpu_hw_events, cpu); +if (!ht_capable ()) +return NOTIFY_OK ; + cpuc->per_core =kzalloc_node (sizeof (struct intel_percore ),GFP_KERNEL ,cpu_to_node (cpu));if (!cpuc->per_core)
@@ -1221,6 +1229,15 @@ static void intel_pmu_cpu_starting(int cpu)int core_id =topology_core_id (cpu);int i; +init_debug_store_on_cpu (cpu); +/* +* Deal with CPUs that don't clear their LBRs on power-up. +*/ +intel_pmu_lbr_reset (); + +if (!ht_capable ()) +return ; +for_each_cpu (i,topology_thread_cpumask (cpu)) {struct intel_percore *pc =per_cpu (cpu_hw_events, i).per_core;
@@ -1233,12 +1250,6 @@ static void intel_pmu_cpu_starting(int cpu) cpuc->per_core->core_id = core_id; cpuc->per_core->refcnt++; - -init_debug_store_on_cpu (cpu); -/* -* Deal with CPUs that don't clear their LBRs on power-up. -*/ -intel_pmu_lbr_reset (); }static void intel_pmu_cpu_dying (int cpu)
Signature · 1 line
1.7.3
PATCH v3 2/4 perf: Fix LLC-* events on Intel Nehalem/Westmere
In reply to Lin MingFrom: Andi Kleen <[email protected]>
The generic perf LLC-* events do count the L2 caches, not the real L3 LLC on Intel Nehalem and Westmere. This lead to quite some confusion.
Fixing this properly requires use of the special OFFCORE_RESPONSE events which need a separate mask register. This has been implemented in a earlier patch.
Now use this infrastructure to set correct events for the LLC-* on Nehalem and Westmere
--- arch/x86/kernel/cpu/perf_event.c | 15 ++++-- arch/x86/kernel/cpu/perf_event_intel.c | 81 +++++++++++++++++++++++++++----- 2 files changed, 79 insertions(+), 17 deletions(-)
arch/x86/kernel/cpu/perf_event.c +10 -5
@@ -310,6 +310,10 @@ static u64 __read_mostly hw_cache_event_ids [PERF_COUNT_HW_CACHE_MAX ] [PERF_COUNT_HW_CACHE_OP_MAX ] [PERF_COUNT_HW_CACHE_RESULT_MAX ]; +static u64 __read_mostly hw_cache_extra_regs + [PERF_COUNT_HW_CACHE_MAX ] + [PERF_COUNT_HW_CACHE_OP_MAX ] + [PERF_COUNT_HW_CACHE_RESULT_MAX ];/* * Propagate event elapsed time into the generic event.
@@ -524,8 +528,9 @@ static inline int x86_pmu_initialized(void) }static inline int -set_ext_hw_attr (struct hw_perf_event *hwc,struct perf_event_attr *attr) +set_ext_hw_attr (struct hw_perf_event *hwc,struct perf_event *event) { +struct perf_event_attr *attr = &event->attr;unsigned int cache_type, cache_op, cache_result;u64 config, val;
@@ -552,8 +557,8 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event_attr *attr)return -EINVAL ; hwc->config |= val; - -return 0 ; + attr->config1 = hw_cache_extra_regs[cache_type][cache_op][cache_result]; +return x86_pmu_extra_regs (val, event); }static int x86_setup_perfctr (struct perf_event *event)
@@ -578,10 +583,10 @@ static int x86_setup_perfctr(struct perf_event *event) }if (attr->type ==PERF_TYPE_RAW ) -return 0 ; +return x86_pmu_extra_regs (event->attr.config, event);if (attr->type ==PERF_TYPE_HW_CACHE ) -return set_ext_hw_attr (hwc, attr); +return set_ext_hw_attr (hwc, event);if (attr->config >= x86_pmu.max_events)return -EINVAL ;
arch/x86/kernel/cpu/perf_event_intel.c +69 -12
119 lines not on this page · raw message
Signature · 1 line
1.7.3
Quoted 3 lines · Lin Ming
Peter,
The event scheduling issue was fixed, could you please consider merging this series?
I'll have a look today.
BTW, you managed to wreck git-send-email, you have git 1.7 which does the right thing by default (--no-chain-reply-to), please do use that. I normally ignore emails send like this.
Quoted 11 lines · Peter Zijlstra
Quoted 3 lines · Lin Ming
Peter,
The event scheduling issue was fixed, could you please consider merging this series?I'll have a look today.
BTW, you managed to wreck git-send-email, you have git 1.7 which does the right thing by default (--no-chain-reply-to), please do use that. I normally ignore emails send like this.
OK. Will use --no-chain-reply-to next time.
[tip:perf/core] perf: Add support for supplementary event registers
In reply to Lin MingCommit-ID: a7e3ed1e470116c9d12c2f778431a481a6be8ab6 Gitweb: http://git.kernel.org/tip/a7e3ed1e470116c9d12c2f778431a481a6be8ab6 Author: Andi Kleen <[email protected]> AuthorDate: Thu, 3 Mar 2011 10:34:47 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 4 Mar 2011 11:32:53 +0100
perf: Add support for supplementary event registers
Change logs against Andi's original version:
- Extends perf_event_attr:config to config{,1,2} (Peter Zijlstra)
- Fixed a major event scheduling issue. There cannot be a ref++ on an event that has already done ref++ once and without calling put_constraint() in between. (Stephane Eranian)
- Use thread_cpumask for percore allocation. (Lin Ming)
- Use MSR names in the extra reg lists. (Lin Ming)
- Remove redundant "c = NULL" in intel_percore_constraints
- Fix comment of perf_event_attr::config1
Intel Nehalem/Westmere have a special OFFCORE_RESPONSE event that can be used to monitor any offcore accesses from a core. This is a very useful event for various tunings, and it's also needed to implement the generic LLC-* events correctly.
Unfortunately this event requires programming a mask in a separate register. And worse this separate register is per core, not per CPU thread.
This patch:
- Teaches perf_events that OFFCORE_RESPONSE needs extra parameters. The extra parameters are passed by user space in the perf_event_attr::config1 field.
- Adds support to the Intel perf_event core to schedule per core resources. This adds fairly generic infrastructure that can be also used for other per core resources.
The basic code has is patterned after the similar AMD northbridge constraints code.
Thanks to Stephane Eranian who pointed out some problems in the original version and suggested improvements.
LKML-Reference: <[email protected]>
--- arch/x86/include/asm/msr-index.h | 3 + arch/x86/kernel/cpu/perf_event.c | 64 ++++++++++ arch/x86/kernel/cpu/perf_event_intel.c | 198 ++++++++++++++++++++++++++++++++ include/linux/perf_event.h | 13 ++- 4 files changed, 276 insertions(+), 2 deletions(-)
arch/x86/include/asm/msr-index.h +3 -0
@@ -47,6 +47,9 @@#define MSR_IA32_MCG_STATUS 0x0000017a#define MSR_IA32_MCG_CTL 0x0000017b +#define MSR_OFFCORE_RSP_0 0x000001a6 +#define MSR_OFFCORE_RSP_1 0x000001a7 +#define MSR_IA32_PEBS_ENABLE 0x000003f1#define MSR_IA32_DS_AREA 0x00000600#define MSR_IA32_PERF_CAPABILITIES 0x00000345
arch/x86/kernel/cpu/perf_event.c +64 -0
106 lines not on this page · raw message
arch/x86/kernel/cpu/perf_event_intel.c +198 -0
269 lines not on this page · raw message
include/linux/perf_event.h +11 -2
@@ -225,8 +225,14 @@ struct perf_event_attr { };__u32 bp_type; -__u64 bp_addr; -__u64 bp_len; +union { +__u64 bp_addr; +__u64 config1;/* extension of config */ + }; +union { +__u64 bp_len; +__u64 config2;/* extension of config1 */ + }; };/*
@@ -541,6 +547,9 @@ struct hw_perf_event {unsigned long event_base;int idx;int last_cpu; +unsigned int extra_reg; +u64 extra_config; +int extra_alloc; };struct {/* software */ struct hrtimer hrtimer;
[tip:perf/core] perf: Fix LLC-* events on Intel Nehalem/Westmere
In reply to Lin MingCommit-ID: e994d7d23a0bae34cd28834e85522ed4e782faf7 Gitweb: http://git.kernel.org/tip/e994d7d23a0bae34cd28834e85522ed4e782faf7 Author: Andi Kleen <[email protected]> AuthorDate: Thu, 3 Mar 2011 10:34:48 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 4 Mar 2011 11:32:53 +0100
perf: Fix LLC-* events on Intel Nehalem/Westmere
On Intel Nehalem and Westmere CPUs the generic perf LLC-* events count the L2 caches, not the real L3 LLC - this was inconsistent with behavior on other CPUs.
Fixing this requires the use of the special OFFCORE_RESPONSE events which need a separate mask register.
This has been implemented by the previous patch, now use this infrastructure to set correct events for the LLC-* on Nehalem and Westmere.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/cpu/perf_event.c | 15 ++++-- arch/x86/kernel/cpu/perf_event_intel.c | 81 +++++++++++++++++++++++++++----- 2 files changed, 79 insertions(+), 17 deletions(-)
arch/x86/kernel/cpu/perf_event.c +10 -5
@@ -310,6 +310,10 @@ static u64 __read_mostly hw_cache_event_ids [PERF_COUNT_HW_CACHE_MAX ] [PERF_COUNT_HW_CACHE_OP_MAX ] [PERF_COUNT_HW_CACHE_RESULT_MAX ]; +static u64 __read_mostly hw_cache_extra_regs + [PERF_COUNT_HW_CACHE_MAX ] + [PERF_COUNT_HW_CACHE_OP_MAX ] + [PERF_COUNT_HW_CACHE_RESULT_MAX ];/* * Propagate event elapsed time into the generic event.
@@ -524,8 +528,9 @@ static inline int x86_pmu_initialized(void) }static inline int -set_ext_hw_attr (struct hw_perf_event *hwc,struct perf_event_attr *attr) +set_ext_hw_attr (struct hw_perf_event *hwc,struct perf_event *event) { +struct perf_event_attr *attr = &event->attr;unsigned int cache_type, cache_op, cache_result;u64 config, val;
@@ -552,8 +557,8 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event_attr *attr)return -EINVAL ; hwc->config |= val; - -return 0 ; + attr->config1 = hw_cache_extra_regs[cache_type][cache_op][cache_result]; +return x86_pmu_extra_regs (val, event); }static int x86_setup_perfctr (struct perf_event *event)
@@ -578,10 +583,10 @@ static int x86_setup_perfctr(struct perf_event *event) }if (attr->type ==PERF_TYPE_RAW ) -return 0 ; +return x86_pmu_extra_regs (event->attr.config, event);if (attr->type ==PERF_TYPE_HW_CACHE ) -return set_ext_hw_attr (hwc, attr); +return set_ext_hw_attr (hwc, event);if (attr->config >= x86_pmu.max_events)return -EINVAL ;
arch/x86/kernel/cpu/perf_event_intel.c +69 -12
119 lines not on this page · raw message
[tip:perf/core] perf: Avoid the percore allocations if the CPU is not HT capable
In reply to Lin MingCommit-ID: 90a37ed96b2be7a2ad86764589eabd6992657c89 Gitweb: http://git.kernel.org/tip/90a37ed96b2be7a2ad86764589eabd6992657c89 Author: Lin Ming <[email protected]> AuthorDate: Thu, 3 Mar 2011 10:34:50 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 4 Mar 2011 12:51:10 +0100
perf: Avoid the percore allocations if the CPU is not HT capable
LKML-Reference: <[email protected]>
--- arch/x86/include/asm/smp.h | 10 ++++++++++ arch/x86/kernel/cpu/perf_event_intel.c | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-)
arch/x86/include/asm/smp.h +10 -0
@@ -17,10 +17,20 @@#endif #include <asm/thread_info.h> #include <asm/cpumask.h> +#include <asm/cpufeature.h> extern int smp_num_siblings;extern unsigned int num_processors; +static inline bool cpu_has_ht_siblings (void ) +{ +bool has_siblings = false; +#ifdef CONFIG_SMP + has_siblings = cpu_has_ht && smp_num_siblings >1 ; +#endif +return has_siblings; +} +DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);DECLARE_PER_CPU (u16, cpu_llc_id);
arch/x86/kernel/cpu/perf_event_intel.c +12 -6
@@ -1205,6 +1205,9 @@ static int intel_pmu_cpu_prepare(int cpu) {struct cpu_hw_events *cpuc = &per_cpu (cpu_hw_events, cpu); +if (!cpu_has_ht_siblings ()) +return NOTIFY_OK ; + cpuc->per_core =kzalloc_node (sizeof (struct intel_percore ),GFP_KERNEL ,cpu_to_node (cpu));if (!cpuc->per_core)
@@ -1221,6 +1224,15 @@ static void intel_pmu_cpu_starting(int cpu)int core_id =topology_core_id (cpu);int i; +init_debug_store_on_cpu (cpu); +/* +* Deal with CPUs that don't clear their LBRs on power-up. +*/ +intel_pmu_lbr_reset (); + +if (!cpu_has_ht_siblings ()) +return ; +for_each_cpu (i,topology_thread_cpumask (cpu)) {struct intel_percore *pc =per_cpu (cpu_hw_events, i).per_core;
@@ -1233,12 +1245,6 @@ static void intel_pmu_cpu_starting(int cpu) cpuc->per_core->core_id = core_id; cpuc->per_core->refcnt++; - -init_debug_store_on_cpu (cpu); -/* -* Deal with CPUs that don't clear their LBRs on power-up. -*/ -intel_pmu_lbr_reset (); }static void intel_pmu_cpu_dying (int cpu)
[tip:perf/core] perf: Avoid the percore allocations if the CPU is not HT capable
In reply to Lin MingCommit-ID: 6909262429b70a162e9e7053672cfd8024c9275d Gitweb: http://git.kernel.org/tip/6909262429b70a162e9e7053672cfd8024c9275d Author: Lin Ming <[email protected]> AuthorDate: Thu, 3 Mar 2011 10:34:50 +0800 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 5 Mar 2011 07:12:16 +0100
perf: Avoid the percore allocations if the CPU is not HT capable
LKML-Reference: <[email protected]>
--- arch/x86/include/asm/smp.h | 10 ++++++++++ arch/x86/kernel/cpu/perf_event.c | 1 + arch/x86/kernel/cpu/perf_event_intel.c | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 6 deletions(-)
arch/x86/include/asm/smp.h +10 -0
@@ -17,10 +17,20 @@#endif #include <asm/thread_info.h> #include <asm/cpumask.h> +#include <asm/cpufeature.h> extern int smp_num_siblings;extern unsigned int num_processors; +static inline bool cpu_has_ht_siblings (void ) +{ +bool has_siblings = false; +#ifdef CONFIG_SMP + has_siblings = cpu_has_ht && smp_num_siblings >1 ; +#endif +return has_siblings; +} +DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);DECLARE_PER_CPU (u16, cpu_llc_id);
arch/x86/kernel/cpu/perf_event.c +1 -0
@@ -30,6 +30,7 @@#include <asm/stacktrace.h> #include <asm/nmi.h> #include <asm/compat.h> +#include <asm/smp.h> #if 0 #undef wrmsrl
arch/x86/kernel/cpu/perf_event_intel.c +12 -6
@@ -1205,6 +1205,9 @@ static int intel_pmu_cpu_prepare(int cpu) {struct cpu_hw_events *cpuc = &per_cpu (cpu_hw_events, cpu); +if (!cpu_has_ht_siblings ()) +return NOTIFY_OK ; + cpuc->per_core =kzalloc_node (sizeof (struct intel_percore ),GFP_KERNEL ,cpu_to_node (cpu));if (!cpuc->per_core)
@@ -1221,6 +1224,15 @@ static void intel_pmu_cpu_starting(int cpu)int core_id =topology_core_id (cpu);int i; +init_debug_store_on_cpu (cpu); +/* +* Deal with CPUs that don't clear their LBRs on power-up. +*/ +intel_pmu_lbr_reset (); + +if (!cpu_has_ht_siblings ()) +return ; +for_each_cpu (i,topology_thread_cpumask (cpu)) {struct intel_percore *pc =per_cpu (cpu_hw_events, i).per_core;
@@ -1233,12 +1245,6 @@ static void intel_pmu_cpu_starting(int cpu) cpuc->per_core->core_id = core_id; cpuc->per_core->refcnt++; - -init_debug_store_on_cpu (cpu); -/* -* Deal with CPUs that don't clear their LBRs on power-up. -*/ -intel_pmu_lbr_reset (); }static void intel_pmu_cpu_dying (int cpu)
tip-bot for Peter Zijlstra
maintainer[tip:perf/urgent] perf events, x86: Fix Intel Nehalem and Westmere last level cache event definitions
In reply to Lin MingCommit-ID: 63b6a6758eede2f9283c3594265b6e32e75d7456 Gitweb: http://git.kernel.org/tip/63b6a6758eede2f9283c3594265b6e32e75d7456 Author: Peter Zijlstra <[email protected]> AuthorDate: Sat, 23 Apr 2011 00:57:42 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 6 May 2011 11:24:48 +0200
perf events, x86: Fix Intel Nehalem and Westmere last level cache event definitions
The Intel Nehalem offcore bits implemented in:
e994d7d23a0b: perf: Fix LLC-* events on Intel Nehalem/Westmere
... are wrong: they implemented _ACCESS as _HIT and counted OTHER_CORE_HIT* as MISS even though its clearly documented as an L3 hit ...
Fix them and the Westmere definitions as well.
--- arch/x86/kernel/cpu/perf_event_intel.c | 87 +++++++++++++++++++------------- 1 files changed, 52 insertions(+), 35 deletions(-)
arch/x86/kernel/cpu/perf_event_intel.c +52 -35
@@ -184,26 +184,23 @@ static __initconst const u64 snb_hw_cache_event_ids }, }, [ C(LL ) ] = { -/* -* TBD: Need Off-core Response Performance Monitoring support - */ [ C(OP_READ) ] = { -/* OFFCORE_RESPONSE_0.ANY_DATA.LOCAL_CACHE */ +/* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ [ C(RESULT_ACCESS) ] = 0x01b7, -/* OFFCORE_RESPONSE_1.ANY_DATA.ANY_LLC_MISS */ - [ C(RESULT_MISS) ] = 0x01bb, +/* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ + [ C(RESULT_MISS) ] = 0x01b7, }, [ C(OP_WRITE) ] = { -/* OFFCORE_RESPONSE_0.ANY_RFO.LOCAL_CACHE */ +/* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ [ C(RESULT_ACCESS) ] = 0x01b7, -/* OFFCORE_RESPONSE_1.ANY_RFO.ANY_LLC_MISS */ - [ C(RESULT_MISS) ] = 0x01bb, +/* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ + [ C(RESULT_MISS) ] = 0x01b7, }, [ C(OP_PREFETCH) ] = { -/* OFFCORE_RESPONSE_0.PREFETCH.LOCAL_CACHE */ +/* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ [ C(RESULT_ACCESS) ] = 0x01b7, -/* OFFCORE_RESPONSE_1.PREFETCH.ANY_LLC_MISS */ - [ C(RESULT_MISS) ] = 0x01bb, +/* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ + [ C(RESULT_MISS) ] = 0x01b7, }, }, [ C(DTLB) ] = {
@@ -285,26 +282,26 @@ static __initconst const u64 westmere_hw_cache_event_ids }, [ C(LL ) ] = { [ C(OP_READ) ] = { -/* OFFCORE_RESPONSE_0.ANY_DATA.LOCAL_CACHE */ +/* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ [ C(RESULT_ACCESS) ] = 0x01b7, -/* OFFCORE_RESPONSE_1.ANY_DATA.ANY_LLC_MISS */ - [ C(RESULT_MISS) ] = 0x01bb, +/* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ + [ C(RESULT_MISS) ] = 0x01b7, },/* * Use RFO, not WRITEBACK, because a write miss would typically occur * on RFO. */ [ C(OP_WRITE) ] = { -/* OFFCORE_RESPONSE_1.ANY_RFO.LOCAL_CACHE */ - [ C(RESULT_ACCESS) ] = 0x01bb, -/* OFFCORE_RESPONSE_0.ANY_RFO.ANY_LLC_MISS */ +/* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ + [ C(RESULT_ACCESS) ] = 0x01b7, +/* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ [ C(RESULT_MISS) ] = 0x01b7, }, [ C(OP_PREFETCH) ] = { -/* OFFCORE_RESPONSE_0.PREFETCH.LOCAL_CACHE */ +/* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ [ C(RESULT_ACCESS) ] = 0x01b7, -/* OFFCORE_RESPONSE_1.PREFETCH.ANY_LLC_MISS */ - [ C(RESULT_MISS) ] = 0x01bb, +/* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ + [ C(RESULT_MISS) ] = 0x01b7, }, }, [ C(DTLB) ] = {
@@ -352,16 +349,36 @@ static __initconst const u64 westmere_hw_cache_event_ids };/* -* OFFCORE_RESPONSE MSR bits (subset), See IA32 SDM Vol 3 30.6.1.3 +* Nehalem/Westmere MSR_OFFCORE_RESPONSE bits; +* See IA32 SDM Vol 3B 30.6.1.3 */ -#define DMND_DATA_RD (1 << 0) -#define DMND_RFO (1 << 1) -#define DMND_WB (1 << 3) -#define PF_DATA_RD (1 << 4) -#define PF_DATA_RFO (1 << 5) -#define RESP_UNCORE_HIT (1 << 8) -#define RESP_MISS (0xf600)/* non uncore hit */ +#define NHM_DMND_DATA_RD (1 << 0) +#define NHM_DMND_RFO (1 << 1) +#define NHM_DMND_IFETCH (1 << 2) +#define NHM_DMND_WB (1 << 3) +#define NHM_PF_DATA_RD (1 << 4) +#define NHM_PF_DATA_RFO (1 << 5) +#define NHM_PF_IFETCH (1 << 6) +#define NHM_OFFCORE_OTHER (1 << 7) +#define NHM_UNCORE_HIT (1 << 8) +#define NHM_OTHER_CORE_HIT_SNP (1 << 9) +#define NHM_OTHER_CORE_HITM (1 << 10) +/* reserved */ +#define NHM_REMOTE_CACHE_FWD (1 << 12) +#define NHM_REMOTE_DRAM (1 << 13) +#define NHM_LOCAL_DRAM (1 << 14) +#define NHM_NON_DRAM (1 << 15) + +#define NHM_ALL_DRAM (NHM_REMOTE_DRAM|NHM_LOCAL_DRAM) + +#define NHM_DMND_READ (NHM_DMND_DATA_RD) +#define NHM_DMND_WRITE (NHM_DMND_RFO|NHM_DMND_WB) +#define NHM_DMND_PREFETCH (NHM_PF_DATA_RD|NHM_PF_DATA_RFO) + +#define NHM_L3_HIT (NHM_UNCORE_HIT|NHM_OTHER_CORE_HIT_SNP|NHM_OTHER_CORE_HITM) +#define NHM_L3_MISS (NHM_NON_DRAM|NHM_ALL_DRAM|NHM_REMOTE_CACHE_FWD) +#define NHM_L3_ACCESS (NHM_L3_HIT|NHM_L3_MISS)static __initconst const u64 nehalem_hw_cache_extra_regs [PERF_COUNT_HW_CACHE_MAX ]
@@ -370,16 +387,16 @@ static __initconst const u64 nehalem_hw_cache_extra_regs { [C (LL ) ] = { [C (OP_READ ) ] = { - [C (RESULT_ACCESS ) ] =DMND_DATA_RD |RESP_UNCORE_HIT , - [C (RESULT_MISS ) ] =DMND_DATA_RD |RESP_MISS , + [C (RESULT_ACCESS ) ] =NHM_DMND_READ |NHM_L3_ACCESS , + [C (RESULT_MISS ) ] =NHM_DMND_READ |NHM_L3_MISS , }, [C (OP_WRITE ) ] = { - [C (RESULT_ACCESS ) ] =DMND_RFO |DMND_WB |RESP_UNCORE_HIT , - [C (RESULT_MISS ) ] =DMND_RFO |DMND_WB |RESP_MISS , + [C (RESULT_ACCESS ) ] =NHM_DMND_WRITE |NHM_L3_ACCESS , + [C (RESULT_MISS ) ] =NHM_DMND_WRITE |NHM_L3_MISS , }, [C (OP_PREFETCH ) ] = { - [C (RESULT_ACCESS ) ] =PF_DATA_RD |PF_DATA_RFO |RESP_UNCORE_HIT , - [C (RESULT_MISS ) ] =PF_DATA_RD |PF_DATA_RFO |RESP_MISS , + [C (RESULT_ACCESS ) ] =NHM_DMND_PREFETCH |NHM_L3_ACCESS , + [C (RESULT_MISS ) ] =NHM_DMND_PREFETCH |NHM_L3_MISS , }, } };