You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2026/01/20 14:33:53 UTC
(nuttx) branch master updated (c95b6b1bb6f -> 8bb67584906)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
from c95b6b1bb6f libxx: fix __config_site for libcxx compile errors
new 0f7c992cea4 sched/task: fix gettid by moving tls_dup_info after child pid initialization
new 8bb67584906 sched: move process ID from kernel to TLS for faster access
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/nuttx/tls.h | 1 +
include/sys/syscall_lookup.h | 1 -
libs/libc/sched/CMakeLists.txt | 3 ++-
libs/libc/sched/Make.defs | 2 +-
libs/libc/sched/{task_gettid.c => task_getpid.c} | 14 ++++++++------
sched/group/group_create.c | 2 ++
sched/task/task_fork.c | 16 ++++++++--------
sched/task/task_getpid.c | 22 ----------------------
syscall/syscall.csv | 1 -
9 files changed, 22 insertions(+), 40 deletions(-)
copy libs/libc/sched/{task_gettid.c => task_getpid.c} (88%)
(nuttx) 01/02: sched/task: fix gettid by moving tls_dup_info after child pid initialization
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 0f7c992cea40e63cd8475d73b3d85a228bcfbc82
Author: hujun5 <hu...@xiaomi.com>
AuthorDate: Fri Jun 6 18:32:01 2025 +0800
sched/task: fix gettid by moving tls_dup_info after child pid initialization
Move tls_dup_info() call to after child process priority is set, ensuring
the child's pid is properly initialized before duplicating TLS information.
This fixes incorrect thread ID assignment during task fork operations.
Signed-off-by: hujun5 <hu...@xiaomi.com>
---
sched/task/task_fork.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/sched/task/task_fork.c b/sched/task/task_fork.c
index 964c55b0395..359db312f48 100644
--- a/sched/task/task_fork.c
+++ b/sched/task/task_fork.c
@@ -221,14 +221,6 @@ FAR struct tcb_s *nxtask_setup_fork(start_t retaddr)
}
#endif
- /* Setup thread local storage */
-
- ret = tls_dup_info(child, parent);
- if (ret < OK)
- {
- goto errout_with_tcb;
- }
-
/* Get the priority of the parent task */
#ifdef CONFIG_PRIORITY_INHERITANCE
@@ -247,6 +239,14 @@ FAR struct tcb_s *nxtask_setup_fork(start_t retaddr)
goto errout_with_tcb;
}
+ /* Setup thread local storage */
+
+ ret = tls_dup_info(child, parent);
+ if (ret < OK)
+ {
+ goto errout_with_tcb;
+ }
+
/* Setup to pass parameters to the new task */
ret = nxtask_setup_stackargs(child, argv[0], &argv[1]);
(nuttx) 02/02: sched: move process ID from kernel to TLS for faster access
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 8bb675849061c4bda7294b075e6f982e81436b19
Author: hujun5 <hu...@xiaomi.com>
AuthorDate: Thu Jun 5 21:11:42 2025 +0800
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 <hu...@xiaomi.com>
---
include/nuttx/tls.h | 1 +
include/sys/syscall_lookup.h | 1 -
libs/libc/sched/CMakeLists.txt | 3 ++-
libs/libc/sched/Make.defs | 2 +-
libs/libc/sched/task_getpid.c | 58 ++++++++++++++++++++++++++++++++++++++++++
sched/group/group_create.c | 2 ++
sched/task/task_getpid.c | 22 ----------------
syscall/syscall.csv | 1 -
8 files changed, 64 insertions(+), 26 deletions(-)
diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h
index 4159035d000..f971afe96f6 100644
--- a/include/nuttx/tls.h
+++ b/include/nuttx/tls.h
@@ -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 *****************************************************/
diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h
index 39ef26c16c4..60fd08dced1 100644
--- a/include/sys/syscall_lookup.h
+++ b/include/sys/syscall_lookup.h
@@ -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
diff --git a/libs/libc/sched/CMakeLists.txt b/libs/libc/sched/CMakeLists.txt
index 8297eebce77..70f76c1e014 100644
--- a/libs/libc/sched/CMakeLists.txt
+++ b/libs/libc/sched/CMakeLists.txt
@@ -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)
diff --git a/libs/libc/sched/Make.defs b/libs/libc/sched/Make.defs
index 23aa8c0b2d5..24793634708 100644
--- a/libs/libc/sched/Make.defs
+++ b/libs/libc/sched/Make.defs
@@ -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)
diff --git a/libs/libc/sched/task_getpid.c b/libs/libc/sched/task_getpid.c
new file mode 100644
index 00000000000..bda6fcf6239
--- /dev/null
+++ b/libs/libc/sched/task_getpid.c
@@ -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;
+}
diff --git a/sched/group/group_create.c b/sched/group/group_create.c
index 336a7a64f1a..122a25d06d6 100644
--- a/sched/group/group_create.c
+++ b/sched/group/group_create.c
@@ -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;
}
diff --git a/sched/task/task_getpid.c b/sched/task/task_getpid.c
index 76c63e9fcbe..0cf46d8ac21 100644
--- a/sched/task/task_getpid.c
+++ b/sched/task/task_getpid.c
@@ -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();
-}
diff --git a/syscall/syscall.csv b/syscall/syscall.csv
index 531154b0c50..4cf841bc3a4 100644
--- a/syscall/syscall.csv
+++ b/syscall/syscall.csv
@@ -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 *"