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 dba77ff043508cf97b877e1379c971c11d8859d5
Author: chenrun1 <[email protected]>
AuthorDate: Thu Jul 11 17:38:22 2024 +0800

    fslock:Optimize the performance overhead caused by frequent close
    
    Summary:
      Indicate whether the file is currently locked by adding a new field 
locked to filep.
        0 - Unlocked
        1 - Locked
      The status of the filep at close is used to determine whether to continue 
with the following procedure.
    
      Optimizing performance:
    Before
      Time taken to close the file: 33984 nsec
    After
      Time taken to close the file: 23744 nsec
    Improvement of about 10 msec
    
    Signed-off-by: chenrun1 <[email protected]>
---
 fs/vfs/fs_lock.c      | 11 +++++++++++
 include/nuttx/fs/fs.h |  4 ++++
 2 files changed, 15 insertions(+)

diff --git a/fs/vfs/fs_lock.c b/fs/vfs/fs_lock.c
index bfb430577b..1c4bb006f9 100644
--- a/fs/vfs/fs_lock.c
+++ b/fs/vfs/fs_lock.c
@@ -30,6 +30,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
+#include <nuttx/fs/fs.h>
 #include <nuttx/lib/lib.h>
 #include <nuttx/kmalloc.h>
 #include <nuttx/mutex.h>
@@ -715,6 +716,10 @@ retry:
       goto out;
     }
 
+  /* Update filep lock state */
+
+  filep->locked = true;
+
   /* When there is a lock change, we need to wake up the blocking lock */
 
   if (bucket->nwaiter > 0)
@@ -751,6 +756,11 @@ void file_closelk(FAR struct file *filep)
   bool deleted = false;
   int ret;
 
+  if (filep->locked == false)
+    {
+      return;
+    }
+
   path = lib_get_pathbuffer();
   if (path == NULL)
     {
@@ -784,6 +794,7 @@ void file_closelk(FAR struct file *filep)
         {
           deleted = true;
           file_lock_delete(file_lock);
+          filep->locked = false;
         }
     }
 
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index 939a8dd546..04f8c07558 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -480,6 +480,10 @@ struct file
 #if CONFIG_FS_BACKTRACE > 0
   FAR void         *f_backtrace[CONFIG_FS_BACKTRACE]; /* Backtrace to while 
file opens */
 #endif
+
+#if CONFIG_FS_LOCK_BUCKET_SIZE > 0
+  bool              locked; /* Filelock state: false - unlocked, true - locked 
*/
+#endif
 };
 
 /* This defines a two layer array of files indexed by the file descriptor.

Reply via email to