From nobody Wed Nov 27 02:42:35 2024 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 96B8D153812; Mon, 14 Oct 2024 08:22:45 +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=1728894167; cv=none; b=WbZZdZJ4ozfqswM9dactVVXZxxkw4RaWFMu470rkI4iKJfrdUXQF++7fBKKR76LE0KaKxJznrGnRhJguJs7hw2pwlG3rxnYpe76XsWiN18/xdK13tWyT8OwHb2103lDqDnBIpbPZsdNxu/phQsmXeBexCMFLsuzELfnIWixsR+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894167; c=relaxed/simple; bh=R59ISuQU6UNetpyfr/6njAfFarMxn1kdLytWjpw5p0U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=scHGMaFFU5waZ7mNM3SVF3tgIZOXexeCumXe6YReKd/wJC19JqhTVRjRKWvsVmw+UfGBvkns7IYveUJNhmyz7SB4VCQTo3duSQ8WJ5UnF5mu74QN0Bd36+sAggrz8oFXjPK0MnIiAlZoPU4/vLS/Z9RllaZsBvUdFEQW/J+YFAA= 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=i0lSOyid; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jtKDHSGP; 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="i0lSOyid"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jtKDHSGP" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894164; 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=cSfli7o6o9K/Eh4c9OZZevk/KHj0m2P7q6V2eNSLExs=; b=i0lSOyidAIK2a1QA0nL8qwP6AR2tRF81HBoq21UrszRxARIOEyGpR1bGHEh48sewtTR0ZG vPKzGypJaZxse9TTsDoRmfWIBy024YgGaCFeFYvubAx6NkWsB0pN9NkkJ3d4F6DMG15uPK 8DsKWlYm+zixZlosbArwle2ElB9qv9DU1VL6zLcVRLTaZuuKu05sdsNp+bt3z1xaMhBj/k kQeeZVHc02dBtrQN5oZu8tNNdQ9WKkQ0eJ39Tqm6LeFat2wg9bjk+35Bc+31I/PUGVYeXe QYwINUz+hCG7nTsvwXMLJcwh1O7SZfKz4hBEihBEMVEdI7vT8Jfkndu8WlEB1g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894164; 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=cSfli7o6o9K/Eh4c9OZZevk/KHj0m2P7q6V2eNSLExs=; b=jtKDHSGPeWtTFWKbHYP4Avh9gmNB5ErrkPI7BReihfJgmmvw6esm4HIf/Uvcxi2C5laJMy 7exp0NwGobZzM3AQ== Date: Mon, 14 Oct 2024 10:22:18 +0200 Subject: [PATCH v3 01/16] MAINTAINERS: Add missing file include/linux/delay.h 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-1-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda include/linux/delay.h is not covered by MAINTAINERS file. Add it to the "HIGH-RESOLUTION TIMERS, TIMER WHEEL, CLOCKEVENTS" section. Signed-off-by: Anna-Maria Behnsen Acked-by: Frederic Weisbecker Reviewed-by: Mark Brown --- v2: New (splitted as requested by Frederic) --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 7ad507f49324..91c3e79c69cd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10165,6 +10165,7 @@ 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 --=20 2.39.5 From nobody Wed Nov 27 02:42:35 2024 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 C548B14B07A; Mon, 14 Oct 2024 08:22:45 +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=1728894169; cv=none; b=J1aZAWhRHw0VhXrf61ETVYToGZSE/hWhPGHwQoojK6dwjS3jebcEMHudWBB3DvVs8Z/HfJZKiewY3WG8pTjqMCG8z7uGaH0KfA/AUQHfZWls9q4Bz9Nqff5GlC3o8LXV59n6x9++qXfuRlJzxmpv2XMI73/39IDPNiUQM868syQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894169; c=relaxed/simple; bh=W9PWd/ItMFmQnOT/0CnlPC6wnFOM4tSVpK13gm+Djiw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rnXan2FRVR4NcL/s29tORSB9XqIwJeX/bU2jGEynzjbkzBBtB6qaHC1aiPs55rK9hbG9DZKn8CgQbw09UZuLTIRR3FyKkyhSG7kfqj5mX8Zj9xotlXC8CdV/sT9sjOxueP+8gLuaRjMLe0+r3K/1jKK8LqdA8toxsF/fRBapsms= 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=t/Iazdyd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7G72bjrG; 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="t/Iazdyd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7G72bjrG" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894164; 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=wBROUf8RO8R0id+0aQBgMewZfex9kNjCh0W1OFhDybw=; b=t/IazdydPQQdUZ0LXEJ6xIDIiVBNTyICRDsc7UhT481twRsJ3nFc3x1llzUG1yu0U6FT3+ tP9tCiBmtZmtkmkWZdOJ/Jg4vqX6dNmXM1ewhswDGkI/GA90VTioZSeia90JOZhpUj45LT Pcdz1m5H+qpKiFTTbZ9AgW0XKtCpaRMfH6L1+nHEmmBhCBkpnl8W9qM5jrNPQfXSUD/6gf mLAHwi8uAro6gYBopJsztP9Dp8PjcqBwY3ZhWkZ3S4x7E6v5LD1oNLm7rYqOuNz5w68kFg HZWtliESqB00VDW+C/HnHGWMdj+8dVWTFW9zq6z/RF6f4ZlEEF5AmN0/ZLJVZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894164; 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=wBROUf8RO8R0id+0aQBgMewZfex9kNjCh0W1OFhDybw=; b=7G72bjrGDeGIZK0pGV23m8bPtanOb2bE6q6NUU8tg59NYx7Bv834Tf7lDamQM2yPaEKkGc Lzn0qlaulvh9Y2Dg== Date: Mon, 14 Oct 2024 10:22:19 +0200 Subject: [PATCH v3 02/16] 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-2-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda 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(). Signed-off-by: Anna-Maria Behnsen Acked-by: Frederic Weisbecker Reviewed-by: Mark Brown --- v2: - Drop adding delay.h to MAINTAINERS file - Some more minor formatting fixups --- MAINTAINERS | 1 + kernel/time/Makefile | 2 +- kernel/time/hrtimer.c | 120 ----------------- kernel/time/sleep_timeout.c | 317 ++++++++++++++++++++++++++++++++++++++++= ++++ kernel/time/timer.c | 192 --------------------------- 5 files changed, 319 insertions(+), 313 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 91c3e79c69cd..4b067e68911b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10170,6 +10170,7 @@ 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 cddcd08ea827..04f7d8a392c3 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..78b2e7e30b1e --- /dev/null +++ b/kernel/time/sleep_timeout.c @@ -0,0 +1,317 @@ +// 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 m= ode) +{ + 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, unsi= gned 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 0fc9d066a7be..02355b275bab 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.5 From nobody Wed Nov 27 02:42:35 2024 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 EED57153BD7; Mon, 14 Oct 2024 08:22:46 +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=1728894168; cv=none; b=Mp9vosiC88b5LTq2EqaJ1PFgZJ60VjYrAzH0Bd70lgDVsrze6zHV3+Qw1m5INGAPtrz9VKJ5kzZ1vAvNLbvxrqn5WhqMdAjQaaKa9YL2xKz1VfiitetHdWuIODHe6wvvwBS56snzYG+nh84U79DqGD9bIQAm9lmUAEbpUh6qPXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894168; c=relaxed/simple; bh=m/9NfYkbSBspHRYgsc7+c2HJCNy9U5Uted8OLc7olNc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J81zKQdi6W0Mq68HyR1gCk9fatcw0vq0usGlK2HA3zVhkif1lRQpesFLEBgyaYf8dbUwVoQ/Ijk11QxhYLC7StiSYQaAyijRe3VV3JewBCMnTJ3IzxIywTF6Rt/hNLCDcVyzZ9gFxi/I+mhgQFsBVpZEcYf7fml+KP+JmXYWSt0= 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=JB3B9MMg; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=SX+7rtvs; 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="JB3B9MMg"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="SX+7rtvs" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894164; 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=x0dkMqLeJQoGt1aUXRfUeE0Qz3QS1tOrq27JnRdcMaI=; b=JB3B9MMgZrpNdD+97PFSwfowXw/9oxad6tmKLf41ufCVFqpuJx/OeMA8IvOpon89iqHQQO c6aDqQtoxfqFktbGRIgxdzrLHznykv52wyoeTmTF287qw8CIm9h2q4kMa6O/PlFu6Vr/0T KYgZv22UJKdzH/aulsFHah7fU3dssQv1mVr0vncAUNshjao123ZAugI/D9Y5YQ+QJZ8XCR apc6LbONMBzF/D7hTCKI/O8zQg+TJ+i3Jko7wtKp/jXfeWkyisjOVFouSQysP4zp0NhOwB iwc7LyuCeEZSj+qcuvsKDH95rEuBtl6MDwNwLG6tsMZx4Q/vSJkvpcxPlDFTTQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894164; 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=x0dkMqLeJQoGt1aUXRfUeE0Qz3QS1tOrq27JnRdcMaI=; b=SX+7rtvshdB9bt6zvamBBqm/KeV9X/+Nr5j7BH6icZshhSkhKhdpxCW6tldmmaaqg12c6F WX/W/rMVUc5dzEDw== Date: Mon, 14 Oct 2024 10:22:20 +0200 Subject: [PATCH v3 03/16] timers: Update schedule_[hr]timeout*() related function descriptions 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-3-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda schedule_timeout*() functions do not have proper kernel-doc formatted function descriptions. schedule_hrtimeout() and schedule_hrtimeout_range() have a almost identical description. Add missing function descriptions. Remove copy of function description and add a pointer to the existing description instead. Signed-off-by: Anna-Maria Behnsen Acked-by: Frederic Weisbecker Reviewed-by: Mark Brown --- v2: New in v2 --- kernel/time/sleep_timeout.c | 66 ++++++++++++++++++++++++++++-------------= ---- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/kernel/time/sleep_timeout.c b/kernel/time/sleep_timeout.c index 78b2e7e30b1e..560d17c30aa5 100644 --- a/kernel/time/sleep_timeout.c +++ b/kernel/time/sleep_timeout.c @@ -110,8 +110,17 @@ signed long __sched schedule_timeout(signed long timeo= ut) EXPORT_SYMBOL(schedule_timeout); =20 /* - * We can use __set_current_state() here because schedule_timeout() calls - * schedule() unconditionally. + * __set_current_state() can be used in schedule_timeout_*() functions, be= cause + * schedule_timeout() calls schedule() unconditionally. + */ + +/** + * schedule_timeout_interruptible - sleep until timeout (interruptible) + * @timeout: timeout value in jiffies + * + * See schedule_timeout() for details. + * + * Task state is set to TASK_INTERRUPTIBLE before starting the timeout. */ signed long __sched schedule_timeout_interruptible(signed long timeout) { @@ -120,6 +129,14 @@ signed long __sched schedule_timeout_interruptible(sig= ned long timeout) } EXPORT_SYMBOL(schedule_timeout_interruptible); =20 +/** + * schedule_timeout_killable - sleep until timeout (killable) + * @timeout: timeout value in jiffies + * + * See schedule_timeout() for details. + * + * Task state is set to TASK_KILLABLE before starting the timeout. + */ signed long __sched schedule_timeout_killable(signed long timeout) { __set_current_state(TASK_KILLABLE); @@ -127,6 +144,14 @@ signed long __sched schedule_timeout_killable(signed l= ong timeout) } EXPORT_SYMBOL(schedule_timeout_killable); =20 +/** + * schedule_timeout_uninterruptible - sleep until timeout (uninterruptible) + * @timeout: timeout value in jiffies + * + * See schedule_timeout() for details. + * + * Task state is set to TASK_UNINTERRUPTIBLE before starting the timeout. + */ signed long __sched schedule_timeout_uninterruptible(signed long timeout) { __set_current_state(TASK_UNINTERRUPTIBLE); @@ -134,9 +159,15 @@ signed long __sched schedule_timeout_uninterruptible(s= igned long timeout) } EXPORT_SYMBOL(schedule_timeout_uninterruptible); =20 -/* - * Like schedule_timeout_uninterruptible(), except this task will not cont= ribute - * to load average. +/** + * schedule_timeout_idle - sleep until timeout (idle) + * @timeout: timeout value in jiffies + * + * See schedule_timeout() for details. + * + * Task state is set to TASK_IDLE before starting the timeout. It is simil= ar to + * schedule_timeout_uninterruptible(), except this task will not contribut= e to + * load average. */ signed long __sched schedule_timeout_idle(signed long timeout) { @@ -151,6 +182,9 @@ EXPORT_SYMBOL(schedule_timeout_idle); * @delta: slack in expires timeout (ktime_t) * @mode: timer mode * @clock_id: timer clock to be used + * + * Details are explained in schedule_hrtimeout_range() function descriptio= n as + * this function is commonly used. */ int __sched schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta, const enum hrtimer_mode mode, clockid_t clock_id) @@ -236,26 +270,8 @@ EXPORT_SYMBOL_GPL(schedule_hrtimeout_range); * @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. + * See schedule_hrtimeout_range() for details. @delta argument of + * schedule_hrtimeout_range() is set to 0 and has therefore no impact. */ int __sched schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode m= ode) { --=20 2.39.5 From nobody Wed Nov 27 02:42:35 2024 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 EECC915383C; Mon, 14 Oct 2024 08:22:46 +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=1728894168; cv=none; b=NN+KgQ3usse/xsP1v2zUurcsF2WOT7i3HOkJVdyP755qsnlp3wmEWawnwkNKOGO+ZCZGmBt8n8jwKsG6VCGxnvAZWx6WgIRbgWP+mTuHsmLF6ALj2cCeCd1Dlzmw/APPbJtu6fDM5WMY++m1AJlNUD5IFYUJBqNC60To7f250m4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894168; c=relaxed/simple; bh=QMpDIDl8umoJdqVbBTfGy0XUBiUV/xPCM1ODVJW+QEM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AK9VVUKl33j/sNJpWm+HydDjCU0fKjcTWnpNT+njl+yx2nLXk5PUNsDp1zRx6MNhI+PIKYrJuLF8Svl6d4v7N5dBSmQFfWuuSkSrvx3TQT/Dv9nC3SpXrHr4gHtG3JPIoW/jE6wlX+cggntdmAEqtNO969L4pPZ8corfjnwTkis= 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=Tdiau+xY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2py3lShc; 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="Tdiau+xY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2py3lShc" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894165; 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=hzqGiPKzKOr/Twl2K0C7DsL38YQ5/v1OOfZz3SGMgIo=; b=Tdiau+xYkkTqIlZOuU7QbocyN3mWZ5cMg+9z7mvzIBXeJf7/egZmEdNUT4osS0wH+O9TwP NYrJ1281gIYm8V8xkpg3g+dd4Ye8HQ0xzLYVpkZ6LwqqpAfDM/WjqjtQhDVDxedtfETgVM O4tLZOCTFe1nf0EkS7Cv6Wha8snd6oQKk30YpOYTfJf5s4B22LOoFxlstGJUDZS2jwigFm VQGXw177tW1TOaGNEU18C9l3fkbc8iaXerdNhqNCbtfqurbpLyVS4ZaRRR5+k3izPPEjKW W8Ezpsyc8MuLlSgGao+CIXHSTK3p00J579HFm818pMrAV90NUAv5GQERFvFV8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894165; 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=hzqGiPKzKOr/Twl2K0C7DsL38YQ5/v1OOfZz3SGMgIo=; b=2py3lShcqxXqMh3SmT3Lr2IIWwIdLZub4OBrE1vPJUwleB5lhSTj/03xbr/IsU35J0MH0+ e5/NuwaJhnQn7zBw== Date: Mon, 14 Oct 2024 10:22:21 +0200 Subject: [PATCH v3 04/16] timers: Rename usleep_idle_range() to usleep_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: <20241014-devel-anna-maria-b4-timers-flseep-v3-4-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, SeongJae Park usleep_idle_range() is a variant of usleep_range(). Both are using usleep_range_state() as a base. To be able to find all the related functions in one go, rename it usleep_idle_range() to usleep_range_idle(). No functional change. Cc: Andrew Morton Cc: damon@lists.linux.dev Cc: linux-mm@kvack.org Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker Reviewed-by: SeongJae Park Reviewed-by: Mark Brown --- v2: Fix typos in commit message --- 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 a83f3b736d51..c725c78b43f0 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1896,7 +1896,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.5 From nobody Wed Nov 27 02:42:35 2024 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 9D61415575B; Mon, 14 Oct 2024 08:22:48 +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=1728894171; cv=none; b=JMWl+UF4e5RceH1PghJu17Ie1uPGFLyXUUtLmNhu7lyHty2yFjexjSXzsiAk0sTss3ntJ25J5quqaNf6Tc0442wxuSfDobzzqiwldk+aQl0zlpAeSFoofyftVrVSoLCPYTMMCtP2cawwuaUnSQIFw6aDpCE75/K/HdS4iJvrrxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894171; c=relaxed/simple; bh=u8QJ5+veB/42sFjbq73Nx90Rwi8dxtfPYberW/kuDhE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EDgZ5Ycz7lTg1wVtYP8aZAmFr82kPsv0u78DMHLtVFQADrPCSkcox13cTbXVLLuKmewzkrYK4mBWMrObS3EXB65xmAWesButiGq6qYePowyHQUYglEtysIQFmhu4BSJqeCO0nH3SbTcU8vX0kpCLqeq++fM6Oa0Lbb1QVg0T3iU= 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=0vO0Nh6O; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Z/ZvZF07; 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="0vO0Nh6O"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Z/ZvZF07" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894165; 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=y6f9ANd86VKUTjMkX0jmN2iyxtAUU2JdpNcLRkkFjFA=; b=0vO0Nh6OCzktv2f7aCX4RjoGIE23b0ST65q/DfxZySwBMbLepYEwkTRBKEOOLOzMUCN3Gf 3bbFyh7wMqdnUzws4nfHzI48rwtOIPc/Gz9oJYEWwEvuNFQZl0WKxT3/sEI1l0Vq2aXVBw zgkb+qXhXRKkEh1lUaxWA9LTlQMU3QZcCjLCMwNuxN1dHXnskGdwMR0ZAZy+WfLWdlj0LD 9RoA7XIbI4gz1ZZxtOpJ0Vd/uiA6ZLoJYSWhWgQmLj2l6Fyrv1lILuYLDXzJtIX/fpBw0s 4a5WXaVZ02LkS8gJ+xghUhVJtKvrbp7BsHp+MDlYqbUkkdl/Aa0YJNqo4BtO+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894165; 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=y6f9ANd86VKUTjMkX0jmN2iyxtAUU2JdpNcLRkkFjFA=; b=Z/ZvZF07hN8kzJsgK9euX4QKIb5o2S7c5/Chk7jBhLk5eAVOdYpsfxhlir+aTs1a4C2Ypp fVxfgK829fCHoWAw== Date: Mon, 14 Oct 2024 10:22:22 +0200 Subject: [PATCH v3 05/16] 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-5-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda , 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 Reviewed-by: Frederic Weisbecker Reviewed-by: Mark Brown --- v3: - Rephrase msleep function description to make it clear v2: - Fix typos - Fix proper usage of kernel-doc return formatting --- include/asm-generic/delay.h | 41 +++++++++++++++++++++++++++++++---- include/linux/delay.h | 48 ++++++++++++++++++++++++++++++---------- kernel/time/sleep_timeout.c | 53 ++++++++++++++++++++++++++++++++++++++++-= ---- 3 files changed, 120 insertions(+), 22 deletions(-) diff --git a/include/asm-generic/delay.h b/include/asm-generic/delay.h index e448ac61430c..a8cee41cc51b 100644 --- a/include/asm-generic/delay.h +++ b/include/asm-generic/delay.h @@ -12,11 +12,39 @@ 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. + * Implementation details: + * + * * 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) -> udelay + * * 0x5 is 2**32 / 1000000000 (rounded up) -> ndelay */ =20 -/* 0x10c7 is 2**32 / 1000000 (rounded up) */ +/** + * udelay - Inserting a delay based on microseconds with busy waiting + * @usec: 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 it is not simple to specify a + * generic threshold for this which will fit for all systems. An approxima= tion + * is 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. + */ #define udelay(n) \ ({ \ if (__builtin_constant_p(n)) { \ @@ -29,7 +57,12 @@ extern void __delay(unsigned long loops); } \ }) =20 -/* 0x5 is 2**32 / 1000000000 (rounded up) */ +/** + * ndelay - Inserting a delay based on nanoseconds with busy waiting + * @nsec: requested delay in nanoseconds + * + * See udelay() for basic information about ndelay() and it's variants. + */ #define ndelay(n) \ ({ \ if (__builtin_constant_p(n)) { \ diff --git a/include/linux/delay.h b/include/linux/delay.h index 2bc586aa2068..2de509e4adce 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 milliseconds with busy waiting + * @n: requested delay in milliseconds + * + * 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 around 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 560d17c30aa5..f3f246e4c8d1 100644 --- a/kernel/time/sleep_timeout.c +++ b/kernel/time/sleep_timeout.c @@ -281,7 +281,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 jiffy based timeouts for the sleep duration. Because of t= he + * design of the timer wheel, the maximum additional percentage delay (sla= ck) is + * 12.5%. This is only valid for timers which will end up in level 1 or a = higher + * level of the timer wheel. For explanation of those 12.5% please check t= he + * detailed description about the basics of the timer wheel. + * + * The slack of timers which will end up in level 0 depends on sleep durat= ion + * (msecs) and HZ configuration and can be calculated in the following way= (with + * the timer wheel design restriction that the slack is not less than 12.5= %): + * + * ``slack =3D MSECS_PER_TICK / msecs`` + * + * When the allowed slack of the callsite is known, the calculation could = be + * turned around to find the minimal allowed sleep duration to meet the + * constraints. For example: + * + * * ``HZ=3D1000`` with ``slack=3D25%``: ``MSECS_PER_TICK / slack =3D 1 / = (1/4) =3D 4``: + * all sleep durations greater or equal 4ms will meet the constraints. + * * ``HZ=3D1000`` with ``slack=3D12.5%``: ``MSECS_PER_TICK / slack =3D 1 = / (1/8) =3D 8``: + * all sleep durations greater or equal 8ms will meet the constraints. + * * ``HZ=3D250`` with ``slack=3D25%``: ``MSECS_PER_TICK / slack =3D 4 / (= 1/4) =3D 16``: + * all sleep durations greater or equal 16ms will meet the constraints. + * * ``HZ=3D250`` with ``slack=3D12.5%``: ``MSECS_PER_TICK / slack =3D 4 /= (1/8) =3D 32``: + * all sleep durations greater or equal 32ms will meet the constraints. + * + * See also the signal aware variant msleep_interruptible(). */ void msleep(unsigned int msecs) { @@ -294,7 +321,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) { @@ -312,11 +347,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, unsi= gned int state) { --=20 2.39.5 From nobody Wed Nov 27 02:42:35 2024 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 9D67315575E; Mon, 14 Oct 2024 08:22:48 +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=1728894170; cv=none; b=UETpqQ5umLmExaPi8yNuS6mOhOufF8Ef8aEe9+zWVNc4Izlq5Wp50GHDJofMUTkPaho4XHB5AB24M8guyuVgfYt/DE67uVb9n1WelJWMgZ50JRgT1kmUvrp24KWG0BOQ7qzrDP1gkehwgwB+aciD9JMMogkwY1OE7m6fbeG3vHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894170; c=relaxed/simple; bh=nQNvsQI/LKOxp28gKqTsbBASM5OGfHUopU7DTfBEIvg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HpO9H8tpdhiuqyKKwCTwnR6HZf71G1aQe8TqiIGashvvLehCiNwlxpve0RsZfRlt0viMtAYIGDNu15gEvk3N9eI84GdVTaSkRlvN+oadmncD9zhbZZtFiFmfBdMk9M7RzzLjvemjRZI/vR+nWdc9Hqn2idrXKO7N1GYulIjdhig= 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=pmhoyqKY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ania52HS; 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="pmhoyqKY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ania52HS" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894166; 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=ry+dtPsZBklLhcJ65uITnod4UvodhQ0YRrocNcHCAkI=; b=pmhoyqKY6/Hp+Nbkc7dId8BgCrzDJ6QT1UuIAFnkO98NXVGsIeP2puUTcKXXoRAgtnRv4t v3JHN9LN6hTMcmamRJFwfGd8KT8qrZTuj08JTdvPeKqS2pgHTR+9I17zcGqGJfBZ8ROWNc XhN942L6KWxiyE5G9R/l70YbCDsVuSmwwXTP2GgoyCi1ko4JzQ5G3fka/yloL2+fN7qQAH HLmBr6Ja4ZNW51iuRnX3Wax4vr+CKfwna0Qy03RlhGPzmFEqsktP97h9E/TUMImncdfLfj flm50SQ/4XzMxPXUkYOtd1xHBiIyJIhkiynMFJzjkL5mnz7GG2QV5bfF+2WBIA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894166; 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=ry+dtPsZBklLhcJ65uITnod4UvodhQ0YRrocNcHCAkI=; b=Ania52HS0L2fPfnAAHtSDj1YuoBZ8Em64TR+UWoTyfZqGcr76FyIrr3kqQKG5cEckfBvAu iGEBM4FwulsR7AAA== Date: Mon, 14 Oct 2024 10:22:23 +0200 Subject: [PATCH v3 06/16] delay: Rework udelay and ndelay 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-6-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda udelay() as well as ndelay() are defines and no functions and are using constants to be able to transform a sleep time into loops and to prevent too long udelays/ndelays. There was a compiler error with non-const 8 bit arguments which was fixed by commit a87e553fabe8 ("asm-generic: delay.h fix udelay and ndelay for 8 bit args"). When using a function, the non-const 8 bit argument is type casted and the problem would be gone. Transform udelay() and ndelay() into proper functions, remove the no longer and confusing division, add defines for the magic values and add some explanations as well. Suggested-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker Reviewed-by: Mark Brown --- v3: Fix build error for i386 (missing linux/math.h include). v2: New in v2 (as suggested by Thomas) --- include/asm-generic/delay.h | 65 ++++++++++++++++++++++++++---------------= ---- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/include/asm-generic/delay.h b/include/asm-generic/delay.h index a8cee41cc51b..76cf237b6e4c 100644 --- a/include/asm-generic/delay.h +++ b/include/asm-generic/delay.h @@ -2,6 +2,9 @@ #ifndef __ASM_GENERIC_DELAY_H #define __ASM_GENERIC_DELAY_H =20 +#include +#include + /* Undefined functions to get compile-time errors */ extern void __bad_udelay(void); extern void __bad_ndelay(void); @@ -12,13 +15,18 @@ extern void __const_udelay(unsigned long xloops); extern void __delay(unsigned long loops); =20 /* - * Implementation details: - * - * * 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) -> udelay - * * 0x5 is 2**32 / 1000000000 (rounded up) -> ndelay + * The microseconds/nanosecond delay multiplicators are used to convert a + * constant microseconds/nanoseconds value to a value which can be used by= the + * architectures specific implementation to transform it into loops. + */ +#define UDELAY_CONST_MULT ((unsigned long)DIV_ROUND_UP(1ULL << 32, USEC_PE= R_SEC)) +#define NDELAY_CONST_MULT ((unsigned long)DIV_ROUND_UP(1ULL << 32, NSEC_PE= R_SEC)) + +/* + * The maximum constant udelay/ndelay value picked out of thin air to prev= ent + * too long constant udelays/ndelays. */ +#define DELAY_CONST_MAX 20000 =20 /** * udelay - Inserting a delay based on microseconds with busy waiting @@ -45,17 +53,17 @@ extern void __delay(unsigned long loops); * #. cache behaviour affecting the time it takes to execute the loop func= tion. * #. CPU clock rate changes. */ -#define udelay(n) \ - ({ \ - if (__builtin_constant_p(n)) { \ - if ((n) / 20000 >=3D 1) \ - __bad_udelay(); \ - else \ - __const_udelay((n) * 0x10c7ul); \ - } else { \ - __udelay(n); \ - } \ - }) +static __always_inline void udelay(unsigned long usec) +{ + if (__builtin_constant_p(usec)) { + if (usec >=3D DELAY_CONST_MAX) + __bad_udelay(); + else + __const_udelay(usec * UDELAY_CONST_MULT); + } else { + __udelay(usec); + } +} =20 /** * ndelay - Inserting a delay based on nanoseconds with busy waiting @@ -63,16 +71,17 @@ extern void __delay(unsigned long loops); * * See udelay() for basic information about ndelay() and it's variants. */ -#define ndelay(n) \ - ({ \ - if (__builtin_constant_p(n)) { \ - if ((n) / 20000 >=3D 1) \ - __bad_ndelay(); \ - else \ - __const_udelay((n) * 5ul); \ - } else { \ - __ndelay(n); \ - } \ - }) +static __always_inline void ndelay(unsigned long nsec) +{ + if (__builtin_constant_p(nsec)) { + if (nsec >=3D DELAY_CONST_MAX) + __bad_udelay(); + else + __const_udelay(nsec * NDELAY_CONST_MULT); + } else { + __udelay(nsec); + } +} +#define ndelay(x) ndelay(x) =20 #endif /* __ASM_GENERIC_DELAY_H */ --=20 2.39.5 From nobody Wed Nov 27 02:42:35 2024 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 DFD32155C98; Mon, 14 Oct 2024 08:22:48 +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=1728894171; cv=none; b=FvjOgVmjlw/TsPQy0Q1HxtTdxpLn4utEi87dnEtTg0RCoj09FJGLd0FqzXjwmShWBqb/vNB2vtY8fyDBpROVBM0WiuFH6afqSQriU2zhiNeAC6V9+CK3dqadcK28Bk3XZYkPGlwGPpdQSVHQ5QF5tE4R28+1x+0rrVUsCnlCmnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894171; c=relaxed/simple; bh=mliOT04cAh0Q6sqAuNHbuq0J5E8JkqPoIqygnaYqzZc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bfF5YBvDXUpwlJQdLlFyv22CnI+F/Fpf5bB57p/bpDMOpZd7wAWktrqsjfwF+QlxpBono+7DvJ0Jr+epxgmOh54iw230ie04nSdNdHpkmG3UWKCqBjEuuKpI6DtwLEBBcvx/9YPM5cGFI5nLqmcN4OAK0QV/W8WTTABhW5HTJmM= 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=M0ystn3b; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VIcrpJ1c; 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="M0ystn3b"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VIcrpJ1c" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894166; 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=F26ftp0OugXu3D3/MI+RurcrPxczoX+xyN50is4hTYs=; b=M0ystn3bumIXHy9z1o3sSXgyQoP8aozHFUTgRjIUo+IH/HMHLBWUmmzDBkcA0eHSDl0BV/ BgWJeuCMBRihoABB0qtMtyDDzksS8iGnF0GcKuM13jgn9AaQRXWCGrVh30Lljn4gY4cQ3c /OVkVWIs8QuAyIHao1kaCqKhkv01TzavqWm+TDNtrrqNXerCkPX97C6Ctg+OWk2DGT1H8S pqmZIsUZe4PblDIVfTB72jEPkxelJfK4PAfafizMek86zakqsQ8ijX9RfsOTa5wECN3Elr NySoK+lzy7fmIo+4fYk3WZbshbt9miXTboL7ciGSZ1k4xZI5KJG7yVBoQSNz+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894166; 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=F26ftp0OugXu3D3/MI+RurcrPxczoX+xyN50is4hTYs=; b=VIcrpJ1cZk5Ja9vWRi+0ahqJk2cq0HNo1EWN49MYzamPW/538Ge9rKVFbNsMwieim2u9Su fnNqRyv1VOWHPeDw== Date: Mon, 14 Oct 2024 10:22:24 +0200 Subject: [PATCH v3 07/16] 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-7-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda , Heiner Kallweit , "David S. Miller" fsleep() simply implements the recommendations 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 Reviewed-by: Frederic Weisbecker Reviewed-by: Mark Brown --- 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 2de509e4adce..89866bab100d 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.5 From nobody Wed Nov 27 02:42:35 2024 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 EA5BA155CBF; Mon, 14 Oct 2024 08:22:48 +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=1728894170; cv=none; b=end8j0fiTQo9WqNbOPYkysHdbYadry0VwFwHblAaPDov6LSJcVM6JgUJ5jGkrpY7iBZKWBVqGra7XR9eALMttTsJD72KvYk5D14q8eoY21at5IzAv1/UFy75NxGQB5oIYdwwdK1LBgmoQNALtljadZnDvZoqfRrCCglR3ditS/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894170; c=relaxed/simple; bh=Bf62MSjNCcOsUnnQm2kzh16d6CLGiUEI3eiVV9t9Owc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lahOfdGA4SuyCKOGfrSGR6dttDoxh3TIlyNE/V0YAx+70SQW/85o/jxJVMvLq59KpWZSEHx8AfVz1owzn0hrwVmwup6A550vXT3pp9diY4R3UIJvliZSjkoVa9mu67GALKnWuSRChS9g2h8lP0eg3jiPpIpUrEjvlnPULlckeIM= 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=B/aSrdnG; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=S6JiLyI3; 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="B/aSrdnG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="S6JiLyI3" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894167; 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=qOaH71wwpXdQZek5RpUCzVvDQCRluMekHdCjKOEhMjY=; b=B/aSrdnG1hdrhqCf9Doxt53XdUEPd/DsqfCqfEtXm+sXaR4YxaOBvD/4G4k6gEJsLkPqNI vHi/uKunKriXr18pR5F29McrnstoIfhveWZg3Q9z3Lafph8GjeECPp6qWNwz+orsvPcojr Snx7csQhHtS1I/k/YSb+dPc2+vClJeJ/Z/M94B8lycT7WPEvSY3DnwB5ND44BUhPWtm7fc 5SbflHJua9/3ny+8zX2+wvL8ioeRogGZNozMCMjJDw9WJfWDlsKzeLlmGzBXOqcHiuQjDw Sh4zc4d6RRhGSRWRewxwX+yWhSDZeoxCFlye9hXYxSs2XZskPwA3I1nondd8+w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894167; 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=qOaH71wwpXdQZek5RpUCzVvDQCRluMekHdCjKOEhMjY=; b=S6JiLyI3D4+gyIiCjKrWzIAm4jv71/fdJjVfoPCojjq13xGDDrzi/OlrF6cyHiZaMmx4Mf 8Fn1cpiVDmJEzqBQ== Date: Mon, 14 Oct 2024 10:22:25 +0200 Subject: [PATCH v3 08/16] 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-8-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda , 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 Reviewed-by: SeongJae Park Reviewed-by: Frederic Weisbecker Reviewed-by: Mark Brown --- 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 c725c78b43f0..79efd8089d6c 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1892,8 +1892,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.5 From nobody Wed Nov 27 02:42:35 2024 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 19708156C52; Mon, 14 Oct 2024 08:22:50 +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=1728894171; cv=none; b=X8CxElObljbuqRUhjbY9tXdZqAwxKUqIjlTIMNgOw3tfS4SvH5k2aN4ZK/EovjEV74sMivNaITIsey2c/WuBm23Qxh4Xn4rvqiS+tutqXSpQWqPCdJS/jTVW4N197Q5Od5UtItwJYynub6mxW2S2imty58FfOfTNMBxopujKEHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894171; c=relaxed/simple; bh=4pR4v9VxzJjaDU9XI6f650AWP+UIWqKOfbpkl7I5tIU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IRd4Hp3HEbf8buOHj3wo9AEDkUL8kHkTMu3BE68hUUc95NURINflmSAyPjKl/XRaW3tjdwiqDTrN4zwUR3SDLTbQoETGs4PjS6bh4t2BTaufP6QJGYT6IASritssCzJGgoV7282qib1QkjQExulo3aydFl44uad+U9dU76TRjYU= 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=wHZEPcaB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UDMmwHg3; 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="wHZEPcaB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UDMmwHg3" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894167; 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=5nqpCkfMkESKp04+U621Yd1HCLdCwf1cAFfQf1SS6sw=; b=wHZEPcaBqHrRVpB8SbfhvRioL52wOH5cY7cXiwlTRnf+NEjgmOZkqoF4TNFfVTHJAZA2mY 2tQGtbaAasUpaGhJvDxImzIid/vvjC47d/SMU2P0CgVq7a9175nE5ZadxujZ9pON6PlNIu j//F9zvLuUclJij8AU1g0RFihTBsqsC2JbBehnYgdhytDcsVbyKd1N6UQ0DSUQrW0f27KA lhXN/fhalFZA0w64244iCc8bTbgob4yhjcP7+Y5pEEiXROfH2PSbHrH9TeFc9Fn3QxMHEQ 5YKaQWBEcsf0WQxpEGbIfMDV1fhwmchYLH9S88m/jIzOVry1JiS5PK8IviglMQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894167; 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=5nqpCkfMkESKp04+U621Yd1HCLdCwf1cAFfQf1SS6sw=; b=UDMmwHg3V2JzZXAI7hppK/+oR/CfnMW52xzqtpSYmbHQSPFpMzzQr7DKXKRYlxYkXyQHol wlfwZjoGES7tEmAw== Date: Mon, 14 Oct 2024 10:22:26 +0200 Subject: [PATCH v3 09/16] 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-9-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda 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. Add this check into the code as a WARN_ON_ONCE() to also cover callsites not using constants and fix the miss usage by resetting the delta to 0. Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker Reviewed-by: Mark Brown --- v3: Drop removal of checkpatch check, fix delta value --- kernel/time/sleep_timeout.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/time/sleep_timeout.c b/kernel/time/sleep_timeout.c index f3f246e4c8d1..3054e5232d20 100644 --- a/kernel/time/sleep_timeout.c +++ b/kernel/time/sleep_timeout.c @@ -364,6 +364,9 @@ void __sched usleep_range_state(unsigned long min, unsi= gned long max, unsigned i ktime_t exp =3D ktime_add_us(ktime_get(), min); u64 delta =3D (u64)(max - min) * NSEC_PER_USEC; =20 + if (WARN_ON_ONCE(max < min)) + delta =3D 0; + for (;;) { __set_current_state(state); /* Do not return before the requested sleep time has elapsed */ --=20 2.39.5 From nobody Wed Nov 27 02:42:35 2024 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 1B7DC156C5E; Mon, 14 Oct 2024 08:22:50 +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=1728894172; cv=none; b=As5D6CLVkt5pu7RP6U+MWGgNCKI2X+4T6ymKcmMwd58TdyIcok/cYmWSuqg2KogHOIv9aFN/tn6pzPOYdDFmyoCZiW7hSBWDygPZLd8rbQT0HWIgfCeNbsLZCDiACqoC5c2xI68AJjBIyHc6F0jeeMLkR3sTutpBnCntffwJtWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894172; c=relaxed/simple; bh=JaL91nwnDzK572vfekANud1US2XICU3EGwgQ0/S3wgE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rD+cI+++3ZlKgRc11KOaLP+yAM57jqEUcV1RVXpMoGbDWDcAA0r2xe4xcP0VVQezt2czqtDYG1an3pO77AEgqGoAK/dVJvMX+bdktMDEpi/ZqZYWzSK1Hm7/8OzokB2CKMsNmq3jY6ThTme5cQQYfyKqQijeGvgZkHxuCdFOYr8= 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=E4YoHwOL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=KbVSJdPa; 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="E4YoHwOL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KbVSJdPa" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894168; 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=P/FQYp1WsHM0Ea/f1W/sKkPBQrz2BmxxCOt6NVM353k=; b=E4YoHwOLb1B3ZAaCdnr6R95ME1AbGI+/GSYZ7c+XqpCFKmyNgR9wf0msWiFE+aSU8b3oIx Bi4NgRn8SKqQx5X9n8lQ9wjJA/2xikZAnL1NbGPvIhH59lTM3Io/Z3XsgzSAJQsFNkaKcT QVxoZbAifS/+U1Y8xSFL619WbmOXJbTlvEB3yDYVe/UvKVCOemwXOkd4WAj+jreU8oCvpj v5FKl1YiIIKzZZVSJgElAbBs6UhbXxr7s4y18XEXUmtqc2cr+OkqytxDMuLBinpUElvRl1 S0V+S4OaYVtNI7giWhFJyo7UlZ3vBtoTvlh1PJD1xQHlTmZGbUjC9BoZFxpJWw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894168; 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=P/FQYp1WsHM0Ea/f1W/sKkPBQrz2BmxxCOt6NVM353k=; b=KbVSJdPaprvvNNQ9A0lLzdXJ5QdgKrThBtv2FolWvO6tgQSnxJ1A44cOcP9GxTbyfvmePm T29kX26KkLnj3HAw== Date: Mon, 14 Oct 2024 10:22:27 +0200 Subject: [PATCH v3 10/16] checkpatch: Remove links to outdated 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-10-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda , 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. Also in checkpatch kernel documentation the outdated documentation is referenced. Replace the links to the outdated documentation with links to the function description. Note: Update of the outdated checkpatch checks is done in a second step. Cc: Andy Whitcroft Cc: Joe Perches Cc: Dwaipayan Ray Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker Reviewed-by: Mark Brown --- v3: new in v3, replace only the links to the outdated documentation --- Documentation/dev-tools/checkpatch.rst | 2 -- scripts/checkpatch.pl | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-too= ls/checkpatch.rst index a9fac978a525..abb3ff682076 100644 --- a/Documentation/dev-tools/checkpatch.rst +++ b/Documentation/dev-tools/checkpatch.rst @@ -470,8 +470,6 @@ API usage usleep_range() should be preferred over udelay(). The proper way of using usleep_range() is mentioned in the kernel docs. =20 - 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 4427572b2477..98790fe5115d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6597,11 +6597,11 @@ sub process { # 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); + "usleep_range is preferred over udelay; see function description o= f usleep_range() and udelay().\n" . $herecurr); } if ($delay > 2000) { WARN("LONG_UDELAY", - "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n"= . $herecurr); + "long udelay - prefer mdelay; see function description of mdelay(= ).\n" . $herecurr); } } =20 @@ -6609,7 +6609,7 @@ sub process { 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); + "msleep < 20ms can sleep for up to 20ms; see function description= of msleep().\n" . $herecurr); } } =20 @@ -7077,11 +7077,11 @@ sub process { 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"); + "usleep_range should not use min =3D=3D max args; see function d= escription of usleep_range().\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"); + "usleep_range args reversed, use min then max; see function desc= ription of usleep_range().\n" . "$here\n$stat\n"); } } =20 --=20 2.39.5 From nobody Wed Nov 27 02:42:35 2024 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 91156156F3A; Mon, 14 Oct 2024 08:22:50 +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=1728894172; cv=none; b=vDiKeklEO18SV0xUmptUcrs99XtHEOek5D+yJvawIIkzJXPHPRPq7sH0J0ZXef3uvfoFzr9uD2jsjn9cCLj6JozY2Mffz347rHrGGwfAEg2wNArmBJP5o9mS6XDSLvWN8oLGF2m68xX/0L91X5e8bC+8ul2qdI+s2HWe2CgpA8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894172; c=relaxed/simple; bh=jHyF4EaZ4omIC4dMBvbcJ73DQBrzr5Z0mWrxwDrWTX0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MkfEfbcUJc9/yc3XEjECiD3QxmnQi4Ezxu1fDqX+bxLy4+GrZRDuINVlm6N++IrL2A9AYpzD+KDEOP+hYiYXj3D8GjJ5vWxDCMfZl8B4pHLExLUEcvEKHKWdOKcKvUEpKn6Umv2rgzU+g3E0Vxy1svUT1m6iF72ay5QgPj6SDAI= 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=4Kt4he8d; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ySQYkIKs; 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="4Kt4he8d"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ySQYkIKs" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894168; 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=MqgLhEru8vtEo9KRnMpNBZU7wGZ0I2RuJBCZU/XIuwo=; b=4Kt4he8dGZ3L9A4R5fKglEtxUcrpLCjgqkeIU9jaDlvUh+xSdhbYVQ90saTdN09bpcQgHW OrlYox5+3vuFmWBb2c6f2vvCakk62huVtddDNEVGdWLGk1sgSQjiK9B6QIsU07VHq6E3MM 0XyjlZcijXZC1n75TkkyrfWNKh3yZyQ+b6yE/PTWTH2/6BTHWzmyVLzojFiM+QqYBcIZDW KOwU+t4h681dJt1RF2ug0d4mSQoDNT2LTp6H9GVRB08167QrCLsOeRT/7rH/wc3DHsfIL8 KxImzn9fMwyZSzVvgXNyLEYJDXbl9n3dzrq/azhrUnFsm8XMEZH9qQ3uQB7tFA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894168; 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=MqgLhEru8vtEo9KRnMpNBZU7wGZ0I2RuJBCZU/XIuwo=; b=ySQYkIKsdlyi2RIofAwYHs7Bq0+z9JQmSHj/YhRkRoy0EMMGrHInsmhg0QZHLEBExvv6al cGr9xt4OGQ5XRSAA== Date: Mon, 14 Oct 2024 10:22:28 +0200 Subject: [PATCH v3 11/16] 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-11-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda , 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() directly. Cc: Liam Girdwood Cc: Mark Brown Signed-off-by: Anna-Maria Behnsen Reviewed-by: Frederic Weisbecker Reviewed-by: Mark Brown --- v2: Use fsleep() directly --- drivers/regulator/core.c | 47 ++++----------------------------------------= --- 1 file changed, 4 insertions(+), 43 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 1179766811f5..2605f6e76ea4 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2642,45 +2642,6 @@ static int regulator_ena_gpio_ctrl(struct regulator_= dev *rdev, bool enable) return 0; } =20 -/** - * _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: - * - * Documentation/timers/timers-howto.rst - * - * The assumption here is that these regulator operations will never used = in - * atomic context and therefore sleeping functions can be used. - */ -static 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); -} - /** * _regulator_check_status_enabled - check if regulator status can be * interpreted as "regulator is enabled" @@ -2733,7 +2694,7 @@ static int _regulator_do_enable(struct regulator_dev = *rdev) s64 remaining =3D ktime_us_delta(end, ktime_get_boottime()); =20 if (remaining > 0) - _regulator_delay_helper(remaining); + fsleep(remaining); } =20 if (rdev->ena_pin) { @@ -2767,7 +2728,7 @@ static int _regulator_do_enable(struct regulator_dev = *rdev) int time_remaining =3D delay; =20 while (time_remaining > 0) { - _regulator_delay_helper(rdev->desc->poll_enabled_time); + fsleep(rdev->desc->poll_enabled_time); =20 if (rdev->desc->ops->get_status) { ret =3D _regulator_check_status_enabled(rdev); @@ -2786,7 +2747,7 @@ static int _regulator_do_enable(struct regulator_dev = *rdev) return -ETIMEDOUT; } } else { - _regulator_delay_helper(delay); + fsleep(delay); } =20 trace_regulator_enable_complete(rdev_get_name(rdev)); @@ -3730,7 +3691,7 @@ static int _regulator_do_set_voltage(struct regulator= _dev *rdev, } =20 /* Insert any necessary delays */ - _regulator_delay_helper(delay); + fsleep(delay); =20 if (best_val >=3D 0) { unsigned long data =3D best_val; --=20 2.39.5 From nobody Wed Nov 27 02:42:35 2024 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 66B3F156F2B; Mon, 14 Oct 2024 08:22:50 +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=1728894173; cv=none; b=eojR8Puax6OX/0/lT23Ei+bbZIzFSbDTHPbeMFKyM9fte/T10ygw+dpDJhkr5stW1p/hhEp5xE+bbIcZ2XOc7PAvImh9/hubGNZsx4TPwD1DcqW+GtCzzMGMQZ+WB9MOjz3nBscqVi1ZBfmolG6pTBEVpkj0+xKg+dTMzFunvnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894173; c=relaxed/simple; bh=RE0lPJ142pYDDUVy84Jj7l/XWzvXfsM2zlFIVk2tmzg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XU+WmtUQo/IsLcvCREngb+HcGbSeHw/NldYlQbPCBdh20H3pW25zkn+zWhGUJ73jJZ1fMehZGns+vAaq61OxMm7NxnqyloEk6ghLkyh/fXmQAHxiox32m3WVbMBx6qFamI0B3lUldY98ScRatBqAFz1WWhxhsdvRll3yLpystT8= 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=yLDIGvZ5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OV92svpV; 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="yLDIGvZ5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OV92svpV" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894169; 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=oqNSgO0ccYOB1F7gXkVsubKRt9n1kvpOSCotor1CtWA=; b=yLDIGvZ5CJjGXi8nakS+qfgGRt82lzRE0oepRgvsJ4wIYX2cLxtG7WE6zcfTEuDsLiEzmd sXB5kHFEc0/Royjv+LQn+3iLv/jBW0v6qgySfxZlagjDuh0uu6/TCoaVBa/yTJlVLarvxp GBVxJ5GriU/b+qUOyTjAyMrrD35HzQUWeZI6qob5DScvRreC3OoAJWt0K9K/fWYx1VT72h hkaMpY91C3leUVUyd1/EjrAa/se/X/vjX59qt5VT9MuUGP3crW4onoXNegNNYpcNHG0hzp pWLmBvTs0DChbjVQsHmIEL1xaSeRIFebrEJmAFbzJ+u/zuoLqgLI2S2WH1eiOg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894169; 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=oqNSgO0ccYOB1F7gXkVsubKRt9n1kvpOSCotor1CtWA=; b=OV92svpV47OwXvi+yta09kQeQB70QgemAJQpdfjmRusSbLu8F3zZLk8IBeacXYJatojiIh rVl0fx7/ikXd/RCA== Date: Mon, 14 Oct 2024 10:22:29 +0200 Subject: [PATCH v3 12/16] 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-12-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda , 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. While at it fix missing colon after "Returns" in function description and move return value description to the end of the function description. 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 Reviewed-by: Andrew Lunn # for phy.h Reviewed-by: Frederic Weisbecker Reviewed-by: Mark Brown --- v2: Add cleanup of usage of 'Returns' in function description --- include/linux/iopoll.h | 52 +++++++++++++++++++++++++---------------------= ---- include/linux/phy.h | 9 +++++---- include/linux/regmap.h | 38 ++++++++++++++++++------------------ sound/soc/sof/ops.h | 8 ++++---- 4 files changed, 54 insertions(+), 53 deletions(-) diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h index 19a7b00baff4..91324c331a4b 100644 --- a/include/linux/iopoll.h +++ b/include/linux/iopoll.h @@ -19,19 +19,19 @@ * @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 * - * 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. - * * When available, you'll probably want to use one of the specialized * macros defined below rather than this macro directly. + * + * 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. */ #define read_poll_timeout(op, val, cond, sleep_us, timeout_us, \ sleep_before_read, args...) \ @@ -64,22 +64,22 @@ * @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 * - * Returns 0 on success and -ETIMEDOUT upon a timeout. In either - * case, the last read value at @args is stored in @val. - * * This macro does not rely on timekeeping. Hence it is safe to call even= when * timekeeping is suspended, at the expense of an underestimation of wall = clock * time, which is rather minimal with a non-zero delay_us. * * When available, you'll probably want to use one of the specialized * macros defined below rather than this macro directly. + * + * Returns: 0 on success and -ETIMEDOUT upon a timeout. In either + * case, the last read value at @args is stored in @val. */ #define read_poll_timeout_atomic(op, val, cond, delay_us, timeout_us, \ delay_before_read, args...) \ @@ -119,17 +119,17 @@ * @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 - * case, the last read value at @addr is stored in @val. Must not - * be called from atomic context if sleep_us or timeout_us are used. - * * When available, you'll probably want to use one of the specialized * macros defined below rather than this macro directly. + * + * Returns: 0 on success and -ETIMEDOUT upon a timeout. In either + * case, the last read value at @addr is stored in @val. Must not + * be called from atomic context if sleep_us or timeout_us are used. */ #define readx_poll_timeout(op, addr, val, cond, sleep_us, timeout_us) \ read_poll_timeout(op, val, cond, sleep_us, timeout_us, false, addr) @@ -140,16 +140,16 @@ * @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 - * case, the last read value at @addr is stored in @val. - * * When available, you'll probably want to use one of the specialized * macros defined below rather than this macro directly. + * + * Returns: 0 on success and -ETIMEDOUT upon a timeout. In either + * case, the last read value at @addr is stored in @val. */ #define readx_poll_timeout_atomic(op, addr, val, cond, delay_us, timeout_u= s) \ read_poll_timeout_atomic(op, val, cond, delay_us, timeout_us, false, addr) diff --git a/include/linux/phy.h b/include/linux/phy.h index a98bc91a0cde..504766d4b2d5 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1378,12 +1378,13 @@ 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 + * + * 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 f9ccad32fc5c..75f162b60ba1 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -106,17 +106,17 @@ 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 + * This is modelled after the readx_poll_timeout macros in linux/iopoll.h. + * + * Returns: 0 on success and -ETIMEDOUT upon a timeout or the regmap_read * error return value in case of a error read. In the two former cases, * the last read value at @addr is stored in @val. Must not be called * from atomic context if sleep_us or timeout_us are used. - * - * This is modelled after the readx_poll_timeout macros in linux/iopoll.h. */ #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_u= s) \ ({ \ @@ -133,20 +133,20 @@ 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 - * error return value in case of a error read. In the two former cases, - * the last read value at @addr is stored in @val. - * * This is modelled after the readx_poll_timeout_atomic macros in linux/io= poll.h. * * Note: In general regmap cannot be used in atomic context. If you want t= o use * this macro then first setup your regmap for atomic use (flat or no cache * and MMIO regmap). + * + * Returns: 0 on success and -ETIMEDOUT upon a timeout or the regmap_read + * error return value in case of a error read. In the two former cases, + * the last read value at @addr is stored in @val. */ #define regmap_read_poll_timeout_atomic(map, addr, val, cond, delay_us, ti= meout_us) \ ({ \ @@ -177,17 +177,17 @@ 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 + * This is modelled after the readx_poll_timeout macros in linux/iopoll.h. + * + * Returns: 0 on success and -ETIMEDOUT upon a timeout or the regmap_field= _read * error return value in case of a error read. In the two former cases, * the last read value at @addr is stored in @val. Must not be called * from atomic context if sleep_us or timeout_us are used. - * - * This is modelled after the readx_poll_timeout macros in linux/iopoll.h. */ #define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout= _us) \ ({ \ diff --git a/sound/soc/sof/ops.h b/sound/soc/sof/ops.h index 2584621c3b2d..d73644e85b6e 100644 --- a/sound/soc/sof/ops.h +++ b/sound/soc/sof/ops.h @@ -597,12 +597,12 @@ snd_sof_is_chain_dma_supported(struct snd_sof_dev *sd= ev, 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 + * Returns: 0 on success and -ETIMEDOUT upon a timeout. In either * case, the last read value at @addr is stored in @val. Must not * be called from atomic context if sleep_us or timeout_us are used. * --=20 2.39.5 From nobody Wed Nov 27 02:42:35 2024 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 1646315747D; Mon, 14 Oct 2024 08:22:50 +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=1728894173; cv=none; b=OuMmguqN+z85LqKnXCx0/QvZ0TXTojoq+7qd4EnOK/YZMf1hzePmtCh4YKGPnF2jjKdpkCwZ9GleDEYnb6vYQPiwvXRGdn7hbxi8MUrBPhCy0Qz7WCVrhE1eXtuSpI+zgbZhwkPTbq3nx/88In7TXbLe4rgZTaLO10PGqcqRxy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894173; c=relaxed/simple; bh=qifAZvSDJ4oCKAVNUiGd2BZc1rUvRYb11jCH8W1tAvc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DH6Es1JMY99TbuaTwWDmlDIakboAi2QSnmrs2MF50VRnVeMIhu6HE6rC551VDoDwuEYgyza+R61gcUjyWCGmpKra4q9AQGx5wWWsiZ4ehBZbyNEXhYAjUy00IC+x3AgdXiLuo5GAejR3KPzO6Mm/i//GVkYOHKL8Lx3i8ALPk10= 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=DBulGqQq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3lxr/e1p; 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="DBulGqQq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3lxr/e1p" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894169; 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=joTkYfZuYDbUq+yir8wGSuEWOSrlObwkU2FwRn80vkM=; b=DBulGqQqivo+HovK0ZWzPaLAfqSi54oj8a/ajqV+NODU3T81A4UvR9G+3PGcGnr8QYePr1 u+qEbqQorp4wld2ryheKfZFZ5okpBxhBU8/pSpUIBXV4v0Uc0dkK0CBLq8qznnWXObHmwB Z+z+ugP/WyxLa36tb1Bz9XsG8IWkRR0yAlVjTfPhF2z1jK4yepBEpyvlo0Tc64eIkFByNv lPG9rwh6ABJLelVeDa6yUAF/fx2XuTetyVM63wYoYJmIhu91QqZU8w+uIK34sMtwpjy5wi ACHL4Xs4oFcwk/rag0QPSA17e34YPL3PeKGp7TSr4FxUSjDD/NIjN1+pcxic5A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894169; 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=joTkYfZuYDbUq+yir8wGSuEWOSrlObwkU2FwRn80vkM=; b=3lxr/e1pnS/X0qbMGdQ/8zMBUdws2K1T64ougHTi6Cb7SKyLSEJxZEdvp6X0bQeW/0yMFj Ci3sE5nPcdyDdwCg== Date: Mon, 14 Oct 2024 10:22:30 +0200 Subject: [PATCH v3 13/16] 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-13-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda , 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 related 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 millisecond. 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) Reviewed-by: Frederic Weisbecker Reviewed-by: Mark Brown --- v2: fix typos --- 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..d31c9799cab2 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 way longer than requested independent of HZ + * configuration, use fsleep(). See fsleep() for details 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.5 From nobody Wed Nov 27 02:42:35 2024 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 E4251158558; Mon, 14 Oct 2024 08:22:51 +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=1728894174; cv=none; b=VeDxXFnY/g1RtXQh1ruTKp0zTyblqlLgP6i0TXPCRbuO0XTlnRxS3V3wbqzPngHX5GulkhDbsDJQcsC2jjl3cxU3wYuMn77XCaS5tgvp7zVcG5jUi/N4tvwln/6N3NYh00bFI/A25GJ6u9Nc3rn8qsqJmvhxmtpdriJitHreSCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894174; c=relaxed/simple; bh=bzBoPBXvgGgBceKCBKqe7YKjn85sRsKmpKifY22AX2A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BVLMmM7TY5epvz6OunAVuQTZ4vVxHgRLqYXSXHO8UTCy2blbyDGbklhlEq+3naR7v/fIqUMNdQtRY8BQNSRMssJ2jcGG6SPt0AYdaZ+wdaWZ7iUzO7jNa9svuFuQOAOirj0iFNaldowkL+PjVQvr7Qadqnk97ySA7EfozjhUXss= 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=sTMTFJFG; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YiXTsO3q; 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="sTMTFJFG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YiXTsO3q" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894170; 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=kNRLICfcMX53Pl818PecpUhWq4UAyd0n3QQSNiHMS0Q=; b=sTMTFJFGvylVpObZzdv1qmknTg52pZ48YWiroJTZicX+jQy1Mlt0Nwy4njse3ScvsitBPN AarLq6u0hB7vf/sWLsDpPRUwWhPjaaUfsKuxH4QzSlaIYa2GRhvZ8jn7lX9m0aadfwvU4/ r/swaKR5jNTOAIjSbgs2jtN8WnxgN51MlifUV8KxK0Sf+2qxEOIiABHiYuqRWNqNoFXcpJ 5FbJ0AXPMhESnvenWqkAtuZ+/XiP4TvWNm24LGiK4v7SFBWPjXkoMFT80ibjuPZpjjNx3S 990cpnZFVbHZmQZJpWxuwnUePpRA0XkSpRYeXyu2gyUhOoYw2pgWgfACEt8fQA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894170; 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=kNRLICfcMX53Pl818PecpUhWq4UAyd0n3QQSNiHMS0Q=; b=YiXTsO3qLxn3vTSHXPfgV/b1ytZOM/RZ2M/bSg5i6/5WqHxHq3X2mwyl7+SxU5Ckqvkxyg waDWkAxliFM0VODQ== Date: Mon, 14 Oct 2024 10:22:31 +0200 Subject: [PATCH v3 14/16] media: anysee: Fix and remove outdated comment 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-14-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda , Mauro Carvalho Chehab , linux-media@vger.kernel.org, Sebastian Andrzej Siewior anysee driver was transformed to use usbv2 years ago. The comments in anysee_ctrl_msg() still are referencing the old interfaces where msleep() was used. The v2 interfaces also changed over the years and with commit 1162c7b383a6 ("[media] dvb_usb_v2: refactor dvb_usbv2_generic_rw()") the usage of msleep() was gone anyway. Remove FIXME comment and update also comment before call to dvb_usbv2_generic_rw_locked(). Cc: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org Signed-off-by: Anna-Maria Behnsen Reviewed-by: Sebastian Andrzej Siewior Reviewed-by: Mark Brown --- v3: Remove FIXME comment completely --- drivers/media/usb/dvb-usb-v2/anysee.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/media/usb/dvb-usb-v2/anysee.c b/drivers/media/usb/dvb-= usb-v2/anysee.c index 8699846eb416..bea12cdc85e8 100644 --- a/drivers/media/usb/dvb-usb-v2/anysee.c +++ b/drivers/media/usb/dvb-usb-v2/anysee.c @@ -46,24 +46,15 @@ static int anysee_ctrl_msg(struct dvb_usb_device *d, =20 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, slen, state->buf); =20 - /* We need receive one message more after dvb_usb_generic_rw due - to weird transaction flow, which is 1 x send + 2 x receive. */ + /* + * We need receive one message more after dvb_usbv2_generic_rw_locked() + * due to weird transaction flow, which is 1 x send + 2 x receive. + */ ret =3D dvb_usbv2_generic_rw_locked(d, state->buf, sizeof(state->buf), state->buf, sizeof(state->buf)); if (ret) goto error_unlock; =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... - * Fixing that correctly is one of those or both; - * 1) use repeat if possible - * 2) add suitable delay - */ - /* get answer, retry few times if error returned */ for (i =3D 0; i < 3; i++) { /* receive 2nd answer */ --=20 2.39.5 From nobody Wed Nov 27 02:42:35 2024 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 0627C1581F9; Mon, 14 Oct 2024 08:22:52 +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=1728894174; cv=none; b=FfjzW1pYpCOTaA33pFE7aqB5jLjG1O8v9VdS5SEtA60i+oX/n9aXacAw5Cn7MM7VuQB3gto5gd4Wm69xPmW3rQFds//SSfrKvd7DCK0Nvuia3Vwdn81/tpSFlWem0fgbr+zrmii+N0fCzzsjWejfby9KOoeN3IpDKgfMtc3NuC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894174; c=relaxed/simple; bh=ZXAYrVZ4w20Nfm7iIvoXhExNTha7O9fJ6fEz0B1hJfQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MitYa0JS6MumHYWV9H2sqoxfSHH0izvtjf0gxKTEzC074AHcWu5SmaCa2CEx/nx1ZZEpeZD3b4dYGCowsy22gIhl4QGZ64p16RdM4jUciMmlu7+/Eaa9eFPxgIX1sS/Ul7YYp/hi49ZwG7i6/tz5th9Gl+PN7kHSCQ7fr2Vh8Fk= 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=SJBhmkIk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UZnZqTXT; 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="SJBhmkIk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UZnZqTXT" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894170; 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=36D4JZFbM4MmKnsf1c64M6HZW4amllGvs/Baa5CaIKo=; b=SJBhmkIkHOu9CWK84IdUtmfqb+EdcoM2IoKcNz1jyFoI0+DppRMZmjZy4GSlgpy1jZix5s bW11otpF04yvCaL4IhOBRPbXs2EP7/G3CP18CfkOraXBwPxDObOvTV/Mwn3T7tQFplIr21 xj8/sXF0vFc5P3fPcWXraBnT4G0BuvNzJIcJcUdEEt7uBtC+5C7V0nNWq1BFPprMWzL6Yn r99SICyALPZYgEgjxum3BOvUMKnnUJ0uzfkucZPGqScNJCjRUQciPnxCON0htd2l7e7Sgp 2teSTDzN8aIX1UDrGFVtVpYvrasZxi1boXEWEs6qZQMOjNT0kWmVRMnrxIv4Zw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894170; 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=36D4JZFbM4MmKnsf1c64M6HZW4amllGvs/Baa5CaIKo=; b=UZnZqTXT3WVKOuG/92s9qNBLKwnCHO1yiDqhQLp94tHUO7lz4/Th4EtYx/qOfo2ipv1njQ mIUUzeyC/iPVSSAQ== Date: Mon, 14 Oct 2024 10:22:32 +0200 Subject: [PATCH v3 15/16] 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-15-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda The documentation which tries to give advices how to properly inserting delays or sleeps is outdated. The file name is 'timers-howto.rst' which might be misleading 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 Reviewed-by: Frederic Weisbecker Reviewed-by: Mark Brown --- Documentation/timers/delay_sleep_functions.rst | 121 +++++++++++++++++++++= ++++ Documentation/timers/index.rst | 2 +- Documentation/timers/timers-howto.rst | 115 ---------------------= -- 3 files changed, 122 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..49d603a3f113 --- /dev/null +++ b/Documentation/timers/delay_sleep_functions.rst @@ -0,0 +1,121 @@ +.. 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 use hrtimers or timer list timers to provide the requested +sleeping duration. In order to decide which function is the right one to u= se, +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 provide some sort of slack as they are jiffy b= ased + +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.5 From nobody Wed Nov 27 02:42:35 2024 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 720F6158A13; Mon, 14 Oct 2024 08:22:52 +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=1728894174; cv=none; b=moXU8fdcK7VcX3tjK+d19vuwWhTZ3zVKw3orTlBlEi8+wXt8i30fgM9Kh//dQf/FxRU5Qd/wDbikJZ7U4MZYvRr7FrW9PvSlEwZ7EYuVygvvn0RanXb5HRmbvx4MC9N3i9lXMDiqHZ0nf09det5Vu4GlU0+SM+9Rs+lOZv+gH3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728894174; c=relaxed/simple; bh=xqAviz1yKAsmHoh5se7gRuA7GtjuV7HmRGx3G4wcIbI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M8Da1lQhOTJ+mw3zfd5IVgLKYj5vXPhFkN5KSWLak9hxFD1xcOnyzEkuFbmqmFqVpY9tpgmpf6SQyuWZ3ttN4bEDb6tOnr3oDnpW6fDgDFn3/H8OnA4xvH7mxnEK/O/beru40QaNUdOSa7cwLopBphh9j7m9fBgTtTsVY791TZU= 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=29TnFL8+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kkSO+aIp; 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="29TnFL8+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kkSO+aIp" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728894171; 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=wODdgjku5JfjriO9kL1m2ZaFUZK+6PTrhP3Cq+020Qc=; b=29TnFL8+G0QlUT07r9L892yuG/RwhZA4VI/5y7EeVlxMfbYHgCKHbwe7/MkcyBCUFmGfKY oEPmHG/SItqbUOCKOcf+AESoRZYy5ddOJJj4tAqzVvArivXfnJ5q2nJmPKO8Tx8Aq84L0U 4gLX5VfSAC/418xlZEtxbs22OT9zIH1B3IL670jKmCSoJZb+9LUA39GsciA8VvpUoDCefQ lV3ZVU42qeNK2Z9Ca2ysRWwyKt+DTfceUMZIIl2vskzeoioJeot1UStbGll9z/DemMJgL0 nAb6nKYb5UVVy84tntRqYJ0DtnqHvDgH/LCrW4p0YPqvHmWHUl6Ut/0dc4lDyg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728894171; 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=wODdgjku5JfjriO9kL1m2ZaFUZK+6PTrhP3Cq+020Qc=; b=kkSO+aIphjh5eZRw/u89nqWbps1prElRs40uxlHVadU6yHJMV7FrnbC7mAf23UOthbCaMH fjdYqYyjYDfkhdAg== Date: Mon, 14 Oct 2024 10:22:33 +0200 Subject: [PATCH v3 16/16] 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: <20241014-devel-anna-maria-b4-timers-flseep-v3-16-dc8b907cb62f@linutronix.de> References: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> In-Reply-To: <20241014-devel-anna-maria-b4-timers-flseep-v3-0-dc8b907cb62f@linutronix.de> To: Frederic Weisbecker , Thomas Gleixner , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, Len Brown , "Rafael J. Wysocki" , rust-for-linux@vger.kernel.org, Alice Ryhl , FUJITA Tomonori , Andrew Lunn , Anna-Maria Behnsen , Miguel Ojeda , 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: msleep(1) might sleep up to 20ms but only on a HZ=3D100 system. On a HZ=3D1000 system this will= be 2ms. This means, the threshold cannot be hard coded as it depends on HZ (jiffy granularity and timer wheel bucket/level granularity) and also on the required accuracy of the callsite. See msleep() and also the USLEEP_RANGE_UPPER_BOUND value. Remove all broken checks. Update checkpatch documentation accordingly. Cc: Andy Whitcroft Cc: Joe Perches Cc: Dwaipayan Ray Signed-off-by: Anna-Maria Behnsen Reviewed-by: Mark Brown --- v3: Move it to the end of the queue and adapt it to the new patch which removes the link to the outdated documentation before. v2: Rephrase commit message --- Documentation/dev-tools/checkpatch.rst | 4 ---- scripts/checkpatch.pl | 38 ------------------------------= ---- 2 files changed, 42 deletions(-) diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-too= ls/checkpatch.rst index abb3ff682076..f5c27be9e673 100644 --- a/Documentation/dev-tools/checkpatch.rst +++ b/Documentation/dev-tools/checkpatch.rst @@ -466,10 +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. - =20 Comments -------- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 98790fe5115d..34d4b5beda29 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6591,28 +6591,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 function description o= f usleep_range() and udelay().\n" . $herecurr); - } - if ($delay > 2000) { - WARN("LONG_UDELAY", - "long udelay - prefer mdelay; see function description of mdelay(= ).\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 function description= of msleep().\n" . $herecurr); - } - } - # check for comparisons of jiffies if ($line =3D~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) { WARN("JIFFIES_COMPARISON", @@ -7069,22 +7047,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 function d= escription of usleep_range().\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 function desc= ription of usleep_range().\n" . "$here\n$stat\n"); - } - } - # check for naked sscanf if ($perl_version_ok && defined $stat && --=20 2.39.5