-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtlb-test.c
68 lines (61 loc) · 1.36 KB
/
tlb-test.c
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
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
volatile char *buffer, *pbuf;
int size = 40960, step = 4096, delay = 0, repeat = 1, remainder = 1;
int i, quiet = 0;
for(i = 1; i < argc; i ++){
switch(argv[i][0]) {
case 'T':
sscanf(&argv[i][1], "%d", &size);
break;
case 'P':
sscanf(&argv[i][1], "%d", &step);
break;
case 'D':
sscanf(&argv[i][1], "%d", &delay);
break;
case 'R':
sscanf(&argv[i][1], "%d", &repeat);
break;
case 'M':
sscanf(&argv[i][1], "%d", &remainder);
break;
case 'q':
quiet = 1;
break;
default:
printf("invalid parameters\n");
return -1;
}
}
if (!quiet)
printf("test with total %d step %d delay %d repeat %d, remainder %d\n", size, step, delay, repeat, remainder);
if (step > size) {
printf("error: step %d > size %d\n", step, size);
return -1;
}
buffer = malloc(size);
if (buffer == NULL) {
printf("error: can't alloc %d bytes\n", size);
return -1;
}
do {
if (!quiet) printf("round %d\n", repeat);
for(pbuf = buffer, i = 0; pbuf < buffer + size; pbuf += step) {
if (delay && i % remainder == 0) {
if (!quiet)
printf("%d addr %p\n", i, pbuf);
sleep(delay);
}
pbuf[0] = (char)i++;
}
} while (--repeat > 0);
if (!quiet) {
printf("%d finish, press any key to continue...", i);
getchar();
}
free((void*)buffer);
return 0;
}