HansiGlaser
Posts: 3
Joined: Sun Feb 05, 2017 8:56 pm

Real-Time Thread in ThreadX on VideoCore

Sun Feb 05, 2017 9:05 pm

Hi!

After some research, I found that the VideoCore actually runs ThreadX before it starts Linux on the ARM CPUs. I want to run a real-time thread on the VideoCore to do some hardware interaction (basically just GPIOs, but without missing any actions).

Unfortunately I only found examples how to run code on the VideoCore either instead of Linux (by replacing bootcode.bin, actually there is also a boot loader for Linux by Christina), or how to run some accelerated code issued from Linux applications, but these can't run in parallel and are no full ThreadX threads.

Is there any information on how to add ThreadX threads?

Thanks
Hansi

PS: I have to other possibilities: a) get the Linux kernel real-time and do the hardware interactions, or b) add an external MCU for this job and communicate to it via UART. However, the coolest solution would clearly be the ThreadX thread. :-)

HansiGlaser
Posts: 3
Joined: Sun Feb 05, 2017 8:56 pm

Re: Real-Time Thread in ThreadX on VideoCore

Sun Feb 19, 2017 8:13 pm

Hi!

Unfortunately no reply and nothing new on this topic.

However, some small news on a related topic. I've tested how well suited the out-of-the-box Raspbian is for real-time operations. Therefore I wrote a small Linux kernel module (https://github.com/hansiglaser/rpi-rt/t ... er/lattest) and let it run on the unpatched kernel (RPi 3 B V1.2, Raspbian Jessie Lite, 2017-01-11-raspbian-jessie-lite.zip, Linux kernel 4.4.38-v7+). The module uses the kernel HR-Timer to run a function every 10ms and determines how precise these 10ms were, and collects descriptive statistics over 10000 intervals.

The results are astonishingly good, even with high system activity.
  • The best results are (surprisingly) achieved with fully loaded CPU (5 tasks with 100% CPU usage): max. +/-7us, std.dev. 140ns
  • With an idling system: max. +/-11us, std.dev. 1930ns
  • The worst results are achieved while reading a large file from the SD card: max. +/-50us, std.dev. 4440ns
  • Heavy TCP traffic (but not so much UDP traffic) and access to an USB stick also result in nearly as bad numbers.
Bye
Hansi

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Real-Time Thread in ThreadX on VideoCore

Sun Feb 19, 2017 8:37 pm

You might find this interesting :
https://stackoverflow.com/questions/907 ... my-process

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

HansiGlaser
Posts: 3
Joined: Sun Feb 05, 2017 8:56 pm

Re: Real-Time Thread in ThreadX on VideoCore

Sun Mar 05, 2017 8:43 pm

Hi!
ghans wrote:You might find this interesting :
https://stackoverflow.com/questions/907 ... my-process
Thanks for this hint! I'll have a look.

Thanks
Hansi

User avatar
Gavinmc42
Posts: 4338
Joined: Wed Aug 28, 2013 3:31 am

Re: Real-Time Thread in ThreadX on VideoCore

Fri Mar 10, 2017 2:55 am

Is there any information on how to add ThreadX threads?
Unfortunately no reply and nothing new on this topic.
Not much info out there on the VCOS.
If you found Christina you found most of those who know anything.

I moved to baremetal via Ultibo because there is some info on cpu multi core usage, like example 11
https://github.com/ultibohub/Examples

If you can write Linux kernel modules then you are probably more capable than 99.9% of the people on the forums.
I would be interested if you could do the same tests on Ultibo.

I did a bit of hex editing on the VC4 binaries, it looks like they use the ARC compiler/assembler toolkit.
You probably would need to use the same tools, disassemble the VC4 code and add you own stuff?

It would be interesting if the LLWM compiler was fully working on the VC4.
Last night I compiled OpenOCD in Raspbian, JTAG VC4 access for debugging?
Two VPU's and 12 QPU's? If you don't use any graphics/hdmi etc how many are free to use?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25368
Joined: Sat Jul 30, 2011 7:41 pm

Re: Real-Time Thread in ThreadX on VideoCore

Fri Mar 10, 2017 10:24 am

HansiGlaser wrote:Hi!

After some research, I found that the VideoCore actually runs ThreadX before it starts Linux on the ARM CPUs. I want to run a real-time thread on the VideoCore to do some hardware interaction (basically just GPIOs, but without missing any actions).

Unfortunately I only found examples how to run code on the VideoCore either instead of Linux (by replacing bootcode.bin, actually there is also a boot loader for Linux by Christina), or how to run some accelerated code issued from Linux applications, but these can't run in parallel and are no full ThreadX threads.

Is there any information on how to add ThreadX threads?

Thanks
Hansi

PS: I have to other possibilities: a) get the Linux kernel real-time and do the hardware interactions, or b) add an external MCU for this job and communicate to it via UART. However, the coolest solution would clearly be the ThreadX thread. :-)
I don't believe what you want to do is possible without access to the VC4 codebase, which is closed source.

There are some example programs out there that use the quads, that might give a way in, but that stuff is not easy, and interaction with Linux would be hairy to say the least.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

User avatar
Gavinmc42
Posts: 4338
Joined: Wed Aug 28, 2013 3:31 am

Re: Real-Time Thread in ThreadX on VideoCore

Sat Mar 11, 2017 3:23 am

Magenta on Pi 3.
viewtopic.php?f=63&t=176953

Little Kernel on VC4?
https://github.com/fuchsia-mirror/magen ... _and_lk.md
LK, RTOS, ThreadX.
We know ThreadX works :lol:

Having Millions of Pi's out there is a platform for experimentation.
The only thing stopping this is lack of info on the VC4.
Still plenty to learn on Pi's as this info is slowly worked out the hard way.
Broadcom could spoil the party for us by releasing all the info :(

But they probably don't care about the next generation of programmers growing up using their micros and gpus :lol:
Hack the Pi, then all those media chips they make for gear could be targets.

Kinect, Rockbox for MP3's, CyanogenMod for Android phones etc prove it can be done.

Just been playing with OpenOCD on Pi3, it installs and Pi's have a footprint for a JTAG connector.
The hardware and software is all there now.

The next gen hardware hacker will have a Pi with bitbanged JTAG via the GPIO?
I don't see it a matter of if DIY ThreadX or an equivalent runs on the VC4 it is just when.
I suspect it has already happened and I have missed it.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
Gavinmc42
Posts: 4338
Joined: Wed Aug 28, 2013 3:31 am

Re: Real-Time Thread in ThreadX on VideoCore

Tue Mar 14, 2017 3:50 am

Found a link to BCM Android code in this
viewtopic.php?f=43&t=177218&p=1130143&h ... a#p1130143

Shh don't tell anyone.
Buried inside is some VCOS and ThreadX code :P
Lots of stuff, how much is useful?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
procount
Posts: 2035
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Real-Time Thread in ThreadX on VideoCore

Fri Feb 14, 2020 10:27 am

HansiGlaser wrote:
Sun Feb 19, 2017 8:13 pm
I've tested how well suited the out-of-the-box Raspbian is for real-time operations ... on the unpatched kernel
HansiGlaser wrote:
Sun Feb 19, 2017 8:13 pm
The results are astonishingly good
HansiGlaser wrote:
Sun Feb 05, 2017 9:05 pm
PS: I have to other possibilities: a) get the Linux kernel real-time and do the hardware interactions
If the unpatched kernel is nearly good enough (I assume you mean without the RT Kernel patch), then you could also consider Xenomai which aims to minimise latencies. (see e.g. http://linuxgizmos.com/real-time-linux-explained/ or https://stackoverflow.com/questions/311 ... time-linux for comparisons). Xenomai patches exist for the RPi, but tend to lag behind the current kernel version.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

Return to “Bare metal, Assembly language”