mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	timers: Always queue timers on the local CPU
The timer pull model is in place so we can remove the heuristics which try to guess the best target CPU at enqueue/modification time. All non pinned timers are queued on the local CPU in the separate storage and eventually pulled at expiry time to a remote CPU. Originally-by: Richard Cochran (linutronix GmbH) <richardcochran@gmail.com> Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://lore.kernel.org/r/20240221090548.36600-21-anna-maria@linutronix.de
This commit is contained in:
		
							parent
							
								
									36e40df35d
								
							
						
					
					
						commit
						b2cf7507e1
					
				
					 2 changed files with 19 additions and 31 deletions
				
			
		| 
						 | 
					@ -36,16 +36,10 @@
 | 
				
			||||||
 * workqueue locking issues. It's not meant for executing random crap
 | 
					 * workqueue locking issues. It's not meant for executing random crap
 | 
				
			||||||
 * with interrupts disabled. Abuse is monitored!
 | 
					 * with interrupts disabled. Abuse is monitored!
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @TIMER_PINNED: A pinned timer will not be affected by any timer
 | 
					 * @TIMER_PINNED: A pinned timer will always expire on the CPU on which the
 | 
				
			||||||
 * placement heuristics (like, NOHZ) and will always expire on the CPU
 | 
					 * timer was enqueued. When a particular CPU is required, add_timer_on()
 | 
				
			||||||
 * on which the timer was enqueued.
 | 
					 * has to be used. Enqueue via mod_timer() and add_timer() is always done
 | 
				
			||||||
 *
 | 
					 * on the local CPU.
 | 
				
			||||||
 * Note: Because enqueuing of timers can migrate the timer from one
 | 
					 | 
				
			||||||
 * CPU to another, pinned timers are not guaranteed to stay on the
 | 
					 | 
				
			||||||
 * initialy selected CPU.  They move to the CPU on which the enqueue
 | 
					 | 
				
			||||||
 * function is invoked via mod_timer() or add_timer().  If the timer
 | 
					 | 
				
			||||||
 * should be placed on a particular CPU, then add_timer_on() has to be
 | 
					 | 
				
			||||||
 * used.
 | 
					 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#define TIMER_CPUMASK		0x0003FFFF
 | 
					#define TIMER_CPUMASK		0x0003FFFF
 | 
				
			||||||
#define TIMER_MIGRATING		0x00040000
 | 
					#define TIMER_MIGRATING		0x00040000
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -635,11 +635,16 @@ trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * We might have to IPI the remote CPU if the base is idle and the
 | 
						 * We might have to IPI the remote CPU if the base is idle and the
 | 
				
			||||||
	 * timer is not deferrable. If the other CPU is on the way to idle
 | 
						 * timer is pinned. If it is a non pinned timer, it is only queued
 | 
				
			||||||
	 * then it can't set base->is_idle as we hold the base lock:
 | 
						 * on the remote CPU, when timer was running during queueing. Then
 | 
				
			||||||
 | 
						 * everything is handled by remote CPU anyway. If the other CPU is
 | 
				
			||||||
 | 
						 * on the way to idle then it can't set base->is_idle as we hold
 | 
				
			||||||
 | 
						 * the base lock:
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (base->is_idle)
 | 
						if (base->is_idle) {
 | 
				
			||||||
 | 
							WARN_ON_ONCE(!(timer->flags & TIMER_PINNED));
 | 
				
			||||||
		wake_up_nohz_cpu(base->cpu);
 | 
							wake_up_nohz_cpu(base->cpu);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
| 
						 | 
					@ -986,17 +991,6 @@ static inline struct timer_base *get_timer_base(u32 tflags)
 | 
				
			||||||
	return get_timer_cpu_base(tflags, tflags & TIMER_CPUMASK);
 | 
						return get_timer_cpu_base(tflags, tflags & TIMER_CPUMASK);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline struct timer_base *
 | 
					 | 
				
			||||||
get_target_base(struct timer_base *base, unsigned tflags)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
 | 
					 | 
				
			||||||
	if (static_branch_likely(&timers_migration_enabled) &&
 | 
					 | 
				
			||||||
	    !(tflags & TIMER_PINNED))
 | 
					 | 
				
			||||||
		return get_timer_cpu_base(tflags, get_nohz_timer_target());
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	return get_timer_this_cpu_base(tflags);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static inline void __forward_timer_base(struct timer_base *base,
 | 
					static inline void __forward_timer_base(struct timer_base *base,
 | 
				
			||||||
					unsigned long basej)
 | 
										unsigned long basej)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -1151,7 +1145,7 @@ __mod_timer(struct timer_list *timer, unsigned long expires, unsigned int option
 | 
				
			||||||
	if (!ret && (options & MOD_TIMER_PENDING_ONLY))
 | 
						if (!ret && (options & MOD_TIMER_PENDING_ONLY))
 | 
				
			||||||
		goto out_unlock;
 | 
							goto out_unlock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	new_base = get_target_base(base, timer->flags);
 | 
						new_base = get_timer_this_cpu_base(timer->flags);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (base != new_base) {
 | 
						if (base != new_base) {
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
| 
						 | 
					@ -2297,7 +2291,7 @@ static inline u64 __get_next_timer_interrupt(unsigned long basej, u64 basem,
 | 
				
			||||||
		 * granularity skew (by design).
 | 
							 * granularity skew (by design).
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (!base_local->is_idle && time_after(nextevt, basej + 1)) {
 | 
							if (!base_local->is_idle && time_after(nextevt, basej + 1)) {
 | 
				
			||||||
			base_local->is_idle = base_global->is_idle = true;
 | 
								base_local->is_idle = true;
 | 
				
			||||||
			trace_timer_base_idle(true, base_local->cpu);
 | 
								trace_timer_base_idle(true, base_local->cpu);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		*idle = base_local->is_idle;
 | 
							*idle = base_local->is_idle;
 | 
				
			||||||
| 
						 | 
					@ -2363,13 +2357,13 @@ u64 timer_base_try_to_set_idle(unsigned long basej, u64 basem, bool *idle)
 | 
				
			||||||
void timer_clear_idle(void)
 | 
					void timer_clear_idle(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * We do this unlocked. The worst outcome is a remote enqueue sending
 | 
						 * We do this unlocked. The worst outcome is a remote pinned timer
 | 
				
			||||||
	 * a pointless IPI, but taking the lock would just make the window for
 | 
						 * enqueue sending a pointless IPI, but taking the lock would just
 | 
				
			||||||
	 * sending the IPI a few instructions smaller for the cost of taking
 | 
						 * make the window for sending the IPI a few instructions smaller
 | 
				
			||||||
	 * the lock in the exit from idle path.
 | 
						 * for the cost of taking the lock in the exit from idle
 | 
				
			||||||
 | 
						 * path. Required for BASE_LOCAL only.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	__this_cpu_write(timer_bases[BASE_LOCAL].is_idle, false);
 | 
						__this_cpu_write(timer_bases[BASE_LOCAL].is_idle, false);
 | 
				
			||||||
	__this_cpu_write(timer_bases[BASE_GLOBAL].is_idle, false);
 | 
					 | 
				
			||||||
	trace_timer_base_idle(false, smp_processor_id());
 | 
						trace_timer_base_idle(false, smp_processor_id());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Activate without holding the timer_base->lock */
 | 
						/* Activate without holding the timer_base->lock */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue