ksched: enable pmc global ctrk counter before using the pmc counter.
#include "ksched.h"
#define KSCHED_PMC_PROBE_DELAY (3)
+#define CORE_PERF_GLOBAL_CTRL_ENABLE_PMC_0 (0x1)
+#define CORE_PERF_GLOBAL_CTRL_ENABLE_PMC_1 (0x2)
MODULE_LICENSE("GPL");
@@ -271,10 +273,16 @@ static u64 ksched_measure_pmc(u64 sel)
return end - start;
}
+static void ksched_enable_pmc(void) {
+ wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, CORE_PERF_GLOBAL_CTRL_ENABLE_PMC_0 |
+ CORE_PERF_GLOBAL_CTRL_ENABLE_PMC_1);
+}
+
static void ksched_ipi(void *unused)
{
struct ksched_percpu *p;
struct ksched_shm_cpu *s;
+ static bool pmc_ctrl_enabled[NR_CPUS];
int cpu, tmp;
cpu = get_cpu();
@@ -289,6 +297,11 @@ static void ksched_ipi(void *unused)
/* check if a performance counter has been requested */
tmp = smp_load_acquire(&s->pmc);
if (tmp == p->last_gen) {
+ if (!pmc_ctrl_enabled[cpu]) {
+ ksched_enable_pmc();
+ pmc_ctrl_enabled[cpu] = true;
+ }
+
s->pmcval = ksched_measure_pmc(READ_ONCE(s->pmcsel));
smp_store_release(&s->pmc, 0);
}
