From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
To: Shan Rizvi <shan@rizvi.nu>, Jonathan Cameron <jic23@kernel.org>,
Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-input@vger.kernel.org
Subject: Re: iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor
Date: Mon, 30 Nov 2026 11:03:14 -0800 [thread overview]
Message-ID: <4c44d7f40b820dd1cb78b77d46747d291a4fc5de.camel@linux.intel.com> (raw)
In-Reply-To: <179606075544.1070896.11410129502695294348@rizvi.nu>
[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]
On Mon, 2026-11-30 at 12:45 -0500, Shan Rizvi wrote:
> On Mon, 2026-11-30 at 05:07 -0800, Srinivas Pandruvada wrote:
> > I think I want to fix by setting report interval rather than
> > ignoring
> > that sensor. Try the attached.
>
> Tested on the HP 8EA2 (Chicony 04F2:B872) against 7.2.15:
>
> - Initial HID-SENSOR-200011.6.auto sampling frequency: 0.000100 Hz.
> - First read of in_proximity0_raw returned 0 in 9560 ms
> (runtime_status
> transitioned to active, no hung task, no runtime PM underflow).
> - Two concurrent reads of in_proximity0_raw both returned 0 cleanly
> in
> 10237 ms with no D-state block.
> - After runtime autosuspend (4 s idle -> suspended), a subsequent
> read
> returned 0 in 9303 ms and in_proximity0_sampling_frequency updated
> from 0.000100 Hz to 0.500000 Hz (2000 ms).
> - The working sensors (HID-SENSOR-200011.3.auto 10 Hz prox and
> HID-SENSOR-200041.4.auto 10 Hz ALS) continued reading normally, and
> module unload/reload completed cleanly.
>
> One small observation: in_proximity0_sampling_frequency still read
> 0.000100 Hz immediately after the first read and only switched to
> 0.500000 Hz after the post-autosuspend power-on (likely because
> hid_sensor_limit_poll_value() runs before power_state/report_state
> are
> written on the first D0 transition). Either way, the sleep was
> bounded
> at 4 s from the very first read and the hang is completely gone.
>
Changed the order, please try.
Thanks,
Srinivas
> Tested-by: Shan Rizvi <shan@rizvi.nu>
>
> Thanks,
> Shan
[-- Attachment #2: 0001-iio-hid-sensors-Limit-the-poll-interval-when-powerin.patch --]
[-- Type: text/x-patch, Size: 3726 bytes --]
From 0822bc3f280ddaf047fc3cc50f6d0362cb61decf Mon Sep 17 00:00:00 2001
From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Date: Mon, 30 Nov 2026 05:03:06 -0800
Subject: [PATCH v2] iio: hid-sensors: Limit the poll interval when powering on
When a sensor is powered on, _hid_sensor_power_state() waits for twice
the poll interval read from the sensor, so that the first sample is
available. On some platforms the poll interval is not initialized and
has a very large value. This results in a very long sleep in
msleep_interruptible(), and the user space process reading the sensor
appears to hang.
Raw sample reads time out after 5 seconds in
sensor_hub_input_attr_get_raw_value(), so there is no point in waiting
longer than that. When the poll interval is more than 2 seconds, set
the poll interval to 2 seconds, which limits the wait to 4 seconds.
Read and set the poll interval after the power state and reporting
state are set, as the sensor may not accept a new poll interval while
it is not powered on.
Also when reading the poll interval fails, hid_sensor_read_poll_value()
returns -EINVAL, which is passed to msleep_interruptible() as a huge
unsigned value. Don't wait in this case.
Fixes: 2b89635e9a9e ("iio: hid_sensor_hub: Common PM functions")
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
.../common/hid-sensors/hid-sensor-trigger.c | 43 ++++++++++++++++---
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index 60808e2430ca..8e5c06d59d63 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -82,11 +82,40 @@ static const struct iio_dev_attr *hid_sensor_fifo_attributes[] = {
NULL,
};
+/*
+ * Raw sample reads time out after 5 seconds, and the power on path waits for
+ * twice the poll interval. Limit the poll interval, so that the wait is within
+ * the timeout.
+ */
+#define HID_SENSOR_MAX_POLL_INTERVAL_MS 2000
+
+static s32 hid_sensor_limit_poll_value(struct hid_sensor_common *st)
+{
+ s32 poll_value, value;
+
+ poll_value = hid_sensor_read_poll_value(st);
+ if (poll_value < 0)
+ return 0;
+
+ if (poll_value <= HID_SENSOR_MAX_POLL_INTERVAL_MS)
+ return poll_value;
+
+ if (st->poll.units == HID_USAGE_SENSOR_UNITS_SECOND)
+ value = HID_SENSOR_MAX_POLL_INTERVAL_MS / MSEC_PER_SEC;
+ else
+ value = HID_SENSOR_MAX_POLL_INTERVAL_MS;
+
+ if (!sensor_hub_set_feature(st->hsdev, st->poll.report_id,
+ st->poll.index, sizeof(value), &value))
+ st->poll_interval = value;
+
+ return HID_SENSOR_MAX_POLL_INTERVAL_MS;
+}
+
static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
{
int state_val;
int report_val;
- s32 poll_value = 0;
if (state) {
if (sensor_hub_device_open(st->hsdev))
@@ -102,8 +131,6 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
st->report_state.report_id,
st->report_state.index,
HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM);
-
- poll_value = hid_sensor_read_poll_value(st);
} else {
int val;
@@ -143,8 +170,14 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
sensor_hub_get_feature(st->hsdev, st->power_state.report_id,
st->power_state.index,
sizeof(state_val), &state_val);
- if (state && poll_value)
- msleep_interruptible(poll_value * 2);
+ if (state) {
+ s32 poll_value;
+
+ /* The sensor may ignore the poll interval when not powered on */
+ poll_value = hid_sensor_limit_poll_value(st);
+ if (poll_value)
+ msleep_interruptible(poll_value * 2);
+ }
return 0;
}
--
2.56.0
prev parent reply other threads:[~2026-11-30 19:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 2:03 iio: hid-sensor-trigger: unclamped msleep_interruptible(poll_value * 2) stalls runtime PM for hours on Chicony 04F2:B872 secondary proximity sensor Shan Rizvi
2026-11-29 14:37 ` Srinivas Pandruvada
2026-11-29 17:26 ` Shan Rizvi
2026-11-29 17:54 ` Srinivas Pandruvada
2026-11-29 19:18 ` Shan Rizvi
2026-11-30 13:07 ` Srinivas Pandruvada
2026-11-30 17:45 ` Shan Rizvi
2026-11-30 19:03 ` Srinivas Pandruvada [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4c44d7f40b820dd1cb78b77d46747d291a4fc5de.camel@linux.intel.com \
--to=srinivas.pandruvada@linux.intel.com \
--cc=bentiss@kernel.org \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=shan@rizvi.nu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox