Skip to contentSkip to conversation

sched_ext: Replace hardcoding with macro and minor typo fix

PATCH In review Zhao Mengmeng 4 participants 4 messages Nov 13, 2024 – Nov 15, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sched_ext: Replace hardcoding with macro and minor typo fix

From: Zhao Mengmeng <[email protected]>

1. replace hardcoding with SCX_KF_UNLOCKED.
2. scx_next_task_picked() has been replaced with siwtch_class().
3. minor typo fixes.

---
 kernel/sched/ext.c             | 6 +++---
 tools/sched_ext/scx_qmap.bpf.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/sched/ext.c +3 -3
index 1b1c33f12dd7..832f77d1d318 100644
@@ -2759,10 +2759,10 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
 		 * If the previous sched_class for the current CPU was not SCX,
 		 * notify the BPF scheduler that it again has control of the
 		 * core. This callback complements ->cpu_release(), which is
-		 * emitted in scx_next_task_picked().
+		 * emitted in switch_class().
 		 */
 		if (SCX_HAS_OP(cpu_acquire))
-			SCX_CALL_OP(0, cpu_acquire, cpu_of(rq), NULL);
+			SCX_CALL_OP(SCX_KF_UNLOCKED, cpu_acquire, cpu_of(rq), NULL);
 		rq->scx.cpu_released = false;
 	}
 
@@ -6096,7 +6096,7 @@ static void kick_cpus_irq_workfn(struct irq_work *irq_work)
 		if (cpu != cpu_of(this_rq)) {
 			/*
 			 * Pairs with smp_store_release() issued by this CPU in
-			 * scx_next_task_picked() on the resched path.
+			 * switch_class() on the resched path.
 			 *
 			 * We busy-wait here to guarantee that no other task can
 			 * be scheduled on our core before the target CPU has
tools/sched_ext/scx_qmap.bpf.c +1 -1
index ee264947e0c3..f230641929ec 100644
@@ -5,7 +5,7 @@
  * There are five FIFOs implemented using BPF_MAP_TYPE_QUEUE. A task gets
  * assigned to one depending on its compound weight. Each CPU round robins
  * through the FIFOs and dispatches more from FIFOs with higher indices - 1 from
- * queue0, 2 from queue1, 4 from queue2 and so on.
+ * queue0, 2 from queue1, 3 from queue2 and so on.
  *
  * This scheduler demonstrates:
  *
Signature · 1 line
2.43.0
reviewer
#1 lore raw

Hello,

Quoted 17 lines · Zhao Mengmeng

From: Zhao Mengmeng <[email protected]>

1. replace hardcoding with SCX_KF_UNLOCKED.
2. scx_next_task_picked() has been replaced with siwtch_class().
3. minor typo fixes.

---
 kernel/sched/ext.c             | 6 +++---
 tools/sched_ext/scx_qmap.bpf.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/sched/ext.c +0 -0
index 1b1c33f12dd7..832f77d1d318 100644

kernel/sched/ext.c static int balance_one(struct rq *rq, struct task_struct *prev) · line 2765

Quoted 9 lines
kernel/sched/ext.c +2 -2
@@ -2759,10 +2759,10 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
 		 * If the previous sched_class for the current CPU was not SCX,
 		 * notify the BPF scheduler that it again has control of the
 		 * core. This callback complements ->cpu_release(), which is
-		 * emitted in scx_next_task_picked().
+		 * emitted in switch_class().
 		 */
 		if (SCX_HAS_OP(cpu_acquire))
-			SCX_CALL_OP(0, cpu_acquire, cpu_of(rq), NULL);
+			SCX_CALL_OP(SCX_KF_UNLOCKED, cpu_acquire, cpu_of(rq), NULL);

I think this is actually a bug. David, shouldn't this be SCX_KF_REST?

Quoted 17 lines
kernel/sched/ext.c +1 -1
 		rq->scx.cpu_released = false;
 	}
 
@@ -6096,7 +6096,7 @@ static void kick_cpus_irq_workfn(struct irq_work *irq_work)
 		if (cpu != cpu_of(this_rq)) {
 			/*
 			 * Pairs with smp_store_release() issued by this CPU in
-			 * scx_next_task_picked() on the resched path.
+			 * switch_class() on the resched path.
 			 *
 			 * We busy-wait here to guarantee that no other task can
 			 * be scheduled on our core before the target CPU has
tools/sched_ext/scx_qmap.bpf.c +0 -0
index ee264947e0c3..f230641929ec 100644

tools/sched_ext/scx_qmap.bpf.c line 8

Quoted 5 lines
tools/sched_ext/scx_qmap.bpf.c +1 -1
@@ -5,7 +5,7 @@
  * There are five FIFOs implemented using BPF_MAP_TYPE_QUEUE. A task gets
  * assigned to one depending on its compound weight. Each CPU round robins
  * through the FIFOs and dispatches more from FIFOs with higher indices - 1 from
- * queue0, 2 from queue1, 4 from queue2 and so on.
+ * queue0, 2 from queue1, 3 from queue2 and so on.

The number to dispatch is determined by:

  cpuc->dsp_cnt = 1 << cpuc->dsp_idx;

I think the existing comment is correct.

Thasnks.

Signature · 1 line
tejun
reviewer
#2 lore raw
Quoted 15 lines · Tejun Heo

Hello,

Quoted 12 lines · Zhao Mengmeng

From: Zhao Mengmeng <[email protected]>

1. replace hardcoding with SCX_KF_UNLOCKED.
2. scx_next_task_picked() has been replaced with siwtch_class().
3. minor typo fixes.

---
 kernel/sched/ext.c             | 6 +++---
 tools/sched_ext/scx_qmap.bpf.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 16 lines
Quoted 5 lines
kernel/sched/ext.c +0 -0
index 1b1c33f12dd7..832f77d1d318 100644

kernel/sched/ext.c static int balance_one(struct rq *rq, struct task_struct *prev) · line 2765

Quoted 9 lines
kernel/sched/ext.c +2 -2
@@ -2759,10 +2759,10 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
 		 * If the previous sched_class for the current CPU was not SCX,
 		 * notify the BPF scheduler that it again has control of the
 		 * core. This callback complements ->cpu_release(), which is
-		 * emitted in scx_next_task_picked().
+		 * emitted in switch_class().
 		 */
 		if (SCX_HAS_OP(cpu_acquire))
-			SCX_CALL_OP(0, cpu_acquire, cpu_of(rq), NULL);
+			SCX_CALL_OP(SCX_KF_UNLOCKED, cpu_acquire, cpu_of(rq), NULL);

I think this is actually a bug. David, shouldn't this be SCX_KF_REST?

Yes, good catch. We're holding the rq lock so SCX_KF_UNLOCKED isn't safe. I agree this should be SCX_KF_REST.

Thanks,
David

#3 lore raw
In reply to Tejun Heo
Quoted 15 lines · Tejun Heo

Hello,

Quoted 12 lines · Zhao Mengmeng

From: Zhao Mengmeng <[email protected]>

1. replace hardcoding with SCX_KF_UNLOCKED.
2. scx_next_task_picked() has been replaced with siwtch_class().
3. minor typo fixes.

---
 kernel/sched/ext.c             | 6 +++---
 tools/sched_ext/scx_qmap.bpf.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 19 lines
Quoted 5 lines
kernel/sched/ext.c +0 -0
index 1b1c33f12dd7..832f77d1d318 100644

kernel/sched/ext.c static int balance_one(struct rq *rq, struct task_struct *prev) · line 2765

Quoted 9 lines
kernel/sched/ext.c +2 -2
@@ -2759,10 +2759,10 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
 		 * If the previous sched_class for the current CPU was not SCX,
 		 * notify the BPF scheduler that it again has control of the
 		 * core. This callback complements ->cpu_release(), which is
-		 * emitted in scx_next_task_picked().
+		 * emitted in switch_class().
 		 */
 		if (SCX_HAS_OP(cpu_acquire))
-			SCX_CALL_OP(0, cpu_acquire, cpu_of(rq), NULL);
+			SCX_CALL_OP(SCX_KF_UNLOCKED, cpu_acquire, cpu_of(rq), NULL);

I think this is actually a bug. David, shouldn't this be SCX_KF_REST?

Quoted 2 lines
kernel/sched/ext.c +0 -0
 		rq->scx.cpu_released = false;
 	}

Got it.

Quoted 22 lines
Quoted 14 lines
kernel/sched/ext.c +1 -1
@@ -6096,7 +6096,7 @@ static void kick_cpus_irq_workfn(struct irq_work *irq_work)
 		if (cpu != cpu_of(this_rq)) {
 			/*
 			 * Pairs with smp_store_release() issued by this CPU in
-			 * scx_next_task_picked() on the resched path.
+			 * switch_class() on the resched path.
 			 *
 			 * We busy-wait here to guarantee that no other task can
 			 * be scheduled on our core before the target CPU has
tools/sched_ext/scx_qmap.bpf.c +0 -0
index ee264947e0c3..f230641929ec 100644

tools/sched_ext/scx_qmap.bpf.c line 8

Quoted 5 lines
tools/sched_ext/scx_qmap.bpf.c +1 -1
@@ -5,7 +5,7 @@
  * There are five FIFOs implemented using BPF_MAP_TYPE_QUEUE. A task gets
  * assigned to one depending on its compound weight. Each CPU round robins
  * through the FIFOs and dispatches more from FIFOs with higher indices - 1 from
- * queue0, 2 from queue1, 4 from queue2 and so on.
+ * queue0, 2 from queue1, 3 from queue2 and so on.

The number to dispatch is determined by:

Quoted 3 lines
  cpuc->dsp_cnt = 1 << cpuc->dsp_idx;

I think the existing comment is correct.

You are right, I missed something. Will send a V3