forked from CyanogenDefy/android_external_bootmenu
-
Notifications
You must be signed in to change notification settings - Fork 3
/
overclock.c
578 lines (469 loc) · 18.4 KB
/
overclock.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
/*
* Copyright (C) 2007-2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
#include "overclock.h"
#include "extendedcommands.h"
#include "minui/minui.h"
#include "bootmenu_ui.h"
#undef USE_4_CLOCK_LEVELS
struct overclock_config
{
const char *name;
int value;
};
struct overclock_config overclock[] = {
{ "enable", 0 },
{ "load_all", 0 },
{ "scaling", 2 },
{ "clk1", 300 },
{ "clk2", 600 },
{ "clk3", 1000 },
{ "clk4", 1100 },
{ "vsel1", 33 },
{ "vsel2", 48 },
{ "vsel3", 58 },
{ "vsel4", 62 },
{ "con_up_threshold", 80 },
{ "con_down_threshold", 20 },
{ "con_freq_step", 5 },
{ "con_sampling_rate", 160000 },
{ "int_min_sample_rate", 50000 },
{ "ond_up_threshold", 86 },
{ "ond_sampling_rate", 50000 },
{ "smt_min_cpu_load", 20 },
{ "smt_max_cpu_load", 80 },
{ "smt_awake_min_freq", 200000 },
{ "smt_sleep_max_freq", 200000 },
{ "smt_up_min_freq", 1000000 },
{ "smt_wakeup_freq", 1000000 },
{ "smt_ramp_up_step", 200000 },
{ NULL, 0 },
};
int
get_overclock_value(char* name) {
struct overclock_config *config;
for (config = overclock; config->name != NULL; ++config) {
if (!strcmp(config->name, name)) {
return config->value;
}
}
return -1;
}
int
set_overclock_value(char* name, int value) {
struct overclock_config *config;
for (config = overclock; config->name != NULL; ++config) {
if (!strcmp(config->name, name)) {
config->value = value;
return config->value;
}
}
return -1;
}
int
get_overclock_config(void) {
FILE *fp;
char name[255];
struct overclock_config *config;
if ((fp = fopen(FILE_OVERCLOCK_CONF, "r")) == NULL) {
return 1;
}
while((fscanf(fp, "%s", name)) != EOF) {
for (config = overclock; config->name != NULL; ++config) {
if (!strcmp(config->name, name)) {
fscanf(fp, "%d", &config->value);
}
}
}
fclose(fp);
return 0;
}
int
set_overclock_config(void) {
FILE *fp;
struct overclock_config *config;
if ((fp = fopen(FILE_OVERCLOCK_CONF, "w")) == NULL) {
return 1;
}
for (config = overclock; config->name != NULL; ++config) {
fprintf(fp, "%s", config->name);
fprintf(fp, " %d\n", config->value);
}
fclose(fp);
return 0;
}
int
menu_overclock_status(int intl_value) {
#define OVERCLOCK_STATUS_DISABLE 0
#define OVERCLOCK_STATUS_ENABLE 1
static char** title_headers = NULL;
if (title_headers == NULL) {
char* headers[] = { " # --> Set Enable/Disable -->",
"",
NULL };
title_headers = prepend_title((const char**)headers);
}
char* items[2][2] = {
{ " *[Disable]", " [Disable]" },
{ " *[Enable]", " [Enable]" },
};
int mode = intl_value;
for (;;) {
char* options[4];
int i;
for (i = 0; i < 2; ++i) {
if (mode == i)
options[i] = items[i][0];
else
options[i] = items[i][1];
}
options[2] = " --Go Back.";
options[3] = NULL;
int chosen_item = get_menu_selection(title_headers, options, 1, mode);
switch (chosen_item) {
case OVERCLOCK_STATUS_ENABLE:
mode = 1;
break;
case OVERCLOCK_STATUS_DISABLE:
mode = 0;
break;
default:
return mode;
}
}
return mode;
}
#if STOCK_VERSION
# define MENU_SYSTEM " System -->"
# define MENU_OVERCLOCK " Overclock -->"
#else
# define MENU_SYSTEM ""
# define MENU_OVERCLOCK " CPU settings -->"
#endif
int
menu_overclock_scaling(void) {
#define OVERCLOCK_SCALING_Conservative 0
#define OVERCLOCK_SCALING_Interactive 1
#define OVERCLOCK_SCALING_Ondemand 2
#define OVERCLOCK_SCALING_Performance 3
#define OVERCLOCK_SCALING_Powersave 4
#define OVERCLOCK_SCALING_Smartass 5
#define OVERCLOCK_SCALING_Userspace 6
static char** title_headers = NULL;
if (title_headers == NULL) {
char* headers[] = {
" #" MENU_SYSTEM MENU_OVERCLOCK " Scaling -->",
"",
NULL
};
title_headers = prepend_title((const char**)headers);
}
char* items[7][2] = {
{ " *[Conservative]", " [Conservative]" },
{ " *[Interactive]", " [Interactive]" },
{ " *[Ondemand]", " [Ondemand]" },
{ " *[Performance]", " [Performance]" },
{ " *[Powersave]", " [Powersave]" },
{ " *[Smartass]", " [Smartass]" },
{ " *[Userspace]", " [Userspace]" },
};
for (;;) {
char* options[9];
int i;
int mode = get_overclock_value("scaling");
for (i = 0; i < 7; ++i) {
if (mode == i)
options[i] = items[i][0];
else
options[i] = items[i][1];
}
options[7] = " --Go Back.";
options[8] = NULL;
int chosen_item = get_menu_selection(title_headers, options, 1, mode);
switch (chosen_item) {
case OVERCLOCK_SCALING_Conservative:
set_overclock_value("scaling", 0);
ui_print("Set Conservative.\n");
break;
case OVERCLOCK_SCALING_Interactive:
set_overclock_value("scaling", 1);
ui_print("Set Interactive.\n");
break;
case OVERCLOCK_SCALING_Ondemand:
set_overclock_value("scaling", 2);
ui_print("Set Ondemand.\n");
break;
case OVERCLOCK_SCALING_Performance:
set_overclock_value("scaling", 3);
ui_print("Set Performance.\n");
break;
case OVERCLOCK_SCALING_Powersave:
set_overclock_value("scaling", 4);
ui_print("Set Powersave.\n");
break;
case OVERCLOCK_SCALING_Smartass:
set_overclock_value("scaling", 5);
ui_print("Set Smartass.\n");
break;
case OVERCLOCK_SCALING_Userspace:
set_overclock_value("scaling", 6);
ui_print("Set Userspace.\n");
break;
default:
return 0;
}
}
return 0;
}
int
menu_set_value(char* name, int intl_value, int min_value, int max_value, int step) {
#define SETVALUE_TITLE 0
#define SETVALUE_SEP 1
#define SETVALUE_ADD 2
#define SETVALUE_SUB 3
#define SETVALUE_BACK 4
static char** title_headers = NULL;
int select = 0;
if (title_headers == NULL) {
char* headers[] = { " # --> Set Value -->",
"",
NULL };
title_headers = prepend_title((const char**)headers);
}
char* items[6];
items[0] = (char*)malloc(sizeof(char)*64);
items[1] = " ----------------------";
items[2] = (char*)malloc(sizeof(char)*64);
items[3] = (char*)malloc(sizeof(char)*64);
items[4] = " --Go Back";
items[5] = NULL;
int value = intl_value;
for (;;) {
if (value < min_value) value = min_value;
if (value > max_value) value = max_value;
sprintf(items[0], " %s: [%d]", name, value);
sprintf(items[2], " [+%d %s]", step, name);
sprintf(items[3], " [-%d %s]", step, name);
int chosen_item = get_menu_selection(title_headers, items, 1, select);
switch (chosen_item) {
case SETVALUE_ADD:
value += step; break;
case SETVALUE_SUB:
value -= step; break;
case SETVALUE_BACK:
free(items[0]); free(items[2]); free(items[3]);
return value;
default:
break;
}
select = chosen_item;
}
free(items[0]); free(items[2]); free(items[3]);
return value;
}
int
show_menu_overclock(void) {
#define OVERCLOCK_STATUS 0
#define OVERCLOCK_LOAD_ALL 1
#define OVERCLOCK_SCALING 2
#define OVERCLOCK_CLOCK1 3
#define OVERCLOCK_CLOCK2 4
#define OVERCLOCK_CLOCK3 5
#define OVERCLOCK_CLOCK4 6
#define OVERCLOCK_VSEL1 7
#define OVERCLOCK_VSEL2 8
#define OVERCLOCK_VSEL3 9
#define OVERCLOCK_VSEL4 10
#define OVERCLOCK_CON_UP_THRESHOLD 11
#define OVERCLOCK_CON_DOWN_THRESHOLD 12
#define OVERCLOCK_CON_FREQ_STEP 13
#define OVERCLOCK_CON_SAMPLING_RATE 14
#define OVERCLOCK_INT_MIN_SAMPLE_RATE 15
#define OVERCLOCK_OND_UP_THRESHOLD 16
#define OVERCLOCK_OND_SAMPLING_RATE 17
#define OVERCLOCK_smt_min_cpu_load 18
#define OVERCLOCK_smt_max_cpu_load 19
#define OVERCLOCK_smt_awake_min_freq 20
#define OVERCLOCK_smt_sleep_max_freq 21
#define OVERCLOCK_smt_up_min_freq 22
#define OVERCLOCK_smt_wakeup_freq 23
#define OVERCLOCK_smt_ramp_up_step 24
#define OVERCLOCK_DEFAULT 25
#define OVERCLOCK_SAVE 26
#define OVERCLOCK_GOBACK 27
static char** title_headers = NULL;
int select = 0;
if (title_headers == NULL) {
char* headers[] = { " #" MENU_SYSTEM MENU_OVERCLOCK,
"",
NULL };
title_headers = prepend_title((const char**)headers);
}
get_overclock_config();
char* items[29];
#define OC_MALLOC_FIRST 3
items[3] = (char*)malloc(sizeof(char)*64);
items[4] = (char*)malloc(sizeof(char)*64);
items[5] = (char*)malloc(sizeof(char)*64);
items[6] = (char*)malloc(sizeof(char)*64);
items[7] = (char*)malloc(sizeof(char)*64);
items[8] = (char*)malloc(sizeof(char)*64);
items[9] = (char*)malloc(sizeof(char)*64);
items[10] = (char*)malloc(sizeof(char)*64);
items[11] = (char*)malloc(sizeof(char)*64);
items[12] = (char*)malloc(sizeof(char)*64);
items[13] = (char*)malloc(sizeof(char)*64);
items[14] = (char*)malloc(sizeof(char)*64);
items[15] = (char*)malloc(sizeof(char)*64);
items[16] = (char*)malloc(sizeof(char)*64);
items[17] = (char*)malloc(sizeof(char)*64);
items[18] = (char*)malloc(sizeof(char)*64);
items[19] = (char*)malloc(sizeof(char)*64);
items[20] = (char*)malloc(sizeof(char)*64);
items[21] = (char*)malloc(sizeof(char)*64);
items[22] = (char*)malloc(sizeof(char)*64);
items[23] = (char*)malloc(sizeof(char)*64);
items[24] = (char*)malloc(sizeof(char)*64);
#define OC_MALLOC_LAST 24
items[25] = " [Set defaults(*req reboot/don't save!!)]";
items[26] = " [Save]";
items[27] = " --Go Back";
items[28] = NULL;
for (;;) {
switch (get_overclock_value("enable")) {
case 0: items[0] = " +Status: [Disable] -->"; break;
case 1: items[0] = " +Status: [Enable] -->"; break;
default: items[0] = " +Status: [Unknown] -->"; break;
}
switch (get_overclock_value("load_all")) {
case 0: items[1] = " +Load all modules: [Disable] -->"; break;
case 1: items[1] = " +Load all modules: [Enable] -->"; break;
default: items[1] = " +Load all modules: [Unknown] -->"; break;
}
switch (get_overclock_value("scaling")) {
case 0: items[2] = " +Scaling: [Conservative] -->"; break;
case 1: items[2] = " +Scaling: [Interactive] -->"; break;
case 2: items[2] = " +Scaling: [Ondemand] -->"; break;
case 3: items[2] = " +Scaling: [Performance] -->"; break;
case 4: items[2] = " +Scaling: [Powersave] -->"; break;
case 5: items[2] = " +Scaling: [Smartass] -->"; break;
case 6: items[2] = " +Scaling: [Userspace] -->"; break;
default: items[2] = " +Scaling: [Unknown] -->"; break;
}
sprintf(items[3], " +Clk1: [%d] -->", get_overclock_value("clk1"));
sprintf(items[4], " +Clk2: [%d] -->", get_overclock_value("clk2"));
sprintf(items[5], " +Clk3: [%d] -->", get_overclock_value("clk3"));
#ifdef USE_4_CLOCK_LEVELS
sprintf(items[6], " +Clk4: [%d] --> (*req 2.3.3 kernel)", get_overclock_value("clk4"));
sprintf(items[10], " +Vsel4: [%d] --> (*req 2.3.3 kernel)", get_overclock_value("vsel4"));
#else
strcpy(items[6], " ----------------------");
strcpy(items[10], " ----------------------");
#endif
sprintf(items[7], " +Vsel1: [%d] -->", get_overclock_value("vsel1"));
sprintf(items[8], " +Vsel2: [%d] -->", get_overclock_value("vsel2"));
sprintf(items[9], " +Vsel3: [%d] -->", get_overclock_value("vsel3"));
sprintf(items[11], " +con_up_threshold: [%d] -->", get_overclock_value("con_up_threshold"));
sprintf(items[12], " +con_down_threshold: [%d] -->", get_overclock_value("con_down_threshold"));
sprintf(items[13], " +con_freq_step: [%d] -->", get_overclock_value("con_freq_step"));
sprintf(items[14], " +con_sampling_rate: [%d] -->", get_overclock_value("con_sampling_rate"));
sprintf(items[15], " +int_min_sample_rate: [%d] -->", get_overclock_value("int_min_sample_rate"));
sprintf(items[16], " +ond_up_threshold: [%d] -->", get_overclock_value("ond_up_threshold"));
sprintf(items[17], " +ond_sampling_rate: [%d] -->", get_overclock_value("ond_sampling_rate"));
sprintf(items[18], " +smt_min_cpu_load: [%d] -->", get_overclock_value("smt_min_cpu_load"));
sprintf(items[19], " +smt_max_cpu_load: [%d] -->", get_overclock_value("smt_max_cpu_load"));
sprintf(items[20], " +smt_awake_min_freq: [%d] -->", get_overclock_value("smt_awake_min_freq"));
sprintf(items[21], " +smt_sleep_max_freq: [%d] -->", get_overclock_value("smt_sleep_max_freq"));
sprintf(items[22], " +smt_up_min_freq: [%d] -->", get_overclock_value("smt_up_min_freq"));
sprintf(items[23], " +smt_wakeup_freq: [%d] -->", get_overclock_value("smt_wakeup_freq"));
sprintf(items[24], " +smt_ramp_up_step: [%d] -->", get_overclock_value("smt_ramp_up_step"));
int chosen_item = get_menu_selection(title_headers, items, 1, select);
switch (chosen_item) {
case OVERCLOCK_STATUS:
set_overclock_value("enable", menu_overclock_status(get_overclock_value("enable"))); break;
case OVERCLOCK_LOAD_ALL:
set_overclock_value("load_all", menu_overclock_status(get_overclock_value("load_all"))); break;
case OVERCLOCK_SCALING:
menu_overclock_scaling(); break;
case OVERCLOCK_CLOCK1:
set_overclock_value("clk1", menu_set_value("Clk1", get_overclock_value("clk1"), 200, 2000, 10)); break;
case OVERCLOCK_CLOCK2:
set_overclock_value("clk2", menu_set_value("Clk2", get_overclock_value("clk2"), 200, 2000, 10)); break;
case OVERCLOCK_CLOCK3:
set_overclock_value("clk3", menu_set_value("Clk3", get_overclock_value("clk3"), 200, 2000, 10)); break;
#ifdef USE_4_CLOCK_LEVELS
case OVERCLOCK_CLOCK4:
set_overclock_value("clk4", menu_set_value("Clk4", get_overclock_value("clk4"), 200, 2000, 10)); break;
case OVERCLOCK_VSEL4:
set_overclock_value("vsel4", menu_set_value("Vsel4", get_overclock_value("vsel4"), 10, 100, 1)); break;
#endif
case OVERCLOCK_VSEL1:
set_overclock_value("vsel1", menu_set_value("Vsel1", get_overclock_value("vsel1"), 10, 100, 1)); break;
case OVERCLOCK_VSEL2:
set_overclock_value("vsel2", menu_set_value("Vsel2", get_overclock_value("vsel2"), 10, 100, 1)); break;
case OVERCLOCK_VSEL3:
set_overclock_value("vsel3", menu_set_value("Vsel3", get_overclock_value("vsel3"), 10, 100, 1)); break;
case OVERCLOCK_CON_UP_THRESHOLD:
set_overclock_value("con_up_threshold", menu_set_value("con_up_threshold", get_overclock_value("con_up_threshold"), 1, 100, 1)); break;
case OVERCLOCK_CON_DOWN_THRESHOLD:
set_overclock_value("con_down_threshold", menu_set_value("con_down_threshold", get_overclock_value("con_down_threshold"), 1, 100, 1)); break;
case OVERCLOCK_CON_FREQ_STEP:
set_overclock_value("con_freq_step", menu_set_value("con_freq_step", get_overclock_value("con_freq_step"), 1, 100, 1)); break;
case OVERCLOCK_CON_SAMPLING_RATE:
set_overclock_value("con_sampling_rate", menu_set_value("con_sampling_rate", get_overclock_value("con_sampling_rate"), 160000, 500000, 1000)); break;
case OVERCLOCK_INT_MIN_SAMPLE_RATE:
set_overclock_value("int_min_sample_rate", menu_set_value("int_min_sample_rate", get_overclock_value("int_min_sample_rate"), 5000, 500000, 1000)); break;
case OVERCLOCK_OND_UP_THRESHOLD:
set_overclock_value("ond_up_threshold", menu_set_value("ond_up_threshold", get_overclock_value("ond_up_threshold"), 1, 100, 1)); break;
case OVERCLOCK_OND_SAMPLING_RATE:
set_overclock_value("ond_sampling_rate", menu_set_value("ond_sampling_rate", get_overclock_value("ond_sampling_rate"), 10000, 100000, 1000)); break;
case OVERCLOCK_smt_min_cpu_load:
set_overclock_value("smt_min_cpu_load", menu_set_value("smt_min_cpu_load", get_overclock_value("smt_min_cpu_load"), 1, 100, 1)); break;
case OVERCLOCK_smt_max_cpu_load:
set_overclock_value("smt_max_cpu_load", menu_set_value("smt_max_cpu_load", get_overclock_value("smt_max_cpu_load"), 1, 100, 1)); break;
case OVERCLOCK_smt_awake_min_freq:
set_overclock_value("smt_awake_min_freq", menu_set_value("smt_awake_min_freq", get_overclock_value("smt_awake_min_freq"), 200000, 2000000, 10000)); break;
case OVERCLOCK_smt_sleep_max_freq:
set_overclock_value("smt_sleep_max_freq", menu_set_value("smt_sleep_max_freq", get_overclock_value("smt_sleep_max_freq"), 200000, 2000000, 10000)); break;
case OVERCLOCK_smt_up_min_freq:
set_overclock_value("smt_up_min_freq", menu_set_value("smt_up_min_freq", get_overclock_value("smt_up_min_freq"), 200000, 2000000, 10000)); break;
case OVERCLOCK_smt_wakeup_freq:
set_overclock_value("smt_wakeup_freq", menu_set_value("smt_wakeup_freq", get_overclock_value("smt_wakeup_freq"), 200000, 2000000, 10000)); break;
case OVERCLOCK_smt_ramp_up_step:
set_overclock_value("smt_ramp_up_step", menu_set_value("smt_ramp_up_step", get_overclock_value("smt_ramp_up_step"), 100000, 500000, 10000)); break;
case OVERCLOCK_SAVE:
ui_print("Saving.... ");
set_overclock_config();
ui_print("Done.\n");
break;
case OVERCLOCK_DEFAULT:
ui_print("Set defaults...");
remove(FILE_OVERCLOCK_CONF);
ui_print("Done. Please reboot.\n");
break;
default:
return 0;
}
select = chosen_item;
}
//release mallocs
for (select=OC_MALLOC_FIRST; select<=OC_MALLOC_LAST; select++) {
free(items[select]);
}
return 0;
}