raiden00pl commented on issue #6012: URL: https://github.com/apache/nuttx/issues/6012#issuecomment-1792748162
I came back to this problem. Why not just add critical section like suggested before (only in this specific place): ``` C flags = enter_critical_section(); // <<<<<<---------------- must be here /* The descriptor is in a valid range to file descriptor... Get the * thread-specific file list. */ /* And return the file pointer from the list */ ret = nxmutex_lock(&list->fl_lock); if (ret < 0) { leave_critical_section(flags); // <<<<<<<<<<<-------- here return ret; } *filep = &list->fl_files[fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK] [fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK]; /* if f_inode is NULL, fd was closed */ if (!(*filep)->f_inode) { *filep = NULL; ret = -EBADF; } nxmutex_unlock(&list->fl_lock); leave_critical_section(flags); // <<<<<<<<<<<-------- here ``` If the root of the problem is a potential interrupt occurring exactly between `nxmutex_lock()` and `nxmutex_unlock()`, then the easiest fix is to disable the interrupts at this point (must be before `nxmutex_lock()`). With above change the maximum execution time of my control loop drops from 8864 cycles to 4615 cycles which looks like it solves the problem. For SMP we probably should use `spin_lock_irqxxx()` here. rwlock would be ideal, but implementing an effective rwlock is not an easy task and rwlock spinlock that is already upstream will lead to deadlocks on not SMP targets. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org