linux/tools/testing/selftests/powerpc/pmu/ebb/close_clears_pmcc_test.c
<<
>>
Prefs
   1/*
   2 * Copyright 2014, Michael Ellerman, IBM Corp.
   3 * Licensed under GPLv2.
   4 */
   5
   6#include <stdio.h>
   7#include <stdlib.h>
   8#include <setjmp.h>
   9#include <signal.h>
  10
  11#include "ebb.h"
  12
  13
  14/*
  15 * Test that closing the EBB event clears MMCR0_PMCC, preventing further access
  16 * by userspace to the PMU hardware.
  17 */
  18
  19int close_clears_pmcc(void)
  20{
  21        struct event event;
  22
  23        SKIP_IF(!ebb_is_supported());
  24
  25        event_init_named(&event, 0x1001e, "cycles");
  26        event_leader_ebb_init(&event);
  27
  28        FAIL_IF(event_open(&event));
  29
  30        ebb_enable_pmc_counting(1);
  31        setup_ebb_handler(standard_ebb_callee);
  32        ebb_global_enable();
  33        FAIL_IF(ebb_event_enable(&event));
  34
  35        mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
  36
  37        while (ebb_state.stats.ebb_count < 1)
  38                FAIL_IF(core_busy_loop());
  39
  40        ebb_global_disable();
  41        event_close(&event);
  42
  43        FAIL_IF(ebb_state.stats.ebb_count == 0);
  44
  45        /* The real test is here, do we take a SIGILL when writing PMU regs now
  46         * that we have closed the event. We expect that we will. */
  47
  48        FAIL_IF(catch_sigill(write_pmc1));
  49
  50        /* We should still be able to read EBB regs though */
  51        mfspr(SPRN_EBBHR);
  52        mfspr(SPRN_EBBRR);
  53        mfspr(SPRN_BESCR);
  54
  55        return 0;
  56}
  57
  58int main(void)
  59{
  60        return test_harness(close_clears_pmcc, "close_clears_pmcc");
  61}
  62