mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-12 10:26:12 +00:00
overlay: Read interrupts from perf
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
parent
14614060b8
commit
d58aed18ee
@ -32,50 +32,82 @@
|
|||||||
|
|
||||||
#include "gem-interrupts.h"
|
#include "gem-interrupts.h"
|
||||||
#include "debugfs.h"
|
#include "debugfs.h"
|
||||||
|
#include "perf.h"
|
||||||
|
|
||||||
int gem_interrupts_init(struct gem_interrupts *irqs)
|
static int perf_open(void)
|
||||||
|
{
|
||||||
|
struct perf_event_attr attr;
|
||||||
|
|
||||||
|
memset(&attr, 0, sizeof (attr));
|
||||||
|
|
||||||
|
attr.type = i915_type_id();
|
||||||
|
if (attr.type == 0)
|
||||||
|
return -ENOENT;
|
||||||
|
attr.config = I915_PERF_INTERRUPTS;
|
||||||
|
|
||||||
|
return perf_event_open(&attr, -1, 0, -1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int debugfs_open(void)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
|
|
||||||
memset(irqs, 0, sizeof(*irqs));
|
|
||||||
|
|
||||||
sprintf(buf, "%s/i915_gem_interrupt", debugfs_dri_path);
|
sprintf(buf, "%s/i915_gem_interrupt", debugfs_dri_path);
|
||||||
if (stat(buf, &st))
|
if (stat(buf, &st))
|
||||||
return irqs->error = errno;
|
return errno;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gem_interrupts_init(struct gem_interrupts *irqs)
|
||||||
|
{
|
||||||
|
memset(irqs, 0, sizeof(*irqs));
|
||||||
|
|
||||||
|
irqs->fd = perf_open();
|
||||||
|
if (irqs->fd < 0)
|
||||||
|
irqs->error = debugfs_open();
|
||||||
|
|
||||||
|
return irqs->error;
|
||||||
|
}
|
||||||
|
|
||||||
int gem_interrupts_update(struct gem_interrupts *irqs)
|
int gem_interrupts_update(struct gem_interrupts *irqs)
|
||||||
{
|
{
|
||||||
char buf[8192], *b;
|
uint64_t val;
|
||||||
int fd, len;
|
int update;
|
||||||
|
|
||||||
if (irqs->error)
|
if (irqs->error)
|
||||||
return irqs->error;
|
return irqs->error;
|
||||||
|
|
||||||
sprintf(buf, "%s/i915_gem_interrupt", debugfs_dri_path);
|
if (irqs->fd < 0) {
|
||||||
fd = open(buf, 0);
|
char buf[8192], *b;
|
||||||
if (fd < 0)
|
int fd, len;
|
||||||
return irqs->error = errno;
|
|
||||||
len = read(fd, buf, sizeof(buf)-1);
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (len < 0)
|
sprintf(buf, "%s/i915_gem_interrupt", debugfs_dri_path);
|
||||||
return irqs->error = errno;
|
fd = open(buf, 0);
|
||||||
|
if (fd < 0)
|
||||||
|
return irqs->error = errno;
|
||||||
|
len = read(fd, buf, sizeof(buf)-1);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
buf[len] = '\0';
|
if (len < 0)
|
||||||
|
return irqs->error = errno;
|
||||||
|
|
||||||
b = strstr(buf, "Interrupts received:");
|
buf[len] = '\0';
|
||||||
if (b == NULL)
|
|
||||||
return irqs->error = ENOENT;
|
|
||||||
|
|
||||||
fd = irqs->last_count == 0;
|
b = strstr(buf, "Interrupts received:");
|
||||||
|
if (b == NULL)
|
||||||
|
return irqs->error = ENOENT;
|
||||||
|
|
||||||
|
val = strtoull(b + sizeof("Interrupts received:"), 0, 0);
|
||||||
|
} else {
|
||||||
|
if (read(irqs->fd, &val, sizeof(val)) < 0)
|
||||||
|
return irqs->error = errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
update = irqs->last_count == 0;
|
||||||
irqs->last_count = irqs->count;
|
irqs->last_count = irqs->count;
|
||||||
irqs->count = strtoull(b + sizeof("Interrupts received:"), 0, 0);
|
irqs->count = val;
|
||||||
irqs->delta = irqs->count - irqs->last_count;
|
irqs->delta = irqs->count - irqs->last_count;
|
||||||
|
return update ? EAGAIN : 0;
|
||||||
return fd ? EAGAIN : 0;
|
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
struct gem_interrupts {
|
struct gem_interrupts {
|
||||||
long unsigned last_count, count, delta;
|
long unsigned last_count, count, delta;
|
||||||
int error;
|
int error;
|
||||||
|
int fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
int gem_interrupts_init(struct gem_interrupts *irqs);
|
int gem_interrupts_init(struct gem_interrupts *irqs);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user