]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Linux: Add missing scheduler constants to <sched.h>
authorFlorian Weimer <fweimer@redhat.com>
Wed, 11 Sep 2024 08:05:08 +0000 (10:05 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 11 Sep 2024 08:05:08 +0000 (10:05 +0200)
And add a test, misc/tst-sched-consts, that checks
consistency with <sched.h>.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
sysdeps/unix/sysv/linux/Makefile
sysdeps/unix/sysv/linux/bits/sched.h
sysdeps/unix/sysv/linux/tst-sched-consts.py [new file with mode: 0644]
sysdeps/unix/sysv/linux/tst-sched_setattr.c

index 0b45d4e42bab0d5d90125f9ed947b427edec8780..7df51a325cef5f65869e0e3b600ceb905c0147cc 100644 (file)
@@ -398,6 +398,16 @@ $(objpfx)tst-mount-compile.out: ../sysdeps/unix/sysv/linux/tst-mount-compile.py
          < /dev/null > $@ 2>&1; $(evaluate-test)
 $(objpfx)tst-mount-compile.out: $(sysdeps-linux-python-deps)
 
+tests-special += \
+  $(objpfx)tst-sched-consts.out \
+  # tests-special
+$(objpfx)tst-sched-consts.out: ../sysdeps/unix/sysv/linux/tst-sched-consts.py
+       $(sysdeps-linux-python) \
+         ../sysdeps/unix/sysv/linux/tst-sched-consts.py \
+           $(sysdeps-linux-python-cc) \
+         < /dev/null > $@ 2>&1; $(evaluate-test)
+$(objpfx)tst-sched-consts.out: $(sysdeps-linux-python-deps)
+
 tst-rseq-disable-ENV = GLIBC_TUNABLES=glibc.pthread.rseq=0
 
 endif # $(subdir) == misc
index e5b7efb887fb98da6fc3961fdd3e1cff05698fad..a02cb69de77794faf271189a603cd653e219b0d0 100644 (file)
@@ -29,6 +29,7 @@
 #define SCHED_FIFO             1
 #define SCHED_RR               2
 #ifdef __USE_GNU
+# define SCHED_NORMAL          SCHED_OTHER
 # define SCHED_BATCH           3
 # define SCHED_ISO             4
 # define SCHED_IDLE            5
 /* Flags that can be used in policy values.  */
 # define SCHED_RESET_ON_FORK   0x40000000
 
+/* Flags for the sched_flags field in struct sched_attr.   */
+#define SCHED_FLAG_RESET_ON_FORK       0x01
+#define SCHED_FLAG_RECLAIM             0x02
+#define SCHED_FLAG_DL_OVERRUN          0x04
+#define SCHED_FLAG_KEEP_POLICY         0x08
+#define SCHED_FLAG_KEEP_PARAMS         0x10
+#define SCHED_FLAG_UTIL_CLAMP_MIN      0x20
+#define SCHED_FLAG_UTIL_CLAMP_MAX      0x40
+
+/* Combinations of sched_flags fields.  */
+#define SCHED_FLAG_KEEP_ALL            0x18
+#define SCHED_FLAG_UTIL_CLAMP          0x60
+
 /* Use "" to work around incorrect macro expansion of the
    __has_include argument (GCC PR 80005).  */
 # ifdef __has_include
diff --git a/sysdeps/unix/sysv/linux/tst-sched-consts.py b/sysdeps/unix/sysv/linux/tst-sched-consts.py
new file mode 100644 (file)
index 0000000..70071dc
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/python3
+# Test that glibc's sched.h constants match the kernel's.
+# Copyright (C) 2018-2024 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+#
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <https://www.gnu.org/licenses/>.
+
+import argparse
+import sys
+
+import glibcextract
+import glibcsyscalls
+
+
+def main():
+    """The main entry point."""
+    parser = argparse.ArgumentParser(
+        description="Test that glibc's sched.h constants "
+        "match the kernel's.")
+    parser.add_argument('--cc', metavar='CC',
+                        help='C compiler (including options) to use')
+    args = parser.parse_args()
+    linux_version_headers = glibcsyscalls.linux_kernel_version(args.cc)
+    linux_version_glibc = (6, 10)
+    sys.exit(glibcextract.compare_macro_consts(
+        '#define _GNU_SOURCE 1\n'
+        '#include <sched.h>\n',
+        '#define _GNU_SOURCE 1\n'
+        '#include <linux/sched.h>\n'
+        '#include <linux/sched/types.h>\n',
+        args.cc,
+        'SCHED_.*',
+        # SCHED_ISO is reserved, but not implemented in the kernel.
+        # SCHED_OTHER is the standard name for SCHED_NORMAL.
+        # SCHED_FLAG_ALL will receive more and more flags, so
+        # exposing it to userspace does not seem useful.
+        'SCHED_ISO'
+        '|SCHED_OTHER'
+        '|SCHED_FLAG_ALL',
+        linux_version_glibc > linux_version_headers,
+        linux_version_headers > linux_version_glibc))
+
+if __name__ == '__main__':
+    main()
index a6288a1a7cc2d01b0a7aea00dda904dc00cde90c..fbb73c31a72de311b507d45b8a1b628950620918 100644 (file)
@@ -44,6 +44,8 @@ check_unused (void)
 static int
 do_test (void)
 {
+  _Static_assert (SCHED_OTHER == SCHED_NORMAL,
+                  "SCHED_OTHER, SCHED_NORMAL values");
   TEST_VERIFY (sizeof (struct sched_attr) < sizeof (u));
 
   /* Check that reading and re-applying the current policy works.  */