Skip to content

Commit f518f15

Browse files
committed
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) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent dbf28ef commit f518f15

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

kernel/rcu/refperf.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,22 @@ u64 process_durations(int n)
333333
// point all the timestamps are printed.
334334
static int main_func(void *arg)
335335
{
336+
bool errexit = false;
336337
int exp, r;
337338
char buf1[64];
338-
char buf[512];
339+
char *buf;
339340
u64 *result_avg;
340341

341342
set_cpus_allowed_ptr(current, cpumask_of(nreaders % nr_cpu_ids));
342343
set_user_nice(current, MAX_NICE);
343344

344345
VERBOSE_PERFOUT("main_func task started");
345346
result_avg = kzalloc(nruns * sizeof(*result_avg), GFP_KERNEL);
346-
if (!result_avg)
347+
buf = kzalloc(64 + nruns * 32, GFP_KERNEL);
348+
if (!result_avg || !buf) {
347349
VERBOSE_PERFOUT_ERRSTRING("out of memory");
350+
errexit = true;
351+
}
348352
atomic_inc(&n_init);
349353

350354
// Wait for all threads to start.
@@ -354,7 +358,7 @@ static int main_func(void *arg)
354358

355359
// Start exp readers up per experiment
356360
for (exp = 0; exp < nruns && !torture_must_stop(); exp++) {
357-
if (!result_avg)
361+
if (errexit)
358362
break;
359363
if (torture_must_stop())
360364
goto end;
@@ -391,13 +395,13 @@ static int main_func(void *arg)
391395
strcat(buf, "Threads\tTime(ns)\n");
392396

393397
for (exp = 0; exp < nruns; exp++) {
394-
if (!result_avg)
398+
if (errexit)
395399
break;
396400
sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
397401
strcat(buf, buf1);
398402
}
399403

400-
if (result_avg)
404+
if (!errexit)
401405
PERFOUT("%s", buf);
402406

403407
// This will shutdown everything including us.
@@ -412,6 +416,8 @@ static int main_func(void *arg)
412416

413417
end:
414418
torture_kthread_stopping("main_func");
419+
kfree(result_avg);
420+
kfree(buf);
415421
return 0;
416422
}
417423

0 commit comments

Comments
 (0)