Steven Barrett commented on issue #104 at Alfred Chen / linux-prjc

Steven Barrett
2025-07-03T13:33:34Z

Unfortunately, this didn't seem to help either. To also confirm, I had ksysguard open showing nice levels ordered by CPU usage, and for sure I'd see very nice tasks running first before negative nice.

± sudo ./nice_bench.py
2025-07-03 08:30:33,196 - Starting experiment...
2025-07-03 08:30:34,196 - Calibrated task size: 7428442
2025-07-03 08:30:34,217 - System has 16 CPUs
2025-07-03 08:30:34,217 - Launched 80 processes with nice levels: [20, 20, 19, 19, 18, 18, 17, 17, 16, 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, -8, -8, -9, -9, -10, -10, -11, -11, -12, -12, -13, -13, -14, -14, -15, -15, -16, -16, -17, -17, -18, -18, -19, -19]
2025-07-03 08:30:34,217 - Running task with size 9. Press Ctrl+C to stop the experiment
2025-07-03 08:30:39,462 - Task completed with nice level 17 in 5.26 seconds, with wakeup latency of 66.77 microseconds
2025-07-03 08:30:39,478 - Task completed with nice level 18 in 5.28 seconds, with wakeup latency of 65.03 microseconds
2025-07-03 08:30:39,481 - Task completed with nice level 14 in 5.28 seconds, with wakeup latency of 31.82 microseconds
2025-07-03 08:30:39,491 - Task completed with nice level 13 in 5.29 seconds, with wakeup latency of 65.64 microseconds
2025-07-03 08:30:39,527 - Task completed with nice level 18 in 5.33 seconds, with wakeup latency of 56.72 microseconds
2025-07-03 08:30:39,535 - Task completed with nice level 17 in 5.34 seconds, with wakeup latency of 66.98 microseconds
2025-07-03 08:30:39,627 - Task completed with nice level 0 in 5.42 seconds, with wakeup latency of 54.98 microseconds
2025-07-03 08:30:40,147 - Task completed with nice level 1 in 5.94 seconds, with wakeup latency of 53.87 microseconds
2025-07-03 08:30:42,693 - Task completed with nice level -13 in 8.48 seconds, with wakeup latency of 13.31 microseconds
2025-07-03 08:30:43,133 - Task completed with nice level -19 in 8.92 seconds, with wakeup latency of 53.32 microseconds
2025-07-03 08:30:43,344 - Task completed with nice level -1 in 9.14 seconds, with wakeup latency of 55.25 microseconds
2025-07-03 08:30:43,373 - Task completed with nice level -18 in 9.16 seconds, with wakeup latency of 36.51 microseconds
2025-07-03 08:30:43,614 - Task completed with nice level -19 in 9.40 seconds, with wakeup latency of 52.86 microseconds
2025-07-03 08:30:43,815 - Task completed with nice level -18 in 9.60 seconds, with wakeup latency of 54.13 microseconds
2025-07-03 08:30:44,512 - Task completed with nice level -15 in 10.30 seconds, with wakeup latency of 54.12 microseconds
2025-07-03 08:30:44,608 - Task completed with nice level 0 in 10.40 seconds, with wakeup latency of 618.21 microseconds
2025-07-03 08:30:44,696 - Task completed with nice level 20 in 10.50 seconds, with wakeup latency of 56.38 microseconds
2025-07-03 08:30:44,745 - Task completed with nice level 19 in 10.55 seconds, with wakeup latency of 54.87 microseconds
2025-07-03 08:30:44,848 - Task completed with nice level -17 in 10.63 seconds, with wakeup latency of 1742.35 microseconds
2025-07-03 08:30:45,125 - Task completed with nice level 6 in 10.92 seconds, with wakeup latency of 54.62 microseconds
2025-07-03 08:30:45,256 - Task completed with nice level -7 in 11.05 seconds, with wakeup latency of 53.18 microseconds
2025-07-03 08:30:45,527 - Task completed with nice level -17 in 11.31 seconds, with wakeup latency of 53.50 microseconds
2025-07-03 08:30:45,641 - Task completed with nice level -14 in 11.43 seconds, with wakeup latency of 53.71 microseconds
2025-07-03 08:30:45,653 - Task completed with nice level -13 in 11.44 seconds, with wakeup latency of 54.73 microseconds
2025-07-03 08:30:46,681 - Task completed with nice level -11 in 12.47 seconds, with wakeup latency of 48.24 microseconds
2025-07-03 08:30:47,144 - Task completed with nice level -16 in 12.93 seconds, with wakeup latency of 53.85 microseconds
2025-07-03 08:30:48,113 - Task completed with nice level -4 in 13.90 seconds, with wakeup latency of 53.48 microseconds
2025-07-03 08:30:48,445 - Task completed with nice level 15 in 14.25 seconds, with wakeup latency of 61.17 microseconds
2025-07-03 08:30:48,862 - Task completed with nice level -16 in 14.65 seconds, with wakeup latency of 53.55 microseconds
2025-07-03 08:30:48,993 - Task completed with nice level 7 in 14.79 seconds, with wakeup latency of 53.16 microseconds
2025-07-03 08:30:49,041 - Task completed with nice level 1 in 14.83 seconds, with wakeup latency of 54.15 microseconds
2025-07-03 08:30:49,218 - Task completed with nice level -15 in 15.00 seconds, with wakeup latency of 52.68 microseconds
2025-07-03 08:30:49,617 - Task completed with nice level 10 in 15.41 seconds, with wakeup latency of 53.10 microseconds
2025-07-03 08:30:49,824 - Task completed with nice level 7 in 15.62 seconds, with wakeup latency of 53.00 microseconds
2025-07-03 08:30:49,844 - Task completed with nice level 9 in 15.64 seconds, with wakeup latency of 1830.70 microseconds
2025-07-03 08:30:50,046 - Task completed with nice level -1 in 15.84 seconds, with wakeup latency of 52.98 microseconds
2025-07-03 08:30:50,049 - Task completed with nice level 19 in 15.85 seconds, with wakeup latency of 55.15 microseconds
2025-07-03 08:30:50,322 - Task completed with nice level -5 in 16.11 seconds, with wakeup latency of 54.78 microseconds
2025-07-03 08:30:50,758 - Task completed with nice level 2 in 16.55 seconds, with wakeup latency of 1709.35 microseconds
2025-07-03 08:30:50,873 - Task completed with nice level 2 in 16.67 seconds, with wakeup latency of 53.93 microseconds
2025-07-03 08:30:51,525 - Task completed with nice level -14 in 17.31 seconds, with wakeup latency of 3167.37 microseconds
2025-07-03 08:30:52,887 - Task completed with nice level -11 in 18.67 seconds, with wakeup latency of 54.32 microseconds
2025-07-03 08:30:53,318 - Task completed with nice level 8 in 19.12 seconds, with wakeup latency of 53.88 microseconds
2025-07-03 08:30:53,357 - Task completed with nice level 12 in 19.16 seconds, with wakeup latency of 627.82 microseconds
2025-07-03 08:30:53,404 - Task completed with nice level 8 in 19.20 seconds, with wakeup latency of 1784.38 microseconds
2025-07-03 08:30:53,903 - Task completed with nice level 9 in 19.70 seconds, with wakeup latency of 54.50 microseconds
2025-07-03 08:30:54,465 - Task completed with nice level -10 in 20.25 seconds, with wakeup latency of 52.95 microseconds
2025-07-03 08:30:54,818 - Task completed with nice level 6 in 20.61 seconds, with wakeup latency of 55.00 microseconds
2025-07-03 08:30:54,892 - Task completed with nice level -7 in 20.68 seconds, with wakeup latency of 3650.94 microseconds
2025-07-03 08:30:55,029 - Task completed with nice level 12 in 20.83 seconds, with wakeup latency of 55.96 microseconds
2025-07-03 08:30:55,142 - Task completed with nice level 20 in 20.94 seconds, with wakeup latency of 55.68 microseconds
2025-07-03 08:30:55,164 - Task completed with nice level -12 in 20.95 seconds, with wakeup latency of 54.80 microseconds
2025-07-03 08:30:55,248 - Task completed with nice level 14 in 21.05 seconds, with wakeup latency of 74.38 microseconds
2025-07-03 08:30:55,511 - Task completed with nice level -6 in 21.30 seconds, with wakeup latency of 603.60 microseconds
2025-07-03 08:30:55,511 - Task completed with nice level -5 in 21.30 seconds, with wakeup latency of 54.86 microseconds
2025-07-03 08:30:55,820 - Task completed with nice level -12 in 21.61 seconds, with wakeup latency of 54.40 microseconds
2025-07-03 08:30:55,879 - Task completed with nice level 3 in 21.67 seconds, with wakeup latency of 53.60 microseconds
2025-07-03 08:30:56,296 - Task completed with nice level -8 in 22.08 seconds, with wakeup latency of 54.71 microseconds
2025-07-03 08:30:57,094 - Task completed with nice level -9 in 22.88 seconds, with wakeup latency of 53.84 microseconds
2025-07-03 08:30:57,101 - Task completed with nice level -9 in 22.89 seconds, with wakeup latency of 53.93 microseconds
2025-07-03 08:30:57,106 - Task completed with nice level -10 in 22.89 seconds, with wakeup latency of 54.49 microseconds
2025-07-03 08:30:57,374 - Task completed with nice level -6 in 23.16 seconds, with wakeup latency of 1914.12 microseconds
2025-07-03 08:30:57,884 - Task completed with nice level -2 in 23.68 seconds, with wakeup latency of 53.18 microseconds
2025-07-03 08:30:58,183 - Task completed with nice level 16 in 23.98 seconds, with wakeup latency of 27.60 microseconds
2025-07-03 08:30:58,188 - Task completed with nice level 11 in 23.99 seconds, with wakeup latency of 1785.60 microseconds
2025-07-03 08:30:59,077 - Task completed with nice level -4 in 24.87 seconds, with wakeup latency of 54.21 microseconds
2025-07-03 08:30:59,576 - Task completed with nice level -2 in 25.37 seconds, with wakeup latency of 61.40 microseconds
2025-07-03 08:30:59,679 - Task completed with nice level -8 in 25.47 seconds, with wakeup latency of 54.20 microseconds
2025-07-03 08:30:59,749 - Task completed with nice level 5 in 25.54 seconds, with wakeup latency of 53.93 microseconds
2025-07-03 08:31:00,186 - Task completed with nice level 5 in 25.98 seconds, with wakeup latency of 53.82 microseconds
2025-07-03 08:31:00,309 - Task completed with nice level 13 in 26.11 seconds, with wakeup latency of 66.11 microseconds
2025-07-03 08:31:00,470 - Task completed with nice level 4 in 26.27 seconds, with wakeup latency of 53.53 microseconds
2025-07-03 08:31:00,923 - Task completed with nice level 16 in 26.72 seconds, with wakeup latency of 73.30 microseconds
2025-07-03 08:31:01,063 - Task completed with nice level 11 in 26.86 seconds, with wakeup latency of 56.15 microseconds
2025-07-03 08:31:01,253 - Task completed with nice level -3 in 27.04 seconds, with wakeup latency of 65.23 microseconds
2025-07-03 08:31:01,268 - Task completed with nice level -3 in 27.06 seconds, with wakeup latency of 54.47 microseconds
2025-07-03 08:31:01,791 - Task completed with nice level 3 in 27.59 seconds, with wakeup latency of 22.92 microseconds
2025-07-03 08:31:02,024 - Task completed with nice level 4 in 27.82 seconds, with wakeup latency of 54.74 microseconds
2025-07-03 08:31:02,612 - Task completed with nice level 10 in 28.41 seconds, with wakeup latency of 56.35 microseconds
2025-07-03 08:31:02,948 - Task completed with nice level 15 in 28.75 seconds, with wakeup latency of 73.65 microseconds
2025-07-03 08:31:02,949 - All tasks completed in 28.73 seconds

And just in-case I made a mistake, here's the diff of the merge commit in 6.15/main of Zen Kernel (https://github.com/zen-kernel/zen-kernel/commit/38e4cd9a3961d91a81dd8001a9d86c7b09099a6e):

diff --git a/kernel/sched/alt_core.c b/kernel/sched/alt_core.c
index 6303191a3cf797..5ad5b9fc86491e 100644
--- a/kernel/sched/alt_core.c
+++ b/kernel/sched/alt_core.c
@@ -4553,11 +4553,11 @@ static inline void time_slice_expired(struct task_struct *p, struct rq *rq)
requeue_task(p, rq);
}

-static inline int balance_select_task_rq(struct task_struct *p)
+static inline int balance_select_task_rq(struct task_struct *p, cpumask_t *avail_mask)
{
cpumask_t mask;

- if (!preempt_mask_check(&mask, cpu_active_mask, task_sched_prio(p)))
+ if (!preempt_mask_check(&mask, avail_mask, task_sched_prio(p)))
return -1;

if (cpumask_and(&mask, &mask, p->cpus_ptr))
@@ -4584,6 +4584,7 @@ __move_queued_task(struct rq *rq, struct task_struct *p, struct rq *dest_rq, int
static inline void prio_balance(struct rq *rq, const int cpu)
{
struct task_struct *p, *next;
+ cpumask_t mask;

if (!rq->online)
return;
@@ -4599,12 +4600,16 @@ static inline void prio_balance(struct rq *rq, const int cpu)

rq->prio_balance_time = rq->clock;

+ cpumask_copy(&mask, cpu_active_mask);
+ cpumask_clear_cpu(cpu, &mask);
+
p = sched_rq_next_task(rq->curr, rq);
while (p != rq->idle) {
next = sched_rq_next_task(p, rq);
if (!is_migration_disabled(p)) {
- int dest_cpu = balance_select_task_rq(p);
+ int dest_cpu;

+ dest_cpu = balance_select_task_rq(p, &mask);
if (dest_cpu < 0)
return;

@@ -4612,6 +4617,8 @@ static inline void prio_balance(struct rq *rq, const int cpu)
struct rq *dest_rq = cpu_rq(dest_cpu);

if (do_raw_spin_trylock(&dest_rq->lock)) {
+ cpumask_clear_cpu(dest_cpu, &mask);
+
spin_acquire(&dest_rq->lock.dep_map,
SINGLE_DEPTH_NESTING, 1, _RET_IP_);