From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D452A36D503 for ; Mon, 2 Feb 2026 14:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770043041; cv=none; b=aMNScEIZ+KihdPZDEihsoTeBFhCP1j3u2qjIzMMjq/V9Wc7r7gJkIE1qH/PL2A+WlmYdDVGV4xFFqln3qU4wWeWLZ0SFq9lB37yGXIR0g9pJUT1nAh+FR/S9X79wuGrmaiUhjES9HtRnaXYqyd5vF6np3Zh9wtzknc73o64P2DM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770043041; c=relaxed/simple; bh=uTbW0l4+X3ttozP/8cmtuZG2vl+/3UsuFraGtk2ZRXM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=XR4WXg+OsPnXYcHutxDdD7r/7ao0NqeekTJShEoM3XOGr520DLO+AE2qzT5ue8EDWkBXqoWhctw99pR62nrPmg9obZIowh2hKk7CvJUzjl/nlXDnRPa7jDl+IkY56tGrLgAGMEnbhiPrGM1qeTQ/J2d/EZx6VaAqt8Wzf5n6GHQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HATAcd7+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3Lhk31hK; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HATAcd7+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3Lhk31hK" From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1770043034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=x5o8KXvgeFXozGMctLKxir84JRhxMxaMR2EOwtfVLRs=; b=HATAcd7+m/JUK+Bmt7UhhYUoNW3vWFwKISR5UqATxDoebPq83qq/Q6kDDaDtWe0qGXGG0U 6rhG2kywDxCJPPn5zwbrixiPiWv2yM20d/YrbHa5iBSG6D/Tbmsny14ANGadElUL0HfBp4 ZYT2L1WLC6niui7W+1KndakGyxZZPBL32COTEoyFtyeoXPArBRqQyKDTZPRObCZamIzn0r S3VHJb/uzvQxryB64J7siL6I87DXyOywq8LprYcOVTqJouIH4Hz/CgE4O+5xTQOlucLqHB rx4/pDII8EMA0+RcumIQ4+vSKfkSON5JFNtETE80eB51Ogm78yiQKR1KeaU2Gg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1770043034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=x5o8KXvgeFXozGMctLKxir84JRhxMxaMR2EOwtfVLRs=; b=3Lhk31hKYfiYBtQ82SP5DA99BC1rk3kJMZsklv/1x9YFcHIrVAMPFnvz6r2vmC6j8uo4tQ BLjsRgFPbLflkRDg== To: Peter Zijlstra Cc: arnd@arndb.de, anna-maria@linutronix.de, frederic@kernel.org, peterz@infradead.org, luto@kernel.org, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, linux-kernel@vger.kernel.org, oliver.sang@intel.com Subject: Re: [PATCH v2 5/6] entry,hrtimer: Push reprogramming timers into the interrupt return path In-Reply-To: <20260121162508.011240183@infradead.org> References: <20260121162010.647043073@infradead.org> <20260121162508.011240183@infradead.org> Date: Mon, 02 Feb 2026 15:37:13 +0100 Message-ID: <878qdbfbza.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Wed, Jan 21 2026 at 17:20, Peter Zijlstra wrote: > while (ti_work & EXIT_TO_USER_MODE_WORK_LOOP) { > > + /* > + * If hrtimer need re-arming, do so before enabling IRQs, > + * except when a reschedule is needed, in that case schedule() > + * will do this. > + */ > + if ((ti_work & (_TIF_NEED_RESCHED | > + _TIF_NEED_RESCHED_LAZY | > + _TIF_HRTIMER_REARM)) == _TIF_HRTIMER_REARM) > + hrtimer_rearm(); Two things I'm not convinced that they are handled correctly: 1) Interrupts After reenabling interrupts and before reaching schedule() an interrupt comes in and runs soft interrupt processing for a while on the way back, which delays the update until that processing completes. 2) Time slice extension When the time slice is granted this will not rearm the clockevent device unless the slice hrtimer becomes the first expiring timer on that CPU, but even then that misses the full reevaluation of the next timer event. > -static void __hrtimer_rearm(struct hrtimer_cpu_base *cpu_base, ktime_t now) > +static void __hrtimer_rearm(struct hrtimer_cpu_base *cpu_base, > + ktime_t now, ktime_t expires_next) > { > - ktime_t expires_next = hrtimer_update_next_event(cpu_base); > - > cpu_base->expires_next = expires_next; > cpu_base->in_hrtirq = 0; > > @@ -1970,9 +1969,30 @@ void hrtimer_interrupt(struct clock_even > cpu_base->hang_detected = 1; > } > > - __hrtimer_rearm(cpu_base, now); > +#ifdef TIF_HRTIMER_REARM > + set_thread_flag(TIF_HRTIMER_REARM); > +#else > + __hrtimer_rearm(cpu_base, now, expires_next); > +#endif in hrtimer.h where you already have the #ifdef TIF_HRTIMER_REARM section: static inline bool hrtimer_set_rearm_delayed() { set_thread_flag(TIF_HRTIMER_REARM); return true; } and a empty stub returning false for the other case then this becomes: if (!hrtimer_set_rearm_delayed()) hrtimer_rearm(...); and the ugly ifdef in the code goes away. > raw_spin_unlock_irqrestore(&cpu_base->lock, flags); > } > + > +#ifdef TIF_HRTIMER_REARM > +void _hrtimer_rearm(void) Grr. I had to read this five times to figure out that we now have hrtimer_rearm() _hrtimer_rearm() __hrtimer_rearm() You clearly ran out of characters to make that obvious: hrtimer_rearm_delayed() hrtimer_rearm() hrtimer_do_rearm() or something like that. Thanks, tglx