Re: [PATCH tip/core/rcu 6/8] rcutorture: Print symbolic name for ->gp_state

From: Paul E. McKenney
Date: Sat Dec 05 2015 - 20:53:59 EST


On Fri, Dec 04, 2015 at 05:04:21PM -0800, Josh Triplett wrote:
> On Fri, Dec 04, 2015 at 04:23:50PM -0800, Paul E. McKenney wrote:
> > Currently, ->gp_state is printed as an integer, which slows debugging.
> > This commit therefore prints a symbolic name in addition to the integer.
> >
> > Signed-off-by: Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx>
> > [ Updated to fix relational operator called out by Dan Carpenter. ]
> > ---
> > kernel/rcu/tree.c | 15 +++++++++++++--
> > kernel/rcu/tree.h | 9 +++++++++
> > 2 files changed, 22 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > index 7b78c88e19a3..491c99a73996 100644
> > --- a/kernel/rcu/tree.c
> > +++ b/kernel/rcu/tree.c
> > @@ -1187,6 +1187,16 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
> > }
> >
> > /*
> > + * Convert a ->gp_state value to a character string.
> > + */
> > +static char *gp_state_getname(short gs)
>
> Same comment about "const char *"

Good point, fixed!

> > +{
> > + if (gs < 0 || gs >= ARRAY_SIZE(gp_state_names))
> > + return "???";
> > + return gp_state_names[gs];
> > +}
> > +
> > +/*
> > * Complain about starvation of grace-period kthread.
> > */
> > static void rcu_check_gp_kthread_starvation(struct rcu_state *rsp)
> > @@ -1197,10 +1207,11 @@ static void rcu_check_gp_kthread_starvation(struct rcu_state *rsp)
> > j = jiffies;
> > gpa = READ_ONCE(rsp->gp_activity);
> > if (j - gpa > 2 * HZ) {
> > - pr_err("%s kthread starved for %ld jiffies! g%lu c%lu f%#x s%d ->state=%#lx\n",
> > + pr_err("%s kthread starved for %ld jiffies! g%lu c%lu f%#x %s(%d) ->state=%#lx\n",
> > rsp->name, j - gpa,
> > rsp->gpnum, rsp->completed,
> > - rsp->gp_flags, rsp->gp_state,
> > + rsp->gp_flags,
> > + gp_state_getname(rsp->gp_state), rsp->gp_state,
> > rsp->gp_kthread ? rsp->gp_kthread->state : ~0);
> > if (rsp->gp_kthread)
> > sched_show_task(rsp->gp_kthread);
> > diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
> > index f32bebb6bc90..f0304988e3f8 100644
> > --- a/kernel/rcu/tree.h
> > +++ b/kernel/rcu/tree.h
> > @@ -544,6 +544,15 @@ struct rcu_state {
> > #define RCU_GP_DOING_FQS 4 /* Wait done for force-quiescent-state time. */
> > #define RCU_GP_CLEANUP 5 /* Grace-period cleanup started. */
> > #define RCU_GP_CLEANED 6 /* Grace-period cleanup complete. */
> > +static char * const gp_state_names[] = {
>
> Same comment about "const char * const", but also, should this really go
> in a header file? Do any circumstances exist where this header could
> get included in more than one source file in a given build? If so,
> multiple copies of this array could potentially end up in the binary, if
> the compiler fails to merge them.

I added the const.

However, I left the array in the .h file. The issue is that the #defines
really have to be in the tree.h file. Given that, if I move the array
elsewhere, they will very likely drift out of sync. So this sounds like
a job for the compiler/linker...

Ah, but there is another approach. It turns out that tree.h in included
only from tree.c and tree_trace.c. And tree_trace.c defines a CPP symbol
RCU_TREE_NONCORE that is used elsewhere in tree.h to keep tree_trace.c's
mitts off a number of attractive but dangerous functions. So I just put
the array under "#ifndef RCU_TREE_NONCORE".

Fair enough?

Thanx, Paul

> > + "RCU_GP_IDLE",
> > + "RCU_GP_WAIT_GPS",
> > + "RCU_GP_DONE_GPS",
> > + "RCU_GP_WAIT_FQS",
> > + "RCU_GP_DOING_FQS",
> > + "RCU_GP_CLEANUP",
> > + "RCU_GP_CLEANED",
> > +};
> >
> > extern struct list_head rcu_struct_flavors;
> >
> > --
> > 2.5.2
> >
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/