Add p10031b_sched feature
This is so code can test for POSIX sched support at runtime instead of
running syscalls like sched_yield and ending up with -1/ENOSYS
MFC after: 1 week
Differential D9041
Add p10031b_sched feature so code can test for POSIX sched support at runtime ngie on Jan 4 2017, 8:10 AM. Authored by Tags None Referenced Files
Subscribers
Details
Diff Detail
Event TimelineComment Actions Almost right and sufficiently portable way to check for this feature is to do if (sysconf(_SC_POSIX_PRIORITY_SCHEDULING) > 0) { /* supported, execute tests */ } else { /* not supported */ } In other words, there is already POSIX-mandated way of checking the feature presence and I do not see why we need non-portable way to report the same thing. I said that this variant is 'almost' right and correct since POSIX allows the compile-time definitions for the feature to be absent, and also allows to detect at compile time that the feature is guaranteed to be always present. Both of these variants are not possible on freebsd and would only make the code clumsier. Comment Actions Unfortunately this is always enabled with sys/sys/unistd.h: 68 #define _POSIX_PRIORITY_SCHEDULING 200112L I think you're on the right track though -- this should be fixed. Comment Actions Wait.. this is confusing: 228 #if _POSIX_PRIORITY_SCHEDULING == 0 So... if it's set to 0, then it'll try to detect the support in the kernel -- otherwise it will always assume that it's on...? This seems really broken :(. Comment Actions Yes, I think the bug in the code which you cited is that sys/sys/unistd.h defines _POSIX_PRIORITY_SCHEDULING as 200112L, instead of 0. From the code in sys/kern/p1003_1b.c and lib/libc/gen/sysconf.c, changing that define to 0 should fix the problem and you would be able to use the intended interface. I added Jilles so that he could state the POSIX view on this. Comment Actions Defining _POSIX_PRIORITY_SCHEDULING as 0 in sys/sys/unistd.h will tell applications that compile-time support is available but run-time support needs to be verified using sysconf(), and will tell lib/libc/gen/sysconf.c to query for support using sysctl. Therefore, that seems the right solution to me. There seems no reason to add a FEATURE since the existing sysctl mechanism works fine. Note that POSIX does not specify the compile-time only support level for the option group _XOPEN_REALTIME, since XBD 2.1.5.2 XSI Option Groups simply specifies that _POSIX_PRIORITY_SCHEDULING be defined to 200809L when _XOPEN_REALTIME is defined to a value other than -1. This is irrelevant for us at this time because we define _XOPEN_REALTIME to -1. Comment Actions Abandoning the revision because https://reviews.freebsd.org/D9055 looks like the right solution! |