~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/pmu/ebb/pmae_handling_test.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Copyright 2014, Michael Ellerman, IBM Corp.
  4  */
  5 
  6 #include <sched.h>
  7 #include <signal.h>
  8 #include <stdbool.h>
  9 #include <stdio.h>
 10 #include <stdlib.h>
 11 
 12 #include "ebb.h"
 13 
 14 
 15 /*
 16  * Test that the kernel properly handles PMAE across context switches.
 17  *
 18  * We test this by calling into the kernel inside our EBB handler, where PMAE
 19  * is clear. A cpu eater companion thread is running on the same CPU as us to
 20  * encourage the scheduler to switch us.
 21  *
 22  * The kernel must make sure that when it context switches us back in, it
 23  * honours the fact that we had PMAE clear.
 24  *
 25  * Observed to hit the failing case on the first EBB with a broken kernel.
 26  */
 27 
 28 static bool mmcr0_mismatch;
 29 static uint64_t before, after;
 30 
 31 static void syscall_ebb_callee(void)
 32 {
 33         uint64_t val;
 34 
 35         val = mfspr(SPRN_BESCR);
 36         if (!(val & BESCR_PMEO)) {
 37                 ebb_state.stats.spurious++;
 38                 goto out;
 39         }
 40 
 41         ebb_state.stats.ebb_count++;
 42         count_pmc(1, sample_period);
 43 
 44         before = mfspr(SPRN_MMCR0);
 45 
 46         /* Try and get ourselves scheduled, to force a PMU context switch */
 47         sched_yield();
 48 
 49         after = mfspr(SPRN_MMCR0);
 50         if (before != after)
 51                 mmcr0_mismatch = true;
 52 
 53 out:
 54         reset_ebb();
 55 }
 56 
 57 static int test_body(void)
 58 {
 59         struct event event;
 60 
 61         SKIP_IF(!ebb_is_supported());
 62 
 63         event_init_named(&event, 0x1001e, "cycles");
 64         event_leader_ebb_init(&event);
 65 
 66         event.attr.exclude_kernel = 1;
 67         event.attr.exclude_hv = 1;
 68         event.attr.exclude_idle = 1;
 69 
 70         FAIL_IF(event_open(&event));
 71 
 72         setup_ebb_handler(syscall_ebb_callee);
 73         ebb_global_enable();
 74 
 75         FAIL_IF(ebb_event_enable(&event));
 76 
 77         mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
 78 
 79         while (ebb_state.stats.ebb_count < 20 && !mmcr0_mismatch)
 80                 FAIL_IF(core_busy_loop());
 81 
 82         ebb_global_disable();
 83         ebb_freeze_pmcs();
 84 
 85         dump_ebb_state();
 86 
 87         if (mmcr0_mismatch)
 88                 printf("Saw MMCR0 before 0x%lx after 0x%lx\n", before, after);
 89 
 90         event_close(&event);
 91 
 92         FAIL_IF(ebb_state.stats.ebb_count == 0);
 93         FAIL_IF(mmcr0_mismatch);
 94 
 95         return 0;
 96 }
 97 
 98 int pmae_handling(void)
 99 {
100         return eat_cpu(test_body);
101 }
102 
103 int main(void)
104 {
105         return test_harness(pmae_handling, "pmae_handling");
106 }
107 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php