refperf: Dynamically allocate experiment-summary output buffer

Currently, the buffer used to accumulate the experiment-summary output
is fixed size, which will cause problems if someone decides to run
one hundred experiments.  This commit therefore dynamically allocates
this buffer.

Cc: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
This commit is contained in:
Paul E. McKenney 2020-05-25 17:32:56 -07:00
parent dbf28efdae
commit f518f154ec

View file

@ -333,9 +333,10 @@ u64 process_durations(int n)
// point all the timestamps are printed. // point all the timestamps are printed.
static int main_func(void *arg) static int main_func(void *arg)
{ {
bool errexit = false;
int exp, r; int exp, r;
char buf1[64]; char buf1[64];
char buf[512]; char *buf;
u64 *result_avg; u64 *result_avg;
set_cpus_allowed_ptr(current, cpumask_of(nreaders % nr_cpu_ids)); set_cpus_allowed_ptr(current, cpumask_of(nreaders % nr_cpu_ids));
@ -343,8 +344,11 @@ static int main_func(void *arg)
VERBOSE_PERFOUT("main_func task started"); VERBOSE_PERFOUT("main_func task started");
result_avg = kzalloc(nruns * sizeof(*result_avg), GFP_KERNEL); result_avg = kzalloc(nruns * sizeof(*result_avg), GFP_KERNEL);
if (!result_avg) buf = kzalloc(64 + nruns * 32, GFP_KERNEL);
if (!result_avg || !buf) {
VERBOSE_PERFOUT_ERRSTRING("out of memory"); VERBOSE_PERFOUT_ERRSTRING("out of memory");
errexit = true;
}
atomic_inc(&n_init); atomic_inc(&n_init);
// Wait for all threads to start. // Wait for all threads to start.
@ -354,7 +358,7 @@ static int main_func(void *arg)
// Start exp readers up per experiment // Start exp readers up per experiment
for (exp = 0; exp < nruns && !torture_must_stop(); exp++) { for (exp = 0; exp < nruns && !torture_must_stop(); exp++) {
if (!result_avg) if (errexit)
break; break;
if (torture_must_stop()) if (torture_must_stop())
goto end; goto end;
@ -391,13 +395,13 @@ static int main_func(void *arg)
strcat(buf, "Threads\tTime(ns)\n"); strcat(buf, "Threads\tTime(ns)\n");
for (exp = 0; exp < nruns; exp++) { for (exp = 0; exp < nruns; exp++) {
if (!result_avg) if (errexit)
break; break;
sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000)); sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
strcat(buf, buf1); strcat(buf, buf1);
} }
if (result_avg) if (!errexit)
PERFOUT("%s", buf); PERFOUT("%s", buf);
// This will shutdown everything including us. // This will shutdown everything including us.
@ -412,6 +416,8 @@ static int main_func(void *arg)
end: end:
torture_kthread_stopping("main_func"); torture_kthread_stopping("main_func");
kfree(result_avg);
kfree(buf);
return 0; return 0;
} }