Re: [PATCH v2][RFC] tracing/context-tracking: Addpreempt_schedule_context() for tracing

From: Steven Rostedt
Date: Tue Jun 04 2013 - 10:17:13 EST


On Tue, 2013-06-04 at 14:27 +0200, Frederic Weisbecker wrote:
> On Fri, May 31, 2013 at 09:30:18PM -0400, Steven Rostedt wrote:
> > diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c
> > index 65349f0..15c9f2e 100644
> > --- a/kernel/context_tracking.c
> > +++ b/kernel/context_tracking.c
> > @@ -71,6 +71,44 @@ void user_enter(void)
> > local_irq_restore(flags);
> > }
> >
> > +/**
> > + * preempt_schedule_context - preempt_schedule called by tracing
> > + *
> > + * The tracing infrastructure uses preempt_enable_notrace to prevent
> > + * recursion and tracing preempt enabling caused by the tracing
> > + * infrastructure itself. But as tracing can happen in areas coming
> > + * from userspace or just about to enter userspace, a preempt enable
> > + * can occur before user_exit() is called. This will cause the scheduler
> > + * to be called when the system is still in usermode.
> > + *
> > + * To prevent this, the preempt_enable_notrace will use this function
> > + * instead of preempt_schedule() to exit user context if needed before
> > + * calling the scheduler.
> > + */
> > +void __sched notrace preempt_schedule_context(void)
>
> Should it be under CONFIG_PREEMPT?

Yes, and one of my tests triggered a failed build, and I fixed it last
night (patch below).

>
> > +{
> > + struct thread_info *ti = current_thread_info();
> > + enum ctx_state prev_ctx;
> > +
> > + if (likely(ti->preempt_count || irqs_disabled()))
> > + return;
> > +
> > + /*
> > + * Need to disable preemption in case user_exit() is traced
> > + * and the tracer calls preempt_enable_notrace() causing
> > + * an infinite recursion.
> > + */
> > + preempt_disable_notrace();
> > + prev_ctx = exception_enter();
> > + preempt_enable_no_resched_notrace();
> > +
> > + preempt_schedule();
> > +
> > + preempt_disable_notrace();
> > + exception_exit(prev_ctx);
> > + preempt_enable_notrace();
> > +}
> > +EXPORT_SYMBOL(preempt_schedule_context);
> >
> > /**
> > * user_exit - Inform the context tracking that the CPU is
> > --
> > 1.7.3.4
> >
> >