@@ -5818,6 +5818,14 @@ static int has_instr_count_access(void)
5818
5818
return has_access ;
5819
5819
}
5820
5820
5821
+ bool is_aperf_access_required (void )
5822
+ {
5823
+ return BIC_IS_ENABLED (BIC_Avg_MHz )
5824
+ || BIC_IS_ENABLED (BIC_Busy )
5825
+ || BIC_IS_ENABLED (BIC_Bzy_MHz )
5826
+ || BIC_IS_ENABLED (BIC_IPC );
5827
+ }
5828
+
5821
5829
/*
5822
5830
* Linux-perf manages the HW instructions-retired counter
5823
5831
* by enabling when requested, and hiding rollover
@@ -5833,8 +5841,7 @@ void linux_perf_init(void)
5833
5841
err (-1 , "calloc fd_instr_count_percpu" );
5834
5842
}
5835
5843
5836
- const bool aperf_required = BIC_IS_ENABLED (BIC_Avg_MHz ) || BIC_IS_ENABLED (BIC_Busy ) ||
5837
- BIC_IS_ENABLED (BIC_Bzy_MHz ) || BIC_IS_ENABLED (BIC_IPC );
5844
+ const bool aperf_required = is_aperf_access_required ();
5838
5845
if (aperf_required && has_aperf && amperf_source == AMPERF_SOURCE_PERF ) {
5839
5846
fd_amperf_percpu = calloc (topo .max_cpu_num + 1 , sizeof (* fd_amperf_percpu ));
5840
5847
if (fd_amperf_percpu == NULL )
@@ -5903,6 +5910,9 @@ static int has_amperf_access_via_perf(void)
5903
5910
/* Check if we can access APERF and MPERF */
5904
5911
static int has_amperf_access (void )
5905
5912
{
5913
+ if (!is_aperf_access_required ())
5914
+ return 0 ;
5915
+
5906
5916
if (!no_msr && has_amperf_access_via_msr ())
5907
5917
return 1 ;
5908
5918
@@ -6581,7 +6591,8 @@ static void set_amperf_source(void)
6581
6591
{
6582
6592
amperf_source = AMPERF_SOURCE_PERF ;
6583
6593
6584
- if (no_perf || !has_amperf_access_via_perf ())
6594
+ const bool aperf_required = is_aperf_access_required ();
6595
+ if (no_perf || !aperf_required || !has_amperf_access_via_perf ())
6585
6596
amperf_source = AMPERF_SOURCE_MSR ;
6586
6597
6587
6598
if (quiet || !debug )
@@ -6590,8 +6601,51 @@ static void set_amperf_source(void)
6590
6601
fprintf (outf , "aperf/mperf source preference: %s\n" , amperf_source == AMPERF_SOURCE_MSR ? "msr" : "perf" );
6591
6602
}
6592
6603
6604
+ bool is_msr_access_required (void )
6605
+ {
6606
+ /* TODO: add detection for dynamic counters from add_counter() */
6607
+ if (no_msr )
6608
+ return false;
6609
+
6610
+ return BIC_IS_ENABLED (BIC_SMI )
6611
+ || BIC_IS_ENABLED (BIC_CPU_c1 )
6612
+ || BIC_IS_ENABLED (BIC_CPU_c3 )
6613
+ || BIC_IS_ENABLED (BIC_CPU_c6 )
6614
+ || BIC_IS_ENABLED (BIC_CPU_c7 )
6615
+ || BIC_IS_ENABLED (BIC_Mod_c6 )
6616
+ || BIC_IS_ENABLED (BIC_CoreTmp )
6617
+ || BIC_IS_ENABLED (BIC_Totl_c0 )
6618
+ || BIC_IS_ENABLED (BIC_Any_c0 )
6619
+ || BIC_IS_ENABLED (BIC_GFX_c0 )
6620
+ || BIC_IS_ENABLED (BIC_CPUGFX )
6621
+ || BIC_IS_ENABLED (BIC_Pkgpc3 )
6622
+ || BIC_IS_ENABLED (BIC_Pkgpc6 )
6623
+ || BIC_IS_ENABLED (BIC_Pkgpc2 )
6624
+ || BIC_IS_ENABLED (BIC_Pkgpc7 )
6625
+ || BIC_IS_ENABLED (BIC_Pkgpc8 )
6626
+ || BIC_IS_ENABLED (BIC_Pkgpc9 )
6627
+ || BIC_IS_ENABLED (BIC_Pkgpc10 )
6628
+ || BIC_IS_ENABLED (BIC_CorWatt )
6629
+ || BIC_IS_ENABLED (BIC_Cor_J )
6630
+ || BIC_IS_ENABLED (BIC_PkgWatt )
6631
+ || BIC_IS_ENABLED (BIC_CorWatt )
6632
+ || BIC_IS_ENABLED (BIC_GFXWatt )
6633
+ || BIC_IS_ENABLED (BIC_RAMWatt )
6634
+ || BIC_IS_ENABLED (BIC_Pkg_J )
6635
+ || BIC_IS_ENABLED (BIC_Cor_J )
6636
+ || BIC_IS_ENABLED (BIC_GFX_J )
6637
+ || BIC_IS_ENABLED (BIC_RAM_J )
6638
+ || BIC_IS_ENABLED (BIC_PKG__ )
6639
+ || BIC_IS_ENABLED (BIC_RAM__ )
6640
+ || BIC_IS_ENABLED (BIC_PkgTmp )
6641
+ || (is_aperf_access_required () && !has_amperf_access_via_perf ());
6642
+ }
6643
+
6593
6644
void check_msr_access (void )
6594
6645
{
6646
+ if (!is_msr_access_required ())
6647
+ no_msr = 1 ;
6648
+
6595
6649
check_dev_msr ();
6596
6650
check_msr_permission ();
6597
6651
@@ -6601,10 +6655,12 @@ void check_msr_access(void)
6601
6655
6602
6656
void check_perf_access (void )
6603
6657
{
6604
- if (no_perf || !has_instr_count_access ())
6658
+ const bool intrcount_required = BIC_IS_ENABLED (BIC_IPC );
6659
+ if (no_perf || !intrcount_required || !has_instr_count_access ())
6605
6660
bic_enabled &= ~BIC_IPC ;
6606
6661
6607
- if (!has_amperf_access ()) {
6662
+ const bool aperf_required = is_aperf_access_required ();
6663
+ if (!aperf_required || !has_amperf_access ()) {
6608
6664
bic_enabled &= ~BIC_Avg_MHz ;
6609
6665
bic_enabled &= ~BIC_Busy ;
6610
6666
bic_enabled &= ~BIC_Bzy_MHz ;
0 commit comments