Skip to content

Commit b73159f

Browse files
committed
[BATTC][COMPBATT] Move the IOCTL_BATTERY_QUERY_STATUS wait hack to BATTC (reactos#8384)
CORE-20343 The 3-second timeout FIXME (instead of waiting indefinitely), made in the COMPBATT worker thread for the `IOCTL_BATTERY_QUERY_STATUS` case, was done because _*our*_ BATTC handler expects the batteries to always support the BTP (Battery Trip Point) feature for signaling a change of battery status, but in the cases where it isn't supported, any waits it tried for the battery to notify about a status change would never happen. Furthermore, following commit 3a6e0d4, the `SetStatusNotify()` call (_which always fails if the battery doesn't support the BTP feature_) would now always exit the `IOCTL_BATTERY_QUERY_STATUS` handling without any waiting nor battery polling [^1], and this would cause the COMPBATT worker thread to busy-poll again forever. The timeout FIXME is now moved to BATTC, instead of COMPBATT, since the actual fixes should be in BATTC. In particular, it should queue all the query IOCTLs and then serve them, either using the StatusNotify (BTP) functionality if the battery supports it, or if not, do a very-slow battery polling. I've also increased the timeout a little bit more (5 seconds and not 3). [^1]: Per the ACPI specification, it is expected that the operating system performs battery polling if the battery doesn't support BTP, see: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/10_Power_Source_and_Power_Meter_Devices/Power_Source_and_Power_Meter_Devices.html#btp-battery-trip-point
1 parent 54489d6 commit b73159f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

drivers/battery/battc/battc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,13 @@ BatteryClassIoctl(PVOID ClassData,
292292
&BattNotify);
293293
if (!NT_SUCCESS(Status))
294294
{
295-
DPRINT1("SetStatusNotify failed (0x%x)\n", Status);
296-
break;
295+
DPRINT("SetStatusNotify failed (0x%x)\n", Status);
296+
// HACK: Continue anyway; the non-zero timeout will limit polling rate.
297+
// FIXME: Hardcoded (wait for 5 seconds) because ACPI notifications don't work...
298+
BattWait.Timeout = 5000;
299+
// FIXME 2: All these IOCTLs handled in BatteryClassIoctl() should actually
300+
// be queued and be serviced by a worker thread that also handles the slow
301+
// battery polling, in case the battery doesn't support status notifications.
297302
}
298303

299304
ExAcquireFastMutex(&BattClass->Mutex);

drivers/battery/compbatt/compbatt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ CompBattSystemControl(
8080
* location which contains the data of the individual battery.
8181
*
8282
* @param[in] Context
83-
* An aribtrary pointer that points to context data, this paramater
83+
* An arbitrary pointer that points to context data, this parameter
8484
* is unused.
8585
*
8686
* @return
@@ -355,7 +355,7 @@ CompBattMonitorIrpCompleteWorker(
355355

356356
/* Setup the necessary data to read battery status */
357357
BatteryData->WaitStatus.BatteryTag = BatteryData->Tag;
358-
BatteryData->WaitStatus.Timeout = 3000; // FIXME: Hardcoded (wait for 3 seconds) because we do not have ACPI notifications implemented yet...
358+
BatteryData->WaitStatus.Timeout = -1;
359359

360360
RtlCopyMemory(&BatteryData->WorkerBuffer.WorkerWaitStatus,
361361
&BatteryData->WaitStatus,

0 commit comments

Comments
 (0)