You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/01/31 19:15:12 UTC

[incubator-nuttx] 01/02: sched/sched/sched_getcpu.c: Implement non-standard interface.

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

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

commit 989770470c82f84896c6fcccc368105451015b7a
Author: Gregory Nutt <gn...@nuttx.org>
AuthorDate: Fri Jan 31 12:22:38 2020 -0600

    sched/sched/sched_getcpu.c:  Implement non-standard interface.
    
    If SMP is enabled this function will return the number of the CPU that the thread is running on.  This is non-standard but follows GLIBC if __GNU_SOURCE is enabled.  The returned CPU number is, however, worthless since it returns the CPU number of the CPU that was executing the task when the function was called.  The application can never know the true CPU number of the CPU tht it is running on since that value is volatile and change change at any time.
---
 boards/arm/stm32l4/nucleo-l432kc/configs/spwm/defconfig |  2 +-
 include/sched.h                                         |  6 ++++--
 include/sys/syscall.h                                   | 14 +++++++++++---
 sched/sched/Make.defs                                   |  4 ++--
 syscall/syscall.csv                                     |  1 +
 syscall/syscall_lookup.h                                |  7 ++++++-
 syscall/syscall_stublookup.c                            |  9 ++++-----
 7 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/boards/arm/stm32l4/nucleo-l432kc/configs/spwm/defconfig b/boards/arm/stm32l4/nucleo-l432kc/configs/spwm/defconfig
index 9f3ca61..a1cc70c 100755
--- a/boards/arm/stm32l4/nucleo-l432kc/configs/spwm/defconfig
+++ b/boards/arm/stm32l4/nucleo-l432kc/configs/spwm/defconfig
@@ -1207,7 +1207,7 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024
 # CONFIG_EXAMPLES_MAX31855 is not set
 # CONFIG_EXAMPLES_MEDIA is not set
 # CONFIG_EXAMPLES_MLX90614 is not set
-# CONFIG_EXAMPLES_MM is not set
+# CONFIG_TESTING_MM is not set
 # CONFIG_EXAMPLES_MODBUS is not set
 # CONFIG_EXAMPLES_MODBUSMASTER is not set
 # CONFIG_EXAMPLES_MOUNT is not set
diff --git a/include/sched.h b/include/sched.h
index 8309c94..06dc6db 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -1,8 +1,8 @@
 /********************************************************************************
  * include/sched.h
  *
- *   Copyright (C) 2007-2009, 2011, 2013, 2015-2016 Gregory Nutt. All rights
- *     reserved.
+ *   Copyright (C) 2007-2009, 2011, 2013, 2015-2016, 2020 Gregory Nutt. All
+ *     rights reserved.
  *   Author: Gregory Nutt <gn...@nuttx.org>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,7 @@
 #include <sys/types.h>
 #include <stdint.h>
 #include <stdbool.h>
+
 #include <nuttx/sched.h>
 
 /********************************************************************************
@@ -265,6 +266,7 @@ int    sched_setaffinity(pid_t pid, size_t cpusetsize,
                          FAR const cpu_set_t *mask);
 int    sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask);
 int    sched_cpu_count(FAR const cpu_set_t *set);
+int    sched_getcpu(void);
 #endif /* CONFIG_SMP */
 
 /* Task Switching Interfaces (non-standard) */
diff --git a/include/sys/syscall.h b/include/sys/syscall.h
index 8518c55..ec5cbf5 100644
--- a/include/sys/syscall.h
+++ b/include/sys/syscall.h
@@ -71,6 +71,7 @@
 #define SYS_exit                       (CONFIG_SYS_RESERVED + 1)
 #define SYS_get_errno                  (CONFIG_SYS_RESERVED + 2)
 #define SYS_getpid                     (CONFIG_SYS_RESERVED + 3)
+
 #define SYS_sched_getparam             (CONFIG_SYS_RESERVED + 4)
 #define SYS_sched_getscheduler         (CONFIG_SYS_RESERVED + 5)
 #define SYS_sched_lock                 (CONFIG_SYS_RESERVED + 6)
@@ -80,9 +81,16 @@
 #define SYS_sched_setscheduler         (CONFIG_SYS_RESERVED + 10)
 #define SYS_sched_unlock               (CONFIG_SYS_RESERVED + 11)
 #define SYS_sched_yield                (CONFIG_SYS_RESERVED + 12)
-#define SYS_set_errno                  (CONFIG_SYS_RESERVED + 13)
-#define SYS_uname                      (CONFIG_SYS_RESERVED + 14)
-#define __SYS_uid                      (CONFIG_SYS_RESERVED + 15)
+#ifdef CONFIG_SMP
+#  define SYS_sched_getcpu             (CONFIG_SYS_RESERVED + 13)
+#  define __SYS_set_errno              (CONFIG_SYS_RESERVED + 14)
+#else
+#  define __SYS_set_errno              (CONFIG_SYS_RESERVED + 13)
+#endif
+
+#define SYS_set_errno                  (__SYS_set_errno + 0)
+#define SYS_uname                      (__SYS_set_errno + 1)
+#define __SYS_uid                      (__SYS_set_errno + 2)
 
 /* User identity */
 
diff --git a/sched/sched/Make.defs b/sched/sched/Make.defs
index 91e239d..11f4c94 100644
--- a/sched/sched/Make.defs
+++ b/sched/sched/Make.defs
@@ -1,7 +1,7 @@
 ############################################################################
 # sched/sched/Make.defs
 #
-#   Copyright (C) 2014, 2018 Gregory Nutt. All rights reserved.
+#   Copyright (C) 2014, 2018, 2020 Gregory Nutt. All rights reserved.
 #   Author: Gregory Nutt <gn...@nuttx.org>
 #
 # Redistribution and use in source and binary forms, with or without
@@ -50,7 +50,7 @@ CSRCS += sched_reprioritize.c
 endif
 
 ifeq ($(CONFIG_SMP),y)
-CSRCS += sched_cpuselect.c sched_cpupause.c
+CSRCS += sched_cpuselect.c sched_cpupause.c sched_getcpu.c
 CSRCS += sched_getaffinity.c sched_setaffinity.c
 endif
 
diff --git a/syscall/syscall.csv b/syscall/syscall.csv
index 80bde70..2f2c9e0 100644
--- a/syscall/syscall.csv
+++ b/syscall/syscall.csv
@@ -119,6 +119,7 @@
 "rewinddir","dirent.h","","void","FAR DIR*"
 "rmdir","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*"
 "rmmod","nuttx/module.h","defined(CONFIG_MODULE)","int","FAR void *"
+"sched_getcpu","sched.h","defined(CONFIG_SMP)","int"
 "sched_getparam","sched.h","","int","pid_t","struct sched_param*"
 "sched_getscheduler","sched.h","","int","pid_t"
 "sched_getstreams","nuttx/sched.h","CONFIG_NFILE_STREAMS > 0","FAR struct streamlist*"
diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h
index df2f6df..00f7fb0 100644
--- a/syscall/syscall_lookup.h
+++ b/syscall/syscall_lookup.h
@@ -1,7 +1,7 @@
 /****************************************************************************
  * syscall/syscall_lookup.h
  *
- *   Copyright (C) 2011, 2013-2019 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2011, 2013-2019, 2020 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <gn...@nuttx.org>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,7 @@ SYSCALL_LOOKUP1(_exit,                     1, STUB__exit)
 SYSCALL_LOOKUP(exit,                       1, STUB_exit)
 SYSCALL_LOOKUP(get_errno,                  0, STUB_get_errno)
 SYSCALL_LOOKUP(getpid,                     0, STUB_getpid)
+
 SYSCALL_LOOKUP(sched_getparam,             2, STUB_sched_getparam)
 SYSCALL_LOOKUP(sched_getscheduler,         1, STUB_sched_getscheduler)
 SYSCALL_LOOKUP(sched_lock,                 0, STUB_sched_lock)
@@ -56,6 +57,10 @@ SYSCALL_LOOKUP(sched_setparam,             2, STUB_sched_setparam)
 SYSCALL_LOOKUP(sched_setscheduler,         3, STUB_sched_setscheduler)
 SYSCALL_LOOKUP(sched_unlock,               0, STUB_sched_unlock)
 SYSCALL_LOOKUP(sched_yield,                0, STUB_sched_yield)
+#ifdef CONFIG_SMP
+SYSCALL_LOOKUP(sched_getcpu,               0, STUB_sched_getcpu)
+#endif
+
 SYSCALL_LOOKUP(set_errno,                  1, STUB_set_errno)
 SYSCALL_LOOKUP(uname,                      1, STUB_uname)
 
diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c
index f9b2fb1..11276e7 100644
--- a/syscall/syscall_stublookup.c
+++ b/syscall/syscall_stublookup.c
@@ -1,7 +1,7 @@
 /****************************************************************************
  * syscall/syscall_stublookup.c
  *
- *   Copyright (C) 2011-2013, 2015-2019 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2011-2013, 2015-2020 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <gn...@nuttx.org>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -49,10 +49,6 @@
 #if defined(CONFIG_LIB_SYSCALL)
 
 /****************************************************************************
- * Pre-processor definitions
- ****************************************************************************/
-
-/****************************************************************************
  * Stub Function Prototypes
  ****************************************************************************/
 
@@ -64,6 +60,7 @@ uintptr_t STUB__exit(int nbr, uintptr_t parm1);
 uintptr_t STUB_exit(int nbr, uintptr_t parm1);
 uintptr_t STUB_get_errno(int nbr);
 uintptr_t STUB_getpid(int nbr);
+
 uintptr_t STUB_sched_getparam(int nbr, uintptr_t parm1, uintptr_t parm2);
 uintptr_t STUB_sched_getscheduler(int nbr, uintptr_t parm1);
 uintptr_t STUB_sched_lock(int nbr);
@@ -75,6 +72,8 @@ uintptr_t STUB_sched_setscheduler(int nbr, uintptr_t parm1, uintptr_t parm2,
             uintptr_t parm3);
 uintptr_t STUB_sched_unlock(int nbr);
 uintptr_t STUB_sched_yield(int nbr);
+uintptr_t STUB_sched_getcpu(int nbr);
+
 uintptr_t STUB_set_errno(int nbr, uintptr_t parm1);
 uintptr_t STUB_uname(int nbr, uintptr_t parm1);