-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.c
More file actions
77 lines (66 loc) · 1.97 KB
/
test.c
File metadata and controls
77 lines (66 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/user.h>
#include <sys/ptrace.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <stdint.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <assert.h>
#include "harness.h"
uint8_t parse_hex_digit(char c) {
if (c >= 'a' && c <= 'f')
return c - 'a' + 0xa;
if (c >= 'A' && c <= 'F')
return c - 'A' + 0xa;
return c - '0';
}
uint8_t *hex2bin(char *hex) {
size_t len = strlen(hex);
assert(len % 2 == 0);
uint8_t *bin = (uint8_t *)malloc(len / 2);
size_t i;
for (i = 0; i < len/2; i++) {
uint8_t hi = parse_hex_digit(hex[i*2]);
uint8_t lo = parse_hex_digit(hex[i*2 + 1]);
bin[i] = hi * 16 + lo;
}
return bin;
}
int main(int argc, char **argv) {
char *code_hex = argv[1];
unsigned int unroll_factor = atoi(argv[2]);
size_t code_size = strlen(code_hex)/2;
char *code_to_test = hex2bin(code_hex);
// allocate 3 pages, the first one for testing
// the rest for writing down result
int shm_fd = create_shm_fd("shm-path");
// `measure` writes the result here
int l1_read_supported, l1_write_supported, icache_supported;
struct pmc_counters *counters = measure(
code_to_test, code_size, unroll_factor,
&l1_read_supported, &l1_write_supported, &icache_supported,
shm_fd);
if (!counters) {
fprintf(stderr, "failed to run test\n");
return 1;
}
// print the result, ignore the first set of counters, which is garbage
printf("Core_cyc\tL1_read_misses\tL1_write_misses\tiCache_misses\tContext_switches\n");
int i;
for (i = 1; i < HARNESS_ITERS; i++) {
printf("%ld\t%ld\t%ld\t%ld\t%ld\n",
counters[i].core_cyc,
l1_read_supported ? counters[i].l1_read_misses : -1,
l1_write_supported ? counters[i].l1_write_misses : -1,
icache_supported ? counters[i].icache_misses : -1,
counters[i].context_switches);
}
return 0;
}