Skip to contentSkip to conversation

selftests/powerpc/pmu: Fix sample field check in the mmcra_thresh_marked_sample_test

PATCH In review Kajol Jain 4 participants 6 messages Mar 1, 2023 – Mar 22, 2023

Subsystems (2)
lore
Share & tools
lore

Kajol Jain

author
#0 lore raw

PATCH 1/2 selftests/powerpc/pmu: Fix sample field check in the mmcra_thresh_marked_sample_test

The testcase verifies the setting of different fields in Monitor Mode Control Register A (MMCRA). In the current code, EV_CODE_EXTRACT macro is used to extract the "sample" field, which then needs to be further processed to fetch rand_samp_elig and rand_samp_mode bits. But the current code is not passing valid sample field to EV_CODE_EXTRACT macro. Patch addresses this by fixing the input for EV_CODE_EXTRACT.

Fixes 29cf373c5766 ("selftests/powerpc/pmu: Add interface test for mmcra register fields")
---
 .../pmu/sampling_tests/mmcra_thresh_marked_sample_test.c      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_thresh_marked_sample_test.c +2 -2
index 022cc1655eb5..75527876ad3c 100644
@@ -63,9 +63,9 @@ static int mmcra_thresh_marked_sample(void)
 			get_mmcra_thd_stop(get_reg_value(intr_regs, "MMCRA"), 4));
 	FAIL_IF(EV_CODE_EXTRACT(event.attr.config, marked) !=
 			get_mmcra_marked(get_reg_value(intr_regs, "MMCRA"), 4));
-	FAIL_IF(EV_CODE_EXTRACT(event.attr.config, sample >> 2) !=
+	FAIL_IF((EV_CODE_EXTRACT(event.attr.config, sample) >> 2) !=
 			get_mmcra_rand_samp_elig(get_reg_value(intr_regs, "MMCRA"), 4));
-	FAIL_IF(EV_CODE_EXTRACT(event.attr.config, sample & 0x3) !=
+	FAIL_IF((EV_CODE_EXTRACT(event.attr.config, sample) & 0x3) !=
 			get_mmcra_sample_mode(get_reg_value(intr_regs, "MMCRA"), 4));
 	FAIL_IF(EV_CODE_EXTRACT(event.attr.config, sm) !=
 			get_mmcra_sm(get_reg_value(intr_regs, "MMCRA"), 4));
Signature · 1 line
2.39.1
author
#1 lore raw

PATCH 2/2 selftests/powerpc/pmu: fix including of utils.h when event.h is included

From: Madhavan Srinivasan <[email protected]>

event.h header already includes utlis.h. Avoid including the same explicitly in the code when event.h included.

---
 tools/testing/selftests/powerpc/pmu/count_instructions.c         | 1 -
 tools/testing/selftests/powerpc/pmu/count_stcx_fail.c            | 1 -
 .../powerpc/pmu/event_code_tests/group_constraint_cache_test.c   | 1 -
 .../pmu/event_code_tests/group_constraint_l2l3_sel_test.c        | 1 -
 .../pmu/event_code_tests/group_constraint_thresh_cmp_test.c      | 1 -
 .../pmu/event_code_tests/group_constraint_thresh_ctl_test.c      | 1 -
 .../pmu/event_code_tests/group_constraint_thresh_sel_test.c      | 1 -
 .../powerpc/pmu/event_code_tests/group_constraint_unit_test.c    | 1 -
 .../powerpc/pmu/event_code_tests/hw_cache_event_type_test.c      | 1 -
 tools/testing/selftests/powerpc/pmu/l3_bank_test.c               | 1 -
 tools/testing/selftests/powerpc/pmu/per_event_excludes.c         | 1 -
 .../selftests/powerpc/pmu/sampling_tests/bhrb_filter_map_test.c  | 1 -
 .../powerpc/pmu/sampling_tests/bhrb_no_crash_wo_pmu_test.c       | 1 -
 .../powerpc/pmu/sampling_tests/intr_regs_no_crash_wo_pmu_test.c  | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcr0_cc56run_test.c    | 1 -
 .../powerpc/pmu/sampling_tests/mmcr0_exceptionbits_test.c        | 1 -
 .../powerpc/pmu/sampling_tests/mmcr0_fc56_pmc1ce_test.c          | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcr0_fc56_pmc56_test.c | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcr0_pmccext_test.c    | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcr0_pmcjce_test.c     | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcr1_comb_test.c       | 1 -
 .../powerpc/pmu/sampling_tests/mmcr1_sel_unit_cache_test.c       | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcr2_fcs_fch_test.c    | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcr2_l2l3_test.c       | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcr3_src_test.c        | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcra_bhrb_any_test.c   | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcra_bhrb_cond_test.c  | 1 -
 .../pmu/sampling_tests/mmcra_bhrb_disable_no_branch_test.c       | 1 -
 .../powerpc/pmu/sampling_tests/mmcra_bhrb_disable_test.c         | 1 -
 .../powerpc/pmu/sampling_tests/mmcra_bhrb_ind_call_test.c        | 1 -
 .../selftests/powerpc/pmu/sampling_tests/mmcra_thresh_cmp_test.c | 1 -
 .../powerpc/pmu/sampling_tests/mmcra_thresh_marked_sample_test.c | 1 -
 32 files changed, 32 deletions(-)
tools/testing/selftests/powerpc/pmu/count_instructions.c +0 -1
index a3984ef1e96a..a0f77065a1e0 100644
@@ -11,7 +11,6 @@
 #include <sys/prctl.h>
 
 #include "event.h"
-#include "utils.h"
 #include "lib.h"
 
 extern void thirty_two_instruction_loop(u64 loops);
tools/testing/selftests/powerpc/pmu/count_stcx_fail.c +0 -1
index 2070a1e2b3a5..07ddac28d3cf 100644
@@ -11,7 +11,6 @@
 #include <sys/prctl.h>
 
 #include "event.h"
-#include "utils.h"
 #include "lib.h"
 
 extern void thirty_two_instruction_loop_with_ll_sc(u64 loops, u64 *ll_sc_target);
tools/testing/selftests/powerpc/pmu/event_code_tests/group_constraint_cache_test.c +0 -1
index f4be05aa3a3d..ad529b8a03ba 100644
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 
 #include "../event.h"
-#include "utils.h"
 #include "../sampling_tests/misc.h"
 
 /* All L1 D cache load references counted at finish, gated by reject */
tools/testing/selftests/powerpc/pmu/event_code_tests/group_constraint_l2l3_sel_test.c +0 -1
index 85a636886069..b2fa5fc54545 100644
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 
 #include "../event.h"
-#include "utils.h"
 #include "../sampling_tests/misc.h"
 
 /* All successful D-side store dispatches for this thread */
tools/testing/selftests/powerpc/pmu/event_code_tests/group_constraint_thresh_cmp_test.c +0 -1
index 9f1197104e8c..d77a730e00df 100644
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 
 #include "../event.h"
-#include "utils.h"
 #include "../sampling_tests/misc.h"
 
 /*
tools/testing/selftests/powerpc/pmu/event_code_tests/group_constraint_thresh_ctl_test.c +0 -1
index e0852ebc1671..f8b79953655a 100644
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 
 #include "../event.h"
-#include "utils.h"
 #include "../sampling_tests/misc.h"
 
 /*
tools/testing/selftests/powerpc/pmu/event_code_tests/group_constraint_thresh_sel_test.c +0 -1
index 50a8cd843ce7..05eb1cf6c5f9 100644
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 
 #include "../event.h"
-#include "utils.h"
 #include "../sampling_tests/misc.h"
 
 /*
tools/testing/selftests/powerpc/pmu/event_code_tests/group_constraint_unit_test.c +0 -1
index a2c18923dcec..151c0b1cff11 100644
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 
 #include "../event.h"
-#include "utils.h"
 #include "../sampling_tests/misc.h"
 
 /* All successful D-side store dispatches for this thread with PMC 2 */
tools/testing/selftests/powerpc/pmu/event_code_tests/hw_cache_event_type_test.c +0 -1
index a45b1da5b568..8020be598d9d 100644
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 
 #include "../event.h"
-#include "utils.h"
 #include "../sampling_tests/misc.h"
 
 /*
tools/testing/selftests/powerpc/pmu/l3_bank_test.c +0 -1
index a5dfa9bf3b9f..29b3039f8fde 100644
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 
 #include "event.h"
-#include "utils.h"
 
 #define MALLOC_SIZE     (0x10000 * 10)  /* Ought to be enough .. */
 
tools/testing/selftests/powerpc/pmu/per_event_excludes.c +0 -1
index ad32a09a6540..5d00220b62ba 100644
@@ -14,7 +14,6 @@
 
 #include "event.h"
 #include "lib.h"
-#include "utils.h"
 
 /*
  * Test that per-event excludes work.
tools/testing/selftests/powerpc/pmu/sampling_tests/bhrb_filter_map_test.c +0 -1
index 3f43c315c666..6a639f255bfa 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 /*
  * A perf sampling test to check bhrb filter
tools/testing/selftests/powerpc/pmu/sampling_tests/bhrb_no_crash_wo_pmu_test.c +0 -1
index 4644c6782974..a6deba5dea00 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 /*
  * A perf sampling test for making sure
tools/testing/selftests/powerpc/pmu/sampling_tests/intr_regs_no_crash_wo_pmu_test.c +0 -1
index 839d2d225da0..a8c1197a577d 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 /*
  * A perf sampling test for making sure
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr0_cc56run_test.c +0 -1
index ae4172f83817..c560073f0f2c 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr0_exceptionbits_test.c +0 -1
index 982aa56d2171..f10e5de08302 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr0_fc56_pmc1ce_test.c +0 -1
index 1c1813c182c0..02d32a5d81ef 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr0_fc56_pmc56_test.c +0 -1
index 332d24b5ab9c..918f72c90e20 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr0_pmccext_test.c +0 -1
index dfd186cd8eec..26c5e3219d8b 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr0_pmcjce_test.c +0 -1
index fdd8ed9bf725..60584f64ed02 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr1_comb_test.c +0 -1
index 5aea6499ee9a..0759a4efc050 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 /* All successful D-side store dispatches for this thread that were L2 Miss */
 #define EventCode 0x46880
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr1_sel_unit_cache_test.c +0 -1
index f0c003282630..b1b34254018c 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 #define MALLOC_SIZE     (0x10000 * 10)  /* Ought to be enough .. */
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr2_fcs_fch_test.c +0 -1
index 4e242fd61b25..ac3ee2b236c2 100644
@@ -10,7 +10,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr2_l2l3_test.c +0 -1
index ceca597016b2..dd4e99dcb6b7 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 /* All successful D-side store dispatches for this thread */
 #define EventCode 0x010000046080
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcr3_src_test.c +0 -1
index e154e2a4cc3a..b8792ee1004b 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop_with_ll_sc(u64 loops, u64 *ll_sc_target);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_bhrb_any_test.c +0 -1
index 14854694af62..e2d1c98602a3 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_bhrb_cond_test.c +0 -1
index 3e08176eb7f8..f502d52c0f5a 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_bhrb_disable_no_branch_test.c +0 -1
index 488c865387e4..eae8634736c0 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_bhrb_disable_test.c +0 -1
index 186a853c0f62..73d66306c010 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void thirty_two_instruction_loop(int loops);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_bhrb_ind_call_test.c +0 -1
index f0706730c099..c5905303e657 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 extern void indirect_branch_loop(void);
 
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_thresh_cmp_test.c +0 -1
index 904362f172c9..ab2dc52766f6 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 /*
  * Primary PMU event used here is PM_MRK_INST_CMPL (0x401e0)
tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_thresh_marked_sample_test.c +0 -1
index 75527876ad3c..6f47e2211163 100644
@@ -8,7 +8,6 @@
 
 #include "../event.h"
 #include "misc.h"
-#include "utils.h"
 
 /*
  * Primary PMU event used here is PM_MRK_INST_CMPL (0x401e0)
Signature · 1 line
2.39.1
#2 lore raw

Re: [PATCH 2/2] selftests/powerpc/pmu: fix including of utils.h when event.h is included

Quoted 6 lines · Kajol Jain

From: Madhavan Srinivasan <[email protected]>

event.h header already includes utlis.h. Avoid including the same explicitly in the code when event.h included.

As I understand, transitive includes should not be depended upon. If you use a thing, and the thing is declared in a header, you should include _that_ header. Anything else is a recipe for weird include dependencies, ordering of the includes, etc.

These files all use FAIL_IF, etc., which are declared in utils.h. So utils.h is a legitimate include. The fact that events.h also includes it (for u64) is a coincidence. If the u64 type def gets moved to, e.g., types.h, and utils.h is removed from events.h, suddenly all these files stop compiling.

#3 lore raw

Re: [PATCH 2/2] selftests/powerpc/pmu: fix including of utils.h when event.h is included

Quoted 12 lines · Benjamin Gray
Quoted 6 lines · Kajol Jain

From: Madhavan Srinivasan <[email protected]>

event.h header already includes utlis.h. Avoid including the same explicitly in the code when event.h included.

As I understand, transitive includes should not be depended upon. If you use a thing, and the thing is declared in a header, you should include _that_ header. Anything else is a recipe for weird include dependencies, ordering of the includes, etc.

Quoted 5 lines

These files all use FAIL_IF, etc., which are declared in utils.h. So utils.h is a legitimate include. The fact that events.h also includes it (for u64) is a coincidence. If the u64 type def gets moved to, e.g., types.h, and utils.h is removed from events.h, suddenly all these files stop compiling.

thanks for the review. IIUC utils.h also carries the some test harness func declarations, also some of these tests does not use type defs anyway. I should have had a better commit message, my bad. But i will try out the suggested case.

Maddy

#4 lore raw

Re: [PATCH 2/2] selftests/powerpc/pmu: fix including of utils.h when event.h is included

Quoted 14 lines · Madhavan Srinivasan
Quoted 12 lines · Benjamin Gray
Quoted 6 lines · Kajol Jain

From: Madhavan Srinivasan <[email protected]>

event.h header already includes utlis.h. Avoid including the same explicitly in the code when event.h included.

As I understand, transitive includes should not be depended upon. If you use a thing, and the thing is declared in a header, you should include _that_ header. Anything else is a recipe for weird include dependencies, ordering of the includes, etc.

Quoted 7 lines
Quoted 5 lines

These files all use FAIL_IF, etc., which are declared in utils.h. So utils.h is a legitimate include. The fact that events.h also includes it (for u64) is a coincidence. If the u64 type def gets moved to, e.g., types.h, and utils.h is removed from events.h, suddenly all these files stop compiling.

thanks for the review. IIUC utils.h also carries the some test harness func declarations, also some of these tests does not use type defs anyway. I should have had a better commit message, my bad. But i will try out the suggested case.

yeah, "utils.h" included in the testcase files are for the tast_harness declarations. So we could get typedef moved from utils.h. Good catch. Thanks.
Kajol, kindly drop this patch.

Maddy

Quoted 2 lines

Maddy

#5 lore raw

Re: (subset) [PATCH 1/2] selftests/powerpc/pmu: Fix sample field check in the mmcra_thresh_marked_sample_test

In reply to Kajol Jain
Quoted 8 lines · Kajol Jain

The testcase verifies the setting of different fields in Monitor Mode Control Register A (MMCRA). In the current code, EV_CODE_EXTRACT macro is used to extract the "sample" field, which then needs to be further processed to fetch rand_samp_elig and rand_samp_mode bits. But the current code is not passing valid sample field to EV_CODE_EXTRACT macro. Patch addresses this by fixing the input for EV_CODE_EXTRACT.

[...]

Patch 1 applied to powerpc/next.

[1/2] selftests/powerpc/pmu: Fix sample field check in the mmcra_thresh_marked_sample_test

      https://git.kernel.org/powerpc/c/8a32341cf04ba05974931b4664683c2c9fb84e56

cheers