Skip to content

Commit 5f8e320

Browse files
committed
rcuscale: Measure grace-period kthread CPU time
This commit adds the ability to output the CPU time consumed by the grace-period kthread for the RCU variant under test. The CPU time is whatever is in the designated task's current->stime field, and thus is controlled by whatever CPU-time accounting scheme is in effect. This output appears in microseconds as follows on the console: rcu_scale: Grace-period kthread CPU time: 42367.037 [ paulmck: Apply feedback from Stephen Rothwell and kernel test robot. ] Signed-off-by: Paul E. McKenney <[email protected]> Tested-by: Yujie Liu <[email protected]>
1 parent bb7bad3 commit 5f8e320

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

include/linux/rcupdate_trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static inline void rcu_read_unlock_trace(void)
8787
void call_rcu_tasks_trace(struct rcu_head *rhp, rcu_callback_t func);
8888
void synchronize_rcu_tasks_trace(void);
8989
void rcu_barrier_tasks_trace(void);
90+
struct task_struct *get_rcu_tasks_trace_gp_kthread(void);
9091
#else
9192
/*
9293
* The BPF JIT forms these addresses even when it doesn't call these

kernel/rcu/rcuscale.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct rcu_scale_ops {
141141
void (*gp_barrier)(void);
142142
void (*sync)(void);
143143
void (*exp_sync)(void);
144+
struct task_struct *(*rso_gp_kthread)(void);
144145
const char *name;
145146
};
146147

@@ -336,6 +337,7 @@ static struct rcu_scale_ops tasks_tracing_ops = {
336337
.gp_barrier = rcu_barrier_tasks_trace,
337338
.sync = synchronize_rcu_tasks_trace,
338339
.exp_sync = synchronize_rcu_tasks_trace,
340+
.rso_gp_kthread = get_rcu_tasks_trace_gp_kthread,
339341
.name = "tasks-tracing"
340342
};
341343

@@ -563,6 +565,8 @@ static struct task_struct **kfree_reader_tasks;
563565
static int kfree_nrealthreads;
564566
static atomic_t n_kfree_scale_thread_started;
565567
static atomic_t n_kfree_scale_thread_ended;
568+
static struct task_struct *kthread_tp;
569+
static u64 kthread_stime;
566570

567571
struct kfree_obj {
568572
char kfree_obj[8];
@@ -808,6 +812,18 @@ rcu_scale_cleanup(void)
808812
if (gp_exp && gp_async)
809813
SCALEOUT_ERRSTRING("No expedited async GPs, so went with async!");
810814

815+
// If built-in, just report all of the GP kthread's CPU time.
816+
if (IS_BUILTIN(CONFIG_RCU_SCALE_TEST) && !kthread_tp && cur_ops->rso_gp_kthread)
817+
kthread_tp = cur_ops->rso_gp_kthread();
818+
if (kthread_tp) {
819+
u32 ns;
820+
u64 us;
821+
822+
kthread_stime = kthread_tp->stime - kthread_stime;
823+
us = div_u64_rem(kthread_stime, 1000, &ns);
824+
pr_info("rcu_scale: Grace-period kthread CPU time: %llu.%03u us\n", us, ns);
825+
show_rcu_gp_kthreads();
826+
}
811827
if (kfree_rcu_test) {
812828
kfree_scale_cleanup();
813829
return;
@@ -921,6 +937,11 @@ rcu_scale_init(void)
921937
if (cur_ops->init)
922938
cur_ops->init();
923939

940+
if (cur_ops->rso_gp_kthread) {
941+
kthread_tp = cur_ops->rso_gp_kthread();
942+
if (kthread_tp)
943+
kthread_stime = kthread_tp->stime;
944+
}
924945
if (kfree_rcu_test)
925946
return kfree_scale_init();
926947

kernel/rcu/tasks.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,12 @@ void show_rcu_tasks_trace_gp_kthread(void)
18301830
EXPORT_SYMBOL_GPL(show_rcu_tasks_trace_gp_kthread);
18311831
#endif // !defined(CONFIG_TINY_RCU)
18321832

1833+
struct task_struct *get_rcu_tasks_trace_gp_kthread(void)
1834+
{
1835+
return rcu_tasks_trace.kthread_ptr;
1836+
}
1837+
EXPORT_SYMBOL_GPL(get_rcu_tasks_trace_gp_kthread);
1838+
18331839
#else /* #ifdef CONFIG_TASKS_TRACE_RCU */
18341840
static void exit_tasks_rcu_finish_trace(struct task_struct *t) { }
18351841
#endif /* #else #ifdef CONFIG_TASKS_TRACE_RCU */

0 commit comments

Comments
 (0)