[BUG] sched/rt: RLIMIT_RTTIME not reset after blocking under SCHED_OTHER

From: l I

Date: Sun Nov 08 2026 - 11:23:48 EST


Hi all,

The RLIMIT_RTTIME counter does not appear to reset when a task switches
from SCHED_FIFO to SCHED_OTHER and then blocks. Repeating this sequence
causes RT runtime to accumulate across sleeps, eventually triggering
SIGXCPU even though each RT execution interval is below the limit.

The reproducer below sets RLIMIT_RTTIME to 50 ms soft / 200 ms hard,
then repeats:
- Run for 8 ms under SCHED_FIFO.
- Switch to SCHED_OTHER.
- Block in nanosleep() for 10 ms.

Expected: blocking sleep resets the RT runtime counter.
Actual: the process is terminated by SIGXCPU.

Reproduced on Ubuntu 7.0.0-38-generic (x86_64).
The missing reset also appears present by source inspection in the mainline.

Example:

#define _GNU_SOURCE
#include <sched.h>
#include <sys/resource.h>
#include <time.h>

static long long cpu_ns(void)
{
struct timespec t;
if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t))
return -1;
return (long long)t.tv_sec * 1000000000 + t.tv_nsec;
}

int main(void)
{
struct rlimit limit = {50000, 200000}; /* soft 50ms, hard 200ms */
struct sched_param fifo = {.sched_priority = 1};
struct sched_param normal = {.sched_priority = 0};

if (setrlimit(RLIMIT_RTTIME, &limit))
return 1;

for (int i = 0; i < 80; i++) {
if (sched_setscheduler(0, SCHED_FIFO, &fifo))
return 1;

long long start = cpu_ns(), now;
if (start < 0)
return 1;
do {
now = cpu_ns();
if (now < 0)
return 1;
} while (now - start < 8000000); /* 8ms */

if (sched_setscheduler(0, SCHED_OTHER, &normal))
return 1;

struct timespec sleep = {.tv_nsec = 10000000}; /* 10ms */
/* RT runtime should reset on blocking sleep, even under SCHED_OTHER. */
if (nanosleep(&sleep, 0))
return 1;
}
return 0;
}



Best regards,
Geonwoo Ahn