Can Lua run within the real-time kernel?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Can Lua run within the real-time kernel?

孙世龙 sunshilong
Hi,

Can Lua run within the real-time kernel?
Does anybody do such a test?

Is it possible to run Lua scripts on the controller for real-time control?

Best regards
Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Rob Kendrick-2
On Wed, Sep 16, 2020 at 09:39:34AM +0800, 孙世龙 sunshilong wrote:
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?

Which real time kernel?

> Is it possible to run Lua scripts on the controller for real-time control?

In general, it's best to avoid languages with garbage collection for
real time applications as they introduce far too much unpredictability,
but it depends on how hard real time you are.  Things to consider are:
will physical damage or monetary loss occur if you miss a deadline, are
your deadlines measured in microseconds?

If the answer is no to both you're probably fine!

B.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
Hi,

>> Can Lua run within the real-time kernel?
>> Does anybody do such a test?
>Which real time kernel?
Xenomai. Did anybody run Lua within xenomai+linux kernel?

>> Is it possible to run Lua scripts on the controller for real-time control?

>In general, it's best to avoid languages with garbage collection for
>real time applications as they introduce far too much unpredictability,
>but it depends on how hard real time you are.  Things to consider are:
>will physical damage or monetary loss occur if you miss a deadline, are
>your deadlines measured in microseconds?
Basically, soft real-time is needed.






On Wed, Sep 16, 2020 at 3:04 PM Rob Kendrick <[hidden email]> wrote:

>
> On Wed, Sep 16, 2020 at 09:39:34AM +0800, 孙世龙 sunshilong wrote:
> > Hi,
> >
> > Can Lua run within the real-time kernel?
> > Does anybody do such a test?
>
> Which real time kernel?
>
> > Is it possible to run Lua scripts on the controller for real-time control?
>
> In general, it's best to avoid languages with garbage collection for
> real time applications as they introduce far too much unpredictability,
> but it depends on how hard real time you are.  Things to consider are:
> will physical damage or monetary loss occur if you miss a deadline, are
> your deadlines measured in microseconds?
>
> If the answer is no to both you're probably fine!
>
> B.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Francisco Olarte
On Wed, Sep 16, 2020 at 1:21 PM 孙世龙 sunshilong <[hidden email]> wrote:
> >will physical damage or monetary loss occur if you miss a deadline, are
> >your deadlines measured in microseconds?
> Basically, soft real-time is needed.

You can try to trade speed for jitter if code is fast enough. I mean,
I have a system which is somehow realtime, I process messages in lua
in response to VoIP call events. I can take a couple milliseconds, and
normally finish in a hundreds of microseconds. I experimented by
running a collection after each message, the mean handling time was
higher but deviation was lower  ( as I had a network of long lived
objects implementing the handlers and a bunch of data generated to
handle the message and expiring after handling ) ( I can try to dig
out the code, but I zapped it many lua versions ago  as collection
pauses where very small and I didn't want to maintain the extra code
).

Francisco Olarte.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Tim McCracken
In reply to this post by 孙世龙 sunshilong

Can Lua run within the real-time kernel?
Does anybody do such a test?

Is it possible to run Lua scripts on the controller for real-time control?
Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?

The real time kernels I have worked with are pretty complete and rarely need anything added within the kernel for real time control itself. As someone else pointed out garbage collection will make the kernel non-deterministic. However, you can leave the "hard" real time tasks coded in 'C' while providing a Lua thin wrapper around the kernel API (and other APIs such as network) and thereby support "soft" real time tasks that are written in Lua. A pretty good hybrid solution that I experimented with sometime ago. There are a number of commercial products that use this solution to provide end user programmability on a closed source product.


From: 孙世龙 sunshilong <[hidden email]>
Sent: Tuesday, September 15, 2020 8:39 PM
To: Lua mailing list <[hidden email]>
Subject: Can Lua run within the real-time kernel?
 
Hi,

Can Lua run within the real-time kernel?
Does anybody do such a test?

Is it possible to run Lua scripts on the controller for real-time control?

Best regards
Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
In reply to this post by Francisco Olarte
Hi, Francisco Olarte

Thank you for your reply.

>>>will physical damage or monetary loss occur if you miss a deadline, are
>>>your deadlines measured in microseconds?
>> Basically, soft real-time is needed.
>I mean, I have a system which is somehow realtime, I process messages
>in lua in response to VoIP call events.
Does Lua run on a realtime OS to process VoIP call events?
What OS do you use?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 7:42 PM Francisco Olarte <[hidden email]> wrote:

>
> On Wed, Sep 16, 2020 at 1:21 PM 孙世龙 sunshilong <[hidden email]> wrote:
> > >will physical damage or monetary loss occur if you miss a deadline, are
> > >your deadlines measured in microseconds?
> > Basically, soft real-time is needed.
>
> You can try to trade speed for jitter if code is fast enough. I mean,
> I have a system which is somehow realtime, I process messages in lua
> in response to VoIP call events. I can take a couple milliseconds, and
> normally finish in a hundreds of microseconds. I experimented by
> running a collection after each message, the mean handling time was
> higher but deviation was lower  ( as I had a network of long lived
> objects implementing the handlers and a bunch of data generated to
> handle the message and expiring after handling ) ( I can try to dig
> out the code, but I zapped it many lua versions ago  as collection
> pauses where very small and I didn't want to maintain the extra code
> ).
>
> Francisco Olarte.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
In reply to this post by Tim McCracken
Hi, Tim McCracken

>>Can Lua run within the real-time kernel?
>>Does anybody do such a test?
>>Is it possible to run Lua scripts on the controller for real-time control?
>Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
Sorry for misleading you.
I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 9:08 PM Tim McCracken <[hidden email]> wrote:

>
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
>
> The real time kernels I have worked with are pretty complete and rarely need anything added within the kernel for real time control itself. As someone else pointed out garbage collection will make the kernel non-deterministic. However, you can leave the "hard" real time tasks coded in 'C' while providing a Lua thin wrapper around the kernel API (and other APIs such as network) and thereby support "soft" real time tasks that are written in Lua. A pretty good hybrid solution that I experimented with sometime ago. There are a number of commercial products that use this solution to provide end user programmability on a closed source product.
>
> ________________________________
> From: 孙世龙 sunshilong <[hidden email]>
> Sent: Tuesday, September 15, 2020 8:39 PM
> To: Lua mailing list <[hidden email]>
> Subject: Can Lua run within the real-time kernel?
>
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Best regards
> Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

François Perrad
In reply to this post by 孙世龙 sunshilong


Le mer. 16 sept. 2020 à 14:53, 孙世龙 sunshilong <[hidden email]> a écrit :
Hi, Francisco Olarte

Thank you for your reply.

>>>will physical damage or monetary loss occur if you miss a deadline, are
>>>your deadlines measured in microseconds?
>> Basically, soft real-time is needed.
>I mean, I have a system which is somehow realtime, I process messages
>in lua in response to VoIP call events.
Does Lua run on a realtime OS to process VoIP call events?

RaptorJIT could be the Lua interpreter that you need.

https://prosody.im/ (a XMPP server) works with LuaJIT.

François

 
What OS do you use?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 7:42 PM Francisco Olarte <[hidden email]> wrote:
>
> On Wed, Sep 16, 2020 at 1:21 PM 孙世龙 sunshilong <[hidden email]> wrote:
> > >will physical damage or monetary loss occur if you miss a deadline, are
> > >your deadlines measured in microseconds?
> > Basically, soft real-time is needed.
>
> You can try to trade speed for jitter if code is fast enough. I mean,
> I have a system which is somehow realtime, I process messages in lua
> in response to VoIP call events. I can take a couple milliseconds, and
> normally finish in a hundreds of microseconds. I experimented by
> running a collection after each message, the mean handling time was
> higher but deviation was lower  ( as I had a network of long lived
> objects implementing the handlers and a bunch of data generated to
> handle the message and expiring after handling ) ( I can try to dig
> out the code, but I zapped it many lua versions ago  as collection
> pauses where very small and I didn't want to maintain the extra code
> ).
>
> Francisco Olarte.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Tim McCracken
In reply to this post by 孙世龙 sunshilong

I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?
I think the question of "should you" has been answered correctly by others, with the key question always being how "hard" is each of your tasks that you plan to run in the kernel. You should not use it for tasks that need a hard response time or else bad things happen. However it's fine for "soft" real time tasks. There is no issue with having multiple tasks written in 'C' and running simultaneous Lua tasks subject to the normal RTOS caveats. 

NOTE: I am not familiar with the RTOS you mentioned. I am familiar with FreeRTOS and the uCOS, which are very similar to other pure RTOS kernels - including all the way back to iRMX in the 1980s. (the 'u' in uCOS is actually the greek letter 'mu', but it's not clear to me if the author intended it to be pronounced 'mucous'. 🙂 )

Here is what I did, and yes it worked fine.
  1. Built a thin wrapper around the FreeRTOS API.
  2. Created a task in 'C' that created and ran a Lua interpreter. The Lua script must be an endless loop, just as if you were writing a C task.
  3. Communicated between my Lua task and 'C' tasks using queues.
I would describe it as a fairly trivial process as I had been working with the Lua C API for a while and had some experience with uCOS - a very similar RTOS. You wouldn't even need the full thin wrapper to prove the concept. You could wrap just the RTOS sleep() function, create a 'C' task that creates a Lua interpreter and run a simple script that prints "Hello, World" and then calls the RTOS sleep() function and loops back.


From: 孙世龙 sunshilong <[hidden email]>
Sent: Wednesday, September 16, 2020 8:29 AM
To: Lua mailing list <[hidden email]>; Tim McCracken <[hidden email]>
Subject: Re: Can Lua run within the real-time kernel?
 
Hi, Tim McCracken

>>Can Lua run within the real-time kernel?
>>Does anybody do such a test?
>>Is it possible to run Lua scripts on the controller for real-time control?
>Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
Sorry for misleading you.
I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 9:08 PM Tim McCracken <[hidden email]> wrote:
>
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
>
> The real time kernels I have worked with are pretty complete and rarely need anything added within the kernel for real time control itself. As someone else pointed out garbage collection will make the kernel non-deterministic. However, you can leave the "hard" real time tasks coded in 'C' while providing a Lua thin wrapper around the kernel API (and other APIs such as network) and thereby support "soft" real time tasks that are written in Lua. A pretty good hybrid solution that I experimented with sometime ago. There are a number of commercial products that use this solution to provide end user programmability on a closed source product.
>
> ________________________________
> From: 孙世龙 sunshilong <[hidden email]>
> Sent: Tuesday, September 15, 2020 8:39 PM
> To: Lua mailing list <[hidden email]>
> Subject: Can Lua run within the real-time kernel?
>
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Best regards
> Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Viacheslav Usov
On Wed, Sep 16, 2020 at 5:03 PM Tim McCracken <[hidden email]> wrote:

> (the 'u' in uCOS is actually the greek letter 'mu', but it's not clear to me if the author intended it to be pronounced 'mucous'.  )

Given what Wikipedeia says, viz., "MicroC/OS, stylized as μC/OS", I'd
think otherwise :)

Unless there is some other uCOS.

Cheers,
V.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Philippe Verdy-2
I read it like "microcosm", i.e. a small isolated and autonomous universes which can continue to like and perform correctly by itself without depending on the outside. However if this evolution includes a growth (and not simply a survival in its existing state), it will fatally start to use external resources and depend on them, and it could fragment itself into competing microcosms...

Compare "uCOS" to "um" (common abbreviation of "micrometer" in US English (or "micrometre" in British English) reduced to the Basic Latin character set: this is not a latin letter u, but the symbol for the "micro-" prefix, borrowing the Greek mu letter used as well to write the same prefix in Greek where it originated).


Le mer. 16 sept. 2020 à 18:10, Viacheslav Usov <[hidden email]> a écrit :
On Wed, Sep 16, 2020 at 5:03 PM Tim McCracken <[hidden email]> wrote:

> (the 'u' in uCOS is actually the greek letter 'mu', but it's not clear to me if the author intended it to be pronounced 'mucous'.  )

Given what Wikipedeia says, viz., "MicroC/OS, stylized as μC/OS", I'd
think otherwise :)

Unless there is some other uCOS.

Cheers,
V.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
In reply to this post by Tim McCracken
Hi,  Tim McCracken

Thank you for the clarification.

>Built a thin wrapper around the FreeRTOS API.
Include the Apis about real-time thread\mutex\conditional_variable?
Please let me know if I missed something.

Thank you for your attention to my question.  

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 11:02 PM Tim McCracken <[hidden email]> wrote:

I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?
I think the question of "should you" has been answered correctly by others, with the key question always being how "hard" is each of your tasks that you plan to run in the kernel. You should not use it for tasks that need a hard response time or else bad things happen. However it's fine for "soft" real time tasks. There is no issue with having multiple tasks written in 'C' and running simultaneous Lua tasks subject to the normal RTOS caveats. 

NOTE: I am not familiar with the RTOS you mentioned. I am familiar with FreeRTOS and the uCOS, which are very similar to other pure RTOS kernels - including all the way back to iRMX in the 1980s. (the 'u' in uCOS is actually the greek letter 'mu', but it's not clear to me if the author intended it to be pronounced 'mucous'. 🙂 )

Here is what I did, and yes it worked fine.
  1. Built a thin wrapper around the FreeRTOS API.
  2. Created a task in 'C' that created and ran a Lua interpreter. The Lua script must be an endless loop, just as if you were writing a C task.
  3. Communicated between my Lua task and 'C' tasks using queues.
I would describe it as a fairly trivial process as I had been working with the Lua C API for a while and had some experience with uCOS - a very similar RTOS. You wouldn't even need the full thin wrapper to prove the concept. You could wrap just the RTOS sleep() function, create a 'C' task that creates a Lua interpreter and run a simple script that prints "Hello, World" and then calls the RTOS sleep() function and loops back.


From: 孙世龙 sunshilong <[hidden email]>
Sent: Wednesday, September 16, 2020 8:29 AM
To: Lua mailing list <[hidden email]>; Tim McCracken <[hidden email]>
Subject: Re: Can Lua run within the real-time kernel?
 
Hi, Tim McCracken

>>Can Lua run within the real-time kernel?
>>Does anybody do such a test?
>>Is it possible to run Lua scripts on the controller for real-time control?
>Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
Sorry for misleading you.
I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 9:08 PM Tim McCracken <[hidden email]> wrote:
>
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
>
> The real time kernels I have worked with are pretty complete and rarely need anything added within the kernel for real time control itself. As someone else pointed out garbage collection will make the kernel non-deterministic. However, you can leave the "hard" real time tasks coded in 'C' while providing a Lua thin wrapper around the kernel API (and other APIs such as network) and thereby support "soft" real time tasks that are written in Lua. A pretty good hybrid solution that I experimented with sometime ago. There are a number of commercial products that use this solution to provide end user programmability on a closed source product.
>
> ________________________________
> From: 孙世龙 sunshilong <[hidden email]>
> Sent: Tuesday, September 15, 2020 8:39 PM
> To: Lua mailing list <[hidden email]>
> Subject: Can Lua run within the real-time kernel?
>
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Best regards
> Sunshilong