Commit 130fd056 authored by Qais Yousef's avatar Qais Yousef Committed by Peter Zijlstra
Browse files

sched/rt: Clean up usage of rt_task()

rt_task() checks if a task has RT priority. But depends on your
dictionary, this could mean it belongs to RT class, or is a 'realtime'
task, which includes RT and DL classes.

Since this has caused some confusion already on discussion [1], it
seemed a clean up is due.

I define the usage of rt_task() to be tasks that belong to RT class.
Make sure that it returns true only for RT class and audit the users and
replace the ones required the old behavior with the new realtime_task()
which returns true for RT and DL classes. Introduce similar
realtime_prio() to create similar distinction to rt_prio() and update
the users that required the old behavior to use the new function.

Move MAX_DL_PRIO to prio.h so it can be used in the new definitions.

Document the functions to make it more obvious what is the difference
between them. PI-boosted tasks is a factor that must be taken into
account when choosing which function to use.

Rename task_is_realtime() to realtime_task_policy() as the old name is
confusing against the new realtime_task().

No functional changes were intended.

[1] https://lore.kernel.org/lkml/20240506100509.GL40213@noisy.programming.kicks-ass.net/



Signed-off-by: default avatarQais Yousef <qyousef@layalina.io>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarPhil Auld <pauld@redhat.com>
Reviewed-by: default avatar"Steven Rostedt (Google)" <rostedt@goodmis.org>
Reviewed-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/r/20240610192018.1567075-2-qyousef@layalina.io
parent 4ae0c2b9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -335,7 +335,7 @@ static inline bool six_owner_running(struct six_lock *lock)
	 */
	rcu_read_lock();
	struct task_struct *owner = READ_ONCE(lock->owner);
	bool ret = owner ? owner_on_cpu(owner) : !rt_task(current);
	bool ret = owner ? owner_on_cpu(owner) : !realtime_task(current);
	rcu_read_unlock();

	return ret;
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ u64 select_estimate_accuracy(struct timespec64 *tv)
	 * Realtime tasks get a slack of 0 for obvious reasons.
	 */

	if (rt_task(current))
	if (realtime_task(current))
		return 0;

	ktime_get_ts64(&now);
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ static inline int task_nice_ioclass(struct task_struct *task)
{
	if (task->policy == SCHED_IDLE)
		return IOPRIO_CLASS_IDLE;
	else if (task_is_realtime(task))
	else if (realtime_task_policy(task))
		return IOPRIO_CLASS_RT;
	else
		return IOPRIO_CLASS_BE;
+4 −2
Original line number Diff line number Diff line
@@ -10,8 +10,6 @@

#include <linux/sched.h>

#define MAX_DL_PRIO		0

static inline int dl_prio(int prio)
{
	if (unlikely(prio < MAX_DL_PRIO))
@@ -19,6 +17,10 @@ static inline int dl_prio(int prio)
	return 0;
}

/*
 * Returns true if a task has a priority that belongs to DL class. PI-boosted
 * tasks will return true. Use dl_policy() to ignore PI-boosted tasks.
 */
static inline int dl_task(struct task_struct *p)
{
	return dl_prio(p->prio);
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
 */

#define MAX_RT_PRIO		100
#define MAX_DL_PRIO		0

#define MAX_PRIO		(MAX_RT_PRIO + NICE_WIDTH)
#define DEFAULT_PRIO		(MAX_RT_PRIO + NICE_WIDTH / 2)
Loading