1*a17ae4c3SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2212188a5SHendrik Brueckner /* 3212188a5SHendrik Brueckner * Performance event support for s390x - CPU-measurement Counter Facility 4212188a5SHendrik Brueckner * 5db17160dSHendrik Brueckner * Copyright IBM Corp. 2012, 2017 6212188a5SHendrik Brueckner * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com> 7212188a5SHendrik Brueckner * 8212188a5SHendrik Brueckner * This program is free software; you can redistribute it and/or modify 9212188a5SHendrik Brueckner * it under the terms of the GNU General Public License (version 2 only) 10212188a5SHendrik Brueckner * as published by the Free Software Foundation. 11212188a5SHendrik Brueckner */ 12212188a5SHendrik Brueckner #define KMSG_COMPONENT "cpum_cf" 13212188a5SHendrik Brueckner #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 14212188a5SHendrik Brueckner 15212188a5SHendrik Brueckner #include <linux/kernel.h> 16212188a5SHendrik Brueckner #include <linux/kernel_stat.h> 17212188a5SHendrik Brueckner #include <linux/perf_event.h> 18212188a5SHendrik Brueckner #include <linux/percpu.h> 19212188a5SHendrik Brueckner #include <linux/notifier.h> 20212188a5SHendrik Brueckner #include <linux/init.h> 21212188a5SHendrik Brueckner #include <linux/export.h> 221e3cab2fSHeiko Carstens #include <asm/ctl_reg.h> 23212188a5SHendrik Brueckner #include <asm/irq.h> 24212188a5SHendrik Brueckner #include <asm/cpu_mf.h> 25212188a5SHendrik Brueckner 26212188a5SHendrik Brueckner enum cpumf_ctr_set { 27ee699f32SHendrik Brueckner CPUMF_CTR_SET_BASIC = 0, /* Basic Counter Set */ 28ee699f32SHendrik Brueckner CPUMF_CTR_SET_USER = 1, /* Problem-State Counter Set */ 29ee699f32SHendrik Brueckner CPUMF_CTR_SET_CRYPTO = 2, /* Crypto-Activity Counter Set */ 30ee699f32SHendrik Brueckner CPUMF_CTR_SET_EXT = 3, /* Extended Counter Set */ 31ee699f32SHendrik Brueckner CPUMF_CTR_SET_MT_DIAG = 4, /* MT-diagnostic Counter Set */ 32212188a5SHendrik Brueckner 33212188a5SHendrik Brueckner /* Maximum number of counter sets */ 34212188a5SHendrik Brueckner CPUMF_CTR_SET_MAX, 35212188a5SHendrik Brueckner }; 36212188a5SHendrik Brueckner 37212188a5SHendrik Brueckner #define CPUMF_LCCTL_ENABLE_SHIFT 16 38212188a5SHendrik Brueckner #define CPUMF_LCCTL_ACTCTL_SHIFT 0 39212188a5SHendrik Brueckner static const u64 cpumf_state_ctl[CPUMF_CTR_SET_MAX] = { 40212188a5SHendrik Brueckner [CPUMF_CTR_SET_BASIC] = 0x02, 41212188a5SHendrik Brueckner [CPUMF_CTR_SET_USER] = 0x04, 42212188a5SHendrik Brueckner [CPUMF_CTR_SET_CRYPTO] = 0x08, 43212188a5SHendrik Brueckner [CPUMF_CTR_SET_EXT] = 0x01, 44ee699f32SHendrik Brueckner [CPUMF_CTR_SET_MT_DIAG] = 0x20, 45212188a5SHendrik Brueckner }; 46212188a5SHendrik Brueckner 47212188a5SHendrik Brueckner static void ctr_set_enable(u64 *state, int ctr_set) 48212188a5SHendrik Brueckner { 49212188a5SHendrik Brueckner *state |= cpumf_state_ctl[ctr_set] << CPUMF_LCCTL_ENABLE_SHIFT; 50212188a5SHendrik Brueckner } 51212188a5SHendrik Brueckner static void ctr_set_disable(u64 *state, int ctr_set) 52212188a5SHendrik Brueckner { 53212188a5SHendrik Brueckner *state &= ~(cpumf_state_ctl[ctr_set] << CPUMF_LCCTL_ENABLE_SHIFT); 54212188a5SHendrik Brueckner } 55212188a5SHendrik Brueckner static void ctr_set_start(u64 *state, int ctr_set) 56212188a5SHendrik Brueckner { 57212188a5SHendrik Brueckner *state |= cpumf_state_ctl[ctr_set] << CPUMF_LCCTL_ACTCTL_SHIFT; 58212188a5SHendrik Brueckner } 59212188a5SHendrik Brueckner static void ctr_set_stop(u64 *state, int ctr_set) 60212188a5SHendrik Brueckner { 61212188a5SHendrik Brueckner *state &= ~(cpumf_state_ctl[ctr_set] << CPUMF_LCCTL_ACTCTL_SHIFT); 62212188a5SHendrik Brueckner } 63212188a5SHendrik Brueckner 64212188a5SHendrik Brueckner /* Local CPUMF event structure */ 65212188a5SHendrik Brueckner struct cpu_hw_events { 66212188a5SHendrik Brueckner struct cpumf_ctr_info info; 67212188a5SHendrik Brueckner atomic_t ctr_set[CPUMF_CTR_SET_MAX]; 68212188a5SHendrik Brueckner u64 state, tx_state; 69212188a5SHendrik Brueckner unsigned int flags; 70fbbe0701SSukadev Bhattiprolu unsigned int txn_flags; 71212188a5SHendrik Brueckner }; 72212188a5SHendrik Brueckner static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { 73212188a5SHendrik Brueckner .ctr_set = { 74212188a5SHendrik Brueckner [CPUMF_CTR_SET_BASIC] = ATOMIC_INIT(0), 75212188a5SHendrik Brueckner [CPUMF_CTR_SET_USER] = ATOMIC_INIT(0), 76212188a5SHendrik Brueckner [CPUMF_CTR_SET_CRYPTO] = ATOMIC_INIT(0), 77212188a5SHendrik Brueckner [CPUMF_CTR_SET_EXT] = ATOMIC_INIT(0), 78ee699f32SHendrik Brueckner [CPUMF_CTR_SET_MT_DIAG] = ATOMIC_INIT(0), 79212188a5SHendrik Brueckner }, 80212188a5SHendrik Brueckner .state = 0, 81212188a5SHendrik Brueckner .flags = 0, 82fbbe0701SSukadev Bhattiprolu .txn_flags = 0, 83212188a5SHendrik Brueckner }; 84212188a5SHendrik Brueckner 85ee699f32SHendrik Brueckner static enum cpumf_ctr_set get_counter_set(u64 event) 86212188a5SHendrik Brueckner { 87ee699f32SHendrik Brueckner int set = CPUMF_CTR_SET_MAX; 88212188a5SHendrik Brueckner 89212188a5SHendrik Brueckner if (event < 32) 90212188a5SHendrik Brueckner set = CPUMF_CTR_SET_BASIC; 91212188a5SHendrik Brueckner else if (event < 64) 92212188a5SHendrik Brueckner set = CPUMF_CTR_SET_USER; 93212188a5SHendrik Brueckner else if (event < 128) 94212188a5SHendrik Brueckner set = CPUMF_CTR_SET_CRYPTO; 95f47586b2SHendrik Brueckner else if (event < 256) 96212188a5SHendrik Brueckner set = CPUMF_CTR_SET_EXT; 97ee699f32SHendrik Brueckner else if (event >= 448 && event < 496) 98ee699f32SHendrik Brueckner set = CPUMF_CTR_SET_MT_DIAG; 99212188a5SHendrik Brueckner 100212188a5SHendrik Brueckner return set; 101212188a5SHendrik Brueckner } 102212188a5SHendrik Brueckner 103212188a5SHendrik Brueckner static int validate_ctr_version(const struct hw_perf_event *hwc) 104212188a5SHendrik Brueckner { 105212188a5SHendrik Brueckner struct cpu_hw_events *cpuhw; 106212188a5SHendrik Brueckner int err = 0; 107ee699f32SHendrik Brueckner u16 mtdiag_ctl; 108212188a5SHendrik Brueckner 109212188a5SHendrik Brueckner cpuhw = &get_cpu_var(cpu_hw_events); 110212188a5SHendrik Brueckner 111212188a5SHendrik Brueckner /* check required version for counter sets */ 112212188a5SHendrik Brueckner switch (hwc->config_base) { 113212188a5SHendrik Brueckner case CPUMF_CTR_SET_BASIC: 114212188a5SHendrik Brueckner case CPUMF_CTR_SET_USER: 115212188a5SHendrik Brueckner if (cpuhw->info.cfvn < 1) 116212188a5SHendrik Brueckner err = -EOPNOTSUPP; 117212188a5SHendrik Brueckner break; 118212188a5SHendrik Brueckner case CPUMF_CTR_SET_CRYPTO: 119212188a5SHendrik Brueckner case CPUMF_CTR_SET_EXT: 120212188a5SHendrik Brueckner if (cpuhw->info.csvn < 1) 121212188a5SHendrik Brueckner err = -EOPNOTSUPP; 122f47586b2SHendrik Brueckner if ((cpuhw->info.csvn == 1 && hwc->config > 159) || 123f47586b2SHendrik Brueckner (cpuhw->info.csvn == 2 && hwc->config > 175) || 124f47586b2SHendrik Brueckner (cpuhw->info.csvn > 2 && hwc->config > 255)) 125f47586b2SHendrik Brueckner err = -EOPNOTSUPP; 126212188a5SHendrik Brueckner break; 127ee699f32SHendrik Brueckner case CPUMF_CTR_SET_MT_DIAG: 128ee699f32SHendrik Brueckner if (cpuhw->info.csvn <= 3) 129ee699f32SHendrik Brueckner err = -EOPNOTSUPP; 130ee699f32SHendrik Brueckner /* 131ee699f32SHendrik Brueckner * MT-diagnostic counters are read-only. The counter set 132ee699f32SHendrik Brueckner * is automatically enabled and activated on all CPUs with 133ee699f32SHendrik Brueckner * multithreading (SMT). Deactivation of multithreading 134ee699f32SHendrik Brueckner * also disables the counter set. State changes are ignored 135ee699f32SHendrik Brueckner * by lcctl(). Because Linux controls SMT enablement through 136ee699f32SHendrik Brueckner * a kernel parameter only, the counter set is either disabled 137ee699f32SHendrik Brueckner * or enabled and active. 138ee699f32SHendrik Brueckner * 139ee699f32SHendrik Brueckner * Thus, the counters can only be used if SMT is on and the 140ee699f32SHendrik Brueckner * counter set is enabled and active. 141ee699f32SHendrik Brueckner */ 142ee699f32SHendrik Brueckner mtdiag_ctl = cpumf_state_ctl[CPUMF_CTR_SET_MT_DIAG]; 143ee699f32SHendrik Brueckner if (!((cpuhw->info.auth_ctl & mtdiag_ctl) && 144ee699f32SHendrik Brueckner (cpuhw->info.enable_ctl & mtdiag_ctl) && 145ee699f32SHendrik Brueckner (cpuhw->info.act_ctl & mtdiag_ctl))) 146ee699f32SHendrik Brueckner err = -EOPNOTSUPP; 147ee699f32SHendrik Brueckner break; 148212188a5SHendrik Brueckner } 149212188a5SHendrik Brueckner 150212188a5SHendrik Brueckner put_cpu_var(cpu_hw_events); 151212188a5SHendrik Brueckner return err; 152212188a5SHendrik Brueckner } 153212188a5SHendrik Brueckner 154212188a5SHendrik Brueckner static int validate_ctr_auth(const struct hw_perf_event *hwc) 155212188a5SHendrik Brueckner { 156212188a5SHendrik Brueckner struct cpu_hw_events *cpuhw; 157212188a5SHendrik Brueckner u64 ctrs_state; 158212188a5SHendrik Brueckner int err = 0; 159212188a5SHendrik Brueckner 160212188a5SHendrik Brueckner cpuhw = &get_cpu_var(cpu_hw_events); 161212188a5SHendrik Brueckner 16258f8e9daSHendrik Brueckner /* Check authorization for cpu counter sets. 16358f8e9daSHendrik Brueckner * If the particular CPU counter set is not authorized, 16458f8e9daSHendrik Brueckner * return with -ENOENT in order to fall back to other 16558f8e9daSHendrik Brueckner * PMUs that might suffice the event request. 16658f8e9daSHendrik Brueckner */ 167212188a5SHendrik Brueckner ctrs_state = cpumf_state_ctl[hwc->config_base]; 168212188a5SHendrik Brueckner if (!(ctrs_state & cpuhw->info.auth_ctl)) 16958f8e9daSHendrik Brueckner err = -ENOENT; 170212188a5SHendrik Brueckner 171212188a5SHendrik Brueckner put_cpu_var(cpu_hw_events); 172212188a5SHendrik Brueckner return err; 173212188a5SHendrik Brueckner } 174212188a5SHendrik Brueckner 175212188a5SHendrik Brueckner /* 176212188a5SHendrik Brueckner * Change the CPUMF state to active. 177212188a5SHendrik Brueckner * Enable and activate the CPU-counter sets according 178212188a5SHendrik Brueckner * to the per-cpu control state. 179212188a5SHendrik Brueckner */ 180212188a5SHendrik Brueckner static void cpumf_pmu_enable(struct pmu *pmu) 181212188a5SHendrik Brueckner { 182eb7e7d76SChristoph Lameter struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events); 183212188a5SHendrik Brueckner int err; 184212188a5SHendrik Brueckner 185212188a5SHendrik Brueckner if (cpuhw->flags & PMU_F_ENABLED) 186212188a5SHendrik Brueckner return; 187212188a5SHendrik Brueckner 188212188a5SHendrik Brueckner err = lcctl(cpuhw->state); 189212188a5SHendrik Brueckner if (err) { 190212188a5SHendrik Brueckner pr_err("Enabling the performance measuring unit " 191af0ee94eSHeiko Carstens "failed with rc=%x\n", err); 192212188a5SHendrik Brueckner return; 193212188a5SHendrik Brueckner } 194212188a5SHendrik Brueckner 195212188a5SHendrik Brueckner cpuhw->flags |= PMU_F_ENABLED; 196212188a5SHendrik Brueckner } 197212188a5SHendrik Brueckner 198212188a5SHendrik Brueckner /* 199212188a5SHendrik Brueckner * Change the CPUMF state to inactive. 200212188a5SHendrik Brueckner * Disable and enable (inactive) the CPU-counter sets according 201212188a5SHendrik Brueckner * to the per-cpu control state. 202212188a5SHendrik Brueckner */ 203212188a5SHendrik Brueckner static void cpumf_pmu_disable(struct pmu *pmu) 204212188a5SHendrik Brueckner { 205eb7e7d76SChristoph Lameter struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events); 206212188a5SHendrik Brueckner int err; 207212188a5SHendrik Brueckner u64 inactive; 208212188a5SHendrik Brueckner 209212188a5SHendrik Brueckner if (!(cpuhw->flags & PMU_F_ENABLED)) 210212188a5SHendrik Brueckner return; 211212188a5SHendrik Brueckner 212212188a5SHendrik Brueckner inactive = cpuhw->state & ~((1 << CPUMF_LCCTL_ENABLE_SHIFT) - 1); 213212188a5SHendrik Brueckner err = lcctl(inactive); 214212188a5SHendrik Brueckner if (err) { 215212188a5SHendrik Brueckner pr_err("Disabling the performance measuring unit " 216af0ee94eSHeiko Carstens "failed with rc=%x\n", err); 217212188a5SHendrik Brueckner return; 218212188a5SHendrik Brueckner } 219212188a5SHendrik Brueckner 220212188a5SHendrik Brueckner cpuhw->flags &= ~PMU_F_ENABLED; 221212188a5SHendrik Brueckner } 222212188a5SHendrik Brueckner 223212188a5SHendrik Brueckner 224212188a5SHendrik Brueckner /* Number of perf events counting hardware events */ 225212188a5SHendrik Brueckner static atomic_t num_events = ATOMIC_INIT(0); 226212188a5SHendrik Brueckner /* Used to avoid races in calling reserve/release_cpumf_hardware */ 227212188a5SHendrik Brueckner static DEFINE_MUTEX(pmc_reserve_mutex); 228212188a5SHendrik Brueckner 229212188a5SHendrik Brueckner /* CPU-measurement alerts for the counter facility */ 230212188a5SHendrik Brueckner static void cpumf_measurement_alert(struct ext_code ext_code, 231212188a5SHendrik Brueckner unsigned int alert, unsigned long unused) 232212188a5SHendrik Brueckner { 233212188a5SHendrik Brueckner struct cpu_hw_events *cpuhw; 234212188a5SHendrik Brueckner 235212188a5SHendrik Brueckner if (!(alert & CPU_MF_INT_CF_MASK)) 236212188a5SHendrik Brueckner return; 237212188a5SHendrik Brueckner 238420f42ecSHeiko Carstens inc_irq_stat(IRQEXT_CMC); 239eb7e7d76SChristoph Lameter cpuhw = this_cpu_ptr(&cpu_hw_events); 240212188a5SHendrik Brueckner 241212188a5SHendrik Brueckner /* Measurement alerts are shared and might happen when the PMU 242212188a5SHendrik Brueckner * is not reserved. Ignore these alerts in this case. */ 243212188a5SHendrik Brueckner if (!(cpuhw->flags & PMU_F_RESERVED)) 244212188a5SHendrik Brueckner return; 245212188a5SHendrik Brueckner 246212188a5SHendrik Brueckner /* counter authorization change alert */ 247212188a5SHendrik Brueckner if (alert & CPU_MF_INT_CF_CACA) 248212188a5SHendrik Brueckner qctri(&cpuhw->info); 249212188a5SHendrik Brueckner 250212188a5SHendrik Brueckner /* loss of counter data alert */ 251212188a5SHendrik Brueckner if (alert & CPU_MF_INT_CF_LCDA) 252212188a5SHendrik Brueckner pr_err("CPU[%i] Counter data was lost\n", smp_processor_id()); 253ee699f32SHendrik Brueckner 254ee699f32SHendrik Brueckner /* loss of MT counter data alert */ 255ee699f32SHendrik Brueckner if (alert & CPU_MF_INT_CF_MTDA) 256ee699f32SHendrik Brueckner pr_warn("CPU[%i] MT counter data was lost\n", 257ee699f32SHendrik Brueckner smp_processor_id()); 258212188a5SHendrik Brueckner } 259212188a5SHendrik Brueckner 260212188a5SHendrik Brueckner #define PMC_INIT 0 261212188a5SHendrik Brueckner #define PMC_RELEASE 1 262212188a5SHendrik Brueckner static void setup_pmc_cpu(void *flags) 263212188a5SHendrik Brueckner { 264eb7e7d76SChristoph Lameter struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events); 265212188a5SHendrik Brueckner 266212188a5SHendrik Brueckner switch (*((int *) flags)) { 267212188a5SHendrik Brueckner case PMC_INIT: 268212188a5SHendrik Brueckner memset(&cpuhw->info, 0, sizeof(cpuhw->info)); 269212188a5SHendrik Brueckner qctri(&cpuhw->info); 270212188a5SHendrik Brueckner cpuhw->flags |= PMU_F_RESERVED; 271212188a5SHendrik Brueckner break; 272212188a5SHendrik Brueckner 273212188a5SHendrik Brueckner case PMC_RELEASE: 274212188a5SHendrik Brueckner cpuhw->flags &= ~PMU_F_RESERVED; 275212188a5SHendrik Brueckner break; 276212188a5SHendrik Brueckner } 277212188a5SHendrik Brueckner 278212188a5SHendrik Brueckner /* Disable CPU counter sets */ 279212188a5SHendrik Brueckner lcctl(0); 280212188a5SHendrik Brueckner } 281212188a5SHendrik Brueckner 282212188a5SHendrik Brueckner /* Initialize the CPU-measurement facility */ 283212188a5SHendrik Brueckner static int reserve_pmc_hardware(void) 284212188a5SHendrik Brueckner { 285212188a5SHendrik Brueckner int flags = PMC_INIT; 286212188a5SHendrik Brueckner 287212188a5SHendrik Brueckner on_each_cpu(setup_pmc_cpu, &flags, 1); 28882003c3eSHeiko Carstens irq_subclass_register(IRQ_SUBCLASS_MEASUREMENT_ALERT); 289212188a5SHendrik Brueckner 290212188a5SHendrik Brueckner return 0; 291212188a5SHendrik Brueckner } 292212188a5SHendrik Brueckner 293212188a5SHendrik Brueckner /* Release the CPU-measurement facility */ 294212188a5SHendrik Brueckner static void release_pmc_hardware(void) 295212188a5SHendrik Brueckner { 296212188a5SHendrik Brueckner int flags = PMC_RELEASE; 297212188a5SHendrik Brueckner 298212188a5SHendrik Brueckner on_each_cpu(setup_pmc_cpu, &flags, 1); 29982003c3eSHeiko Carstens irq_subclass_unregister(IRQ_SUBCLASS_MEASUREMENT_ALERT); 300212188a5SHendrik Brueckner } 301212188a5SHendrik Brueckner 302212188a5SHendrik Brueckner /* Release the PMU if event is the last perf event */ 303212188a5SHendrik Brueckner static void hw_perf_event_destroy(struct perf_event *event) 304212188a5SHendrik Brueckner { 305212188a5SHendrik Brueckner if (!atomic_add_unless(&num_events, -1, 1)) { 306212188a5SHendrik Brueckner mutex_lock(&pmc_reserve_mutex); 307212188a5SHendrik Brueckner if (atomic_dec_return(&num_events) == 0) 308212188a5SHendrik Brueckner release_pmc_hardware(); 309212188a5SHendrik Brueckner mutex_unlock(&pmc_reserve_mutex); 310212188a5SHendrik Brueckner } 311212188a5SHendrik Brueckner } 312212188a5SHendrik Brueckner 313212188a5SHendrik Brueckner /* CPUMF <-> perf event mappings for kernel+userspace (basic set) */ 314212188a5SHendrik Brueckner static const int cpumf_generic_events_basic[] = { 315212188a5SHendrik Brueckner [PERF_COUNT_HW_CPU_CYCLES] = 0, 316212188a5SHendrik Brueckner [PERF_COUNT_HW_INSTRUCTIONS] = 1, 317212188a5SHendrik Brueckner [PERF_COUNT_HW_CACHE_REFERENCES] = -1, 318212188a5SHendrik Brueckner [PERF_COUNT_HW_CACHE_MISSES] = -1, 319212188a5SHendrik Brueckner [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = -1, 320212188a5SHendrik Brueckner [PERF_COUNT_HW_BRANCH_MISSES] = -1, 321212188a5SHendrik Brueckner [PERF_COUNT_HW_BUS_CYCLES] = -1, 322212188a5SHendrik Brueckner }; 323212188a5SHendrik Brueckner /* CPUMF <-> perf event mappings for userspace (problem-state set) */ 324212188a5SHendrik Brueckner static const int cpumf_generic_events_user[] = { 325212188a5SHendrik Brueckner [PERF_COUNT_HW_CPU_CYCLES] = 32, 326212188a5SHendrik Brueckner [PERF_COUNT_HW_INSTRUCTIONS] = 33, 327212188a5SHendrik Brueckner [PERF_COUNT_HW_CACHE_REFERENCES] = -1, 328212188a5SHendrik Brueckner [PERF_COUNT_HW_CACHE_MISSES] = -1, 329212188a5SHendrik Brueckner [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = -1, 330212188a5SHendrik Brueckner [PERF_COUNT_HW_BRANCH_MISSES] = -1, 331212188a5SHendrik Brueckner [PERF_COUNT_HW_BUS_CYCLES] = -1, 332212188a5SHendrik Brueckner }; 333212188a5SHendrik Brueckner 334212188a5SHendrik Brueckner static int __hw_perf_event_init(struct perf_event *event) 335212188a5SHendrik Brueckner { 336212188a5SHendrik Brueckner struct perf_event_attr *attr = &event->attr; 337212188a5SHendrik Brueckner struct hw_perf_event *hwc = &event->hw; 338ee699f32SHendrik Brueckner enum cpumf_ctr_set set; 339212188a5SHendrik Brueckner int err; 340212188a5SHendrik Brueckner u64 ev; 341212188a5SHendrik Brueckner 342212188a5SHendrik Brueckner switch (attr->type) { 343212188a5SHendrik Brueckner case PERF_TYPE_RAW: 344212188a5SHendrik Brueckner /* Raw events are used to access counters directly, 345212188a5SHendrik Brueckner * hence do not permit excludes */ 346212188a5SHendrik Brueckner if (attr->exclude_kernel || attr->exclude_user || 347212188a5SHendrik Brueckner attr->exclude_hv) 348212188a5SHendrik Brueckner return -EOPNOTSUPP; 349212188a5SHendrik Brueckner ev = attr->config; 350212188a5SHendrik Brueckner break; 351212188a5SHendrik Brueckner 352212188a5SHendrik Brueckner case PERF_TYPE_HARDWARE: 353212188a5SHendrik Brueckner ev = attr->config; 354212188a5SHendrik Brueckner /* Count user space (problem-state) only */ 355212188a5SHendrik Brueckner if (!attr->exclude_user && attr->exclude_kernel) { 356212188a5SHendrik Brueckner if (ev >= ARRAY_SIZE(cpumf_generic_events_user)) 357212188a5SHendrik Brueckner return -EOPNOTSUPP; 358212188a5SHendrik Brueckner ev = cpumf_generic_events_user[ev]; 359212188a5SHendrik Brueckner 360212188a5SHendrik Brueckner /* No support for kernel space counters only */ 361212188a5SHendrik Brueckner } else if (!attr->exclude_kernel && attr->exclude_user) { 362212188a5SHendrik Brueckner return -EOPNOTSUPP; 363212188a5SHendrik Brueckner 364212188a5SHendrik Brueckner /* Count user and kernel space */ 365212188a5SHendrik Brueckner } else { 366212188a5SHendrik Brueckner if (ev >= ARRAY_SIZE(cpumf_generic_events_basic)) 367212188a5SHendrik Brueckner return -EOPNOTSUPP; 368212188a5SHendrik Brueckner ev = cpumf_generic_events_basic[ev]; 369212188a5SHendrik Brueckner } 370212188a5SHendrik Brueckner break; 371212188a5SHendrik Brueckner 372212188a5SHendrik Brueckner default: 373212188a5SHendrik Brueckner return -ENOENT; 374212188a5SHendrik Brueckner } 375212188a5SHendrik Brueckner 376212188a5SHendrik Brueckner if (ev == -1) 377212188a5SHendrik Brueckner return -ENOENT; 378212188a5SHendrik Brueckner 37920ba46daSHendrik Brueckner if (ev > PERF_CPUM_CF_MAX_CTR) 380212188a5SHendrik Brueckner return -EINVAL; 381212188a5SHendrik Brueckner 382ee699f32SHendrik Brueckner /* Obtain the counter set to which the specified counter belongs */ 383ee699f32SHendrik Brueckner set = get_counter_set(ev); 384ee699f32SHendrik Brueckner switch (set) { 385ee699f32SHendrik Brueckner case CPUMF_CTR_SET_BASIC: 386ee699f32SHendrik Brueckner case CPUMF_CTR_SET_USER: 387ee699f32SHendrik Brueckner case CPUMF_CTR_SET_CRYPTO: 388ee699f32SHendrik Brueckner case CPUMF_CTR_SET_EXT: 389ee699f32SHendrik Brueckner case CPUMF_CTR_SET_MT_DIAG: 390ee699f32SHendrik Brueckner /* 391ee699f32SHendrik Brueckner * Use the hardware perf event structure to store the 392ee699f32SHendrik Brueckner * counter number in the 'config' member and the counter 393ee699f32SHendrik Brueckner * set number in the 'config_base'. The counter set number 394ee699f32SHendrik Brueckner * is then later used to enable/disable the counter(s). 395212188a5SHendrik Brueckner */ 396212188a5SHendrik Brueckner hwc->config = ev; 397ee699f32SHendrik Brueckner hwc->config_base = set; 398ee699f32SHendrik Brueckner break; 399ee699f32SHendrik Brueckner case CPUMF_CTR_SET_MAX: 400ee699f32SHendrik Brueckner /* The counter could not be associated to a counter set */ 401ee699f32SHendrik Brueckner return -EINVAL; 402ee699f32SHendrik Brueckner }; 403212188a5SHendrik Brueckner 404212188a5SHendrik Brueckner /* Initialize for using the CPU-measurement counter facility */ 405212188a5SHendrik Brueckner if (!atomic_inc_not_zero(&num_events)) { 406212188a5SHendrik Brueckner mutex_lock(&pmc_reserve_mutex); 407212188a5SHendrik Brueckner if (atomic_read(&num_events) == 0 && reserve_pmc_hardware()) 408212188a5SHendrik Brueckner err = -EBUSY; 409212188a5SHendrik Brueckner else 410212188a5SHendrik Brueckner atomic_inc(&num_events); 411212188a5SHendrik Brueckner mutex_unlock(&pmc_reserve_mutex); 412212188a5SHendrik Brueckner } 413212188a5SHendrik Brueckner event->destroy = hw_perf_event_destroy; 414212188a5SHendrik Brueckner 415212188a5SHendrik Brueckner /* Finally, validate version and authorization of the counter set */ 416212188a5SHendrik Brueckner err = validate_ctr_auth(hwc); 417212188a5SHendrik Brueckner if (!err) 418212188a5SHendrik Brueckner err = validate_ctr_version(hwc); 419212188a5SHendrik Brueckner 420212188a5SHendrik Brueckner return err; 421212188a5SHendrik Brueckner } 422212188a5SHendrik Brueckner 423212188a5SHendrik Brueckner static int cpumf_pmu_event_init(struct perf_event *event) 424212188a5SHendrik Brueckner { 425212188a5SHendrik Brueckner int err; 426212188a5SHendrik Brueckner 427212188a5SHendrik Brueckner switch (event->attr.type) { 428212188a5SHendrik Brueckner case PERF_TYPE_HARDWARE: 429212188a5SHendrik Brueckner case PERF_TYPE_HW_CACHE: 430212188a5SHendrik Brueckner case PERF_TYPE_RAW: 431212188a5SHendrik Brueckner err = __hw_perf_event_init(event); 432212188a5SHendrik Brueckner break; 433212188a5SHendrik Brueckner default: 434212188a5SHendrik Brueckner return -ENOENT; 435212188a5SHendrik Brueckner } 436212188a5SHendrik Brueckner 437212188a5SHendrik Brueckner if (unlikely(err) && event->destroy) 438212188a5SHendrik Brueckner event->destroy(event); 439212188a5SHendrik Brueckner 440212188a5SHendrik Brueckner return err; 441212188a5SHendrik Brueckner } 442212188a5SHendrik Brueckner 443212188a5SHendrik Brueckner static int hw_perf_event_reset(struct perf_event *event) 444212188a5SHendrik Brueckner { 445212188a5SHendrik Brueckner u64 prev, new; 446212188a5SHendrik Brueckner int err; 447212188a5SHendrik Brueckner 448212188a5SHendrik Brueckner do { 449212188a5SHendrik Brueckner prev = local64_read(&event->hw.prev_count); 450212188a5SHendrik Brueckner err = ecctr(event->hw.config, &new); 451212188a5SHendrik Brueckner if (err) { 452212188a5SHendrik Brueckner if (err != 3) 453212188a5SHendrik Brueckner break; 454212188a5SHendrik Brueckner /* The counter is not (yet) available. This 455212188a5SHendrik Brueckner * might happen if the counter set to which 456212188a5SHendrik Brueckner * this counter belongs is in the disabled 457212188a5SHendrik Brueckner * state. 458212188a5SHendrik Brueckner */ 459212188a5SHendrik Brueckner new = 0; 460212188a5SHendrik Brueckner } 461212188a5SHendrik Brueckner } while (local64_cmpxchg(&event->hw.prev_count, prev, new) != prev); 462212188a5SHendrik Brueckner 463212188a5SHendrik Brueckner return err; 464212188a5SHendrik Brueckner } 465212188a5SHendrik Brueckner 466485527baSHendrik Brueckner static void hw_perf_event_update(struct perf_event *event) 467212188a5SHendrik Brueckner { 468212188a5SHendrik Brueckner u64 prev, new, delta; 469212188a5SHendrik Brueckner int err; 470212188a5SHendrik Brueckner 471212188a5SHendrik Brueckner do { 472212188a5SHendrik Brueckner prev = local64_read(&event->hw.prev_count); 473212188a5SHendrik Brueckner err = ecctr(event->hw.config, &new); 474212188a5SHendrik Brueckner if (err) 475485527baSHendrik Brueckner return; 476212188a5SHendrik Brueckner } while (local64_cmpxchg(&event->hw.prev_count, prev, new) != prev); 477212188a5SHendrik Brueckner 478212188a5SHendrik Brueckner delta = (prev <= new) ? new - prev 479212188a5SHendrik Brueckner : (-1ULL - prev) + new + 1; /* overflow */ 480212188a5SHendrik Brueckner local64_add(delta, &event->count); 481212188a5SHendrik Brueckner } 482212188a5SHendrik Brueckner 483212188a5SHendrik Brueckner static void cpumf_pmu_read(struct perf_event *event) 484212188a5SHendrik Brueckner { 485212188a5SHendrik Brueckner if (event->hw.state & PERF_HES_STOPPED) 486212188a5SHendrik Brueckner return; 487212188a5SHendrik Brueckner 488212188a5SHendrik Brueckner hw_perf_event_update(event); 489212188a5SHendrik Brueckner } 490212188a5SHendrik Brueckner 491212188a5SHendrik Brueckner static void cpumf_pmu_start(struct perf_event *event, int flags) 492212188a5SHendrik Brueckner { 493eb7e7d76SChristoph Lameter struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events); 494212188a5SHendrik Brueckner struct hw_perf_event *hwc = &event->hw; 495212188a5SHendrik Brueckner 496212188a5SHendrik Brueckner if (WARN_ON_ONCE(!(hwc->state & PERF_HES_STOPPED))) 497212188a5SHendrik Brueckner return; 498212188a5SHendrik Brueckner 499212188a5SHendrik Brueckner if (WARN_ON_ONCE(hwc->config == -1)) 500212188a5SHendrik Brueckner return; 501212188a5SHendrik Brueckner 502212188a5SHendrik Brueckner if (flags & PERF_EF_RELOAD) 503212188a5SHendrik Brueckner WARN_ON_ONCE(!(hwc->state & PERF_HES_UPTODATE)); 504212188a5SHendrik Brueckner 505212188a5SHendrik Brueckner hwc->state = 0; 506212188a5SHendrik Brueckner 507212188a5SHendrik Brueckner /* (Re-)enable and activate the counter set */ 508212188a5SHendrik Brueckner ctr_set_enable(&cpuhw->state, hwc->config_base); 509212188a5SHendrik Brueckner ctr_set_start(&cpuhw->state, hwc->config_base); 510212188a5SHendrik Brueckner 511212188a5SHendrik Brueckner /* The counter set to which this counter belongs can be already active. 512212188a5SHendrik Brueckner * Because all counters in a set are active, the event->hw.prev_count 513212188a5SHendrik Brueckner * needs to be synchronized. At this point, the counter set can be in 514212188a5SHendrik Brueckner * the inactive or disabled state. 515212188a5SHendrik Brueckner */ 516212188a5SHendrik Brueckner hw_perf_event_reset(event); 517212188a5SHendrik Brueckner 518212188a5SHendrik Brueckner /* increment refcount for this counter set */ 519212188a5SHendrik Brueckner atomic_inc(&cpuhw->ctr_set[hwc->config_base]); 520212188a5SHendrik Brueckner } 521212188a5SHendrik Brueckner 522212188a5SHendrik Brueckner static void cpumf_pmu_stop(struct perf_event *event, int flags) 523212188a5SHendrik Brueckner { 524eb7e7d76SChristoph Lameter struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events); 525212188a5SHendrik Brueckner struct hw_perf_event *hwc = &event->hw; 526212188a5SHendrik Brueckner 527212188a5SHendrik Brueckner if (!(hwc->state & PERF_HES_STOPPED)) { 528212188a5SHendrik Brueckner /* Decrement reference count for this counter set and if this 529212188a5SHendrik Brueckner * is the last used counter in the set, clear activation 530212188a5SHendrik Brueckner * control and set the counter set state to inactive. 531212188a5SHendrik Brueckner */ 532212188a5SHendrik Brueckner if (!atomic_dec_return(&cpuhw->ctr_set[hwc->config_base])) 533212188a5SHendrik Brueckner ctr_set_stop(&cpuhw->state, hwc->config_base); 534212188a5SHendrik Brueckner event->hw.state |= PERF_HES_STOPPED; 535212188a5SHendrik Brueckner } 536212188a5SHendrik Brueckner 537212188a5SHendrik Brueckner if ((flags & PERF_EF_UPDATE) && !(hwc->state & PERF_HES_UPTODATE)) { 538212188a5SHendrik Brueckner hw_perf_event_update(event); 539212188a5SHendrik Brueckner event->hw.state |= PERF_HES_UPTODATE; 540212188a5SHendrik Brueckner } 541212188a5SHendrik Brueckner } 542212188a5SHendrik Brueckner 543212188a5SHendrik Brueckner static int cpumf_pmu_add(struct perf_event *event, int flags) 544212188a5SHendrik Brueckner { 545eb7e7d76SChristoph Lameter struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events); 546212188a5SHendrik Brueckner 547212188a5SHendrik Brueckner /* Check authorization for the counter set to which this 548212188a5SHendrik Brueckner * counter belongs. 549212188a5SHendrik Brueckner * For group events transaction, the authorization check is 550212188a5SHendrik Brueckner * done in cpumf_pmu_commit_txn(). 551212188a5SHendrik Brueckner */ 5528f3e5684SSukadev Bhattiprolu if (!(cpuhw->txn_flags & PERF_PMU_TXN_ADD)) 553212188a5SHendrik Brueckner if (validate_ctr_auth(&event->hw)) 55458f8e9daSHendrik Brueckner return -ENOENT; 555212188a5SHendrik Brueckner 556212188a5SHendrik Brueckner ctr_set_enable(&cpuhw->state, event->hw.config_base); 557212188a5SHendrik Brueckner event->hw.state = PERF_HES_UPTODATE | PERF_HES_STOPPED; 558212188a5SHendrik Brueckner 559212188a5SHendrik Brueckner if (flags & PERF_EF_START) 560212188a5SHendrik Brueckner cpumf_pmu_start(event, PERF_EF_RELOAD); 561212188a5SHendrik Brueckner 562212188a5SHendrik Brueckner perf_event_update_userpage(event); 563212188a5SHendrik Brueckner 564212188a5SHendrik Brueckner return 0; 565212188a5SHendrik Brueckner } 566212188a5SHendrik Brueckner 567212188a5SHendrik Brueckner static void cpumf_pmu_del(struct perf_event *event, int flags) 568212188a5SHendrik Brueckner { 569eb7e7d76SChristoph Lameter struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events); 570212188a5SHendrik Brueckner 571212188a5SHendrik Brueckner cpumf_pmu_stop(event, PERF_EF_UPDATE); 572212188a5SHendrik Brueckner 573212188a5SHendrik Brueckner /* Check if any counter in the counter set is still used. If not used, 574212188a5SHendrik Brueckner * change the counter set to the disabled state. This also clears the 575212188a5SHendrik Brueckner * content of all counters in the set. 576212188a5SHendrik Brueckner * 577212188a5SHendrik Brueckner * When a new perf event has been added but not yet started, this can 578212188a5SHendrik Brueckner * clear enable control and resets all counters in a set. Therefore, 579212188a5SHendrik Brueckner * cpumf_pmu_start() always has to reenable a counter set. 580212188a5SHendrik Brueckner */ 581212188a5SHendrik Brueckner if (!atomic_read(&cpuhw->ctr_set[event->hw.config_base])) 582212188a5SHendrik Brueckner ctr_set_disable(&cpuhw->state, event->hw.config_base); 583212188a5SHendrik Brueckner 584212188a5SHendrik Brueckner perf_event_update_userpage(event); 585212188a5SHendrik Brueckner } 586212188a5SHendrik Brueckner 587212188a5SHendrik Brueckner /* 588212188a5SHendrik Brueckner * Start group events scheduling transaction. 589212188a5SHendrik Brueckner * Set flags to perform a single test at commit time. 590fbbe0701SSukadev Bhattiprolu * 591fbbe0701SSukadev Bhattiprolu * We only support PERF_PMU_TXN_ADD transactions. Save the 592fbbe0701SSukadev Bhattiprolu * transaction flags but otherwise ignore non-PERF_PMU_TXN_ADD 593fbbe0701SSukadev Bhattiprolu * transactions. 594212188a5SHendrik Brueckner */ 595fbbe0701SSukadev Bhattiprolu static void cpumf_pmu_start_txn(struct pmu *pmu, unsigned int txn_flags) 596212188a5SHendrik Brueckner { 597eb7e7d76SChristoph Lameter struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events); 598212188a5SHendrik Brueckner 599fbbe0701SSukadev Bhattiprolu WARN_ON_ONCE(cpuhw->txn_flags); /* txn already in flight */ 600fbbe0701SSukadev Bhattiprolu 601fbbe0701SSukadev Bhattiprolu cpuhw->txn_flags = txn_flags; 602fbbe0701SSukadev Bhattiprolu if (txn_flags & ~PERF_PMU_TXN_ADD) 603fbbe0701SSukadev Bhattiprolu return; 604fbbe0701SSukadev Bhattiprolu 605212188a5SHendrik Brueckner perf_pmu_disable(pmu); 606212188a5SHendrik Brueckner cpuhw->tx_state = cpuhw->state; 607212188a5SHendrik Brueckner } 608212188a5SHendrik Brueckner 609212188a5SHendrik Brueckner /* 610212188a5SHendrik Brueckner * Stop and cancel a group events scheduling tranctions. 611212188a5SHendrik Brueckner * Assumes cpumf_pmu_del() is called for each successful added 612212188a5SHendrik Brueckner * cpumf_pmu_add() during the transaction. 613212188a5SHendrik Brueckner */ 614212188a5SHendrik Brueckner static void cpumf_pmu_cancel_txn(struct pmu *pmu) 615212188a5SHendrik Brueckner { 616fbbe0701SSukadev Bhattiprolu unsigned int txn_flags; 617eb7e7d76SChristoph Lameter struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events); 618212188a5SHendrik Brueckner 619fbbe0701SSukadev Bhattiprolu WARN_ON_ONCE(!cpuhw->txn_flags); /* no txn in flight */ 620fbbe0701SSukadev Bhattiprolu 621fbbe0701SSukadev Bhattiprolu txn_flags = cpuhw->txn_flags; 622fbbe0701SSukadev Bhattiprolu cpuhw->txn_flags = 0; 623fbbe0701SSukadev Bhattiprolu if (txn_flags & ~PERF_PMU_TXN_ADD) 624fbbe0701SSukadev Bhattiprolu return; 625fbbe0701SSukadev Bhattiprolu 626212188a5SHendrik Brueckner WARN_ON(cpuhw->tx_state != cpuhw->state); 627212188a5SHendrik Brueckner 628212188a5SHendrik Brueckner perf_pmu_enable(pmu); 629212188a5SHendrik Brueckner } 630212188a5SHendrik Brueckner 631212188a5SHendrik Brueckner /* 632212188a5SHendrik Brueckner * Commit the group events scheduling transaction. On success, the 633212188a5SHendrik Brueckner * transaction is closed. On error, the transaction is kept open 634212188a5SHendrik Brueckner * until cpumf_pmu_cancel_txn() is called. 635212188a5SHendrik Brueckner */ 636212188a5SHendrik Brueckner static int cpumf_pmu_commit_txn(struct pmu *pmu) 637212188a5SHendrik Brueckner { 638eb7e7d76SChristoph Lameter struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events); 639212188a5SHendrik Brueckner u64 state; 640212188a5SHendrik Brueckner 641fbbe0701SSukadev Bhattiprolu WARN_ON_ONCE(!cpuhw->txn_flags); /* no txn in flight */ 642fbbe0701SSukadev Bhattiprolu 643fbbe0701SSukadev Bhattiprolu if (cpuhw->txn_flags & ~PERF_PMU_TXN_ADD) { 644fbbe0701SSukadev Bhattiprolu cpuhw->txn_flags = 0; 645fbbe0701SSukadev Bhattiprolu return 0; 646fbbe0701SSukadev Bhattiprolu } 647fbbe0701SSukadev Bhattiprolu 648212188a5SHendrik Brueckner /* check if the updated state can be scheduled */ 649212188a5SHendrik Brueckner state = cpuhw->state & ~((1 << CPUMF_LCCTL_ENABLE_SHIFT) - 1); 650212188a5SHendrik Brueckner state >>= CPUMF_LCCTL_ENABLE_SHIFT; 651212188a5SHendrik Brueckner if ((state & cpuhw->info.auth_ctl) != state) 65258f8e9daSHendrik Brueckner return -ENOENT; 653212188a5SHendrik Brueckner 654fbbe0701SSukadev Bhattiprolu cpuhw->txn_flags = 0; 655212188a5SHendrik Brueckner perf_pmu_enable(pmu); 656212188a5SHendrik Brueckner return 0; 657212188a5SHendrik Brueckner } 658212188a5SHendrik Brueckner 659212188a5SHendrik Brueckner /* Performance monitoring unit for s390x */ 660212188a5SHendrik Brueckner static struct pmu cpumf_pmu = { 6619254e70cSHendrik Brueckner .task_ctx_nr = perf_sw_context, 6629254e70cSHendrik Brueckner .capabilities = PERF_PMU_CAP_NO_INTERRUPT, 663212188a5SHendrik Brueckner .pmu_enable = cpumf_pmu_enable, 664212188a5SHendrik Brueckner .pmu_disable = cpumf_pmu_disable, 665212188a5SHendrik Brueckner .event_init = cpumf_pmu_event_init, 666212188a5SHendrik Brueckner .add = cpumf_pmu_add, 667212188a5SHendrik Brueckner .del = cpumf_pmu_del, 668212188a5SHendrik Brueckner .start = cpumf_pmu_start, 669212188a5SHendrik Brueckner .stop = cpumf_pmu_stop, 670212188a5SHendrik Brueckner .read = cpumf_pmu_read, 671212188a5SHendrik Brueckner .start_txn = cpumf_pmu_start_txn, 672212188a5SHendrik Brueckner .commit_txn = cpumf_pmu_commit_txn, 673212188a5SHendrik Brueckner .cancel_txn = cpumf_pmu_cancel_txn, 674212188a5SHendrik Brueckner }; 675212188a5SHendrik Brueckner 6764f0f8217SThomas Gleixner static int cpumf_pmf_setup(unsigned int cpu, int flags) 677212188a5SHendrik Brueckner { 6785bc73539SAnna-Maria Gleixner local_irq_disable(); 6795bc73539SAnna-Maria Gleixner setup_pmc_cpu(&flags); 6805bc73539SAnna-Maria Gleixner local_irq_enable(); 6814f0f8217SThomas Gleixner return 0; 682212188a5SHendrik Brueckner } 683212188a5SHendrik Brueckner 6844f0f8217SThomas Gleixner static int s390_pmu_online_cpu(unsigned int cpu) 6854f0f8217SThomas Gleixner { 6864f0f8217SThomas Gleixner return cpumf_pmf_setup(cpu, PMC_INIT); 6874f0f8217SThomas Gleixner } 6884f0f8217SThomas Gleixner 6894f0f8217SThomas Gleixner static int s390_pmu_offline_cpu(unsigned int cpu) 6904f0f8217SThomas Gleixner { 6914f0f8217SThomas Gleixner return cpumf_pmf_setup(cpu, PMC_RELEASE); 692212188a5SHendrik Brueckner } 693212188a5SHendrik Brueckner 694212188a5SHendrik Brueckner static int __init cpumf_pmu_init(void) 695212188a5SHendrik Brueckner { 696212188a5SHendrik Brueckner int rc; 697212188a5SHendrik Brueckner 698212188a5SHendrik Brueckner if (!cpum_cf_avail()) 699212188a5SHendrik Brueckner return -ENODEV; 700212188a5SHendrik Brueckner 701212188a5SHendrik Brueckner /* clear bit 15 of cr0 to unauthorize problem-state to 702212188a5SHendrik Brueckner * extract measurement counters */ 703212188a5SHendrik Brueckner ctl_clear_bit(0, 48); 704212188a5SHendrik Brueckner 705212188a5SHendrik Brueckner /* register handler for measurement-alert interruptions */ 7061dad093bSThomas Huth rc = register_external_irq(EXT_IRQ_MEASURE_ALERT, 7071dad093bSThomas Huth cpumf_measurement_alert); 708212188a5SHendrik Brueckner if (rc) { 709212188a5SHendrik Brueckner pr_err("Registering for CPU-measurement alerts " 710212188a5SHendrik Brueckner "failed with rc=%i\n", rc); 7114f0f8217SThomas Gleixner return rc; 712212188a5SHendrik Brueckner } 713212188a5SHendrik Brueckner 714c7168325SHendrik Brueckner cpumf_pmu.attr_groups = cpumf_cf_event_group(); 715212188a5SHendrik Brueckner rc = perf_pmu_register(&cpumf_pmu, "cpum_cf", PERF_TYPE_RAW); 716212188a5SHendrik Brueckner if (rc) { 717212188a5SHendrik Brueckner pr_err("Registering the cpum_cf PMU failed with rc=%i\n", rc); 7181dad093bSThomas Huth unregister_external_irq(EXT_IRQ_MEASURE_ALERT, 7191dad093bSThomas Huth cpumf_measurement_alert); 720212188a5SHendrik Brueckner return rc; 721212188a5SHendrik Brueckner } 7224f0f8217SThomas Gleixner return cpuhp_setup_state(CPUHP_AP_PERF_S390_CF_ONLINE, 72373c1b41eSThomas Gleixner "perf/s390/cf:online", 7244f0f8217SThomas Gleixner s390_pmu_online_cpu, s390_pmu_offline_cpu); 7254f0f8217SThomas Gleixner } 726212188a5SHendrik Brueckner early_initcall(cpumf_pmu_init); 727