diff mbox series

[01/14] sched: Provide sched_set_deadline()

Message ID 20200507181012.29791-2-qperret@google.com (mailing list archive)
State RFC, archived
Headers show
Series Modularize schedutil | expand

Commit Message

Quentin Perret May 7, 2020, 6:09 p.m. UTC
As all the sched_setscheduler*() exports have been removed, introduce
sched_set_deadline() on the model of sched_set_fifo() to enable modules
to create SCHED_DEADLINE tasks.

Signed-off-by: Quentin Perret <qperret@google.com>
---
 include/linux/sched.h |  2 ++
 kernel/sched/core.c   | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/sched.h b/include/linux/sched.h
index c0da93a26f62..63c8ae7a0dd8 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1630,6 +1630,8 @@  extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sc
 extern void sched_set_fifo(struct task_struct *p);
 extern void sched_set_fifo_low(struct task_struct *p);
 extern void sched_set_normal(struct task_struct *p, int nice);
+extern int sched_set_deadline(struct task_struct *p, u64 runtime, u64 deadline,
+			      u64 period, u64 flags);
 extern int sched_setattr(struct task_struct *, const struct sched_attr *);
 extern int sched_setattr_nocheck(struct task_struct *, const struct sched_attr *);
 extern struct task_struct *idle_task(int cpu);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 7324f3b0f8d2..dbaf3f63df22 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5136,6 +5136,23 @@  void sched_set_normal(struct task_struct *p, int nice)
 }
 EXPORT_SYMBOL_GPL(sched_set_normal);
 
+int sched_set_deadline(struct task_struct *p, u64 runtime, u64 deadline,
+		       u64 period, u64 flags)
+{
+	struct sched_attr attr = {
+		.size		= sizeof(struct sched_attr),
+		.sched_policy	= SCHED_DEADLINE,
+		.sched_flags	= flags,
+		.sched_nice	= 0,
+		.sched_priority	= 0,
+		.sched_runtime	= runtime,
+		.sched_deadline = deadline,
+		.sched_period	= period,
+	};
+	return sched_setattr_nocheck(p, &attr);
+}
+EXPORT_SYMBOL_GPL(sched_set_deadline);
+
 static int
 do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param)
 {