Hi Chengdong,

> I submitted a PR (#18437) to address the CLOCK_BOOTTIME and CLOCK_MONOTONIC
> time source issue. Could you please take a look when you have a chance?

That's okay, you fixed a change that was made by commit 1c643b5cc on 30dec25. 


> So my suggestion is not to use CLOCK_MONOTONIC  for nxsem_clockwait. if you
> do not want the behavior you mentioned.

That's not a solution. If nxsem_clockwait is only working as expected for 
CLOCK_REALTIME and CLOCK_BOOTTIME, it should al least return an error for other 
values.


In my opinion, the main problem is that CLOCK_MONOTONIC's behaviour has been 
changed. This means that all uses of CLOCK_MONOTONIC must be checked and 
possibly changed. In nuttx, in the nuttx apps and in the all applications of 
all nuttx users!
Am I the only one who had problems with that?


BR,
Mathias






chengdong wang schrieb am 25.02.2026 03:46 (GMT +01:00):

> Hi Mathias,
> 
> I submitted a PR (#18437) to address the CLOCK_BOOTTIME and CLOCK_MONOTONIC
> time source issue. Could you please take a look when you have a chance?
> 
> Regarding the error you mentioned, I think it should be expected behavior,
> because CLOCK_MONOTONIC excludes the time the system is suspended while the
> wdog for sem timeout using the time that includes the suspended period.
> 
> So my suggestion is not to use CLOCK_MONOTONIC  for nxsem_clockwait. if you
> do not want the behavior you mentioned.
> 
> Best regards,
> Chengdong
> 
> <[email protected]> 于2026年2月20日周五 16:37写道:
> 
>>
>> Hi ChengDong,
>>
>>
>> were you able to check my error message?
>> How can we solve the problem?
>>
>> BR,
>>
>> Mathias
>>
>>
>>
>>
>> chengdong wang schrieb am 06.02.2026 02:28 (GMT +01:00):
>>
>> > OK, I will take a look at this as soon as possible
>> >
>> > BR,
>> > ChengDong
>> >
>> > Alan C. Assis <[email protected]> 于2026年2月6日周五 00:50写道:
>> >
>> >> Hi Mathias,
>> >>
>> >> Thank you for finding and reporting this issue. I'm CC Chengdong here.
>> >>
>> >> Chengdong, could you please take a look at this issue?
>> >>
>> >> BR,
>> >>
>> >> Alan
>> >>
>> >> On Thu, Feb 5, 2026 at 12:32 PM <[email protected]> wrote:
>> >>
>> >> >
>> >> > Hello,
>> >> >
>> >> > I have problems with the following commit, which is part of PR #17199
>> >> >
>> >> >    commit c7b6442974545b92476615ef048633609d828e5b
>> >> >    Author: wangchengdong <[email protected]>
>> >> >    Date: Mon Oct 13 20:57:43 2025 +0800
>> >> >    sched/clock: Improve CLOCK_MONOTONIC nxclock_gettime()
>> >> >
>> >> >    Improve nxclock_gettime(), to get the system time excluding
>> >> >    the time that the system is suspended, when the clockid is
>> >> >    CLOCK_MONOTONIC
>> >> >
>> >> >    Signed-off-by: Chengdong Wang [email protected]
>> >> >
>> >> >
>> >> >
>> >> > This commit changes the behaviour of CLOCK_MONOTONIC. It is running
>> >> slower
>> >> > than CLOCK_BOOTTIME now.
>> >> >
>> >> > I called sem_clockwait() with CLOCK_MONOTONIC, but the "if" in line
>> 143
>> >> in
>> >> > nuttx/sched/semaphore/sem_clockwait.c handles on two cases. I used
>> >> > CLOCK_MONOTONIC to calculate the value "abstime", but
>> wd_start_abstime()
>> >> > uses CLOCK_BOOTTIME now. When the system in running for some time this
>> >> > leads to an immediate timeout, because two different clocks are
>> compared.
>> >> >
>> >> >
>> >> > int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
>> >> >                     FAR const struct timespec *abstime)
>> >> > {
>> >> > ...
>> >> >     if (clockid == CLOCK_REALTIME)
>> >> >       {
>> >> >         wd_start_realtime(&rtcb->waitdog, abstime,
>> >> >                           nxsem_timeout, (uintptr_t)rtcb);
>> >> >       }
>> >> >     else
>> >> >       {
>> >> >         wd_start_abstime(&rtcb->waitdog, abstime,
>> >> >                          nxsem_timeout, (uintptr_t)rtcb);
>> >> >       }
>> >> > ...
>> >> >
>> >> >
>> >> >
>> >> > For my understanding the change of CLOCK_MONOTONIC is not correct.
>> >> > According to the POSIX definition
>> >> > https://pubs.opengroup.org/onlinepubs/9799919799/ it must be a
>> >> > "system-wide monotonic clock", CLOCK_BOOTTIME is not defined here.
>> >> >
>> >> >
>> >> > On the other hand, if such a low level change is made, all usages
>> should
>> >> > be reviewed. There a lot of places where CLOCK_MONOTONIC is used in
>> the
>> >> > nuttx source code. And there are places like in nxsem_clockwait()
>> where
>> >> the
>> >> > change leads to an error even though CLOCK_MONOTONIC is not used in
>> the
>> >> > code.
>> >> >
>> >> >
>> >> > What do you think?
>> >> >
>> >> > BR,
>> >> > Mathias
>> >> >
>> >>
>> >
>>
> 

Reply via email to