]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chrt: add support for SCHED_EXT
authorShashank Balaji <shashank.mahadasyam@sony.com>
Fri, 16 May 2025 09:33:45 +0000 (18:33 +0900)
committerShashank Balaji <shashank.mahadasyam@sony.com>
Fri, 16 May 2025 09:33:45 +0000 (18:33 +0900)
SCHED_EXT lets processes be scheduled by a BPF program-defined
scheduler. This is supported since kernel version 6.12.

Signed-off-by: Shashank Balaji <shashank.mahadasyam@sony.com>
schedutils/chrt.c
schedutils/sched_attr.h

index 4f6a027f3b8c0c741c28119c6a86ed8ee9d8443f..075b592bbebb37fb9d8c332e58bfc8b53a282ad5 100644 (file)
@@ -71,6 +71,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_("Policy options:\n"), out);
        fputs(_(" -b, --batch          set policy to SCHED_BATCH\n"), out);
        fputs(_(" -d, --deadline       set policy to SCHED_DEADLINE\n"), out);
+       fputs(_(" -e, --ext            set policy to SCHED_EXT\n"), out);
        fputs(_(" -f, --fifo           set policy to SCHED_FIFO\n"), out);
        fputs(_(" -i, --idle           set policy to SCHED_IDLE\n"), out);
        fputs(_(" -o, --other          set policy to SCHED_OTHER\n"), out);
@@ -120,6 +121,10 @@ static const char *get_policy_name(int policy)
 #ifdef SCHED_DEADLINE
        case SCHED_DEADLINE:
                return "SCHED_DEADLINE";
+#endif
+#ifdef SCHED_EXT
+       case SCHED_EXT:
+               return "SCHED_EXT";
 #endif
        default:
                break;
@@ -289,6 +294,9 @@ static void show_min_max(void)
 #endif
 #ifdef SCHED_DEADLINE
                SCHED_DEADLINE,
+#endif
+#ifdef SCHED_EXT
+               SCHED_EXT,
 #endif
        };
 
@@ -397,6 +405,7 @@ int main(int argc, char **argv)
                { "all-tasks",  no_argument, NULL, 'a' },
                { "batch",      no_argument, NULL, 'b' },
                { "deadline",   no_argument, NULL, 'd' },
+               { "ext",        no_argument, NULL, 'e' },
                { "fifo",       no_argument, NULL, 'f' },
                { "idle",       no_argument, NULL, 'i' },
                { "pid",        no_argument, NULL, 'p' },
@@ -418,7 +427,7 @@ int main(int argc, char **argv)
        textdomain(PACKAGE);
        close_stdout_atexit();
 
-       while((c = getopt_long(argc, argv, "+abdD:fiphmoP:T:rRvV", longopts, NULL)) != -1)
+       while((c = getopt_long(argc, argv, "+abdD:efiphmoP:T:rRvV", longopts, NULL)) != -1)
        {
                switch (c) {
                case 'a':
@@ -433,6 +442,11 @@ int main(int argc, char **argv)
                case 'd':
 #ifdef SCHED_DEADLINE
                        ctl->policy = SCHED_DEADLINE;
+#endif
+                       break;
+               case 'e':
+#ifdef SCHED_EXT
+                       ctl->policy = SCHED_EXT;
 #endif
                        break;
                case 'f':
index b7559434cca5de1270edcfb1e487811d3593bfe7..e597bced8734ea273bb567d3142cef46232dd696 100644 (file)
@@ -124,4 +124,12 @@ static int sched_getattr(pid_t pid, struct sched_attr *attr, unsigned int size,
 # define SCHED_DEADLINE 6
 #endif
 
+/* the SCHED_EXT is supported since Linux 6.12
+ * commit id f0e1a0643a59bf1f922fa209cec86a170b784f3f
+ * -- temporary workaround for people with old glibc headers
+ */
+#if defined(__linux__) && !defined(SCHED_EXT)
+# define SCHED_EXT 7
+#endif
+
 #endif /* UTIL_LINUX_SCHED_ATTR_H */