Skip to content

Commit

Permalink
lockdep: Add hrtimer context tracing bits
Browse files Browse the repository at this point in the history
Set current->irq_config = 1 for hrtimers which are not marked to expire in
hard interrupt context during hrtimer_init(). These timers will expire in
softirq context on PREEMPT_RT.

Setting this allows lockdep to differentiate these timers. If a timer is
marked to expire in hard interrupt context then the timer callback is not
supposed to acquire a regular spinlock instead of a raw_spinlock in the
expiry callback.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200321113242.534508206@linutronix.de
  • Loading branch information
Sebastian Andrzej Siewior authored and Peter Zijlstra committed Mar 21, 2020
1 parent de8f5e4 commit 40db173
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
15 changes: 15 additions & 0 deletions include/linux/irqflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ do { \
do { \
current->softirq_context--; \
} while (0)

# define lockdep_hrtimer_enter(__hrtimer) \
do { \
if (!__hrtimer->is_hard) \
current->irq_config = 1; \
} while (0)

# define lockdep_hrtimer_exit(__hrtimer) \
do { \
if (!__hrtimer->is_hard) \
current->irq_config = 0; \
} while (0)

#else
# define trace_hardirqs_on() do { } while (0)
# define trace_hardirqs_off() do { } while (0)
Expand All @@ -68,6 +81,8 @@ do { \
# define trace_hardirq_exit() do { } while (0)
# define lockdep_softirq_enter() do { } while (0)
# define lockdep_softirq_exit() do { } while (0)
# define lockdep_hrtimer_enter(__hrtimer) do { } while (0)
# define lockdep_hrtimer_exit(__hrtimer) do { } while (0)
#endif

#if defined(CONFIG_IRQSOFF_TRACER) || \
Expand Down
1 change: 1 addition & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ struct task_struct {
unsigned int softirq_enable_event;
int softirqs_enabled;
int softirq_context;
int irq_config;
#endif

#ifdef CONFIG_LOCKDEP
Expand Down
2 changes: 1 addition & 1 deletion kernel/locking/lockdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -4025,7 +4025,7 @@ static int check_wait_context(struct task_struct *curr, struct held_lock *next)
/*
* Check if force_irqthreads will run us threaded.
*/
if (curr->hardirq_threaded)
if (curr->hardirq_threaded || curr->irq_config)
curr_inner = LD_WAIT_CONFIG;
else
curr_inner = LD_WAIT_SPIN;
Expand Down
6 changes: 5 additions & 1 deletion kernel/time/hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
base = softtimer ? HRTIMER_MAX_CLOCK_BASES / 2 : 0;
base += hrtimer_clockid_to_base(clock_id);
timer->is_soft = softtimer;
timer->is_hard = !softtimer;
timer->is_hard = !!(mode & HRTIMER_MODE_HARD);
timer->base = &cpu_base->clock_base[base];
timerqueue_init(&timer->node);
}
Expand Down Expand Up @@ -1514,7 +1514,11 @@ static void __run_hrtimer(struct hrtimer_cpu_base *cpu_base,
*/
raw_spin_unlock_irqrestore(&cpu_base->lock, flags);
trace_hrtimer_expire_entry(timer, now);
lockdep_hrtimer_enter(timer);

restart = fn(timer);

lockdep_hrtimer_exit(timer);
trace_hrtimer_expire_exit(timer);
raw_spin_lock_irq(&cpu_base->lock);

Expand Down

0 comments on commit 40db173

Please sign in to comment.