Disallow setting of priority for SCHED_OTHER threads on NetBSD
authorKamil Rytarowski <n54@gmx.com>
Sat, 20 Feb 2016 14:51:18 +0000 (15:51 +0100)
committerKamil Rytarowski <n54@gmx.com>
Sat, 20 Feb 2016 14:55:27 +0000 (15:55 +0100)
commit7a9ccddf47b138f55ffa2bb0d52210e32738bd22
tree19c9e25ec1d2ecca337f232d925e1627a3b0072b
parent764c98414a5218fd66dd8b801ea8e88af156f43d
Disallow setting of priority for SCHED_OTHER threads on NetBSD

There are 7 PAL tests that are falling down due to calling
pthread_setschedparam(3) on NetBSD.

Diving into the kernel code I have found that SCHED_OTHER does not support
setting priorities other than PRI_NONE.

        /* Disallow setting of priority for SCHED_OTHER threads */
        if (lpolicy == SCHED_OTHER && pri != PRI_NONE) {
            lwp_unlock(t);
            error = EINVAL;
            break;
        }

-- NetBSD sources sys/kern/sys_sched.c Line 167

/usr/include/sys/param.h:#define    PRI_NONE        (-1)

It looks like the same rule applies for Linux:

       SCHED_OTHER is the default universal time-sharing scheduler policy used
       by most processes, SCHED_FIFO and SCHED_RR  are  intended  for  special
       time-critical  applications  that  need precise control over the way in
       which runnable processes are selected for execution.  Processes  sched-
       uled with SCHED_OTHER must be assigned the static priority 0, processes
       scheduled under SCHED_FIFO or SCHED_RR can have a  static  priority  in
       the  range  1 to 99. Only processes with superuser privileges can get a
       ordering within the list of runnable processes with equal static prior-
       ity.

-- http://ccrma.stanford.edu/planetccrma/man/man2/sched_setscheduler.2.html

Standard says:

    The pthread_getschedparam() and pthread_setschedparam() functions shall,
    respectively, get and set the scheduling policy and parameters of individual
    threads within a multi-threaded process to be retrieved and set. For
    SCHED_FIFO and SCHED_RR, the only required member of the sched_param
    structure is the priority sched_priority. For SCHED_OTHER, the affected
    scheduling parameters are implementation-defined.

    The policy parameter may have the value SCHED_OTHER, SCHED_FIFO, or
    SCHED_RR. The scheduling parameters for the SCHED_OTHER policy are
    implementation-defined. The SCHED_FIFO and SCHED_RR policies shall have a
    single scheduling parameter, priority.

http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getschedparam.html

The culprit code is here: src/pal/src/thread/thread.cpp Line 1276

Fix dotnet/coreclr#3272

Commit migrated from https://github.com/dotnet/coreclr/commit/d279c120b271393726920d85f46c2b503cb1b14d
src/coreclr/src/pal/src/config.h.in
src/coreclr/src/pal/src/configure.cmake
src/coreclr/src/pal/src/thread/thread.cpp