You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/06/24 11:50:57 UTC

[incubator-nuttx] 01/02: libc/sched: Map the nice value more correctly

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 3d0320f8912188663f1aab908d37736bc482b528
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Jun 22 17:00:09 2021 +0800

    libc/sched: Map the nice value more correctly
    
    from https://pubs.opengroup.org/onlinepubs/007904875/functions/setpriority.html:
    1.The nice value shall in the range [-{NZERO},{NZERO} -1]
    2.Lower nice value shall cause more favorable scheduling
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Change-Id: I5ad60d92abc3b69fbaa406da68cec2e40ca3fa6d
---
 include/limits.h                   | 4 ++--
 libs/libc/unistd/lib_getpriority.c | 6 +++++-
 libs/libc/unistd/lib_setpriority.c | 2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/limits.h b/include/limits.h
index ec18dd7..28f02c4 100644
--- a/include/limits.h
+++ b/include/limits.h
@@ -276,10 +276,10 @@
 #define NL_TEXTMAX _POSIX2_LINE_MAX
 
 /* NZERO
- *   Default process priority. Minimum Acceptable Value: 20
+ *   Default process priority. Minimum Acceptable Value: 128
  */
 
-#define NZERO 20
+#define NZERO 128
 
 /* Required for asynchronous I/O */
 
diff --git a/libs/libc/unistd/lib_getpriority.c b/libs/libc/unistd/lib_getpriority.c
index 95996d2..44d9c8d 100644
--- a/libs/libc/unistd/lib_getpriority.c
+++ b/libs/libc/unistd/lib_getpriority.c
@@ -82,5 +82,9 @@ int getpriority(int which, id_t who)
       return ret;
     }
 
-  return param.sched_priority;
+  /* Since -1 is a legal return value, clear errno to avoid the chaos */
+
+  set_errno(0);
+
+  return NZERO - param.sched_priority;
 }
diff --git a/libs/libc/unistd/lib_setpriority.c b/libs/libc/unistd/lib_setpriority.c
index 057f05f..d02c7af 100644
--- a/libs/libc/unistd/lib_setpriority.c
+++ b/libs/libc/unistd/lib_setpriority.c
@@ -69,7 +69,7 @@ int setpriority(int which, id_t who, int value)
       return ret;
     }
 
-  param.sched_priority = value;
+  param.sched_priority = NZERO - value;
 
   return sched_setparam(who, &param);
 }