@@ -70,18 +70,18 @@ MODULE_LICENSE("GPL");
7070/*
7171 * RAPL energy status counters
7272 */
73- enum perf_rapl_events {
73+ enum perf_rapl_pkg_events {
7474 PERF_RAPL_PP0 = 0 , /* all cores */
7575 PERF_RAPL_PKG , /* entire package */
7676 PERF_RAPL_RAM , /* DRAM */
7777 PERF_RAPL_PP1 , /* gpu */
7878 PERF_RAPL_PSYS , /* psys */
7979
80- PERF_RAPL_MAX ,
81- NR_RAPL_DOMAINS = PERF_RAPL_MAX ,
80+ PERF_RAPL_PKG_EVENTS_MAX ,
81+ NR_RAPL_PKG_DOMAINS = PERF_RAPL_PKG_EVENTS_MAX ,
8282};
8383
84- static const char * const rapl_domain_names [ NR_RAPL_DOMAINS ] __initconst = {
84+ static const char * const rapl_pkg_domain_names [ NR_RAPL_PKG_DOMAINS ] __initconst = {
8585 "pp0-core" ,
8686 "package" ,
8787 "dram" ,
@@ -112,7 +112,7 @@ static struct perf_pmu_events_attr event_attr_##v = { \
112112 * considered as either pkg-scope or die-scope, and we are considering
113113 * them as die-scope.
114114 */
115- #define rapl_pmu_is_pkg_scope () \
115+ #define rapl_pkg_pmu_is_pkg_scope () \
116116 (boot_cpu_data.x86_vendor == X86_VENDOR_AMD || \
117117 boot_cpu_data.x86_vendor == X86_VENDOR_HYGON)
118118
@@ -139,16 +139,16 @@ enum rapl_unit_quirk {
139139};
140140
141141struct rapl_model {
142- struct perf_msr * rapl_msrs ;
143- unsigned long events ;
142+ struct perf_msr * rapl_pkg_msrs ;
143+ unsigned long pkg_events ;
144144 unsigned int msr_power_unit ;
145145 enum rapl_unit_quirk unit_quirk ;
146146};
147147
148148 /* 1/2^hw_unit Joule */
149- static int rapl_hw_unit [ NR_RAPL_DOMAINS ] __read_mostly ;
150- static struct rapl_pmus * rapl_pmus ;
151- static unsigned int rapl_cntr_mask ;
149+ static int rapl_pkg_hw_unit [ NR_RAPL_PKG_DOMAINS ] __read_mostly ;
150+ static struct rapl_pmus * rapl_pmus_pkg ;
151+ static unsigned int rapl_pkg_cntr_mask ;
152152static u64 rapl_timer_ms ;
153153static struct perf_msr * rapl_msrs ;
154154static struct rapl_model * rapl_model ;
@@ -164,8 +164,8 @@ static inline unsigned int get_rapl_pmu_idx(int cpu)
164164 * (for non-existent mappings in topology map) to UINT_MAX, so
165165 * the error check in the caller is simplified.
166166 */
167- return rapl_pmu_is_pkg_scope () ? topology_logical_package_id (cpu ) :
168- topology_logical_die_id (cpu );
167+ return rapl_pkg_pmu_is_pkg_scope () ? topology_logical_package_id (cpu ) :
168+ topology_logical_die_id (cpu );
169169}
170170
171171static inline u64 rapl_read_counter (struct perf_event * event )
@@ -177,7 +177,7 @@ static inline u64 rapl_read_counter(struct perf_event *event)
177177
178178static inline u64 rapl_scale (u64 v , int cfg )
179179{
180- if (cfg > NR_RAPL_DOMAINS ) {
180+ if (cfg > NR_RAPL_PKG_DOMAINS ) {
181181 pr_warn ("Invalid domain %d, failed to scale data\n" , cfg );
182182 return v ;
183183 }
@@ -187,7 +187,7 @@ static inline u64 rapl_scale(u64 v, int cfg)
187187 * or use ldexp(count, -32).
188188 * Watts = Joules/Time delta
189189 */
190- return v << (32 - rapl_hw_unit [cfg - 1 ]);
190+ return v << (32 - rapl_pkg_hw_unit [cfg - 1 ]);
191191}
192192
193193static u64 rapl_event_update (struct perf_event * event )
@@ -348,7 +348,7 @@ static int rapl_pmu_event_init(struct perf_event *event)
348348 unsigned int rapl_pmu_idx ;
349349
350350 /* only look at RAPL events */
351- if (event -> attr .type != rapl_pmus -> pmu .type )
351+ if (event -> attr .type != rapl_pmus_pkg -> pmu .type )
352352 return - ENOENT ;
353353
354354 /* check only supported bits are set */
@@ -358,26 +358,26 @@ static int rapl_pmu_event_init(struct perf_event *event)
358358 if (event -> cpu < 0 )
359359 return - EINVAL ;
360360
361- if (!cfg || cfg >= NR_RAPL_DOMAINS + 1 )
361+ if (!cfg || cfg >= NR_RAPL_PKG_DOMAINS + 1 )
362362 return - EINVAL ;
363363
364- cfg = array_index_nospec ((long )cfg , NR_RAPL_DOMAINS + 1 );
364+ cfg = array_index_nospec ((long )cfg , NR_RAPL_PKG_DOMAINS + 1 );
365365 bit = cfg - 1 ;
366366
367367 /* check event supported */
368- if (!(rapl_cntr_mask & (1 << bit )))
368+ if (!(rapl_pkg_cntr_mask & (1 << bit )))
369369 return - EINVAL ;
370370
371371 /* unsupported modes and filters */
372372 if (event -> attr .sample_period ) /* no sampling */
373373 return - EINVAL ;
374374
375375 rapl_pmu_idx = get_rapl_pmu_idx (event -> cpu );
376- if (rapl_pmu_idx >= rapl_pmus -> nr_rapl_pmu )
376+ if (rapl_pmu_idx >= rapl_pmus_pkg -> nr_rapl_pmu )
377377 return - EINVAL ;
378378
379379 /* must be done before validate_group */
380- rapl_pmu = rapl_pmus -> rapl_pmu [rapl_pmu_idx ];
380+ rapl_pmu = rapl_pmus_pkg -> rapl_pmu [rapl_pmu_idx ];
381381 if (!rapl_pmu )
382382 return - EINVAL ;
383383
@@ -531,11 +531,11 @@ static struct perf_msr intel_rapl_spr_msrs[] = {
531531};
532532
533533/*
534- * Force to PERF_RAPL_MAX size due to:
535- * - perf_msr_probe(PERF_RAPL_MAX )
534+ * Force to PERF_RAPL_PKG_EVENTS_MAX size due to:
535+ * - perf_msr_probe(PERF_RAPL_PKG_EVENTS_MAX )
536536 * - want to use same event codes across both architectures
537537 */
538- static struct perf_msr amd_rapl_msrs [] = {
538+ static struct perf_msr amd_rapl_pkg_msrs [] = {
539539 [PERF_RAPL_PP0 ] = { 0 , & rapl_events_cores_group , NULL , false, 0 },
540540 [PERF_RAPL_PKG ] = { MSR_AMD_PKG_ENERGY_STATUS , & rapl_events_pkg_group , test_msr , false, RAPL_MSR_MASK },
541541 [PERF_RAPL_RAM ] = { 0 , & rapl_events_ram_group , NULL , false, 0 },
@@ -551,8 +551,8 @@ static int rapl_check_hw_unit(void)
551551 /* protect rdmsrl() to handle virtualization */
552552 if (rdmsrl_safe (rapl_model -> msr_power_unit , & msr_rapl_power_unit_bits ))
553553 return -1 ;
554- for (i = 0 ; i < NR_RAPL_DOMAINS ; i ++ )
555- rapl_hw_unit [i ] = (msr_rapl_power_unit_bits >> 8 ) & 0x1FULL ;
554+ for (i = 0 ; i < NR_RAPL_PKG_DOMAINS ; i ++ )
555+ rapl_pkg_hw_unit [i ] = (msr_rapl_power_unit_bits >> 8 ) & 0x1FULL ;
556556
557557 switch (rapl_model -> unit_quirk ) {
558558 /*
@@ -562,11 +562,11 @@ static int rapl_check_hw_unit(void)
562562 * of 2. Datasheet, September 2014, Reference Number: 330784-001 "
563563 */
564564 case RAPL_UNIT_QUIRK_INTEL_HSW :
565- rapl_hw_unit [PERF_RAPL_RAM ] = 16 ;
565+ rapl_pkg_hw_unit [PERF_RAPL_RAM ] = 16 ;
566566 break ;
567567 /* SPR uses a fixed energy unit for Psys domain. */
568568 case RAPL_UNIT_QUIRK_INTEL_SPR :
569- rapl_hw_unit [PERF_RAPL_PSYS ] = 0 ;
569+ rapl_pkg_hw_unit [PERF_RAPL_PSYS ] = 0 ;
570570 break ;
571571 default :
572572 break ;
@@ -581,9 +581,9 @@ static int rapl_check_hw_unit(void)
581581 * if hw unit is 32, then we use 2 ms 1/200/2
582582 */
583583 rapl_timer_ms = 2 ;
584- if (rapl_hw_unit [0 ] < 32 ) {
584+ if (rapl_pkg_hw_unit [0 ] < 32 ) {
585585 rapl_timer_ms = (1000 / (2 * 100 ));
586- rapl_timer_ms *= (1ULL << (32 - rapl_hw_unit [0 ] - 1 ));
586+ rapl_timer_ms *= (1ULL << (32 - rapl_pkg_hw_unit [0 ] - 1 ));
587587 }
588588 return 0 ;
589589}
@@ -593,12 +593,12 @@ static void __init rapl_advertise(void)
593593 int i ;
594594
595595 pr_info ("API unit is 2^-32 Joules, %d fixed counters, %llu ms ovfl timer\n" ,
596- hweight32 (rapl_cntr_mask ), rapl_timer_ms );
596+ hweight32 (rapl_pkg_cntr_mask ), rapl_timer_ms );
597597
598- for (i = 0 ; i < NR_RAPL_DOMAINS ; i ++ ) {
599- if (rapl_cntr_mask & (1 << i )) {
598+ for (i = 0 ; i < NR_RAPL_PKG_DOMAINS ; i ++ ) {
599+ if (rapl_pkg_cntr_mask & (1 << i )) {
600600 pr_info ("hw unit of domain %s 2^-%d Joules\n" ,
601- rapl_domain_names [i ], rapl_hw_unit [i ]);
601+ rapl_pkg_domain_names [i ], rapl_pkg_hw_unit [i ]);
602602 }
603603 }
604604}
@@ -679,71 +679,71 @@ static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr, int rapl_pmu_
679679}
680680
681681static struct rapl_model model_snb = {
682- .events = BIT (PERF_RAPL_PP0 ) |
682+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
683683 BIT (PERF_RAPL_PKG ) |
684684 BIT (PERF_RAPL_PP1 ),
685685 .msr_power_unit = MSR_RAPL_POWER_UNIT ,
686- .rapl_msrs = intel_rapl_msrs ,
686+ .rapl_pkg_msrs = intel_rapl_msrs ,
687687};
688688
689689static struct rapl_model model_snbep = {
690- .events = BIT (PERF_RAPL_PP0 ) |
690+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
691691 BIT (PERF_RAPL_PKG ) |
692692 BIT (PERF_RAPL_RAM ),
693693 .msr_power_unit = MSR_RAPL_POWER_UNIT ,
694- .rapl_msrs = intel_rapl_msrs ,
694+ .rapl_pkg_msrs = intel_rapl_msrs ,
695695};
696696
697697static struct rapl_model model_hsw = {
698- .events = BIT (PERF_RAPL_PP0 ) |
698+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
699699 BIT (PERF_RAPL_PKG ) |
700700 BIT (PERF_RAPL_RAM ) |
701701 BIT (PERF_RAPL_PP1 ),
702702 .msr_power_unit = MSR_RAPL_POWER_UNIT ,
703- .rapl_msrs = intel_rapl_msrs ,
703+ .rapl_pkg_msrs = intel_rapl_msrs ,
704704};
705705
706706static struct rapl_model model_hsx = {
707- .events = BIT (PERF_RAPL_PP0 ) |
707+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
708708 BIT (PERF_RAPL_PKG ) |
709709 BIT (PERF_RAPL_RAM ),
710710 .unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW ,
711711 .msr_power_unit = MSR_RAPL_POWER_UNIT ,
712- .rapl_msrs = intel_rapl_msrs ,
712+ .rapl_pkg_msrs = intel_rapl_msrs ,
713713};
714714
715715static struct rapl_model model_knl = {
716- .events = BIT (PERF_RAPL_PKG ) |
716+ .pkg_events = BIT (PERF_RAPL_PKG ) |
717717 BIT (PERF_RAPL_RAM ),
718718 .unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW ,
719719 .msr_power_unit = MSR_RAPL_POWER_UNIT ,
720- .rapl_msrs = intel_rapl_msrs ,
720+ .rapl_pkg_msrs = intel_rapl_msrs ,
721721};
722722
723723static struct rapl_model model_skl = {
724- .events = BIT (PERF_RAPL_PP0 ) |
724+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
725725 BIT (PERF_RAPL_PKG ) |
726726 BIT (PERF_RAPL_RAM ) |
727727 BIT (PERF_RAPL_PP1 ) |
728728 BIT (PERF_RAPL_PSYS ),
729729 .msr_power_unit = MSR_RAPL_POWER_UNIT ,
730- .rapl_msrs = intel_rapl_msrs ,
730+ .rapl_pkg_msrs = intel_rapl_msrs ,
731731};
732732
733733static struct rapl_model model_spr = {
734- .events = BIT (PERF_RAPL_PP0 ) |
734+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
735735 BIT (PERF_RAPL_PKG ) |
736736 BIT (PERF_RAPL_RAM ) |
737737 BIT (PERF_RAPL_PSYS ),
738738 .unit_quirk = RAPL_UNIT_QUIRK_INTEL_SPR ,
739739 .msr_power_unit = MSR_RAPL_POWER_UNIT ,
740- .rapl_msrs = intel_rapl_spr_msrs ,
740+ .rapl_pkg_msrs = intel_rapl_spr_msrs ,
741741};
742742
743743static struct rapl_model model_amd_hygon = {
744- .events = BIT (PERF_RAPL_PKG ),
744+ .pkg_events = BIT (PERF_RAPL_PKG ),
745745 .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT ,
746- .rapl_msrs = amd_rapl_msrs ,
746+ .rapl_pkg_msrs = amd_rapl_pkg_msrs ,
747747};
748748
749749static const struct x86_cpu_id rapl_model_match [] __initconst = {
@@ -799,32 +799,32 @@ MODULE_DEVICE_TABLE(x86cpu, rapl_model_match);
799799static int __init rapl_pmu_init (void )
800800{
801801 const struct x86_cpu_id * id ;
802- int rapl_pmu_scope = PERF_PMU_SCOPE_DIE ;
802+ int rapl_pkg_pmu_scope = PERF_PMU_SCOPE_DIE ;
803803 int ret ;
804804
805- if (rapl_pmu_is_pkg_scope ())
806- rapl_pmu_scope = PERF_PMU_SCOPE_PKG ;
805+ if (rapl_pkg_pmu_is_pkg_scope ())
806+ rapl_pkg_pmu_scope = PERF_PMU_SCOPE_PKG ;
807807
808808 id = x86_match_cpu (rapl_model_match );
809809 if (!id )
810810 return - ENODEV ;
811811
812812 rapl_model = (struct rapl_model * ) id -> driver_data ;
813813
814- rapl_msrs = rapl_model -> rapl_msrs ;
814+ rapl_msrs = rapl_model -> rapl_pkg_msrs ;
815815
816- rapl_cntr_mask = perf_msr_probe (rapl_msrs , PERF_RAPL_MAX ,
817- false, (void * ) & rapl_model -> events );
816+ rapl_pkg_cntr_mask = perf_msr_probe (rapl_msrs , PERF_RAPL_PKG_EVENTS_MAX ,
817+ false, (void * ) & rapl_model -> pkg_events );
818818
819819 ret = rapl_check_hw_unit ();
820820 if (ret )
821821 return ret ;
822822
823- ret = init_rapl_pmus (& rapl_pmus , rapl_pmu_scope );
823+ ret = init_rapl_pmus (& rapl_pmus_pkg , rapl_pkg_pmu_scope );
824824 if (ret )
825825 return ret ;
826826
827- ret = perf_pmu_register (& rapl_pmus -> pmu , "power" , -1 );
827+ ret = perf_pmu_register (& rapl_pmus_pkg -> pmu , "power" , -1 );
828828 if (ret )
829829 goto out ;
830830
@@ -833,14 +833,14 @@ static int __init rapl_pmu_init(void)
833833
834834out :
835835 pr_warn ("Initialization failed (%d), disabled\n" , ret );
836- cleanup_rapl_pmus (rapl_pmus );
836+ cleanup_rapl_pmus (rapl_pmus_pkg );
837837 return ret ;
838838}
839839module_init (rapl_pmu_init );
840840
841841static void __exit intel_rapl_exit (void )
842842{
843- perf_pmu_unregister (& rapl_pmus -> pmu );
844- cleanup_rapl_pmus (rapl_pmus );
843+ perf_pmu_unregister (& rapl_pmus_pkg -> pmu );
844+ cleanup_rapl_pmus (rapl_pmus_pkg );
845845}
846846module_exit (intel_rapl_exit );
0 commit comments