Inconsistent delay between GPIO toggle


I’m using Jetson AGX xavier development kit. I need to generate a clock using gpio so I configured gpio_250 as a output pin and toggling using gpio_set_value() API. But the delay between the toggling is not uniform. because of this non uniform timing issue I couldn’t get the expected sequence of my requirement.


Scope capture of the output:

Could you boost the CPU as performance to try.

sudo nvpmodel -m 0
sudo jetson_clocks
sudo su
echo 1 > /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
cat /sys/kernel/debug/bpmp/debug/clk/emc/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/emc/rate

Hi Shane,
Thanks for your prompt response. I have tried your suggestion but that inconsistent behavior is exist. Here is the logs and output image.

root@c2v-desktop:/home/c2v/Desktop/sinchana/kmod_test# rmmod user_kmodule.ko
root@c2v-desktop:/home/c2v/Desktop/sinchana/kmod_test# sudo nvpmodel -m 0
root@c2v-desktop:/home/c2v/Desktop/sinchana/kmod_test# sudo jetson_clocks
root@c2v-desktop:/home/c2v/Desktop/sinchana/kmod_test# echo 1 > /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
root@c2v-desktop:/home/c2v/Desktop/sinchana/kmod_test# cat /sys/kernel/debug/bpmp/debug/clk/emc/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/emc/rate


very few times i’m getting proper output.

Any suggestion would be helpful for us.

Any update on this?

Can anyone help on this? Pls share your suggestions if any.

It could be the ndelay() to smaller for the GPIO sample rate. As the GPIO Max sample rate is 50Khz so I think the min delay is 20ns

Hi Shane,
we used udelay() not ndelay(). Our requirement is like each toggle should be with in 2uS(max). But sometimes toggle delay is more than 30uS.

The udelay() is a busy wait loop (kind of sleep) call . There might be some higher priority task taken up by CPU.?
Can you please check if any higher priority task is running during this time?

Hi Shane,
we haven’t run any tasks from our side apart from this. If it so it should be default system tasks only running behind this. But how we can check which tasks interrupting this. Please suggest a way to find that.

And moreover we have tried with kernel timers instead of using delay() APIs but still its not resolving.

Is there any way to set priority for kernel modules?

Could you try below.

  1. Add isolcpus=1 to extlinux.conf and reboot the system
  2. Manually schedule the application to the core:
    $ taskset 0x1 <USER_APPLICATION> &

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.