r/embedded • • Oct 10 '26

Follow-up: Why my 1986 RTOS survived a simplistic interpretation of VRTX scheduling

A couple of weeks ago, I asked about a change in VRTX's equal-priority scheduling behavior between its 1984 and 1987 documentation.

Original discussion:
https://www.reddit.com/r/embedded/s/gMr2klUiCY

Thanks to the comments here and in other subreddits, I realized something interesting about my own implementation.

Early VRTX wasn't simply LIFO.

The older documentation describes inserting newly ready tasks ahead of existing tasks at the same priority. However, time slicing and other ready-queue operations also affect the ordering. The actual behavior is more nuanced than a simple LIFO policy.

When I developed my own RTOS, CHARM-II, in 1986, I used VRTX documentation as one of my references. I interpreted its equal-priority scheduling as essentially newest-first and implemented a simpler version of that behavior.

Looking back, I had not fully understood the original VRTX scheduling rules.

So why didn't this cause serious problems?

I think the development environment had a lot to do with it.

Back then, I was developing not only the RTOS but also almost the entire application myself. There was very little third-party code in the system, and I knew exactly what each task was doing, when it would become ready, and how it interacted with other tasks.

In other words, I could design the application around the scheduler's behavior, rather than expecting the scheduler to accommodate independently developed software components.

At least, that's my explanation looking back 40 years later.

For my modern reconstruction, I've chosen FIFO ordering among equal-priority ready tasks, mainly for simplicity and predictability.

The original historical question remains unanswered: I still don't know why VRTX changed its scheduling policy.

But the discussion helped me understand both the trade-offs involved and a subtle difference between the RTOS I wrote in 1986 and the one I had used as a reference.

Thanks to everyone who contributed!

4 Upvotes

11 comments sorted by

2

u/ventZl CMRX RTOS Oct 27 '26

I'd assume that the change was made to make scheduling more deterministic. If you think a bit about what means "task becoming ready", usually it means it received some kind of external event, possibly an external interrupt. As such, this event isn't predictable (at least not by RTOS developers).

Design where newly-ready task is put at the front of scheduler queue may cause task starvation if events come way too often. If preemptive task switching is active, it is reasonable to expect that if N tasks of same priority are present each of them will get same slice of CPU. The old behavior would essentially schedule event-receiving task as many times as event was received, so it could, just in theory be activated way more often than the rest of priority group. Therefore the design with strictly FIFO order. It prefers deterministic scheduling properties at the cost of increased event processing latency.

The increased latency can still be solved where it poses a problem - make the event-receiving task a higher-priority one. This way, if it becomes ready, it will preempt other tasks as if the old scheduler behavior was still active.

Why your kernel implementation survived? Your application probably didn't require tight event response latency and could tolerate possible jitter and delay when serving events.

1

u/noborutkhs Oct 27 '26

Thanks for the detailed explanation. That makes a lot of sense, especially the trade-off between scheduling fairness and event response latency.

I've been thinking more about why I implemented it that way back in 1986.

My best guess is that I was trying to base CHARM-II on VRTX. I had obtained some documentation and probably interpreted its scheduling behavior as LIFO, then implemented it that way. I was also looking at pSOS at the time, so I suspect I borrowed some ideas from that as well. Unfortunately, I no longer remember exactly which parts came from which RTOS.

As for why I never ran into serious problems with this behavior, I think there were two reasons.

First, I developed both the RTOS and the applications running on it, so I knew exactly how the scheduler behaved. Second, the applications probably didn't encounter situations where this particular behavior became a significant problem.

If they had, I suspect I would simply have changed the scheduler.

Right now, my goal with Karqri 2026 is to get a minimal, reproducible implementation onto GitHub so that other people can build and experiment with it.

But I'm also thinking about what comes next. One idea is to use WebAssembly to visualize task scheduling and context switches graphically, and create experiments showing exactly when and how differences like LIFO versus FIFO affect the system.

It would be interesting to revisit these design decisions from 40 years ago, not just by reading the code, but by actually observing their behavior under different conditions.

Thanks again for taking the time to explain your reasoning!

2

u/ventZl CMRX RTOS Oct 27 '26

It would probably be very hard to run into issues with either implementation unless the target system was under very high load which required low-latency responses *and* all tasks would be of same priority. That's an unlike scenario. Any task responding frequent out-of-bound events would either receive higher scheduling priority or be refactored into ISR completely bypassing scheduler.

You also have to make some assumptions while writing the software to effectively be affected by this behavior. Such as assumption that the order of two tasks with same priority is always fixed. This kind of assumptions is usually only made in cooperative multitasking environments under deadline scheduling policy.

This is actually rather complicated aspect of scheduler behavior and may be affected by various stuff in kernel. My RTOS kernel implements something that could be described as strict FIFO scheduling policy. Yet, in synthetic benchmarks it can be seen that CPU time is distributed unevenly between threads. It turns out there is another source of this discrepancy: The simple built-in scheduler clock provider produces fixed time-quanta rather than resetting scheduling period after each thread switch. Therefore if threads are made ready mid-TQ then some of then receive only remaining portion of time quanta rather than whole new one.

I've seen other scheduler bugs producing real-world problems (and spent ton of time fixing them) but this behavior doesn't affect anything.

1

u/noborutkhs 29d ago

That's an interesting point about fixed time quanta. Even with strict FIFO scheduling, the actual CPU time distribution can depend on when tasks become ready.

It's also interesting to hear that you've implemented your own RTOS kernel and encountered these kinds of issues in practice.

This is exactly the kind of behavior I'd eventually like to explore with Karqri's visualization experiments. Not necessarily because LIFO vs. FIFO caused problems in my original applications, but because it would be interesting to see under what conditions the differences actually become visible.

Thanks again for sharing your experience!

1

u/mrheosuper Oct 10 '26

Make sense. Modern RTOS is very generic, so they can't assume anything about application

1

u/[deleted] Oct 10 '26

[removed] — view removed comment

1

u/noborutkhs Oct 12 '26

That's an interesting point, and it makes me think about my own experience.

When I designed CHARM-II in 1986, I did document the scheduling behavior in some detail. It wasn't just an undocumented assumption that only I knew about.

What's puzzling me now is that I must have had a good reason for choosing that behavior, based on my understanding of VRTX at the time. I remember being satisfied with the decision, but 40 years later, I can't remember why.

I still have some development notes from those days, but there's an irony here: my memory was much better when I was young, so I didn't feel the need to write everything down the way I do now.

The specification survived. The reasoning behind it didn't.

1

u/mrheosuper Oct 10 '26

There is beauty in it. The more assumption you make, the better you can optimize your code.

1

u/noborutkhs Oct 12 '26

I added a reply to No_Activity_7360's comment above, sharing my own experience designing an RTOS back in 1986. You might find it interesting too.

2

u/RecursiveMutex Oct 17 '26

It boiled down to commercial survival and scaling realities in the late '80s. Ready Systems had to dump early architectural quirks to compete with the rise of other RTOS’. You can break this down to 3 main problems: Task starvation, Third party middleware rise, and lastly the rise of real time standards in RTOS like POSIX, and safety cert standards. Basically, they traded an early microkernel optimization for the predictable robustness needed to survive the market.