How to query vblank count or get notification of vblank interrupt?

Just wondering if there is any way to receive a callback in C/C++ code when the vblank interval occurs. Or alternatively, is it possible to query the current count of vblanks?

Thanks!

Do you men the camera output?
In current driver design don’t support it.

No, I mean on the HDMI output (or DisplayPort)

Are you using DRM based sample code?

I’m willing to use anything that can run in user space. I am creating an application, not a driver or anything that runs in kernel space. What is the “DRM based sample code” ?

There are multiple of graphic applications.

Some applications are based on DRM-KMS to work. Such application does not need window manager to help and they can run.

https://www.kernel.org/doc/html/v4.15/gpu/drm-kms.html

And some other kind of application requires to use window manager. Make it more easier to understand, if your graphic application requires to have “export DISPLAY=:0” before running it, then it is based on X11, which is managed by gdm window manager.

DRM based sample may be able to listen to the flip callback, but X11 based may not.

I don’t know what is your purpose.

Kernel side would handle the the vblank event and theoretically, it is just the 1/fps of the display mode.
This kind of info is not able to get in userspace app. Need to enable trace in kernel driver to read out.

If you are debugging some latency issue, then you need to tell what kind of graphic application you are using. Otherwise, I cannot help.

My application is rendering realtime video. For example, rendering a 60fps video on a 60fps display.

It is important to know whether or not the application is keeping up with the display device. Knowing how many frames the display device has shown is important. If for example the application does not deliver a frame on time, the display will show the same frame for two frame cycles, and the application should skip the next frame of video to stay in sync with the display.

Using high resolution system timers to determine how much time has passed during playback helps solve this problem but it is not as precise as a timer that is based on the device’s frame count. System timers are susceptible to jitter and you will find that they do not increment exactly 1/60th of a frame every time around your rendering loop. This is why I would like to construct a timer based off of timing data (vertical refresh counter) from the display device itself.

So what is the exact kind of application you are running…?? As I said, the display vblank is the hardware behavior, so only enabling the trace in kernel side will know that.

For the sake of this discussion just assume I am writing the basic nvgears application and I want to get a precise measurement if the display vblank count after every call to swapbuffers

Is there anything I could add to the nvgears example that would get a count of the vertical retrace counter from the hardware?

Hi,

If you use default “gears” from GL app, then the libraries between your app and the kernel are not open source, not able to add print from it. You can only check the interval between of swapbuffer in your app.

As for hardware side, you can check the tegra_dc_ext_flip called in display controller (dc) driver in kernel.

Is there any way I could check tegra_dc_ext_flip from a user mode program? would I have to create some kind of kernel device driver or something?

No, the code and driver is already there. But you may need to add some print function in kernel, rebuild the kernel so that you can check the timestamp.

If your true problem is you never tried any linux kernel work before, then I can share some basic tutorial.

Yes please share a basic tutorial that would be awesome. It sounds like if I modify the kernel with an additional function, the user space program will be able to request this vblank count from my modified kernel? Thanks again!

Hi,

Actually, this depends on the case you are using.

For example, if your case is just “gears” from GL sample, then the intermediate layers of the whole graphic pipeline, I mean from the application to the screen, are not open-source. Only the screen side, which is handled by kernel, is open source.

Due to missing of those intermediate layers, you cannot really “request it from your userspace program”, but you can see when does the flip function gets called in kernel.

Honestly, some users’ tearing issue is investigated by us but not themselves because those drivers are not open source and it is unlikely to check on end users’ side.

As for the jetson’s linux kernel:

You can download the kernel here.

And follow this page to know how to build it.

https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/kernel_custom.html#

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