-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.h
More file actions
73 lines (63 loc) · 2.36 KB
/
parse.h
File metadata and controls
73 lines (63 loc) · 2.36 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
#include <assert.h>
#include <string.h>
///////////////////////////////////////////////////////////////////////////
// If return value is >0, CACTI failed on this cache configuration.
// Always check the return value!
///////////////////////////////////////////////////////////////////////////
int get_cacti_results(int SIZE, int BLOCKSIZE, int ASSOC, float *AccessTime, float *Energy, float *Area)
{
char command[128];
FILE *pipe;
char buffer[128];
char *substring;
float Height, Width;
int errflag = 3;
/////////////////////////////////////////////////////////
// 1. Generate the cacti command.
/////////////////////////////////////////////////////////
if (ASSOC == (SIZE/BLOCKSIZE))
sprintf(command, "./cacti %d %d FA 45nm 1 2>&1", SIZE, BLOCKSIZE); // fully-associative case
else
sprintf(command, "./cacti %d %d %d 45nm 1 2>&1", SIZE, BLOCKSIZE, ASSOC);
/////////////////////////////////////////////////////////
// 2. Execute cacti, and create a pipe between
// this process and the cacti process.
/////////////////////////////////////////////////////////
pipe = popen(command, "r");
assert(pipe);
/////////////////////////////////////////////////////////
// 3. Extract the key results from cacti.
//
// Format of key outputs from CACTI 6.0 (examples given):
//
// Access time (ns): 0.24435
// Total dynamic read energy per access (nJ):0.0064104
// Cache height x width (mm): 0.402309 x 0.218135
/////////////////////////////////////////////////////////
while (fgets(buffer, 128, pipe)) {
if ((substring = strstr(buffer, "Access time"))) {
assert(substring = strstr(buffer, ":"));
sscanf(substring, ": %f", AccessTime);
//printf("%s", buffer);
errflag--;
}
else if ((substring = strstr(buffer, "Total dynamic read energy per access"))) {
assert(substring = strstr(buffer, ":"));
sscanf(substring, ":%f", Energy);
//printf("%s", buffer);
errflag--;
}
else if ((substring = strstr(buffer, "Cache height x width"))) {
assert(substring = strstr(buffer, ":"));
sscanf(substring, ": %f x %f", &Height, &Width);
*Area = Height*Width;
//printf("%s", buffer);
errflag--;
}
}
/////////////////////////////////////////////////////////
// 4. Close the pipe.
/////////////////////////////////////////////////////////
pclose(pipe);
return(errflag);
}