forked from kliu20/jRAPL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dvfs.c
112 lines (97 loc) · 2.82 KB
/
dvfs.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int check_write_gov(int cores, char govFile[cores][60], const char *target) {
int i;
int rc;
FILE *f[cores];
size_t data_length, data_written;
char string[cores][25];
for (i = 0; i < cores; i++) {
f[i] = fopen(govFile[i], "r");
if (f[i] == NULL) {
//LOGI("Failed to open %s: %s", filename, strerror(errno));
printf("Failed to open %s", govFile[i]);
return 1;
}
fscanf(f[i], "%s", string[i]);
rc = fclose(f[i]);
if (rc != 0) {
//LOGI("Failed to close %s: %s", filename, strerror(rc));
printf("Failed to close %s", govFile[i]);
return 1;
}
if (strcmp(string[i], target) != 0) {
//Write govenor
f[i] = fopen(govFile[i], "w");
if (f[i] == NULL) {
//LOGI("Failed to open %s: %s", govFile, strerror(errno));
printf("Failed to open %s", govFile[i]);
return 1;
}
data_length = strlen(target);
data_written = fwrite(target, 1, data_length, f[i]);
if (data_length != data_written) {
//LOGI("Failed to write to %s: %s", filename, strerror(errno));
printf("Failed to write %s", target);
return 1;
}
rc = fclose(f[i]);
if (rc != 0) {
//LOGI("Failed to close %s: %s", filename, strerror(rc));
printf("Failed to close %s", govFile[i]);
return 1;
}
}
}
return 0;
}
write_freq_all_cores(int cores, char filename[cores][60], const char *cur_freq, const char *scal_freq, int freq) {
int i;
FILE *f[cores];
int rc;
size_t data_length, data_written;
int cpu_freq[cores];
int scal_cpufreq[cores];
for(i = 0; i < cores; i++) {
f[i] = fopen(filename[i], "w");
if (f[i] == NULL) {
//LOGI("Failed to open %s: %s", filename, strerror(errno));
printf("Failed to open %s", filename[i]);
return 1;
}
// data_length = strlen(freq);
// data_written = fwrite(freq, 1, data_length, f); //For binary code
data_length = get_pos_intnum(freq);
data_written = fprintf(f[i], "%d", freq); //For integer
if (data_length != data_written) {
//LOGI("Failed to write to %s: %s", filename, strerror(errno));
printf("Failed to write %s", filename[i]);
return 1;
}
rc = fclose(f[i]);
if (rc != 0) {
//LOGI("Failed to close %s: %s", filename, strerror(rc));
printf("Failed to close %s", filename[i]);
return 1;
}
f[i] = fopen(cur_freq, "r");
if (f[i] == NULL) {
//LOGI("Failed to open %s: %s", filename, strerror(errno));
printf("Failed to open %s", cur_freq);
return 1;
}
fscanf(f[i], "%d", &cpu_freq[i]);
rc= fclose(f[i]);
f[i] = fopen(scal_freq, "r");
if (f[i] == NULL) {
//LOGI("Failed to open %s: %s", filename, strerror(errno));
printf("Failed to open %s", scal_freq);
return 1;
}
fscanf(f[i], "%d", &scal_cpufreq[i]);
rc= fclose(f[i]);
printf("cpu_freq: %d\n", cpu_freq[i]);
printf("scal_cpufreq: %d\n", scal_cpufreq[i]);
}
}