diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2013-08-18 16:42:25 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2013-08-18 16:53:18 +0100 |
commit | de2c97b27fa176deec12a6277448397fcc246e47 (patch) | |
tree | 864807fcce4ca870c2c595cb782392c864f46bfa /overlay/gpu-freq.c | |
parent | 6a64ee938b90a2d27342aa42ba1d2d90da40dc7b (diff) |
overlay: Add GPU frequency
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'overlay/gpu-freq.c')
-rw-r--r-- | overlay/gpu-freq.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/overlay/gpu-freq.c b/overlay/gpu-freq.c new file mode 100644 index 000000000..f0285a5fa --- /dev/null +++ b/overlay/gpu-freq.c @@ -0,0 +1,75 @@ +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <stdio.h> + +#include "gpu-freq.h" + +int gpu_freq_init(struct gpu_freq *gf) +{ + char buf[4096], *s; + int fd, len = -1; + + memset(gf, 0, sizeof(*gf)); + + fd = open("/sys/kernel/debug/dri/0/i915_cur_delayinfo", 0); + if (fd < 0) + return errno; + + len = read(fd, buf, sizeof(buf)-1); + close(fd); + if (len < 0) + return EIO; + + buf[len] = '\0'; + + s = strstr(buf, "(RPN)"); + if (s == NULL) + return EIO; + sscanf(s, "(RPN) frequency: %dMHz", &gf->rpn); + + s = strstr(s, "(RP1)"); + if (s == NULL) + return EIO; + sscanf(s, "(RP1) frequency: %dMHz", &gf->rp1); + + s = strstr(s, "(RP0)"); + if (s == NULL) + return EIO; + sscanf(s, "(RP0) frequency: %dMHz", &gf->rp0); + + s = strstr(s, "Max"); + if (s == NULL) + return EIO; + sscanf(s, "Max overclocked frequency: %dMHz", &gf->max); + + return 0; +} + +int gpu_freq_update(struct gpu_freq *gf) +{ + char buf[4096], *s; + int fd, len = -1; + + fd = open("/sys/kernel/debug/dri/0/i915_cur_delayinfo", 0); + if (fd < 0) + return errno; + + len = read(fd, buf, sizeof(buf)-1); + close(fd); + if (len < 0) + return EIO; + + buf[len] = '\0'; + + s = strstr(buf, "RPNSWREQ:"); + if (s) + sscanf(s, "RPNSWREQ: %dMHz", &gf->request); + + s = strstr(buf, "CAGF:"); + if (s) + sscanf(s, "CAGF: %dMHz", &gf->current); + + return 0; +} |