Re: [RFC 2/3] preempt_tracer: Disable IRQ while starting/stopping due to a preempt_counter change

From: Steven Rostedt
Date: Tue Jun 04 2019 - 11:05:31 EST


On Tue, 4 Jun 2019 12:12:36 +0200
Daniel Bristot de Oliveira <bristot@xxxxxxxxxx> wrote:

> I discussed this with Steve at the Summit on the Summit (the reason why I did
> not reply this email earlier is because I was in the conf/traveling), and he
> also agrees with peterz, disabling and (mainly) re-enabling IRQs costs too much.
>
> We need to find another way to resolve this problem (or mitigate the cost).... :-(.
>
> Ideas?

I thought we talked about using flags in the pc to let us know that we
are about to trace the preemption off?


If an interrupt comes in, we check the flag:

irq_enter()
preempt_count_add(HARDIRQ_OFFSET)


Then we can have something like:

preempt_count_add(val) {
int pc = preempt_count();
int trace_val = TRACE_FLAG;

if (val == HARDIRQ_OFFSET && (pc & TRACE_FLAG)) {
__preempt_count_sub(TRACE_FLAG);
trace_val |= TRACE_SET;
}

__preempt_count_add(val + trace_val);
if (!pc)
trace_preempt_disable();
__preempt_count_sub(trace_val);


And in trace_preempt_enable() we have:

if ((preempt_count() & TRACE_SET) && in_irq())
return;

Thus, we wont call the preempt_enable tracing code if we started it due
to an interrupt preempting the process of setting the trace.

Note, I'm writing this while extremely tired (still have yet to get
more than 4 hours of sleep) so it may still have bugs, but you should
get the idea ;-)

-- Steve