Skip to content

Commit dbf28ef

Browse files
committed
refperf: Provide module parameter to specify number of experiments
The current code uses the number of threads both to limit the number of threads and to specify the number of experiments, but also varies the number of threads as the experiments progress. This commit takes a different approach by adding an refperf.nruns module parameter that specifies the number of experiments, and furthermore uses the same number of threads for each experiment. Cc: Joel Fernandes (Google) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 8fc2878 commit dbf28ef

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

kernel/rcu/refperf.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ struct reader_task {
8383
atomic_t start;
8484
wait_queue_head_t wq;
8585
u64 last_duration_ns;
86-
87-
// The average latency When 1..<this reader> are concurrently
88-
// running an experiment. For example, if this reader_task is
89-
// of index 5 in the reader_tasks array, then result is for
90-
// 6 cores.
91-
u64 result_avg;
9286
};
9387

9488
static struct task_struct *shutdown_task;
@@ -289,12 +283,12 @@ ref_perf_reader(void *arg)
289283
return 0;
290284
}
291285

292-
void reset_readers(int n)
286+
void reset_readers(void)
293287
{
294288
int i;
295289
struct reader_task *rt;
296290

297-
for (i = 0; i < n; i++) {
291+
for (i = 0; i < nreaders; i++) {
298292
rt = &(reader_tasks[i]);
299293

300294
rt->last_duration_ns = 0;
@@ -314,7 +308,7 @@ u64 process_durations(int n)
314308
sprintf(buf, "Experiment #%d (Format: <THREAD-NUM>:<Total loop time in ns>)",
315309
exp_idx);
316310

317-
for (i = 0; i <= n && !torture_must_stop(); i++) {
311+
for (i = 0; i < n && !torture_must_stop(); i++) {
318312
rt = &(reader_tasks[i]);
319313
sprintf(buf1, "%d: %llu\t", i, rt->last_duration_ns);
320314

@@ -342,11 +336,15 @@ static int main_func(void *arg)
342336
int exp, r;
343337
char buf1[64];
344338
char buf[512];
339+
u64 *result_avg;
345340

346341
set_cpus_allowed_ptr(current, cpumask_of(nreaders % nr_cpu_ids));
347342
set_user_nice(current, MAX_NICE);
348343

349344
VERBOSE_PERFOUT("main_func task started");
345+
result_avg = kzalloc(nruns * sizeof(*result_avg), GFP_KERNEL);
346+
if (!result_avg)
347+
VERBOSE_PERFOUT_ERRSTRING("out of memory");
350348
atomic_inc(&n_init);
351349

352350
// Wait for all threads to start.
@@ -355,22 +353,24 @@ static int main_func(void *arg)
355353
schedule_timeout_interruptible(holdoff * HZ);
356354

357355
// Start exp readers up per experiment
358-
for (exp = 0; exp < nreaders && !torture_must_stop(); exp++) {
356+
for (exp = 0; exp < nruns && !torture_must_stop(); exp++) {
357+
if (!result_avg)
358+
break;
359359
if (torture_must_stop())
360360
goto end;
361361

362-
reset_readers(exp);
363-
atomic_set(&nreaders_exp, exp + 1);
362+
reset_readers();
363+
atomic_set(&nreaders_exp, nreaders);
364364

365365
exp_idx = exp;
366366

367-
for (r = 0; r <= exp; r++) {
367+
for (r = 0; r < nreaders; r++) {
368368
atomic_set(&reader_tasks[r].start, 1);
369369
wake_up(&reader_tasks[r].wq);
370370
}
371371

372372
VERBOSE_PERFOUT("main_func: experiment started, waiting for %d readers",
373-
exp);
373+
nreaders);
374374

375375
wait_event(main_wq,
376376
!atomic_read(&nreaders_exp) || torture_must_stop());
@@ -380,7 +380,7 @@ static int main_func(void *arg)
380380
if (torture_must_stop())
381381
goto end;
382382

383-
reader_tasks[exp].result_avg = 1000 * process_durations(exp) / ((exp + 1) * loops);
383+
result_avg[exp] = 1000 * process_durations(nreaders) / (nreaders * loops);
384384
}
385385

386386
// Print the average of all experiments
@@ -390,12 +390,15 @@ static int main_func(void *arg)
390390
strcat(buf, "\n");
391391
strcat(buf, "Threads\tTime(ns)\n");
392392

393-
for (exp = 0; exp < nreaders; exp++) {
394-
sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, reader_tasks[exp].result_avg / 1000, (int)(reader_tasks[exp].result_avg % 1000));
393+
for (exp = 0; exp < nruns; exp++) {
394+
if (!result_avg)
395+
break;
396+
sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
395397
strcat(buf, buf1);
396398
}
397399

398-
PERFOUT("%s", buf);
400+
if (result_avg)
401+
PERFOUT("%s", buf);
399402

400403
// This will shutdown everything including us.
401404
if (shutdown) {
@@ -416,8 +419,8 @@ static void
416419
ref_perf_print_module_parms(struct ref_perf_ops *cur_ops, const char *tag)
417420
{
418421
pr_alert("%s" PERF_FLAG
419-
"--- %s: verbose=%d shutdown=%d holdoff=%d loops=%ld nreaders=%d\n", perf_type, tag,
420-
verbose, shutdown, holdoff, loops, nreaders);
422+
"--- %s: verbose=%d shutdown=%d holdoff=%d loops=%ld nreaders=%d nruns=%d\n", perf_type, tag,
423+
verbose, shutdown, holdoff, loops, nreaders, nruns);
421424
}
422425

423426
static void

0 commit comments

Comments
 (0)