public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ACPI: Replace msleep() with usleep_range() in acpi_os_sleep().
@ 2024-11-15 23:11 Len Brown
  2024-11-18 11:03 ` Rafael J. Wysocki
  0 siblings, 1 reply; 21+ messages in thread
From: Len Brown @ 2024-11-15 23:11 UTC (permalink / raw)
  To: rafael
  Cc: anna-maria, tglx, peterz, frederic, corbet, akpm, linux-acpi,
	linux-pm, linux-kernel, Len Brown, Arjan van de Ven, Todd Brandt

From: Len Brown <len.brown@intel.com>

Replace msleep() with usleep_range() in acpi_os_sleep().

This has a significant user-visible performance benefit
on some ACPI flows on some systems.  eg. Kernel resume
time of a Dell XPS-13-9300 drops from 1943ms to 1127ms (42%).

usleep_range(min, min) is used because there is scant
opportunity for timer coalescing during ACPI flows
related to system suspend, resume (or initialization).

ie. During these flows usleep_range(min, max) is observed to
be effectvely be the same as usleep_range(max, max).

Similarly, msleep() for long sleeps is not considered because
these flows almost never have opportunities to coalesce
with other activity on jiffie boundaries, leaving no
measurably benefit to rounding up to jiffie boundaries.

Background:

acpi_os_sleep() supports the ACPI AML Sleep(msec) operator,
and it must not return before the requested number of msec.

Until Linux-3.13, this contract was sometimes violated by using
schedule_timeout_interruptible(j), which could return early.

Since Linux-3.13, acpi_os_sleep() uses msleep(),
which doesn't return early, but is still subject
to long delays due to the low resolution of the jiffie clock.

Linux-6.12 removed a stray jiffie from msleep: commit 4381b895f544
("timers: Remove historical extra jiffie for timeout in msleep()")
The 4ms savings is material for some durations,
but msleep is still generally too course. eg msleep(5)
on a 250HZ system still takes 11.9ms.

System resume performance of a Dell XPS 13 9300:

Linux-6.11:
msleep HZ 250	2460 ms

Linux-6.12:
msleep HZ 250	1943 ms
msleep HZ 1000	1233 ms
usleep HZ 250	1127 ms
usleep HZ 1000	1130 ms

Closes: https://bugzilla.kernel.org/show_bug.cgi?id=216263
Signed-off-by: Len Brown <len.brown@intel.com>
Suggested-by: Arjan van de Ven <arjan@linux.intel.com>
Tested-by: Todd Brandt <todd.e.brandt@intel.com>
---
 drivers/acpi/osl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 70af3fbbebe5..daf87e33b8ea 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -607,7 +607,9 @@ acpi_status acpi_os_remove_interrupt_handler(u32 gsi, acpi_osd_handler handler)
 
 void acpi_os_sleep(u64 ms)
 {
-	msleep(ms);
+	u64 us = ms * USEC_PER_MSEC;
+
+	usleep_range(us, us);
 }
 
 void acpi_os_stall(u32 us)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2024-11-21 10:33 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-15 23:11 [PATCH v2] ACPI: Replace msleep() with usleep_range() in acpi_os_sleep() Len Brown
2024-11-18 11:03 ` Rafael J. Wysocki
2024-11-18 11:38   ` Hans de Goede
2024-11-18 12:02     ` Rafael J. Wysocki
2024-11-18 12:10       ` Hans de Goede
2024-11-18 12:22         ` Rafael J. Wysocki
2024-11-20  9:01       ` Pierre Gondois
2024-11-20 12:06         ` Dietmar Eggemann
2024-11-20 12:59           ` Pierre Gondois
2024-11-18 14:35   ` Arjan van de Ven
2024-11-19 13:42     ` Rafael J. Wysocki
2024-11-19 15:08       ` Arjan van de Ven
2024-11-20 18:03         ` Rafael J. Wysocki
2024-11-20 18:37           ` Arjan van de Ven
2024-11-20 18:49             ` Rafael J. Wysocki
2024-11-20 18:54               ` Len Brown
2024-11-20 19:27                 ` Rafael J. Wysocki
2024-11-20 19:18               ` Arjan van de Ven
2024-11-20 19:41                 ` Rafael J. Wysocki
2024-11-21 10:33                   ` Len Brown
2024-11-20 18:35   ` Len Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox