1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel Running Average Power Limit (RAPL) Driver
4 * Copyright (c) 2013, Intel Corporation.
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/list.h>
11 #include <linux/types.h>
12 #include <linux/device.h>
13 #include <linux/slab.h>
14 #include <linux/log2.h>
15 #include <linux/bitmap.h>
16 #include <linux/delay.h>
17 #include <linux/sysfs.h>
18 #include <linux/cpu.h>
19 #include <linux/powercap.h>
20 #include <linux/suspend.h>
21 #include <linux/intel_rapl.h>
23 #include <asm/iosf_mbi.h>
24 #include <asm/processor.h>
25 #include <asm/cpu_device_id.h>
26 #include <asm/intel-family.h>
29 #define MSR_PLATFORM_POWER_LIMIT 0x0000065C
31 /* bitmasks for RAPL MSRs, used by primitive access functions */
32 #define ENERGY_STATUS_MASK 0xffffffff
34 #define POWER_LIMIT1_MASK 0x7FFF
35 #define POWER_LIMIT1_ENABLE BIT(15)
36 #define POWER_LIMIT1_CLAMP BIT(16)
38 #define POWER_LIMIT2_MASK (0x7FFFULL<<32)
39 #define POWER_LIMIT2_ENABLE BIT_ULL(47)
40 #define POWER_LIMIT2_CLAMP BIT_ULL(48)
41 #define POWER_PACKAGE_LOCK BIT_ULL(63)
42 #define POWER_PP_LOCK BIT(31)
44 #define TIME_WINDOW1_MASK (0x7FULL<<17)
45 #define TIME_WINDOW2_MASK (0x7FULL<<49)
47 #define POWER_UNIT_OFFSET 0
48 #define POWER_UNIT_MASK 0x0F
50 #define ENERGY_UNIT_OFFSET 0x08
51 #define ENERGY_UNIT_MASK 0x1F00
53 #define TIME_UNIT_OFFSET 0x10
54 #define TIME_UNIT_MASK 0xF0000
56 #define POWER_INFO_MAX_MASK (0x7fffULL<<32)
57 #define POWER_INFO_MIN_MASK (0x7fffULL<<16)
58 #define POWER_INFO_MAX_TIME_WIN_MASK (0x3fULL<<48)
59 #define POWER_INFO_THERMAL_SPEC_MASK 0x7fff
61 #define PERF_STATUS_THROTTLE_TIME_MASK 0xffffffff
62 #define PP_POLICY_MASK 0x1F
64 /* Non HW constants */
65 #define RAPL_PRIMITIVE_DERIVED BIT(1) /* not from raw data */
66 #define RAPL_PRIMITIVE_DUMMY BIT(2)
68 #define TIME_WINDOW_MAX_MSEC 40000
69 #define TIME_WINDOW_MIN_MSEC 250
70 #define ENERGY_UNIT_SCALE 1000 /* scale from driver unit to powercap unit */
72 ARBITRARY_UNIT, /* no translation */
78 /* private data for RAPL MSR Interface */
79 static struct rapl_if_priv rapl_msr_priv;
81 /* per domain data, some are optional */
82 #define NR_RAW_PRIMITIVES (NR_RAPL_PRIMITIVES - 2)
91 #define DOMAIN_STATE_INACTIVE BIT(0)
92 #define DOMAIN_STATE_POWER_LIMIT_SET BIT(1)
93 #define DOMAIN_STATE_BIOS_LOCKED BIT(2)
95 static const char pl1_name[] = "long_term";
96 static const char pl2_name[] = "short_term";
98 #define power_zone_to_rapl_domain(_zone) \
99 container_of(_zone, struct rapl_domain, power_zone)
101 struct rapl_defaults {
102 u8 floor_freq_reg_addr;
103 int (*check_unit)(struct rapl_package *rp, int cpu);
104 void (*set_floor_freq)(struct rapl_domain *rd, bool mode);
105 u64 (*compute_time_window)(struct rapl_package *rp, u64 val,
107 unsigned int dram_domain_energy_unit;
109 static struct rapl_defaults *rapl_defaults;
111 /* Sideband MBI registers */
112 #define IOSF_CPU_POWER_BUDGET_CTL_BYT (0x2)
113 #define IOSF_CPU_POWER_BUDGET_CTL_TNG (0xdf)
115 #define PACKAGE_PLN_INT_SAVED BIT(0)
116 #define MAX_PRIM_NAME (32)
118 /* per domain data. used to describe individual knobs such that access function
119 * can be consolidated into one instead of many inline functions.
121 struct rapl_primitive_info {
125 enum rapl_domain_reg_id id;
130 #define PRIMITIVE_INFO_INIT(p, m, s, i, u, f) { \
139 static void rapl_init_domains(struct rapl_package *rp);
140 static int rapl_read_data_raw(struct rapl_domain *rd,
141 enum rapl_primitives prim,
142 bool xlate, u64 *data);
143 static int rapl_write_data_raw(struct rapl_domain *rd,
144 enum rapl_primitives prim,
145 unsigned long long value);
146 static u64 rapl_unit_xlate(struct rapl_domain *rd,
147 enum unit_type type, u64 value,
149 static void package_power_limit_irq_save(struct rapl_package *rp);
151 static LIST_HEAD(rapl_packages); /* guarded by CPU hotplug lock */
153 static const char * const rapl_domain_names[] = {
161 /* caller to ensure CPU hotplug lock is held */
162 static struct rapl_package *rapl_find_package_domain(int cpu, struct rapl_if_priv *priv)
164 int id = topology_logical_die_id(cpu);
165 struct rapl_package *rp;
167 list_for_each_entry(rp, &rapl_packages, plist) {
168 if (rp->id == id && rp->priv->control_type == priv->control_type)
175 static int get_energy_counter(struct powercap_zone *power_zone, u64 *energy_raw)
177 struct rapl_domain *rd;
180 /* prevent CPU hotplug, make sure the RAPL domain does not go
181 * away while reading the counter.
184 rd = power_zone_to_rapl_domain(power_zone);
186 if (!rapl_read_data_raw(rd, ENERGY_COUNTER, true, &energy_now)) {
187 *energy_raw = energy_now;
197 static int get_max_energy_counter(struct powercap_zone *pcd_dev, u64 *energy)
199 struct rapl_domain *rd = power_zone_to_rapl_domain(pcd_dev);
201 *energy = rapl_unit_xlate(rd, ENERGY_UNIT, ENERGY_STATUS_MASK, 0);
205 static int release_zone(struct powercap_zone *power_zone)
207 struct rapl_domain *rd = power_zone_to_rapl_domain(power_zone);
208 struct rapl_package *rp = rd->rp;
210 /* package zone is the last zone of a package, we can free
211 * memory here since all children has been unregistered.
213 if (rd->id == RAPL_DOMAIN_PACKAGE) {
222 static int find_nr_power_limit(struct rapl_domain *rd)
226 for (i = 0; i < NR_POWER_LIMITS; i++) {
234 static int set_domain_enable(struct powercap_zone *power_zone, bool mode)
236 struct rapl_domain *rd = power_zone_to_rapl_domain(power_zone);
238 if (rd->state & DOMAIN_STATE_BIOS_LOCKED)
242 rapl_write_data_raw(rd, PL1_ENABLE, mode);
243 if (rapl_defaults->set_floor_freq)
244 rapl_defaults->set_floor_freq(rd, mode);
250 static int get_domain_enable(struct powercap_zone *power_zone, bool *mode)
252 struct rapl_domain *rd = power_zone_to_rapl_domain(power_zone);
255 if (rd->state & DOMAIN_STATE_BIOS_LOCKED) {
260 if (rapl_read_data_raw(rd, PL1_ENABLE, true, &val)) {
270 /* per RAPL domain ops, in the order of rapl_domain_type */
271 static const struct powercap_zone_ops zone_ops[] = {
272 /* RAPL_DOMAIN_PACKAGE */
274 .get_energy_uj = get_energy_counter,
275 .get_max_energy_range_uj = get_max_energy_counter,
276 .release = release_zone,
277 .set_enable = set_domain_enable,
278 .get_enable = get_domain_enable,
280 /* RAPL_DOMAIN_PP0 */
282 .get_energy_uj = get_energy_counter,
283 .get_max_energy_range_uj = get_max_energy_counter,
284 .release = release_zone,
285 .set_enable = set_domain_enable,
286 .get_enable = get_domain_enable,
288 /* RAPL_DOMAIN_PP1 */
290 .get_energy_uj = get_energy_counter,
291 .get_max_energy_range_uj = get_max_energy_counter,
292 .release = release_zone,
293 .set_enable = set_domain_enable,
294 .get_enable = get_domain_enable,
296 /* RAPL_DOMAIN_DRAM */
298 .get_energy_uj = get_energy_counter,
299 .get_max_energy_range_uj = get_max_energy_counter,
300 .release = release_zone,
301 .set_enable = set_domain_enable,
302 .get_enable = get_domain_enable,
304 /* RAPL_DOMAIN_PLATFORM */
306 .get_energy_uj = get_energy_counter,
307 .get_max_energy_range_uj = get_max_energy_counter,
308 .release = release_zone,
309 .set_enable = set_domain_enable,
310 .get_enable = get_domain_enable,
316 * Constraint index used by powercap can be different than power limit (PL)
317 * index in that some PLs maybe missing due to non-existant MSRs. So we
318 * need to convert here by finding the valid PLs only (name populated).
320 static int contraint_to_pl(struct rapl_domain *rd, int cid)
324 for (i = 0, j = 0; i < NR_POWER_LIMITS; i++) {
325 if ((rd->rpl[i].name) && j++ == cid) {
326 pr_debug("%s: index %d\n", __func__, i);
330 pr_err("Cannot find matching power limit for constraint %d\n", cid);
335 static int set_power_limit(struct powercap_zone *power_zone, int cid,
338 struct rapl_domain *rd;
339 struct rapl_package *rp;
344 rd = power_zone_to_rapl_domain(power_zone);
345 id = contraint_to_pl(rd, cid);
353 if (rd->state & DOMAIN_STATE_BIOS_LOCKED) {
354 dev_warn(&power_zone->dev, "%s locked by BIOS, monitoring only\n",
360 switch (rd->rpl[id].prim_id) {
362 rapl_write_data_raw(rd, POWER_LIMIT1, power_limit);
365 rapl_write_data_raw(rd, POWER_LIMIT2, power_limit);
371 package_power_limit_irq_save(rp);
377 static int get_current_power_limit(struct powercap_zone *power_zone, int cid,
380 struct rapl_domain *rd;
387 rd = power_zone_to_rapl_domain(power_zone);
388 id = contraint_to_pl(rd, cid);
394 switch (rd->rpl[id].prim_id) {
405 if (rapl_read_data_raw(rd, prim, true, &val))
416 static int set_time_window(struct powercap_zone *power_zone, int cid,
419 struct rapl_domain *rd;
424 rd = power_zone_to_rapl_domain(power_zone);
425 id = contraint_to_pl(rd, cid);
431 switch (rd->rpl[id].prim_id) {
433 rapl_write_data_raw(rd, TIME_WINDOW1, window);
436 rapl_write_data_raw(rd, TIME_WINDOW2, window);
447 static int get_time_window(struct powercap_zone *power_zone, int cid, u64 *data)
449 struct rapl_domain *rd;
455 rd = power_zone_to_rapl_domain(power_zone);
456 id = contraint_to_pl(rd, cid);
462 switch (rd->rpl[id].prim_id) {
464 ret = rapl_read_data_raw(rd, TIME_WINDOW1, true, &val);
467 ret = rapl_read_data_raw(rd, TIME_WINDOW2, true, &val);
482 static const char *get_constraint_name(struct powercap_zone *power_zone, int cid)
484 struct rapl_domain *rd;
487 rd = power_zone_to_rapl_domain(power_zone);
488 id = contraint_to_pl(rd, cid);
490 return rd->rpl[id].name;
496 static int get_max_power(struct powercap_zone *power_zone, int id,
499 struct rapl_domain *rd;
505 rd = power_zone_to_rapl_domain(power_zone);
506 switch (rd->rpl[id].prim_id) {
508 prim = THERMAL_SPEC_POWER;
517 if (rapl_read_data_raw(rd, prim, true, &val))
527 static const struct powercap_zone_constraint_ops constraint_ops = {
528 .set_power_limit_uw = set_power_limit,
529 .get_power_limit_uw = get_current_power_limit,
530 .set_time_window_us = set_time_window,
531 .get_time_window_us = get_time_window,
532 .get_max_power_uw = get_max_power,
533 .get_name = get_constraint_name,
536 /* called after domain detection and package level data are set */
537 static void rapl_init_domains(struct rapl_package *rp)
540 struct rapl_domain *rd = rp->domains;
542 for (i = 0; i < RAPL_DOMAIN_MAX; i++) {
543 unsigned int mask = rp->domain_map & (1 << i);
545 case BIT(RAPL_DOMAIN_PACKAGE):
546 rd->name = rapl_domain_names[RAPL_DOMAIN_PACKAGE];
547 rd->id = RAPL_DOMAIN_PACKAGE;
548 rd->regs[RAPL_DOMAIN_REG_LIMIT] = MSR_PKG_POWER_LIMIT;
549 rd->regs[RAPL_DOMAIN_REG_STATUS] = MSR_PKG_ENERGY_STATUS;
550 rd->regs[RAPL_DOMAIN_REG_PERF] = MSR_PKG_PERF_STATUS;
551 rd->regs[RAPL_DOMAIN_REG_POLICY] = 0;
552 rd->regs[RAPL_DOMAIN_REG_INFO] = MSR_PKG_POWER_INFO;
553 rd->rpl[0].prim_id = PL1_ENABLE;
554 rd->rpl[0].name = pl1_name;
555 rd->rpl[1].prim_id = PL2_ENABLE;
556 rd->rpl[1].name = pl2_name;
558 case BIT(RAPL_DOMAIN_PP0):
559 rd->name = rapl_domain_names[RAPL_DOMAIN_PP0];
560 rd->id = RAPL_DOMAIN_PP0;
561 rd->regs[RAPL_DOMAIN_REG_LIMIT] = MSR_PP0_POWER_LIMIT;
562 rd->regs[RAPL_DOMAIN_REG_STATUS] = MSR_PP0_ENERGY_STATUS;
563 rd->regs[RAPL_DOMAIN_REG_PERF] = 0;
564 rd->regs[RAPL_DOMAIN_REG_POLICY] = MSR_PP0_POLICY;
565 rd->regs[RAPL_DOMAIN_REG_INFO] = 0;
566 rd->rpl[0].prim_id = PL1_ENABLE;
567 rd->rpl[0].name = pl1_name;
569 case BIT(RAPL_DOMAIN_PP1):
570 rd->name = rapl_domain_names[RAPL_DOMAIN_PP1];
571 rd->id = RAPL_DOMAIN_PP1;
572 rd->regs[RAPL_DOMAIN_REG_LIMIT] = MSR_PP1_POWER_LIMIT;
573 rd->regs[RAPL_DOMAIN_REG_STATUS] = MSR_PP1_ENERGY_STATUS;
574 rd->regs[RAPL_DOMAIN_REG_PERF] = 0;
575 rd->regs[RAPL_DOMAIN_REG_POLICY] = MSR_PP1_POLICY;
576 rd->regs[RAPL_DOMAIN_REG_INFO] = 0;
577 rd->rpl[0].prim_id = PL1_ENABLE;
578 rd->rpl[0].name = pl1_name;
580 case BIT(RAPL_DOMAIN_DRAM):
581 rd->name = rapl_domain_names[RAPL_DOMAIN_DRAM];
582 rd->id = RAPL_DOMAIN_DRAM;
583 rd->regs[RAPL_DOMAIN_REG_LIMIT] = MSR_DRAM_POWER_LIMIT;
584 rd->regs[RAPL_DOMAIN_REG_STATUS] = MSR_DRAM_ENERGY_STATUS;
585 rd->regs[RAPL_DOMAIN_REG_PERF] = MSR_DRAM_PERF_STATUS;
586 rd->regs[RAPL_DOMAIN_REG_POLICY] = 0;
587 rd->regs[RAPL_DOMAIN_REG_INFO] = MSR_DRAM_POWER_INFO;
588 rd->rpl[0].prim_id = PL1_ENABLE;
589 rd->rpl[0].name = pl1_name;
590 rd->domain_energy_unit =
591 rapl_defaults->dram_domain_energy_unit;
592 if (rd->domain_energy_unit)
593 pr_info("DRAM domain energy unit %dpj\n",
594 rd->domain_energy_unit);
604 static u64 rapl_unit_xlate(struct rapl_domain *rd, enum unit_type type,
605 u64 value, int to_raw)
608 struct rapl_package *rp = rd->rp;
613 units = rp->power_unit;
616 scale = ENERGY_UNIT_SCALE;
617 /* per domain unit takes precedence */
618 if (rd->domain_energy_unit)
619 units = rd->domain_energy_unit;
621 units = rp->energy_unit;
624 return rapl_defaults->compute_time_window(rp, value, to_raw);
631 return div64_u64(value, units) * scale;
635 return div64_u64(value, scale);
638 /* in the order of enum rapl_primitives */
639 static struct rapl_primitive_info rpi[] = {
640 /* name, mask, shift, msr index, unit divisor */
641 PRIMITIVE_INFO_INIT(ENERGY_COUNTER, ENERGY_STATUS_MASK, 0,
642 RAPL_DOMAIN_REG_STATUS, ENERGY_UNIT, 0),
643 PRIMITIVE_INFO_INIT(POWER_LIMIT1, POWER_LIMIT1_MASK, 0,
644 RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
645 PRIMITIVE_INFO_INIT(POWER_LIMIT2, POWER_LIMIT2_MASK, 32,
646 RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
647 PRIMITIVE_INFO_INIT(FW_LOCK, POWER_PP_LOCK, 31,
648 RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
649 PRIMITIVE_INFO_INIT(PL1_ENABLE, POWER_LIMIT1_ENABLE, 15,
650 RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
651 PRIMITIVE_INFO_INIT(PL1_CLAMP, POWER_LIMIT1_CLAMP, 16,
652 RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
653 PRIMITIVE_INFO_INIT(PL2_ENABLE, POWER_LIMIT2_ENABLE, 47,
654 RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
655 PRIMITIVE_INFO_INIT(PL2_CLAMP, POWER_LIMIT2_CLAMP, 48,
656 RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
657 PRIMITIVE_INFO_INIT(TIME_WINDOW1, TIME_WINDOW1_MASK, 17,
658 RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
659 PRIMITIVE_INFO_INIT(TIME_WINDOW2, TIME_WINDOW2_MASK, 49,
660 RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
661 PRIMITIVE_INFO_INIT(THERMAL_SPEC_POWER, POWER_INFO_THERMAL_SPEC_MASK,
662 0, RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
663 PRIMITIVE_INFO_INIT(MAX_POWER, POWER_INFO_MAX_MASK, 32,
664 RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
665 PRIMITIVE_INFO_INIT(MIN_POWER, POWER_INFO_MIN_MASK, 16,
666 RAPL_DOMAIN_REG_INFO, POWER_UNIT, 0),
667 PRIMITIVE_INFO_INIT(MAX_TIME_WINDOW, POWER_INFO_MAX_TIME_WIN_MASK, 48,
668 RAPL_DOMAIN_REG_INFO, TIME_UNIT, 0),
669 PRIMITIVE_INFO_INIT(THROTTLED_TIME, PERF_STATUS_THROTTLE_TIME_MASK, 0,
670 RAPL_DOMAIN_REG_PERF, TIME_UNIT, 0),
671 PRIMITIVE_INFO_INIT(PRIORITY_LEVEL, PP_POLICY_MASK, 0,
672 RAPL_DOMAIN_REG_POLICY, ARBITRARY_UNIT, 0),
674 PRIMITIVE_INFO_INIT(AVERAGE_POWER, 0, 0, 0, POWER_UNIT,
675 RAPL_PRIMITIVE_DERIVED),
679 /* Read primitive data based on its related struct rapl_primitive_info.
680 * if xlate flag is set, return translated data based on data units, i.e.
681 * time, energy, and power.
682 * RAPL MSRs are non-architectual and are laid out not consistently across
683 * domains. Here we use primitive info to allow writing consolidated access
685 * For a given primitive, it is processed by MSR mask and shift. Unit conversion
686 * is pre-assigned based on RAPL unit MSRs read at init time.
687 * 63-------------------------- 31--------------------------- 0
689 * | |<- shift ----------------|
690 * 63-------------------------- 31--------------------------- 0
692 static int rapl_read_data_raw(struct rapl_domain *rd,
693 enum rapl_primitives prim,
694 bool xlate, u64 *data)
698 struct rapl_primitive_info *rp = &rpi[prim];
701 if (!rp->name || rp->flag & RAPL_PRIMITIVE_DUMMY)
704 msr = rd->regs[rp->id];
708 cpu = rd->rp->lead_cpu;
710 /* special-case package domain, which uses a different bit*/
711 if (prim == FW_LOCK && rd->id == RAPL_DOMAIN_PACKAGE) {
712 rp->mask = POWER_PACKAGE_LOCK;
715 /* non-hardware data are collected by the polling thread */
716 if (rp->flag & RAPL_PRIMITIVE_DERIVED) {
717 *data = rd->rdd.primitives[prim];
721 if (rdmsrl_safe_on_cpu(cpu, msr, &value)) {
722 pr_debug("failed to read msr 0x%x on cpu %d\n", msr, cpu);
726 final = value & rp->mask;
727 final = final >> rp->shift;
729 *data = rapl_unit_xlate(rd, rp->unit, final, 0);
737 static int msrl_update_safe(u32 msr_no, u64 clear_mask, u64 set_mask)
742 err = rdmsrl_safe(msr_no, &val);
749 err = wrmsrl_safe(msr_no, val);
755 static void msrl_update_func(void *info)
757 struct msrl_action *ma = info;
759 ma->err = msrl_update_safe(ma->msr_no, ma->clear_mask, ma->set_mask);
762 /* Similar use of primitive info in the read counterpart */
763 static int rapl_write_data_raw(struct rapl_domain *rd,
764 enum rapl_primitives prim,
765 unsigned long long value)
767 struct rapl_primitive_info *rp = &rpi[prim];
770 struct msrl_action ma;
773 cpu = rd->rp->lead_cpu;
774 bits = rapl_unit_xlate(rd, rp->unit, value, 1);
778 memset(&ma, 0, sizeof(ma));
780 ma.msr_no = rd->regs[rp->id];
781 ma.clear_mask = rp->mask;
784 ret = smp_call_function_single(cpu, msrl_update_func, &ma, 1);
794 * Raw RAPL data stored in MSRs are in certain scales. We need to
795 * convert them into standard units based on the units reported in
796 * the RAPL unit MSRs. This is specific to CPUs as the method to
797 * calculate units differ on different CPUs.
798 * We convert the units to below format based on CPUs.
800 * energy unit: picoJoules : Represented in picoJoules by default
801 * power unit : microWatts : Represented in milliWatts by default
802 * time unit : microseconds: Represented in seconds by default
804 static int rapl_check_unit_core(struct rapl_package *rp, int cpu)
809 if (rdmsrl_safe_on_cpu(cpu, MSR_RAPL_POWER_UNIT, &msr_val)) {
810 pr_err("Failed to read power unit MSR 0x%x on CPU %d, exit.\n",
811 MSR_RAPL_POWER_UNIT, cpu);
815 value = (msr_val & ENERGY_UNIT_MASK) >> ENERGY_UNIT_OFFSET;
816 rp->energy_unit = ENERGY_UNIT_SCALE * 1000000 / (1 << value);
818 value = (msr_val & POWER_UNIT_MASK) >> POWER_UNIT_OFFSET;
819 rp->power_unit = 1000000 / (1 << value);
821 value = (msr_val & TIME_UNIT_MASK) >> TIME_UNIT_OFFSET;
822 rp->time_unit = 1000000 / (1 << value);
824 pr_debug("Core CPU %s energy=%dpJ, time=%dus, power=%duW\n",
825 rp->name, rp->energy_unit, rp->time_unit, rp->power_unit);
830 static int rapl_check_unit_atom(struct rapl_package *rp, int cpu)
835 if (rdmsrl_safe_on_cpu(cpu, MSR_RAPL_POWER_UNIT, &msr_val)) {
836 pr_err("Failed to read power unit MSR 0x%x on CPU %d, exit.\n",
837 MSR_RAPL_POWER_UNIT, cpu);
840 value = (msr_val & ENERGY_UNIT_MASK) >> ENERGY_UNIT_OFFSET;
841 rp->energy_unit = ENERGY_UNIT_SCALE * 1 << value;
843 value = (msr_val & POWER_UNIT_MASK) >> POWER_UNIT_OFFSET;
844 rp->power_unit = (1 << value) * 1000;
846 value = (msr_val & TIME_UNIT_MASK) >> TIME_UNIT_OFFSET;
847 rp->time_unit = 1000000 / (1 << value);
849 pr_debug("Atom %s energy=%dpJ, time=%dus, power=%duW\n",
850 rp->name, rp->energy_unit, rp->time_unit, rp->power_unit);
855 static void power_limit_irq_save_cpu(void *info)
858 struct rapl_package *rp = (struct rapl_package *)info;
860 /* save the state of PLN irq mask bit before disabling it */
861 rdmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &l, &h);
862 if (!(rp->power_limit_irq & PACKAGE_PLN_INT_SAVED)) {
863 rp->power_limit_irq = l & PACKAGE_THERM_INT_PLN_ENABLE;
864 rp->power_limit_irq |= PACKAGE_PLN_INT_SAVED;
866 l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
867 wrmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
872 * When package power limit is set artificially low by RAPL, LVT
873 * thermal interrupt for package power limit should be ignored
874 * since we are not really exceeding the real limit. The intention
875 * is to avoid excessive interrupts while we are trying to save power.
876 * A useful feature might be routing the package_power_limit interrupt
877 * to userspace via eventfd. once we have a usecase, this is simple
878 * to do by adding an atomic notifier.
881 static void package_power_limit_irq_save(struct rapl_package *rp)
883 if (!boot_cpu_has(X86_FEATURE_PTS) || !boot_cpu_has(X86_FEATURE_PLN))
886 smp_call_function_single(rp->lead_cpu, power_limit_irq_save_cpu, rp, 1);
890 * Restore per package power limit interrupt enable state. Called from cpu
891 * hotplug code on package removal.
893 static void package_power_limit_irq_restore(struct rapl_package *rp)
897 if (!boot_cpu_has(X86_FEATURE_PTS) || !boot_cpu_has(X86_FEATURE_PLN))
900 /* irq enable state not saved, nothing to restore */
901 if (!(rp->power_limit_irq & PACKAGE_PLN_INT_SAVED))
904 rdmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, &l, &h);
906 if (rp->power_limit_irq & PACKAGE_THERM_INT_PLN_ENABLE)
907 l |= PACKAGE_THERM_INT_PLN_ENABLE;
909 l &= ~PACKAGE_THERM_INT_PLN_ENABLE;
911 wrmsr_safe(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
914 static void set_floor_freq_default(struct rapl_domain *rd, bool mode)
916 int nr_powerlimit = find_nr_power_limit(rd);
918 /* always enable clamp such that p-state can go below OS requested
919 * range. power capping priority over guranteed frequency.
921 rapl_write_data_raw(rd, PL1_CLAMP, mode);
923 /* some domains have pl2 */
924 if (nr_powerlimit > 1) {
925 rapl_write_data_raw(rd, PL2_ENABLE, mode);
926 rapl_write_data_raw(rd, PL2_CLAMP, mode);
930 static void set_floor_freq_atom(struct rapl_domain *rd, bool enable)
932 static u32 power_ctrl_orig_val;
935 if (!rapl_defaults->floor_freq_reg_addr) {
936 pr_err("Invalid floor frequency config register\n");
940 if (!power_ctrl_orig_val)
941 iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_CR_READ,
942 rapl_defaults->floor_freq_reg_addr,
943 &power_ctrl_orig_val);
944 mdata = power_ctrl_orig_val;
946 mdata &= ~(0x7f << 8);
949 iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_CR_WRITE,
950 rapl_defaults->floor_freq_reg_addr, mdata);
953 static u64 rapl_compute_time_window_core(struct rapl_package *rp, u64 value,
956 u64 f, y; /* fraction and exp. used for time unit */
959 * Special processing based on 2^Y*(1+F/4), refer
960 * to Intel Software Developer's manual Vol.3B: CH 14.9.3.
963 f = (value & 0x60) >> 5;
965 value = (1 << y) * (4 + f) * rp->time_unit / 4;
967 do_div(value, rp->time_unit);
969 f = div64_u64(4 * (value - (1 << y)), 1 << y);
970 value = (y & 0x1f) | ((f & 0x3) << 5);
975 static u64 rapl_compute_time_window_atom(struct rapl_package *rp, u64 value,
979 * Atom time unit encoding is straight forward val * time_unit,
980 * where time_unit is default to 1 sec. Never 0.
983 return (value) ? value *= rp->time_unit : rp->time_unit;
985 value = div64_u64(value, rp->time_unit);
990 static const struct rapl_defaults rapl_defaults_core = {
991 .floor_freq_reg_addr = 0,
992 .check_unit = rapl_check_unit_core,
993 .set_floor_freq = set_floor_freq_default,
994 .compute_time_window = rapl_compute_time_window_core,
997 static const struct rapl_defaults rapl_defaults_hsw_server = {
998 .check_unit = rapl_check_unit_core,
999 .set_floor_freq = set_floor_freq_default,
1000 .compute_time_window = rapl_compute_time_window_core,
1001 .dram_domain_energy_unit = 15300,
1004 static const struct rapl_defaults rapl_defaults_byt = {
1005 .floor_freq_reg_addr = IOSF_CPU_POWER_BUDGET_CTL_BYT,
1006 .check_unit = rapl_check_unit_atom,
1007 .set_floor_freq = set_floor_freq_atom,
1008 .compute_time_window = rapl_compute_time_window_atom,
1011 static const struct rapl_defaults rapl_defaults_tng = {
1012 .floor_freq_reg_addr = IOSF_CPU_POWER_BUDGET_CTL_TNG,
1013 .check_unit = rapl_check_unit_atom,
1014 .set_floor_freq = set_floor_freq_atom,
1015 .compute_time_window = rapl_compute_time_window_atom,
1018 static const struct rapl_defaults rapl_defaults_ann = {
1019 .floor_freq_reg_addr = 0,
1020 .check_unit = rapl_check_unit_atom,
1021 .set_floor_freq = NULL,
1022 .compute_time_window = rapl_compute_time_window_atom,
1025 static const struct rapl_defaults rapl_defaults_cht = {
1026 .floor_freq_reg_addr = 0,
1027 .check_unit = rapl_check_unit_atom,
1028 .set_floor_freq = NULL,
1029 .compute_time_window = rapl_compute_time_window_atom,
1032 static const struct x86_cpu_id rapl_ids[] __initconst = {
1033 INTEL_CPU_FAM6(SANDYBRIDGE, rapl_defaults_core),
1034 INTEL_CPU_FAM6(SANDYBRIDGE_X, rapl_defaults_core),
1036 INTEL_CPU_FAM6(IVYBRIDGE, rapl_defaults_core),
1037 INTEL_CPU_FAM6(IVYBRIDGE_X, rapl_defaults_core),
1039 INTEL_CPU_FAM6(HASWELL_CORE, rapl_defaults_core),
1040 INTEL_CPU_FAM6(HASWELL_ULT, rapl_defaults_core),
1041 INTEL_CPU_FAM6(HASWELL_GT3E, rapl_defaults_core),
1042 INTEL_CPU_FAM6(HASWELL_X, rapl_defaults_hsw_server),
1044 INTEL_CPU_FAM6(BROADWELL_CORE, rapl_defaults_core),
1045 INTEL_CPU_FAM6(BROADWELL_GT3E, rapl_defaults_core),
1046 INTEL_CPU_FAM6(BROADWELL_XEON_D, rapl_defaults_core),
1047 INTEL_CPU_FAM6(BROADWELL_X, rapl_defaults_hsw_server),
1049 INTEL_CPU_FAM6(SKYLAKE_DESKTOP, rapl_defaults_core),
1050 INTEL_CPU_FAM6(SKYLAKE_MOBILE, rapl_defaults_core),
1051 INTEL_CPU_FAM6(SKYLAKE_X, rapl_defaults_hsw_server),
1052 INTEL_CPU_FAM6(KABYLAKE_MOBILE, rapl_defaults_core),
1053 INTEL_CPU_FAM6(KABYLAKE_DESKTOP, rapl_defaults_core),
1054 INTEL_CPU_FAM6(CANNONLAKE_MOBILE, rapl_defaults_core),
1055 INTEL_CPU_FAM6(ICELAKE_MOBILE, rapl_defaults_core),
1057 INTEL_CPU_FAM6(ATOM_SILVERMONT, rapl_defaults_byt),
1058 INTEL_CPU_FAM6(ATOM_AIRMONT, rapl_defaults_cht),
1059 INTEL_CPU_FAM6(ATOM_SILVERMONT_MID, rapl_defaults_tng),
1060 INTEL_CPU_FAM6(ATOM_AIRMONT_MID, rapl_defaults_ann),
1061 INTEL_CPU_FAM6(ATOM_GOLDMONT, rapl_defaults_core),
1062 INTEL_CPU_FAM6(ATOM_GOLDMONT_PLUS, rapl_defaults_core),
1063 INTEL_CPU_FAM6(ATOM_GOLDMONT_X, rapl_defaults_core),
1064 INTEL_CPU_FAM6(ATOM_TREMONT_X, rapl_defaults_core),
1066 INTEL_CPU_FAM6(XEON_PHI_KNL, rapl_defaults_hsw_server),
1067 INTEL_CPU_FAM6(XEON_PHI_KNM, rapl_defaults_hsw_server),
1070 MODULE_DEVICE_TABLE(x86cpu, rapl_ids);
1072 /* Read once for all raw primitive data for domains */
1073 static void rapl_update_domain_data(struct rapl_package *rp)
1078 for (dmn = 0; dmn < rp->nr_domains; dmn++) {
1079 pr_debug("update %s domain %s data\n", rp->name,
1080 rp->domains[dmn].name);
1081 /* exclude non-raw primitives */
1082 for (prim = 0; prim < NR_RAW_PRIMITIVES; prim++) {
1083 if (!rapl_read_data_raw(&rp->domains[dmn], prim,
1084 rpi[prim].unit, &val))
1085 rp->domains[dmn].rdd.primitives[prim] = val;
1091 static void rapl_unregister_powercap(void)
1093 if (&rapl_msr_priv.platform_rapl_domain) {
1094 powercap_unregister_zone(rapl_msr_priv.control_type,
1095 &rapl_msr_priv.platform_rapl_domain->power_zone);
1096 kfree(rapl_msr_priv.platform_rapl_domain);
1098 powercap_unregister_control_type(rapl_msr_priv.control_type);
1101 static int rapl_package_register_powercap(struct rapl_package *rp)
1103 struct rapl_domain *rd;
1104 struct powercap_zone *power_zone = NULL;
1107 /* Update the domain data of the new package */
1108 rapl_update_domain_data(rp);
1110 /* first we register package domain as the parent zone*/
1111 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) {
1112 if (rd->id == RAPL_DOMAIN_PACKAGE) {
1113 nr_pl = find_nr_power_limit(rd);
1114 pr_debug("register package domain %s\n", rp->name);
1115 power_zone = powercap_register_zone(&rd->power_zone,
1116 rp->priv->control_type,
1121 if (IS_ERR(power_zone)) {
1122 pr_debug("failed to register power zone %s\n",
1124 return PTR_ERR(power_zone);
1126 /* track parent zone in per package/socket data */
1127 rp->power_zone = power_zone;
1128 /* done, only one package domain per socket */
1133 pr_err("no package domain found, unknown topology!\n");
1136 /* now register domains as children of the socket/package*/
1137 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) {
1138 if (rd->id == RAPL_DOMAIN_PACKAGE)
1140 /* number of power limits per domain varies */
1141 nr_pl = find_nr_power_limit(rd);
1142 power_zone = powercap_register_zone(&rd->power_zone,
1143 rp->priv->control_type, rd->name,
1145 &zone_ops[rd->id], nr_pl,
1148 if (IS_ERR(power_zone)) {
1149 pr_debug("failed to register power_zone, %s:%s\n",
1150 rp->name, rd->name);
1151 ret = PTR_ERR(power_zone);
1159 * Clean up previously initialized domains within the package if we
1160 * failed after the first domain setup.
1162 while (--rd >= rp->domains) {
1163 pr_debug("unregister %s domain %s\n", rp->name, rd->name);
1164 powercap_unregister_zone(rp->priv->control_type, &rd->power_zone);
1170 static int __init rapl_register_psys(void)
1172 struct rapl_domain *rd;
1173 struct powercap_zone *power_zone;
1176 if (rdmsrl_safe_on_cpu(0, MSR_PLATFORM_ENERGY_STATUS, &val) || !val)
1179 if (rdmsrl_safe_on_cpu(0, MSR_PLATFORM_POWER_LIMIT, &val) || !val)
1182 rd = kzalloc(sizeof(*rd), GFP_KERNEL);
1186 rd->name = rapl_domain_names[RAPL_DOMAIN_PLATFORM];
1187 rd->id = RAPL_DOMAIN_PLATFORM;
1188 rd->regs[RAPL_DOMAIN_REG_LIMIT] = MSR_PLATFORM_POWER_LIMIT;
1189 rd->regs[RAPL_DOMAIN_REG_STATUS] = MSR_PLATFORM_ENERGY_STATUS;
1190 rd->rpl[0].prim_id = PL1_ENABLE;
1191 rd->rpl[0].name = pl1_name;
1192 rd->rpl[1].prim_id = PL2_ENABLE;
1193 rd->rpl[1].name = pl2_name;
1194 rd->rp = rapl_find_package_domain(0, &rapl_msr_priv);
1196 power_zone = powercap_register_zone(&rd->power_zone, rapl_msr_priv.control_type,
1198 &zone_ops[RAPL_DOMAIN_PLATFORM],
1199 2, &constraint_ops);
1201 if (IS_ERR(power_zone)) {
1203 return PTR_ERR(power_zone);
1206 rapl_msr_priv.platform_rapl_domain = rd;
1211 static int __init rapl_register_powercap(void)
1213 rapl_msr_priv.control_type = powercap_register_control_type(NULL, "intel-rapl", NULL);
1214 if (IS_ERR(rapl_msr_priv.control_type)) {
1215 pr_debug("failed to register powercap control_type.\n");
1216 return PTR_ERR(rapl_msr_priv.control_type);
1221 static int rapl_check_domain(int cpu, int domain)
1227 case RAPL_DOMAIN_PACKAGE:
1228 msr = MSR_PKG_ENERGY_STATUS;
1230 case RAPL_DOMAIN_PP0:
1231 msr = MSR_PP0_ENERGY_STATUS;
1233 case RAPL_DOMAIN_PP1:
1234 msr = MSR_PP1_ENERGY_STATUS;
1236 case RAPL_DOMAIN_DRAM:
1237 msr = MSR_DRAM_ENERGY_STATUS;
1239 case RAPL_DOMAIN_PLATFORM:
1240 /* PSYS(PLATFORM) is not a CPU domain, so avoid printng error */
1243 pr_err("invalid domain id %d\n", domain);
1246 /* make sure domain counters are available and contains non-zero
1247 * values, otherwise skip it.
1249 if (rdmsrl_safe_on_cpu(cpu, msr, &val) || !val)
1257 * Check if power limits are available. Two cases when they are not available:
1258 * 1. Locked by BIOS, in this case we still provide read-only access so that
1259 * users can see what limit is set by the BIOS.
1260 * 2. Some CPUs make some domains monitoring only which means PLx MSRs may not
1261 * exist at all. In this case, we do not show the contraints in powercap.
1263 * Called after domains are detected and initialized.
1265 static void rapl_detect_powerlimit(struct rapl_domain *rd)
1270 /* check if the domain is locked by BIOS, ignore if MSR doesn't exist */
1271 if (!rapl_read_data_raw(rd, FW_LOCK, false, &val64)) {
1273 pr_info("RAPL %s domain %s locked by BIOS\n",
1274 rd->rp->name, rd->name);
1275 rd->state |= DOMAIN_STATE_BIOS_LOCKED;
1278 /* check if power limit MSRs exists, otherwise domain is monitoring only */
1279 for (i = 0; i < NR_POWER_LIMITS; i++) {
1280 int prim = rd->rpl[i].prim_id;
1281 if (rapl_read_data_raw(rd, prim, false, &val64))
1282 rd->rpl[i].name = NULL;
1286 /* Detect active and valid domains for the given CPU, caller must
1287 * ensure the CPU belongs to the targeted package and CPU hotlug is disabled.
1289 static int rapl_detect_domains(struct rapl_package *rp, int cpu)
1291 struct rapl_domain *rd;
1294 for (i = 0; i < RAPL_DOMAIN_MAX; i++) {
1295 /* use physical package id to read counters */
1296 if (!rapl_check_domain(cpu, i)) {
1297 rp->domain_map |= 1 << i;
1298 pr_info("Found RAPL domain %s\n", rapl_domain_names[i]);
1301 rp->nr_domains = bitmap_weight(&rp->domain_map, RAPL_DOMAIN_MAX);
1302 if (!rp->nr_domains) {
1303 pr_debug("no valid rapl domains found in %s\n", rp->name);
1306 pr_debug("found %d domains on %s\n", rp->nr_domains, rp->name);
1308 rp->domains = kcalloc(rp->nr_domains + 1, sizeof(struct rapl_domain),
1313 rapl_init_domains(rp);
1315 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++)
1316 rapl_detect_powerlimit(rd);
1321 /* called from CPU hotplug notifier, hotplug lock held */
1322 static void rapl_remove_package(struct rapl_package *rp)
1324 struct rapl_domain *rd, *rd_package = NULL;
1326 package_power_limit_irq_restore(rp);
1328 for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) {
1329 rapl_write_data_raw(rd, PL1_ENABLE, 0);
1330 rapl_write_data_raw(rd, PL1_CLAMP, 0);
1331 if (find_nr_power_limit(rd) > 1) {
1332 rapl_write_data_raw(rd, PL2_ENABLE, 0);
1333 rapl_write_data_raw(rd, PL2_CLAMP, 0);
1335 if (rd->id == RAPL_DOMAIN_PACKAGE) {
1339 pr_debug("remove package, undo power limit on %s: %s\n",
1340 rp->name, rd->name);
1341 powercap_unregister_zone(rp->priv->control_type, &rd->power_zone);
1343 /* do parent zone last */
1344 powercap_unregister_zone(rp->priv->control_type, &rd_package->power_zone);
1345 list_del(&rp->plist);
1349 /* called from CPU hotplug notifier, hotplug lock held */
1350 static struct rapl_package *rapl_add_package(int cpu, struct rapl_if_priv *priv)
1352 int id = topology_logical_die_id(cpu);
1353 struct rapl_package *rp;
1354 struct cpuinfo_x86 *c = &cpu_data(cpu);
1357 rp = kzalloc(sizeof(struct rapl_package), GFP_KERNEL);
1359 return ERR_PTR(-ENOMEM);
1361 /* add the new package to the list */
1366 if (topology_max_die_per_package() > 1)
1367 snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH,
1368 "package-%d-die-%d", c->phys_proc_id, c->cpu_die_id);
1370 snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH, "package-%d",
1373 /* check if the package contains valid domains */
1374 if (rapl_detect_domains(rp, cpu) ||
1375 rapl_defaults->check_unit(rp, cpu)) {
1377 goto err_free_package;
1379 ret = rapl_package_register_powercap(rp);
1381 INIT_LIST_HEAD(&rp->plist);
1382 list_add(&rp->plist, &rapl_packages);
1389 return ERR_PTR(ret);
1392 /* Handles CPU hotplug on multi-socket systems.
1393 * If a CPU goes online as the first CPU of the physical package
1394 * we add the RAPL package to the system. Similarly, when the last
1395 * CPU of the package is removed, we remove the RAPL package and its
1396 * associated domains. Cooling devices are handled accordingly at
1399 static int rapl_cpu_online(unsigned int cpu)
1401 struct rapl_package *rp;
1403 rp = rapl_find_package_domain(cpu, &rapl_msr_priv);
1405 rp = rapl_add_package(cpu, &rapl_msr_priv);
1409 cpumask_set_cpu(cpu, &rp->cpumask);
1413 static int rapl_cpu_down_prep(unsigned int cpu)
1415 struct rapl_package *rp;
1418 rp = rapl_find_package_domain(cpu, &rapl_msr_priv);
1422 cpumask_clear_cpu(cpu, &rp->cpumask);
1423 lead_cpu = cpumask_first(&rp->cpumask);
1424 if (lead_cpu >= nr_cpu_ids)
1425 rapl_remove_package(rp);
1426 else if (rp->lead_cpu == cpu)
1427 rp->lead_cpu = lead_cpu;
1431 static void power_limit_state_save(void)
1433 struct rapl_package *rp;
1434 struct rapl_domain *rd;
1438 list_for_each_entry(rp, &rapl_packages, plist) {
1439 if (!rp->power_zone)
1441 rd = power_zone_to_rapl_domain(rp->power_zone);
1442 nr_pl = find_nr_power_limit(rd);
1443 for (i = 0; i < nr_pl; i++) {
1444 switch (rd->rpl[i].prim_id) {
1446 ret = rapl_read_data_raw(rd,
1449 &rd->rpl[i].last_power_limit);
1451 rd->rpl[i].last_power_limit = 0;
1454 ret = rapl_read_data_raw(rd,
1457 &rd->rpl[i].last_power_limit);
1459 rd->rpl[i].last_power_limit = 0;
1467 static void power_limit_state_restore(void)
1469 struct rapl_package *rp;
1470 struct rapl_domain *rd;
1474 list_for_each_entry(rp, &rapl_packages, plist) {
1475 if (!rp->power_zone)
1477 rd = power_zone_to_rapl_domain(rp->power_zone);
1478 nr_pl = find_nr_power_limit(rd);
1479 for (i = 0; i < nr_pl; i++) {
1480 switch (rd->rpl[i].prim_id) {
1482 if (rd->rpl[i].last_power_limit)
1483 rapl_write_data_raw(rd,
1485 rd->rpl[i].last_power_limit);
1488 if (rd->rpl[i].last_power_limit)
1489 rapl_write_data_raw(rd,
1491 rd->rpl[i].last_power_limit);
1499 static int rapl_pm_callback(struct notifier_block *nb,
1500 unsigned long mode, void *_unused)
1503 case PM_SUSPEND_PREPARE:
1504 power_limit_state_save();
1506 case PM_POST_SUSPEND:
1507 power_limit_state_restore();
1513 static struct notifier_block rapl_pm_notifier = {
1514 .notifier_call = rapl_pm_callback,
1517 static int __init rapl_init(void)
1519 const struct x86_cpu_id *id;
1522 id = x86_match_cpu(rapl_ids);
1524 pr_err("driver does not support CPU family %d model %d\n",
1525 boot_cpu_data.x86, boot_cpu_data.x86_model);
1530 rapl_defaults = (struct rapl_defaults *)id->driver_data;
1532 ret = rapl_register_powercap();
1536 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "powercap/rapl:online",
1537 rapl_cpu_online, rapl_cpu_down_prep);
1540 rapl_msr_priv.pcap_rapl_online = ret;
1542 /* Don't bail out if PSys is not supported */
1543 rapl_register_psys();
1545 ret = register_pm_notifier(&rapl_pm_notifier);
1552 cpuhp_remove_state(rapl_msr_priv.pcap_rapl_online);
1555 rapl_unregister_powercap();
1559 static void __exit rapl_exit(void)
1561 unregister_pm_notifier(&rapl_pm_notifier);
1562 cpuhp_remove_state(rapl_msr_priv.pcap_rapl_online);
1563 rapl_unregister_powercap();
1566 module_init(rapl_init);
1567 module_exit(rapl_exit);
1569 MODULE_DESCRIPTION("Driver for Intel RAPL (Running Average Power Limit)");
1570 MODULE_AUTHOR("Jacob Pan <jacob.jun.pan@intel.com>");
1571 MODULE_LICENSE("GPL v2");