Commit f0704827 authored by Richard Cochran's avatar Richard Cochran Committed by Ingo Molnar

perf/x86/intel/cqm: Convert Intel CQM to hotplug state machine

Install the callbacks via the state machine and let the core invoke
the callbacks on the already online CPUs.
Signed-off-by: default avatarRichard Cochran <rcochran@linutronix.de>
Signed-off-by: default avatarAnna-Maria Gleixner <anna-maria@linutronix.de>
Reviewed-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt.fleming@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Vikas Shivappa <vikas.shivappa@linux.intel.com>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: rt@linutronix.de
Link: http://lkml.kernel.org/r/20160713153334.096956222@linutronix.deSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 8b5b773d
...@@ -1577,7 +1577,7 @@ static inline void cqm_pick_event_reader(int cpu) ...@@ -1577,7 +1577,7 @@ static inline void cqm_pick_event_reader(int cpu)
cpumask_set_cpu(cpu, &cqm_cpumask); cpumask_set_cpu(cpu, &cqm_cpumask);
} }
static void intel_cqm_cpu_starting(unsigned int cpu) static int intel_cqm_cpu_starting(unsigned int cpu)
{ {
struct intel_pqr_state *state = &per_cpu(pqr_state, cpu); struct intel_pqr_state *state = &per_cpu(pqr_state, cpu);
struct cpuinfo_x86 *c = &cpu_data(cpu); struct cpuinfo_x86 *c = &cpu_data(cpu);
...@@ -1588,39 +1588,26 @@ static void intel_cqm_cpu_starting(unsigned int cpu) ...@@ -1588,39 +1588,26 @@ static void intel_cqm_cpu_starting(unsigned int cpu)
WARN_ON(c->x86_cache_max_rmid != cqm_max_rmid); WARN_ON(c->x86_cache_max_rmid != cqm_max_rmid);
WARN_ON(c->x86_cache_occ_scale != cqm_l3_scale); WARN_ON(c->x86_cache_occ_scale != cqm_l3_scale);
cqm_pick_event_reader(cpu);
return 0;
} }
static void intel_cqm_cpu_exit(unsigned int cpu) static int intel_cqm_cpu_exit(unsigned int cpu)
{ {
int target; int target;
/* Is @cpu the current cqm reader for this package ? */ /* Is @cpu the current cqm reader for this package ? */
if (!cpumask_test_and_clear_cpu(cpu, &cqm_cpumask)) if (!cpumask_test_and_clear_cpu(cpu, &cqm_cpumask))
return; return 0;
/* Find another online reader in this package */ /* Find another online reader in this package */
target = cpumask_any_but(topology_core_cpumask(cpu), cpu); target = cpumask_any_but(topology_core_cpumask(cpu), cpu);
if (target < nr_cpu_ids) if (target < nr_cpu_ids)
cpumask_set_cpu(target, &cqm_cpumask); cpumask_set_cpu(target, &cqm_cpumask);
}
static int intel_cqm_cpu_notifier(struct notifier_block *nb,
unsigned long action, void *hcpu)
{
unsigned int cpu = (unsigned long)hcpu;
switch (action & ~CPU_TASKS_FROZEN) {
case CPU_DOWN_PREPARE:
intel_cqm_cpu_exit(cpu);
break;
case CPU_STARTING:
intel_cqm_cpu_starting(cpu);
cqm_pick_event_reader(cpu);
break;
}
return NOTIFY_OK; return 0;
} }
static const struct x86_cpu_id intel_cqm_match[] = { static const struct x86_cpu_id intel_cqm_match[] = {
...@@ -1682,7 +1669,7 @@ static int intel_mbm_init(void) ...@@ -1682,7 +1669,7 @@ static int intel_mbm_init(void)
static int __init intel_cqm_init(void) static int __init intel_cqm_init(void)
{ {
char *str = NULL, scale[20]; char *str = NULL, scale[20];
int i, cpu, ret; int cpu, ret;
if (x86_match_cpu(intel_cqm_match)) if (x86_match_cpu(intel_cqm_match))
cqm_enabled = true; cqm_enabled = true;
...@@ -1705,8 +1692,7 @@ static int __init intel_cqm_init(void) ...@@ -1705,8 +1692,7 @@ static int __init intel_cqm_init(void)
* *
* Also, check that the scales match on all cpus. * Also, check that the scales match on all cpus.
*/ */
cpu_notifier_register_begin(); get_online_cpus();
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
struct cpuinfo_x86 *c = &cpu_data(cpu); struct cpuinfo_x86 *c = &cpu_data(cpu);
...@@ -1743,11 +1729,6 @@ static int __init intel_cqm_init(void) ...@@ -1743,11 +1729,6 @@ static int __init intel_cqm_init(void)
if (ret) if (ret)
goto out; goto out;
for_each_online_cpu(i) {
intel_cqm_cpu_starting(i);
cqm_pick_event_reader(i);
}
if (mbm_enabled) if (mbm_enabled)
ret = intel_mbm_init(); ret = intel_mbm_init();
if (ret && !cqm_enabled) if (ret && !cqm_enabled)
...@@ -1772,12 +1753,18 @@ static int __init intel_cqm_init(void) ...@@ -1772,12 +1753,18 @@ static int __init intel_cqm_init(void)
pr_info("Intel MBM enabled\n"); pr_info("Intel MBM enabled\n");
/* /*
* Register the hot cpu notifier once we are sure cqm * Setup the hot cpu notifier once we are sure cqm
* is enabled to avoid notifier leak. * is enabled to avoid notifier leak.
*/ */
__perf_cpu_notifier(intel_cqm_cpu_notifier); cpuhp_setup_state(CPUHP_AP_PERF_X86_CQM_STARTING,
"AP_PERF_X86_CQM_STARTING",
intel_cqm_cpu_starting, NULL);
cpuhp_setup_state(CPUHP_AP_PERF_X86_CQM_ONLINE, "AP_PERF_X86_CQM_ONLINE",
NULL, intel_cqm_cpu_exit);
out: out:
cpu_notifier_register_done(); put_online_cpus();
if (ret) { if (ret) {
kfree(str); kfree(str);
cqm_cleanup(); cqm_cleanup();
......
...@@ -25,6 +25,7 @@ enum cpuhp_state { ...@@ -25,6 +25,7 @@ enum cpuhp_state {
CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING, CPUHP_AP_PERF_X86_AMD_UNCORE_STARTING,
CPUHP_AP_PERF_X86_STARTING, CPUHP_AP_PERF_X86_STARTING,
CPUHP_AP_PERF_X86_AMD_IBS_STARTING, CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
CPUHP_AP_PERF_X86_CQM_STARTING,
CPUHP_AP_NOTIFY_STARTING, CPUHP_AP_NOTIFY_STARTING,
CPUHP_AP_ONLINE, CPUHP_AP_ONLINE,
CPUHP_TEARDOWN_CPU, CPUHP_TEARDOWN_CPU,
...@@ -36,6 +37,7 @@ enum cpuhp_state { ...@@ -36,6 +37,7 @@ enum cpuhp_state {
CPUHP_AP_PERF_X86_UNCORE_ONLINE, CPUHP_AP_PERF_X86_UNCORE_ONLINE,
CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE, CPUHP_AP_PERF_X86_AMD_UNCORE_ONLINE,
CPUHP_AP_PERF_X86_RAPL_ONLINE, CPUHP_AP_PERF_X86_RAPL_ONLINE,
CPUHP_AP_PERF_X86_CQM_ONLINE,
CPUHP_AP_NOTIFY_ONLINE, CPUHP_AP_NOTIFY_ONLINE,
CPUHP_AP_ONLINE_DYN, CPUHP_AP_ONLINE_DYN,
CPUHP_AP_ONLINE_DYN_END = CPUHP_AP_ONLINE_DYN + 30, CPUHP_AP_ONLINE_DYN_END = CPUHP_AP_ONLINE_DYN + 30,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment