Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpupowerutils: bench - ConfigStyle bugfixes

Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>

+75 -58
+2 -3
tools/power/cpupower/Makefile
··· 38 38 CPUFRQ_BENCH ?= true 39 39 40 40 # Prefix to the directories we're installing to 41 - DESTDIR ?= 41 + DESTDIR ?= 42 42 43 43 # --- CONFIGURATION END --- 44 44 ··· 277 277 rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo; \ 278 278 done; 279 279 280 - .PHONY: all utils libcpufreq update-po create-gmo install-lib install-tools install-man install-gmo install uninstall \ 281 - clean 280 + .PHONY: all utils libcpufreq update-po create-gmo install-lib install-tools install-man install-gmo install uninstall clean
+29 -19
tools/power/cpupower/bench/benchmark.c
··· 37 37 * compute how many rounds of calculation we should do 38 38 * to get the given load time 39 39 * 40 - * @param load aimed load time in �s 40 + * @param load aimed load time in µs 41 41 * 42 42 * @retval rounds of calculation 43 43 **/ ··· 61 61 timed = (unsigned int)(then - now); 62 62 63 63 /* approximation of the wanted load time by comparing with the 64 - * initial calculation time */ 65 - for (i= 0; i < 4; i++) 66 - { 64 + * initial calculation time */ 65 + for (i = 0; i < 4; i++) { 67 66 rounds = (unsigned int)(load * estimated / timed); 68 67 dprintf("calibrating with %u rounds\n", rounds); 69 68 now = get_time(); ··· 101 102 load_time = config->load; 102 103 103 104 /* For the progress bar */ 104 - for (_round=1; _round <= config->rounds; _round++) 105 + for (_round = 1; _round <= config->rounds; _round++) 105 106 total_time += _round * (config->sleep + config->load); 106 107 total_time *= 2; /* powersave and performance cycles */ 107 108 108 - for (_round=0; _round < config->rounds; _round++) { 109 + for (_round = 0; _round < config->rounds; _round++) { 109 110 performance_time = 0LL; 110 111 powersave_time = 0LL; 111 112 ··· 129 130 fprintf(config->output, "%u %li %li ", 130 131 _round, load_time, sleep_time); 131 132 132 - if (config->verbose) { 133 - printf("avarage: %lius, rps:%li\n", load_time / calculations, 1000000 * calculations / load_time); 134 - } 133 + if (config->verbose) 134 + printf("avarage: %lius, rps:%li\n", 135 + load_time / calculations, 136 + 1000000 * calculations / load_time); 135 137 136 138 /* do some sleep/load cycles with the performance governor */ 137 139 for (cycle = 0; cycle < config->cycles; cycle++) { ··· 142 142 then = get_time(); 143 143 performance_time += then - now - sleep_time; 144 144 if (config->verbose) 145 - printf("performance cycle took %lius, sleep: %lius, load: %lius, rounds: %u\n", 146 - (long)(then - now), sleep_time, load_time, calculations); 145 + printf("performance cycle took %lius, " 146 + "sleep: %lius, " 147 + "load: %lius, rounds: %u\n", 148 + (long)(then - now), sleep_time, 149 + load_time, calculations); 147 150 } 148 - fprintf(config->output, "%li ", performance_time / config->cycles); 151 + fprintf(config->output, "%li ", 152 + performance_time / config->cycles); 149 153 150 154 progress_time += sleep_time + load_time; 151 155 show_progress(total_time, progress_time); ··· 159 155 if (set_cpufreq_governor(config->governor, config->cpu) != 0) 160 156 return; 161 157 162 - /* again, do some sleep/load cycles with the powersave governor */ 158 + /* again, do some sleep/load cycles with the 159 + * powersave governor */ 163 160 for (cycle = 0; cycle < config->cycles; cycle++) { 164 161 now = get_time(); 165 162 usleep(sleep_time); ··· 168 163 then = get_time(); 169 164 powersave_time += then - now - sleep_time; 170 165 if (config->verbose) 171 - printf("powersave cycle took %lius, sleep: %lius, load: %lius, rounds: %u\n", 172 - (long)(then - now), sleep_time, load_time, calculations); 166 + printf("powersave cycle took %lius, " 167 + "sleep: %lius, " 168 + "load: %lius, rounds: %u\n", 169 + (long)(then - now), sleep_time, 170 + load_time, calculations); 173 171 } 174 172 175 173 progress_time += sleep_time + load_time; 176 174 177 175 /* compare the avarage sleep/load cycles */ 178 - fprintf(config->output, "%li ", powersave_time / config->cycles); 179 - fprintf(config->output, "%.3f\n", performance_time * 100.0 / powersave_time); 176 + fprintf(config->output, "%li ", 177 + powersave_time / config->cycles); 178 + fprintf(config->output, "%.3f\n", 179 + performance_time * 100.0 / powersave_time); 180 180 fflush(config->output); 181 181 182 182 if (config->verbose) 183 - printf("performance is at %.2f%%\n", performance_time * 100.0 / powersave_time); 183 + printf("performance is at %.2f%%\n", 184 + performance_time * 100.0 / powersave_time); 184 185 185 186 sleep_time += config->sleep_step; 186 187 load_time += config->load_step; 187 188 } 188 189 } 189 -
+5 -3
tools/power/cpupower/bench/benchmark.h
··· 19 19 20 20 /* load loop, this schould take about 1 to 2ms to complete */ 21 21 #define ROUNDS(x) {unsigned int rcnt; \ 22 - for (rcnt = 0; rcnt< x*1000; rcnt++) { \ 23 - (void)(((int)(pow(rcnt, rcnt) * sqrt(rcnt*7230970)) ^ 7230716) ^ (int)atan2(rcnt, rcnt)); \ 24 - }} \ 22 + for (rcnt = 0; rcnt < x*1000; rcnt++) { \ 23 + (void)(((int)(pow(rcnt, rcnt) * \ 24 + sqrt(rcnt*7230970)) ^ 7230716) ^ \ 25 + (int)atan2(rcnt, rcnt)); \ 26 + } } \ 25 27 26 28 27 29 void start_benchmark(struct config *config);
+1 -1
tools/power/cpupower/bench/config.h
··· 31 31 #ifdef DEBUG 32 32 #define dprintf printf 33 33 #else 34 - #define dprintf( ... ) while(0) { } 34 + #define dprintf(...) do { } while (0) 35 35 #endif 36 36
+3 -4
tools/power/cpupower/bench/main.c
··· 28 28 #include "system.h" 29 29 #include "benchmark.h" 30 30 31 - static struct option long_options[] = 32 - { 31 + static struct option long_options[] = { 33 32 {"output", 1, 0, 'o'}, 34 33 {"sleep", 1, 0, 's'}, 35 34 {"load", 1, 0, 'l'}, ··· 49 50 usage 50 51 *******************************************************************/ 51 52 52 - void usage() 53 + void usage() 53 54 { 54 55 printf("usage: ./bench\n"); 55 56 printf("Options:\n"); ··· 66 67 printf(" -o, --output=<dir>\t\t\toutput path. Filename will be OUTPUTPATH/benchmark_TIMESTAMP.log\n"); 67 68 printf(" -v, --verbose\t\t\t\tverbose output on/off\n"); 68 69 printf(" -h, --help\t\t\t\tPrint this help screen\n"); 69 - exit (1); 70 + exit(1); 70 71 } 71 72 72 73 /*******************************************************************
+19 -18
tools/power/cpupower/bench/parse.c
··· 86 86 len += strlen(sysdata.nodename) + strlen(sysdata.release); 87 87 filename = realloc(filename, sizeof(char) * len); 88 88 89 - if(filename == NULL) { 89 + if (filename == NULL) { 90 90 perror("realloc"); 91 91 return NULL; 92 92 } 93 93 94 - snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log", 94 + snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log", 95 95 dirname, sysdata.nodename, sysdata.release, time(NULL)); 96 96 } else { 97 - snprintf(filename, len -1, "%s/benchmark_%li.log", dirname, time(NULL)); 97 + snprintf(filename, len - 1, "%s/benchmark_%li.log", 98 + dirname, time(NULL)); 98 99 } 99 100 100 101 dprintf("logilename: %s\n", filename); 101 102 102 - if ((output = fopen(filename, "w+")) == NULL) { 103 + output = fopen(filename, "w+"); 104 + if (output == NULL) { 103 105 perror("fopen"); 104 106 fprintf(stderr, "error: unable to open logfile\n"); 105 107 } ··· 132 130 config->load_step = 500000; 133 131 config->cycles = 5; 134 132 config->rounds = 50; 135 - config->cpu = 0; 133 + config->cpu = 0; 136 134 config->prio = SCHED_HIGH; 137 135 config->verbose = 0; 138 136 strncpy(config->governor, "ondemand", 8); ··· 168 166 169 167 if (configfile == NULL) { 170 168 perror("fopen"); 171 - fprintf(stderr, "error: unable to read configfile\n"); 169 + fprintf(stderr, "error: unable to read configfile\n"); 172 170 free(config); 173 171 return 1; 174 172 } 175 173 176 - while (getline(&line, &len, configfile) != -1) 177 - { 174 + while (getline(&line, &len, configfile) != -1) { 178 175 if (line[0] == '#' || line[0] == ' ') 179 176 continue; 180 177 ··· 184 183 if (strncmp("sleep", opt, strlen(opt)) == 0) 185 184 sscanf(val, "%li", &config->sleep); 186 185 187 - else if (strncmp("load", opt, strlen(opt)) == 0) 186 + else if (strncmp("load", opt, strlen(opt)) == 0) 188 187 sscanf(val, "%li", &config->load); 189 188 190 - else if (strncmp("load_step", opt, strlen(opt)) == 0) 189 + else if (strncmp("load_step", opt, strlen(opt)) == 0) 191 190 sscanf(val, "%li", &config->load_step); 192 191 193 - else if (strncmp("sleep_step", opt, strlen(opt)) == 0) 192 + else if (strncmp("sleep_step", opt, strlen(opt)) == 0) 194 193 sscanf(val, "%li", &config->sleep_step); 195 194 196 - else if (strncmp("cycles", opt, strlen(opt)) == 0) 195 + else if (strncmp("cycles", opt, strlen(opt)) == 0) 197 196 sscanf(val, "%u", &config->cycles); 198 197 199 - else if (strncmp("rounds", opt, strlen(opt)) == 0) 198 + else if (strncmp("rounds", opt, strlen(opt)) == 0) 200 199 sscanf(val, "%u", &config->rounds); 201 200 202 - else if (strncmp("verbose", opt, strlen(opt)) == 0) 201 + else if (strncmp("verbose", opt, strlen(opt)) == 0) 203 202 sscanf(val, "%u", &config->verbose); 204 203 205 - else if (strncmp("output", opt, strlen(opt)) == 0) 204 + else if (strncmp("output", opt, strlen(opt)) == 0) 206 205 config->output = prepare_output(val); 207 206 208 - else if (strncmp("cpu", opt, strlen(opt)) == 0) 207 + else if (strncmp("cpu", opt, strlen(opt)) == 0) 209 208 sscanf(val, "%u", &config->cpu); 210 209 211 - else if (strncmp("governor", opt, 14) == 0) 210 + else if (strncmp("governor", opt, 14) == 0) 212 211 strncpy(config->governor, val, 14); 213 212 214 213 else if (strncmp("priority", opt, strlen(opt)) == 0) { 215 - if (string_to_prio(val) != SCHED_ERR) 214 + if (string_to_prio(val) != SCHED_ERR) 216 215 config->prio = string_to_prio(val); 217 216 } 218 217 }
+8 -5
tools/power/cpupower/bench/parse.h
··· 20 20 /* struct that holds the required config parameters */ 21 21 struct config 22 22 { 23 - long sleep; /* sleep time in �s */ 24 - long load; /* load time in �s */ 23 + long sleep; /* sleep time in µs */ 24 + long load; /* load time in µs */ 25 25 long sleep_step; /* time value which changes the 26 - * sleep time after every round in �s */ 26 + * sleep time after every round in µs */ 27 27 long load_step; /* time value which changes the 28 - * load time after every round in �s */ 28 + * load time after every round in µs */ 29 29 unsigned int cycles; /* calculation cycles with the same sleep/load time */ 30 30 unsigned int rounds; /* calculation rounds with iterated sleep/load time */ 31 31 unsigned int cpu; /* cpu for which the affinity is set */ 32 32 char governor[15]; /* cpufreq governor */ 33 33 enum sched_prio /* possible scheduler priorities */ 34 34 { 35 - SCHED_ERR=-1,SCHED_HIGH, SCHED_DEFAULT, SCHED_LOW 35 + SCHED_ERR = -1, 36 + SCHED_HIGH, 37 + SCHED_DEFAULT, 38 + SCHED_LOW 36 39 } prio; 37 40 38 41 unsigned int verbose; /* verbose output */
+8 -5
tools/power/cpupower/bench/system.c
··· 31 31 #include "system.h" 32 32 33 33 /** 34 - * returns time since epoch in �s 34 + * returns time since epoch in µs 35 35 * 36 36 * @retval time 37 37 **/ ··· 87 87 int set_cpu_affinity(unsigned int cpu) 88 88 { 89 89 cpu_set_t cpuset; 90 - 90 + 91 91 CPU_ZERO(&cpuset); 92 92 CPU_SET(cpu, &cpuset); 93 93 ··· 129 129 } 130 130 131 131 /** 132 - * notifys the user that the benchmark may run some time 132 + * notifies the user that the benchmark may run some time 133 133 * 134 134 * @param config benchmark config values 135 135 * ··· 142 142 unsigned int round; 143 143 144 144 for (round = 0; round < config->rounds; round++) { 145 - sleep_time += 2 * config->cycles * (config->sleep + config->sleep_step * round); 146 - load_time += 2 * config->cycles * (config->load + config->load_step * round) + (config->load + config->load_step * round * 4); 145 + sleep_time += 2 * config->cycles * 146 + (config->sleep + config->sleep_step * round); 147 + load_time += 2 * config->cycles * 148 + (config->load + config->load_step * round) + 149 + (config->load + config->load_step * round * 4); 147 150 } 148 151 149 152 if (config->verbose || config->output != stdout)