Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc/pmu: Add selftest for group constraint check for MMCRA thresh_ctl field

Thresh control bits in the event code is used to program thresh_ctl
field in Monitor Mode Control Register A (MMCRA: 48-55). When scheduling
events as a group, all events in that group should match value in these
bits. Otherwise event open for the sibling events will fail.

Testcase uses event code PM_MRK_INST_CMPL (0x401e0) as leader and
another event PM_THRESH_MET (101ec) as sibling event, and checks if
group constraint checks for thresh_ctl field added correctly via perf
interface.

Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220610134113.62991-34-atrajeev@linux.vnet.ibm.com

authored by

Kajol Jain and committed by
Michael Ellerman
c178606a 142c9bd1

+65 -1
+1 -1
tools/testing/selftests/powerpc/pmu/event_code_tests/Makefile
··· 6 6 group_constraint_mmcra_sample_test invalid_event_code_test reserved_bits_mmcra_thresh_ctl_test \ 7 7 blacklisted_events_test event_alternatives_tests_p9 event_alternatives_tests_p10 generic_events_valid_test \ 8 8 group_constraint_l2l3_sel_test group_constraint_cache_test group_constraint_thresh_cmp_test \ 9 - group_constraint_unit_test 9 + group_constraint_unit_test group_constraint_thresh_ctl_test 10 10 11 11 top_srcdir = ../../../../../.. 12 12 include ../../../lib.mk
+64
tools/testing/selftests/powerpc/pmu/event_code_tests/group_constraint_thresh_ctl_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright 2022, Kajol Jain, IBM Corp. 4 + */ 5 + 6 + #include <stdio.h> 7 + #include <stdlib.h> 8 + 9 + #include "../event.h" 10 + #include "utils.h" 11 + #include "../sampling_tests/misc.h" 12 + 13 + /* 14 + * Primary PMU events used here are PM_MRK_INST_CMPL (0x401e0) and 15 + * PM_THRESH_MET (0x101ec). 16 + * Threshold event selection used is issue to complete and issue to 17 + * finished for cycles 18 + * Sampling criteria is Load or Store only sampling 19 + */ 20 + #define EventCode_1 0x35340401e0 21 + #define EventCode_2 0x34340101ec 22 + #define EventCode_3 0x35340101ec 23 + 24 + /* 25 + * Testcase for group constraint check of thresh_ctl bits which is 26 + * used to program thresh compare field in Monitor Mode Control Register A 27 + * (MMCR0: 48-55). 28 + * All events in the group should match thresh ctl bits otherwise 29 + * event_open for the group will fail. 30 + */ 31 + static int group_constraint_thresh_ctl(void) 32 + { 33 + struct event event, leader; 34 + 35 + /* Check for platform support for the test */ 36 + SKIP_IF(platform_check_for_tests()); 37 + 38 + /* Init the events for the group contraint thresh control test */ 39 + event_init(&leader, EventCode_1); 40 + FAIL_IF(event_open(&leader)); 41 + 42 + event_init(&event, EventCode_2); 43 + 44 + /* Expected to fail as sibling and leader event request different thresh_ctl bits */ 45 + FAIL_IF(!event_open_with_group(&event, leader.fd)); 46 + 47 + event_close(&event); 48 + 49 + /* Init the event for the group contraint thresh control test */ 50 + event_init(&event, EventCode_3); 51 + 52 + /* Expected to succeed as sibling and leader event request same thresh_ctl bits */ 53 + FAIL_IF(event_open_with_group(&event, leader.fd)); 54 + 55 + event_close(&leader); 56 + event_close(&event); 57 + 58 + return 0; 59 + } 60 + 61 + int main(void) 62 + { 63 + return test_harness(group_constraint_thresh_ctl, "group_constraint_thresh_ctl"); 64 + }