[newlib-cygwin/main] Cygwin: sched_setscheduler: accept SCHED_IDLE

Corinna Vinschen corinna@sourceware.org
Wed Dec 4 20:44:22 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=61c2f075cd55d4a52b4713383f75870c1e416923

commit 61c2f075cd55d4a52b4713383f75870c1e416923
Author:     Christian Franke <christian.franke@t-online.de>
AuthorDate: Tue Dec 3 15:42:50 2024 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Dec 4 19:06:48 2024 +0100

    Cygwin: sched_setscheduler: accept SCHED_IDLE
    
    Add SCHED_IDLE to <sys/sched.h>.  If SCHED_IDLE is selected, preserve
    the nice value and set the Windows priority to IDLE_PRIORITY_CLASS.
    
    Signed-off-by: Christian Franke <christian.franke@t-online.de>

Diff:
---
 newlib/libc/include/sys/sched.h |  4 ++++
 winsup/cygwin/release/3.6.0     | 10 ++++++----
 winsup/cygwin/sched.cc          |  9 +++++++--
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/newlib/libc/include/sys/sched.h b/newlib/libc/include/sys/sched.h
index 4adb6e2d617d..c96355c24de7 100644
--- a/newlib/libc/include/sys/sched.h
+++ b/newlib/libc/include/sys/sched.h
@@ -42,6 +42,10 @@ extern "C" {
 #define SCHED_SPORADIC 4
 #endif
 
+#if __GNU_VISIBLE
+#define SCHED_IDLE     5
+#endif
+
 /* Scheduling Parameters */
 /* Open Group Specifications Issue 6 */
 
diff --git a/winsup/cygwin/release/3.6.0 b/winsup/cygwin/release/3.6.0
index 9e924dabbf2a..8ca91f0c99c1 100644
--- a/winsup/cygwin/release/3.6.0
+++ b/winsup/cygwin/release/3.6.0
@@ -54,9 +54,11 @@ What changed:
   to POSIX and Linux (glibc >= 2.2.4) behavior.
 
 - sched_setscheduler(2) now emulates changes between SCHED_OTHER,
-  SCHED_FIFO and SCHED_RR.  If SCHED_OTHER is selected, the Windows
-  priority is set according to the nice value.  If SCHED_FIFO or
-  SCHED_RR is selected, the nice value is preserved and the Windows
-  priority is set according to the realtime priority.
+  SCHED_IDLE, SCHED_FIFO and SCHED_RR.  If SCHED_OTHER is selected, the
+  Windows priority is set according to the nice value. If SCHED_IDLE is
+  selected, the nice value is preserved and the Windows priority is set
+  to IDLE_PRIORITY_CLASS.  If SCHED_FIFO or SCHED_RR is selected, the
+  nice value is preserved and the Windows priority is set according to
+  the realtime priority.
   Note: Windows does not offer alternative scheduling policies so
   this could only emulate API behavior.
diff --git a/winsup/cygwin/sched.cc b/winsup/cygwin/sched.cc
index c48c433d7348..8b4e7efc4545 100644
--- a/winsup/cygwin/sched.cc
+++ b/winsup/cygwin/sched.cc
@@ -34,6 +34,7 @@ sched_get_priority_max (int policy)
   switch (policy)
     {
     case SCHED_OTHER:
+    case SCHED_IDLE:
       return 0;
     case SCHED_FIFO:
     case SCHED_RR:
@@ -50,6 +51,7 @@ sched_get_priority_min (int policy)
   switch (policy)
     {
     case SCHED_OTHER:
+    case SCHED_IDLE:
       return 0;
     case SCHED_FIFO:
     case SCHED_RR:
@@ -93,7 +95,7 @@ sched_getparam (pid_t pid, struct sched_param *param)
       return -1;
     }
 
-  if (p->sched_policy == SCHED_OTHER)
+  if (p->sched_policy == SCHED_OTHER || p->sched_policy == SCHED_IDLE)
     {
       /* No realtime policy. */
       param->sched_priority = 0;
@@ -235,6 +237,9 @@ sched_setparam_pinfo (pinfo & p, const struct sched_param *param)
   if (p->sched_policy == SCHED_OTHER && pri == 0)
     /* No realtime policy, reapply the nice value. */
     pclass = nice_to_winprio (p->nice);
+  else if (p->sched_policy == SCHED_IDLE && pri == 0)
+    /* Idle policy, ignore the nice value. */
+    pclass = IDLE_PRIORITY_CLASS;
   else if (1 <= pri && pri <= 6)
     pclass = IDLE_PRIORITY_CLASS;
   else if (pri <= 12)
@@ -417,7 +422,7 @@ sched_setscheduler (pid_t pid, int policy,
 		    const struct sched_param *param)
 {
   if (!(pid >= 0 && param &&
-      ((policy == SCHED_OTHER && param->sched_priority == 0) ||
+      (((policy == SCHED_OTHER || policy == SCHED_IDLE) && param->sched_priority == 0) ||
       ((policy == SCHED_FIFO || policy == SCHED_RR) && valid_sched_parameters(param)))))
     {
       set_errno (EINVAL);


More information about the Cygwin-cvs mailing list