mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
sched/getpid: replace syscall getpid/tid/ppid() to kernel version
NuttX kernel should not use the syscall functions, especially after enabling CONFIG_SCHED_INSTRUMENTATION_SYSCALL, all system functions will be traced to backend, which will impact system performance. Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
@@ -102,7 +102,7 @@ static inline void mempool_add_backtrace(FAR struct mempool_s *pool,
|
||||
FAR struct mempool_backtrace_s *buf)
|
||||
{
|
||||
list_add_head(&pool->alist, &buf->node);
|
||||
buf->pid = gettid();
|
||||
buf->pid = _SCHED_GETTID();
|
||||
# if CONFIG_MM_BACKTRACE > 0
|
||||
if (pool->procfs.backtrace)
|
||||
{
|
||||
|
||||
+2
-2
@@ -75,7 +75,7 @@
|
||||
do \
|
||||
{ \
|
||||
FAR struct mm_allocnode_s *tmp = (FAR struct mm_allocnode_s *)(ptr); \
|
||||
tmp->pid = gettid(); \
|
||||
tmp->pid = _SCHED_GETTID(); \
|
||||
} \
|
||||
while (0)
|
||||
#elif CONFIG_MM_BACKTRACE > 0
|
||||
@@ -84,7 +84,7 @@
|
||||
{ \
|
||||
FAR struct mm_allocnode_s *tmp = (FAR struct mm_allocnode_s *)(ptr); \
|
||||
FAR struct tcb_s *tcb; \
|
||||
tmp->pid = gettid(); \
|
||||
tmp->pid = _SCHED_GETTID(); \
|
||||
tcb = nxsched_get_tcb(tmp->pid); \
|
||||
if ((heap)->mm_procfs.backtrace || (tcb && tcb->flags & TCB_FLAG_HEAP_DUMP)) \
|
||||
{ \
|
||||
|
||||
@@ -77,17 +77,17 @@ int mm_lock(FAR struct mm_heap_s *heap)
|
||||
else
|
||||
#endif
|
||||
|
||||
/* gettid() returns the task ID of the task at the head of the ready-to-
|
||||
* run task list. mm_lock() may be called during context
|
||||
/* _SCHED_GETTID() returns the task ID of the task at the head of the
|
||||
* ready-to-run task list. mm_lock() may be called during context
|
||||
* switches. There are certain situations during context switching when
|
||||
* the OS data structures are in flux and then can't be freed immediately
|
||||
* (e.g. the running thread stack).
|
||||
*
|
||||
* This is handled by gettid() to return the special value -ESRCH to
|
||||
* indicate this special situation.
|
||||
* This is handled by _SCHED_GETTID() to return the special value -ESRCH
|
||||
* to indicate this special situation.
|
||||
*/
|
||||
|
||||
if (gettid() < 0)
|
||||
if (_SCHED_GETTID() < 0)
|
||||
{
|
||||
return -ESRCH;
|
||||
}
|
||||
|
||||
+2
-1
@@ -33,6 +33,7 @@
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/sched.h>
|
||||
#include <nuttx/pgalloc.h>
|
||||
|
||||
#include "shm/shm.h"
|
||||
@@ -184,7 +185,7 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf)
|
||||
/* Save the process ID of the last operation */
|
||||
|
||||
region = &g_shminfo.si_region[shmid];
|
||||
region->sr_ds.shm_lpid = getpid();
|
||||
region->sr_ds.shm_lpid = _SCHED_GETPID();
|
||||
|
||||
/* Save the time of the last shmctl() */
|
||||
|
||||
|
||||
+2
-1
@@ -32,6 +32,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/pgalloc.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
#include "shm/shm.h"
|
||||
|
||||
@@ -268,7 +269,7 @@ static int shm_create(key_t key, size_t size, int shmflg)
|
||||
/* Save the process ID of the creator */
|
||||
|
||||
region = &g_shminfo.si_region[shmid];
|
||||
region->sr_ds.shm_cpid = getpid();
|
||||
region->sr_ds.shm_cpid = _SCHED_GETPID();
|
||||
|
||||
/* Return the shared memory ID */
|
||||
|
||||
|
||||
+6
-6
@@ -144,7 +144,7 @@ static void memdump_backtrace(FAR struct mm_heap_s *heap,
|
||||
FAR struct tcb_s *tcb;
|
||||
# endif
|
||||
|
||||
dump->pid = getpid();
|
||||
dump->pid = _SCHED_GETPID();
|
||||
# if CONFIG_MM_BACKTRACE > 0
|
||||
tcb = nxsched_get_tcb(dump->pid);
|
||||
if (heap->mm_procfs.backtrace ||
|
||||
@@ -319,17 +319,17 @@ static int mm_lock(FAR struct mm_heap_s *heap)
|
||||
else
|
||||
#endif
|
||||
|
||||
/* gettid() returns the task ID of the task at the head of the ready-to-
|
||||
* run task list. mm_lock() may be called during context
|
||||
/* _SCHED_GETTID() returns the task ID of the task at the head of the
|
||||
* ready-to-run task list. mm_lock() may be called during context
|
||||
* switches. There are certain situations during context switching when
|
||||
* the OS data structures are in flux and then can't be freed immediately
|
||||
* (e.g. the running thread stack).
|
||||
*
|
||||
* This is handled by gettid() to return the special value -ESRCH to
|
||||
* indicate this special situation.
|
||||
* This is handled by _SCHED_GETTID() to return the special value
|
||||
* -ESRCH to indicate this special situation.
|
||||
*/
|
||||
|
||||
if (gettid() < 0)
|
||||
if (_SCHED_GETTID() < 0)
|
||||
{
|
||||
return -ESRCH;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user