Readit News logoReadit News
mijoharas · 4 years ago
This looks like a cool project but there's something I'm confused about.

Is the goal of this project to allow people to run realtime software? if so, isn't using lua a problem because of it's memory management causing GC stalls?

It doesn't appear to be addressed in the README of the github. One other explanation is that I'm missing the point, and it's just using RTOS as a small embeddable OS on which to run lua, is that the case?

mastax · 4 years ago
"RTOS" has come to mean a library os for embedded microcontrollers. A lot of embedded projects don't care about realtime-ness at all.
caseymarquis · 4 years ago
I think anything truly real time would be interrupt driven and use C/assembly. This would act as the glue between that critical code. I don't feel like we've hit peak embedded development yet. I love the idea of rapid embedded development that deploys scripts over a network or RS232, but most scripting languages aren't great for this. I would like to see a statically typed actor system with no GC or optional per actor GC that is pre-allocated and can only cause a single actor to fail in a predictable way.
cinntaile · 4 years ago
There are languages invented for this purpose, such as Ada. I'd look at that instead of C when you're doing real time systems. Although there are many different kinds of real time systems so it depends on the goal. Soft real time systems aren't as time critical as hard real time systems so the way you program and reason about them is a bit different.
bluGill · 4 years ago
How real time do you need to be? some real time is you need to react within milliseconds or bad things happen, humans will notice if there is 10ms lag in real time audio. Some real time is you need to react within seconds. A machine might need several tens of seconds to get up to speed, so controlling the motor only needs to update a once a second or so for the speed to remain within tolerance. And everything in between.

Depending on where you are on the need for control different technologies can work for you.

pjmlp · 4 years ago
Lua is definitly not the best option, but GC isn't an issue when a real time aware implementation is used.

https://www.ptc.com/en/products/developer-tools/perc

https://www.aicas.com/wp

https://www.microej.com/product/vee/

gnzoidberg · 4 years ago
I don't think this is true. No current GC tech is fully hard real time. (I am happy to be corrected, as it'd make my life way easier)
samatman · 4 years ago
Lua's garbage collector can be driven 'manually' quite easily.

That is, one can start it, stop it, run it to completion, run a 'step', tune the size of the step and the aggressiveness of collection, all from within Lua.

It's true that you can't get hard realtime guarantees while using Lua naively, you do have to be aware of what you're doing. If you need to be 'cycle perfect', probably use something else.

But there are an enormous number of applications where what Lua offers is just fine, and there's no reason a Lua program should have GC 'stalls', if that means unexpected and lengthy pauses in execution.

This is a really cool project imho.

snarfy · 4 years ago
All the real time guarantees would only ever happen in the libraries you are calling out to, not in the scripting language. That's just glue code. If the scripting language has the equivalent of eval() there is no way it can be made real time anyway.
admax88q · 4 years ago
I can't speak for this projevt specifically, but you can do GC in a real time system. IBMs metronome garbage collector is a real time garbage collector.
bob1029 · 4 years ago
I do soft real-time in .NET5 without any problems.

I find that if I completely abduct a high-priority thread and never yield back to the OS, things on the critical execution path run incredibly smoothly. I am able to execute a custom high precision timer in one of these loops while experiencing less than a microsecond of jitter. Granted, it will light up an entire core to 100% the whole time the app is running. But, in today's world of 256+ core 1U servers, I think this is a fantastic price to pay for the performance you get as a result. Not yielding keeps your cache very toasty.

Avoiding any allocation is also super important. In .NET, anything touching gen2 or LOH is death sentence. You probably don't even want stuff making it into gen1. Structs and streams are your friends for this adventure.

OskarS · 4 years ago
I'm curious about this as well. And it's not just GC: just allocating memory is not real-time safe unless you're using something like a bump allocator. Lua seems very much like the wrong language for this.
fullstop · 4 years ago
Lua doesn't need to use malloc directly -- you can replace the memory allocation function with your own implementation which is real-time safe.
mmoskal · 4 years ago
If your heap is on the order of 100kB the GC stalls may not be so bad. A bigger problem may be pulling your code from external SPI flash - typically you will need to put all your real time code in RAM and you have only so much of it.
ludamad · 4 years ago
You could disable the Lua GC and mostly manage C buffers with Lua functions. There's some precedent given that Lua has been used a lot in embedding
mijoharas · 4 years ago
can you disable the GC? in my last role we had a large C++ application that had embedded lua. I didn't touch it much, but I would have thought that while most of the stuff it did was calling out to our C++ api, the "lua objects" and tables e.t.c. would still be created and need to be garbage collected as normal.

Can you entirely turn off lua's GC?

gnzoidberg · 4 years ago
Embedded != real time

Deleted Comment

m00x · 4 years ago
GC stalls aren't as bad on a low memory chip since there's much less memory to clean up.
hikarudo · 4 years ago
> isn't using lua a problem because of it's memory management causing GC stalls?

Perhaps even more important is the increased memory use due to Lua. Some devices have very little memory to begin with.

pjmlp · 4 years ago
While others, like the ESP32, are much better than the PCs our computer school club had to play Defender of the Crown.

Yet MS-DOS had plenty of programming languages to chose from, when we weren't coding games or demoscene stuff.

TickleSteve · 4 years ago
The Lua interpreter is not a real-time interpreter and cannot give bounded response time.

This is a non-realtime application running on top of a scheduler that is capable of supporting realtime applications.

Just placing an application on top of an RTOS does not make it realtime.

fullstop · 4 years ago
Execution can be interrupted, though, through debug hooks. It could be set up to yield every N instructions. [1]

There's a few caveats, though, in that this will not be called if you've called into C code. That is, you will only yield while executing code in the Lua interpreter.

1. https://pgl.yoyo.org/luai/i/lua_sethook

antattack · 4 years ago
The project seems to have started in 2017 but it does not appear to be very popular. Whitecat IDE is still in alpha.

https://ide.whitecatboard.org/

Renaud · 4 years ago
I thought there was something wrong on that page:L I wanted to try the IDE but just got this video filling the page and that single red button: "sign in with your google account".

Why does an IDE for microcontrollers requires a Google Account? Guess I'll never know.

teleforce · 4 years ago
Very interesting project on RTOS and hopefully this can support the new RISC-V based ESP32-C3 MCU [1].

I wonder if the performance can significantly be improved if this is ported to Terra language, a system programming language meta-programmed in Lua [2]. It's going to stable 1.0 version real soon.

[1]https://www.espressif.com/en/news/ESP32_C3

[2]https://terralang.org/

rainer42 · 4 years ago
https://github.com/crmulliner/fluxnode follows the same idea providing a JavaScript runtime for the application development, runs on ESP32 and supports LoRa. Fewer features as this is a hobby project.
mastrsushi · 4 years ago
A language centric OS isn't a compelling idea to users outside enthusiasts of that language.
samatman · 4 years ago
Most RTOS are 'language centric', it's just that the language is C.
lebuffon · 4 years ago
or Forth... :)
qyi · 4 years ago
This is true until you realize all general purpose languages are the same and redundant. There is no reason to have more than one on a given system.
pjmlp · 4 years ago
You mean like UNIX?