All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Desfossez <jdesfossez@efficios.com>
To: peterz@infradead.org, tglx@linutronix.de, rostedt@goodmis.org,
	mingo@redhat.com, daolivei@redhat.com
Cc: mathieu.desnoyers@efficios.com, linux-kernel@vger.kernel.org,
	Julien Desfossez <jdesfossez@efficios.com>
Subject: [RFC PATCH v2 1/5] sched: get effective policy and rt_prio
Date: Fri, 23 Sep 2016 12:49:31 -0400	[thread overview]
Message-ID: <1474649375-28056-2-git-send-email-jdesfossez@efficios.com> (raw)
In-Reply-To: <1474649375-28056-1-git-send-email-jdesfossez@efficios.com>

Helper functions to get the effective policy and rt_priority from the
prio and policy values. This is useful in PI situations because these
fields are not updated in the task, only the sched_class is temporarily
modified.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt (Red Hat) <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
---
 include/linux/sched.h |  2 ++
 kernel/sched/core.c   | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index af39baf..0c03595 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2594,6 +2594,8 @@ static inline bool is_idle_task(const struct task_struct *p)
 	struct thread_info thread_info;
 	unsigned long stack[THREAD_SIZE/sizeof(long)];
 };
+extern int effective_policy(int policy, int prio);
+extern int effective_rt_prio(int prio);
 
 #ifndef __HAVE_ARCH_KSTACK_END
 static inline int kstack_end(void *addr)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f5f7b3c..f3817b5 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -916,6 +916,42 @@ static int effective_prio(struct task_struct *p)
 	return p->prio;
 }
 
+/*
+ * Get the effective policy based on the current prio value.
+ */
+int effective_policy(int policy, int prio)
+{
+	if (dl_prio(prio))
+		return SCHED_DEADLINE;
+
+	/* With RT, the default class is SCHED_FIFO. */
+	if (rt_prio(prio)) {
+		if (policy == SCHED_RR)
+			return SCHED_RR;
+		return SCHED_FIFO;
+	}
+
+	/* With fair, the default class is SCHED_NORMAL. */
+	switch (policy) {
+	case SCHED_NORMAL:
+	case SCHED_IDLE:
+	case SCHED_BATCH:
+		return policy;
+	}
+	return SCHED_NORMAL;
+}
+
+/*
+ * Get the effective rt priority based on the current prio value.
+ */
+int effective_rt_prio(int prio)
+{
+	if (!rt_prio(prio))
+		return 0;
+
+	return MAX_RT_PRIO - 1 - prio;
+}
+
 /**
  * task_curr - is this task currently executing on a CPU?
  * @p: the task in question.
-- 
1.9.1

  reply	other threads:[~2016-09-23 16:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-23 16:49 [RFC PATCH v2 0/5] Additional scheduling information in tracepoints Julien Desfossez
2016-09-23 16:49 ` Julien Desfossez [this message]
2016-09-23 16:49 ` [RFC PATCH v2 2/5] tracing: add TRACE_EVENT_MAP Julien Desfossez
2016-09-23 16:49 ` [RFC PATCH v2 3/5] tracing: extend scheduling tracepoints Julien Desfossez
2016-09-23 16:49 ` [RFC PATCH v2 4/5] tracing: extend sched_pi_setprio Julien Desfossez
2016-09-23 16:49 ` [RFC PATCH v2 5/5] tracing: add sched_update_prio Julien Desfossez
2016-09-24 13:28   ` Mathieu Desnoyers
2016-09-26 12:27 ` [RFC PATCH v2 0/5] Additional scheduling information in tracepoints Peter Zijlstra
2016-09-26 19:37   ` Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474649375-28056-2-git-send-email-jdesfossez@efficios.com \
    --to=jdesfossez@efficios.com \
    --cc=daolivei@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.