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.
This commit is contained in:
Gregory Nutt
2020-01-31 20:25:15 +00:00
committed by Ouss4
parent 80277d1630
commit 2def8035db
7 changed files with 108 additions and 13 deletions
+4 -2
View File
@@ -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 <gnutt@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) */
+11 -3
View File
@@ -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 */