diff options
Diffstat (limited to 'arch/x86/kernel/cpu/perf_event_intel_rapl.c')
-rw-r--r-- | arch/x86/kernel/cpu/perf_event_intel_rapl.c | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c index 059218ed5208..619f7699487a 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c | |||
@@ -59,7 +59,7 @@ | |||
59 | #define INTEL_RAPL_PKG 0x2 /* pseudo-encoding */ | 59 | #define INTEL_RAPL_PKG 0x2 /* pseudo-encoding */ |
60 | #define RAPL_IDX_RAM_NRG_STAT 2 /* DRAM */ | 60 | #define RAPL_IDX_RAM_NRG_STAT 2 /* DRAM */ |
61 | #define INTEL_RAPL_RAM 0x3 /* pseudo-encoding */ | 61 | #define INTEL_RAPL_RAM 0x3 /* pseudo-encoding */ |
62 | #define RAPL_IDX_PP1_NRG_STAT 3 /* DRAM */ | 62 | #define RAPL_IDX_PP1_NRG_STAT 3 /* gpu */ |
63 | #define INTEL_RAPL_PP1 0x4 /* pseudo-encoding */ | 63 | #define INTEL_RAPL_PP1 0x4 /* pseudo-encoding */ |
64 | 64 | ||
65 | /* Clients have PP0, PKG */ | 65 | /* Clients have PP0, PKG */ |
@@ -72,6 +72,12 @@ | |||
72 | 1<<RAPL_IDX_PKG_NRG_STAT|\ | 72 | 1<<RAPL_IDX_PKG_NRG_STAT|\ |
73 | 1<<RAPL_IDX_RAM_NRG_STAT) | 73 | 1<<RAPL_IDX_RAM_NRG_STAT) |
74 | 74 | ||
75 | /* Servers have PP0, PKG, RAM, PP1 */ | ||
76 | #define RAPL_IDX_HSW (1<<RAPL_IDX_PP0_NRG_STAT|\ | ||
77 | 1<<RAPL_IDX_PKG_NRG_STAT|\ | ||
78 | 1<<RAPL_IDX_RAM_NRG_STAT|\ | ||
79 | 1<<RAPL_IDX_PP1_NRG_STAT) | ||
80 | |||
75 | /* | 81 | /* |
76 | * event code: LSB 8 bits, passed in attr->config | 82 | * event code: LSB 8 bits, passed in attr->config |
77 | * any other bit is reserved | 83 | * any other bit is reserved |
@@ -425,6 +431,24 @@ static struct attribute *rapl_events_cln_attr[] = { | |||
425 | NULL, | 431 | NULL, |
426 | }; | 432 | }; |
427 | 433 | ||
434 | static struct attribute *rapl_events_hsw_attr[] = { | ||
435 | EVENT_PTR(rapl_cores), | ||
436 | EVENT_PTR(rapl_pkg), | ||
437 | EVENT_PTR(rapl_gpu), | ||
438 | EVENT_PTR(rapl_ram), | ||
439 | |||
440 | EVENT_PTR(rapl_cores_unit), | ||
441 | EVENT_PTR(rapl_pkg_unit), | ||
442 | EVENT_PTR(rapl_gpu_unit), | ||
443 | EVENT_PTR(rapl_ram_unit), | ||
444 | |||
445 | EVENT_PTR(rapl_cores_scale), | ||
446 | EVENT_PTR(rapl_pkg_scale), | ||
447 | EVENT_PTR(rapl_gpu_scale), | ||
448 | EVENT_PTR(rapl_ram_scale), | ||
449 | NULL, | ||
450 | }; | ||
451 | |||
428 | static struct attribute_group rapl_pmu_events_group = { | 452 | static struct attribute_group rapl_pmu_events_group = { |
429 | .name = "events", | 453 | .name = "events", |
430 | .attrs = NULL, /* patched at runtime */ | 454 | .attrs = NULL, /* patched at runtime */ |
@@ -511,6 +535,7 @@ static int rapl_cpu_prepare(int cpu) | |||
511 | struct rapl_pmu *pmu = per_cpu(rapl_pmu, cpu); | 535 | struct rapl_pmu *pmu = per_cpu(rapl_pmu, cpu); |
512 | int phys_id = topology_physical_package_id(cpu); | 536 | int phys_id = topology_physical_package_id(cpu); |
513 | u64 ms; | 537 | u64 ms; |
538 | u64 msr_rapl_power_unit_bits; | ||
514 | 539 | ||
515 | if (pmu) | 540 | if (pmu) |
516 | return 0; | 541 | return 0; |
@@ -518,6 +543,10 @@ static int rapl_cpu_prepare(int cpu) | |||
518 | if (phys_id < 0) | 543 | if (phys_id < 0) |
519 | return -1; | 544 | return -1; |
520 | 545 | ||
546 | /* protect rdmsrl() to handle virtualization */ | ||
547 | if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &msr_rapl_power_unit_bits)) | ||
548 | return -1; | ||
549 | |||
521 | pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu)); | 550 | pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu)); |
522 | if (!pmu) | 551 | if (!pmu) |
523 | return -1; | 552 | return -1; |
@@ -531,8 +560,7 @@ static int rapl_cpu_prepare(int cpu) | |||
531 | * | 560 | * |
532 | * we cache in local PMU instance | 561 | * we cache in local PMU instance |
533 | */ | 562 | */ |
534 | rdmsrl(MSR_RAPL_POWER_UNIT, pmu->hw_unit); | 563 | pmu->hw_unit = (msr_rapl_power_unit_bits >> 8) & 0x1FULL; |
535 | pmu->hw_unit = (pmu->hw_unit >> 8) & 0x1FULL; | ||
536 | pmu->pmu = &rapl_pmu_class; | 564 | pmu->pmu = &rapl_pmu_class; |
537 | 565 | ||
538 | /* | 566 | /* |
@@ -631,11 +659,14 @@ static int __init rapl_pmu_init(void) | |||
631 | switch (boot_cpu_data.x86_model) { | 659 | switch (boot_cpu_data.x86_model) { |
632 | case 42: /* Sandy Bridge */ | 660 | case 42: /* Sandy Bridge */ |
633 | case 58: /* Ivy Bridge */ | 661 | case 58: /* Ivy Bridge */ |
634 | case 60: /* Haswell */ | ||
635 | case 69: /* Haswell-Celeron */ | ||
636 | rapl_cntr_mask = RAPL_IDX_CLN; | 662 | rapl_cntr_mask = RAPL_IDX_CLN; |
637 | rapl_pmu_events_group.attrs = rapl_events_cln_attr; | 663 | rapl_pmu_events_group.attrs = rapl_events_cln_attr; |
638 | break; | 664 | break; |
665 | case 60: /* Haswell */ | ||
666 | case 69: /* Haswell-Celeron */ | ||
667 | rapl_cntr_mask = RAPL_IDX_HSW; | ||
668 | rapl_pmu_events_group.attrs = rapl_events_hsw_attr; | ||
669 | break; | ||
639 | case 45: /* Sandy Bridge-EP */ | 670 | case 45: /* Sandy Bridge-EP */ |
640 | case 62: /* IvyTown */ | 671 | case 62: /* IvyTown */ |
641 | rapl_cntr_mask = RAPL_IDX_SRV; | 672 | rapl_cntr_mask = RAPL_IDX_SRV; |
@@ -650,7 +681,9 @@ static int __init rapl_pmu_init(void) | |||
650 | cpu_notifier_register_begin(); | 681 | cpu_notifier_register_begin(); |
651 | 682 | ||
652 | for_each_online_cpu(cpu) { | 683 | for_each_online_cpu(cpu) { |
653 | rapl_cpu_prepare(cpu); | 684 | ret = rapl_cpu_prepare(cpu); |
685 | if (ret) | ||
686 | goto out; | ||
654 | rapl_cpu_init(cpu); | 687 | rapl_cpu_init(cpu); |
655 | } | 688 | } |
656 | 689 | ||
@@ -673,6 +706,7 @@ static int __init rapl_pmu_init(void) | |||
673 | hweight32(rapl_cntr_mask), | 706 | hweight32(rapl_cntr_mask), |
674 | ktime_to_ms(pmu->timer_interval)); | 707 | ktime_to_ms(pmu->timer_interval)); |
675 | 708 | ||
709 | out: | ||
676 | cpu_notifier_register_done(); | 710 | cpu_notifier_register_done(); |
677 | 711 | ||
678 | return 0; | 712 | return 0; |