0

I am trying to find a variable/some metric that can help me compute the actual number of frames rendered in the Midgard GPU driver in the Linux kernel.

While testing my algorithms on a user-level program, I used a system call (shown below) that got the frame count from SurfaceFlinger and stored this value to a file, which I later read in the user-level program.

system("setsid adb shell service call SurfaceFlinger 1013 | \
   grep -o -E \\([a-fA-F0-9]+\\ \\)> frames.txt");

Note: I'm trying to create a dvfs governor that uses this information but I can't seem to find a way to access it in the Midgard driver. I only have access to the 'utilization' of the GPU cores, but this doesn't always match the frame count. Any ideas on how to go about this?

Bob Dalgleish
  • 8,167
  • 4
  • 32
  • 42

2 Answers2

0

For Android, you can monitor the frame completion fences which are used for buffer exchange between components. More info here:

However note that this is a class of use cases which don't have "frames" in the traditional sense.

  • Rendering to VR and AR goggles uses front-buffer rendering where there will be no buffer swap and therefore no completion fence.
  • OpenCL or GPU compute use cases tend to render back to arbitrary memory, not a displayable frame, so similarly you may not get frames there either.
solidpixel
  • 10,688
  • 1
  • 20
  • 33
  • Thanks! This actually helps. I've nailed down a kbase_fence_wait_callback function and just by doing a number of printk's I can see its called more when there's more action on the screen. I'll proceed to establish its relation to frames then use it if they match or have a predictable relationship – mwauras Apr 18 '19 at 15:34
0

So I've been digging and I finally found how the total number of frames (since boot) can be calculated from the kernel. This is done by monitoring sync fences, as suggested by @solidpixel above. First, it's important to understand the types of fences created by the buffer consumer in question. For Android, the buffer consumer is the Hardware Composer - HWC. The HWC creates a number of fences, but the one relevant to frames rendered is the 'display' fence. So you can check the name of each fence being created, and if it matches 'display', this is what you want to count. Only 1 display fence is created per frame, so counting how many times display fences are created will give you the number of frames.