Skip to content

win32 port timing and reliability issues #832

Closed

Description

@ntfreak

Describe the bug

currently using the Cortex-M7 (STM32H7) port for our main target, however the win32 port is also used to speed up our development cycle.

This has worked well for a while now, however after updating to v6.5.2.202603_rel we have experienced both timing and reliability issues in the win32 port.

all issues have been tracked down to commit f5e59a1 - anything before that commit works as before.

The timing issues appear related to the new define TX_WIN32_TICKS_PER_INTERRUPT, this can be fixed by using 1 from the default 5.

for info our project uses a 5ms tick for ThreadX and uses the following in tx_user.h

/* Define the common timer tick reference for use by other middleware components. */
#define TX_TIMER_TICKS_PER_SECOND   200

#ifdef WIN32

/* win32 port uses TX_TIMER_PERIODIC */
#define TX_TIMER_PERIODIC (1000 / TX_TIMER_TICKS_PER_SECOND)

/* also define since v6.5.2.202603_rel */
#define TX_WIN32_TICKS_PER_INTERRUPT 1
 
#endif

The other issues is reliability. Sometimes the win32 port works as expected, other times it stops after a few seconds. It does not appear repeatable.
Checked on a few laptops and the same behaviour. If we revert back to 44d7c95 (based on v6.5.1.202602a_rel) all works again.

Additional context
Building using Visual Studio 2022 (17.14.43) and Win11 (10.0.26200).
Cortex-M7 port working as expected.

Activity

  1. added
    bug
    hardware
    on Nov 4, 2026
  2. fdesbiens commented on Nov 5, 2026

    @fdesbiens
    Contributor

    Thank you for reporting this, and sorry for disrupting your workflow. Narrowing it down to f5e59a1 made it much quicker to find: both symptoms come from that commit.

    Timing. That release made the Win32 and Win64 simulators process TX_WIN32_TICKS_PER_INTERRUPT ticks, default 5, on each host timer interrupt. It also changed the default TX_TIMER_PERIODIC from 10 to 1. Simulated time therefore ran 5 times faster than TX_TIMER_PERIODIC implied, or 50 times at the defaults. Your TX_WIN32_TICKS_PER_INTERRUPT 1 workaround is correct. The fix restores 10 and 1 as the defaults, so TX_TIMER_PERIODIC (1000 / TX_TIMER_TICKS_PER_SECOND) gives host-clock time again without the extra define.

    Stops after a few seconds. The same commit made a simulated interrupt wait until the thread it woke had started running. Only one waiter was supported. If a second host thread also simulates interrupts by calling _tx_thread_context_save() and _tx_thread_context_restore(), both can wait at once. The GUIX Win32 driver does this, as do custom UART or network simulation threads. Both waiters then spin above the priority of the ThreadX threads, so the woken thread never runs. Either the tick count stops, or it keeps advancing while no thread is scheduled. A test with a second interrupt thread reproduces this every time on both ports, and passes with the fix.

    To confirm this is what you are seeing:

    1. Does your application have host threads, besides the port's timer, that call _tx_thread_context_save()/_tx_thread_context_restore(), or that call ThreadX services from outside a ThreadX thread? That includes the GUIX Win32 driver, a simulated peripheral or a network driver.
    2. Which TX_WIN32_* options do you define, if any, besides TX_WIN32_TICKS_PER_INTERRUPT? For example TX_WIN32_NO_IDLE_ENABLE or TX_WIN32_BYPASS_AFFINITY_SETUP.
    3. Could you try the fix in Fixed Windows simulator stalls and restored host-clock tick rate #833 and say whether the stalls stop?

    If you have no second interrupt source, or the stalls continue with the fix, please break into the stalled process in Visual Studio (Debug > Break All) and send:

    • the call stacks of all threads (Debug > Windows > Parallel Stacks, or a minidump via Debug > Save Dump As);
    • the values of _tx_thread_current_ptr, _tx_thread_execute_ptr, _tx_thread_system_state, _tx_win32_system_error and _tx_win32_critical_section;
    • whether _tx_timer_system_clock still advances between two breaks.
  3. self-assigned this
    on Nov 5, 2026
  4. ntfreak commented on Nov 5, 2026

    @ntfreak
    ContributorAuthor

    Thanks for the fast response, very much appreciated. Yes our code uses host threads that call _tx_thread_context_save()/_tx_thread_context_restore().

    I have tested your branch and it does indeed fix the issues😃
    For info we have no other TX_WIN32_ options defined.

    Just one observation - in one of our applications we send a canopen msg every second.
    On the previous win32 port it was seen on the can analyser at ~1sec. With this update the msg appears offset by ~60ms. This offset seems deterministic as it is ~30ms for a 0.5sec message.

    It does not cause any issues, just thought i would mention it.

  5. fdesbiens commented on Nov 5, 2026

    @fdesbiens
    Contributor

    Thank you for testing, and for confirming the interrupt threads; that matches what I reproduced.

    The offset you measured is a second defect from the same rework. After each simulated interrupt, the timer was re-armed relative to the moment that interrupt finished, so the time spent handling each interrupt was added to every 5 ms tick. 60 ms per second is 6%, the same proportion as your 30 ms per 0.5 s. The 6.5.1 port used a periodic timer, so it did not drift. With your settings I measured 191 ticks/s against 200 on an idle system.

    #834 fixes this by scheduling each interrupt from the previous deadline instead of from the end of the last interrupt. With TX_TIMER_PERIODIC 5 it measures 200.0 ticks/s against the host clock. It is stacked on #833, so its branch contains both fixes. If you can repeat your CANopen check on it, that would confirm it on real traffic.

    If all looks good, I will merge both fixes into dev, and they will ship with v6.5.3 in December.

  6. ntfreak commented on Nov 6, 2026

    @ntfreak
    ContributorAuthor

    yes that fixes the offset issue thanks. probably better than it was previously.
    really appreciate the time you have taken to resolve my issues 👏

  7. added a commit that references this issue on Nov 6, 2026
    f72eb37
  8. fdesbiens commented on Nov 6, 2026

    @fdesbiens
    Contributor

    Thank you again for reporting this, and for testing both fixes. They are now merged into dev (#833 and #834), so you can pick them up from there, and they will ship with v6.5.3 in December. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bughardware

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions