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:56 UTC

[incubator-nuttx] branch master updated (fe992a5 -> 9cc41f4)

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

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


    from fe992a5  libc: Implement fesetround & fegetround for arm
     new 3d0320f  libc/sched: Map the nice value more correctly
     new 9cc41f4  libc/sched: Implement nice API

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 include/limits.h                                 |  4 +--
 include/unistd.h                                 |  2 ++
 libs/libc/unistd/Make.defs                       | 15 ++++------
 libs/libc/unistd/lib_getpriority.c               |  6 +++-
 libs/libc/unistd/{lib_getrlimit.c => lib_nice.c} | 38 ++++++++++++++----------
 libs/libc/unistd/lib_setpriority.c               |  2 +-
 6 files changed, 37 insertions(+), 30 deletions(-)
 copy libs/libc/unistd/{lib_getrlimit.c => lib_nice.c} (73%)

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

Posted by ac...@apache.org.
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);
 }

[incubator-nuttx] 02/02: libc/sched: Implement nice API

Posted by ac...@apache.org.
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 9cc41f44f09146cce645c47738414f94797c6f99
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Jun 22 15:38:17 2021 +0800

    libc/sched: Implement nice API
    
    Specified here:
    https://pubs.opengroup.org/onlinepubs/007904875/functions/nice.html
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
    Change-Id: Ib25be28c8dc1c9288e8c78ad756c91ec6ef325a7
---
 include/unistd.h            |  2 ++
 libs/libc/unistd/Make.defs  | 15 ++++-------
 libs/libc/unistd/lib_nice.c | 63 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 10 deletions(-)

diff --git a/include/unistd.h b/include/unistd.h
index 62e505a..0f86f82 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -301,6 +301,8 @@ void    _exit(int status) noreturn_function;
 unsigned int sleep(unsigned int seconds);
 int     usleep(useconds_t usec);
 int     pause(void);
+int     nice(int inc);
+
 int     daemon(int nochdir, int noclose);
 
 /* File descriptor operations */
diff --git a/libs/libc/unistd/Make.defs b/libs/libc/unistd/Make.defs
index 822e853..3bf34d9 100644
--- a/libs/libc/unistd/Make.defs
+++ b/libs/libc/unistd/Make.defs
@@ -23,15 +23,12 @@
 CSRCS += lib_access.c lib_daemon.c lib_swab.c lib_pathconf.c lib_sysconf.c
 CSRCS += lib_getopt_common.c lib_getopt.c lib_getopt_long.c
 CSRCS += lib_getopt_longonly.c lib_getoptvars.c lib_getoptargp.c
-CSRCS += lib_getopterrp.c
-CSRCS += lib_getoptindp.c lib_getoptoptp.c
-CSRCS += lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c
+CSRCS += lib_getopterrp.c lib_getoptindp.c lib_getoptoptp.c
+CSRCS += lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c lib_nice.c
 CSRCS += lib_usleep.c lib_seteuid.c lib_setegid.c lib_geteuid.c lib_getegid.c
-CSRCS += lib_setreuid.c lib_setregid.c
-CSRCS += lib_getrusage.c lib_utimes.c
-CSRCS += lib_setrlimit.c lib_getrlimit.c
-CSRCS += lib_setpriority.c lib_getpriority.c
-CSRCS += lib_futimes.c lib_futimens.c
+CSRCS += lib_setreuid.c lib_setregid.c lib_getrusage.c lib_utimes.c
+CSRCS += lib_setrlimit.c lib_getrlimit.c lib_setpriority.c lib_getpriority.c
+CSRCS += lib_futimes.c lib_futimens.c lib_gethostname.c lib_sethostname.c
 
 ifneq ($(CONFIG_SCHED_USER_IDENTITY),y)
 CSRCS += lib_setuid.c lib_setgid.c lib_getuid.c lib_getgid.c
@@ -53,8 +50,6 @@ ifeq ($(CONFIG_PIPES),y)
 CSRCS += lib_pipe.c lib_pipe2.c
 endif
 
-CSRCS += lib_gethostname.c lib_sethostname.c
-
 # Add the unistd directory to the build
 
 DEPPATH += --dep-path unistd
diff --git a/libs/libc/unistd/lib_nice.c b/libs/libc/unistd/lib_nice.c
new file mode 100644
index 0000000..d3861e4
--- /dev/null
+++ b/libs/libc/unistd/lib_nice.c
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * libs/libc/unistd/lib_nice.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/resource.h>
+#include <unistd.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nice
+ *
+ * Description:
+ *  The nice() function shall add the value of incr to the nice value of the
+ *  calling process. A process' nice value is a non-negative number for which
+ *  a more positive value shall result in less favorable scheduling.
+ *
+ ****************************************************************************/
+
+int nice(int inc)
+{
+  int prio;
+  int ret;
+
+  set_errno(0);
+  ret = getpriority(PRIO_PROCESS, 0);
+  if (get_errno() != 0)
+    {
+      return ret;
+    }
+
+  prio = ret + inc;
+  ret = setpriority(PRIO_PROCESS, 0, prio);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  return prio;
+}