GeezerVison is showing github.com — Add `SCHED_DEADLINE` and `SCHED_NORMAL` constants to `os` module · Issue #127688 · python/cpython
Add SCHED_DEADLINE and SCHED_NORMAL constants to os module #127688DescriptionFeature or enhancement
Proposal:
This issue suggests adding new os constants.
os.SCHED_DEADLINE
# deadline scheduling
# Set the current schedule to real-time schedule, To be precise, it
# is not real-time scheduling, but it is relatively real-time.
prio = os.sched_param(sched_priority=10)
os.sched_setscheduler(0, os.SCHED_DEADLINE, prio)
SCHED_NORMAL is the same as SCHED_OTHER.
But to run in the old linux, we can't remove SCHED_OTHER, even if it no longer exists in the current main branch.
But we still need to add SCHED_NORMAL, because SCHED_OTHER only exists in the old distribution.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
Activitychanged the title [-]Add SCHED_DEADLINE and SCHED_NORMAL constants to `os` module[/-] [+]Add `SCHED_DEADLINE` and `SCHED_NORMAL` constants to `os` module[/+] on Dec 6, 2024encukou commented on Dec 13, 2024 I don't have SCHED_NORMAL on my Fedora 41. I'd like to test with a system that has it; are you aware of one? rruuaanng commented on Dec 14, 2024 ContributorAuthor More actions Can you try running the following code? SCHED_NORMAL has been present in Linux 2.6.12 and still exists in later versions.
#include <linux/sched.h>
#include <stdio.h>
int main()
{
printf("%d ", SCHED_NORMAL);
/* It should output 0 */
return 0;
}
In pyrepl
>>> import os
>>> os.SCHED_NORMAL
0
>>> os.SCHED_OTHER
0
ref:
https://github.com/torvalds/linux/blob/9ee1c939d1cb936b1f98e8d81aeffab57bae46ab/include/linux/sched.h#L132
my os: Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-86-generic x86_64)
Edit
etc. That was actually my mistake, we should have imported linux/sched.h, not sched.h. Our existing posixmodule.c uses sched.h. encukou commented on Dec 16, 2024 Looking around, it seems like the kernel headers in linux/*.h are meant for the kernel, rather than user-space programs -- e.g. from this LWN article:
The use of kernel headers in user space has long been discouraged.
I didn't find any official source saying it's OK to include linux/sched.h outside the kernel. Am I overthinking this? rruuaanng commented on Dec 17, 2024 ContributorAuthor More actions
I didn't find any official source saying it's OK to include linux/sched.h outside the kernel. Am I overthinking this?
What I mean is, yes.
Looking around, it seems like the kernel headers in linux/*.h are meant for the kernel
Typically, GCC searches using the following paths, assuming you haven’t changed them. Additionally, linux/*.h files are divided into kernel-space and user-space headers. Only when compiling a kernel module will it link to the kernel header files.
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/11/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
# 0 "/dev/null"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "/dev/null"
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-E' '-mtune=generic' '-march=x86-64'
https://github.com/torvalds/linux/blob/f44d154d6e3d633d4c49a5d6aed8a0e4684ae25e/include/uapi/linux/sched.h#L114
You will find that the content of your /usr/include/linux/sched.h is almost the same as it.
Edit
This may not be convincing as they are not exactly similar, but we import multiple linux/*.h in posixmodule.c and I don't think it matters.
#ifdef HAVE_LINUX_RANDOM_H
# include <linux/random.h>
#endif
#ifdef HAVE_LINUX_MEMFD_H
# include <linux/memfd.h>
#endif
#ifdef HAVE_LINUX_WAIT_H
# include <linux/wait.h> // P_PIDFD
#endif
added a commit that references this issue on Dec 19, 2024gh-127688: Add `SCHED_DEADLINE` and `SCHED_NORMAL` constants to `os` … encukou commented on Dec 19, 2024 OK.
Merged, thank you for the contribution! Reacted by RUANG (James Roy)
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|