glibc/glibc-RHEL-58357-4.patch
Frédéric Bérat f8b71945b7 Added sched_setattr and sched_getattr functions to glibc.
- Backport: stdlib: Do not use GLIBC_PRIVATE ABI for errno in libc_nonshared.a
- Backport: manual: Extract the @manpageurl{func,sec} macro
- Backport: Linux: Add the sched_setattr and sched_getattr functions
  Note: The patch has been adapted downstream to avoid ABI changes
- Backport: Linux: Add missing scheduler constants to <sched.h>
- Backport: Linux: Do not check unused bytes after sched_getattr in tst-sched_setattr
- Backport: Linux: Add the pthread_gettid_np function (bug 27880)
  Note: The patch has been adapted downstream to avoid ABI changes
- Backport: Linux: Remove attribute access from sched_getattr (bug 32781)
- Backport: Linux: Add new test misc/tst-sched_setattr-thread
- Backport: nptl: Include <stdbool.h> in tst-pthread_gettid_np.c
- Backport: Makefile: Clean up pthread_atfork integration
- Backport: manual: fix typo for sched_[sg]etattr

Resolves: RHEL-58357
2025-08-07 16:07:09 +02:00

140 lines
5.1 KiB
Diff

commit c444cc1d8335243c5c4e636d6a26c472df85522c
Author: Florian Weimer <fweimer@redhat.com>
Date: Wed Sep 11 10:05:08 2024 +0200
Linux: Add missing scheduler constants to <sched.h>
And add a test, misc/tst-sched-consts, that checks
consistency with <sched.h>.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index a0f79f7513a64616..af7fbac14534e601 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -403,6 +403,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
diff --git a/sysdeps/unix/sysv/linux/bits/sched.h b/sysdeps/unix/sysv/linux/bits/sched.h
index e5b7efb887fb98da..a02cb69de77794fa 100644
--- a/sysdeps/unix/sysv/linux/bits/sched.h
+++ b/sysdeps/unix/sysv/linux/bits/sched.h
@@ -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
@@ -37,6 +38,19 @@
/* 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
index 0000000000000000..70071dcd974fe064
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-sched-consts.py
@@ -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()
diff --git a/sysdeps/unix/sysv/linux/tst-sched_setattr.c b/sysdeps/unix/sysv/linux/tst-sched_setattr.c
index a6288a1a7cc2d01b..fbb73c31a72de311 100644
--- a/sysdeps/unix/sysv/linux/tst-sched_setattr.c
+++ b/sysdeps/unix/sysv/linux/tst-sched_setattr.c
@@ -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. */