Skip to content

Conversation

francdoc
Copy link

@francdoc francdoc commented Sep 6, 2025

Checklist

Describe the contribution
Fixes #1401. Make OS_QueueGet finite timeouts immune to CLOCK_REALTIME changes in OSAL POSIX by:

  • Adding OS_Posix_CompAbsDelayTimeMonotonic() and mq_timedreceive_monotonic() (uses CLOCK_MONOTONIC + poll). mq_timedreceive_monotonic() is a new method I implemented to try to fix the issue.
  • Adding a unit-test “time jumper” task that steps CLOCK_REALTIME forward to test and validate behavior.

Testing performed

  • Build: standard OSAL unit tests (generic-linux) via CMake; build queue-test.
  • Run (needs CAP_SYS_TIME): sudo ./queue-test
  • Observed periodic logs: realtime jumps (clock_settime +10 seconds every 5 seconds) while OS_QueueGet continues to timeout ~every 1s.

All tests PASS: TOTAL::43 PASS::43 FAIL::0.

Expected behavior changes

  • API Change: No changes (public API unchanged).
  • Behavior Change: OS_QueueGet with a finite timeout is now based on monotonic time; unaffected by wall-clock jumps (settimeofday). OS_PEND and OS_CHECK semantics unchanged.

System(s) tested on

Additional context

  • Test includes a realtime “jumper” task using clock_settime(CLOCK_REALTIME, …) to simulate wall-clock discontinuities.

Third party code
None.

Contributor Info - All information REQUIRED for consideration of pull request
Franco Chiesa Docampo - Personal.

@joelsherrill
Copy link

mq_timedreceive_monotonic() is not in the POSIX standard. Per what I found on the Net, it is specific to QNX and not supported on Linux, FreeBSD, or RTEMS. Per the POSIX Issue 8 definition of mqueue.h, message queues do not include a function similar to pthread_mutex_clocklock() which lets you specify the clock.

poll() is similar to select() in that there it should not be assumed that it will work on anything other than sockets when dealing with an RTOS TCP/IP stack.

@francdoc
Copy link
Author

francdoc commented Sep 8, 2025

Hi @joelsherrill I apologize. Yes, mq_timedreceive_monotonic() is a method I implemented to try to propose a solution. It does not exist in the POSIX standard. I can edit my original post to be more clear and specific to avoid any misunderstanding.

I will review your feedback and make proper changes to the proposed solution to check if it remains viable. Thank you for your response.

I'm changing this PR to draft.

@francdoc francdoc marked this pull request as draft September 8, 2025 16:36
@joelsherrill
Copy link

Hi @joelsherrill I apologize. Yes, mq_timedreceive_monotonic() is a method I implemented to try to propose a solution. It does not exist in the POSIX standard. I can edit my original post to be more clear and specific to avoid any misunderstanding.

I will review your feedback and make proper changes to the proposed solution to check if it remains viable. Thank you for your response.

I'm changing this PR to draft.

Since the name looks like POSIX function, you need to at least add the suffix of "_np" for non-portable. But since it is provided outside of the OS and libraries, I'd recommend using another name entirely.

What does the implementation of that function depend on?

@francdoc
Copy link
Author

francdoc commented Sep 17, 2025

Hi @joelsherrill I apologize. Yes, mq_timedreceive_monotonic() is a method I implemented to try to propose a solution. It does not exist in the POSIX standard. I can edit my original post to be more clear and specific to avoid any misunderstanding.
I will review your feedback and make proper changes to the proposed solution to check if it remains viable. Thank you for your response.
I'm changing this PR to draft.

Since the name looks like POSIX function, you need to at least add the suffix of "_np" for non-portable. But since it is provided outside of the OS and libraries, I'd recommend using another name entirely.

What does the implementation of that function depend on?

Hi Joel. Function is now purely internal and no longer exposed in os-posix.h.

It depends on:

    • clock_gettime(CLOCK_MONOTONIC, …)
    • poll() on the mqd_t file descriptor
    • mq_receive()

The helper is now a static in the .c file. I renamed to OS_Posix_MqReceiveUntilMonotonicDeadline, with no public prototype.

I’ll continue testing this PR for further improvements.

@francdoc francdoc marked this pull request as ready for review September 17, 2025 16:58
@francdoc francdoc marked this pull request as draft September 17, 2025 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Message Receive timeout if system clock changes?

2 participants