mirror of
https://github.com/apache/nuttx.git
synced 2026-05-09 23:12:17 +08:00
fs/inode: add optional manual FD backtrace control via task group flag
When CONFIG_FS_BACKTRACE is enabled, collecting a stack trace for every new file descriptor adds overhead to fast path operations like open(), dup(), and socket(). This patch adds a new configuration option CONFIG_FS_BACKTRACE_DEFAULT. When enabled (default behavior), the GROUP_FLAG_FD_BACKTRACE flag is automatically set during group allocation, causing backtrace to be captured for all tasks globally, preserving the original diagnostic capability. When disabled, backtrace capture is zero-cost by default and must be explicitly enabled per task group using GROUP_FLAG_FD_BACKTRACE. Signed-off-by: zhanxiaoqi <zhanxiaoqi@bytedance.com>
This commit is contained in:
committed by
Alin Jerpelea
parent
62b71c3b30
commit
786b315947
+15
-6
@@ -75,13 +75,22 @@
|
||||
# define FS_ADD_BACKTRACE(fd) \
|
||||
do \
|
||||
{ \
|
||||
int n = sched_backtrace(_SCHED_GETTID(), \
|
||||
(fd)->f_backtrace, \
|
||||
CONFIG_FS_BACKTRACE, \
|
||||
CONFIG_FS_BACKTRACE_SKIP); \
|
||||
if (n < CONFIG_FS_BACKTRACE) \
|
||||
FAR struct tcb_s *tcb = nxsched_get_tcb(nxsched_gettid()); \
|
||||
if (tcb != NULL && tcb->group != NULL && \
|
||||
(tcb->group->tg_flags & GROUP_FLAG_FD_BACKTRACE) != 0) \
|
||||
{ \
|
||||
(fd)->f_backtrace[n] = NULL; \
|
||||
int n = sched_backtrace(tcb->pid, \
|
||||
(fd)->f_backtrace, \
|
||||
CONFIG_FS_BACKTRACE, \
|
||||
CONFIG_FS_BACKTRACE_SKIP); \
|
||||
if (n < CONFIG_FS_BACKTRACE) \
|
||||
{ \
|
||||
(fd)->f_backtrace[n] = NULL; \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
(fd)->f_backtrace[0] = NULL; \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
@@ -99,3 +99,13 @@ config FS_BACKTRACE_SKIP
|
||||
depends on FS_BACKTRACE > 0
|
||||
---help---
|
||||
Skip depth of backtrace.
|
||||
|
||||
config FS_BACKTRACE_DEFAULT
|
||||
bool "Enable the backtrace record by default"
|
||||
default y
|
||||
depends on FS_BACKTRACE > 0
|
||||
---help---
|
||||
Enable automatic backtrace capture for all file descriptor operations
|
||||
globally. When disabled, backtrace capture is zero-cost by default
|
||||
and must be explicitly enabled per task group by setting the
|
||||
GROUP_FLAG_FD_BACKTRACE flag.
|
||||
|
||||
@@ -117,6 +117,7 @@
|
||||
#define GROUP_FLAG_PRIVILEGED (1 << 1) /* Bit 1: Group is privileged */
|
||||
#define GROUP_FLAG_DELETED (1 << 2) /* Bit 2: Group has been deleted but not yet freed */
|
||||
#define GROUP_FLAG_EXITING (1 << 3) /* Bit 3: Group exit is in progress */
|
||||
#define GROUP_FLAG_FD_BACKTRACE (1 << 4) /* Bit 4: Enable FD backtrace for the group */
|
||||
/* Bits 3-7: Available */
|
||||
|
||||
/* Values for struct child_status_s ch_flags */
|
||||
|
||||
@@ -163,6 +163,12 @@ int group_allocate(FAR struct tcb_s *tcb, uint8_t ttype)
|
||||
sq_init(&group->tg_members);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FS_BACKTRACE_DEFAULT
|
||||
/* Enable FD backtrace for the group by default */
|
||||
|
||||
group->tg_flags |= GROUP_FLAG_FD_BACKTRACE;
|
||||
#endif
|
||||
|
||||
/* Attach the group to the TCB */
|
||||
|
||||
tcb->group = group;
|
||||
|
||||
Reference in New Issue
Block a user