cstate.c (d29859e7777ebc2c8e2db6e4d8e299f50fc26414) cstate.c (c7afba320e91cca46fdf078798002b9ec84be8d3)
1/*
2 * perf_event_intel_cstate.c: support cstate residency counters
3 *
4 * Copyright (C) 2015, Intel Corp.
5 * Author: Kan Liang (kan.liang@intel.com)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public

--- 77 unchanged lines hidden (view full) ---

86 */
87
88#include <linux/module.h>
89#include <linux/slab.h>
90#include <linux/perf_event.h>
91#include <asm/cpu_device_id.h>
92#include "../perf_event.h"
93
1/*
2 * perf_event_intel_cstate.c: support cstate residency counters
3 *
4 * Copyright (C) 2015, Intel Corp.
5 * Author: Kan Liang (kan.liang@intel.com)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public

--- 77 unchanged lines hidden (view full) ---

86 */
87
88#include <linux/module.h>
89#include <linux/slab.h>
90#include <linux/perf_event.h>
91#include <asm/cpu_device_id.h>
92#include "../perf_event.h"
93
94MODULE_LICENSE("GPL");
95
94#define DEFINE_CSTATE_FORMAT_ATTR(_var, _name, _format) \
95static ssize_t __cstate_##_var##_show(struct kobject *kobj, \
96 struct kobj_attribute *attr, \
97 char *page) \
98{ \
99 BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
100 return sprintf(page, _format "\n"); \
101} \

--- 325 unchanged lines hidden (view full) ---

427 cstate_cpu_exit(cpu);
428 break;
429 default:
430 break;
431 }
432 return NOTIFY_OK;
433}
434
96#define DEFINE_CSTATE_FORMAT_ATTR(_var, _name, _format) \
97static ssize_t __cstate_##_var##_show(struct kobject *kobj, \
98 struct kobj_attribute *attr, \
99 char *page) \
100{ \
101 BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
102 return sprintf(page, _format "\n"); \
103} \

--- 325 unchanged lines hidden (view full) ---

429 cstate_cpu_exit(cpu);
430 break;
431 default:
432 break;
433 }
434 return NOTIFY_OK;
435}
436
437static struct notifier_block cstate_cpu_nb = {
438 .notifier_call = cstate_cpu_notifier,
439 .priority = CPU_PRI_PERF + 1,
440};
441
435static struct pmu cstate_core_pmu = {
436 .attr_groups = core_attr_groups,
437 .name = "cstate_core",
438 .task_ctx_nr = perf_invalid_context,
439 .event_init = cstate_pmu_event_init,
440 .add = cstate_pmu_event_add,
441 .del = cstate_pmu_event_del,
442 .start = cstate_pmu_event_start,

--- 133 unchanged lines hidden (view full) ---

576
577 has_cstate_pkg = cstate_probe_msr(cm->pkg_events,
578 PERF_CSTATE_PKG_EVENT_MAX,
579 pkg_msr, pkg_events_attrs);
580
581 return (has_cstate_core || has_cstate_pkg) ? 0 : -ENODEV;
582}
583
442static struct pmu cstate_core_pmu = {
443 .attr_groups = core_attr_groups,
444 .name = "cstate_core",
445 .task_ctx_nr = perf_invalid_context,
446 .event_init = cstate_pmu_event_init,
447 .add = cstate_pmu_event_add,
448 .del = cstate_pmu_event_del,
449 .start = cstate_pmu_event_start,

--- 133 unchanged lines hidden (view full) ---

583
584 has_cstate_pkg = cstate_probe_msr(cm->pkg_events,
585 PERF_CSTATE_PKG_EVENT_MAX,
586 pkg_msr, pkg_events_attrs);
587
588 return (has_cstate_core || has_cstate_pkg) ? 0 : -ENODEV;
589}
590
584static void __init cstate_cleanup(void)
591static inline void cstate_cleanup(void)
585{
586 if (has_cstate_core)
587 perf_pmu_unregister(&cstate_core_pmu);
588
589 if (has_cstate_pkg)
590 perf_pmu_unregister(&cstate_pkg_pmu);
591}
592

--- 18 unchanged lines hidden (view full) ---

611 err = perf_pmu_register(&cstate_pkg_pmu, cstate_pkg_pmu.name, -1);
612 if (err) {
613 has_cstate_pkg = false;
614 pr_info("Failed to register cstate pkg pmu\n");
615 cstate_cleanup();
616 goto out;
617 }
618 }
592{
593 if (has_cstate_core)
594 perf_pmu_unregister(&cstate_core_pmu);
595
596 if (has_cstate_pkg)
597 perf_pmu_unregister(&cstate_pkg_pmu);
598}
599

--- 18 unchanged lines hidden (view full) ---

618 err = perf_pmu_register(&cstate_pkg_pmu, cstate_pkg_pmu.name, -1);
619 if (err) {
620 has_cstate_pkg = false;
621 pr_info("Failed to register cstate pkg pmu\n");
622 cstate_cleanup();
623 goto out;
624 }
625 }
619 __perf_cpu_notifier(cstate_cpu_notifier);
626 __register_cpu_notifier(&cstate_cpu_nb);
620out:
621 cpu_notifier_register_done();
622 return err;
623}
624
625static int __init cstate_pmu_init(void)
626{
627 const struct x86_cpu_id *id;

--- 7 unchanged lines hidden (view full) ---

635 return -ENODEV;
636
637 err = cstate_probe((const struct cstate_model *) id->driver_data);
638 if (err)
639 return err;
640
641 return cstate_init();
642}
627out:
628 cpu_notifier_register_done();
629 return err;
630}
631
632static int __init cstate_pmu_init(void)
633{
634 const struct x86_cpu_id *id;

--- 7 unchanged lines hidden (view full) ---

642 return -ENODEV;
643
644 err = cstate_probe((const struct cstate_model *) id->driver_data);
645 if (err)
646 return err;
647
648 return cstate_init();
649}
643device_initcall(cstate_pmu_init);
650module_init(cstate_pmu_init);
651
652static void __exit cstate_pmu_exit(void)
653{
654 cpu_notifier_register_begin();
655 __unregister_cpu_notifier(&cstate_cpu_nb);
656 cstate_cleanup();
657 cpu_notifier_register_done();
658}
659module_exit(cstate_pmu_exit);