summaryrefslogtreecommitdiff
path: root/overlay/gpu-freq.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2013-08-20 10:04:23 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2013-08-20 10:26:23 +0100
commit5c81cda0ff092a13c6a1eb24149e7bf98e7242fa (patch)
treed04fc37c213aed9ea124427469298f3fad3dc206 /overlay/gpu-freq.c
parentbaa5be07d6652bcd86353d25188505cb0199450a (diff)
overlay: Add graph for GPU power consumption
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'overlay/gpu-freq.c')
-rw-r--r--overlay/gpu-freq.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/overlay/gpu-freq.c b/overlay/gpu-freq.c
index 545ba781..23af1d48 100644
--- a/overlay/gpu-freq.c
+++ b/overlay/gpu-freq.c
@@ -15,37 +15,40 @@ int gpu_freq_init(struct gpu_freq *gf)
fd = open("/sys/kernel/debug/dri/0/i915_cur_delayinfo", 0);
if (fd < 0)
- return errno;
+ return gf->error = errno;
len = read(fd, buf, sizeof(buf)-1);
close(fd);
if (len < 0)
- return EIO;
+ goto err;
buf[len] = '\0';
s = strstr(buf, "(RPN)");
if (s == NULL)
- return EIO;
+ goto err;
sscanf(s, "(RPN) frequency: %dMHz", &gf->rpn);
s = strstr(s, "(RP1)");
if (s == NULL)
- return EIO;
+ goto err;
sscanf(s, "(RP1) frequency: %dMHz", &gf->rp1);
s = strstr(s, "(RP0)");
if (s == NULL)
- return EIO;
+ goto err;
sscanf(s, "(RP0) frequency: %dMHz", &gf->rp0);
s = strstr(s, "Max");
if (s == NULL)
- return EIO;
+ goto err;
sscanf(s, "Max overclocked frequency: %dMHz", &gf->max);
gf->min = gf->rpn;
return 0;
+
+err:
+ return gf->error = EIO;
}
int gpu_freq_update(struct gpu_freq *gf)
@@ -53,14 +56,17 @@ int gpu_freq_update(struct gpu_freq *gf)
char buf[4096], *s;
int fd, len = -1;
+ if (gf->error)
+ return gf->error;
+
fd = open("/sys/kernel/debug/dri/0/i915_cur_delayinfo", 0);
if (fd < 0)
- return errno;
+ return gf->error = errno;
len = read(fd, buf, sizeof(buf)-1);
close(fd);
if (len < 0)
- return EIO;
+ return gf->error = EIO;
buf[len] = '\0';