maprobe.h 2.5 KB
Newer Older
1 2 3 4 5 6 7
// basic microarchtectural probe

#ifndef PROBE_H
#define PROBE_H

#include <klib.h>
#include <csr.h>
W
William Wang 已提交
8 9 10 11
#include "bitutils.h"

// config
// #define PERF_SIM // probe run in simulatior, diaable perf counters
12 13 14 15 16 17 18 19

// perf const
#define BYTE (1)
#define KB (1024*BYTE)
#define MB (1024*KB)
#define GB (1024*MB)

// platform dependent const
W
William Wang 已提交
20 21 22 23
#ifndef _PERF_TEST_ADDR_BASE
#define _PERF_TEST_ADDR_BASE 0x80400000
// #define _PERF_TEST_ADDR_BASE 0x2000400000
#endif
24
#define _PERF_CACHELINE_SIZE_BYTE (64 * BYTE)
25 26
#define _PERF_PAGE_SIZE_BYTE (4 * KB)
#define _PERF_L1_NOALIAS_SIZE_BYTE (16 * KB)
W
William Wang 已提交
27
#define _PERF_L1_SIZE_BYTE (64 * KB)
28 29 30
#define _PERF_L2_SIZE_BYTE (1 * MB)
#define _PERF_L3_SIZE_BYTE (6 * MB)
#define _PERF_MEM_SIZE_BYTE (1024 * MB)
W
William Wang 已提交
31
#define _PERF_L1_NUM_WAYS 4
32 33 34 35 36 37 38 39 40
#define _PERF_L1_NUM_SETS 256
#define _PERF_L2_NUM_SLICES 4
// #define _PERF_L2_NUM_SETS 512

#define _PERF_ADDR_STRIDE_L1_SAME_BANK _PERF_CACHELINE_SIZE_BYTE
#define _PERF_ADDR_STRIDE_L1_SAME_SET (_PERF_L1_NUM_SETS * _PERF_CACHELINE_SIZE_BYTE)
#define _PERF_ADDR_STRIDE_L2_SAME_SLICE (_PERF_L2_NUM_SLICES * _PERF_CACHELINE_SIZE_BYTE)
// #define _PERF_ADDR_STRIDE_L2_SAME_SET (_PERF_L2_NUM_SETS * _PERF_CACHELINE_SIZE_BYTE)
#define _PERF_ADDR_STRIDE_NEXT_PAGE (_PERF_PAGE_SIZE_BYTE)
41 42 43 44 45 46 47

// probe const
#define _PERF_BLACKHOLE _PERF_TEST_ADDR_BASE

struct perf
{
    // const to be calibrated at run time
W
William Wang 已提交
48
    uint64_t csr_read_cycle; // # of cycles to read mcycle
49 50 51 52 53
    uint64_t csr_read_ninst; // # of inst needed to read minstret

    // timer
    uint64_t cycle;
    uint64_t instrcnt;
W
William Wang 已提交
54 55 56
};
extern struct perf perf;

57 58
extern uint64_t _perf_g_total_samples;

W
William Wang 已提交
59 60 61 62 63 64 65 66
// common perf tools
extern void _perf_start_timer();
extern void _perf_end_timer();
extern void _perf_print_timer();
extern void _perf_calibrate();
extern void _perf_blackhole(uint64_t value);

// latency test
67 68
extern uint64_t setup_pointer_tracing_linklist(uint64_t base_addr, uint64_t end_addr, uint64_t step);
extern uint64_t read_pointer_tracing_linklist(uint64_t base_addr, uint64_t num_valid_node);
W
William Wang 已提交
69
extern void latency_test_warmup(uint64_t base_addr, uint64_t end_addr);
70 71 72 73 74 75 76
extern void test_pointer_tracing_latency(uint64_t size, int step, int iter, int to_csv);
extern void test_linear_access_latency(uint64_t size, uint64_t step, int iter, int to_csv);
extern void test_random_access_latency(uint64_t num_access, uint64_t test_range, uint64_t test_align, int pregen_addr, int iter, int to_csv);
extern void test_same_address_load_latency(int iter, int to_csv);

extern void legacy_test_mem_throughput(uint64_t iter);
extern void legacy_test_mem_throughput_same_set(uint64_t iter);
77

78
#endif