From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=158.69.130.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147086; b=zH9LMDRaCpa8vuJlQFNBhR1m7x/UOCUz6OV7Zy4x///ukXvY7pCGScIo/7Tfcl4vHDxa b57UG1MuDwJSOVtXwDzRrG0F9aLSE8+B9r8B7zFPvwIZSioGGRtXO8L0ryuku4ECFMhze u47fiWHYx3udtCFZKMEvfjvPMkFx7AsbydCiUV5SKrWdTPn0+1u1Hi2F5mepkofdM+yvA YcuI6C4duTYmWi/OyhLfMfshwuAaaGupXjTCweWmF6pvT/JfLTrqXQGmMkhAVr0+oZHei FyGZ72gqnZgvXGho0FH4NtSyqmG7aT5t1Vfcvae6UDIFdCYmq4bTI2u0UPr7Euyb3QA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147086; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=QfF7L2yUnlHgFi4DU7BXiUN4mEKoUb928kRlIMaSWPE=; b=OYh1BnU8YQEwn9KcR0LRqkUxNZ7FPnCRfEv+QRalmmvgaiRgf3X7BiGKCa4VZiYFskSE rv2Epq2z1a0ZYG9X6UVbne3Y7d/r9olhehs9ERbSiA0PnvTCdt8CEiZTtqSg8jzrjNGSV GNmgB4GbHCH9iyIcTz5xaoW1JVOX9rEwrayDAWuueTIPdxMwHQuWSEI7potdpihhl84I/ yUqLVNhI3DE8SCxMakWmuo7bpUakFk+XEaottb5WQdjVHJgzj5mF66YLnYuRdOHGK5X3J cKQB0INN8SJSxAg51bLELX5fqY9yAGKe0otTuNq8J5m9TBhi0MakYlkTdxRrIAo634A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=Gv7CUcOU; arc=none smtp.remote-ip=158.69.130.18 Received: from smtpout.efficios.com (smtpout.efficios.com [158.69.130.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69E0D606B651; Tue, 1 Dec 2026 17:44:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 69E0D606B651 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=Gv7CUcOU DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796147079; bh=QfF7L2yUnlHgFi4DU7BXiUN4mEKoUb928kRlIMaSWPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gv7CUcOUqO2ODsadB27o9ZaT/WDt5hyLKq+3EWjQZ/DdwR+QektG6czutaOIYeAsO q0jzVuw1BbeuddP/AoauRtzDs37JzUG65sXMtf3x9uOKkcptbRp4SrEIE0NfihDfBh xnL4UX5pwPmRaXEjU8fTjHr7tSyaVMdvGqH0GwmOVXQA+FrpFdgLmSRs6A0wtnHOx2 EHVIbvA3bUEeO4ved60Pq/rmrvQ0rmG6IFQuXsjmmEjShEvn7jUKojU1XuliFTRpap fIydSDRPTgBpy356JswHt9loYlogRrBLiu6EPpYfP1HR7vwt4OSEdFjJJx0QWq73C6 QDcz3I0xJi7QQ== Received: from thinkos.internal.efficios.com (mtl.efficios.com [216.120.195.104]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jf7Yz40BszYQh; Tue, 01 Dec 2026 12:44:39 -0500 (EST) From: Mathieu Desnoyers To: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org Cc: Mathieu Desnoyers , tglx@kernel.org, will@kernel.org, boqun@kernel.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, luca.abeni@santannapisa.it, tommaso.cucinotta@gmail.com, mathieu.poirier@linaro.org, longman@redhat.com, ridong.chen@linux.dev, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, shuah@kernel.org, bigeasy@linutronix.de, clrkwllms@kernel.org, parri.andrea@gmail.com, m.szyprowski@samsung.com, kayracizmeci@gmail.com, weihengqiuu@gmail.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev, oleg@redhat.com, brauner@kernel.org Subject: [PATCH v13 35/36] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test Date: Tue, 1 Dec 2026 12:44:29 -0500 Message-ID: X-Mailer: git-send-email 2.47.3 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add two cases to deadline_bw_test. The comment above each case gives its scenario. Each case fails without one fix of this series: - pi_departed_offline_boost. A task leaves SCHED_DEADLINE while its root domain still counts its bandwidth. Then the CPU recorded with that bandwidth goes offline. The rebuild of the accounting that follows drops the bandwidth. A deadline waiter then boosts the task back into the class. The case checks that total_bw counts the task again. The fix is "sched/deadline: Count again a departed task that a boost brings back". Without it, the case failed in every run. - pi_deboost_during_rebuild. The timeout of a deadline waiter deboosts a task while a rebuild of the accounting walks the task list. The case checks that total_bw still counts the task right after the rebuild. The fix is "sched/deadline: Count a task that departs while a rebuild walks the tasks". pi_deboost_during_rebuild tests a race. It runs rounds for 25s, and fails at the first round where total_bw misses the task. A filler process of 1000 threads is forked before the task. The walk meets these threads first, so the race window is wider. Without the fix, 35 of 43 runs failed. pi_departed_offline_boost needs 4 housekeeping CPUs, two of them hotpluggable. pi_deboost_during_rebuild needs 5. Each case skips without them. With the whole series, both cases pass in every run. No kernel warning is logged. Signed-off-by: Mathieu Desnoyers --- .../sched/deadline/deadline_bw_test.c | 487 +++++++++++++++++- 1 file changed, 481 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/sched/deadline/deadline_bw_test.c b/tools/testing/selftests/sched/deadline/deadline_bw_test.c index bca333d5498c..e68d9437580f 100644 --- a/tools/testing/selftests/sched/deadline/deadline_bw_test.c +++ b/tools/testing/selftests/sched/deadline/deadline_bw_test.c @@ -40,15 +40,16 @@ * hotplug cases, and the cases with no_hp set, which take no CPU * offline. The test skips the hotplug cases if no CPU can go offline. It * still runs the no_hp ones. - * death_zombie_hotplug takes CPUs offline too, but it is in p_cases[]: it - * needs the cpuset setup of those cases. + * death_zombie_hotplug and pi_departed_offline_boost take CPUs offline + * too, but they are in p_cases[]: they need the cpuset setup of those + * cases. * * The server cases change the fair server of a CPU through debugfs, and * the test then puts it back. * * The test needs root, deadline admission control and 3 housekeeping - * CPUs. Some cases need 4. Most also need the cgroup v2 cpuset - * controller. Some need debugfs or CPU hotplug. Twenty-nine need + * CPUs. Some cases need 4, one needs 5. Most also need the cgroup v2 + * cpuset controller. Some need debugfs or CPU hotplug. Twenty-nine need * isolcpus="domain" at boot. */ #define _GNU_SOURCE @@ -8338,8 +8339,9 @@ static int random_mix(void) } /* - * CPU hotplug, from the main process, with no P. Two cases below run with - * P instead: death_zombie_hotplug and pi_departed_moved. + * CPU hotplug, from the main process, with no P. Three cases below run + * with P instead: death_zombie_hotplug, pi_departed_moved and + * pi_departed_offline_boost. */ static int hp_cpu = -1; @@ -8928,6 +8930,163 @@ static int pi_departed_moved(void) return ret; } +/* + * Q is a partition root of CPUs X and Y. The owner is a deadline task of + * 200ms every 2s in Q. The steps: + * 1. The owner takes shm_lock, runs 180ms and sleeps on X. Its 0-lag + * time is about 1.6s ahead. + * 2. The case switches the owner to SCHED_OTHER. The root domain of Q + * keeps its bandwidth until the 0-lag time. The kernel records X with + * that bandwidth. + * 3. The case pins the owner to Y and wakes it up. It runs on Y, then + * sleeps there. The record stays X. + * 4. The case takes X offline, which rebuilds the accounting. The + * recorded CPU is no longer active, so the rebuild drops the + * bandwidth of the owner. + * 5. A deadline waiter of 5ms every 50ms, outside Q, blocks on shm_lock. + * It boosts the owner back into the class. + * + * The boost must add the bandwidth of the owner to this_bw of Y, and to + * total_bw of Q. Once the owner and the waiter are gone, past the 0-lag + * time, total_bw of Q must be what it was at the start. + */ +static int pi_departed_offline_boost(void) +{ + int cpu[2] = { top_cpu(3), top_cpu(2) }, x, y, ret = KSFT_FAIL; + long long base, bw, off, boosted; + long this0, this1, running; + pid_t owner = -1, waiter = -1; + char cpus[32]; + cpu_set_t set; + uint64_t t; + + if (ncpus < 4 || !cpu_hotpluggable(cpu[0]) || !cpu_hotpluggable(cpu[1])) { + ksft_print_msg("needs 4 non-isolated CPUs, 2 hotpluggable beside P\n"); + return KSFT_SKIP; + } + snprintf(cpus, sizeof(cpus), "%d,%d", cpu[0], cpu[1]); + if (make_partition_cpus(cg_q, cpus)) { + ksft_print_msg("no partition root Q of CPUs %s\n", cpus); + remove_partition(cg_q); + return KSFT_SKIP; + } + base = total_bw_of(cpu[0]); + if (base < 0 || rq_bw_of(cpu[0], &this0, &running)) { + ksft_print_msg("no total_bw or this_bw in /sys/kernel/debug/sched/debug\n"); + remove_partition(cg_q); + return KSFT_SKIP; + } + if (shm_lock_init()) { + remove_partition(cg_q); + return KSFT_SKIP; + } + bw = (ZOMBIE_RUNTIME << 20) / ZOMBIE_PERIOD; /* as to_ratio() */ + mv_state[1] = 0; + mv_state[3] = 0; + owner = fork_child("the owner of the lock"); + if (!owner) { + signal(SIGUSR1, no_op); + if (enter(cg_q, getpid()) || pthread_mutex_lock(shm_lock) || + set_deadline(0, ZOMBIE_RUNTIME, ZOMBIE_PERIOD)) { + mv_state[0] = -1; + _exit(1); + } + /* 20ms left: the 0-lag time is 200ms before the deadline. */ + spin_ns(ZOMBIE_RUNTIME - 20 * NSEC_PER_MSEC); + mv_state[0] = 1; + while (!mv_state[3]) + pause(); + mv_state[1] = 1; + for (;;) + pause(); + } + if (owner < 0 || child_up("the owner of the lock", 0)) + goto out; + t = now_ns(); + if (wait_for(100, proc_state_of(owner) == 'S')) { + ksft_print_msg("the owner is not asleep\n"); + goto out; + } + /* Step 2. Asleep, the owner departs from the CPU it sleeps on. */ + if (set_other(owner)) { + ksft_print_msg("the owner cannot leave SCHED_DEADLINE\n"); + goto out; + } + x = task_cpu_of(owner); + if (x != cpu[0] && x != cpu[1]) { + ksft_print_msg("the owner sleeps on CPU %d, not in Q\n", x); + goto out; + } + y = x == cpu[0] ? cpu[1] : cpu[0]; + /* Step 3 */ + CPU_ZERO(&set); + CPU_SET(y, &set); + if (sched_setaffinity(owner, sizeof(set), &set)) { + ksft_print_msg("the owner cannot be pinned to CPU %d: %s\n", y, strerror(errno)); + goto out; + } + mv_state[3] = 1; + kill(owner, SIGUSR1); + if (wait_state(&mv_state[1], 1) || wait_for(500, proc_state_of(owner) == 'S') || + task_cpu_of(owner) != y) { + ksft_print_msg("the owner did not move to CPU %d\n", y); + goto out; + } + /* Step 4 */ + if (cpu_online(x, 0)) { + ksft_print_msg("CPU %d cannot go offline\n", x); + goto out; + } + off = total_bw_of(y); + if (rq_bw_of(y, &this0, &running)) { + ksft_print_msg("no this_bw of CPU %d\n", y); + goto online; + } + /* Step 5 */ + waiter = lock_waiter(); + if (waiter < 0 || wait_state(&mv_state[2], 1)) { + ksft_print_msg("no waiter\n"); + goto online; + } + sleep_ns(50 * NSEC_PER_MSEC); /* blocked, boosting the owner */ + if (prio_of(owner) != DL_TASK_PRIO) { + ksft_print_msg("the owner is not boosted: prio %d\n", prio_of(owner)); + goto online; + } + boosted = total_bw_of(y); + if (rq_bw_of(y, &this1, &running)) { + ksft_print_msg("no this_bw of CPU %d\n", y); + } else if (now_ns() - t > NSEC_PER_SEC) { + ksft_print_msg("the steps took over 1s: the 0-lag time may be past\n"); + ret = KSFT_SKIP; + } else if (this1 - this0 != bw) { + ksft_print_msg("the boost adds %ld to this_bw of CPU %d, %lld expected\n", + this1 - this0, y, bw); + } else if (boosted != off + bw) { + ksft_print_msg("total_bw of Q: %lld boosted, %lld expected%s\n", + boosted, off + bw, + boosted == off ? ": the owner is not counted" : ""); + } else { + ret = KSFT_PASS; + } +online: + reap(waiter); + cpu_up(x); +out: + reap(owner); + if (ret == KSFT_PASS) { + sleep_ns(ZOMBIE_PERIOD); /* past the 0-lag time of the owner */ + off = total_bw_of(cpu[0]); + if (off != base) { + ksft_print_msg("total_bw of Q past the 0-lag time: %lld, %lld expected\n", + off, base); + ret = KSFT_FAIL; + } + } + remove_partition(cg_q); + return ret; +} + /* * The bandwidth of a fair server must leave the root domain with its CPU * and come back with it, whatever its size. Probe the housekeeping root @@ -12596,6 +12755,320 @@ static int affinity_vs_setattr(void) return ret; } +/* A deboost against a rebuild of the accounting */ + +#define RACE_T_RUNTIME (20 * NSEC_PER_MSEC) +#define RACE_T_PERIOD (200 * NSEC_PER_MSEC) +#define RACE_W_RUNTIME (5 * NSEC_PER_MSEC) +#define RACE_W_PERIOD (50 * NSEC_PER_MSEC) +#define RACE_FILLERS 1000 +#define RACE_SECS 25 + +/* + * The state that pi_deboost_during_rebuild() shares with its processes, + * in shared memory. T and W are the threads that its comment describes. + * go and w_go count the rounds of T and W. t_ready and w_done tell the + * case that a round of T or of W is done. + */ +static struct race_shm { + atomic_int go, t_ready, w_go, w_blocked, w_done, w_err, fill; + _Atomic pid_t t_tid, w_tid; + _Atomic int64_t w_abs, w_ret; +} *rs; + +/* The priority inheritance mutex of T and W, threads of one process */ +static pthread_mutex_t race_m; + +static int64_t realtime_ns(void) +{ + struct timespec ts; + + clock_gettime(CLOCK_REALTIME, &ts); + return (int64_t)ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec; +} + +/* Wait for the futex @f, in shared memory, to change from @val. */ +static void wait_change(atomic_int *f, int val) +{ + while (*f == val) + syscall(SYS_futex, f, FUTEX_WAIT, val, NULL, NULL, 0); +} + +static void *race_filler(void *arg) +{ + for (;;) + pause(); + return arg; +} + +/* + * W: become a deadline task. In each round, block on race_m until the + * time rs->w_abs, CLOCK_REALTIME. The wait must time out: T holds + * race_m. + */ +static void *race_w(void *arg) +{ + int i = 0; + + rs->w_tid = gettid_(); + if (set_deadline(0, RACE_W_RUNTIME, RACE_W_PERIOD)) { + set_flag(&rs->w_err, -1); + return arg; + } + for (;;) { + struct timespec ts; + int err; + + wait_change(&rs->w_go, i); + i = rs->w_go; + if (i < 0) + return arg; + ts.tv_sec = rs->w_abs / NSEC_PER_SEC; + ts.tv_nsec = rs->w_abs % NSEC_PER_SEC; + rs->w_blocked = i; + err = pthread_mutex_timedlock(&race_m, &ts); + rs->w_ret = realtime_ns(); + if (!err) { + pthread_mutex_unlock(&race_m); + rs->w_err = 1; + } else if (err != ETIMEDOUT) { + rs->w_err = 2; + } + set_flag(&rs->w_done, i); + } +} + +/* + * Fork the process of T and W, in the cgroup @cg. T, its main thread, + * takes race_m and starts W. In each round, T makes itself a deadline + * task, runs most of its runtime and sleeps. Return the pid, or -1. + */ +static pid_t race_t(const char *cg) +{ + pid_t pid = fork_child("T and W"); + + if (!pid) { + pthread_mutexattr_t a; + pthread_t w; + int i = 0; + + if (enter(cg, getpid()) || pthread_mutexattr_init(&a) || + pthread_mutexattr_setprotocol(&a, PTHREAD_PRIO_INHERIT) || + pthread_mutex_init(&race_m, &a) || pthread_mutex_lock(&race_m) || + pthread_create(&w, NULL, race_w, NULL)) { + set_flag(&rs->w_err, -1); + _exit(1); + } + rs->t_tid = gettid_(); + for (;;) { + wait_change(&rs->go, i); + i = rs->go; + if (i < 0) + _exit(0); + if (set_deadline(0, RACE_T_RUNTIME, RACE_T_PERIOD)) { + set_flag(&rs->t_ready, -i); + continue; + } + /* 2ms left: the 0-lag time is 20ms before the deadline. */ + spin_ns(RACE_T_RUNTIME - 2 * NSEC_PER_MSEC); + set_flag(&rs->t_ready, i); + } + } + return pid; +} + +/* + * Fork a process of RACE_FILLERS threads that sleep. Return its pid, or + * -1. It sets rs->fill to the count of threads it made, or to -1. + */ +static pid_t race_fill(void) +{ + pid_t pid = fork_child("the filler"); + + if (!pid) { + pthread_attr_t at; + pthread_t t; + int n; + + pthread_attr_init(&at); + pthread_attr_setstacksize(&at, THREAD_STACK); + for (n = 0; n < RACE_FILLERS; n++) { + if (pthread_create(&t, &at, race_filler, NULL)) + break; + } + set_flag(&rs->fill, n ? n : -1); + for (;;) + pause(); + } + return pid; +} + +/* Toggle Q between a partition root and a member. Return 0, or -errno. */ +static int toggle_q(int *q_root) +{ + *q_root = !*q_root; + return write_file(cg_q, "cpuset.cpus.partition", *q_root ? "root" : "member"); +} + +/* + * A rebuild of the accounting clears the bandwidth of the root domains, + * then walks the task list and adds back each deadline task. A task can + * leave the class in the window between the clear and the walk reaching + * it. It must still be counted until its 0-lag time. + * + * R is a partition root of two CPUs. Q is a partition root of one CPU. T + * and W are threads of one process in R. T holds race_m, a priority + * inheritance mutex. Before T and W, the case forks a filler process of + * RACE_FILLERS threads that sleep. The walk meets them before T, which + * makes the window wider. In each round: + * 1. T makes itself a deadline task of 20ms every 200ms. It runs 18ms + * and sleeps. Its 0-lag time is about 160ms ahead. + * 2. W, a deadline task of 5ms every 50ms, blocks on race_m with a + * timeout. It boosts T. + * 3. The case switches T to SCHED_OTHER. The boost keeps T in the class. + * 4. The case switches Q between member and partition root. This + * rebuilds the accounting. The case times the write so that the + * timeout of W falls in it, at a random point. The timeout ends the + * boost: T leaves the class before its 0-lag time. + * 5. Right after, total_bw of R must count W and T. + * 6. Past the 0-lag time of T, total_bw of R must count W only. + * + * The rounds run for RACE_SECS seconds. The case fails at the first + * round where total_bw of R misses T. + */ +static int pi_deboost_during_rebuild(void) +{ + int cpu[2] = { top_cpu(4), top_cpu(3) }, q_root = 1, ret = KSFT_FAIL, i; + long long base, bw_t, bw_w, tb; + char cg_r[PATH_MAX + 32], cpus[32]; + pid_t filler = -1, proc = -1; + uint64_t end, d, dmax = 0; + + if (ncpus < 5) { + ksft_print_msg("needs 5 non-isolated CPUs\n"); + return KSFT_SKIP; + } + snprintf(cg_r, sizeof(cg_r), "%s/deadline_bw_r", root); + snprintf(cpus, sizeof(cpus), "%d,%d", cpu[0], cpu[1]); + if (make_partition_cpus(cg_r, cpus) || make_partition(cg_q, top_cpu(2))) { + ksft_print_msg("no partition roots R of CPUs %s and Q of CPU %d\n", + cpus, top_cpu(2)); + ret = KSFT_SKIP; + goto out_cg; + } + rs = mmap(NULL, sizeof(*rs), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); + if (rs == MAP_FAILED) { + ksft_print_msg("mmap: %s\n", strerror(errno)); + goto out_cg; + } + memset(rs, 0, sizeof(*rs)); + bw_t = bw_of(RACE_T_RUNTIME, RACE_T_PERIOD); + bw_w = bw_of(RACE_W_RUNTIME, RACE_W_PERIOD); + + filler = race_fill(); + if (filler < 0 || wait_for(10000, rs->fill) || rs->fill < 0) { + ksft_print_msg("no filler threads\n"); + goto out; + } + /* The longest of 8 writes to Q sets the range of the timeouts. */ + for (i = 0; i < 8; i++) { + uint64_t t = now_ns(); + + if (toggle_q(&q_root)) { + ksft_print_msg("Q cannot change between root and member\n"); + ret = KSFT_SKIP; + goto out; + } + d = now_ns() - t; + if (d > dmax) + dmax = d; + } + if (total_bw_of(cpu[0]) < 0) { + ksft_print_msg("no total_bw in /sys/kernel/debug/sched/debug\n"); + ret = KSFT_SKIP; + goto out; + } + proc = race_t(cg_r); + if (proc < 0 || wait_for(2000, (rs->w_tid && rs->t_tid) || rs->w_err) || rs->w_err) { + ksft_print_msg("no T and W\n"); + goto out; + } + sleep_ns(100 * NSEC_PER_MSEC); + base = total_bw_of(cpu[0]) - bw_w; + + srand(getpid() ^ now_ns()); + end = now_ns() + RACE_SECS * NSEC_PER_SEC; + for (i = 1; now_ns() < end; i++) { + int64_t abs, lead, w0; + struct timespec ts; + + set_flag(&rs->go, i); + if (wait_for_step(1000, 100 * NSEC_PER_USEC, + rs->t_ready == i || rs->t_ready == -i) || + rs->t_ready != i) { + ksft_print_msg("round %d: T cannot become a deadline task\n", i); + goto out; + } + if (wait_for_step(100, 100 * NSEC_PER_USEC, proc_state_of(rs->t_tid) == 'S')) + continue; + /* Leave W 20ms to block, then time out within the write. */ + lead = (int64_t)((double)rand() / RAND_MAX * 1.2 * dmax); + abs = realtime_ns() + 20 * NSEC_PER_MSEC + dmax; + rs->w_abs = abs; + set_flag(&rs->w_go, i); + if (wait_for_step(100, 100 * NSEC_PER_USEC, rs->w_blocked == i) || + wait_for_step(100, 100 * NSEC_PER_USEC, proc_state_of(rs->w_tid) == 'S')) { + ksft_print_msg("round %d: W did not block\n", i); + goto out; + } + if (set_other(rs->t_tid)) { + ksft_print_msg("round %d: T cannot leave SCHED_DEADLINE\n", i); + goto out; + } + if (prio_of(rs->t_tid) != DL_TASK_PRIO) { + ksft_print_msg("round %d: W does not boost T\n", i); + goto out; + } + ts.tv_sec = (abs - lead) / NSEC_PER_SEC; + ts.tv_nsec = (abs - lead) % NSEC_PER_SEC; + while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL) == EINTR) + ; + w0 = realtime_ns(); + toggle_q(&q_root); + d = realtime_ns() - w0; + if (wait_for_step(1000, 100 * NSEC_PER_USEC, rs->w_done == i) || rs->w_err) { + ksft_print_msg("round %d: the wait of W did not time out\n", i); + goto out; + } + tb = total_bw_of(cpu[0]); + if (tb != base + bw_w + bw_t) { + ksft_print_msg("round %d: total_bw of R %lld, %lld expected%s\n", + i, tb, base + bw_w + bw_t, + tb == base + bw_w ? ": T is missing" : ""); + ksft_print_msg("round %d: timeout %lldus into a write of %lldus\n", + i, (long long)(rs->w_ret - w0) / 1000, (long long)d / 1000); + goto out; + } + /* Past the 0-lag time of T: R counts W only. */ + if (wait_for_step(1000, 5 * NSEC_PER_MSEC, total_bw_of(cpu[0]) == base + bw_w)) { + ksft_print_msg("round %d: past the 0-lag time of T, total_bw of R %lld, %lld expected\n", + i, total_bw_of(cpu[0]), base + bw_w); + goto out; + } + } + ret = KSFT_PASS; +out: + set_flag(&rs->go, -1); + set_flag(&rs->w_go, -1); + reap(proc); + reap(filler); + munmap(rs, sizeof(*rs)); +out_cg: + remove_partition(cg_q); + remove_partition(cg_r); + return ret; +} + /* The tables of the cases, and main() */ enum where { @@ -12614,6 +13087,7 @@ static const struct p_case { { "pi_unlock_running", pi_unlock_running, MEASURED_IN_P }, { "pi_chain_two_owners", pi_chain_two_owners, MEASURED_IN_P }, { "pi_departed_moved", pi_departed_moved, FROM_OUTSIDE }, + { "pi_departed_offline_boost", pi_departed_offline_boost, FROM_OUTSIDE }, { "params_asleep", params_asleep, IN_P }, { "params_non_contending", params_non_contending, MEASURED_IN_P }, { "params_switched_asleep", params_switched_asleep, MEASURED_IN_P }, @@ -12703,6 +13177,7 @@ static const struct p_case { { "params_swap_overload", params_swap_overload, FROM_OUTSIDE }, { "random_mix", random_mix, FROM_OUTSIDE }, { "move_normalized", move_normalized, FROM_OUTSIDE }, + { "pi_deboost_during_rebuild", pi_deboost_during_rebuild, FROM_OUTSIDE }, }; #define N_P_CASES ((int)ARRAY_SIZE(p_cases)) -- 2.47.3