Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int read_command(char command[]) {
- int current_data = 0;
- FILE *fp;
- fp = popen(command, "r");
- if (fp == NULL) {
- printf("Comando não executado\n");
- exit(1);
- } else {
- fscanf(fp, "%d", ¤t_data);
- }
- fclose(fp);
- return current_data;
- }
- short int cpu_cores () {
- short int cores = 0;
- cores = read_command("nproc");
- return cores;
- }
- int check_max_freq () {
- return read_command("cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq")/1000;
- }
- int set_performance (int freq, short int cores) {
- char command[50];
- for (short int i=0; i<cores; i++) {
- sprintf(command, "cpufreq-set -d %d -c %d -g performance", freq, i);
- system(command);
- }
- }
- int main (void) {
- int maxFrequency = 0;
- short int cpuCores = 0;
- cpuCores = cpu_cores();
- maxFrequency = check_max_freq(cpuCores);
- set_performance(maxFrequency, cpuCores);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement