Skip to contentSkip to conversation

fix share rt runtime with offline rq

PATCH In review chenying 3 participants 3 messages Dec 21, 2019 – Jan 8, 2020 Scheduler

lore
Share & tools
lore

chenying

author
#0 lore raw

PATCH 1/1 fix share rt runtime with offline rq

In my environment,cpu0-11 are online, cpu12-15 are offline, CPU2 is isolated, sched_rt_runtime_us is 950000,and then bind a rt process with dead loop to CPU2. We can see that CPU usage on CPU2 reaches 100%,but only one cpu is isolated, so it can be inferred that CPU2 shares the rt runtime of offline cpu.

/ # cat /sys/devices/system/cpu/online
0-11
/ # cat /sys/devices/system/cpu/offline
12-15
/ # cat /sys/devices/system/cpu/isolated
2
/ # cat /proc/sys/kernel/sched_rt_runtime_us
950000
/ # chrt -p 357
pid 357's current scheduling policy: SCHED_FIFO
pid 357's current scheduling priority: 1

top - 15:52:12 up 4 min, 0 users, load average: 0.92, 0.41, 0.16
Tasks: 201 total, 2 running, 199 sleeping, 0 stopped, 0 zombie

%Cpu0  :  0.3 us,  0.3 sy,  0.0 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  :100.0 us,  0.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu4  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu5  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu6  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu7  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu8  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu9  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu10 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  357 root      -2   0    4044    172    136 R 100.0  0.0   2:32.99 deadloop
  366 root      20   0   22060   2404   2128 R   0.7  0.0   0:00.06 top
    1 root      20   0    2624     20      0 S   0.0  0.0   0:05.93 init
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd
    3 root      20   0       0      0      0 S   0.0  0.0   0:00.00 ksoftirqd/0
    4 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0
---
 kernel/sched/rt.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/sched/rt.c +4 -0
index a532558..d20dc86 100644
@@ -648,8 +648,12 @@ static void do_balance_runtime(struct rt_rq *rt_rq)
 	rt_period = ktime_to_ns(rt_b->rt_period);
 	for_each_cpu(i, rd->span) {
 		struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
+		struct rq *rq = rq_of_rt_rq(iter);
 		s64 diff;
 
+		if (!rq->online)
+			continue;
+
 		if (iter == rt_rq)
 			continue;
 
Signature · 1 line
2.15.2
#1 lore raw
Quoted 5 lines · On Sat, 21 Dec 2019 10:20:12 +0800 chenying <[email protected]> wrote:

In my environment,cpu0-11 are online, cpu12-15 are offline, CPU2 is isolated, sched_rt_runtime_us is 950000,and then bind a rt process with dead loop to CPU2. We can see that CPU usage on CPU2 reaches 100%,but only one cpu is isolated, so it can be inferred that CPU2 shares the rt runtime of offline cpu.

Quoted 11 lines

/ # cat /sys/devices/system/cpu/online
0-11
/ # cat /sys/devices/system/cpu/offline
12-15
/ # cat /sys/devices/system/cpu/isolated
2
/ # cat /proc/sys/kernel/sched_rt_runtime_us
950000
/ # chrt -p 357
pid 357's current scheduling policy: SCHED_FIFO
pid 357's current scheduling priority: 1

I'm guessing that you took the cpus offline via the kernel command line parameter. Because when I tried this with just:

 # echo 0 > /sys/devices/system/cpu/cpu${cpu}/online

I could not reproduce it. But when I booted with maxcpus=X set, I could.

Quoted 33 lines

top - 15:52:12 up 4 min, 0 users, load average: 0.92, 0.41, 0.16
Tasks: 201 total, 2 running, 199 sleeping, 0 stopped, 0 zombie

%Cpu0  :  0.3 us,  0.3 sy,  0.0 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu1  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  :100.0 us,  0.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu4  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu5  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu6  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu7  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu8  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu9  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu10 :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  357 root      -2   0    4044    172    136 R 100.0  0.0   2:32.99 deadloop
  366 root      20   0   22060   2404   2128 R   0.7  0.0   0:00.06 top
    1 root      20   0    2624     20      0 S   0.0  0.0   0:05.93 init
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd
    3 root      20   0       0      0      0 S   0.0  0.0   0:00.00 ksoftirqd/0
    4 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0
---
 kernel/sched/rt.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/sched/rt.c +0 -0
index a532558..d20dc86 100644

kernel/sched/rt.c static void do_balance_runtime(struct rt_rq *rt_rq) · line 656

Quoted 9 lines
kernel/sched/rt.c +4 -0
@@ -648,8 +648,12 @@ static void do_balance_runtime(struct rt_rq *rt_rq)
 	rt_period = ktime_to_ns(rt_b->rt_period);
 	for_each_cpu(i, rd->span) {
 		struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
+		struct rq *rq = rq_of_rt_rq(iter);
 		s64 diff;
 
+		if (!rq->online)
+			continue;
+

I think this might be papering over the real issue. Perhaps rq_offline_rt() needs to be called for CPUs not being brought online?

-- Steve

Quoted 3 lines
kernel/sched/rt.c +0 -0
 		if (iter == rt_rq)
 			continue;
 
maintainer
#2 lore raw
Quoted 14 lines · Steven Rostedt
Quoted 14 lines
 kernel/sched/rt.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/sched/rt.c +1 -0
index a532558..d20dc86 100644
@@ -648,8 +648,12 @@ static void do_balance_runtime(struct rt_rq *rt_rq)
 	rt_period = ktime_to_ns(rt_b->rt_period);
 	for_each_cpu(i, rd->span) {
 		struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
+		struct rq *rq = rq_of_rt_rq(iter);
 		s64 diff;
 
Quoted 6 lines

kernel/sched/rt.c static void do_balance_runtime(struct rt_rq *rt_rq) · line 656

Quoted 3 lines
kernel/sched/rt.c +3 -0
+		if (!rq->online)
+			continue;
+

I think this might be papering over the real issue. Perhaps rq_offline_rt() needs to be called for CPUs not being brought online?

Yeah, very much that. Something like the below perhaps. But I really want to rip out the whole RT_CGROUP_SCHED stuff so we can start over.

Perhaps the poster can explain what he's using this stuff for?

---

kernel/sched/rt.c +6 -0
index 4043abe45459..96a0320cfadb 100644
@@ -208,7 +208,13 @@ int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)
 			goto err_free_rq;
 
 		init_rt_rq(rt_rq);
+
+		cpus_read_lock();
 		rt_rq->rt_runtime = tg->rt_bandwidth.rt_runtime;
+		if (!cpu_online(i))
+			rt_rq->rt_runtime = RUNTIME_INF;
+		cpus_read_unlock();
+
 		init_tg_rt_entry(tg, rt_rq, rt_se, i, parent->rt_se[i]);
 	}