top of page

MicroZed Chronicles: PREEMPT_RT PetaLinux

We’ve looked at using PetaLinux on our SoCs and MicroBlaze several times throughout our journey. Embedded Linux, however, does not always provide us with the desired interrupt latency and response time. There are, of course, several methods which can be used to improve this like using OpenAMP and a dedicated real time processor to patching the embedded Linux kernel with a pre-empt_rt patch.

In this blog, we are going to explore how we can patch a PetaLinux project to include the PREEMPT_RT patch and then verify the latency improvement we see.

To get started, we are going to target the UltraZed 3EG variant. This will enable us to see the capabilities of the PREEMPT_RT running on a Zynq UltraScale+ MPSoC.

The first thing we are going to do is create a simple hardware definition in Vivado 2023.1 I am using this version because we need to ensure the patches align.

With the XSA available, the next step is to create a simple PetaLinux project targeting the Zynq MPSoC and customize it for the hardware design using the XSA we just created. With the project created and customized for our hardware, we can patch the kernel and install the real-time test applications. To do this, we need to do the following:

  1. Download the Xilinx Linux Repo

  2. atch it with the PREEMPT_RT patch

  3. Include the rt-tests within the Root FS

  4. Customize the PetaLinux kernel to use the PREEMPT_RT kernel

The first thing to do within the PetaLinux project is to change the directory to the components directory and download the Xilinx Linux Repo and PREEMPT_RT repo and merge them. Once these have been merged, we need to set the PetaLinux project to use the kernel source here and not its normal location.

Use the command below to download and patch the kernel with the PREMEPT_RT patch.

git clone
cd linux-xlnx
git remote add rt_origin
git remote update
git checkout xilinx-v2023.1
git merge v6.1-rc7-rt5
git checkout --ours drivers/net/ethernet/xilinx/xilinx_axienet_main.c
git add drivers/net/ethernet/xilinx/xilinx_axienet_main.c
git merge --continue

Once this has been completed, we can customize the project to use this downloaded and patched kernel when it builds the project.

To do this, we need to issue the command petalinux-config and set the source to ext-local-src under the configuration.

A new option will open once selected which allows us to define the location of the patched kernel in the file system. Save and exit the configuration.

We then need to configure the kernel itself by using the command petalinux-config -c kernel to open the kernel configuration dialog. Select the kernel as the Fully Preemptible Kernel (Real-Time). Save and exit the configuration.

To include the rt-tests, we need to add the CONFIG_rt-tests to the conf file under the meta-user layer and then customize the rootfs to include the packages within the file system.

We can now build PetaLinux by using the command petalinux-build.

Once the application is built, we need to package the boot.bin and copy the boot.bin, boot.scr and image.ub on to the SD card.

petalinux-package --boot --fsbl zynqmp_fsbl.elf --u-boot u-boot.elf --pmufw pmufw.elf --fpga system.bit

Insert the SD card and boot the target board (in this case my UltraZed). Examining the boot log or the querying -uname a will show the PREEMPT_RT kernel is loaded.

Insert the SD card and boot the target board (in this case my UltraZed). Examining the boot log or the querying -uname a will show the PREEMPT_RT kernel is loaded.

We can run the cyclictest once we are all logged in.

cyclictest --mlockall --smp --priority=80 --interval=200 --distance=0

This will update the results on the terminal window while showing the average and maximum latency.

If need be, we can also further isolate a processor so that it’s only used for dedicated tasks when we build PetaLinux.

This enables us to get the best of both worlds: a low latency response while also having the capabilities and features of embedded Linux.

Workshops and Webinars

If you enjoyed the blog why not take a look at the free webinars, workshops and training courses we have created over the years. Highlights include

Embedded System Book Do you want to know more about designing embedded systems from scratch? Check out our book on creating embedded systems. This book will walk you through all the stages of requirements, architecture, component selection, schematics, layout, and FPGA / software design. We designed and manufactured the board at the heart of the book! The schematics and layout are available in Altium here Learn more about the board (see previous blogs on Bring up, DDR validation, USB, Sensors) and view the schematics here.

Sponsored by AMD

1 comment

Recent Posts

See All
bottom of page