jlaitine opened a new issue, #8346:
URL: https://github.com/apache/nuttx/issues/8346

   It seems that several timeout functions have broken recently due to this 
commit:
   
   commit 1fb8c13e5e80ee4cd5758e76821378162451c2fa
   Author: Xiang Xiao <xiaoxi...@xiaomi.com>
   Date:   Tue May 10 09:32:31 2022 +0800
   
       Replace nxsem_timedwait_uninterruptible with 
nxsem_tickwait_uninterruptible
       
       Signed-off-by: Xiang Xiao <xiaoxi...@xiaomi.com>
   
   For example: in net/utils/net_lock.c the change looks like this:
   
   ```
   --- a/net/utils/net_lock.c
   +++ b/net/utils/net_lock.c
   @@ -97,27 +97,15 @@ _net_timedwait(sem_t *sem, bool interruptible, unsigned 
int timeout)
    
      if (timeout != UINT_MAX)
        {
   -      struct timespec abstime;
   -
   -      DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime));
   -
   -      abstime.tv_sec  += timeout / MSEC_PER_SEC;
   -      abstime.tv_nsec += timeout % MSEC_PER_SEC * NSEC_PER_MSEC;
   -      if (abstime.tv_nsec >= NSEC_PER_SEC)
   -        {
   -          abstime.tv_sec++;
   -          abstime.tv_nsec -= NSEC_PER_SEC;
   -        }
   -
          /* Wait until we get the lock or until the timeout expires */
    
          if (interruptible)
            {
   -          ret = nxsem_timedwait(sem, &abstime);
   +          ret = nxsem_tickwait(sem, MSEC2TICK(timeout));
            }
          else
            {
   -          ret = nxsem_timedwait_uninterruptible(sem, &abstime);
   +          ret = nxsem_tickwait_uninterruptible(sem, MSEC2TICK(timeout));
            }
        }
   ```
   
   In the original code, the _net_timedwait alwas went to sleep if the timeout 
is > 0. In the changed code, if MSEC2TICK(timeout) rounds to 0, the 
nxsem_tickwait doesn't sleep at all.
   
   I noticed this problem when i2c driver broke for stm32f7 board, and fixed 
only this in PR #8303 . However, we are also experiencing some networking 
problems, which may be due to the code above
   
   
   There are several alternatives to fix this problem:
   
   1) 
   
   In all of the places be changed into rounding up the MSEC2TICK / USEC2TICK 
return value, for example "MSEC2TICK(timeout + (MSEC_PER_TICK / 2)  - 1).
   
   Pros:
   - Doesn't break anything unknown
   
   Cons:
   - The rounding creeps in to almost everywhere where the macros are used
   
   2) 
   
   We could change the functionality of MSEC2TIC/USEC2TICK to round up by 
default (actually some OS's do this, see e..g linux jiffy calculation).
   
   Pros:
   - Cleanest code, fixes all the places at once
   
   Cons:
   - May affect off-tree/private code of nuttx users
   - The functionality of current MSEC2TIC/USEC2TICK has been as it is since 
90's
   
   3)
   
   We could revert the change
   
   Pros:
   
   -Fixes the original problem
   
   Cons:
   
   - The original change greatly simplifies the code
   - Would probably lead to rebase problems
   
   
   
   
   
   
   
   
   
   
   
   
   


-- 
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.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to