fs/inode: add pre-allocated task files to avoid allocator access

Pre-allocated files to avoid allocator access during thread creation
phase, For functional safety requirements, increase
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK could also avoid allocator access
caused by the file descriptor exceeding the limit.

For Task Termination, the time consumption will be reduced ~3us (Tricore TC397 300MHZ):
10.65(us) -> 7.35(us)

NOTE:
This commit will not waste of extra heap, just pre-allocates the list of files for task_group.

Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
chao an
2024-03-06 15:03:13 +08:00
committed by Xiang Xiao
parent 236ec9844f
commit d29748258b
2 changed files with 25 additions and 4 deletions
+16 -4
View File
@@ -154,7 +154,7 @@ static int files_extend(FAR struct filelist *list, size_t row)
spin_unlock_irqrestore(&list->fl_lock, flags); spin_unlock_irqrestore(&list->fl_lock, flags);
if (tmp != NULL) if (tmp != NULL && tmp != &list->fl_prefile)
{ {
kmm_free(tmp); kmm_free(tmp);
} }
@@ -298,7 +298,13 @@ static int nx_dup3_from_tcb(FAR struct tcb_s *tcb, int fd1, int fd2,
void files_initlist(FAR struct filelist *list) void files_initlist(FAR struct filelist *list)
{ {
DEBUGASSERT(list); /* The first row will reuse pre-allocated files, which will avoid
* unnecessary allocator accesses during file initialization.
*/
list->fl_rows = 1;
list->fl_files = &list->fl_prefile;
list->fl_prefile = list->fl_prefiles;
} }
/**************************************************************************** /****************************************************************************
@@ -328,10 +334,16 @@ void files_releaselist(FAR struct filelist *list)
file_close(&list->fl_files[i][j]); file_close(&list->fl_files[i][j]);
} }
kmm_free(list->fl_files[i]); if (i != 0)
{
kmm_free(list->fl_files[i]);
}
} }
kmm_free(list->fl_files); if (list->fl_files != &list->fl_prefile)
{
kmm_free(list->fl_files);
}
} }
/**************************************************************************** /****************************************************************************
+9
View File
@@ -488,6 +488,15 @@ struct filelist
spinlock_t fl_lock; /* Manage access to the file list */ spinlock_t fl_lock; /* Manage access to the file list */
uint8_t fl_rows; /* The number of rows of fl_files array */ uint8_t fl_rows; /* The number of rows of fl_files array */
FAR struct file **fl_files; /* The pointer of two layer file descriptors array */ FAR struct file **fl_files; /* The pointer of two layer file descriptors array */
/* Pre-allocated files to avoid allocator access during thread creation
* phase, For functional safety requirements, increase
* CONFIG_NFILE_DESCRIPTORS_PER_BLOCK could also avoid allocator access
* caused by the file descriptor exceeding the limit.
*/
FAR struct file *fl_prefile;
FAR struct file fl_prefiles[CONFIG_NFILE_DESCRIPTORS_PER_BLOCK];
}; };
/* The following structure defines the list of files used for standard C I/O. /* The following structure defines the list of files used for standard C I/O.