cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

mmcr1_comb_test.c (1491B)


      1// SPDX-License-Identifier: GPL-2.0-only
      2/*
      3 * Copyright 2022, Athira Rajeev, IBM Corp.
      4 */
      5
      6#include <stdio.h>
      7#include <stdlib.h>
      8
      9#include "../event.h"
     10#include "misc.h"
     11#include "utils.h"
     12
     13/* All successful D-side store dispatches for this thread that were L2 Miss */
     14#define EventCode 0x46880
     15
     16extern void thirty_two_instruction_loop_with_ll_sc(u64 loops, u64 *ll_sc_target);
     17
     18/*
     19 * A perf sampling test for mmcr1
     20 * fields : comb.
     21 */
     22static int mmcr1_comb(void)
     23{
     24	struct event event;
     25	u64 *intr_regs;
     26	u64 dummy;
     27
     28	/* Check for platform support for the test */
     29	SKIP_IF(check_pvr_for_sampling_tests());
     30
     31	/* Init the event for the sampling test */
     32	event_init_sampling(&event, EventCode);
     33	event.attr.sample_regs_intr = platform_extended_mask;
     34	FAIL_IF(event_open(&event));
     35	event.mmap_buffer = event_sample_buf_mmap(event.fd, 1);
     36
     37	FAIL_IF(event_enable(&event));
     38
     39	/* workload to make the event overflow */
     40	thirty_two_instruction_loop_with_ll_sc(10000000, &dummy);
     41
     42	FAIL_IF(event_disable(&event));
     43
     44	/* Check for sample count */
     45	FAIL_IF(!collect_samples(event.mmap_buffer));
     46
     47	intr_regs = get_intr_regs(&event, event.mmap_buffer);
     48
     49	/* Check for intr_regs */
     50	FAIL_IF(!intr_regs);
     51
     52	/*
     53	 * Verify that comb field match with
     54	 * corresponding event code fields
     55	 */
     56	FAIL_IF(EV_CODE_EXTRACT(event.attr.config, comb) !=
     57		get_mmcr1_comb(get_reg_value(intr_regs, "MMCR1"), 4));
     58
     59	event_close(&event);
     60	return 0;
     61}
     62
     63int main(void)
     64{
     65	return test_harness(mmcr1_comb, "mmcr1_comb");
     66}