Skip to content

Commit d50dde5

Browse files
dfaggioliIngo Molnar
authored andcommitted
sched: Add new scheduler syscalls to support an extended scheduling parameters ABI
Add the syscalls needed for supporting scheduling algorithms with extended scheduling parameters (e.g., SCHED_DEADLINE). In general, it makes possible to specify a periodic/sporadic task, that executes for a given amount of runtime at each instance, and is scheduled according to the urgency of their own timing constraints, i.e.: - a (maximum/typical) instance execution time, - a minimum interval between consecutive instances, - a time constraint by which each instance must be completed. Thus, both the data structure that holds the scheduling parameters of the tasks and the system calls dealing with it must be extended. Unfortunately, modifying the existing struct sched_param would break the ABI and result in potentially serious compatibility issues with legacy binaries. For these reasons, this patch: - defines the new struct sched_attr, containing all the fields that are necessary for specifying a task in the computational model described above; - defines and implements the new scheduling related syscalls that manipulate it, i.e., sched_setattr() and sched_getattr(). Syscalls are introduced for x86 (32 and 64 bits) and ARM only, as a proof of concept and for developing and testing purposes. Making them available on other architectures is straightforward. Since no "user" for these new parameters is introduced in this patch, the implementation of the new system calls is just identical to their already existing counterpart. Future patches that implement scheduling policies able to exploit the new data structure must also take care of modifying the sched_*attr() calls accordingly with their own purposes. Signed-off-by: Dario Faggioli <raistlin@linux.it> [ Rewrote to use sched_attr. ] Signed-off-by: Juri Lelli <juri.lelli@gmail.com> [ Removed sched_setscheduler2() for now. ] Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1383831828-15501-3-git-send-email-juri.lelli@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 56b4811 commit d50dde5

File tree

9 files changed

+326
-24
lines changed

9 files changed

+326
-24
lines changed

arch/arm/include/asm/unistd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include <uapi/asm/unistd.h>
1717

18-
#define __NR_syscalls (380)
18+
#define __NR_syscalls (384)
1919
#define __ARM_NR_cmpxchg (__ARM_NR_BASE+0x00fff0)
2020

2121
#define __ARCH_WANT_STAT64

arch/arm/include/uapi/asm/unistd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@
406406
#define __NR_process_vm_writev (__NR_SYSCALL_BASE+377)
407407
#define __NR_kcmp (__NR_SYSCALL_BASE+378)
408408
#define __NR_finit_module (__NR_SYSCALL_BASE+379)
409+
#define __NR_sched_setattr (__NR_SYSCALL_BASE+380)
410+
#define __NR_sched_getattr (__NR_SYSCALL_BASE+381)
409411

410412
/*
411413
* This may need to be greater than __NR_last_syscall+1 in order to

arch/arm/kernel/calls.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@
389389
CALL(sys_process_vm_writev)
390390
CALL(sys_kcmp)
391391
CALL(sys_finit_module)
392+
/* 380 */ CALL(sys_sched_setattr)
393+
CALL(sys_sched_getattr)
392394
#ifndef syscalls_counted
393395
.equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls
394396
#define syscalls_counted

arch/x86/syscalls/syscall_32.tbl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,5 @@
357357
348 i386 process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev
358358
349 i386 kcmp sys_kcmp
359359
350 i386 finit_module sys_finit_module
360+
351 i386 sched_setattr sys_sched_setattr
361+
352 i386 sched_getattr sys_sched_getattr

arch/x86/syscalls/syscall_64.tbl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@
320320
311 64 process_vm_writev sys_process_vm_writev
321321
312 common kcmp sys_kcmp
322322
313 common finit_module sys_finit_module
323+
314 common sched_setattr sys_sched_setattr
324+
315 common sched_getattr sys_sched_getattr
323325

324326
#
325327
# x32-specific system call numbers start at 512 to avoid cache impact

include/linux/sched.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,66 @@ struct sched_param {
5656

5757
#include <asm/processor.h>
5858

59+
#define SCHED_ATTR_SIZE_VER0 48 /* sizeof first published struct */
60+
61+
/*
62+
* Extended scheduling parameters data structure.
63+
*
64+
* This is needed because the original struct sched_param can not be
65+
* altered without introducing ABI issues with legacy applications
66+
* (e.g., in sched_getparam()).
67+
*
68+
* However, the possibility of specifying more than just a priority for
69+
* the tasks may be useful for a wide variety of application fields, e.g.,
70+
* multimedia, streaming, automation and control, and many others.
71+
*
72+
* This variant (sched_attr) is meant at describing a so-called
73+
* sporadic time-constrained task. In such model a task is specified by:
74+
* - the activation period or minimum instance inter-arrival time;
75+
* - the maximum (or average, depending on the actual scheduling
76+
* discipline) computation time of all instances, a.k.a. runtime;
77+
* - the deadline (relative to the actual activation time) of each
78+
* instance.
79+
* Very briefly, a periodic (sporadic) task asks for the execution of
80+
* some specific computation --which is typically called an instance--
81+
* (at most) every period. Moreover, each instance typically lasts no more
82+
* than the runtime and must be completed by time instant t equal to
83+
* the instance activation time + the deadline.
84+
*
85+
* This is reflected by the actual fields of the sched_attr structure:
86+
*
87+
* @size size of the structure, for fwd/bwd compat.
88+
*
89+
* @sched_policy task's scheduling policy
90+
* @sched_flags for customizing the scheduler behaviour
91+
* @sched_nice task's nice value (SCHED_NORMAL/BATCH)
92+
* @sched_priority task's static priority (SCHED_FIFO/RR)
93+
* @sched_deadline representative of the task's deadline
94+
* @sched_runtime representative of the task's runtime
95+
* @sched_period representative of the task's period
96+
*
97+
* Given this task model, there are a multiplicity of scheduling algorithms
98+
* and policies, that can be used to ensure all the tasks will make their
99+
* timing constraints.
100+
*/
101+
struct sched_attr {
102+
u32 size;
103+
104+
u32 sched_policy;
105+
u64 sched_flags;
106+
107+
/* SCHED_NORMAL, SCHED_BATCH */
108+
s32 sched_nice;
109+
110+
/* SCHED_FIFO, SCHED_RR */
111+
u32 sched_priority;
112+
113+
/* SCHED_DEADLINE */
114+
u64 sched_runtime;
115+
u64 sched_deadline;
116+
u64 sched_period;
117+
};
118+
59119
struct exec_domain;
60120
struct futex_pi_state;
61121
struct robust_list_head;
@@ -1958,6 +2018,8 @@ extern int sched_setscheduler(struct task_struct *, int,
19582018
const struct sched_param *);
19592019
extern int sched_setscheduler_nocheck(struct task_struct *, int,
19602020
const struct sched_param *);
2021+
extern int sched_setattr(struct task_struct *,
2022+
const struct sched_attr *);
19612023
extern struct task_struct *idle_task(int cpu);
19622024
/**
19632025
* is_idle_task - is the specified task an idle task?

include/linux/syscalls.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct rlimit;
3838
struct rlimit64;
3939
struct rusage;
4040
struct sched_param;
41+
struct sched_attr;
4142
struct sel_arg_struct;
4243
struct semaphore;
4344
struct sembuf;
@@ -279,9 +280,14 @@ asmlinkage long sys_sched_setscheduler(pid_t pid, int policy,
279280
struct sched_param __user *param);
280281
asmlinkage long sys_sched_setparam(pid_t pid,
281282
struct sched_param __user *param);
283+
asmlinkage long sys_sched_setattr(pid_t pid,
284+
struct sched_attr __user *attr);
282285
asmlinkage long sys_sched_getscheduler(pid_t pid);
283286
asmlinkage long sys_sched_getparam(pid_t pid,
284287
struct sched_param __user *param);
288+
asmlinkage long sys_sched_getattr(pid_t pid,
289+
struct sched_attr __user *attr,
290+
unsigned int size);
285291
asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
286292
unsigned long __user *user_mask_ptr);
287293
asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len,

0 commit comments

Comments
 (0)