#4690 closed defect (fixed)

CLOCK_REALTIME thread queue not updated as part of clock_settime call

Reported by: Chris Johns Owned by: Chris Johns <chrisj@…>
Priority: normal Milestone: 6.1
Component: score Version: 6
Severity: normal Keywords: qualification
Cc: Blocked By:
Blocking:

Description

Setting the CLOCK_REALTIME clock using clock_settime(CLOCK_REALTIME, , ) clock does not update thread relative period entries on the watchdog timer queue.

A system's stability is effected if a user calls clock_settime on the CLOCK_REALTIME clock. The watchdog's REALTIME clock queue is references against the realtime clock and movement of the time means

The effected parts are:

  1. User C code that calls nanosleep, usleep, sleep or clock_nanosleep(CLOCK_REALTIME, , ).
  2. User C++ code that uses std::this_thread::sleep_for() as GCC uses the nanosleep() call.
  3. LibBSD uses CLOCK_REALTIME.

The nanosleep call is explained in more detail in the clock_nanosleep rational. The nanosleep clock must be CLOCK_REALTIME. The clock_settime standard says:

Setting the value of the CLOCK_REALTIME clock via clock_settime() shall have no effect on threads that are blocked waiting for a relative time service based upon this clock, including the nanosleep() function; nor on the expiration of relative timers based upon this clock. Consequently, these time services shall expire when the requested relative interval elapses, independently of the new or old value of the clock.

Attachments (1)

init.c (14.4 KB) - added by Chris Johns on 08/01/22 at 08:07:48.
testsuites/psxtests/psxclock/init.c

Download all attachments as: .zip

Change History (9)

comment:1 Changed on 08/01/22 at 04:23:04 by Chris Johns

Summary: CLOCK_REALTIME thread queue no updated as part of clock_settime callCLOCK_REALTIME thread queue not updated as part of clock_settime call

comment:2 Changed on 08/01/22 at 06:56:47 by Chris Johns

The attached test checks the times. It will show the failure however it does not pass the initial check because the expected ticks is not the actual ticks. The failure is:

Clock settime while sleeping: step=0
clock: nanosleep: sec=0 nsec=500000000 ticks=51 expected-ticks=50
../../../testsuites/psxtests/psxclock/init.c: 120 ctx->ticks == ticks

Should the ticks the sleeper sees be 51 or 50?

Changed on 08/01/22 at 08:07:48 by Chris Johns

Attachment: init.c added

testsuites/psxtests/psxclock/init.c

comment:3 in reply to:  2 Changed on 08/02/22 at 00:53:45 by Chris Johns

Replying to Chris Johns:

The attached test checks the times. It will show the failure however it does not pass the initial check because the expected ticks is not the actual ticks. The failure is:

Clock settime while sleeping: step=0
clock: nanosleep: sec=0 nsec=500000000 ticks=51 expected-ticks=50
../../../testsuites/psxtests/psxclock/init.c: 120 ctx->ticks == ticks

Should the ticks the sleeper sees be 51 or 50?

https://lists.rtems.org/pipermail/devel/2022-August/072735.html

The extra 1 is needed.

comment:4 Changed on 08/04/22 at 05:47:27 by Sebastian Huber <sebastian.huber@…>

In c64c638/rtems:

posix: Fix relative CLOCK_REALTIME sleep

A relative CLOCK_REALTIME time out shall not be affected by CLOCK_REALTIME
changes through clock_settime(). Since our CLOCK_REALTIME is basically just
CLOCK_MONOTONIC plus an offset, we can simply use the CLOCK_MONOTONIC watchdog
for relative CLOCK_REALTIME time outs.

Update #4690.

comment:5 Changed on 08/04/22 at 05:50:25 by Sebastian Huber

Keywords: qualification added

comment:6 Changed on 08/04/22 at 05:53:26 by Sebastian Huber <sebastian.huber@…>

In 11121d0/rtems-central:

spec: Fix relative CLOCK_REALTIME sleep

A relative CLOCK_REALTIME time out shall not be affected by CLOCK_REALTIME
changes through clock_settime(). Since our CLOCK_REALTIME is basically just
CLOCK_MONOTONIC plus an offset, we can simply use the CLOCK_MONOTONIC watchdog
for relative CLOCK_REALTIME time outs.

Update #4690.

comment:7 Changed on 08/04/22 at 21:48:28 by Chris Johns <chrisj@…>

Owner: set to Chris Johns <chrisj@…>
Resolution: fixed
Status: newclosed

In 1a883b9/rtems:

testsuite/psxclock: Check setting realtime clock does not effect sleeping tasks

Closes #4690

comment:8 Changed on 08/05/22 at 06:12:49 by Sebastian Huber <sebastian.huber@…>

In c3c4525/rtems:

posix: Avoid dead code in clock_nanosleep()

This issue was reported by Coverity Scan for RTEMS:

CID 1507760: Control flow issues (DEADCODE)

Closes #4690.

Note: See TracTickets for help on using tickets.