@@ -70,18 +70,18 @@ MODULE_LICENSE("GPL");
70
70
/*
71
71
* RAPL energy status counters
72
72
*/
73
- enum perf_rapl_events {
73
+ enum perf_rapl_pkg_events {
74
74
PERF_RAPL_PP0 = 0 , /* all cores */
75
75
PERF_RAPL_PKG , /* entire package */
76
76
PERF_RAPL_RAM , /* DRAM */
77
77
PERF_RAPL_PP1 , /* gpu */
78
78
PERF_RAPL_PSYS , /* psys */
79
79
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 ,
82
82
};
83
83
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 = {
85
85
"pp0-core" ,
86
86
"package" ,
87
87
"dram" ,
@@ -112,7 +112,7 @@ static struct perf_pmu_events_attr event_attr_##v = { \
112
112
* considered as either pkg-scope or die-scope, and we are considering
113
113
* them as die-scope.
114
114
*/
115
- #define rapl_pmu_is_pkg_scope () \
115
+ #define rapl_pkg_pmu_is_pkg_scope () \
116
116
(boot_cpu_data.x86_vendor == X86_VENDOR_AMD || \
117
117
boot_cpu_data.x86_vendor == X86_VENDOR_HYGON)
118
118
@@ -139,16 +139,16 @@ enum rapl_unit_quirk {
139
139
};
140
140
141
141
struct rapl_model {
142
- struct perf_msr * rapl_msrs ;
143
- unsigned long events ;
142
+ struct perf_msr * rapl_pkg_msrs ;
143
+ unsigned long pkg_events ;
144
144
unsigned int msr_power_unit ;
145
145
enum rapl_unit_quirk unit_quirk ;
146
146
};
147
147
148
148
/* 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 ;
152
152
static u64 rapl_timer_ms ;
153
153
static struct perf_msr * rapl_msrs ;
154
154
static struct rapl_model * rapl_model ;
@@ -164,8 +164,8 @@ static inline unsigned int get_rapl_pmu_idx(int cpu)
164
164
* (for non-existent mappings in topology map) to UINT_MAX, so
165
165
* the error check in the caller is simplified.
166
166
*/
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 );
169
169
}
170
170
171
171
static inline u64 rapl_read_counter (struct perf_event * event )
@@ -177,7 +177,7 @@ static inline u64 rapl_read_counter(struct perf_event *event)
177
177
178
178
static inline u64 rapl_scale (u64 v , int cfg )
179
179
{
180
- if (cfg > NR_RAPL_DOMAINS ) {
180
+ if (cfg > NR_RAPL_PKG_DOMAINS ) {
181
181
pr_warn ("Invalid domain %d, failed to scale data\n" , cfg );
182
182
return v ;
183
183
}
@@ -187,7 +187,7 @@ static inline u64 rapl_scale(u64 v, int cfg)
187
187
* or use ldexp(count, -32).
188
188
* Watts = Joules/Time delta
189
189
*/
190
- return v << (32 - rapl_hw_unit [cfg - 1 ]);
190
+ return v << (32 - rapl_pkg_hw_unit [cfg - 1 ]);
191
191
}
192
192
193
193
static u64 rapl_event_update (struct perf_event * event )
@@ -348,7 +348,7 @@ static int rapl_pmu_event_init(struct perf_event *event)
348
348
unsigned int rapl_pmu_idx ;
349
349
350
350
/* only look at RAPL events */
351
- if (event -> attr .type != rapl_pmus -> pmu .type )
351
+ if (event -> attr .type != rapl_pmus_pkg -> pmu .type )
352
352
return - ENOENT ;
353
353
354
354
/* check only supported bits are set */
@@ -358,26 +358,26 @@ static int rapl_pmu_event_init(struct perf_event *event)
358
358
if (event -> cpu < 0 )
359
359
return - EINVAL ;
360
360
361
- if (!cfg || cfg >= NR_RAPL_DOMAINS + 1 )
361
+ if (!cfg || cfg >= NR_RAPL_PKG_DOMAINS + 1 )
362
362
return - EINVAL ;
363
363
364
- cfg = array_index_nospec ((long )cfg , NR_RAPL_DOMAINS + 1 );
364
+ cfg = array_index_nospec ((long )cfg , NR_RAPL_PKG_DOMAINS + 1 );
365
365
bit = cfg - 1 ;
366
366
367
367
/* check event supported */
368
- if (!(rapl_cntr_mask & (1 << bit )))
368
+ if (!(rapl_pkg_cntr_mask & (1 << bit )))
369
369
return - EINVAL ;
370
370
371
371
/* unsupported modes and filters */
372
372
if (event -> attr .sample_period ) /* no sampling */
373
373
return - EINVAL ;
374
374
375
375
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 )
377
377
return - EINVAL ;
378
378
379
379
/* 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 ];
381
381
if (!rapl_pmu )
382
382
return - EINVAL ;
383
383
@@ -531,11 +531,11 @@ static struct perf_msr intel_rapl_spr_msrs[] = {
531
531
};
532
532
533
533
/*
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 )
536
536
* - want to use same event codes across both architectures
537
537
*/
538
- static struct perf_msr amd_rapl_msrs [] = {
538
+ static struct perf_msr amd_rapl_pkg_msrs [] = {
539
539
[PERF_RAPL_PP0 ] = { 0 , & rapl_events_cores_group , NULL , false, 0 },
540
540
[PERF_RAPL_PKG ] = { MSR_AMD_PKG_ENERGY_STATUS , & rapl_events_pkg_group , test_msr , false, RAPL_MSR_MASK },
541
541
[PERF_RAPL_RAM ] = { 0 , & rapl_events_ram_group , NULL , false, 0 },
@@ -551,8 +551,8 @@ static int rapl_check_hw_unit(void)
551
551
/* protect rdmsrl() to handle virtualization */
552
552
if (rdmsrl_safe (rapl_model -> msr_power_unit , & msr_rapl_power_unit_bits ))
553
553
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 ;
556
556
557
557
switch (rapl_model -> unit_quirk ) {
558
558
/*
@@ -562,11 +562,11 @@ static int rapl_check_hw_unit(void)
562
562
* of 2. Datasheet, September 2014, Reference Number: 330784-001 "
563
563
*/
564
564
case RAPL_UNIT_QUIRK_INTEL_HSW :
565
- rapl_hw_unit [PERF_RAPL_RAM ] = 16 ;
565
+ rapl_pkg_hw_unit [PERF_RAPL_RAM ] = 16 ;
566
566
break ;
567
567
/* SPR uses a fixed energy unit for Psys domain. */
568
568
case RAPL_UNIT_QUIRK_INTEL_SPR :
569
- rapl_hw_unit [PERF_RAPL_PSYS ] = 0 ;
569
+ rapl_pkg_hw_unit [PERF_RAPL_PSYS ] = 0 ;
570
570
break ;
571
571
default :
572
572
break ;
@@ -581,9 +581,9 @@ static int rapl_check_hw_unit(void)
581
581
* if hw unit is 32, then we use 2 ms 1/200/2
582
582
*/
583
583
rapl_timer_ms = 2 ;
584
- if (rapl_hw_unit [0 ] < 32 ) {
584
+ if (rapl_pkg_hw_unit [0 ] < 32 ) {
585
585
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 ));
587
587
}
588
588
return 0 ;
589
589
}
@@ -593,12 +593,12 @@ static void __init rapl_advertise(void)
593
593
int i ;
594
594
595
595
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 );
597
597
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 )) {
600
600
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 ]);
602
602
}
603
603
}
604
604
}
@@ -679,71 +679,71 @@ static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr, int rapl_pmu_
679
679
}
680
680
681
681
static struct rapl_model model_snb = {
682
- .events = BIT (PERF_RAPL_PP0 ) |
682
+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
683
683
BIT (PERF_RAPL_PKG ) |
684
684
BIT (PERF_RAPL_PP1 ),
685
685
.msr_power_unit = MSR_RAPL_POWER_UNIT ,
686
- .rapl_msrs = intel_rapl_msrs ,
686
+ .rapl_pkg_msrs = intel_rapl_msrs ,
687
687
};
688
688
689
689
static struct rapl_model model_snbep = {
690
- .events = BIT (PERF_RAPL_PP0 ) |
690
+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
691
691
BIT (PERF_RAPL_PKG ) |
692
692
BIT (PERF_RAPL_RAM ),
693
693
.msr_power_unit = MSR_RAPL_POWER_UNIT ,
694
- .rapl_msrs = intel_rapl_msrs ,
694
+ .rapl_pkg_msrs = intel_rapl_msrs ,
695
695
};
696
696
697
697
static struct rapl_model model_hsw = {
698
- .events = BIT (PERF_RAPL_PP0 ) |
698
+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
699
699
BIT (PERF_RAPL_PKG ) |
700
700
BIT (PERF_RAPL_RAM ) |
701
701
BIT (PERF_RAPL_PP1 ),
702
702
.msr_power_unit = MSR_RAPL_POWER_UNIT ,
703
- .rapl_msrs = intel_rapl_msrs ,
703
+ .rapl_pkg_msrs = intel_rapl_msrs ,
704
704
};
705
705
706
706
static struct rapl_model model_hsx = {
707
- .events = BIT (PERF_RAPL_PP0 ) |
707
+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
708
708
BIT (PERF_RAPL_PKG ) |
709
709
BIT (PERF_RAPL_RAM ),
710
710
.unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW ,
711
711
.msr_power_unit = MSR_RAPL_POWER_UNIT ,
712
- .rapl_msrs = intel_rapl_msrs ,
712
+ .rapl_pkg_msrs = intel_rapl_msrs ,
713
713
};
714
714
715
715
static struct rapl_model model_knl = {
716
- .events = BIT (PERF_RAPL_PKG ) |
716
+ .pkg_events = BIT (PERF_RAPL_PKG ) |
717
717
BIT (PERF_RAPL_RAM ),
718
718
.unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW ,
719
719
.msr_power_unit = MSR_RAPL_POWER_UNIT ,
720
- .rapl_msrs = intel_rapl_msrs ,
720
+ .rapl_pkg_msrs = intel_rapl_msrs ,
721
721
};
722
722
723
723
static struct rapl_model model_skl = {
724
- .events = BIT (PERF_RAPL_PP0 ) |
724
+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
725
725
BIT (PERF_RAPL_PKG ) |
726
726
BIT (PERF_RAPL_RAM ) |
727
727
BIT (PERF_RAPL_PP1 ) |
728
728
BIT (PERF_RAPL_PSYS ),
729
729
.msr_power_unit = MSR_RAPL_POWER_UNIT ,
730
- .rapl_msrs = intel_rapl_msrs ,
730
+ .rapl_pkg_msrs = intel_rapl_msrs ,
731
731
};
732
732
733
733
static struct rapl_model model_spr = {
734
- .events = BIT (PERF_RAPL_PP0 ) |
734
+ .pkg_events = BIT (PERF_RAPL_PP0 ) |
735
735
BIT (PERF_RAPL_PKG ) |
736
736
BIT (PERF_RAPL_RAM ) |
737
737
BIT (PERF_RAPL_PSYS ),
738
738
.unit_quirk = RAPL_UNIT_QUIRK_INTEL_SPR ,
739
739
.msr_power_unit = MSR_RAPL_POWER_UNIT ,
740
- .rapl_msrs = intel_rapl_spr_msrs ,
740
+ .rapl_pkg_msrs = intel_rapl_spr_msrs ,
741
741
};
742
742
743
743
static struct rapl_model model_amd_hygon = {
744
- .events = BIT (PERF_RAPL_PKG ),
744
+ .pkg_events = BIT (PERF_RAPL_PKG ),
745
745
.msr_power_unit = MSR_AMD_RAPL_POWER_UNIT ,
746
- .rapl_msrs = amd_rapl_msrs ,
746
+ .rapl_pkg_msrs = amd_rapl_pkg_msrs ,
747
747
};
748
748
749
749
static const struct x86_cpu_id rapl_model_match [] __initconst = {
@@ -799,32 +799,32 @@ MODULE_DEVICE_TABLE(x86cpu, rapl_model_match);
799
799
static int __init rapl_pmu_init (void )
800
800
{
801
801
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 ;
803
803
int ret ;
804
804
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 ;
807
807
808
808
id = x86_match_cpu (rapl_model_match );
809
809
if (!id )
810
810
return - ENODEV ;
811
811
812
812
rapl_model = (struct rapl_model * ) id -> driver_data ;
813
813
814
- rapl_msrs = rapl_model -> rapl_msrs ;
814
+ rapl_msrs = rapl_model -> rapl_pkg_msrs ;
815
815
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 );
818
818
819
819
ret = rapl_check_hw_unit ();
820
820
if (ret )
821
821
return ret ;
822
822
823
- ret = init_rapl_pmus (& rapl_pmus , rapl_pmu_scope );
823
+ ret = init_rapl_pmus (& rapl_pmus_pkg , rapl_pkg_pmu_scope );
824
824
if (ret )
825
825
return ret ;
826
826
827
- ret = perf_pmu_register (& rapl_pmus -> pmu , "power" , -1 );
827
+ ret = perf_pmu_register (& rapl_pmus_pkg -> pmu , "power" , -1 );
828
828
if (ret )
829
829
goto out ;
830
830
@@ -833,14 +833,14 @@ static int __init rapl_pmu_init(void)
833
833
834
834
out :
835
835
pr_warn ("Initialization failed (%d), disabled\n" , ret );
836
- cleanup_rapl_pmus (rapl_pmus );
836
+ cleanup_rapl_pmus (rapl_pmus_pkg );
837
837
return ret ;
838
838
}
839
839
module_init (rapl_pmu_init );
840
840
841
841
static void __exit intel_rapl_exit (void )
842
842
{
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 );
845
845
}
846
846
module_exit (intel_rapl_exit );
0 commit comments