Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 261778
b: refs/heads/master
c: 02af3cb
h: refs/heads/master
v: v3
  • Loading branch information
Dominik Brodowski committed Jul 29, 2011
1 parent 4f3ff1e commit 7faffca
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 59 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f5ac0641d129348399a8f39c95e7a16dc6e19f53
refs/heads/master: 02af3cb5aac13d8ef7edb7876260564b7d42ad2b
5 changes: 2 additions & 3 deletions trunk/tools/power/cpupower/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ NLS ?= true
CPUFRQ_BENCH ?= true

# Prefix to the directories we're installing to
DESTDIR ?=
DESTDIR ?=

# --- CONFIGURATION END ---

Expand Down Expand Up @@ -277,5 +277,4 @@ uninstall:
rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo; \
done;

.PHONY: all utils libcpufreq update-po create-gmo install-lib install-tools install-man install-gmo install uninstall \
clean
.PHONY: all utils libcpufreq update-po create-gmo install-lib install-tools install-man install-gmo install uninstall clean
48 changes: 29 additions & 19 deletions trunk/tools/power/cpupower/bench/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (config->output != stdout) { \
* compute how many rounds of calculation we should do
* to get the given load time
*
* @param load aimed load time in µs
* @param load aimed load time in µs
*
* @retval rounds of calculation
**/
Expand All @@ -61,9 +61,8 @@ unsigned int calculate_timespace(long load, struct config *config)
timed = (unsigned int)(then - now);

/* approximation of the wanted load time by comparing with the
* initial calculation time */
for (i= 0; i < 4; i++)
{
* initial calculation time */
for (i = 0; i < 4; i++) {
rounds = (unsigned int)(load * estimated / timed);
dprintf("calibrating with %u rounds\n", rounds);
now = get_time();
Expand Down Expand Up @@ -102,11 +101,11 @@ void start_benchmark(struct config *config)
load_time = config->load;

/* For the progress bar */
for (_round=1; _round <= config->rounds; _round++)
for (_round = 1; _round <= config->rounds; _round++)
total_time += _round * (config->sleep + config->load);
total_time *= 2; /* powersave and performance cycles */

for (_round=0; _round < config->rounds; _round++) {
for (_round = 0; _round < config->rounds; _round++) {
performance_time = 0LL;
powersave_time = 0LL;

Expand All @@ -130,9 +129,10 @@ void start_benchmark(struct config *config)
fprintf(config->output, "%u %li %li ",
_round, load_time, sleep_time);

if (config->verbose) {
printf("avarage: %lius, rps:%li\n", load_time / calculations, 1000000 * calculations / load_time);
}
if (config->verbose)
printf("avarage: %lius, rps:%li\n",
load_time / calculations,
1000000 * calculations / load_time);

/* do some sleep/load cycles with the performance governor */
for (cycle = 0; cycle < config->cycles; cycle++) {
Expand All @@ -142,10 +142,14 @@ void start_benchmark(struct config *config)
then = get_time();
performance_time += then - now - sleep_time;
if (config->verbose)
printf("performance cycle took %lius, sleep: %lius, load: %lius, rounds: %u\n",
(long)(then - now), sleep_time, load_time, calculations);
printf("performance cycle took %lius, "
"sleep: %lius, "
"load: %lius, rounds: %u\n",
(long)(then - now), sleep_time,
load_time, calculations);
}
fprintf(config->output, "%li ", performance_time / config->cycles);
fprintf(config->output, "%li ",
performance_time / config->cycles);

progress_time += sleep_time + load_time;
show_progress(total_time, progress_time);
Expand All @@ -155,30 +159,36 @@ void start_benchmark(struct config *config)
if (set_cpufreq_governor(config->governor, config->cpu) != 0)
return;

/* again, do some sleep/load cycles with the powersave governor */
/* again, do some sleep/load cycles with the
* powersave governor */
for (cycle = 0; cycle < config->cycles; cycle++) {
now = get_time();
usleep(sleep_time);
ROUNDS(calculations);
then = get_time();
powersave_time += then - now - sleep_time;
if (config->verbose)
printf("powersave cycle took %lius, sleep: %lius, load: %lius, rounds: %u\n",
(long)(then - now), sleep_time, load_time, calculations);
printf("powersave cycle took %lius, "
"sleep: %lius, "
"load: %lius, rounds: %u\n",
(long)(then - now), sleep_time,
load_time, calculations);
}

progress_time += sleep_time + load_time;

/* compare the avarage sleep/load cycles */
fprintf(config->output, "%li ", powersave_time / config->cycles);
fprintf(config->output, "%.3f\n", performance_time * 100.0 / powersave_time);
fprintf(config->output, "%li ",
powersave_time / config->cycles);
fprintf(config->output, "%.3f\n",
performance_time * 100.0 / powersave_time);
fflush(config->output);

if (config->verbose)
printf("performance is at %.2f%%\n", performance_time * 100.0 / powersave_time);
printf("performance is at %.2f%%\n",
performance_time * 100.0 / powersave_time);

sleep_time += config->sleep_step;
load_time += config->load_step;
}
}

8 changes: 5 additions & 3 deletions trunk/tools/power/cpupower/bench/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

/* load loop, this schould take about 1 to 2ms to complete */
#define ROUNDS(x) {unsigned int rcnt; \
for (rcnt = 0; rcnt< x*1000; rcnt++) { \
(void)(((int)(pow(rcnt, rcnt) * sqrt(rcnt*7230970)) ^ 7230716) ^ (int)atan2(rcnt, rcnt)); \
}} \
for (rcnt = 0; rcnt < x*1000; rcnt++) { \
(void)(((int)(pow(rcnt, rcnt) * \
sqrt(rcnt*7230970)) ^ 7230716) ^ \
(int)atan2(rcnt, rcnt)); \
} } \


void start_benchmark(struct config *config);
2 changes: 1 addition & 1 deletion trunk/tools/power/cpupower/bench/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
#ifdef DEBUG
#define dprintf printf
#else
#define dprintf( ... ) while(0) { }
#define dprintf(...) do { } while (0)
#endif

7 changes: 3 additions & 4 deletions trunk/tools/power/cpupower/bench/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
#include "system.h"
#include "benchmark.h"

static struct option long_options[] =
{
static struct option long_options[] = {
{"output", 1, 0, 'o'},
{"sleep", 1, 0, 's'},
{"load", 1, 0, 'l'},
Expand All @@ -50,7 +49,7 @@ static struct option long_options[] =
usage
*******************************************************************/

void usage()
void usage()
{
printf("usage: ./bench\n");
printf("Options:\n");
Expand All @@ -67,7 +66,7 @@ void usage()
printf(" -o, --output=<dir>\t\t\toutput path. Filename will be OUTPUTPATH/benchmark_TIMESTAMP.log\n");
printf(" -v, --verbose\t\t\t\tverbose output on/off\n");
printf(" -h, --help\t\t\t\tPrint this help screen\n");
exit (1);
exit(1);
}

/*******************************************************************
Expand Down
37 changes: 19 additions & 18 deletions trunk/tools/power/cpupower/bench/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,22 @@ FILE *prepare_output(const char *dirname)
len += strlen(sysdata.nodename) + strlen(sysdata.release);
filename = realloc(filename, sizeof(char) * len);

if(filename == NULL) {
if (filename == NULL) {
perror("realloc");
return NULL;
}

snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log",
snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log",
dirname, sysdata.nodename, sysdata.release, time(NULL));
} else {
snprintf(filename, len -1, "%s/benchmark_%li.log", dirname, time(NULL));
snprintf(filename, len - 1, "%s/benchmark_%li.log",
dirname, time(NULL));
}

dprintf("logilename: %s\n", filename);

if ((output = fopen(filename, "w+")) == NULL) {
output = fopen(filename, "w+");
if (output == NULL) {
perror("fopen");
fprintf(stderr, "error: unable to open logfile\n");
}
Expand Down Expand Up @@ -130,7 +132,7 @@ struct config *prepare_default_config()
config->load_step = 500000;
config->cycles = 5;
config->rounds = 50;
config->cpu = 0;
config->cpu = 0;
config->prio = SCHED_HIGH;
config->verbose = 0;
strncpy(config->governor, "ondemand", 8);
Expand Down Expand Up @@ -166,13 +168,12 @@ int prepare_config(const char *path, struct config *config)

if (configfile == NULL) {
perror("fopen");
fprintf(stderr, "error: unable to read configfile\n");
fprintf(stderr, "error: unable to read configfile\n");
free(config);
return 1;
}

while (getline(&line, &len, configfile) != -1)
{
while (getline(&line, &len, configfile) != -1) {
if (line[0] == '#' || line[0] == ' ')
continue;

Expand All @@ -183,35 +184,35 @@ int prepare_config(const char *path, struct config *config)
if (strncmp("sleep", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->sleep);

else if (strncmp("load", opt, strlen(opt)) == 0)
else if (strncmp("load", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->load);

else if (strncmp("load_step", opt, strlen(opt)) == 0)
else if (strncmp("load_step", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->load_step);

else if (strncmp("sleep_step", opt, strlen(opt)) == 0)
else if (strncmp("sleep_step", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->sleep_step);

else if (strncmp("cycles", opt, strlen(opt)) == 0)
else if (strncmp("cycles", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->cycles);

else if (strncmp("rounds", opt, strlen(opt)) == 0)
else if (strncmp("rounds", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->rounds);

else if (strncmp("verbose", opt, strlen(opt)) == 0)
else if (strncmp("verbose", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->verbose);

else if (strncmp("output", opt, strlen(opt)) == 0)
else if (strncmp("output", opt, strlen(opt)) == 0)
config->output = prepare_output(val);

else if (strncmp("cpu", opt, strlen(opt)) == 0)
else if (strncmp("cpu", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->cpu);

else if (strncmp("governor", opt, 14) == 0)
else if (strncmp("governor", opt, 14) == 0)
strncpy(config->governor, val, 14);

else if (strncmp("priority", opt, strlen(opt)) == 0) {
if (string_to_prio(val) != SCHED_ERR)
if (string_to_prio(val) != SCHED_ERR)
config->prio = string_to_prio(val);
}
}
Expand Down
13 changes: 8 additions & 5 deletions trunk/tools/power/cpupower/bench/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@
/* struct that holds the required config parameters */
struct config
{
long sleep; /* sleep time in µs */
long load; /* load time in µs */
long sleep; /* sleep time in µs */
long load; /* load time in µs */
long sleep_step; /* time value which changes the
* sleep time after every round in µs */
* sleep time after every round in µs */
long load_step; /* time value which changes the
* load time after every round in µs */
* load time after every round in µs */
unsigned int cycles; /* calculation cycles with the same sleep/load time */
unsigned int rounds; /* calculation rounds with iterated sleep/load time */
unsigned int cpu; /* cpu for which the affinity is set */
char governor[15]; /* cpufreq governor */
enum sched_prio /* possible scheduler priorities */
{
SCHED_ERR=-1,SCHED_HIGH, SCHED_DEFAULT, SCHED_LOW
SCHED_ERR = -1,
SCHED_HIGH,
SCHED_DEFAULT,
SCHED_LOW
} prio;

unsigned int verbose; /* verbose output */
Expand Down
13 changes: 8 additions & 5 deletions trunk/tools/power/cpupower/bench/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "system.h"

/**
* returns time since epoch in µs
* returns time since epoch in µs
*
* @retval time
**/
Expand Down Expand Up @@ -87,7 +87,7 @@ int set_cpufreq_governor(char *governor, unsigned int cpu)
int set_cpu_affinity(unsigned int cpu)
{
cpu_set_t cpuset;

CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);

Expand Down Expand Up @@ -129,7 +129,7 @@ int set_process_priority(int priority)
}

/**
* notifys the user that the benchmark may run some time
* notifies the user that the benchmark may run some time
*
* @param config benchmark config values
*
Expand All @@ -142,8 +142,11 @@ void prepare_user(const struct config *config)
unsigned int round;

for (round = 0; round < config->rounds; round++) {
sleep_time += 2 * config->cycles * (config->sleep + config->sleep_step * round);
load_time += 2 * config->cycles * (config->load + config->load_step * round) + (config->load + config->load_step * round * 4);
sleep_time += 2 * config->cycles *
(config->sleep + config->sleep_step * round);
load_time += 2 * config->cycles *
(config->load + config->load_step * round) +
(config->load + config->load_step * round * 4);
}

if (config->verbose || config->output != stdout)
Expand Down

0 comments on commit 7faffca

Please sign in to comment.