mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 02:36:11 +08:00
sched: move process ID from kernel to TLS for faster access
Add pid field to task_info_s and move getpid() implementation to user space TLS access. Remove getpid from syscall interface as it now returns cached PID from thread local storage instead of kernel lookup. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
@@ -149,6 +149,7 @@ struct task_info_s
|
||||
#ifdef CONFIG_PTHREAD_ATFORK
|
||||
struct list_node ta_atfork; /* Holds the pthread_atfork_s list */
|
||||
#endif
|
||||
pid_t ta_pid; /* Process ID */
|
||||
};
|
||||
|
||||
/* struct tls_cleanup_s *****************************************************/
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
SYSCALL_LOOKUP1(_exit, 1)
|
||||
SYSCALL_LOOKUP(_assert, 4)
|
||||
SYSCALL_LOOKUP(getpid, 0)
|
||||
SYSCALL_LOOKUP(prctl, 2)
|
||||
|
||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
||||
|
||||
@@ -28,7 +28,8 @@ set(SRCS
|
||||
task_setcancelstate.c
|
||||
task_setcanceltype.c
|
||||
task_testcancel.c
|
||||
task_gettid.c)
|
||||
task_gettid.c
|
||||
task_getpid.c)
|
||||
|
||||
if(CONFIG_SMP)
|
||||
list(APPEND SRCS sched_cpucount.c)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
CSRCS += sched_getprioritymax.c sched_getprioritymin.c
|
||||
CSRCS += task_cancelpt.c task_setcancelstate.c task_setcanceltype.c
|
||||
CSRCS += task_testcancel.c task_gettid.c
|
||||
CSRCS += task_testcancel.c task_gettid.c task_getpid.c
|
||||
CSRCS += clock_getcpuclockid.c
|
||||
|
||||
ifeq ($(CONFIG_SMP),y)
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/****************************************************************************
|
||||
* libs/libc/sched/task_getpid.c
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <nuttx/tls.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: getpid
|
||||
*
|
||||
* Description:
|
||||
* Get the process ID of the currently executing thread.
|
||||
*
|
||||
* Input parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns the thread ID of the calling process.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
pid_t getpid(void)
|
||||
{
|
||||
FAR struct task_info_s *info = task_get_info();
|
||||
|
||||
DEBUGASSERT(info != NULL);
|
||||
return info->ta_pid;
|
||||
}
|
||||
@@ -254,4 +254,6 @@ void group_initialize(FAR struct tcb_s *tcb)
|
||||
{
|
||||
group->tg_pid = tcb->pid;
|
||||
}
|
||||
|
||||
group->tg_info->ta_pid = group->tg_pid;
|
||||
}
|
||||
|
||||
@@ -80,25 +80,3 @@ pid_t nxsched_getpid(void)
|
||||
|
||||
return IDLE_PROCESS_ID;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: getpid
|
||||
*
|
||||
* Description:
|
||||
* Get the Process ID of the currently executing task.
|
||||
*
|
||||
* Input parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Normally when called from user applications, getpid() will return the
|
||||
* Process ID of the currently executing task. that is, the main task
|
||||
* for the task groups. There is no specification for any errors
|
||||
* returned from getpid().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
pid_t getpid(void)
|
||||
{
|
||||
return nxsched_getpid();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
"gethostname","unistd.h","","int","FAR char *","size_t"
|
||||
"getitimer","sys/time.h","!defined(CONFIG_DISABLE_POSIX_TIMERS)","int","int","FAR struct itimerval *"
|
||||
"getpeername","sys/socket.h","defined(CONFIG_NET)","int","int","FAR struct sockaddr *","FAR socklen_t *"
|
||||
"getpid","unistd.h","","pid_t"
|
||||
"getppid","unistd.h","defined(CONFIG_SCHED_HAVE_PARENT)","pid_t"
|
||||
"getsockname","sys/socket.h","defined(CONFIG_NET)","int","int","FAR struct sockaddr *","FAR socklen_t *"
|
||||
"getsockopt","sys/socket.h","defined(CONFIG_NET)","int","int","int","int","FAR void *","FAR socklen_t *"
|
||||
|
||||
|
Reference in New Issue
Block a user