diff --git a/kernel-open/nvidia/hwmon_adapter.c b/kernel-open/nvidia/hwmon_adapter.c index 5aca874d..166ecaff 100644 --- a/kernel-open/nvidia/hwmon_adapter.c +++ b/kernel-open/nvidia/hwmon_adapter.c @@ -94,6 +94,7 @@ struct nv_rs_hwmon_slot { spinlock_t sample_lock; u64 mirror_seq; bool has_poll; + bool attempted; unsigned long last_poll_jiffies; unsigned long live_stamps[NV_RS_HWMON_LIVE_COUNT]; u64 pub_seq[NV_RS_HWMON_LIVE_COUNT]; @@ -194,16 +195,18 @@ static void nv_rs_hwmon_maybe_refresh(struct nv_rs_hwmon_slot *slot) poll_ms = NV_RS_HWMON_POLL_MAX_MS; ttl = msecs_to_jiffies(poll_ms); - /* Rate-limit attempts on last_poll_jiffies alone so a failing cold - * start retries at most once per window. A failed poll does not - * count as a successful poll; unsupported providers are retried - * instead of latched, so a runtime that starts later still - * acquires. */ - if (time_before(jiffies, READ_ONCE(slot->last_poll_jiffies) + ttl)) + /* Rate-limit repeated attempts with the poll interval, but never + * gate the very first attempt: a freshly registered slot must + * acquire immediately (the zero-initialized attempt timestamp is + * a sentinel, not a real attempt). Failures and unsupported + * providers stay rate-limited once an attempt has happened. */ + if (READ_ONCE(slot->attempted) && + time_before(jiffies, READ_ONCE(slot->last_poll_jiffies) + ttl)) return; mutex_lock(&slot->poll_lock); - if (time_before(jiffies, READ_ONCE(slot->last_poll_jiffies) + ttl)) { + if (READ_ONCE(slot->attempted) && + time_before(jiffies, READ_ONCE(slot->last_poll_jiffies) + ttl)) { mutex_unlock(&slot->poll_lock); return; } @@ -228,6 +231,7 @@ static void nv_rs_hwmon_maybe_refresh(struct nv_rs_hwmon_slot *slot) * normally. */ nv_rs_rmapi_node_unlock(); WRITE_ONCE(slot->last_poll_jiffies, jiffies); + WRITE_ONCE(slot->attempted, true); mutex_unlock(&slot->poll_lock); return; } @@ -271,6 +275,7 @@ static void nv_rs_hwmon_maybe_refresh(struct nv_rs_hwmon_slot *slot) /* Rate-limit the next attempt regardless of the outcome. */ WRITE_ONCE(slot->last_poll_jiffies, jiffies); + WRITE_ONCE(slot->attempted, true); if (rc == 0) WRITE_ONCE(slot->has_poll, true); mutex_unlock(&slot->poll_lock); @@ -550,6 +555,7 @@ int nv_rs_hwmon_register_dev(struct device *dev, u32 gpu_id) /* Start with valid_mask = 0 (-ENODATA for every sensor) until live telemetry * arrives; never publish fabricated placeholder readings (#141). */ slot->has_poll = false; + slot->attempted = false; slot->last_poll_jiffies = 0; memset(slot->live_stamps, 0, sizeof(slot->live_stamps)); memset(slot->pub_seq, 0, sizeof(slot->pub_seq)); @@ -708,6 +714,7 @@ void nv_rs_hwmon_mark_polled(u32 gpu_id) * exclusively from a publication that carries * VALID_TEMP. */ WRITE_ONCE(slot->last_poll_jiffies, jiffies); + WRITE_ONCE(slot->attempted, true); return; } } diff --git a/tests/hwmon-mock/fixture.c b/tests/hwmon-mock/fixture.c index 14b053fd..9ffcde29 100644 --- a/tests/hwmon-mock/fixture.c +++ b/tests/hwmon-mock/fixture.c @@ -495,6 +495,18 @@ static void test_default_interval_never_starves_a_healthy_provider(void) nv_rs_hwmon_unregister_dev(&mock_dev); } +static void test_cold_start_acquires_immediately(void) +{ + reset_slot(); + mock_jiffies = 100; /* before the poll interval elapses since boot */ + CHECK(nv_rs_hwmon_register_dev(&mock_dev, 20) == 0, "register"); + CHECK(read_temp() == 40000, "first read acquires immediately, no sentinel throttle"); + CHECK(mock_poll_calls == 1, "exactly one poll"); + CHECK(read_temp() == 40000, "fresh reading served"); + CHECK(mock_poll_calls == 1, "no second poll inside the window"); + nv_rs_hwmon_unregister_dev(&mock_dev); +} + int main(void) { failures = 0; @@ -518,6 +530,7 @@ int main(void) test_long_poll_interval_honors_request_and_exposes_expiry(); test_intermediate_poll_interval_returns_enodata_then_recovers(); test_default_interval_never_starves_a_healthy_provider(); + test_cold_start_acquires_immediately(); printf("%s\n", failures ? "FAILED" : "ALL PASSED"); return failures ? 1 : 0; }