Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecb49d1a authored by Thomas Gleixner's avatar Thomas Gleixner
Browse files

hrtimers: Convert to raw_spinlocks



Convert locks which cannot be sleeping locks in preempt-rt to
raw_spinlocks.

Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarPeter Zijlstra <peterz@infradead.org>
Acked-by: default avatarIngo Molnar <mingo@elte.hu>
parent 239007b8
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -169,7 +169,7 @@ struct hrtimer_clock_base {
 * @max_hang_time:	Maximum time spent in hrtimer_interrupt
 * @max_hang_time:	Maximum time spent in hrtimer_interrupt
 */
 */
struct hrtimer_cpu_base {
struct hrtimer_cpu_base {
	spinlock_t			lock;
	raw_spinlock_t			lock;
	struct hrtimer_clock_base	clock_base[HRTIMER_MAX_CLOCK_BASES];
	struct hrtimer_clock_base	clock_base[HRTIMER_MAX_CLOCK_BASES];
#ifdef CONFIG_HIGH_RES_TIMERS
#ifdef CONFIG_HIGH_RES_TIMERS
	ktime_t				expires_next;
	ktime_t				expires_next;
+25 −25
Original line number Original line Diff line number Diff line
@@ -127,11 +127,11 @@ struct hrtimer_clock_base *lock_hrtimer_base(const struct hrtimer *timer,
	for (;;) {
	for (;;) {
		base = timer->base;
		base = timer->base;
		if (likely(base != NULL)) {
		if (likely(base != NULL)) {
			spin_lock_irqsave(&base->cpu_base->lock, *flags);
			raw_spin_lock_irqsave(&base->cpu_base->lock, *flags);
			if (likely(base == timer->base))
			if (likely(base == timer->base))
				return base;
				return base;
			/* The timer has migrated to another CPU: */
			/* The timer has migrated to another CPU: */
			spin_unlock_irqrestore(&base->cpu_base->lock, *flags);
			raw_spin_unlock_irqrestore(&base->cpu_base->lock, *flags);
		}
		}
		cpu_relax();
		cpu_relax();
	}
	}
@@ -208,13 +208,13 @@ switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base,


		/* See the comment in lock_timer_base() */
		/* See the comment in lock_timer_base() */
		timer->base = NULL;
		timer->base = NULL;
		spin_unlock(&base->cpu_base->lock);
		raw_spin_unlock(&base->cpu_base->lock);
		spin_lock(&new_base->cpu_base->lock);
		raw_spin_lock(&new_base->cpu_base->lock);


		if (cpu != this_cpu && hrtimer_check_target(timer, new_base)) {
		if (cpu != this_cpu && hrtimer_check_target(timer, new_base)) {
			cpu = this_cpu;
			cpu = this_cpu;
			spin_unlock(&new_base->cpu_base->lock);
			raw_spin_unlock(&new_base->cpu_base->lock);
			spin_lock(&base->cpu_base->lock);
			raw_spin_lock(&base->cpu_base->lock);
			timer->base = base;
			timer->base = base;
			goto again;
			goto again;
		}
		}
@@ -230,7 +230,7 @@ lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
{
{
	struct hrtimer_clock_base *base = timer->base;
	struct hrtimer_clock_base *base = timer->base;


	spin_lock_irqsave(&base->cpu_base->lock, *flags);
	raw_spin_lock_irqsave(&base->cpu_base->lock, *flags);


	return base;
	return base;
}
}
@@ -628,12 +628,12 @@ static void retrigger_next_event(void *arg)
	base = &__get_cpu_var(hrtimer_bases);
	base = &__get_cpu_var(hrtimer_bases);


	/* Adjust CLOCK_REALTIME offset */
	/* Adjust CLOCK_REALTIME offset */
	spin_lock(&base->lock);
	raw_spin_lock(&base->lock);
	base->clock_base[CLOCK_REALTIME].offset =
	base->clock_base[CLOCK_REALTIME].offset =
		timespec_to_ktime(realtime_offset);
		timespec_to_ktime(realtime_offset);


	hrtimer_force_reprogram(base, 0);
	hrtimer_force_reprogram(base, 0);
	spin_unlock(&base->lock);
	raw_spin_unlock(&base->lock);
}
}


/*
/*
@@ -694,9 +694,9 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
{
{
	if (base->cpu_base->hres_active && hrtimer_reprogram(timer, base)) {
	if (base->cpu_base->hres_active && hrtimer_reprogram(timer, base)) {
		if (wakeup) {
		if (wakeup) {
			spin_unlock(&base->cpu_base->lock);
			raw_spin_unlock(&base->cpu_base->lock);
			raise_softirq_irqoff(HRTIMER_SOFTIRQ);
			raise_softirq_irqoff(HRTIMER_SOFTIRQ);
			spin_lock(&base->cpu_base->lock);
			raw_spin_lock(&base->cpu_base->lock);
		} else
		} else
			__raise_softirq_irqoff(HRTIMER_SOFTIRQ);
			__raise_softirq_irqoff(HRTIMER_SOFTIRQ);


@@ -790,7 +790,7 @@ static inline void timer_stats_account_hrtimer(struct hrtimer *timer)
static inline
static inline
void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
{
{
	spin_unlock_irqrestore(&timer->base->cpu_base->lock, *flags);
	raw_spin_unlock_irqrestore(&timer->base->cpu_base->lock, *flags);
}
}


/**
/**
@@ -1123,7 +1123,7 @@ ktime_t hrtimer_get_next_event(void)
	unsigned long flags;
	unsigned long flags;
	int i;
	int i;


	spin_lock_irqsave(&cpu_base->lock, flags);
	raw_spin_lock_irqsave(&cpu_base->lock, flags);


	if (!hrtimer_hres_active()) {
	if (!hrtimer_hres_active()) {
		for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) {
		for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) {
@@ -1140,7 +1140,7 @@ ktime_t hrtimer_get_next_event(void)
		}
		}
	}
	}


	spin_unlock_irqrestore(&cpu_base->lock, flags);
	raw_spin_unlock_irqrestore(&cpu_base->lock, flags);


	if (mindelta.tv64 < 0)
	if (mindelta.tv64 < 0)
		mindelta.tv64 = 0;
		mindelta.tv64 = 0;
@@ -1222,11 +1222,11 @@ static void __run_hrtimer(struct hrtimer *timer, ktime_t *now)
	 * they get migrated to another cpu, therefore its safe to unlock
	 * they get migrated to another cpu, therefore its safe to unlock
	 * the timer base.
	 * the timer base.
	 */
	 */
	spin_unlock(&cpu_base->lock);
	raw_spin_unlock(&cpu_base->lock);
	trace_hrtimer_expire_entry(timer, now);
	trace_hrtimer_expire_entry(timer, now);
	restart = fn(timer);
	restart = fn(timer);
	trace_hrtimer_expire_exit(timer);
	trace_hrtimer_expire_exit(timer);
	spin_lock(&cpu_base->lock);
	raw_spin_lock(&cpu_base->lock);


	/*
	/*
	 * Note: We clear the CALLBACK bit after enqueue_hrtimer and
	 * Note: We clear the CALLBACK bit after enqueue_hrtimer and
@@ -1261,7 +1261,7 @@ void hrtimer_interrupt(struct clock_event_device *dev)
retry:
retry:
	expires_next.tv64 = KTIME_MAX;
	expires_next.tv64 = KTIME_MAX;


	spin_lock(&cpu_base->lock);
	raw_spin_lock(&cpu_base->lock);
	/*
	/*
	 * We set expires_next to KTIME_MAX here with cpu_base->lock
	 * We set expires_next to KTIME_MAX here with cpu_base->lock
	 * held to prevent that a timer is enqueued in our queue via
	 * held to prevent that a timer is enqueued in our queue via
@@ -1317,7 +1317,7 @@ void hrtimer_interrupt(struct clock_event_device *dev)
	 * against it.
	 * against it.
	 */
	 */
	cpu_base->expires_next = expires_next;
	cpu_base->expires_next = expires_next;
	spin_unlock(&cpu_base->lock);
	raw_spin_unlock(&cpu_base->lock);


	/* Reprogramming necessary ? */
	/* Reprogramming necessary ? */
	if (expires_next.tv64 == KTIME_MAX ||
	if (expires_next.tv64 == KTIME_MAX ||
@@ -1457,7 +1457,7 @@ void hrtimer_run_queues(void)
			gettime = 0;
			gettime = 0;
		}
		}


		spin_lock(&cpu_base->lock);
		raw_spin_lock(&cpu_base->lock);


		while ((node = base->first)) {
		while ((node = base->first)) {
			struct hrtimer *timer;
			struct hrtimer *timer;
@@ -1469,7 +1469,7 @@ void hrtimer_run_queues(void)


			__run_hrtimer(timer, &base->softirq_time);
			__run_hrtimer(timer, &base->softirq_time);
		}
		}
		spin_unlock(&cpu_base->lock);
		raw_spin_unlock(&cpu_base->lock);
	}
	}
}
}


@@ -1625,7 +1625,7 @@ static void __cpuinit init_hrtimers_cpu(int cpu)
	struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
	struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
	int i;
	int i;


	spin_lock_init(&cpu_base->lock);
	raw_spin_lock_init(&cpu_base->lock);


	for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++)
	for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++)
		cpu_base->clock_base[i].cpu_base = cpu_base;
		cpu_base->clock_base[i].cpu_base = cpu_base;
@@ -1683,16 +1683,16 @@ static void migrate_hrtimers(int scpu)
	 * The caller is globally serialized and nobody else
	 * The caller is globally serialized and nobody else
	 * takes two locks at once, deadlock is not possible.
	 * takes two locks at once, deadlock is not possible.
	 */
	 */
	spin_lock(&new_base->lock);
	raw_spin_lock(&new_base->lock);
	spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
	raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);


	for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
	for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
		migrate_hrtimer_list(&old_base->clock_base[i],
		migrate_hrtimer_list(&old_base->clock_base[i],
				     &new_base->clock_base[i]);
				     &new_base->clock_base[i]);
	}
	}


	spin_unlock(&old_base->lock);
	raw_spin_unlock(&old_base->lock);
	spin_unlock(&new_base->lock);
	raw_spin_unlock(&new_base->lock);


	/* Check, if we got expired work to do */
	/* Check, if we got expired work to do */
	__hrtimer_peek_ahead_timers();
	__hrtimer_peek_ahead_timers();
+3 −3
Original line number Original line Diff line number Diff line
@@ -84,7 +84,7 @@ print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,


next_one:
next_one:
	i = 0;
	i = 0;
	spin_lock_irqsave(&base->cpu_base->lock, flags);
	raw_spin_lock_irqsave(&base->cpu_base->lock, flags);


	curr = base->first;
	curr = base->first;
	/*
	/*
@@ -100,13 +100,13 @@ print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,


		timer = rb_entry(curr, struct hrtimer, node);
		timer = rb_entry(curr, struct hrtimer, node);
		tmp = *timer;
		tmp = *timer;
		spin_unlock_irqrestore(&base->cpu_base->lock, flags);
		raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);


		print_timer(m, timer, &tmp, i, now);
		print_timer(m, timer, &tmp, i, now);
		next++;
		next++;
		goto next_one;
		goto next_one;
	}
	}
	spin_unlock_irqrestore(&base->cpu_base->lock, flags);
	raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
}
}


static void
static void
+9 −8
Original line number Original line Diff line number Diff line
@@ -86,7 +86,7 @@ static DEFINE_SPINLOCK(table_lock);
/*
/*
 * Per-CPU lookup locks for fast hash lookup:
 * Per-CPU lookup locks for fast hash lookup:
 */
 */
static DEFINE_PER_CPU(spinlock_t, tstats_lookup_lock);
static DEFINE_PER_CPU(raw_spinlock_t, tstats_lookup_lock);


/*
/*
 * Mutex to serialize state changes with show-stats activities:
 * Mutex to serialize state changes with show-stats activities:
@@ -238,7 +238,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
	/*
	/*
	 * It doesnt matter which lock we take:
	 * It doesnt matter which lock we take:
	 */
	 */
	spinlock_t *lock;
	raw_spinlock_t *lock;
	struct entry *entry, input;
	struct entry *entry, input;
	unsigned long flags;
	unsigned long flags;


@@ -253,7 +253,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
	input.pid = pid;
	input.pid = pid;
	input.timer_flag = timer_flag;
	input.timer_flag = timer_flag;


	spin_lock_irqsave(lock, flags);
	raw_spin_lock_irqsave(lock, flags);
	if (!timer_stats_active)
	if (!timer_stats_active)
		goto out_unlock;
		goto out_unlock;


@@ -264,7 +264,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
		atomic_inc(&overflow_count);
		atomic_inc(&overflow_count);


 out_unlock:
 out_unlock:
	spin_unlock_irqrestore(lock, flags);
	raw_spin_unlock_irqrestore(lock, flags);
}
}


static void print_name_offset(struct seq_file *m, unsigned long addr)
static void print_name_offset(struct seq_file *m, unsigned long addr)
@@ -348,10 +348,11 @@ static void sync_access(void)
	int cpu;
	int cpu;


	for_each_online_cpu(cpu) {
	for_each_online_cpu(cpu) {
		spinlock_t *lock = &per_cpu(tstats_lookup_lock, cpu);
		raw_spinlock_t *lock = &per_cpu(tstats_lookup_lock, cpu);
		spin_lock_irqsave(lock, flags);

		raw_spin_lock_irqsave(lock, flags);
		/* nothing */
		/* nothing */
		spin_unlock_irqrestore(lock, flags);
		raw_spin_unlock_irqrestore(lock, flags);
	}
	}
}
}


@@ -409,7 +410,7 @@ void __init init_timer_stats(void)
	int cpu;
	int cpu;


	for_each_possible_cpu(cpu)
	for_each_possible_cpu(cpu)
		spin_lock_init(&per_cpu(tstats_lookup_lock, cpu));
		raw_spin_lock_init(&per_cpu(tstats_lookup_lock, cpu));
}
}


static int __init init_tstats_procfs(void)
static int __init init_tstats_procfs(void)