perf pmu driver for OA counters
Subsystems (4)
cover perf pmu driver for OA counters
This is still a work in progress, but as I've started to get some useful results with some simple igt tools and integration into Mesa too, others could be interested in this proof-of-concept perf pmu driver to forward Haswell Observation Architecture counters to userspace...
This has some similarities to the pmu driver Chris wrote back in September last year, except that in this case the driver is configuring a unit of the gpu to write out periodic counter snapshots to a circular buffer that then get forwarded to userspace as perf samples, instead of using hrtimer based sampling. I think if there is general agreement on leveraging perf pmus for gpu metrics that we'll likely also want some separate hrtimer based pmus later too.
As well as this RFC, I also recently sent an RFC to the LKML since I wanted to see if the core perf maintainers would be happy with us exposing device metrics via perf pmus (currently perf is very cpu centric). Initial feedback seems positive and receptive to the idea which is reassuring:
https://lkml.org/lkml/2014/10/22/462
When I started looking at this, it wasn't entirely clear that perf would be a good fit for covering the tooling and Mesa use cases we have and in particular there was a big question mark over how the permission model would work considering that GL apps shouldn't need to run as root to use INTEL_performance_query. Having got something working though I do feel much more confident now that it can work for us to build on perf infrastructure here.
For the permission issue, the current driver depends on a small change to kernel/events/core so it can flag that its pmu relates to a device, as opposed to the cpu which lets the driver also handle its own authentication. In this case a drm file descriptor and context id can be passed as part of the config when opening an event so it's only possible to profile a specific context that you have a corresponding open drm file descriptor for. You have to be running as root to profile across all contexts.
For reference the PRM for these counters can be found here:
https://01.org/linuxgraphics/sites/default/files/documentation/
observability_performance_counters_haswell.pdf
To test the driver out I have two igt tools; intel_oacounter_top_pmu, which is something like intel_gpu_top but based on our observability counters, and intel_gpu_trace_pmu which gives me a way to log all of the pmu sample data in detail in a json format that can be visualised using the chrome://tracing ui. These tools can be found here:
https://github.com/rib/intel-gpu-tools/tree/wip/rib/intel-i915-oa-pmu
I've also been experimenting with using the driver from Mesa, and that can be seen here:
https://github.com/rib/mesa/tree/wip/rib/i915_oa_perf
Currently the mesa driver is limited to only using the i915_oa driver as a way to configure the OA unit and still needs updating to also collect periodic counter snapshots for detecting counter wrapping.
For anyone interested in an introduction to how the lower level perf interface works this may be a useful reference:
http://web.eece.maine.edu/~vweaver/projects/perf_events/
perf_event_open.html
For convenience these patches can also be pulled from here:
https://github.com/rib/linux/tree/wip/rib/i915_oa_perf
Regards,
- Robert
Robert Bragg (4):
perf: export perf_event_overflow
perf: Add PERF_PMU_CAP_IS_DEVICE flag drm/i915: add api to pin/unpin context state drm/i915: Expose PMU for Observation Architecture
drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/i915_dma.c | 2 + drivers/gpu/drm/i915/i915_drv.h | 37 ++ drivers/gpu/drm/i915/i915_gem_context.c | 30 +- drivers/gpu/drm/i915/i915_oa_perf.c | 649 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_reg.h | 68 ++++ include/linux/perf_event.h | 1 + include/uapi/drm/i915_drm.h | 21 ++ kernel/events/core.c | 40 +- 9 files changed, 834 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/i915/i915_oa_perf.c
Signature · 6 lines
2.1.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 1/4 perf: export perf_event_overflow
To support pmu drivers in loadable modules, such as the i915 driver
--- kernel/events/core.c | 1 + 1 file changed, 1 insertion(+)
kernel/events/core.c +1 -0
@@ -5640,6 +5640,7 @@ int perf_event_overflow(struct perf_event *event, {return __perf_event_overflow (event,1 , data, regs); } +EXPORT_SYMBOL_GPL (perf_event_overflow);/* * Generic software event infrastructure
Signature · 6 lines
2.1.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 2/4 perf: Add PERF_PMU_CAP_IS_DEVICE flag
In reply to Robert BraggThe PERF_PMU_CAP_IS_DEVICE flag provides pmu drivers a way to declare that they only monitor device specific metrics and since they don't monitor any cpu metrics then perf should bypass any cpu centric security checks, as well as disallow cpu centric attributes.
--- include/linux/perf_event.h | 1 + kernel/events/core.c | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-)
include/linux/perf_event.h +1 -0
@@ -171,6 +171,7 @@ struct perf_event;* pmu::capabilities flags */ #define PERF_PMU_CAP_NO_INTERRUPT 0x01 +#define PERF_PMU_CAP_IS_DEVICE 0x02/** * struct pmu - generic performance monitoring unit
kernel/events/core.c +33 -6
@@ -3209,7 +3209,8 @@ find_get_context(struct pmu *pmu, struct task_struct *task, int cpu)if (!task) {/* Must be root to operate on a CPU event: */ -if (perf_paranoid_cpu () && !capable (CAP_SYS_ADMIN )) +if (!(pmu->capabilities &PERF_PMU_CAP_IS_DEVICE ) && +perf_paranoid_cpu () && !capable (CAP_SYS_ADMIN ))return ERR_PTR (-EACCES );/*
@@ -7253,11 +7254,6 @@ SYSCALL_DEFINE5(perf_event_open,if (err)return err; -if (!attr.exclude_kernel) { -if (perf_paranoid_kernel () && !capable (CAP_SYS_ADMIN )) -return -EACCES ; - } -if (attr.freq) {if (attr.sample_freq > sysctl_perf_event_sample_rate)return -EINVAL ;
@@ -7316,6 +7312,37 @@ SYSCALL_DEFINE5(perf_event_open, goto err_cpus; } +if (event->pmu->capabilities &PERF_PMU_CAP_IS_DEVICE ) { + +/* Don't allow cpu centric attributes... */ +if (event->attr.exclude_user || + event->attr.exclude_callchain_user || + event->attr.exclude_kernel || + event->attr.exclude_callchain_kernel || + event->attr.exclude_hv || + event->attr.exclude_idle || + event->attr.exclude_host || + event->attr.exclude_guest || + event->attr.mmap || + event->attr.comm || + event->attr.task) +return -EINVAL ; + +if (attr.sample_type & + (PERF_SAMPLE_IP | +PERF_SAMPLE_TID | +PERF_SAMPLE_ADDR | +PERF_SAMPLE_CALLCHAIN | +PERF_SAMPLE_CPU | +PERF_SAMPLE_BRANCH_STACK | +PERF_SAMPLE_REGS_USER | +PERF_SAMPLE_STACK_USER )) +return -EINVAL ; + }else if (!attr.exclude_kernel) { +if (perf_paranoid_kernel () && !capable (CAP_SYS_ADMIN )) +return -EACCES ; + } +if (flags &PERF_FLAG_PID_CGROUP ) { err =perf_cgroup_connect (pid, event, &attr, group_leader);if (err) {
Signature · 6 lines
2.1.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 3/4 drm/i915: add api to pin/unpin context state
In reply to Robert BraggThis adds i915_gem_context_pin/unpin_state functions so that code outside i915_gem_context.c can pin/unpin a context without duplicating knowledge about the alignment constraints.
--- drivers/gpu/drm/i915/i915_drv.h | 4 ++++ drivers/gpu/drm/i915/i915_gem_context.c | 30 +++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -2675,6 +2675,10 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,int i915_gem_context_destroy_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int i915_gem_context_pin_state (struct drm_device *dev, +struct intel_context *ctx); +void i915_gem_context_unpin_state (struct intel_context *ctx); +/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,
drivers/gpu/drm/i915/i915_gem_context.c +21 -9
@@ -132,6 +132,20 @@ static int get_context_size(struct drm_device *dev)return ret; } +int i915_gem_context_pin_state (struct drm_device *dev, +struct intel_context *ctx) +{ +BUG_ON (!mutex_is_locked (&dev->struct_mutex)); + +return i915_gem_obj_ggtt_pin (ctx->legacy_hw_ctx.rcs_state, +get_context_alignment (dev),0 ); +} + +void i915_gem_context_unpin_state (struct intel_context *ctx) +{ +i915_gem_object_ggtt_unpin (ctx->legacy_hw_ctx.rcs_state); +} +void i915_gem_context_free (struct kref *ctx_ref) { struct intel_context *ctx = container_of(ctx_ref,
@@ -253,8 +267,7 @@ i915_gem_create_context(struct drm_device *dev,* be available. To avoid this we always pin the default * context. */ - ret =i915_gem_obj_ggtt_pin (ctx->legacy_hw_ctx.rcs_state, -get_context_alignment (dev),0 ); + ret =i915_gem_context_pin_state (dev, ctx);if (ret) {DRM_DEBUG_DRIVER ("Couldn't pin %d\n" , ret); goto err_destroy;
@@ -278,7 +291,7 @@ i915_gem_create_context(struct drm_device *dev, err_unpin:if (is_global_default_ctx && ctx->legacy_hw_ctx.rcs_state) -i915_gem_object_ggtt_unpin (ctx->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (ctx); err_destroy:i915_gem_context_unreference (ctx);return ERR_PTR (ret);
@@ -375,12 +388,12 @@ void i915_gem_context_fini(struct drm_device *dev)if (dev_priv->ring[RCS ].last_context == dctx) {/* Fake switch to NULL context */ WARN_ON (dctx->legacy_hw_ctx.rcs_state->active); -i915_gem_object_ggtt_unpin (dctx->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (dctx);i915_gem_context_unreference (dctx); dev_priv->ring[RCS ].last_context =NULL ; } -i915_gem_object_ggtt_unpin (dctx->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (dctx); }for (i =0 ; i <I915_NUM_RINGS ; i++) {
@@ -534,8 +547,7 @@ static int do_switch(struct intel_engine_cs *ring,/* Trying to pin first makes error handling easier. */ if (ring == &dev_priv->ring[RCS ]) { - ret =i915_gem_obj_ggtt_pin (to->legacy_hw_ctx.rcs_state, -get_context_alignment (ring->dev),0 ); + ret =i915_gem_context_pin_state (ring->dev, to);if (ret)return ret; }
@@ -616,7 +628,7 @@ static int do_switch(struct intel_engine_cs *ring,BUG_ON (from->legacy_hw_ctx.rcs_state->ring != ring);/* obj is kept alive until the next request by its active ref */ -i915_gem_object_ggtt_unpin (from->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (from);i915_gem_context_unreference (from); }
@@ -643,7 +655,7 @@ done: unpin_out:if (ring->id ==RCS ) -i915_gem_object_ggtt_unpin (to->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (to);return ret; }
Signature · 6 lines
2.1.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC PATCH 3/4] drm/i915: add api to pin/unpin context state
Quoted 5 lines · Robert Bragg
This adds i915_gem_context_pin/unpin_state functions so that code outside
i915_gem_context.ccan pin/unpin a context without duplicating knowledge about the alignment constraints.Signed-off-by Robert Bragg <[email protected]>
At first I've thought this is ok to get going, but then I pondered a bit more. We unpin ctx objects from the shrinker, and this here torpedos that a bit. And I think the proper implementation isn't more fuzz that this here:
When pinning the context we call an OA function to update OA state. When OA notices that this is the buffer it cares about (for filtered mode) and that it has moved, it updates OA hw/sw state. I don't think this can race since a ctx can only be moved when it's not actively used by the gpu, so I think we should be able to do this. Also unbinding ctxs is a fairly last-resort kind of thing, so even when this requires a stall (maybe OA needs to be stopped/restarted) it should still be ok.
Or do I miss something and this is too much fuzz?
-Daniel
Quoted 114 lines
--- drivers/gpu/drm/i915/i915_drv.h | 4 ++++ drivers/gpu/drm/i915/i915_gem_context.c | 30 +++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-)drivers/gpu/drm/i915/i915_drv.h +4
-0@@ -2675,6 +2675,10 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,int i915_gem_context_destroy_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int i915_gem_context_pin_state (struct drm_device *dev, +struct intel_context *ctx); +void i915_gem_context_unpin_state (struct intel_context *ctx); +/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,drivers/gpu/drm/i915/i915_gem_context.c +21
-9@@ -132,6 +132,20 @@ static int get_context_size(struct drm_device *dev)return ret; } +int i915_gem_context_pin_state (struct drm_device *dev, +struct intel_context *ctx) +{ +BUG_ON (!mutex_is_locked (&dev->struct_mutex)); + +return i915_gem_obj_ggtt_pin (ctx->legacy_hw_ctx.rcs_state, +get_context_alignment (dev),0 ); +} + +void i915_gem_context_unpin_state (struct intel_context *ctx) +{ +i915_gem_object_ggtt_unpin (ctx->legacy_hw_ctx.rcs_state); +} +void i915_gem_context_free (struct kref *ctx_ref) { struct intel_context *ctx = container_of(ctx_ref,@@ -253,8 +267,7 @@ i915_gem_create_context(struct drm_device *dev,* be available. To avoid this we always pin the default * context. */ - ret =i915_gem_obj_ggtt_pin (ctx->legacy_hw_ctx.rcs_state, -get_context_alignment (dev),0 ); + ret =i915_gem_context_pin_state (dev, ctx);if (ret) {DRM_DEBUG_DRIVER ("Couldn't pin %d\n" , ret); goto err_destroy;@@ -278,7 +291,7 @@ i915_gem_create_context(struct drm_device *dev, err_unpin:if (is_global_default_ctx && ctx->legacy_hw_ctx.rcs_state) -i915_gem_object_ggtt_unpin (ctx->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (ctx); err_destroy:i915_gem_context_unreference (ctx);return ERR_PTR (ret);@@ -375,12 +388,12 @@ void i915_gem_context_fini(struct drm_device *dev)if (dev_priv->ring[RCS ].last_context == dctx) {/* Fake switch to NULL context */ WARN_ON (dctx->legacy_hw_ctx.rcs_state->active); -i915_gem_object_ggtt_unpin (dctx->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (dctx);i915_gem_context_unreference (dctx); dev_priv->ring[RCS ].last_context =NULL ; } -i915_gem_object_ggtt_unpin (dctx->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (dctx); }for (i =0 ; i <I915_NUM_RINGS ; i++) {@@ -534,8 +547,7 @@ static int do_switch(struct intel_engine_cs *ring,/* Trying to pin first makes error handling easier. */ if (ring == &dev_priv->ring[RCS ]) { - ret =i915_gem_obj_ggtt_pin (to->legacy_hw_ctx.rcs_state, -get_context_alignment (ring->dev),0 ); + ret =i915_gem_context_pin_state (ring->dev, to);if (ret)return ret; }@@ -616,7 +628,7 @@ static int do_switch(struct intel_engine_cs *ring,BUG_ON (from->legacy_hw_ctx.rcs_state->ring != ring);/* obj is kept alive until the next request by its active ref */ -i915_gem_object_ggtt_unpin (from->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (from);i915_gem_context_unreference (from); }@@ -643,7 +655,7 @@ done: unpin_out:if (ring->id ==RCS ) -i915_gem_object_ggtt_unpin (to->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (to);return ret; }Signature · 6 lines
2.1.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC PATCH 3/4] drm/i915: add api to pin/unpin context state
Quoted 20 lines · Daniel Vetter
Quoted 5 lines · Robert Bragg
This adds i915_gem_context_pin/unpin_state functions so that code outside
i915_gem_context.ccan pin/unpin a context without duplicating knowledge about the alignment constraints.Signed-off-by Robert Bragg <[email protected]>At first I've thought this is ok to get going, but then I pondered a bit more. We unpin ctx objects from the shrinker, and this here torpedos that a bit. And I think the proper implementation isn't more fuzz that this here:
When pinning the context we call an OA function to update OA state. When OA notices that this is the buffer it cares about (for filtered mode) and that it has moved, it updates OA hw/sw state. I don't think this can race since a ctx can only be moved when it's not actively used by the gpu, so I think we should be able to do this. Also unbinding ctxs is a fairly last-resort kind of thing, so even when this requires a stall (maybe OA needs to be stopped/restarted) it should still be ok.
Quoted 2 lines
Or do I miss something and this is too much fuzz?
Yeah, this seems workable too; and seems similar to what I had in mind with the previous version I sent out to the lkml:
/* XXX: Not sure that this is really acceptable...
*
* i915_gem_context.c currently owns pinning/unpinning legacy
* context buffers and although that code has a
* get_context_alignment() func to handle a different
* constraint for gen6 we are assuming it's fixed for gen7
* here. Another option besides pinning here would be to
* instead hook into context switching and update the
* OACONTROL configuration on the fly.
*/
if (dev_priv->oa_pmu.specific_ctx) {
struct intel_context *ctx = dev_priv->oa_pmu.specific_ctx;
int ret;
ret = i915_gem_obj_ggtt_pin(ctx->legacy_hw_ctx.rcs_state,
4096, 0);
if (ret) {
DRM_DEBUG_DRIVER("Couldn't pin %d\n", ret);
ret = -EBUSY;
goto err;
}
}Incidentally; considering some initial patches that Peng Li sent me recently adding experimental Broadwell support, that also requires us to hook into the context switching to be able to insert some LRIs after the MI_SET_CONTEXT so adding some form of pre set-context hook for this too seems similar.
Thanks,
- Robert
Quoted 119 lines
-Daniel
Quoted 3 lines
--- drivers/gpu/drm/i915/i915_drv.h | 4 ++++ drivers/gpu/drm/i915/i915_gem_context.c | 30+++++++++++++++++++++---------
Review
Quoted 3 lines
2 files changed, 25 insertions(+), 9 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_drv.hdrivers/gpu/drm/i915/i915_drv.h int i915_gem_context_create_ioctl(struct
Quoted 4 lines
index 3212d62..acaf76c 100644
drivers/gpu/drm/i915/i915_drv.h +0
-0@@ -2675,6 +2675,10 @@ int i915_gem_context_create_ioctl(struct
drm_device*dev, void *data,Review
Quoted 11 lines
drivers/gpu/drm/i915/i915_drv.h +4
-0int i915_gem_context_destroy_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int i915_gem_context_pin_state (struct drm_device *dev, +struct intel_context *ctx); +void i915_gem_context_unpin_state (struct intel_context *ctx); +/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_gem_context.cQuoted 44 lines
index a5221d8..feb1a23 100644
drivers/gpu/drm/i915/i915_gem_context.c +16
-3@@ -132,6 +132,20 @@ static int get_context_size(struct drm_device *dev)return ret; } +int i915_gem_context_pin_state (struct drm_device *dev, +struct intel_context *ctx) +{ +BUG_ON (!mutex_is_locked (&dev->struct_mutex)); + +return i915_gem_obj_ggtt_pin (ctx->legacy_hw_ctx.rcs_state, +get_context_alignment (dev),0 ); +} + +void i915_gem_context_unpin_state (struct intel_context *ctx) +{ +i915_gem_object_ggtt_unpin (ctx->legacy_hw_ctx.rcs_state); +} +void i915_gem_context_free (struct kref *ctx_ref) { struct intel_context *ctx = container_of(ctx_ref,@@ -253,8 +267,7 @@ i915_gem_create_context(struct drm_device *dev,* be available. To avoid this we always pin the default * context. */ - ret =i915_gem_obj_ggtt_pin (ctx->legacy_hw_ctx.rcs_state, -get_context_alignment (dev),0 ); + ret =i915_gem_context_pin_state (dev, ctx);if (ret) {DRM_DEBUG_DRIVER ("Couldn't pin %d\n" , ret); goto err_destroy;@@ -278,7 +291,7 @@ i915_gem_create_context(struct drm_device *dev, err_unpin:if (is_global_default_ctx && ctx->legacy_hw_ctx.rcs_state) -i915_gem_object_ggtt_unpin (ctx->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (ctx); err_destroy:i915_gem_context_unreference (ctx);return ERR_PTR (ret);drivers/gpu/drm/i915/i915_gem_context.c void i915_gem_context_fini(struct drm_device *dev) · line 378
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_context.c +0
-1@@ -375,12 +388,12 @@ void i915_gem_context_fini(struct drm_device *dev)if (dev_priv->ring[RCS ].last_context == dctx) {/* Fake switch to NULL context */ WARN_ON (dctx->legacy_hw_ctx.rcs_state->active); -
i915_gem_object_ggtt_unpin(dctx->legacy_hw_ctx.rcs_state);Quoted 11 lines
drivers/gpu/drm/i915/i915_gem_context.c +2
-1+i915_gem_context_unpin_state (dctx);i915_gem_context_unreference (dctx); dev_priv->ring[RCS ].last_context =NULL ; } -i915_gem_object_ggtt_unpin (dctx->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (dctx); }for (i =0 ; i <I915_NUM_RINGS ; i++) {drivers/gpu/drm/i915/i915_gem_context.c static int do_switch(struct intel_engine_cs *ring, · line 538
Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_context.c +0
-2@@ -534,8 +547,7 @@ static int do_switch(struct intel_engine_cs *ring,/* Trying to pin first makes error handling easier. */ if (ring == &dev_priv->ring[RCS ]) { - ret = i915_gem_obj_ggtt_pin(to->legacy_hw_ctx.rcs_state, -
get_context_alignment(ring->dev), 0);drivers/gpu/drm/i915/i915_gem_context.c static int do_switch(struct intel_engine_cs *ring, · line 630
Quoted 8 lines
drivers/gpu/drm/i915/i915_gem_context.c +1
-0+ ret =i915_gem_context_pin_state (ring->dev, to);if (ret)return ret; }@@ -616,7 +628,7 @@ static int do_switch(struct intel_engine_cs *ring,BUG_ON (from->legacy_hw_ctx.rcs_state->ring != ring);/* obj is kept alive until the next request by its active ref */
Quoted 17 lines
drivers/gpu/drm/i915/i915_gem_context.c +2
-3-i915_gem_object_ggtt_unpin (from->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (from);i915_gem_context_unreference (from); }@@ -643,7 +655,7 @@ done: unpin_out:if (ring->id ==RCS ) -i915_gem_object_ggtt_unpin (to->legacy_hw_ctx.rcs_state); +i915_gem_context_unpin_state (to);return ret; } --2.1.3
Quoted 14 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 4/4 drm/i915: Expose PMU for Observation Architecture
In reply to Robert BraggGen graphics hardware can be set up to periodically write snapshots of performance counters into a circular buffer and this patch exposes that capability to userspace via the perf interface.
Only Haswell is supported currently.
--- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/i915_dma.c | 2 + drivers/gpu/drm/i915/i915_drv.h | 33 ++ drivers/gpu/drm/i915/i915_oa_perf.c | 649 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_reg.h | 68 ++++ include/uapi/drm/i915_drm.h | 21 ++ 6 files changed, 774 insertions(+) create mode 100644 drivers/gpu/drm/i915/i915_oa_perf.c
drivers/gpu/drm/i915/Makefile +1 -0
@@ -16,6 +16,7 @@ i915-y := i915_drv.o \ i915-$(CONFIG_COMPAT) += i915_ioc32.o i915-$(CONFIG_DEBUG_FS) += i915_debugfs.o +i915-$(CONFIG_PERF_EVENTS) += i915_oa_perf.o # GEM code i915-y += i915_cmd_parser.o \
drivers/gpu/drm/i915/i915_dma.c +2 -0
@@ -1792,6 +1792,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)intel_gpu_ips_init (dev_priv);intel_runtime_pm_enable (dev_priv); +i915_oa_pmu_register (dev);return 0 ;
@@ -1839,6 +1840,7 @@ int i915_driver_unload(struct drm_device *dev)return ret; } +i915_oa_pmu_unregister (dev);intel_power_domains_fini (dev_priv);intel_gpu_ips_teardown ();
drivers/gpu/drm/i915/i915_drv.h +33 -0
@@ -48,6 +48,7 @@#include <linux/hashtable.h> #include <linux/intel-iommu.h> #include <linux/kref.h> +#include <linux/perf_event.h> #include <linux/pm_qos.h> /* General customization:
@@ -1693,6 +1694,29 @@ struct drm_i915_private {uint32_t bios_vgacntr; +#ifdef CONFIG_PERF_EVENTS +struct { +struct pmu pmu; +spinlock_t lock; +struct hrtimer timer; +struct pt_regs dummy_regs; + +struct perf_event *exclusive_event; +struct intel_context *specific_ctx; + +struct { +struct kref refcount; +struct drm_i915_gem_object *obj; +u32 gtt_offset; +u8 *addr; +u32 head; +u32 tail; +int format; +int format_size; + } oa_buffer; + } oa_pmu; +#endif +/* Old dri1 support infrastructure, beware the dragons ya fools entering * here! */ struct i915_dri1_state dri1;
@@ -2773,6 +2797,15 @@ int i915_parse_cmds(struct intel_engine_cs *ring,u32 batch_start_offset, bool is_master); +/* i915_oa_perf.c */ +#ifdef CONFIG_PERF_EVENTS +extern void i915_oa_pmu_register (struct drm_device *dev); +extern void i915_oa_pmu_unregister (struct drm_device *dev); +#else +static inline void i915_oa_pmu_register (struct drm_device *dev) {} +static inline void i915_oa_pmu_unregister (struct drm_device *dev) {} +#endif +/* i915_suspend.c */ extern int i915_save_state (struct drm_device *dev);extern int i915_restore_state (struct drm_device *dev);
drivers/gpu/drm/i915/i915_oa_perf.c new file +649 -0
649 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +68 -0
80 lines not on this page · raw message
include/uapi/drm/i915_drm.h +21 -0
@@ -58,6 +58,27 @@#define I915_ERROR_UEVENT "ERROR"#define I915_RESET_UEVENT "RESET" +/** +* DOC: perf events configuration exposed by i915 through /sys/bus/event_sources/drivers/i915_oa +* +*/ +#define I915_PERF_OA_CTX_ID_MASK 0xffffffff +#define I915_PERF_OA_SINGLE_CONTEXT_ENABLE (1ULL << 32) + +#define I915_PERF_OA_FORMAT_SHIFT 33 +#define I915_PERF_OA_FORMAT_MASK (0x7ULL << 33) +#define I915_PERF_OA_FORMAT_A13_HSW (0ULL << 33) +#define I915_PERF_OA_FORMAT_A29_HSW (1ULL << 33) +#define I915_PERF_OA_FORMAT_A13_B8_C8_HSW (2ULL << 33) +#define I915_PERF_OA_FORMAT_A29_B8_C8_HSW (3ULL << 33) +#define I915_PERF_OA_FORMAT_B4_C8_HSW (4ULL << 33) +#define I915_PERF_OA_FORMAT_A45_B8_C8_HSW (5ULL << 33) +#define I915_PERF_OA_FORMAT_B4_C8_A16_HSW (6ULL << 33) +#define I915_PERF_OA_FORMAT_C4_B8_HSW (7ULL << 33) + +#define I915_PERF_OA_TIMER_EXPONENT_SHIFT 36 +#define I915_PERF_OA_TIMER_EXPONENT_MASK (0x3fULL << 36) +/* Each region is a minimum of 16k, and there are at most 255 of them. */ #define I915_NR_TEX_REGIONS 255/* table size 2k - maximum due to use
Signature · 6 lines
2.1.3 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx