History

sched/uclamp: Extend sched_setattr() to support utilization clamping

The SCHED_DEADLINE scheduling class provides an advanced and formal model to define tasks requirements that can translate into proper decisions for both task placements and frequencies selections. Other classes have a more simplified model based on the POSIX concept of priorities. Such a simple priority based model however does not allow to exploit most advanced features of the Linux scheduler like, for example, driving frequencies selection via the schedutil cpufreq governor. However, also for non SCHED_DEADLINE tasks, it's still interesting to define tasks properties to support scheduler decisions. Utilization clamping exposes to user-space a new set of per-task attributes the scheduler can use as hints about the expected/required utilization for a task. This allows to implement a "proactive" per-task frequency control policy, a more advanced policy than the current one based just on "passive" measured task utilization. For example, it's possible to boost interactive tasks (e.g. to get better performance) or cap background tasks (e.g. to be more energy/thermal efficient). Introduce a new API to set utilization clamping values for a specified task by extending sched_setattr(), a syscall which already allows to define task specific properties for different scheduling classes. A new pair of attributes allows to specify a minimum and maximum utilization the scheduler can consider for a task. Do that by validating the required clamp values before and then applying the required changes using _the_ same pattern already in use for __setscheduler(). This ensures that the task is re-enqueued with the new clamp values.

Patrick Bellasi committed 7 years ago

Commit a509a7c1 parent 1d6362f4 files · +161 −17Browse files

Showing the changes to include/uapi/linux (2 of 4 files). Show all

Unified · Split

2 files
  1. include/uapi/linux/sched.h +11 −1
  2. include/uapi/linux/sched/types.h +57 −9
include/uapi/linux/sched.h+11−1
@@ -52,10 +52,20 @@ · 51 unmodified lines
5252 #define SCHED_FLAG_RECLAIM 0x02
5353 #define SCHED_FLAG_DL_OVERRUN 0x04
5454 #define SCHED_FLAG_KEEP_POLICY 0x08
55+#define SCHED_FLAG_KEEP_PARAMS 0x10
56+#define SCHED_FLAG_UTIL_CLAMP_MIN 0x20
57+#define SCHED_FLAG_UTIL_CLAMP_MAX 0x40
58+
59+#define SCHED_FLAG_KEEP_ALL (SCHED_FLAG_KEEP_POLICY | \
60+ SCHED_FLAG_KEEP_PARAMS)
61+
62+#define SCHED_FLAG_UTIL_CLAMP (SCHED_FLAG_UTIL_CLAMP_MIN | \
63+ SCHED_FLAG_UTIL_CLAMP_MAX)
5564
5665 #define SCHED_FLAG_ALL (SCHED_FLAG_RESET_ON_FORK | \
5766 SCHED_FLAG_RECLAIM | \
5867 SCHED_FLAG_DL_OVERRUN | \
59− SCHED_FLAG_KEEP_POLICY)
68+ SCHED_FLAG_KEEP_ALL | \
69+ SCHED_FLAG_UTIL_CLAMP)
6070
6171 #endif /* _UAPI_LINUX_SCHED_H */
include/uapi/linux/sched/types.h+57−9
@@ -9,6 +9,7 @@ struct sched_param { · 8 unmodified lines
99 };
1010
1111 #define SCHED_ATTR_SIZE_VER0 48 /* sizeof first published struct */
12+#define SCHED_ATTR_SIZE_VER1 56 /* add: util_{min,max} */
1213
1314 /*
1415 * Extended scheduling parameters data structure.
@@ -21,8 +22,33 @@ struct sched_param { · 6 unmodified lines
2122 * the tasks may be useful for a wide variety of application fields, e.g.,
2223 * multimedia, streaming, automation and control, and many others.
2324 *
24− * This variant (sched_attr) is meant at describing a so-called
25− * sporadic time-constrained task. In such model a task is specified by:
25+ * This variant (sched_attr) allows to define additional attributes to
26+ * improve the scheduler knowledge about task requirements.
27+ *
28+ * Scheduling Class Attributes
29+ * ===========================
30+ *
31+ * A subset of sched_attr attributes specifies the
32+ * scheduling policy and relative POSIX attributes:
33+ *
34+ * @size size of the structure, for fwd/bwd compat.
35+ *
36+ * @sched_policy task's scheduling policy
37+ * @sched_nice task's nice value (SCHED_NORMAL/BATCH)
38+ * @sched_priority task's static priority (SCHED_FIFO/RR)
39+ *
40+ * Certain more advanced scheduling features can be controlled by a
41+ * predefined set of flags via the attribute:
42+ *
43+ * @sched_flags for customizing the scheduler behaviour
44+ *
45+ * Sporadic Time-Constrained Task Attributes
46+ * =========================================
47+ *
48+ * A subset of sched_attr attributes allows to describe a so-called
49+ * sporadic time-constrained task.
50+ *
51+ * In such a model a task is specified by:
2652 * - the activation period or minimum instance inter-arrival time;
2753 * - the maximum (or average, depending on the actual scheduling
2854 * discipline) computation time of all instances, a.k.a. runtime;
@@ -34,14 +60,8 @@ struct sched_param { · 5 unmodified lines
3460 * than the runtime and must be completed by time instant t equal to
3561 * the instance activation time + the deadline.
3662 *
37− * This is reflected by the actual fields of the sched_attr structure:
63+ * This is reflected by the following fields of the sched_attr structure:
3864 *
39− * @size size of the structure, for fwd/bwd compat.
40− *
41− * @sched_policy task's scheduling policy
42− * @sched_flags for customizing the scheduler behaviour
43− * @sched_nice task's nice value (SCHED_NORMAL/BATCH)
44− * @sched_priority task's static priority (SCHED_FIFO/RR)
4565 * @sched_deadline representative of the task's deadline
4666 * @sched_runtime representative of the task's runtime
4767 * @sched_period representative of the task's period
@@ -53,6 +73,29 @@ struct sched_param { · 5 unmodified lines
5373 * As of now, the SCHED_DEADLINE policy (sched_dl scheduling class) is the
5474 * only user of this new interface. More information about the algorithm
5575 * available in the scheduling class file or in Documentation/.
76+ *
77+ * Task Utilization Attributes
78+ * ===========================
79+ *
80+ * A subset of sched_attr attributes allows to specify the utilization
81+ * expected for a task. These attributes allow to inform the scheduler about
82+ * the utilization boundaries within which it should schedule the task. These
83+ * boundaries are valuable hints to support scheduler decisions on both task
84+ * placement and frequency selection.
85+ *
86+ * @sched_util_min represents the minimum utilization
87+ * @sched_util_max represents the maximum utilization
88+ *
89+ * Utilization is a value in the range [0..SCHED_CAPACITY_SCALE]. It
90+ * represents the percentage of CPU time used by a task when running at the
91+ * maximum frequency on the highest capacity CPU of the system. For example, a
92+ * 20% utilization task is a task running for 2ms every 10ms at maximum
93+ * frequency.
94+ *
95+ * A task with a min utilization value bigger than 0 is more likely scheduled
96+ * on a CPU with a capacity big enough to fit the specified value.
97+ * A task with a max utilization value smaller than 1024 is more likely
98+ * scheduled on a CPU with no more capacity than the specified value.
5699 */
57100 struct sched_attr {
58101 __u32 size;
@@ -70,6 +113,11 @@ struct sched_attr { · 11 unmodified lines
70113 __u64 sched_runtime;
71114 __u64 sched_deadline;
72115 __u64 sched_period;
116+
117+ /* Utilization hints */
118+ __u32 sched_util_min;
119+ __u32 sched_util_max;
120+
73121 };
74122
75123 #endif /* _UAPI_LINUX_SCHED_TYPES_H */