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

mem.c (1326B)


      1// SPDX-License-Identifier: GPL-2.0
      2#include "util/map_symbol.h"
      3#include "util/mem-events.h"
      4#include "util/symbol.h"
      5#include "linux/perf_event.h"
      6#include "util/debug.h"
      7#include "tests.h"
      8#include <string.h>
      9
     10static int check(union perf_mem_data_src data_src,
     11		  const char *string)
     12{
     13	char out[100];
     14	char failure[100];
     15	struct mem_info mi = { .data_src = data_src };
     16
     17	int n;
     18
     19	n = perf_mem__snp_scnprintf(out, sizeof out, &mi);
     20	n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, &mi);
     21	scnprintf(failure, sizeof failure, "unexpected %s", out);
     22	TEST_ASSERT_VAL(failure, !strcmp(string, out));
     23	return 0;
     24}
     25
     26static int test__mem(struct test_suite *text __maybe_unused, int subtest __maybe_unused)
     27{
     28	int ret = 0;
     29	union perf_mem_data_src src;
     30
     31	memset(&src, 0, sizeof(src));
     32
     33	src.mem_lvl = PERF_MEM_LVL_HIT;
     34	src.mem_lvl_num = 4;
     35
     36	ret |= check(src, "N/AL4 hit");
     37
     38	src.mem_remote = 1;
     39
     40	ret |= check(src, "N/ARemote L4 hit");
     41
     42	src.mem_lvl = PERF_MEM_LVL_MISS;
     43	src.mem_lvl_num = PERF_MEM_LVLNUM_PMEM;
     44	src.mem_remote = 0;
     45
     46	ret |= check(src, "N/APMEM miss");
     47
     48	src.mem_remote = 1;
     49
     50	ret |= check(src, "N/ARemote PMEM miss");
     51
     52	src.mem_snoopx = PERF_MEM_SNOOPX_FWD;
     53	src.mem_lvl_num = PERF_MEM_LVLNUM_RAM;
     54
     55	ret |= check(src , "FwdRemote RAM miss");
     56
     57	return ret;
     58}
     59
     60DEFINE_SUITE("Test data source output", mem);