From nobody Fri Dec 19 15:19:52 2025 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 A2ECD1DB942 for ; Wed, 4 Sep 2024 13:05:34 +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=1725455136; cv=none; b=M27M0qzILqaibzdhppUjclA121fv9K8C8KkWV5S+OQW7l6esMfx5s8miYhPNodly2VlG2x4T4ykyxAYYwXHfOGKJIifTTal9hrt6tRDQD3BEyNqzsM2B+7PfarG0stB+63TpGlT9dCM+fCwzXGU70t5MiyDTrbnq7e/uSOdGeV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455136; c=relaxed/simple; bh=PVBamWA90dG0GtoUae7n0pSnC/+Ad2phybotoldzGv0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DtRBsJ1809hrC/Q3pQk+ITASaFj74ccP5s61GabBFX6UaHmfJ54mWFQLRKtwVI/Zsf3sXrUlRuH0cKWLnfNEdwkZQYWrUUcPYukaxt7FWnyown/z+shL+Tei0yTmSoL+PLtRz5+7LEtYBupXXm86fxb06EYX1KmhvOiobO/hW4Y= 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=XWIELyuD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Rj9SvQ/M; 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="XWIELyuD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Rj9SvQ/M" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455132; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s7qec2sb6ncYP6uk7h36V0HagfHlRIyzZPjUXHyLPpI=; b=XWIELyuDfqQSBl3TS8800c8GiXKQGIPEuKQiqJuUvX8MLVdlHJ4QhNbUHuIh3YfE57NMgV vP9SP+mHX1DcH8uQlez1zDeFFFAY+sElJnycX0XXOTwVGkrWLve5eZTJBgZ+JLCgSmb9A/ kYSNs5EwyRNqupxCndRsuo3dOwC8JdINs9Lb3uStLREDMFmyK2h7p8ArK62Zb658l4pDwP XRJWX3s7mc+3UsKf4AnCywXitS4FWmtU2pZuIEwk2ZEhYjAIjY82/wghQiFsymDIOCxxW+ MYx2BMKfpfHDvM1PMMquQqXbjufZ8oJxuKDs61PENkQgWDlI6Unxn8pVmX17ZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455132; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s7qec2sb6ncYP6uk7h36V0HagfHlRIyzZPjUXHyLPpI=; b=Rj9SvQ/MTXhF2KAa5hw0PTpph8S2J85cxCIVDjdznhkVqmsxsrG2Zozj2/xvfA6quERew2 GOMksECSdxD9T1Dw== Date: Wed, 04 Sep 2024 15:04:51 +0200 Subject: [PATCH 01/15] timers: Rename next_expiry_recalc() to be unique Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-1-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen next_expiry_recalc is the name of a function as well as the name of a struct member of struct timer_base. This might lead to confusion. Rename next_expiry_recalc() to timer_recalc_next_expiry(). No functional change. Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki Reviewed-by: Frederic Weisbecker --- kernel/time/timer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 311ea459b976..5e021a2d8d61 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -1900,7 +1900,7 @@ static int next_pending_bucket(struct timer_base *bas= e, unsigned offset, * * Store next expiry time in base->next_expiry. */ -static void next_expiry_recalc(struct timer_base *base) +static void timer_recalc_next_expiry(struct timer_base *base) { unsigned long clk, next, adj; unsigned lvl, offset =3D 0; @@ -2009,7 +2009,7 @@ static unsigned long next_timer_interrupt(struct time= r_base *base, unsigned long basej) { if (base->next_expiry_recalc) - next_expiry_recalc(base); + timer_recalc_next_expiry(base); =20 /* * Move next_expiry for the empty base into the future to prevent an @@ -2413,7 +2413,7 @@ static inline void __run_timers(struct timer_base *ba= se) * jiffies to avoid endless requeuing to current jiffies. */ base->clk++; - next_expiry_recalc(base); + timer_recalc_next_expiry(base); =20 while (levels--) expire_timers(base, heads + levels); --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 A2E351DB93D for ; Wed, 4 Sep 2024 13:05:34 +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=1725455136; cv=none; b=KsakX50tdgUuf5sHHCWybGBpSm9VcldfpareDnh/OFgTIeQPcpsZzzBCAuGG2H32H8nTpfTze77i8PqBMj5bVxQOW/c/U6EiYTS9vMk+I2rz/5ks8nq823uKVv+czga+GHAJnNcf8xPFxkbkyc7EqKjbTISLsMYizip9uHm3qZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455136; c=relaxed/simple; bh=7R+bkza0AYRIpqcsoHtjn9cM4+pcPUpfwS2tZjfPbx0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QqknMj5dDK2LtZXF6v79ax735nqISCi8vzAdGev1nTQ4CPuBfBpaVvtPeY4pmILcqSAD41I11MgIKZIERoZ6XMLWEZHMAOtC+/bRUCbixmyaoJpbx+LO6SlpJStVCH3ZMd1Co5+hLE65/FjfbS6SNYemUT077vWp4AvE9N1NYM0= 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=4ENSxVrQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=q2jEhvSx; 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="4ENSxVrQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="q2jEhvSx" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455133; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R2WqQGDvcfGVZJkLVoW0Q8qCwVWbSPkBmha+bcsdPYw=; b=4ENSxVrQD7qCW7OoarRfzNQYHWngWjSYrWrReAfZMMa4F4fSMgRxod9GWhCAahYoLiY/bL i5y8Q+h93ZIeqVMmwFNlueRwg45ztON7OyMkKxc+HKmGJ6w4BSjXYc3p6rylOWtf6bXoc1 P6HQkEyjGtQ6SWcdnZgBAAo3CI+7bUfOMVOnMLKv6a/OoSba7i4SlbE5JWQe3wKBt0b3BI loXvm17eXh94T/YlJovyv7aI77/NgXjfkILnyZX1t3Xu9WEGnH1yYhNcS9Lel7LFT+WhsP PeU41WaZ3aZZFjpp4HdRlswD/GjFZfM9et0AdrwV3xp/uOQYAE5OuPTgd2Pqbg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455133; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R2WqQGDvcfGVZJkLVoW0Q8qCwVWbSPkBmha+bcsdPYw=; b=q2jEhvSx0Wd8wcE99qqkT9yBormEb1Lup42V1W27Mw+g5XNsLiHPObP70/nTuTnUeH6H3p 4ZpLR+JWoaWqtjDw== Date: Wed, 04 Sep 2024 15:04:52 +0200 Subject: [PATCH 02/15] cpu: Use already existing usleep_range() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-2-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , Peter Zijlstra usleep_range() is a wrapper arount usleep_range_state() which hands in TASK_UNTINTERRUPTIBLE as state argument. Use already exising wrapper usleep_range(). No functional change. Cc: Peter Zijlstra Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki Reviewed-by: Frederic Weisbecker --- kernel/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index 1209ddaec026..031a2c15481b 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -330,7 +330,7 @@ static bool cpuhp_wait_for_sync_state(unsigned int cpu,= enum cpuhp_sync_state st /* Poll for one millisecond */ arch_cpuhp_sync_state_poll(); } else { - usleep_range_state(USEC_PER_MSEC, 2 * USEC_PER_MSEC, TASK_UNINTERRUPTIB= LE); + usleep_range(USEC_PER_MSEC, 2 * USEC_PER_MSEC); } sync =3D atomic_read(st); } --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 2BC7C1DB54A for ; Wed, 4 Sep 2024 13:05:34 +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=1725455137; cv=none; b=K56tDfOn3TyV9SuKakuZ/EBrI3csaYM3ERUCgIJGrzowqy6auSGyNf35p6L/0t25uqFKdtoM5YpL5JY5WFNcVpUJH00OTNY5Ydbg0nIsjBmnPObRG+EqRuRLCENl+TCypx2ta2G7jxuJuJDI2JA/LklpfMDDzuX7Aj/4PrYCDDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455137; c=relaxed/simple; bh=MTJL4Zkzckx7B+yEBbwwYRmr38U6nUmiuTCpxJ4/AFc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ioOoebq8wjsPCjHG2HSsJpWywSc9yDWHGrCR7HEKB2yJaNVhyQnJtxQQdmUBeoTREPP91+veHEdeXSYqDfkEKmV0ap1lvIrN4cE1E9gQX4PKIH6RWKdeYYFfDWGbw7S0svdNzXjZZJGES/SDY8fU1r6iiJpzftjaUMM0wEzTrZA= 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=L40TBvDd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=w3osrh9x; 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="L40TBvDd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="w3osrh9x" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455133; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h+i4/OFoPPq+xjtuv5gmXePpdIiBTWSikyghyXzck/s=; b=L40TBvDdghSx+aIB8NfXLTn4tqJWarVO4OZ9s56JNbnRbxU0T5GBYD0T/4gY0UfKLm2Gnd QO444uEkFJaSnBnJprn+bX+RTyaFDJc8Q6QlyoC4W/1r8rf4VCLeAkaJr/3UtbWsAjDAgf KSWqfuEPe91uAHDwiZgVxdJw+qCX3x3gUWW1Cp1sUOvXQ9TTozOCuf1wIK/MGADON7PhPV bu90SP2iGyOiBPAX/4nrF9jLviv30DcqtjZ+I9V3kt9RR0IJZPspUgbjlaypG1n0A7+bsd X0xlbZFg0oiMXItjyOAHZTyVkCJDRMO+HHYM6OkDs0T8qz6gQJally4km67MvQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455133; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h+i4/OFoPPq+xjtuv5gmXePpdIiBTWSikyghyXzck/s=; b=w3osrh9xPaa106cN0ciiHQvAOL/3IjBNxuDfinKCq720oXKNP7/miCHeduZ5IfEOc5hae4 ZJ/4xz13DkyCF4DA== Date: Wed, 04 Sep 2024 15:04:53 +0200 Subject: [PATCH 03/15] Comments: Fix wrong singular form of jiffies Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-3-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen There are several comments all over the place, which uses a wrong singular form of jiffies. Replace 'jiffie' by 'jiffy'. No functional change. Signed-off-by: Anna-Maria Behnsen Acked-by: Geert Uytterhoeven # m68k Acked-by: Rafael J. Wysocki --- Documentation/admin-guide/media/vivid.rst | 2 +- Documentation/timers/timers-howto.rst | 2 +- .../translations/sp_SP/scheduler/sched-design-CFS.rst | 2 +- arch/arm/mach-versatile/spc.c | 2 +- arch/m68k/q40/q40ints.c | 2 +- arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +- drivers/char/ipmi/ipmi_ssif.c | 2 +- drivers/dma-buf/st-dma-fence.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 2 +- drivers/gpu/drm/i915/gt/selftest_execlists.c | 4 ++-- drivers/gpu/drm/i915/i915_utils.c | 2 +- drivers/gpu/drm/v3d/v3d_bo.c | 2 +- drivers/isdn/mISDN/dsp_cmx.c | 2 +- drivers/net/ethernet/marvell/mvmdio.c | 2 +- fs/xfs/xfs_buf.h | 2 +- include/linux/jiffies.h | 2 +- include/linux/timekeeper_internal.h | 2 +- kernel/time/alarmtimer.c | 2 +- kernel/time/clockevents.c | 2 +- kernel/time/hrtimer.c | 2 +- kernel/time/posix-timers.c | 4 ++-- kernel/time/timer.c | 12 ++++++--= ---- lib/Kconfig.debug | 2 +- net/batman-adv/types.h | 2 +- 24 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Documentation/admin-guide/media/vivid.rst b/Documentation/admi= n-guide/media/vivid.rst index 1306f19ecb5a..c9d301ab46a3 100644 --- a/Documentation/admin-guide/media/vivid.rst +++ b/Documentation/admin-guide/media/vivid.rst @@ -328,7 +328,7 @@ and an HDMI input, one input for each input type. Those= are described in more detail below. =20 Special attention has been given to the rate at which new frames become -available. The jitter will be around 1 jiffie (that depends on the HZ +available. The jitter will be around 1 jiffy (that depends on the HZ configuration of your kernel, so usually 1/100, 1/250 or 1/1000 of a secon= d), but the long-term behavior is exactly following the framerate. So a framerate of 59.94 Hz is really different from 60 Hz. If the framerate diff --git a/Documentation/timers/timers-howto.rst b/Documentation/timers/t= imers-howto.rst index 5c169e3d29a8..ef7a4652ccc9 100644 --- a/Documentation/timers/timers-howto.rst +++ b/Documentation/timers/timers-howto.rst @@ -19,7 +19,7 @@ it really need to delay in atomic context?" If so... =20 ATOMIC CONTEXT: You must use the `*delay` family of functions. These - functions use the jiffie estimation of clock speed + functions use the jiffy estimation of clock speed and will busy wait for enough loop cycles to achieve the desired delay: =20 diff --git a/Documentation/translations/sp_SP/scheduler/sched-design-CFS.rs= t b/Documentation/translations/sp_SP/scheduler/sched-design-CFS.rst index 90a153cad4e8..731c266beb1a 100644 --- a/Documentation/translations/sp_SP/scheduler/sched-design-CFS.rst +++ b/Documentation/translations/sp_SP/scheduler/sched-design-CFS.rst @@ -109,7 +109,7 @@ para que se ejecute, y la tarea en ejecuci=C3=B3n es in= terrumpida. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 CFS usa una granularidad de nanosegundos y no depende de ning=C3=BAn -jiffie o detalles como HZ. De este modo, el gestor de tareas CFS no tiene +jiffy o detalles como HZ. De este modo, el gestor de tareas CFS no tiene noci=C3=B3n de "ventanas de tiempo" de la forma en que ten=C3=ADa el gesto= r de tareas previo, y tampoco tiene heur=C3=ADsticos. =C3=9Anicamente hay un pa= r=C3=A1metro central ajustable (se ha de cambiar en CONFIG_SCHED_DEBUG): diff --git a/arch/arm/mach-versatile/spc.c b/arch/arm/mach-versatile/spc.c index 5e44170e1a9a..790092734cf6 100644 --- a/arch/arm/mach-versatile/spc.c +++ b/arch/arm/mach-versatile/spc.c @@ -73,7 +73,7 @@ =20 /* * Even though the SPC takes max 3-5 ms to complete any OPP/COMMS - * operation, the operation could start just before jiffie is about + * operation, the operation could start just before jiffy is about * to be incremented. So setting timeout value of 20ms =3D 2jiffies@100Hz */ #define TIMEOUT_US 20000 diff --git a/arch/m68k/q40/q40ints.c b/arch/m68k/q40/q40ints.c index 10f1f294e91f..14b774b9d308 100644 --- a/arch/m68k/q40/q40ints.c +++ b/arch/m68k/q40/q40ints.c @@ -106,7 +106,7 @@ void __init q40_init_IRQ(void) * this stuff doesn't really belong here.. */ =20 -int ql_ticks; /* 200Hz ticks since last jiffie */ +int ql_ticks; /* 200Hz ticks since last jiffy */ static int sound_ticks; =20 #define SVOL 45 diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce= /dev-mcelog.c index a05ac0716ecf..a3aa0199222e 100644 --- a/arch/x86/kernel/cpu/mce/dev-mcelog.c +++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c @@ -314,7 +314,7 @@ static ssize_t mce_chrdev_write(struct file *filp, cons= t char __user *ubuf, =20 /* * Need to give user space some time to set everything up, - * so do it a jiffie or two later everywhere. + * so do it a jiffy or two later everywhere. */ schedule_timeout(2); =20 diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c index 96ad571d041a..e093028391af 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c @@ -980,7 +980,7 @@ static void msg_written_handler(struct ssif_info *ssif_= info, int result, ipmi_ssif_unlock_cond(ssif_info, flags); start_get(ssif_info); } else { - /* Wait a jiffie then request the next message */ + /* Wait a jiffy then request the next message */ ssif_info->waiting_alert =3D true; ssif_info->retries_left =3D SSIF_RECV_RETRIES; if (!ssif_info->stopping) diff --git a/drivers/dma-buf/st-dma-fence.c b/drivers/dma-buf/st-dma-fence.c index 6a1bfcd0cc21..cf2ce3744ce6 100644 --- a/drivers/dma-buf/st-dma-fence.c +++ b/drivers/dma-buf/st-dma-fence.c @@ -402,7 +402,7 @@ static int test_wait_timeout(void *arg) =20 if (dma_fence_wait_timeout(wt.f, false, 2) =3D=3D -ETIME) { if (timer_pending(&wt.timer)) { - pr_notice("Timer did not fire within the jiffie!\n"); + pr_notice("Timer did not fire within the jiffy!\n"); err =3D 0; /* not our fault! */ } else { pr_err("Wait reported incomplete after timeout\n"); diff --git a/drivers/gpu/drm/i915/gem/i915_gem_wait.c b/drivers/gpu/drm/i91= 5/gem/i915_gem_wait.c index d4b918fb11ce..1f55e62044a4 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_wait.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_wait.c @@ -266,7 +266,7 @@ i915_gem_wait_ioctl(struct drm_device *dev, void *data,= struct drm_file *file) if (ret =3D=3D -ETIME && !nsecs_to_jiffies(args->timeout_ns)) args->timeout_ns =3D 0; =20 - /* Asked to wait beyond the jiffie/scheduler precision? */ + /* Asked to wait beyond the jiffy/scheduler precision? */ if (ret =3D=3D -ETIME && args->timeout_ns) ret =3D -EAGAIN; } diff --git a/drivers/gpu/drm/i915/gt/selftest_execlists.c b/drivers/gpu/drm= /i915/gt/selftest_execlists.c index 4202df5b8c12..222ca7c44951 100644 --- a/drivers/gpu/drm/i915/gt/selftest_execlists.c +++ b/drivers/gpu/drm/i915/gt/selftest_execlists.c @@ -93,7 +93,7 @@ static int wait_for_reset(struct intel_engine_cs *engine, return -EINVAL; } =20 - /* Give the request a jiffie to complete after flushing the worker */ + /* Give the request a jiffy to complete after flushing the worker */ if (i915_request_wait(rq, 0, max(0l, (long)(timeout - jiffies)) + 1) < 0) { pr_err("%s: hanging request %llx:%lld did not complete\n", @@ -3426,7 +3426,7 @@ static int live_preempt_timeout(void *arg) cpu_relax(); =20 saved_timeout =3D engine->props.preempt_timeout_ms; - engine->props.preempt_timeout_ms =3D 1; /* in ms, -> 1 jiffie */ + engine->props.preempt_timeout_ms =3D 1; /* in ms, -> 1 jiffy */ =20 i915_request_get(rq); i915_request_add(rq); diff --git a/drivers/gpu/drm/i915/i915_utils.c b/drivers/gpu/drm/i915/i915_= utils.c index 6f9e7b354b54..f2ba51c20e97 100644 --- a/drivers/gpu/drm/i915/i915_utils.c +++ b/drivers/gpu/drm/i915/i915_utils.c @@ -110,7 +110,7 @@ void set_timer_ms(struct timer_list *t, unsigned long t= imeout) * Paranoia to make sure the compiler computes the timeout before * loading 'jiffies' as jiffies is volatile and may be updated in * the background by a timer tick. All to reduce the complexity - * of the addition and reduce the risk of losing a jiffie. + * of the addition and reduce the risk of losing a jiffy. */ barrier(); =20 diff --git a/drivers/gpu/drm/v3d/v3d_bo.c b/drivers/gpu/drm/v3d/v3d_bo.c index a165cbcdd27b..9eafe53a8f41 100644 --- a/drivers/gpu/drm/v3d/v3d_bo.c +++ b/drivers/gpu/drm/v3d/v3d_bo.c @@ -279,7 +279,7 @@ v3d_wait_bo_ioctl(struct drm_device *dev, void *data, else args->timeout_ns =3D 0; =20 - /* Asked to wait beyond the jiffie/scheduler precision? */ + /* Asked to wait beyond the jiffy/scheduler precision? */ if (ret =3D=3D -ETIME && args->timeout_ns) ret =3D -EAGAIN; =20 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c index 61cb45c5d0d8..53fad9487574 100644 --- a/drivers/isdn/mISDN/dsp_cmx.c +++ b/drivers/isdn/mISDN/dsp_cmx.c @@ -82,7 +82,7 @@ * - has multiple clocks. * - has no usable clock due to jitter or packet loss (VoIP). * In this case the system's clock is used. The clock resolution depends on - * the jiffie resolution. + * the jiffy resolution. * * If a member joins a conference: * diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/m= arvell/mvmdio.c index 9190eff6c0bb..e1d003fdbc2e 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -104,7 +104,7 @@ static int orion_mdio_wait_ready(const struct orion_mdi= o_ops *ops, return 0; } else { /* wait_event_timeout does not guarantee a delay of at - * least one whole jiffie, so timeout must be no less + * least one whole jiffy, so timeout must be no less * than two. */ timeout =3D max(usecs_to_jiffies(MVMDIO_SMI_TIMEOUT), 2); diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index b1580644501f..209a389f2abc 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -210,7 +210,7 @@ struct xfs_buf { * success the write is considered to be failed permanently and the * iodone handler will take appropriate action. * - * For retry timeouts, we record the jiffie of the first failure. This + * For retry timeouts, we record the jiffy of the first failure. This * means that we can change the retry timeout for buffers already under * I/O and thus avoid getting stuck in a retry loop with a long timeout. * diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h index d9f1435a5a13..1220f0fbe5bf 100644 --- a/include/linux/jiffies.h +++ b/include/linux/jiffies.h @@ -418,7 +418,7 @@ extern unsigned long preset_lpj; #define NSEC_CONVERSION ((unsigned long)((((u64)1 << NSEC_JIFFIE_SC) +\ TICK_NSEC -1) / (u64)TICK_NSEC)) /* - * The maximum jiffie value is (MAX_INT >> 1). Here we translate that + * The maximum jiffy value is (MAX_INT >> 1). Here we translate that * into seconds. The 64-bit case will overflow if we are not careful, * so use the messy SH_DIV macro to do it. Still all constants. */ diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper= _internal.h index 84ff2844df2a..902c20ef495a 100644 --- a/include/linux/timekeeper_internal.h +++ b/include/linux/timekeeper_internal.h @@ -73,7 +73,7 @@ struct tk_read_base { * @overflow_seen: Overflow warning flag (DEBUG_TIMEKEEPING) * * Note: For timespec(64) based interfaces wall_to_monotonic is what - * we need to add to xtime (or xtime corrected for sub jiffie times) + * we need to add to xtime (or xtime corrected for sub jiffy times) * to get to monotonic time. Monotonic is pegged at zero at system * boot time, so wall_to_monotonic will be negative, however, we will * ALWAYS keep the tv_nsec part positive so we can use the usual diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 76bd4fda3472..8bf888641694 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -493,7 +493,7 @@ static u64 __alarm_forward_now(struct alarm *alarm, kti= me_t interval, bool throt * promised in the context of posix_timer_fn() never * materialized, but someone should really work on it. * - * To prevent DOS fake @now to be 1 jiffie out which keeps + * To prevent DOS fake @now to be 1 jiffy out which keeps * the overrun accounting correct but creates an * inconsistency vs. timer_gettime(2). */ diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c index 60a6484831b1..78c7bd64d0dd 100644 --- a/kernel/time/clockevents.c +++ b/kernel/time/clockevents.c @@ -190,7 +190,7 @@ int clockevents_tick_resume(struct clock_event_device *= dev) =20 #ifdef CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST =20 -/* Limit min_delta to a jiffie */ +/* Limit min_delta to a jiffy */ #define MIN_DELTA_LIMIT (NSEC_PER_SEC / HZ) =20 /** diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index a023946f8558..e834b2bd83df 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1177,7 +1177,7 @@ static inline ktime_t hrtimer_update_lowres(struct hr= timer *timer, ktime_t tim, /* * CONFIG_TIME_LOW_RES indicates that the system has no way to return * granular time values. For relative timers we add hrtimer_resolution - * (i.e. one jiffie) to prevent short timeouts. + * (i.e. one jiffy) to prevent short timeouts. */ timer->is_rel =3D mode & HRTIMER_MODE_REL; if (timer->is_rel) diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 1cc830ef93a7..4576aaed13b2 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -339,14 +339,14 @@ static enum hrtimer_restart posix_timer_fn(struct hrt= imer *timer) * change to the signal handling code. * * For now let timers with an interval less than a - * jiffie expire every jiffie and recheck for a + * jiffy expire every jiffy and recheck for a * valid signal handler. * * This avoids interrupt starvation in case of a * very small interval, which would expire the * timer immediately again. * - * Moving now ahead of time by one jiffie tricks + * Moving now ahead of time by one jiffy tricks * hrtimer_forward() to expire the timer later, * while it still maintains the overrun accuracy * for the price of a slight inconsistency in the diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 5e021a2d8d61..2b38f3035a3e 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -365,7 +365,7 @@ static unsigned long round_jiffies_common(unsigned long= j, int cpu, rem =3D j % HZ; =20 /* - * If the target jiffie is just after a whole second (which can happen + * If the target jiffy is just after a whole second (which can happen * due to delays of the timer irq, long irq off times etc etc) then * we should round down to the whole second, not up. Use 1/4th second * as cutoff for this rounding as an extreme upper bound for this. @@ -1930,7 +1930,7 @@ static void timer_recalc_next_expiry(struct timer_bas= e *base) * bits are zero, we look at the next level as is. If not we * need to advance it by one because that's going to be the * next expiring bucket in that level. base->clk is the next - * expiring jiffie. So in case of: + * expiring jiffy. So in case of: * * LVL5 LVL4 LVL3 LVL2 LVL1 LVL0 * 0 0 0 0 0 0 @@ -1995,7 +1995,7 @@ static u64 cmp_next_hrtimer_event(u64 basem, u64 expi= res) return basem; =20 /* - * Round up to the next jiffie. High resolution timers are + * Round up to the next jiffy. High resolution timers are * off, so the hrtimers are expired in the tick and we need to * make sure that this tick really expires the timer to avoid * a ping pong of the nohz stop code. @@ -2254,7 +2254,7 @@ static inline u64 __get_next_timer_interrupt(unsigned= long basej, u64 basem, base_global, &tevt); =20 /* - * If the next event is only one jiffie ahead there is no need to call + * If the next event is only one jiffy ahead there is no need to call * timer migration hierarchy related functions. The value for the next * global timer in @tevt struct equals then KTIME_MAX. This is also * true, when the timer base is idle. @@ -2486,11 +2486,11 @@ static void run_local_timers(void) * updated. When this update is missed, this isn't a * problem, as an IPI is executed nevertheless when the CPU * was idle before. When the CPU wasn't idle but the update - * is missed, then the timer would expire one jiffie late - + * is missed, then the timer would expire one jiffy late - * bad luck. * * Those unlikely corner cases where the worst outcome is only a - * one jiffie delay or a superfluous raise of the softirq are + * one jiffy delay or a superfluous raise of the softirq are * not that expensive as doing the check always while holding * the lock. * diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index a30c03a66172..a40aa606cd04 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -97,7 +97,7 @@ config BOOT_PRINTK_DELAY using "boot_delay=3DN". =20 It is likely that you would also need to use "lpj=3DM" to preset - the "loops per jiffie" value. + the "loops per jiffy" value. See a previous boot log for the "lpj" value to use for your system, and then set "lpj=3DM" before setting "boot_delay=3DN". NOTE: Using this option may adversely affect SMP systems. diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index 00840d5784fe..04f6398b3a40 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -287,7 +287,7 @@ struct batadv_frag_table_entry { /** @lock: lock to protect the list of fragments */ spinlock_t lock; =20 - /** @timestamp: time (jiffie) of last received fragment */ + /** @timestamp: time (jiffy) of last received fragment */ unsigned long timestamp; =20 /** @seqno: sequence number of the fragments in the list */ --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 B802C1DB952 for ; Wed, 4 Sep 2024 13:05:35 +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=1725455138; cv=none; b=TG4iBzCz+BPLNBeSo/PUp3IRO0vCcMma9An5srqhNPx3J0LffWr3O2ba0Lh15mBr/bemMuDv8aCoNjRy5b4lw3/AQfjo2lmC57k7yzaOTW7kUhTvjtV6LDfwGVqkyGo+1tDU/TLn+As0DpVsruXkAzsQ0+lEOfZ9oq3FHKSGlaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455138; c=relaxed/simple; bh=em2N7rF7z5+u9IeG68v5zVAh6CzhV7Xw70Z17/621HQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q9zFA8FyZhl7odPyV34EaGkv8HhuIQ5LcZV93wYKr/WvnZRFIgc7uRIt7KW76X6A5drkefX3Rj7hkUY63zcHhuWoPZMZ+gZPIc1wdQItwizFw64H+r7Ey9zNdSDs45a+ov7p5AQoENyl6Zm3/5d9KpAus0D4AEB86V/uaFqOxuE= 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=zFJXDPdV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cHW4fGnl; 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="zFJXDPdV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cHW4fGnl" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455134; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ztFVARnh4fLRlAGS80PoqKvJNvpKqlSKmKZi2G9C0Cg=; b=zFJXDPdV4J2BI+xTO/DAJGZ+HinrWA3Q515p9G4pM2nmAmKp5pkcrtsAcxX0AgufZas98u ROyD6P7BO84/xbHfGKbahPfiTcPliuFBRTmvW9bUZvjXPgrUj/u/P746vXw5SfTBzAPgqq jCaUFCKgs6Ov85E+3Hgu5dI6P0A+Fx7Jnr/TkHZ8JYshclE+bUngPBy/r3dzesv/aukBDA UisHEJUzrGrGZNrQdur8NkuBur/iz2PRCEoEX6ZPy/slvhRwPo+pwrVRBvGE4YAgJ1bTCU n3x62UGdZbO6KrWsoRaIxO+wEid9K/yhlq/Tx5alFObu20H3eodnolqrzrdcfQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455134; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ztFVARnh4fLRlAGS80PoqKvJNvpKqlSKmKZi2G9C0Cg=; b=cHW4fGnl+xqBVRYSjePzdkC3SLeqzlIM297jgqGQp3MOD41da++odLBMTdpDLC8AKZePpf IwPH1NUVPtKTMkBw== Date: Wed, 04 Sep 2024 15:04:54 +0200 Subject: [PATCH 04/15] timers: Move *sleep*() and timeout functions into a separate file Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-4-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen All schedule_timeout() and *sleep*() related functions are interfaces on top of timer list timers and hrtimers to add a sleep to the code. As they are built on top of the timer list timers and hrtimers, the [hr]timer interfaces are already used except when queuing the timer in schedule_timeout(). But there exists the appropriate interface add_timer() which does the same job with an extra check for an already pending timer. Split all those functions as they are into a separate file and use add_timer() instead of __mod_timer() in schedule_timeout(). While at it fix minor formatting issues and a multi line printk function call in schedule_timeout(). While at it also add not listed include/linux/delay.h to the MAINTAINTERS file. Signed-off-by: Anna-Maria Behnsen Acked-by: Frederic Weisbecker Acked-by: Rafael J. Wysocki --- MAINTAINERS | 2 + kernel/time/Makefile | 2 +- kernel/time/hrtimer.c | 120 ----------------- kernel/time/sleep_timeout.c | 320 ++++++++++++++++++++++++++++++++++++++++= ++++ kernel/time/timer.c | 192 -------------------------- 5 files changed, 323 insertions(+), 313 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 42decde38320..e9cb09990e2a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10010,10 +10010,12 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/co= re F: Documentation/timers/ F: include/linux/clockchips.h +F: include/linux/delay.h F: include/linux/hrtimer.h F: include/linux/timer.h F: kernel/time/clockevents.c F: kernel/time/hrtimer.c +F: kernel/time/sleep_timeout.c F: kernel/time/timer.c F: kernel/time/timer_list.c F: kernel/time/timer_migration.* diff --git a/kernel/time/Makefile b/kernel/time/Makefile index 4af2a264a160..fe0ae82124fe 100644 --- a/kernel/time/Makefile +++ b/kernel/time/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y +=3D time.o timer.o hrtimer.o +obj-y +=3D time.o timer.o hrtimer.o sleep_timeout.o obj-y +=3D timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o obj-y +=3D timeconv.o timecounter.o alarmtimer.o =20 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index e834b2bd83df..2750ce6cb2e4 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -2242,123 +2242,3 @@ void __init hrtimers_init(void) hrtimers_prepare_cpu(smp_processor_id()); open_softirq(HRTIMER_SOFTIRQ, hrtimer_run_softirq); } - -/** - * schedule_hrtimeout_range_clock - sleep until timeout - * @expires: timeout value (ktime_t) - * @delta: slack in expires timeout (ktime_t) - * @mode: timer mode - * @clock_id: timer clock to be used - */ -int __sched -schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta, - const enum hrtimer_mode mode, clockid_t clock_id) -{ - struct hrtimer_sleeper t; - - /* - * Optimize when a zero timeout value is given. It does not - * matter whether this is an absolute or a relative time. - */ - if (expires && *expires =3D=3D 0) { - __set_current_state(TASK_RUNNING); - return 0; - } - - /* - * A NULL parameter means "infinite" - */ - if (!expires) { - schedule(); - return -EINTR; - } - - hrtimer_init_sleeper_on_stack(&t, clock_id, mode); - hrtimer_set_expires_range_ns(&t.timer, *expires, delta); - hrtimer_sleeper_start_expires(&t, mode); - - if (likely(t.task)) - schedule(); - - hrtimer_cancel(&t.timer); - destroy_hrtimer_on_stack(&t.timer); - - __set_current_state(TASK_RUNNING); - - return !t.task ? 0 : -EINTR; -} -EXPORT_SYMBOL_GPL(schedule_hrtimeout_range_clock); - -/** - * schedule_hrtimeout_range - sleep until timeout - * @expires: timeout value (ktime_t) - * @delta: slack in expires timeout (ktime_t) - * @mode: timer mode - * - * Make the current task sleep until the given expiry time has - * elapsed. The routine will return immediately unless - * the current task state has been set (see set_current_state()). - * - * The @delta argument gives the kernel the freedom to schedule the - * actual wakeup to a time that is both power and performance friendly - * for regular (non RT/DL) tasks. - * The kernel give the normal best effort behavior for "@expires+@delta", - * but may decide to fire the timer earlier, but no earlier than @expires. - * - * You can set the task state as follows - - * - * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to - * pass before the routine returns unless the current task is explicitly - * woken up, (e.g. by wake_up_process()). - * - * %TASK_INTERRUPTIBLE - the routine may return early if a signal is - * delivered to the current task or the current task is explicitly woken - * up. - * - * The current task state is guaranteed to be TASK_RUNNING when this - * routine returns. - * - * Returns 0 when the timer has expired. If the task was woken before the - * timer expired by a signal (only possible in state TASK_INTERRUPTIBLE) or - * by an explicit wakeup, it returns -EINTR. - */ -int __sched schedule_hrtimeout_range(ktime_t *expires, u64 delta, - const enum hrtimer_mode mode) -{ - return schedule_hrtimeout_range_clock(expires, delta, mode, - CLOCK_MONOTONIC); -} -EXPORT_SYMBOL_GPL(schedule_hrtimeout_range); - -/** - * schedule_hrtimeout - sleep until timeout - * @expires: timeout value (ktime_t) - * @mode: timer mode - * - * Make the current task sleep until the given expiry time has - * elapsed. The routine will return immediately unless - * the current task state has been set (see set_current_state()). - * - * You can set the task state as follows - - * - * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to - * pass before the routine returns unless the current task is explicitly - * woken up, (e.g. by wake_up_process()). - * - * %TASK_INTERRUPTIBLE - the routine may return early if a signal is - * delivered to the current task or the current task is explicitly woken - * up. - * - * The current task state is guaranteed to be TASK_RUNNING when this - * routine returns. - * - * Returns 0 when the timer has expired. If the task was woken before the - * timer expired by a signal (only possible in state TASK_INTERRUPTIBLE) or - * by an explicit wakeup, it returns -EINTR. - */ -int __sched schedule_hrtimeout(ktime_t *expires, - const enum hrtimer_mode mode) -{ - return schedule_hrtimeout_range(expires, 0, mode); -} -EXPORT_SYMBOL_GPL(schedule_hrtimeout); diff --git a/kernel/time/sleep_timeout.c b/kernel/time/sleep_timeout.c new file mode 100644 index 000000000000..9ecbce7da537 --- /dev/null +++ b/kernel/time/sleep_timeout.c @@ -0,0 +1,320 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Kernel internal schedule timeout and sleeping functions + */ + +#include +#include +#include +#include +#include + +#include "tick-internal.h" + +/* + * Since schedule_timeout()'s timer is defined on the stack, it must store + * the target task on the stack as well. + */ +struct process_timer { + struct timer_list timer; + struct task_struct *task; +}; + +static void process_timeout(struct timer_list *t) +{ + struct process_timer *timeout =3D from_timer(timeout, t, timer); + + wake_up_process(timeout->task); +} + +/** + * schedule_timeout - sleep until timeout + * @timeout: timeout value in jiffies + * + * Make the current task sleep until @timeout jiffies have elapsed. + * The function behavior depends on the current task state + * (see also set_current_state() description): + * + * %TASK_RUNNING - the scheduler is called, but the task does not sleep + * at all. That happens because sched_submit_work() does nothing for + * tasks in %TASK_RUNNING state. + * + * %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to + * pass before the routine returns unless the current task is explicitly + * woken up, (e.g. by wake_up_process()). + * + * %TASK_INTERRUPTIBLE - the routine may return early if a signal is + * delivered to the current task or the current task is explicitly woken + * up. + * + * The current task state is guaranteed to be %TASK_RUNNING when this + * routine returns. + * + * Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule + * the CPU away without a bound on the timeout. In this case the return + * value will be %MAX_SCHEDULE_TIMEOUT. + * + * Returns 0 when the timer has expired otherwise the remaining time in + * jiffies will be returned. In all cases the return value is guaranteed + * to be non-negative. + */ +signed long __sched schedule_timeout(signed long timeout) +{ + struct process_timer timer; + unsigned long expire; + + switch (timeout) { + case MAX_SCHEDULE_TIMEOUT: + /* + * These two special cases are useful to be comfortable + * in the caller. Nothing more. We could take + * MAX_SCHEDULE_TIMEOUT from one of the negative value + * but I' d like to return a valid offset (>=3D0) to allow + * the caller to do everything it want with the retval. + */ + schedule(); + goto out; + default: + /* + * Another bit of PARANOID. Note that the retval will be + * 0 since no piece of kernel is supposed to do a check + * for a negative retval of schedule_timeout() (since it + * should never happens anyway). You just have the printk() + * that will tell you if something is gone wrong and where. + */ + if (timeout < 0) { + pr_err("%s: wrong timeout value %lx\n", __func__, timeout); + dump_stack(); + __set_current_state(TASK_RUNNING); + goto out; + } + } + + expire =3D timeout + jiffies; + + timer.task =3D current; + timer_setup_on_stack(&timer.timer, process_timeout, 0); + timer.timer.expires =3D expire; + add_timer(&timer.timer); + schedule(); + del_timer_sync(&timer.timer); + + /* Remove the timer from the object tracker */ + destroy_timer_on_stack(&timer.timer); + + timeout =3D expire - jiffies; + + out: + return timeout < 0 ? 0 : timeout; +} +EXPORT_SYMBOL(schedule_timeout); + +/* + * We can use __set_current_state() here because schedule_timeout() calls + * schedule() unconditionally. + */ +signed long __sched schedule_timeout_interruptible(signed long timeout) +{ + __set_current_state(TASK_INTERRUPTIBLE); + return schedule_timeout(timeout); +} +EXPORT_SYMBOL(schedule_timeout_interruptible); + +signed long __sched schedule_timeout_killable(signed long timeout) +{ + __set_current_state(TASK_KILLABLE); + return schedule_timeout(timeout); +} +EXPORT_SYMBOL(schedule_timeout_killable); + +signed long __sched schedule_timeout_uninterruptible(signed long timeout) +{ + __set_current_state(TASK_UNINTERRUPTIBLE); + return schedule_timeout(timeout); +} +EXPORT_SYMBOL(schedule_timeout_uninterruptible); + +/* + * Like schedule_timeout_uninterruptible(), except this task will not cont= ribute + * to load average. + */ +signed long __sched schedule_timeout_idle(signed long timeout) +{ + __set_current_state(TASK_IDLE); + return schedule_timeout(timeout); +} +EXPORT_SYMBOL(schedule_timeout_idle); + +/** + * schedule_hrtimeout_range_clock - sleep until timeout + * @expires: timeout value (ktime_t) + * @delta: slack in expires timeout (ktime_t) + * @mode: timer mode + * @clock_id: timer clock to be used + */ +int __sched +schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta, + const enum hrtimer_mode mode, clockid_t clock_id) +{ + struct hrtimer_sleeper t; + + /* + * Optimize when a zero timeout value is given. It does not + * matter whether this is an absolute or a relative time. + */ + if (expires && *expires =3D=3D 0) { + __set_current_state(TASK_RUNNING); + return 0; + } + + /* + * A NULL parameter means "infinite" + */ + if (!expires) { + schedule(); + return -EINTR; + } + + hrtimer_init_sleeper_on_stack(&t, clock_id, mode); + hrtimer_set_expires_range_ns(&t.timer, *expires, delta); + hrtimer_sleeper_start_expires(&t, mode); + + if (likely(t.task)) + schedule(); + + hrtimer_cancel(&t.timer); + destroy_hrtimer_on_stack(&t.timer); + + __set_current_state(TASK_RUNNING); + + return !t.task ? 0 : -EINTR; +} +EXPORT_SYMBOL_GPL(schedule_hrtimeout_range_clock); + +/** + * schedule_hrtimeout_range - sleep until timeout + * @expires: timeout value (ktime_t) + * @delta: slack in expires timeout (ktime_t) + * @mode: timer mode + * + * Make the current task sleep until the given expiry time has + * elapsed. The routine will return immediately unless + * the current task state has been set (see set_current_state()). + * + * The @delta argument gives the kernel the freedom to schedule the + * actual wakeup to a time that is both power and performance friendly + * for regular (non RT/DL) tasks. + * The kernel give the normal best effort behavior for "@expires+@delta", + * but may decide to fire the timer earlier, but no earlier than @expires. + * + * You can set the task state as follows - + * + * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to + * pass before the routine returns unless the current task is explicitly + * woken up, (e.g. by wake_up_process()). + * + * %TASK_INTERRUPTIBLE - the routine may return early if a signal is + * delivered to the current task or the current task is explicitly woken + * up. + * + * The current task state is guaranteed to be TASK_RUNNING when this + * routine returns. + * + * Returns 0 when the timer has expired. If the task was woken before the + * timer expired by a signal (only possible in state TASK_INTERRUPTIBLE) or + * by an explicit wakeup, it returns -EINTR. + */ +int __sched schedule_hrtimeout_range(ktime_t *expires, u64 delta, + const enum hrtimer_mode mode) +{ + return schedule_hrtimeout_range_clock(expires, delta, mode, + CLOCK_MONOTONIC); +} +EXPORT_SYMBOL_GPL(schedule_hrtimeout_range); + +/** + * schedule_hrtimeout - sleep until timeout + * @expires: timeout value (ktime_t) + * @mode: timer mode + * + * Make the current task sleep until the given expiry time has + * elapsed. The routine will return immediately unless + * the current task state has been set (see set_current_state()). + * + * You can set the task state as follows - + * + * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to + * pass before the routine returns unless the current task is explicitly + * woken up, (e.g. by wake_up_process()). + * + * %TASK_INTERRUPTIBLE - the routine may return early if a signal is + * delivered to the current task or the current task is explicitly woken + * up. + * + * The current task state is guaranteed to be TASK_RUNNING when this + * routine returns. + * + * Returns 0 when the timer has expired. If the task was woken before the + * timer expired by a signal (only possible in state TASK_INTERRUPTIBLE) or + * by an explicit wakeup, it returns -EINTR. + */ +int __sched schedule_hrtimeout(ktime_t *expires, + const enum hrtimer_mode mode) +{ + return schedule_hrtimeout_range(expires, 0, mode); +} +EXPORT_SYMBOL_GPL(schedule_hrtimeout); + +/** + * msleep - sleep safely even with waitqueue interruptions + * @msecs: Time in milliseconds to sleep for + */ +void msleep(unsigned int msecs) +{ + unsigned long timeout =3D msecs_to_jiffies(msecs); + + while (timeout) + timeout =3D schedule_timeout_uninterruptible(timeout); +} +EXPORT_SYMBOL(msleep); + +/** + * msleep_interruptible - sleep waiting for signals + * @msecs: Time in milliseconds to sleep for + */ +unsigned long msleep_interruptible(unsigned int msecs) +{ + unsigned long timeout =3D msecs_to_jiffies(msecs); + + while (timeout && !signal_pending(current)) + timeout =3D schedule_timeout_interruptible(timeout); + return jiffies_to_msecs(timeout); +} +EXPORT_SYMBOL(msleep_interruptible); + +/** + * usleep_range_state - Sleep for an approximate time in a given state + * @min: Minimum time in usecs to sleep + * @max: Maximum time in usecs to sleep + * @state: State of the current task that will be while sleeping + * + * In non-atomic context where the exact wakeup time is flexible, use + * usleep_range_state() instead of udelay(). The sleep improves responsiv= eness + * by avoiding the CPU-hogging busy-wait of udelay(), and the range reduces + * power usage by allowing hrtimers to take advantage of an already- + * scheduled interrupt instead of scheduling a new one just for this sleep. + */ +void __sched usleep_range_state(unsigned long min, unsigned long max, + unsigned int state) +{ + ktime_t exp =3D ktime_add_us(ktime_get(), min); + u64 delta =3D (u64)(max - min) * NSEC_PER_USEC; + + for (;;) { + __set_current_state(state); + /* Do not return before the requested sleep time has elapsed */ + if (!schedule_hrtimeout_range(&exp, delta, HRTIMER_MODE_ABS)) + break; + } +} +EXPORT_SYMBOL(usleep_range_state); diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 2b38f3035a3e..bb53d22cc911 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -2526,141 +2525,6 @@ void update_process_times(int user_tick) run_posix_cpu_timers(); } =20 -/* - * Since schedule_timeout()'s timer is defined on the stack, it must store - * the target task on the stack as well. - */ -struct process_timer { - struct timer_list timer; - struct task_struct *task; -}; - -static void process_timeout(struct timer_list *t) -{ - struct process_timer *timeout =3D from_timer(timeout, t, timer); - - wake_up_process(timeout->task); -} - -/** - * schedule_timeout - sleep until timeout - * @timeout: timeout value in jiffies - * - * Make the current task sleep until @timeout jiffies have elapsed. - * The function behavior depends on the current task state - * (see also set_current_state() description): - * - * %TASK_RUNNING - the scheduler is called, but the task does not sleep - * at all. That happens because sched_submit_work() does nothing for - * tasks in %TASK_RUNNING state. - * - * %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to - * pass before the routine returns unless the current task is explicitly - * woken up, (e.g. by wake_up_process()). - * - * %TASK_INTERRUPTIBLE - the routine may return early if a signal is - * delivered to the current task or the current task is explicitly woken - * up. - * - * The current task state is guaranteed to be %TASK_RUNNING when this - * routine returns. - * - * Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule - * the CPU away without a bound on the timeout. In this case the return - * value will be %MAX_SCHEDULE_TIMEOUT. - * - * Returns 0 when the timer has expired otherwise the remaining time in - * jiffies will be returned. In all cases the return value is guaranteed - * to be non-negative. - */ -signed long __sched schedule_timeout(signed long timeout) -{ - struct process_timer timer; - unsigned long expire; - - switch (timeout) - { - case MAX_SCHEDULE_TIMEOUT: - /* - * These two special cases are useful to be comfortable - * in the caller. Nothing more. We could take - * MAX_SCHEDULE_TIMEOUT from one of the negative value - * but I' d like to return a valid offset (>=3D0) to allow - * the caller to do everything it want with the retval. - */ - schedule(); - goto out; - default: - /* - * Another bit of PARANOID. Note that the retval will be - * 0 since no piece of kernel is supposed to do a check - * for a negative retval of schedule_timeout() (since it - * should never happens anyway). You just have the printk() - * that will tell you if something is gone wrong and where. - */ - if (timeout < 0) { - printk(KERN_ERR "schedule_timeout: wrong timeout " - "value %lx\n", timeout); - dump_stack(); - __set_current_state(TASK_RUNNING); - goto out; - } - } - - expire =3D timeout + jiffies; - - timer.task =3D current; - timer_setup_on_stack(&timer.timer, process_timeout, 0); - __mod_timer(&timer.timer, expire, MOD_TIMER_NOTPENDING); - schedule(); - del_timer_sync(&timer.timer); - - /* Remove the timer from the object tracker */ - destroy_timer_on_stack(&timer.timer); - - timeout =3D expire - jiffies; - - out: - return timeout < 0 ? 0 : timeout; -} -EXPORT_SYMBOL(schedule_timeout); - -/* - * We can use __set_current_state() here because schedule_timeout() calls - * schedule() unconditionally. - */ -signed long __sched schedule_timeout_interruptible(signed long timeout) -{ - __set_current_state(TASK_INTERRUPTIBLE); - return schedule_timeout(timeout); -} -EXPORT_SYMBOL(schedule_timeout_interruptible); - -signed long __sched schedule_timeout_killable(signed long timeout) -{ - __set_current_state(TASK_KILLABLE); - return schedule_timeout(timeout); -} -EXPORT_SYMBOL(schedule_timeout_killable); - -signed long __sched schedule_timeout_uninterruptible(signed long timeout) -{ - __set_current_state(TASK_UNINTERRUPTIBLE); - return schedule_timeout(timeout); -} -EXPORT_SYMBOL(schedule_timeout_uninterruptible); - -/* - * Like schedule_timeout_uninterruptible(), except this task will not cont= ribute - * to load average. - */ -signed long __sched schedule_timeout_idle(signed long timeout) -{ - __set_current_state(TASK_IDLE); - return schedule_timeout(timeout); -} -EXPORT_SYMBOL(schedule_timeout_idle); - #ifdef CONFIG_HOTPLUG_CPU static void migrate_timer_list(struct timer_base *new_base, struct hlist_h= ead *head) { @@ -2757,59 +2621,3 @@ void __init init_timers(void) posix_cputimers_init_work(); open_softirq(TIMER_SOFTIRQ, run_timer_softirq); } - -/** - * msleep - sleep safely even with waitqueue interruptions - * @msecs: Time in milliseconds to sleep for - */ -void msleep(unsigned int msecs) -{ - unsigned long timeout =3D msecs_to_jiffies(msecs); - - while (timeout) - timeout =3D schedule_timeout_uninterruptible(timeout); -} - -EXPORT_SYMBOL(msleep); - -/** - * msleep_interruptible - sleep waiting for signals - * @msecs: Time in milliseconds to sleep for - */ -unsigned long msleep_interruptible(unsigned int msecs) -{ - unsigned long timeout =3D msecs_to_jiffies(msecs); - - while (timeout && !signal_pending(current)) - timeout =3D schedule_timeout_interruptible(timeout); - return jiffies_to_msecs(timeout); -} - -EXPORT_SYMBOL(msleep_interruptible); - -/** - * usleep_range_state - Sleep for an approximate time in a given state - * @min: Minimum time in usecs to sleep - * @max: Maximum time in usecs to sleep - * @state: State of the current task that will be while sleeping - * - * In non-atomic context where the exact wakeup time is flexible, use - * usleep_range_state() instead of udelay(). The sleep improves responsiv= eness - * by avoiding the CPU-hogging busy-wait of udelay(), and the range reduces - * power usage by allowing hrtimers to take advantage of an already- - * scheduled interrupt instead of scheduling a new one just for this sleep. - */ -void __sched usleep_range_state(unsigned long min, unsigned long max, - unsigned int state) -{ - ktime_t exp =3D ktime_add_us(ktime_get(), min); - u64 delta =3D (u64)(max - min) * NSEC_PER_USEC; - - for (;;) { - __set_current_state(state); - /* Do not return before the requested sleep time has elapsed */ - if (!schedule_hrtimeout_range(&exp, delta, HRTIMER_MODE_ABS)) - break; - } -} -EXPORT_SYMBOL(usleep_range_state); --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 ADE871DC1AA for ; Wed, 4 Sep 2024 13:05:37 +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=1725455139; cv=none; b=B9JgfuoR9/5/6gXteoV1FjIT4W3yJQzTRHsYjJxSd32gcjvB94+l7zI1BOLMNhqVWAGKhsu12O+wTWIJKsoD1ztsOBrYGtUt1Q0MnEHdgH+N1Yb/NVM8IwVMBVE7H8WhCayfbNQxFHSzMGgjjoFp4hNdN/Ey1fXIlplbQnd3eJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455139; c=relaxed/simple; bh=xONkljkqAACvrhcLR/IpmJ9rZkgqlFfHZySmfYcCH4s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XIKHosn32Bh6+MEyQqlhGJv2/4H/X+kIzzJN8t0I8p1JUu77HMaHllEIkkT5Pg65EY7QCQQcZGgVYsXLeiIEfxVwBPNDtCeKQRw8gtRl/YHyNz1OD65PsWzp8SlDtnalGUXvin2prasMlwjMiZoy14ftujf9g2KKXWekeeBxhlg= 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=K1fHHPDD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VmFDXr0l; 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="K1fHHPDD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VmFDXr0l" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455134; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R6JzfinROxb0cF6NxXq0JcmrJuw7pVBPvlFaejLfwHs=; b=K1fHHPDD27YunAkdxRxKlxq7v0mgwE/YXfmGTccsLisSDbEUJP5ilOZ/AOSa8xlcm5JLZE ZLWQ2TfNLuirTGa9IWwYtePyYKOwoh++7/zmmWgD9ivb5c6RTvf0wOlpX/GKY13Kyl0seU BImyKU9xR37tQ82WpC1Zow2CrcJo9KJL+z4IGxHDGV8G2w/NdFm3/qMJ1UGSvJR679MCTo 7uGRz3apBsEUNJlIXVAWnn5SbZqusjwabJCNmzHHcguNXR0AJ0mYyMzbZujKiKu1gne04r z8YFjvYcwCf2Qn2DLHU6hIqDJis0IaNf+iV5b2HHROWjLZmmKN+TEFlDvjQeLg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455134; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R6JzfinROxb0cF6NxXq0JcmrJuw7pVBPvlFaejLfwHs=; b=VmFDXr0lbLciL542cJmYJCDZ6Oumihap+7q+8O9BQBdroT1ZJJulw0rGnYOb5gGnS5egov SD8iMVd4PfPjvBBQ== Date: Wed, 04 Sep 2024 15:04:55 +0200 Subject: [PATCH 05/15] timers: Rename sleep_idle_range() to sleep_range_idle() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-5-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org sleep_idle_range() is a variant of sleep_range(). Both are using sleep_range_state() as a base. To be able to find all the related functions in one go, rename it sleep_idle_range() to sleep_range_idle(). No functional change. Cc: SeongJae Park Cc: Andrew Morton Cc: damon@lists.linux.dev Cc: linux-mm@kvack.org Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki Reviewed-by: Frederic Weisbecker Reviewed-by: SeongJae Park --- include/linux/delay.h | 2 +- mm/damon/core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/delay.h b/include/linux/delay.h index ff9cda975e30..2bc586aa2068 100644 --- a/include/linux/delay.h +++ b/include/linux/delay.h @@ -68,7 +68,7 @@ static inline void usleep_range(unsigned long min, unsign= ed long max) usleep_range_state(min, max, TASK_UNINTERRUPTIBLE); } =20 -static inline void usleep_idle_range(unsigned long min, unsigned long max) +static inline void usleep_range_idle(unsigned long min, unsigned long max) { usleep_range_state(min, max, TASK_IDLE); } diff --git a/mm/damon/core.c b/mm/damon/core.c index 7a87628b76ab..94fe2f1f9b0e 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1887,7 +1887,7 @@ static void kdamond_usleep(unsigned long usecs) if (usecs > 20 * USEC_PER_MSEC) schedule_timeout_idle(usecs_to_jiffies(usecs)); else - usleep_idle_range(usecs, usecs + 1); + usleep_range_idle(usecs, usecs + 1); } =20 /* Returns negative error code if it's not activated but should return */ --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 ADF7C1DC1AC; Wed, 4 Sep 2024 13:05:37 +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=1725455139; cv=none; b=VJ1db6scj97tvvgxZkUT08IRZ4oRQgZRNsXPMqIlGzEfLKTxJDzutc11Djh8v5wdz9bvWOIlQ2IWamhlorSejuq3XC5+AJLf3BBuc79enNsezWoYqvJn6FxkjP87fhIXbsGVF4y2EIn4gZ9DjBlrhUERwRzwh23mYyWJLdcWCzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455139; c=relaxed/simple; bh=lq+j0e/8+B+CBghNSJokdBW4yysfRaHHcpZuOTFu4jA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OC32ZJddXzWZx6u4BhOrZ9T2N1nPMFtJ9jeCCVCXPwoHAFXvCf8+dUJIujLAXXB4PWu8GaZsxl+1urHXHl9xLseEh8qZTMzidOh/k3E2XnXPeBXsrglh59VnGrSb5JoapcW/3EPMIebM2AghZRz7ofL17PsMnPCvWg2HEddzvqA= 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=KkWUiI7G; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zGVPaphm; 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="KkWUiI7G"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zGVPaphm" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455135; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S6wpVq7tSU8GXjnK50bDdv4b35oGLvoXViWUHQ1ET4U=; b=KkWUiI7G5XAYGHsQr1rkeyfVFQ7dZPXjuv80Vxc5N2xu6MUZ8RBweRA9houKeZMcXhtDjb oTl4BGrdRa/p9umShdst3ON7WcUW/Yhy8iSGmGFtjjL9BVRXL/VUw5Kl5dp9efEWNSOlh6 qAW7tvfJR79Jg2EAvPntIe5Z5T/+uFR6UAkDsnScuNBiFG/rjF4dlNHtphfzWFsuxDveng hh8M46l3OhNdKoVasY3GlvB8gYHaCjJ294CsJsepc5SzUHx8op8Uv6yNiX5S/AFGyrSDaX 5m4qdi6QnurqaXPcf6IrECWTtbJ1yQ8gkhR4RdmixEubLbRpZA77Fw5EPaqRWw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455135; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S6wpVq7tSU8GXjnK50bDdv4b35oGLvoXViWUHQ1ET4U=; b=zGVPaphm8MGqWJxNTta9PUrLNw4Jfjrye1zXQp7mXvr3NtTBLS1OcNTAyh7jD31Qx9MvBB 4F+4rH/koRGvxIBg== Date: Wed, 04 Sep 2024 15:04:56 +0200 Subject: [PATCH 06/15] timers: Update function descriptions of sleep/delay related functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-6-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , Arnd Bergmann , linux-arch@vger.kernel.org A lot of commonly used functions for inserting a sleep or delay lack a proper function description. Add function descriptions to all of them to have important information in a central place close to the code. No functional change. Cc: Arnd Bergmann Cc: linux-arch@vger.kernel.org Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki --- include/asm-generic/delay.h | 46 ++++++++++++++++++++++++++++++++++----- include/linux/delay.h | 48 ++++++++++++++++++++++++++++++---------- kernel/time/sleep_timeout.c | 53 ++++++++++++++++++++++++++++++++++++++++-= ---- 3 files changed, 123 insertions(+), 24 deletions(-) diff --git a/include/asm-generic/delay.h b/include/asm-generic/delay.h index e448ac61430c..76531ea7597a 100644 --- a/include/asm-generic/delay.h +++ b/include/asm-generic/delay.h @@ -11,12 +11,37 @@ extern void __ndelay(unsigned long nsecs); extern void __const_udelay(unsigned long xloops); extern void __delay(unsigned long loops); =20 -/* - * The weird n/20000 thing suppresses a "comparison is always false due to - * limited range of data type" warning with non-const 8-bit arguments. +/** + * udelay - Inserting a delay based on microseconds with busy waiting + * @n: requested delay in microseconds + * + * When delaying in an atomic context ndelay(), udelay() and mdelay() are = the + * only valid variants of delaying/sleeping to go with. + * + * When inserting delays in non atomic context which are shorter than the = time + * which is required to queue e.g. an hrtimer and to enter then the schedu= ler, + * it is also valuable to use udelay(). But is not simple to specify a gen= eric + * threshold for this which will fit for all systems, but an approximation= would + * be a threshold for all delays up to 10 microseconds. + * + * When having a delay which is larger than the architecture specific + * %MAX_UDELAY_MS value, please make sure mdelay() is used. Otherwise a ov= erflow + * risk is given. + * + * Please note that ndelay(), udelay() and mdelay() may return early for s= everal + * reasons (https://lists.openwall.net/linux-kernel/2011/01/09/56): + * + * #. computed loops_per_jiffy too low (due to the time taken to execute t= he + * timer interrupt.) + * #. cache behaviour affecting the time it takes to execute the loop func= tion. + * #. CPU clock rate changes. + * + * Impelementation details for udelay() only: + * + * * The weird n/20000 thing suppresses a "comparison is always false due = to + * limited range of data type" warning with non-const 8-bit arguments. + * * 0x10c7 is 2**32 / 1000000 (rounded up) */ - -/* 0x10c7 is 2**32 / 1000000 (rounded up) */ #define udelay(n) \ ({ \ if (__builtin_constant_p(n)) { \ @@ -29,7 +54,16 @@ extern void __delay(unsigned long loops); } \ }) =20 -/* 0x5 is 2**32 / 1000000000 (rounded up) */ +/** + * ndelay - Inserting a delay based on nanoseconds with busy waiting + * @n: requested delay in nanoseconds + * + * See udelay() for basic information about ndelay() and it's variants. + * + * Impelmentation details for ndelay(): + * + * * 0x5 is 2**32 / 1000000000 (rounded up) + */ #define ndelay(n) \ ({ \ if (__builtin_constant_p(n)) { \ diff --git a/include/linux/delay.h b/include/linux/delay.h index 2bc586aa2068..23623fa79768 100644 --- a/include/linux/delay.h +++ b/include/linux/delay.h @@ -6,17 +6,7 @@ * Copyright (C) 1993 Linus Torvalds * * Delay routines, using a pre-computed "loops_per_jiffy" value. - * - * Please note that ndelay(), udelay() and mdelay() may return early for - * several reasons: - * 1. computed loops_per_jiffy too low (due to the time taken to - * execute the timer interrupt.) - * 2. cache behaviour affecting the time it takes to execute the - * loop function. - * 3. CPU clock rate changes. - * - * Please see this thread: - * https://lists.openwall.net/linux-kernel/2011/01/09/56 + * Sleep routines using timer list timers or hrtimers. */ =20 #include @@ -35,12 +25,21 @@ extern unsigned long loops_per_jiffy; * The 2nd mdelay() definition ensures GCC will optimize away the=20 * while loop for the common cases where n <=3D MAX_UDELAY_MS -- Paul G. */ - #ifndef MAX_UDELAY_MS #define MAX_UDELAY_MS 5 #endif =20 #ifndef mdelay +/** + * mdelay - Inserting a delay based on microseconds with busy waiting + * @n: requested delay in microseconds + * + * See udelay() for basic information about mdelay() and it's variants. + * + * Please double check, whether mdelay() is the right way to go or whether= a + * refactoring of the code is the better variant to be able to use msleep() + * instead. + */ #define mdelay(n) (\ (__builtin_constant_p(n) && (n)<=3DMAX_UDELAY_MS) ? udelay((n)*1000) : \ ({unsigned long __ms=3D(n); while (__ms--) udelay(1000);})) @@ -63,16 +62,41 @@ unsigned long msleep_interruptible(unsigned int msecs); void usleep_range_state(unsigned long min, unsigned long max, unsigned int state); =20 +/** + * usleep_range - Sleep for an approximate time + * @min: Minimum time in microseconds to sleep + * @max: Maximum time in microseconds to sleep + * + * For basic information please refere to usleep_range_state(). + * + * The task will be in the state TASK_UNINTERRUPTIBLE during the sleep. + */ static inline void usleep_range(unsigned long min, unsigned long max) { usleep_range_state(min, max, TASK_UNINTERRUPTIBLE); } =20 +/** + * usleep_range_idle - Sleep for an approximate time with idle time accoun= ting + * @min: Minimum time in microseconds to sleep + * @max: Maximum time in microseconds to sleep + * + * For basic information please refere to usleep_range_state(). + * + * The sleeping task has the state TASK_IDLE during the sleep to prevent + * contribution to the load avarage. + */ static inline void usleep_range_idle(unsigned long min, unsigned long max) { usleep_range_state(min, max, TASK_IDLE); } =20 +/** + * ssleep - wrapper for seconds arount msleep + * @seconds: Requested sleep duration in seconds + * + * Please refere to msleep() for detailed information. + */ static inline void ssleep(unsigned int seconds) { msleep(seconds * 1000); diff --git a/kernel/time/sleep_timeout.c b/kernel/time/sleep_timeout.c index 9ecbce7da537..1ebd8429a64a 100644 --- a/kernel/time/sleep_timeout.c +++ b/kernel/time/sleep_timeout.c @@ -267,7 +267,34 @@ EXPORT_SYMBOL_GPL(schedule_hrtimeout); =20 /** * msleep - sleep safely even with waitqueue interruptions - * @msecs: Time in milliseconds to sleep for + * @msecs: Requested sleep duration in milliseconds + * + * msleep() uses jiffie based timeouts for the sleep duration. The accurac= y of + * the resulting sleep duration depends on: + * + * * HZ configuration + * * sleep duration (as granularity of a bucket which collects timers incr= eases + * with the timer wheel levels) + * + * When the timer is queued into the second level of the timer wheel the m= aximum + * additional delay will be 12.5%. For explanation please check the detail= ed + * description about the basics of the timer wheel. In case this is accura= te + * enough check which sleep length is selected to make sure required accur= acy is + * given. Please use therefore the following simple steps: + * + * #. Decide which slack is fine for the requested sleep duration - but do= not + * use values shorter than 1/8 + * #. Check whether your sleep duration is equal or greater than the follo= wing + * result: ``TICK_NSEC / slack / NSEC_PER_MSEC`` + * + * Examples: + * + * * ``HZ=3D1000`` with `slack=3D1/4``: all sleep durations greater or equ= al 4ms will meet + * the constrains. + * * ``HZ=3D250`` with ``slack=3D1/4``: all sleep durations greater or equ= al 16ms will meet + * the constrains. + * + * See also the signal aware variant msleep_interruptible(). */ void msleep(unsigned int msecs) { @@ -280,7 +307,15 @@ EXPORT_SYMBOL(msleep); =20 /** * msleep_interruptible - sleep waiting for signals - * @msecs: Time in milliseconds to sleep for + * @msecs: Requested sleep duration in milliseconds + * + * See msleep() for some basic information. + * + * The difference between msleep() and msleep_interruptible() is that the = sleep + * could be interrupted by a signal delivery and then returns early. + * + * Returns the remaining time of the sleep duration transformed to msecs (= see + * schedule_timeout() for details). */ unsigned long msleep_interruptible(unsigned int msecs) { @@ -298,11 +333,17 @@ EXPORT_SYMBOL(msleep_interruptible); * @max: Maximum time in usecs to sleep * @state: State of the current task that will be while sleeping * + * usleep_range_state() sleeps at least for the minimum specified time but= not + * longer than the maximum specified amount of time. The range might reduce + * power usage by allowing hrtimers to coalesce an already scheduled inter= rupt + * with this hrtimer. In the worst case, an interrupt is scheduled for the= upper + * bound. + * + * The sleeping task is set to the specified state before starting the sle= ep. + * * In non-atomic context where the exact wakeup time is flexible, use - * usleep_range_state() instead of udelay(). The sleep improves responsiv= eness - * by avoiding the CPU-hogging busy-wait of udelay(), and the range reduces - * power usage by allowing hrtimers to take advantage of an already- - * scheduled interrupt instead of scheduling a new one just for this sleep. + * usleep_range() or its variants instead of udelay(). The sleep improves + * responsiveness by avoiding the CPU-hogging busy-wait of udelay(). */ void __sched usleep_range_state(unsigned long min, unsigned long max, unsigned int state) --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 ADF081DC1AB for ; Wed, 4 Sep 2024 13:05:37 +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=1725455139; cv=none; b=GrRyh42mDk7I1oN7GW9/tT0LqOSWufN6pGyrIUhtuLCep5ua5YxQaceUDGBvFoaJvc3rJIzqeGRX6oSAYL5PjzdCs8J3rfHlJjUT/pQbMgv6w0kDI90XfxKl8oYAz179PwAltuKdM0n9sHl1QBEDlXXc006x9beKOmAbOcaNBCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455139; c=relaxed/simple; bh=Y0mUmw49im+/GxQ7ebJqx9Ja6vnn3XngWh6DjT6xiJ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aPiCTcaV1aMRzaQaRk5jUwlzMNGzuEfjz4OPxWluXp1ODYm2n4X4j4eyy0PaHjSLtK5bb1qE6tDaanZy+CGySRivCrQjlYy+qGcOGEhORF6lGhE5I04/bMSB+c/7iTcpg2wwMm/glyru3ppeECxSuAHAOPSuuC8o76LxIpD1Q7w= 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=Nzr4EQHY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=PtBCvLOn; 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="Nzr4EQHY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="PtBCvLOn" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455135; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QzFZJPN6OCoOjFijLF5zzv1PdmAEslKaMmEzLI7TVjw=; b=Nzr4EQHYlyIMIpic/3BDET4263SCnG8oHigCRvoTDervAgGX+aK63HtpD0ngLnvVRfTlUi WK/Ar03LRiNzXTffIcBX5AA4h/3RB551yrXtCMnd6fCey1WKVbdD2IUFy3w01Rmtn3EGKq Njb77TJqkCxBhCJR64zGsD4J2+8r736BIjMHLFCQnCEg+uyoDeDT1y/HgqFtWXBTFE7JYr Ej3wMfSsBShL7dRo9r6RMcEYKknlLZsnoPegtcSLg+tTvYArR5KF2FTWLSIixan03JdxDT Dn5TGLNoHiEUmOFw66ShxDY6dW97DTXQ8piTrNLB3CPpNsduColNKJIONyVS4A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455135; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QzFZJPN6OCoOjFijLF5zzv1PdmAEslKaMmEzLI7TVjw=; b=PtBCvLOnizTzndJBtagTZ7VBAzA4O6RNpa0ih7NZnIM6jaDbMrwbJxW5KlYtO3/RMTqV/x e7EG/X0WJ44wa1BA== Date: Wed, 04 Sep 2024 15:04:57 +0200 Subject: [PATCH 07/15] timers: Adjust flseep() to reflect reality Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-7-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , Heiner Kallweit , "David S. Miller" fsleep() simply implements the recommondations of the outdated documentation in "Documentation/timers/timers-howto.rst". This should be a user friendly interface to choose always the best timeout function approach: - udelay() for very short sleep durations shorter than 10 microseconds - usleep_range() for sleep durations until 20 milliseconds - msleep() for the others The actual implementation has several problems: - It does not take into account that HZ resolution also has an impact on granularity of jiffies and has also an impact on the granularity of the buckets of timer wheel levels. This means that accuracy for the timeout does not have an upper limit. When executing fsleep(20000) on a HZ=3D100 system, the possible additional slack will be 50% as the granularity of the buckets in the lowest level is 10 milliseconds. - The upper limit of usleep_range() is twice the requested timeout. When no other interrupts occur in this range, the maximum value is used. This means that the requested sleep length has then an additional delay of 100%. Change the thresholds for the decisions in fsleep() to make sure the maximum slack which is added to the sleep duration is 25%. Note: Outdated documentation will be updated in a followup patch. Cc: Heiner Kallweit Cc: David S. Miller Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki --- include/linux/delay.h | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/include/linux/delay.h b/include/linux/delay.h index 23623fa79768..b49a63c85c43 100644 --- a/include/linux/delay.h +++ b/include/linux/delay.h @@ -11,6 +11,7 @@ =20 #include #include +#include =20 extern unsigned long loops_per_jiffy; =20 @@ -102,15 +103,35 @@ static inline void ssleep(unsigned int seconds) msleep(seconds * 1000); } =20 -/* see Documentation/timers/timers-howto.rst for the thresholds */ +static const unsigned int max_slack_shift =3D 2; +#define USLEEP_RANGE_UPPER_BOUND ((TICK_NSEC << max_slack_shift) / NSEC_PE= R_USEC) + +/** + * fsleep - flexible sleep which autoselects the best mechanism + * @usecs: requested sleep duration in microseconds + * + * flseep() selects the best mechanism that will provide maximum 25% slack + * to the requested sleep duration. Therefore it uses: + * + * * udelay() loop for sleep durations <=3D 10 microseconds to avoid hrtim= er + * overhead for really short sleep durations. + * * usleep_range() for sleep durations which would lead with the usage of + * msleep() to a slack larger than 25%. This depends on the granularity = of + * jiffies. + * * msleep() for all other sleep durations. + * + * Note: When %CONFIG_HIGH_RES_TIMERS is not set, all sleeps are processed= with + * the granularity of jiffies and the slack might exceed 25% especially for + * short sleep durations. + */ static inline void fsleep(unsigned long usecs) { if (usecs <=3D 10) udelay(usecs); - else if (usecs <=3D 20000) - usleep_range(usecs, 2 * usecs); + else if (usecs < USLEEP_RANGE_UPPER_BOUND) + usleep_range(usecs, usecs + (usecs >> max_slack_shift)); else - msleep(DIV_ROUND_UP(usecs, 1000)); + msleep(DIV_ROUND_UP(usecs, USEC_PER_MSEC)); } =20 #endif /* defined(_LINUX_DELAY_H) */ --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 EE7681DC190 for ; Wed, 4 Sep 2024 13:05:37 +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=1725455139; cv=none; b=dZ8hCtcOLQZBF6/pvLjbTG0r7NKx7AazAtXotikB+XsCoZ+S2e7oQSsCKBN1ea6+FXT+uzNKisJvOUW91q+JVIM2k/MB7B2TLmB6cLAtfihff+3yM+qvmia5QvsagJ4OJ0wMtHMo/Ywjmz1OWP7TMzgqoSJAZ0yBzTx4qMc3vKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455139; c=relaxed/simple; bh=9O92jwveh5iVzWgN1l3Cbbq7pWWFYLxcl+f0fnqDjoU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iqyKIX+TWggQoCyUrAIDYqa/eA+LVcd0bfQkZa6DuGlLeF3EN2N7/k2M61pD0C6iKtHCEJvPcLHViuvpkr+7rWhqIxyltT7kq8ldx1UERcAeM+EvgT6d8EvpoOBT6ePtExLOFWb+ET5UfpOF5l+LA4bpL/Y+IdYUL2tHAW5kcCM= 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=nE7oMldu; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JVYH5NQQ; 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="nE7oMldu"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JVYH5NQQ" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455136; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rtNvbsuelbk0+4PJUSwQ16v3Vz38xbL3/UvjLhGlwIk=; b=nE7oMldu2nWfetQ+sxMrs/59NURPzMfcqI3TaZ7BL7TGcn1MzXkvp3kTGSYEkf3siHecZV cf43vfqI50vDV/+IWPmgXM6/1Ltpv3826dY2v06JY1bYmnV1ljagxhUaItdPsDZFZJzlQc QZ3ri72YT0SMEPnvzfQEM/gGLGZBwvFWhGTpOCMjTQBVEPeEdBTKtATs7/c/bWs3ZFltaS vdWZlR6EMkkksHLeGBu1xMiYQQpeWdT86s55dmundWoar6z9Uj4ojDZKNDjmJiBGoKB/xn W96AK58tL7f3xkqd6DQZxXtFK/e1NdsdDK5Ymy+dZZ5UCC1tYePYjdPRxQTXYw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455136; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rtNvbsuelbk0+4PJUSwQ16v3Vz38xbL3/UvjLhGlwIk=; b=JVYH5NQQLMH5sMCQbT+2vpj1ZKtkXWgS5nGPCOxg/Qua+HONrSXt1Q4ONon4fpKmK1kuRX HSgSgbVT/mSS56CQ== Date: Wed, 04 Sep 2024 15:04:58 +0200 Subject: [PATCH 08/15] mm/damon/core: Use generic upper bound recommondation for usleep_range() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-8-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org The upper bound for usleep_range_idle() was taken from the outdated documentation. As a recommondation for the upper bound of usleep_range() depends on HZ configuration it is not possible to hard code it. Use the define "USLEEP_RANGE_UPPER_BOUND" instead. Cc: SeongJae Park Cc: Andrew Morton Cc: damon@lists.linux.dev Cc: linux-mm@kvack.org Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki Reviewed-by: SeongJae Park --- mm/damon/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 94fe2f1f9b0e..4b971871da75 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1883,8 +1883,7 @@ static unsigned long damos_wmark_wait_us(struct damos= *scheme) =20 static void kdamond_usleep(unsigned long usecs) { - /* See Documentation/timers/timers-howto.rst for the thresholds */ - if (usecs > 20 * USEC_PER_MSEC) + if (usecs >=3D USLEEP_RANGE_UPPER_BOUND) schedule_timeout_idle(usecs_to_jiffies(usecs)); else usleep_range_idle(usecs, usecs + 1); --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 739A81DC74D for ; Wed, 4 Sep 2024 13:05:38 +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=1725455140; cv=none; b=QY3Aq/azo+iUP3qZnD3tYtm4yETx8DHexP/Yewim5Li9m4x3J0bVP5+35xrUKdX2QkprnilKC0Vh1X53mBbAF2SRxC2XOB8l5oQsUegpWECx5S9kj4H1FOCouYFa7qd8Uye3EWmHAmP4XRf6vUCUmRRkAslKOKKZeWPMjAkePlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455140; c=relaxed/simple; bh=BkjqhbzOsTIK6A0jTcSXL5z177Nm8EkKpKlLKrux6IM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j+IZFDHzroWbOQeXJdOhYFQVCNI3GFRKiSSh2tXKWZFhn5Tg0P5mpyBeUi1eILy8LJ8hdhJ+uJtRCT4tNTYwq2tV7HVotwy9sbmlxnLjNDlkxmNJMNfWNByDZyWrTJwKj9MmNQqJCJkiMdg42KHUsl4sTdxVt5cjfZHNRKcmc08= 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=mojNKCYU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=KmKpN5yL; 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="mojNKCYU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KmKpN5yL" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455137; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9FelinSIqbGgcRPJNr21DeiIIYCh7RT2oX01854/V04=; b=mojNKCYU/DYy8ZqwXWcIS76oqTLVdKQwNiPvNi/ledLV2y6AHvaVFutmmqowQMs1uZpGTj hPFrv5V0ogmRnYNyRg8yJd2gysAxbdhGVNDxxPLX1V3um1NXf3e3JJBuAeKW/vAqUlsf8y sRMhVBsGndynT5dveLorT2AH8vTJi8PdOrBewY74w5ILf0bpo4a3hV5pZ+XLHyJtPDSaCZ lwfYwbz/IU7B1DOBUCQNwcxLR8jUfTErVdQ2n92gdI9GW6qPmsJ157VIRRfJWo0qLgPCvs TDwYC3oUdpQG1HNb8f3IqiBoc4qxsE9eOv+sYhpVMZvmBBoWeVH7gvp+QYyySw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455137; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9FelinSIqbGgcRPJNr21DeiIIYCh7RT2oX01854/V04=; b=KmKpN5yLITjGPmyVGJwksVDFKwYMeCKKXoaj8lPgkKeEW0jDDNwB4SpKAMEsCxA4UPcU2H YKO5+IYEQibT0pCA== Date: Wed, 04 Sep 2024 15:04:59 +0200 Subject: [PATCH 09/15] timers: Add a warning to usleep_range_state() for wrong order of arguments Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-9-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , Andy Whitcroft , Joe Perches There is a warning in checkpatch script that triggers, when min and max arguments of usleep_range_state() are in reverse order. This check does only cover callsites which uses constants. Move this check into the code as a WARN_ON_ONCE() to also cover callsites not using constants and get rid of it in checkpatch. Cc: Andy Whitcroft Cc: Joe Perches Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki --- kernel/time/sleep_timeout.c | 2 ++ scripts/checkpatch.pl | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/time/sleep_timeout.c b/kernel/time/sleep_timeout.c index 1ebd8429a64a..e028e9b4b113 100644 --- a/kernel/time/sleep_timeout.c +++ b/kernel/time/sleep_timeout.c @@ -351,6 +351,8 @@ void __sched usleep_range_state(unsigned long min, unsi= gned long max, ktime_t exp =3D ktime_add_us(ktime_get(), min); u64 delta =3D (u64)(max - min) * NSEC_PER_USEC; =20 + WARN_ON_ONCE(max < min); + for (;;) { __set_current_state(state); /* Do not return before the requested sleep time has elapsed */ diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 39032224d504..ba3359bdd1fa 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -7088,10 +7088,6 @@ sub process { if ($min eq $max) { WARN("USLEEP_RANGE", "usleep_range should not use min =3D=3D max args; see Documentati= on/timers/timers-howto.rst\n" . "$here\n$stat\n"); - } elsif ($min =3D~ /^\d+$/ && $max =3D~ /^\d+$/ && - $min > $max) { - WARN("USLEEP_RANGE", - "usleep_range args reversed, use min then max; see Documentation/= timers/timers-howto.rst\n" . "$here\n$stat\n"); } } =20 --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 D79D11DCB1A for ; Wed, 4 Sep 2024 13:05:39 +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=1725455141; cv=none; b=QPSUM8WE8EEWut1Z55N/e5ocXhsffbn4AsJPslzc28EvK7je4rF5jDiSo+mgEtr4qBScII0KTk+JIBSw6D0Q5IovvRg7P6PXqYDz8cpDy/tDbRlsS2jbjI3u4iiVNE+ZM3AZypqHhBnEOVunkVoAkc+7XNwHXnoCwqc+npga8c0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455141; c=relaxed/simple; bh=jj7sdFDyKXAj1zaKWm870qpEcJ4teMl2gx7a6e3vtT0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nidFngNa0PIi9V/qn8Yz62AIv/cRnF/UvySKhsteHfDqr6+HgR7zOw71rHZF+JH/HVhpwSgkamlHjUDufaAXziaTmclNY98I+SYiW9hIjwqchprY9ifXzyLFF2vRuL+BXiLEbXakbNSs0Q5wzhK4EKtEDMq8e/uYnEAfVJrhfi0= 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=MQMEHC9u; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IOTUgeRj; 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="MQMEHC9u"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IOTUgeRj" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455137; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3hfd1PxbozLQzK7m8fWFTIzSCte8OkQB0IfjqNg3wQU=; b=MQMEHC9uCgO9Bu8eRUkgM1VzwCAACJRoARdehKzGkOywApNjtMFfd8yrdI3lK64hW5PGOZ vB0ot85XSEBikxeByrtltiqb/ZSci+9cNVYrfVLOXZ/AGB/x1uqJJGRR3dDfRlOplT8wfx ZxWE4wa6CvTJxtdwaBWYDQlXTD6RP+Q1rgJNRtf+xPqUVZZomPgJqx/mXfT2vhvZEMDbzI gpxRHmdmkalyokVeEclc/mo8/M9u3T69yAEFcTin4gWBWBhK6+yvkrvNFX1SgWjiU6MGDN vGG5aoLJBPZUSJ1uMWdEvwQKo/ecrOsCxtpn5FyIN+nIyXvGCNmF4zHoB4xkcw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455137; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3hfd1PxbozLQzK7m8fWFTIzSCte8OkQB0IfjqNg3wQU=; b=IOTUgeRjgq0Isv5szLcOo/E7OM5kxEXgCJ1hzVrV7fBBu1PVtxCT2Ebl5K+Ce1CddlP0aC e5wmO2jK1/NonsAw== Date: Wed, 04 Sep 2024 15:05:00 +0200 Subject: [PATCH 10/15] checkpatch: Remove broken sleep/delay related checks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-10-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , Andy Whitcroft , Joe Perches , Dwaipayan Ray checkpatch.pl checks for several things related to sleep and delay functions. In all warnings the outdated documentation is referenced. All broken parts are listed one by one in the following with an explanation why this check is broken. For a basic background of those functions please also refere to the updated function descriptions of udelay(), nsleep_range() and msleep(). Be aware: The change is done with a perl knowledge of the level "I'm able to spell perl". The following checks are broken: - Check: (! ($delay < 10) ) Message: "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst\n" Why is the check broken: When it is an atomic context, udelay() is mandatory. - Check: ($min eq $max) Message: "usleep_range should not use min =3D=3D max args; see Documentation/timers/timers-howto.rst\n" Why is the check broken: When the requested accuracy for the sleep duration requires it, it is also valid to use min =3D=3D max. - Check: ($delay > 2000) Message: "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" Why is the check broken: The threshold when to start using mdelay() to prevent an overflow depends on MAX_UDELAY_MS. This value is architecture dependent. The used value for the check and reference is arm specific. Generic would be 5ms, but this would "break" arm, loongarch and mips and also the arm value might "break" mips and loongarch in some configurations. - Check: ($1 < 20) Message: "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst\n" Why is the check broken: The message is simply wrong. msleep() will not sleep (and never did it before) for at least 20ms. This threshold cannot be hard coded as it depends on the required accuracy and also on HZ (jiffie granularity and timer wheel bucket/level granularity). See msleep() and also the USLEEP_RANGE_UPPER_BOUND value. Remove all broken checks. Remove also no longer required checkpatch documentation section about USLEEP_RANGE. Cc: Andy Whitcroft Cc: Joe Perches Cc: Dwaipayan Ray Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki --- Documentation/dev-tools/checkpatch.rst | 6 ------ scripts/checkpatch.pl | 34 ------------------------------= ---- 2 files changed, 40 deletions(-) diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-too= ls/checkpatch.rst index a9fac978a525..f5c27be9e673 100644 --- a/Documentation/dev-tools/checkpatch.rst +++ b/Documentation/dev-tools/checkpatch.rst @@ -466,12 +466,6 @@ API usage **UAPI_INCLUDE** No #include statements in include/uapi should use a uapi/ path. =20 - **USLEEP_RANGE** - usleep_range() should be preferred over udelay(). The proper way of - using usleep_range() is mentioned in the kernel docs. - - See: https://www.kernel.org/doc/html/latest/timers/timers-howto.html#d= elays-information-on-the-various-kernel-delay-sleep-mechanisms - =20 Comments -------- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ba3359bdd1fa..80497da4aaac 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6601,28 +6601,6 @@ sub process { } } =20 -# prefer usleep_range over udelay - if ($line =3D~ /\budelay\s*\(\s*(\d+)\s*\)/) { - my $delay =3D $1; - # ignore udelay's < 10, however - if (! ($delay < 10) ) { - CHK("USLEEP_RANGE", - "usleep_range is preferred over udelay; see Documentation/timers/t= imers-howto.rst\n" . $herecurr); - } - if ($delay > 2000) { - WARN("LONG_UDELAY", - "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n"= . $herecurr); - } - } - -# warn about unexpectedly long msleep's - if ($line =3D~ /\bmsleep\s*\((\d+)\);/) { - if ($1 < 20) { - WARN("MSLEEP", - "msleep < 20ms can sleep for up to 20ms; see Documentation/timers= /timers-howto.rst\n" . $herecurr); - } - } - # check for comparisons of jiffies if ($line =3D~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) { WARN("JIFFIES_COMPARISON", @@ -7079,18 +7057,6 @@ sub process { } } =20 -# check usleep_range arguments - if ($perl_version_ok && - defined $stat && - $stat =3D~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncA= rg)\s*\)/) { - my $min =3D $1; - my $max =3D $7; - if ($min eq $max) { - WARN("USLEEP_RANGE", - "usleep_range should not use min =3D=3D max args; see Documentati= on/timers/timers-howto.rst\n" . "$here\n$stat\n"); - } - } - # check for naked sscanf if ($perl_version_ok && defined $stat && --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 D797B1DCB15 for ; Wed, 4 Sep 2024 13:05:39 +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=1725455141; cv=none; b=elwRLXwgSvjSELZ41caGJHUEIdSC/vWejkPBbcTTfD6psh2Yd8ot8mRAubqah/yeZWwW5zdO4e39GV7fWxgzbiistX1KW5jsAYn140H3UvOPWnuZQIY9jNqOd3iCGS37dN7ldtc4JhEntRAWUv3Sq2X+UXJGH93vTWCS5QdCQ2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455141; c=relaxed/simple; bh=K0E05+A2SNEqI/Ye/Bk6h3XXJnoT8Rxi+IG0Ye2aWTQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HaVSMWDM6/UkDpLYAKACbsCENXTxmEPu7XerbukjdaskyrVlYkH7EJU9FJw9Oz6Kn7WARAJ6lTrwO7ZdFRQ/IK+a4os+skIBWrLgYefRhdBw57U87fIXGP8LsFKXpQbXTSIfUU8slubBWbH+3/AgFpEVHDfp4HjDDUEN8EhwO3I= 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=ZnF669/c; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jePl3NGH; 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="ZnF669/c"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jePl3NGH" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455138; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aApgCIlZz9jOhCumewDeDaW+t/dUKkzZt/+qsZgyD3A=; b=ZnF669/ctay0aFqM0brRNubYaI85tzRZGJQtu9C2TpH0ZlmeNX2gGgypczjUuRanXD0aiP eiMf0kK3GUdMbG8x3KqxMcQJbiAH7OiSke0Z+PEGYtEcZzXxrbxHUe+euHSdPrlh5slrbg /lwBR4ni9UiFMNfdCaf7n6sLyIUMR4Q/Zl7cUo2/F+06YyNTfQq561Kcmq5XUD993J2ps2 LPoIl9OX2MhH/ZFxDC3EPO9RTsifMbTp0z5hwIoHinLtq6MaoKn3HrNauLzWyawLAaDmc9 rHK1+V5n7wlyMaHTxBSC39CW81j12r5/0rW5T0F+YS4+OHxfosTH9NKO/cXFJQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455138; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aApgCIlZz9jOhCumewDeDaW+t/dUKkzZt/+qsZgyD3A=; b=jePl3NGHbBDlFRmMVCMzgtXc3o3ilipvEHPrRIWLdwA1QgMQrkaGfUI+l+ihlSzIYrwath BcrEZCP8ntWSWnAQ== Date: Wed, 04 Sep 2024 15:05:01 +0200 Subject: [PATCH 11/15] regulator: core: Use fsleep() to get best sleep mechanism Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-11-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , Liam Girdwood , Mark Brown _regulator_delay_helper() implements the recommondation of the outdated documentation which sleep mechanism should be used. There is already a function in place which does everything and also maps to reality called fsleep(). Use fsleep() to choose the best mechanism. Cc: Liam Girdwood Cc: Mark Brown Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki --- drivers/regulator/core.c | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 7674b7f2df14..155c3e3ab3f1 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2671,39 +2671,14 @@ static int regulator_ena_gpio_ctrl(struct regulator= _dev *rdev, bool enable) * _regulator_delay_helper - a delay helper function * @delay: time to delay in microseconds * - * Delay for the requested amount of time as per the guidelines in: + * For details please refere to fsleep() function description. * - * Documentation/timers/timers-howto.rst - * - * The assumption here is that these regulator operations will never used = in + * The assumption here is that these regulator operations are never used in * atomic context and therefore sleeping functions can be used. */ -static void _regulator_delay_helper(unsigned int delay) +static inline void _regulator_delay_helper(unsigned int delay) { - unsigned int ms =3D delay / 1000; - unsigned int us =3D delay % 1000; - - if (ms > 0) { - /* - * For small enough values, handle super-millisecond - * delays in the usleep_range() call below. - */ - if (ms < 20) - us +=3D ms * 1000; - else - msleep(ms); - } - - /* - * Give the scheduler some room to coalesce with any other - * wakeup sources. For delays shorter than 10 us, don't even - * bother setting up high-resolution timers and just busy- - * loop. - */ - if (us >=3D 10) - usleep_range(us, us + 100); - else - udelay(us); + fsleep(delay); } =20 /** --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 CF1501DEFC8; Wed, 4 Sep 2024 13:05:40 +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=1725455143; cv=none; b=iW7+y2pBTeRe30Nf6cmaB276uuWj2lOOTdEvxm4cE/cZbZsqESDR5PDevcdeyZYm4DRnXaLaEtuRp/zhfFYs0PXFGz31JnN8YKy47X/C2nSYoZlgLaOoiQJojVTn1llksRn328VHI82gIMaF7XIwhx3wG7x9fpbk76iIROJmKec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455143; c=relaxed/simple; bh=53Qu+mZNVA9LMP8wt82pryIqg4R9IHgNbSfzDTdUPnA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZFMaIG1l69F0cHnxxpCrJTbWHdJNHs7kb0qUmFO/DP9EyNZKRPJDOhG4T2WNfxMkq5CHIoH5hGsZJ40zP+awqeYkPn28EbpsNe2r5+79TrlwNMiun0DznrQWSxzNw3dfehT6y9eAlqfOhMACNtGAlujOPgsW4FFOGUb+Lv+rxig= 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=oId6Xyqh; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2tGGhiio; 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="oId6Xyqh"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2tGGhiio" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455139; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NqwpnyrFg1QVhhfFvZbjd8GTWo9T8rGMAEt4kbVzwz0=; b=oId6Xyqhb8BluxKsbA0UFv/950t0HHUh/umBvqRT+nOdHNOAur5soDP/4o7RWyxytl5NDR 05UqOskqpDWKhM90PHGdBcqs+0TYi6L8ORwn72i3k2GhBZ5eszJhcUngx9Cype6aUKbM6c Um7YDXtXIQaEZstBsiTAVYL6ArKTrN9kq0WuR4EQUT0abkPBlcYidD+reP2TDk5ALMPSXq ljYJPERFx9cB/fAex4V7q+AtP0NHVmQWzc1X1U5G57zeBxs1z6EhcCdedMhaU41It5dtZ5 fFp8mVsAltx8iF75PjHyEHnBpYdeHKsegfFXUP7IbX7aET/d9pU8qBsmKzvcug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455139; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NqwpnyrFg1QVhhfFvZbjd8GTWo9T8rGMAEt4kbVzwz0=; b=2tGGhiioz16mddKFwGZakFHH3N7/jCHrLmVZNKi8ysTMdO2Gx2JZyV0QsZ33lb201KlSlc jZDOpCyx8ANn2hAg== Date: Wed, 04 Sep 2024 15:05:02 +0200 Subject: [PATCH 12/15] iopoll/regmap/phy/snd: Fix comment referencing outdated timer documentation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-12-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , Andrew Lunn , Heiner Kallweit , Jaroslav Kysela , Takashi Iwai , netdev@vger.kernel.org, linux-sound@vger.kernel.org Function descriptions in iopoll.h, regmap.h, phy.h and sound/soc/sof/ops.h copied all the same outdated documentation about sleep/delay function limitations. In those comments, the generic (and still outdated) timer documentation file is referenced. As proper function descriptions for used delay and sleep functions are in place, simply update the descriptions to reference to them. Cc: Andrew Lunn Cc: Heiner Kallweit Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: netdev@vger.kernel.org Cc: linux-sound@vger.kernel.org Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki Reviewed-by: Andrew Lunn --- include/linux/iopoll.h | 24 ++++++++++++------------ include/linux/phy.h | 7 ++++--- include/linux/regmap.h | 18 +++++++++--------- sound/soc/sof/ops.h | 6 +++--- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index 19a7b00baff4..34b52ab2e394 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -19,9 +19,9 @@ * @op: accessor function (takes @args as its arguments) * @val: Variable to read the value into * @cond: Break condition (usually involving @val) - * @sleep_us: Maximum time to sleep between reads in us (0 - * tight-loops). Should be less than ~20ms since usleep_range - * is used (see Documentation/timers/timers-howto.rst). + * @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). P= lease + * read usleep_range() function description for details and + * limitations. * @timeout_us: Timeout in us, 0 means never timeout * @sleep_before_read: if it is true, sleep @sleep_us before read. * @args: arguments for @op poll @@ -64,9 +64,9 @@ * @op: accessor function (takes @args as its arguments) * @val: Variable to read the value into * @cond: Break condition (usually involving @val) - * @delay_us: Time to udelay between reads in us (0 tight-loops). Should - * be less than ~10us since udelay is used (see - * Documentation/timers/timers-howto.rst). + * @delay_us: Time to udelay between reads in us (0 tight-loops). Please + * read udelay() function description for details and + * limitations. * @timeout_us: Timeout in us, 0 means never timeout * @delay_before_read: if it is true, delay @delay_us before read. * @args: arguments for @op poll @@ -119,9 +119,9 @@ * @addr: Address to poll * @val: Variable to read the value into * @cond: Break condition (usually involving @val) - * @sleep_us: Maximum time to sleep between reads in us (0 - * tight-loops). Should be less than ~20ms since usleep_range - * is used (see Documentation/timers/timers-howto.rst). + * @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). P= lease + * read usleep_range() function description for details and + * limitations. * @timeout_us: Timeout in us, 0 means never timeout * * Returns 0 on success and -ETIMEDOUT upon a timeout. In either @@ -140,9 +140,9 @@ * @addr: Address to poll * @val: Variable to read the value into * @cond: Break condition (usually involving @val) - * @delay_us: Time to udelay between reads in us (0 tight-loops). Should - * be less than ~10us since udelay is used (see - * Documentation/timers/timers-howto.rst). + * @delay_us: Time to udelay between reads in us (0 tight-loops). Please + * read udelay() function description for details and + * limitations. * @timeout_us: Timeout in us, 0 means never timeout * * Returns 0 on success and -ETIMEDOUT upon a timeout. In either diff --git a/include/linux/phy.h b/include/linux/phy.h index 6b7d40d49129..b09490e08365 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1374,11 +1374,12 @@ int phy_read_mmd(struct phy_device *phydev, int dev= ad, u32 regnum); * @regnum: The register on the MMD to read * @val: Variable to read the register into * @cond: Break condition (usually involving @val) - * @sleep_us: Maximum time to sleep between reads in us (0 - * tight-loops). Should be less than ~20ms since usleep_range - * is used (see Documentation/timers/timers-howto.rst). + * @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). P= lease + * read usleep_range() function description for details and + * limitations. * @timeout_us: Timeout in us, 0 means never timeout * @sleep_before_read: if it is true, sleep @sleep_us before read. + * * Returns 0 on success and -ETIMEDOUT upon a timeout. In either * case, the last read value at @args is stored in @val. Must not * be called from atomic context if sleep_us or timeout_us are used. diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 122e38161acb..85de129a9e02 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -106,9 +106,9 @@ struct reg_sequence { * @addr: Address to poll * @val: Unsigned integer variable to read the value into * @cond: Break condition (usually involving @val) - * @sleep_us: Maximum time to sleep between reads in us (0 - * tight-loops). Should be less than ~20ms since usleep_range - * is used (see Documentation/timers/timers-howto.rst). + * @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). P= lease + * read usleep_range() function description for details and + * limitations. * @timeout_us: Timeout in us, 0 means never timeout * * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read @@ -133,9 +133,9 @@ struct reg_sequence { * @addr: Address to poll * @val: Unsigned integer variable to read the value into * @cond: Break condition (usually involving @val) - * @delay_us: Time to udelay between reads in us (0 tight-loops). - * Should be less than ~10us since udelay is used - * (see Documentation/timers/timers-howto.rst). + * @delay_us: Time to udelay between reads in us (0 tight-loops). Please + * read udelay() function description for details and + * limitations. * @timeout_us: Timeout in us, 0 means never timeout * * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read @@ -177,9 +177,9 @@ struct reg_sequence { * @field: Regmap field to read from * @val: Unsigned integer variable to read the value into * @cond: Break condition (usually involving @val) - * @sleep_us: Maximum time to sleep between reads in us (0 - * tight-loops). Should be less than ~20ms since usleep_range - * is used (see Documentation/timers/timers-howto.rst). + * @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). P= lease + * read usleep_range() function description for details and + * limitations. * @timeout_us: Timeout in us, 0 means never timeout * * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_= read diff --git a/sound/soc/sof/ops.h b/sound/soc/sof/ops.h index 2584621c3b2d..b1b8253aefad 100644 --- a/sound/soc/sof/ops.h +++ b/sound/soc/sof/ops.h @@ -597,9 +597,9 @@ snd_sof_is_chain_dma_supported(struct snd_sof_dev *sdev= , u32 dai_type) * @addr: Address to poll * @val: Variable to read the value into * @cond: Break condition (usually involving @val) - * @sleep_us: Maximum time to sleep between reads in us (0 - * tight-loops). Should be less than ~20ms since usleep_range - * is used (see Documentation/timers/timers-howto.rst). + * @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). P= lease + * read usleep_range() function description for details and + * limitations. * @timeout_us: Timeout in us, 0 means never timeout * * Returns 0 on success and -ETIMEDOUT upon a timeout. In either --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 5E88E1DEFDD for ; Wed, 4 Sep 2024 13:05:41 +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=1725455143; cv=none; b=ZjC5w01JdBsJmMDByf9t6Jhm7Psy27pHzXHpinf3NjUp02yiEPRvxWJZneh3AMt3ex0GZmvRX3Kq+vrSE/9W+ZjMrs0yH2UDHnnDLlX9580SZ+nA9pNxkiwjVR8Xgo6cxL+uVxDttu6a34+2PuPqsvjB6Z+dzb/5B9CD2S9lUgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455143; c=relaxed/simple; bh=8qQChXqfhyyyzG47FL8wei2jgAz4j1vTLzxX5e0laqM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JZYGPd2fH+VCFLXhWi2YulDTVj2m9hphhH7VsACxI4FyXm/oJCKTmDHRJnSkX0LHcxaH3d28gErN1RfP0RpqADimWYcfLV/zBMxnPFYg0TgCFFkwsgiQU5YMKl/uNX4xrBSXCzqFJlo4rH8TcWtWFYwy+Sj+IV6o51jVqQbXE6g= 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=z4P3q5Oy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=eF3O2ZUl; 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="z4P3q5Oy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="eF3O2ZUl" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455139; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w1hgFVgMLZ521/p+E0dyRVQl2rbyAAPZ0ir+q/NjJSQ=; b=z4P3q5OyzPM2OPXYhZTZDs8f4jcuLXx0cBv0nAd6tj54uuDk226NFzqzGYYv+cEf0yNFBv 2yhEQ5zKBeqeI5WD6+FlldipAPRUQP1Tmuov+v3qNMInz2MxJ459rZB+gmeNHDywYlsJT8 9XV+cy/iLbLzw/cls81OoMpxQog7EZK0iwd9G8h7Rm38JJwMa028TjJbIpOStnZg1QEDjo UzOoayLQcd8JfBUUPQNFdeFMgkjaiE1ibKLtRbUxKtDvMJIKv1HXyldBidorvuDun5piZd DFE0s/9jqzZQqXHkluJ2HLAgz3rW0R519TeZ1t6lFHKo9US3BOcDTNRKRtaWpw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455139; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w1hgFVgMLZ521/p+E0dyRVQl2rbyAAPZ0ir+q/NjJSQ=; b=eF3O2ZUlBaIyY4KkXmRltcDq2SpPujm++XqPS46DXxIeh832EzE2Ujm17IhwcLC8u0Sq7Q 4OVnhvqKgszJr8Aw== Date: Wed, 04 Sep 2024 15:05:03 +0200 Subject: [PATCH 13/15] powerpc/rtas: Use fsleep() to minimize additional sleep duration Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-13-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , Michael Ellerman , Nathan Lynch , linuxppc-dev@lists.ozlabs.org When commit 38f7b7067dae ("powerpc/rtas: rtas_busy_delay() improvements") was introduced, documentation about proper usage of sleep realted functions was outdated. The commit message references the usage of a HZ=3D100 system. When using a 20ms sleep duration on such a system and therefore using msleep(), the possible additional slack will be +10ms. When the system is configured with HZ=3D100 the granularity of a jiffy and = of a bucket of the lowest timer wheel level is 10ms. To make sure a timer will not expire early (when queueing of the timer races with an concurrent update of jiffies), timers are always queued into the next bucket. This is the reason for the maximal possible slack of 10ms. fsleep() limits the maximal possible slack to 25% by making threshold between usleep_range() and msleep() HZ dependent. As soon as the accuracy of msleep() is sufficient, the less expensive timer list timer based sleeping function is used instead of the more expensive hrtimer based usleep_range() function. The udelay() will not be used in this specific usecase as the lowest sleep length is larger than 1 microsecond. Use fsleep() directly instead of using an own heuristic for the best sleeping mechanism to use.. Cc: Michael Ellerman Cc: Nathan Lynch Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Anna-Maria Behnsen Acked-by: Michael Ellerman (powerpc) Acked-by: Rafael J. Wysocki --- arch/powerpc/kernel/rtas.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c index f7e86e09c49f..0794ca28e51e 100644 --- a/arch/powerpc/kernel/rtas.c +++ b/arch/powerpc/kernel/rtas.c @@ -1390,21 +1390,14 @@ bool __ref rtas_busy_delay(int status) */ ms =3D clamp(ms, 1U, 1000U); /* - * The delay hint is an order-of-magnitude suggestion, not - * a minimum. It is fine, possibly even advantageous, for - * us to pause for less time than hinted. For small values, - * use usleep_range() to ensure we don't sleep much longer - * than actually needed. - * - * See Documentation/timers/timers-howto.rst for - * explanation of the threshold used here. In effect we use - * usleep_range() for 9900 and 9901, msleep() for - * 9902-9905. + * The delay hint is an order-of-magnitude suggestion, not a + * minimum. It is fine, possibly even advantageous, for us to + * pause for less time than hinted. To make sure pause time will + * not be a way longer than requested independent of HZ + * configuration, use fsleep(). See fsleep() for detailes of + * used sleeping functions. */ - if (ms <=3D 20) - usleep_range(ms * 100, ms * 1000); - else - msleep(ms); + fsleep(ms * 1000); break; case RTAS_BUSY: ret =3D true; --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 A1FF01DEFEC; Wed, 4 Sep 2024 13:05:41 +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=1725455143; cv=none; b=EWrmWYSBnbpK0Q0QqxWqVjHN6Q07BsJI8cnYzcPytQ/DS75T019ZS97CNwzKc8v4Ps23GWJjl/a1wwnYYaZO61JVCAjRxNAQVLnVUY7owvh6TUTfOMS2i6gZM2tyur6YPalFWAHPrwHRvybTxxuaWq8qIYTn5a7FZCjBVf0Gjss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455143; c=relaxed/simple; bh=75n5UjPAswXizo2Gb+4Lf6s8hs9mh1+0oQvxojBGbbE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BJ2DZUvYpPUg2mVShg8fO9AcSKMnLyk3ao83HwAQLVnm+aLCrNEPHr5GCX5CQKn/i4kIc+PeBIJGOKxG6GyhhDcUxY6tm/VDHzT6SdwJ6BhiaT8j0vw+nEY66G/x91+apnjlm6X0O0UVqslBM2UC05+651k8uOB14fKpEnsuVPc= 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=CWxjpdZL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hQANh9H6; 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="CWxjpdZL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hQANh9H6" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455140; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v75l3ZYBbsP13asMW41FuZtAe9X+N+Ak4ZgbeSG9nK0=; b=CWxjpdZLIOTspIObzG4iJxNM1u6C5T2ZQHrYiEW4rEVJ2nRtzHsmkJKANPcWovynGNYgvK x7AGUwZNcEgDYR5mbJw7AZnvpGSUbr9a5tvZerpejqcBt/9lpHoR86Vf1h0TWg9xBGUM/O kzcIldoL+r5zBT5mxcMvOe3dDyMsIxip8si/4aD4sj2GinjQRIbl/rBkl9Iltpq0v6OO26 2z5rZjIrEAyoTbRR1omxrIB1bG4Xs5N+q/0c9pVdtlJy0XbN0uFamrHGGPrIXyRffYQopl 6p0OJTW6LgZlGiwXTBa7AQJ4XU3X6u9flbUsM9ke5y0uRqJhI7MlMciGXIY8PQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455140; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v75l3ZYBbsP13asMW41FuZtAe9X+N+Ak4ZgbeSG9nK0=; b=hQANh9H6c9Jq9dDBCOAPDvB9UG3LUe7NZt9kLCYAREhOvWyAXlYDgIeM/lWhPE0EuSN/yd oL9cx2u9+QrrDJDg== Date: Wed, 04 Sep 2024 15:05:04 +0200 Subject: [PATCH 14/15] media: anysee: Fix link to outdated sleep function documentation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-14-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen , Mauro Carvalho Chehab , linux-media@vger.kernel.org The TODO FIXME comment references the outdated lower limit for msleep() function of 20ms. As this is not right and the proper documentation of msleep() is now part of the function description, remove the old stuff and point to the up to date documentation. Cc: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki --- drivers/media/usb/dvb-usb-v2/anysee.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/dvb-usb-v2/anysee.c b/drivers/media/usb/dvb-= usb-v2/anysee.c index 8699846eb416..b2f5db961245 100644 --- a/drivers/media/usb/dvb-usb-v2/anysee.c +++ b/drivers/media/usb/dvb-usb-v2/anysee.c @@ -55,10 +55,8 @@ static int anysee_ctrl_msg(struct dvb_usb_device *d, =20 /* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32 * (EPIPE, Broken pipe). Function supports currently msleep() as a - * parameter but I would not like to use it, since according to - * Documentation/timers/timers-howto.rst it should not be used such - * short, under < 20ms, sleeps. Repeating failed message would be - * better choice as not to add unwanted delays... + * parameter. Check msleep() for details. Repeating failed message would + * be better choice as not to add unwanted delays... * Fixing that correctly is one of those or both; * 1) use repeat if possible * 2) add suitable delay --=20 2.39.2 From nobody Fri Dec 19 15:19:52 2025 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 5A7FC1DFE0F for ; Wed, 4 Sep 2024 13:05:42 +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=1725455144; cv=none; b=MSOrTIvaXIo+dXseZhGvmf1QTUiUCMlP4nI7Zv7aPEsByh0Wcwwg8TnRgPhihxCd9sQ6n+rFftDI7+3/u3YlsF2UpQVmixM4Y16wAGLJiM/8fHWIS838Hy5O6/VpAWGWZfrLshc1V3xYLF8NPVfiWL13P36fvsxSIUhlvS+CP2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725455144; c=relaxed/simple; bh=MnkTO+SoXn9ALpaHKD0yv6agPOoMrHkkYtt8oXOQSeI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RAQBKSUQPZBz9NHbMVF6ollC9Sxdovlfw5PGDpNOGV/5Wzq1RwjAdbQMmucqk0SdwojXQQx2VU1Y3iZg316WiZnCHo9FTNVwG9MRZJwHVtSWusVbCevMJEL9Uh5mRbtUs/Dogn2EhWXS6n3XI4JVexIaRvWAMrGTpOhZ3l9bAbw= 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=RnDuoUNC; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tv5aATDo; 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="RnDuoUNC"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tv5aATDo" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725455140; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vaCS8Wy4nmdabahzumttPewmZzyJlsqugb8Ai6FeVCc=; b=RnDuoUNC1qnfSLHxaZjrP1s54UbHEGEfFQ+Ae8H4Jr9k/DcbAmZDB7YqnpXvwUeDi9DIRo /ljYnwY5w2LwDnw7aDxutw1rhGyAIK00eHJLq5jx7n+I+S6McC2gwi+0429OI0E+eVzdyp +qYQymg8i2+GZ5kyZjUsoJurpVmGDOfRTkE+IExuolVyEh/U/sSZHq5wrRtH6+810yS1kJ lg9++TjW1rWKKKvHF/veqOVMTT6u3wtu5KmthS4Twd71ZvxU8CZC6QKO031k0yIbTbHY8L esyUqK/WvKobBSo9ueFdAPz3O4U07LwrpodppJnhh0S9NGvW/cCbl30B1mqmTg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725455140; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vaCS8Wy4nmdabahzumttPewmZzyJlsqugb8Ai6FeVCc=; b=tv5aATDot9gdwZmFekQEaNMeLadVkLZCKDFHuZuHtX2v2cFZJJzwRGiCPt5CfgCtuzPq/g 0XB+D9u08+x+bOBg== Date: Wed, 04 Sep 2024 15:05:05 +0200 Subject: [PATCH 15/15] timers/Documentation: Cleanup delay/sleep documentation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240904-devel-anna-maria-b4-timers-flseep-v1-15-e98760256370@linutronix.de> References: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> In-Reply-To: <20240904-devel-anna-maria-b4-timers-flseep-v1-0-e98760256370@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , Anna-Maria Behnsen The documentation which tries to give advises how to properly inserting delays or sleeps is outdated. The file name is 'timers-howto.rst' which might be missleading as it is only about delay and sleep mechanisms and not how to use timers. Update the documentation by integrating the important parts from the related function descriptions and move it all into a self explaining file with the name "delay_sleep_functions.rst". Signed-off-by: Anna-Maria Behnsen Acked-by: Rafael J. Wysocki --- Documentation/timers/delay_sleep_functions.rst | 122 +++++++++++++++++++++= ++++ Documentation/timers/index.rst | 2 +- Documentation/timers/timers-howto.rst | 115 ---------------------= -- 3 files changed, 123 insertions(+), 116 deletions(-) diff --git a/Documentation/timers/delay_sleep_functions.rst b/Documentation= /timers/delay_sleep_functions.rst new file mode 100644 index 000000000000..05d7c3c8fbe8 --- /dev/null +++ b/Documentation/timers/delay_sleep_functions.rst @@ -0,0 +1,122 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Delay and sleep mechanisms +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + +This document seeks to answer the common question: "What is the +RightWay (TM) to insert a delay?" + +This question is most often faced by driver writers who have to +deal with hardware delays and who may not be the most intimately +familiar with the inner workings of the Linux Kernel. + +The following table gives a rough overview about the existing function +'families' and their limitations. This overview table does not replace the +reading of the function description before usage! + +.. list-table:: + :widths: 20 20 20 20 20 + :header-rows: 2 + + * - + - `*delay()` + - `usleep_range*()` + - `*sleep()` + - `fsleep()` + * - + - busy-wait loop + - hrtimers based + - timer list timers based + - combines the others + * - Usage in atomic Context + - yes + - no + - no + - no + * - precise on "short intervals" + - yes + - yes + - depends + - yes + * - precise on "long intervals" + - Do not use! + - yes + - max 12.5% slack + - yes + * - interruptible variant + - no + - yes + - yes + - no + +A generic advice for non atomic contexts could be: + +#. Use `fsleep()` whenever unsure (as it combines all the advantages of the + others) +#. Use `*sleep()` whenever possible +#. Use `usleep_range*()` whenever accuracy of `*sleep()` is not sufficient +#. Use `*delay()` for very, very short delays + +Find some more detailed information about the function 'families' in the n= ext +sections. + +`*delay()` family of functions +------------------------------ + +These functions use the jiffy estimation of clock speed and will busy wait= for +enough loop cycles to achieve the desired delay. udelay() is the basic +implementation and ndelay() as well as mdelay() are variants. + +These functions are mainly used to add a delay in atomic context. Please m= ake +sure to ask yourself before adding a delay in atomic context: Is this real= ly +required? + +.. kernel-doc:: include/asm-generic/delay.h + :identifiers: udelay ndelay + +.. kernel-doc:: include/linux/delay.h + :identifiers: mdelay + + +`usleep_range*()` and `*sleep()` family of functions +---------------------------------------------------- + +These functions uses hrtimers or timer list timers to provide the requested +sleeping duration. For a decision which function is the right one to use, = take +some basic information into account: + +#. hrtimers are more expensive as they are using an rb-tree (instead of ha= shing) +#. hrtimers are more expensive when the requested sleeping duration is the= first + timer which means real hardware has to be programmed +#. timer list timers always providing some sort of slack as they are jiffy + based + +The generic advice is repeated here: + +#. Use `fsleep()` whenever unsure (as it combines all the advantages of the + others) +#. Use `*sleep()` whenever possible +#. Use `usleep_range*()` whenever accuracy of `*sleep()` is not sufficient + +First check fsleep() function description and to learn more about accuracy, +please check msleep() function description. + + +`usleep_range*()` +~~~~~~~~~~~~~~~~~ + +.. kernel-doc:: include/linux/delay.h + :identifiers: usleep_range usleep_range_idle + +.. kernel-doc:: kernel/time/sleep_timeout.c + :identifiers: usleep_range_state + + +`*sleep()` +~~~~~~~~~~ + +.. kernel-doc:: kernel/time/sleep_timeout.c + :identifiers: msleep msleep_interruptible + +.. kernel-doc:: include/linux/delay.h + :identifiers: ssleep fsleep diff --git a/Documentation/timers/index.rst b/Documentation/timers/index.rst index 983f91f8f023..4e88116e4dcf 100644 --- a/Documentation/timers/index.rst +++ b/Documentation/timers/index.rst @@ -12,7 +12,7 @@ Timers hrtimers no_hz timekeeping - timers-howto + delay_sleep_functions =20 .. only:: subproject and html =20 diff --git a/Documentation/timers/timers-howto.rst b/Documentation/timers/t= imers-howto.rst deleted file mode 100644 index ef7a4652ccc9..000000000000 --- a/Documentation/timers/timers-howto.rst +++ /dev/null @@ -1,115 +0,0 @@ -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -delays - Information on the various kernel delay / sleep mechanisms -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -This document seeks to answer the common question: "What is the -RightWay (TM) to insert a delay?" - -This question is most often faced by driver writers who have to -deal with hardware delays and who may not be the most intimately -familiar with the inner workings of the Linux Kernel. - - -Inserting Delays ----------------- - -The first, and most important, question you need to ask is "Is my -code in an atomic context?" This should be followed closely by "Does -it really need to delay in atomic context?" If so... - -ATOMIC CONTEXT: - You must use the `*delay` family of functions. These - functions use the jiffy estimation of clock speed - and will busy wait for enough loop cycles to achieve - the desired delay: - - ndelay(unsigned long nsecs) - udelay(unsigned long usecs) - mdelay(unsigned long msecs) - - udelay is the generally preferred API; ndelay-level - precision may not actually exist on many non-PC devices. - - mdelay is macro wrapper around udelay, to account for - possible overflow when passing large arguments to udelay. - In general, use of mdelay is discouraged and code should - be refactored to allow for the use of msleep. - -NON-ATOMIC CONTEXT: - You should use the `*sleep[_range]` family of functions. - There are a few more options here, while any of them may - work correctly, using the "right" sleep function will - help the scheduler, power management, and just make your - driver better :) - - -- Backed by busy-wait loop: - - udelay(unsigned long usecs) - - -- Backed by hrtimers: - - usleep_range(unsigned long min, unsigned long max) - - -- Backed by jiffies / legacy_timers - - msleep(unsigned long msecs) - msleep_interruptible(unsigned long msecs) - - Unlike the `*delay` family, the underlying mechanism - driving each of these calls varies, thus there are - quirks you should be aware of. - - - SLEEPING FOR "A FEW" USECS ( < ~10us? ): - * Use udelay - - - Why not usleep? - On slower systems, (embedded, OR perhaps a speed- - stepped PC!) the overhead of setting up the hrtimers - for usleep *may* not be worth it. Such an evaluation - will obviously depend on your specific situation, but - it is something to be aware of. - - SLEEPING FOR ~USECS OR SMALL MSECS ( 10us - 20ms): - * Use usleep_range - - - Why not msleep for (1ms - 20ms)? - Explained originally here: - https://lore.kernel.org/r/15327.1186166232@lwn.net - - msleep(1~20) may not do what the caller intends, and - will often sleep longer (~20 ms actual sleep for any - value given in the 1~20ms range). In many cases this - is not the desired behavior. - - - Why is there no "usleep" / What is a good range? - Since usleep_range is built on top of hrtimers, the - wakeup will be very precise (ish), thus a simple - usleep function would likely introduce a large number - of undesired interrupts. - - With the introduction of a range, the scheduler is - free to coalesce your wakeup with any other wakeup - that may have happened for other reasons, or at the - worst case, fire an interrupt for your upper bound. - - The larger a range you supply, the greater a chance - that you will not trigger an interrupt; this should - be balanced with what is an acceptable upper bound on - delay / performance for your specific code path. Exact - tolerances here are very situation specific, thus it - is left to the caller to determine a reasonable range. - - SLEEPING FOR LARGER MSECS ( 10ms+ ) - * Use msleep or possibly msleep_interruptible - - - What's the difference? - msleep sets the current task to TASK_UNINTERRUPTIBLE - whereas msleep_interruptible sets the current task to - TASK_INTERRUPTIBLE before scheduling the sleep. In - short, the difference is whether the sleep can be ended - early by a signal. In general, just use msleep unless - you know you have a need for the interruptible variant. - - FLEXIBLE SLEEPING (any delay, uninterruptible) - * Use fsleep --=20 2.39.2