This repository has been archived by the owner on Jul 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeassure_recv.c
97 lines (79 loc) · 2.04 KB
/
meassure_recv.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "lib.h"
size_t* payload;
size_t method, length;
size_t (*meassure)(void (* addr)(void));
size_t frequency, interval;
void* receiver(void* _);
int main(int argc, char* argv[])
{
if(argc == 4)
{
if(strcmp(argv[1], "-ff")==0)
{
method = FLUSH_FLUSH;
meassure = meassure_ff;
}
else
{
if(strcmp(argv[1], "-fr")==0)
{
method = FLUSH_RELOAD;
meassure = meassure_fr;
}
else
{
goto invalid;
}
}
frequency = strtoll(argv[2], NULL, 10);
if(frequency==0) goto invalid;
// interval in nsecs
interval = 1000000000/frequency;
length = strtoll(argv[3], NULL, 10);
if(length==0) goto invalid;
}
else
{
invalid:
fprintf(stderr, "usage: ./meassure_recv [-ff/-fr] [FREQUENCY] [TESTPOINTS]\n");
exit(1);
}
payload = malloc(sizeof(size_t)*length);
if(!payload){fprintf(stderr, "could not allocate memory\n"); exit(2);}
printf("Receiving alternating \'1\' and \'0\'\n- Frequency in Hz: %zu\n"
"- Testdata Length: %lu\n"
"- Method: %s\n",
frequency, length, method == FLUSH_FLUSH ? "Flush+Flush" : "Flush+Reload");
pthread_t r;
pthread_create(&r, NULL, receiver, NULL);
pthread_join(r, NULL);
{
FILE* group_A = fopen("groupA.txt", "w");
for(int i = 0; i < length; i+=2)
{
fprintf(group_A, "%lu\n", payload[i]);
}
fclose(group_A);
FILE* group_B = fopen("groupB.txt", "w");
for(int i = 1; i < length; i+=2)
{
fprintf(group_B, "%lu\n", payload[i]);
}
fclose(group_B);
}
return 0;
}
void* receiver(void* _)
{
INIT_CLOCK
int i = 0;
while(1)
{
sched_yield();
size_t d = meassure(function + 64);
payload[i++] = d;
if(i == length)
return NULL;
WAIT_FOR_CLOCK
}
}