2 * Copyright © 2013 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
36 #include "gem-interrupts.h"
39 static long long debugfs_read(void)
44 sprintf(buf
, "%s/i915_gem_interrupt", debugfs_dri_path
);
49 len
= read(fd
, buf
, sizeof(buf
)-1);
57 b
= strstr(buf
, "Interrupts received:");
61 return strtoull(b
+ sizeof("Interrupts received:"), 0, 0);
64 static long long procfs_read(void)
68 unsigned long long val
;
70 /* 44: 51 42446 0 0 PCI-MSI-edge i915*/
71 fd
= open("/proc/interrupts", 0);
75 len
= read(fd
, buf
, sizeof(buf
)-1);
83 b
= strstr(buf
, "i915");
96 val
+= strtoull(b
, &b
, 0);
102 static long long interrupts_read(void)
106 val
= debugfs_read();
112 int gem_interrupts_init(struct gem_interrupts
*irqs
)
114 memset(irqs
, 0, sizeof(*irqs
));
116 irqs
->fd
= perf_igfx_open(I915_PMU_INTERRUPTS
);
117 if (irqs
->fd
< 0 && interrupts_read() < 0)
118 irqs
->error
= ENODEV
;
123 int gem_interrupts_update(struct gem_interrupts
*irqs
)
133 ret
= interrupts_read();
135 return irqs
->error
= ENODEV
;
141 if (read(irqs
->fd
, data
, sizeof(data
)) < 0)
142 return irqs
->error
= errno
;
147 update
= irqs
->last_count
== 0;
148 irqs
->last_count
= irqs
->count
;
150 irqs
->delta
= irqs
->count
- irqs
->last_count
;
151 return update
? EAGAIN
: 0;