Skip to contentSkip to conversation

sched/rt: Add a helper to test for a RT task

PATCH In review Sebastian Andrzej Siewior 3 participants 6 messages Oct 4, 2017 – Oct 10, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 sched/rt: Add a helper to test for a RT task

This helper returns true if a task has elevated priority which is true for RT tasks (SCHED_RR and SCHED_FIFO) and also for SCHED_DEADLINE. A task which runs at RT priority due to PI-boosting is not considered as one with elevated priority.

---
 include/linux/sched/rt.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/sched/rt.h +11 -0
index f93329aba31a..30a86b8178f8 100644
@@ -17,6 +17,17 @@ static inline int rt_task(struct task_struct *p)
 	return rt_prio(p->prio);
 }
 
+static inline bool task_is_elevated(struct task_struct *tsk)
+{
+	int policy = tsk->policy;
+
+	if (policy == SCHED_FIFO || policy == SCHED_RR)
+		return true;
+	if (policy == SCHED_DEADLINE)
+		return true;
+	return false;
+}
+
 #ifdef CONFIG_RT_MUTEXES
 /*
  * Must hold either p->pi_lock or task_rq(p)->lock.
Signature · 1 line
2.14.2
#1 lore raw

PATCH 2/2 block/ioprio: use a helper to check for RT prio

A side-effect to the old code is that now SCHED_DEADLINE is also recognized.

---
 include/linux/ioprio.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/ioprio.h +2 -1
index 8c1239020d79..c8f3f0302220 100644
@@ -2,6 +2,7 @@
 #define IOPRIO_H
 
 #include <linux/sched.h>
+#include <linux/sched/rt.h>
 #include <linux/iocontext.h>
 
 /*
@@ -62,7 +63,7 @@ static inline int task_nice_ioclass(struct task_struct *task)
 {
 	if (task->policy == SCHED_IDLE)
 		return IOPRIO_CLASS_IDLE;
-	else if (task->policy == SCHED_FIFO || task->policy == SCHED_RR)
+	else if (task_is_elevated(task))
 		return IOPRIO_CLASS_RT;
 	else
 		return IOPRIO_CLASS_BE;
Signature · 1 line
2.14.2
#2 lore raw

[tip:sched/core] block/ioprio: Use a helper to check for RT prio

block/ioprio: Use a helper to check for RT prio
Commit-ID:  36436440cd19f59f5be12a1b181d299af2725140
Gitweb:     https://git.kernel.org/tip/36436440cd19f59f5be12a1b181d299af2725140
Author:     Sebastian Andrzej Siewior <[email protected]>
AuthorDate: Wed, 4 Oct 2017 17:49:01 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 10 Oct 2017 11:45:39 +0200

block/ioprio: Use a helper to check for RT prio

A side-effect to the old code is that now SCHED_DEADLINE is also recognized.

---
 include/linux/ioprio.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/ioprio.h +2 -1
index 8c12390..2f19aab 100644
@@ -2,6 +2,7 @@
 #define IOPRIO_H
 
 #include <linux/sched.h>
+#include <linux/sched/rt.h>
 #include <linux/iocontext.h>
 
 /*
@@ -62,7 +63,7 @@ static inline int task_nice_ioclass(struct task_struct *task)
 {
 	if (task->policy == SCHED_IDLE)
 		return IOPRIO_CLASS_IDLE;
-	else if (task->policy == SCHED_FIFO || task->policy == SCHED_RR)
+	else if (task_is_realtime(task))
 		return IOPRIO_CLASS_RT;
 	else
 		return IOPRIO_CLASS_BE;
#3 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 15 lines · Sebastian Andrzej Siewior

This helper returns true if a task has elevated priority which is true for RT tasks (SCHED_RR and SCHED_FIFO) and also for SCHED_DEADLINE. A task which runs at RT priority due to PI-boosting is not considered as one with elevated priority.

---
 include/linux/sched/rt.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/sched/rt.h +0 -0
index f93329aba31a..30a86b8178f8 100644

include/linux/sched/rt.h static inline int rt_task(struct task_struct *p) · line 20

Quoted 4 lines
include/linux/sched/rt.h +1 -0
@@ -17,6 +17,17 @@ static inline int rt_task(struct task_struct *p)
 	return rt_prio(p->prio);
 }
 
+static inline bool task_is_elevated(struct task_struct *tsk)

Would you be terribly upset if I rename that? I'm thinking something like task_is_realtime() better reflects what it does.

Quoted 16 lines
include/linux/sched/rt.h +10 -0
+{
+	int policy = tsk->policy;
+
+	if (policy == SCHED_FIFO || policy == SCHED_RR)
+		return true;
+	if (policy == SCHED_DEADLINE)
+		return true;
+	return false;
+}
+
 #ifdef CONFIG_RT_MUTEXES
 /*
  * Must hold either p->pi_lock or task_rq(p)->lock.
Signature · 1 line
2.14.2
#4 lore raw
Quoted 10 lines · Peter Zijlstra

include/linux/sched/rt.h static inline int rt_task(struct task_struct *p) · line 20

Quoted 7 lines
include/linux/sched/rt.h +1 -0
@@ -17,6 +17,17 @@ static inline int rt_task(struct task_struct *p)
 	return rt_prio(p->prio);
 }
 
+static inline bool task_is_elevated(struct task_struct *tsk)

Would you be terribly upset if I rename that? I'm thinking something like task_is_realtime() better reflects what it does.

no, not at all.

Sebastian

#5 lore raw
In reply to Sebastian Andrzej Siewior
sched/rt: Add a helper to test for a RT task
Commit-ID:  ff0d4a9dc16b1f4c954f6407c233ab848bdfe8b0
Gitweb:     https://git.kernel.org/tip/ff0d4a9dc16b1f4c954f6407c233ab848bdfe8b0
Author:     Sebastian Andrzej Siewior <[email protected]>
AuthorDate: Wed, 4 Oct 2017 17:49:00 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 10 Oct 2017 11:45:38 +0200

sched/rt: Add a helper to test for a RT task

This helper returns true if a task has elevated priority which is true for RT tasks (SCHED_RR and SCHED_FIFO) and also for SCHED_DEADLINE. A task which runs at RT priority due to PI-boosting is not considered as one with elevated priority.

---
 include/linux/sched/rt.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/sched/rt.h +11 -0
index f93329a..1330016 100644
@@ -17,6 +17,17 @@ static inline int rt_task(struct task_struct *p)
 	return rt_prio(p->prio);
 }
 
+static inline bool task_is_realtime(struct task_struct *tsk)
+{
+	int policy = tsk->policy;
+
+	if (policy == SCHED_FIFO || policy == SCHED_RR)
+		return true;
+	if (policy == SCHED_DEADLINE)
+		return true;
+	return false;
+}
+
 #ifdef CONFIG_RT_MUTEXES
 /*
  * Must hold either p->pi_lock or task_rq(p)->lock.