git: fde43820f31d - main - acpi: Tasks: Precisely report the maximum number of slots used
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 13 Nov 2026 18:49:52 UTC
The branch main has been updated by olce:
URL: https://cgit.FreeBSD.org/src/commit/?id=fde43820f31dbcec64e41a1ffe3fe1b799e09d04
commit fde43820f31dbcec64e41a1ffe3fe1b799e09d04
Author: Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2026-10-02 08:11:31 +0000
Commit: Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-11-13 18:41:20 +0000
acpi: Tasks: Precisely report the maximum number of slots used
To this end, store the actual number of busy slots instead of the index
of the final slot selected (off by one), and fix races when updating
'acpi_tasks_hiwater'.
The race is that it could happen that a first thread enqueued a task at
a higher index than the current maximum, followed by a second one
enqueuing at some even higher index, with the first thread updating
'acpi_tasks_hiwater' while the second was exactly after the 'if (i >
acpi_tasks_hiwater)' but just before attempting the atomic_cmpset_int()
that updates 'acpi_task_hiwater', which then would fail silently (the
return value was ignored) leading to the real maximum not being
recorded.
Fix the race by simply testing the return value of atomic_cmpset_int()
and retrying. Use an explicit atomic_load_int() for the guard (that
compiles to a regular load, so this change is cosmetic).
Note that the atomic_cmpset_int() loop can at most be executed a number
of times equal to the reported 'acpi_tasks_hiwater', which appears to be
low in practice (~#CPUS).
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D60375
---
sys/dev/acpica/Osd/OsdSchedule.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/sys/dev/acpica/Osd/OsdSchedule.c b/sys/dev/acpica/Osd/OsdSchedule.c
index badb15dd009f..2684e13ff86a 100644
--- a/sys/dev/acpica/Osd/OsdSchedule.c
+++ b/sys/dev/acpica/Osd/OsdSchedule.c
@@ -155,7 +155,7 @@ static ACPI_STATUS
acpi_task_enqueue(int priority, ACPI_OSD_EXEC_CALLBACK Function, void *Context)
{
struct acpi_task_ctx *at;
- int i;
+ int hiwater, i;
for (at = NULL, i = 0; i < acpi_max_tasks; i++)
if (atomic_cmpset_int(&acpi_tasks[i].at_flag, ACPI_TASK_FREE,
@@ -165,8 +165,11 @@ acpi_task_enqueue(int priority, ACPI_OSD_EXEC_CALLBACK Function, void *Context)
break;
}
- if (i > acpi_tasks_hiwater)
- atomic_cmpset_int(&acpi_tasks_hiwater, acpi_tasks_hiwater, i);
+ while (hiwater = atomic_load_int(&acpi_tasks_hiwater), i + 1 > hiwater) {
+ if (atomic_cmpset_int(&acpi_tasks_hiwater, hiwater, i + 1))
+ break;
+ cpu_spinwait();
+ }
if (at == NULL) {
printf("AcpiOsExecute: failed to enqueue task, consider increasing "