@Moderator I think I might have found the problem. This portion of the code:
https://gitlab.com/voxl-public/voxl-sdk/services/voxl-cpu-monitor/-/blob/master/server/voxl-cpu-monitor.c?ref_type=heads#L958
This is reading the /sys/class/kgsl/kgsl-3d0/gpubusy file contents into a 15 byte buffer. The problem is the contents of the file are 15 bytes exactly, so when the sscanf is called, it is pulling the contents extending past the 15th byte in memory.
I updated it to be a 16-byte buffer, zeroing out the 16th byte, and still reading only 15-bytes, and it is giving a proper gpu utilization percentage now, matching what is in the /sys/class/kgsl/kgsl-3d0/gpubusy and /sys/class/kgsl/kgsl-3d0/gpu_busy_percentage files.
Name Freq (MHz) Temp (C) Util (%)
-----------------------------------
cpu0 691.2 76.8 24.55
cpu1 691.2 76.0 17.78
cpu2 691.2 76.0 16.55
cpu3 691.2 76.8 17.34
cpu4 1286.4 76.8 1.74
cpu5 1286.4 79.9 33.74
cpu6 1286.4 76.8 0.58
cpu7 844.8 77.2 0.00
Total 77.0 14.04
10s avg 14.53
-----------------------------------
small cores only 19.06
big cores only 9.02
-----------------------------------
GPU 587.0 77.6 39.16
GPU 10s avg 38.52
-----------------------------------
memory temp: 79.2 C
memory used: 2930/7671 MB
-----------------------------------
Flags
CPU freq scaling mode: auto
Standby Not Active
-----------------------------------
$ cat /sys/class/kgsl/kgsl-3d0/gpubusy
418136 1034679
$ cat /sys/class/kgsl/kgsl-3d0/gpu_busy_percentage
40 %
// gets gpu busy value
static float _get_gpu_busy()
{
fflush(stdout);
float gpu_busy[2]; // stores busy values
float gpu_busy_ret = 0;
char buf[16];
int fd, ret;
buf[15] = 0;
fd = open(SYSTEM_GPU_BUSY_COUNTER, O_RDONLY);
if(fd<0){
perror("ERROR failed to open gpu busy counter for reading");
return 0;
}
ret = read(fd, buf, sizeof(buf)-1);
if(ret<1){
perror("ERROR failed to read gpu busy counter");
close(fd);
return 0;
}
sscanf(buf, "%f %f", &gpu_busy[0], &gpu_busy[1]);
if(en_debug){
printf("gpu busy: %f %f\n", (double)gpu_busy[0], (double)gpu_busy[1]);
}
if (gpu_busy[1] == 0){ // check if gpu_busy[1] is 0 to avoid divide by 0 errors
close(fd);
return 0;
}
gpu_busy_ret = (gpu_busy[0] / gpu_busy[1])*(float)100;
close(fd);
return gpu_busy_ret;
}