Enable Gen 7 Observation Architecture
Subsystems (3)
v3 cover Enable Gen 7 Observation Architecture
Mostly just a rebase on a more recent nightly, except for an update to how POLLIN events are reported to reduce the CPU overhead that was otherwise seen while running gputop.
The problem seen with poll was largely a fault with gputop having multiple redundant 200ms, but out-of-phase, timers tracked in its mainloop resulting in excessive poll wake ups due to timeouts. This was fixed, but still it highlighted that the per-fd code that runs after a poll wait wakes (regardless of the cause of the wake up) can easily become hot and i915 mmio reads here can quickly jump to the top of a cpu profile.
The main value of the i915-perf poll implementation is for throttling more than for having a quick notification of new data, so it works nicely to only rely on the hrtimer callback that's polling for new data to be the thing that flags POLLIN events and check for that after the wait without any mmio.
Just to plug gputop as a tool for visualising these metrics with, I'm now automatically publishing a demo of the interface via Travis to
http://gputop.github.io which is also usable with local targets if you point a browser at E.g.: http://gputop.github.io?target=localhost while you have the gputop server running. Apologies that currently the demo site on its own (not connected to real hardware) doesn't show much since it doesn't have any fake metric values to graph, though it is possible to at least browse the different platform metric sets and selecting individual counters will show the description + normalization equation. Having the web UI hosted on github hopefully lowers the bar to trying it out since it avoids needing to set up Emscripten first as a build dependency.
Regards,
- Robert
Robert Bragg (11):
drm/i915: Add i915 perf infrastructure drm/i915: rename OACONTROL GEN7_OACONTROL drm/i915: return EACCES for check_cmd() failures drm/i915: don't whitelist oacontrol in cmd parser drm/i915: Add 'render basic' Haswell OA unit config drm/i915: Enable i915 perf stream for Haswell OA unit drm/i915: advertise available metrics via sysfs drm/i915: Add dev.i915.perf_event_paranoid sysctl option drm/i915: add oa_event_min_timer_exponent sysctl drm/i915: Add more Haswell OA metric sets drm/i915: Add a kerneldoc summary for i915_perf.c
drivers/gpu/drm/i915/Makefile | 4 + drivers/gpu/drm/i915/i915_cmd_parser.c | 40 +- drivers/gpu/drm/i915/i915_drv.c | 6 + drivers/gpu/drm/i915/i915_drv.h | 157 +++ drivers/gpu/drm/i915/i915_gem_context.c | 22 +- drivers/gpu/drm/i915/i915_oa_hsw.c | 659 +++++++++++++ drivers/gpu/drm/i915/i915_oa_hsw.h | 38 + drivers/gpu/drm/i915/i915_perf.c | 1615 +++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_reg.h | 340 ++++++- drivers/gpu/drm/i915/intel_ringbuffer.c | 7 +- include/uapi/drm/i915_drm.h | 133 +++ 11 files changed, 2979 insertions(+), 42 deletions(-) create mode 100644 drivers/gpu/drm/i915/i915_oa_hsw.c create mode 100644 drivers/gpu/drm/i915/i915_oa_hsw.h create mode 100644 drivers/gpu/drm/i915/i915_perf.c
Signature · 6 lines
2.9.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 1/11 drm/i915: Add i915 perf infrastructure
Adds base i915 perf infrastructure for Gen performance metrics.
This adds a DRM_IOCTL_I915_PERF_OPEN ioctl that takes an array of uint64 properties to configure a stream of metrics and returns a new fd usable with standard VFS system calls including read() to read typed and sized records; ioctl() to enable or disable capture and poll() to wait for data.
A stream is opened something like:
uint64_t properties[] = {
/* Single context sampling */
DRM_I915_PERF_PROP_CTX_HANDLE, ctx_handle, /* Include OA reports in samples */
DRM_I915_PERF_PROP_SAMPLE_OA, true,
/* OA unit configuration */
DRM_I915_PERF_PROP_OA_METRICS_SET, metrics_set_id,
DRM_I915_PERF_PROP_OA_FORMAT, report_format,
DRM_I915_PERF_PROP_OA_EXPONENT, period_exponent,
};
struct drm_i915_perf_open_param parm = {
.flags = I915_PERF_FLAG_FD_CLOEXEC |
I915_PERF_FLAG_FD_NONBLOCK |
I915_PERF_FLAG_DISABLED,
.properties_ptr = (uint64_t)properties,
.num_properties = sizeof(properties) / 16, };
int fd = drmIoctl(drm_fd, DRM_IOCTL_I915_PERF_OPEN, ¶m);
Records read all start with a common { type, size } header with DRM_I915_PERF_RECORD_SAMPLE being of most interest. Sample records contain an extensible number of fields and it's the DRM_I915_PERF_PROP_SAMPLE_xyz properties given when opening that determine what's included in every sample.
No specific streams are supported yet so any attempt to open a stream will return an error.
--- drivers/gpu/drm/i915/Makefile | 3 + drivers/gpu/drm/i915/i915_drv.c | 6 + drivers/gpu/drm/i915/i915_drv.h | 92 +++++++++ drivers/gpu/drm/i915/i915_perf.c | 430 +++++++++++++++++++++++++++++++++++++++ include/uapi/drm/i915_drm.h | 67 ++++++ 5 files changed, 598 insertions(+) create mode 100644 drivers/gpu/drm/i915/i915_perf.c
drivers/gpu/drm/i915/Makefile +3 -0
@@ -106,6 +106,9 @@ i915-y += dvo_ch7017.o \ # virtual gpu code i915-y += i915_vgpu.o +# perf code +i915-y += i915_perf.o + ifeq ($(CONFIG_DRM_I915_GVT),y) i915-y += intel_gvt.o include $(src)/gvt/Makefile
drivers/gpu/drm/i915/i915_drv.c +6 -0
@@ -1169,6 +1169,9 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)* cannot run before the connectors are registered. */ intel_fbdev_initial_config_async (dev); + +/* Depends on sysfs having been initialized */ +i915_perf_init (dev_priv); }/**
@@ -1177,6 +1180,8 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)*/ static void i915_driver_unregister (struct drm_i915_private *dev_priv) { +i915_perf_fini (dev_priv); +i915_audio_component_cleanup (dev_priv);intel_gpu_ips_teardown ();
@@ -2578,6 +2583,7 @@ static const struct drm_ioctl_desc i915_ioctls[] = {DRM_IOCTL_DEF_DRV (I915_GEM_USERPTR , i915_gem_userptr_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (I915_GEM_CONTEXT_GETPARAM , i915_gem_context_getparam_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (I915_GEM_CONTEXT_SETPARAM , i915_gem_context_setparam_ioctl,DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(I915_PERF_OPEN, i915_perf_open_ioctl, DRM_RENDER_ALLOW), }; static struct drm_driver driver = {
drivers/gpu/drm/i915/i915_drv.h +92 -0
116 lines not on this page · raw message
drivers/gpu/drm/i915/i915_perf.c new file +430 -0
430 lines not on this page · raw message
include/uapi/drm/i915_drm.h +67 -0
85 lines not on this page · raw message
Signature · 6 lines
2.9.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 01/11] drm/i915: Add i915 perf infrastructure
Quoted 69 lines · Robert Bragg
Adds base i915 perf infrastructure for Gen performance metrics.
This adds a
DRM_IOCTL_I915_PERF_OPENioctl that takes an array of uint64 properties to configure a stream of metrics and returns a new fd usable with standard VFS system calls includingread()to read typed and sized records;ioctl()to enable or disable capture andpoll()to wait for data.A stream is opened something like:
uint64_t properties[] = { /* Single context sampling */ DRM_I915_PERF_PROP_CTX_HANDLE, ctx_handle,/* Include OA reports in samples */ DRM_I915_PERF_PROP_SAMPLE_OA, true, /* OA unit configuration */ DRM_I915_PERF_PROP_OA_METRICS_SET, metrics_set_id, DRM_I915_PERF_PROP_OA_FORMAT, report_format, DRM_I915_PERF_PROP_OA_EXPONENT, period_exponent, }; struct drm_i915_perf_open_param parm = { .flags = I915_PERF_FLAG_FD_CLOEXEC | I915_PERF_FLAG_FD_NONBLOCK | I915_PERF_FLAG_DISABLED, .properties_ptr = (uint64_t)properties, .num_properties = sizeof(properties) / 16, }; int fd = drmIoctl(drm_fd, DRM_IOCTL_I915_PERF_OPEN, ¶m);Records read all start with a common { type, size } header with
DRM_I915_PERF_RECORD_SAMPLEbeing of most interest. Sample records contain an extensible number of fields and it's theDRM_I915_PERF_PROP_SAMPLE_xyzproperties given when opening that determine what's included in every sample.No specific streams are supported yet so any attempt to open a stream will return an error.
Signed-off-by Robert Bragg <[email protected]>--- drivers/gpu/drm/i915/Makefile | 3 + drivers/gpu/drm/i915/i915_drv.c | 6 + drivers/gpu/drm/i915/i915_drv.h | 92 +++++++++ drivers/gpu/drm/i915/i915_perf.c | 430 +++++++++++++++++++++++++++++++++++++++ include/uapi/drm/i915_drm.h | 67 ++++++ 5 files changed, 598 insertions(+) create mode 100644 drivers/gpu/drm/i915/i915_perf.cdrivers/gpu/drm/i915/Makefile +3
-0@@ -106,6 +106,9 @@ i915-y += dvo_ch7017.o \ # virtual gpu code i915-y += i915_vgpu.o +# perf code +i915-y += i915_perf.o + ifeq ($(CONFIG_DRM_I915_GVT),y) i915-y += intel_gvt.o include $(src)/gvt/Makefiledrivers/gpu/drm/i915/i915_drv.c +0
-0
drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1174
Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.c +3
-0@@ -1169,6 +1169,9 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)* cannot run before the connectors are registered. */ intel_fbdev_initial_config_async (dev); + +/* Depends on sysfs having been initialized */ +i915_perf_init (dev_priv);
Then please call it i915_perf_register() and i915_perf_unregister() respectively.
drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1176
Quoted 2 lines
drivers/gpu/drm/i915/i915_drv.c +2
-0+struct { +bool initialized;
This is bogus. We simply cannot allow userspace to access internals before we set them up. As it stands you have no serialisation here, so the protect is moot.
i915_perf_init() needs to be split up into the early initialisation function to setup internals, and the i915_perf_register() function to enable userspace (with however many steps you need in between).
Quoted 75 lines
drivers/gpu/drm/i915/i915_drv.c +10
-0+struct list_head streams; + } perf; +/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */ struct { int (*execbuf_submit)(struct i915_execbuffer_params *params,@@ -3421,6 +3506,9 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,int i915_gem_context_reset_stats_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int i915_perf_open_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,@@ -3540,6 +3628,10 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,u32 batch_len, bool is_master); +/* i915_perf.c */ +extern void i915_perf_init (struct drm_i915_private *dev_priv); +extern void i915_perf_fini (struct drm_i915_private *dev_priv); +/* 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_perf.c new file +42
-0@@ -0,0 +1,430 @@ +/* +* Copyright © 2015-2016 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +* +* Authors: +* Robert Bragg <[email protected]> +*/ + +#include <linux/anon_inodes.h> +#include <linux/sizes.h> + +#include "i915_drv.h" + +struct perf_open_properties { +u32 sample_flags; + +u64 single_context:1 ; +u64 ctx_handle; +}; + +static ssize_t i915_perf_read_locked(struct i915_perf_stream *stream, + struct file *file, + char __user *buf, + size_t count,
drivers/gpu/drm/i915/i915_perf.c line 52
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c new file +10
-0+ loff_t *ppos) +{ +struct i915_perf_read_state state = { count,0 , buf }; +int ret = stream->ops->read (stream, &state); + +/* If we've successfully copied any data then reporting that +* takes precedence over any internal error status, so the +* data isn't lost +*/ +return state.read ? state.read : (ret ? ret : -EAGAIN );
return state.read ?: ret ?: -EAGAIN;
Alternatively you could follow the standard pattern for read. Dare I ask what is going to go into state that needs the obfuscation? -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 01/11] drm/i915: Add i915 perf infrastructure
Quoted 85 lines · Chris Wilson
Quoted 40 lines · Robert Bragg
Adds base i915 perf infrastructure for Gen performance metrics.
This adds a
DRM_IOCTL_I915_PERF_OPENioctl that takes an array of uint64 properties to configure a stream of metrics and returns a new fd usable with standard VFS system calls includingread()to read typed and sized records;ioctl()to enable or disable capture andpoll()to wait for data.A stream is opened something like:
uint64_t properties[] = { /* Single context sampling */ DRM_I915_PERF_PROP_CTX_HANDLE, ctx_handle,/* Include OA reports in samples */ DRM_I915_PERF_PROP_SAMPLE_OA, true, /* OA unit configuration */ DRM_I915_PERF_PROP_OA_METRICS_SET, metrics_set_id, DRM_I915_PERF_PROP_OA_FORMAT, report_format, DRM_I915_PERF_PROP_OA_EXPONENT, period_exponent, }; struct drm_i915_perf_open_param parm = { .flags = I915_PERF_FLAG_FD_CLOEXEC | I915_PERF_FLAG_FD_NONBLOCK | I915_PERF_FLAG_DISABLED, .properties_ptr = (uint64_t)properties, .num_properties = sizeof(properties) / 16, }; int fd = drmIoctl(drm_fd, DRM_IOCTL_I915_PERF_OPEN, ¶m);Records read all start with a common { type, size } header with
DRM_I915_PERF_RECORD_SAMPLEbeing of most interest. Sample records contain an extensible number of fields and it's theDRM_I915_PERF_PROP_SAMPLE_xyzproperties given when opening that determine what's included in every sample.No specific streams are supported yet so any attempt to open a stream will return an error.
Quoted 6 lines
Signed-off-by Robert Bragg <[email protected]>--- drivers/gpu/drm/i915/Makefile | 3 + drivers/gpu/drm/i915/i915_drv.c | 6 + drivers/gpu/drm/i915/i915_drv.h | 92 +++++++++ drivers/gpu/drm/i915/i915_perf.c | 430 +++++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/i915/
Quoted 5 lines
include/uapi/drm/i915_drm.h | 67 ++++++ 5 files changed, 598 insertions(+) create mode 100644 drivers/gpu/drm/i915/i915_perf.cdrivers/gpu/drm/i915/ renamed from drivers/gpu/drm/i915/Makefile +0
-0
MakefileReview
Quoted 14 lines
index 6092f0e..9a2f1f9 100644
drivers/gpu/drm/i915/Makefile +3
-0@@ -106,6 +106,9 @@ i915-y += dvo_ch7017.o \ # virtual gpu code i915-y += i915_vgpu.o +# perf code +i915-y += i915_perf.o + ifeq ($(CONFIG_DRM_I915_GVT),y) i915-y += intel_gvt.o include $(src)/gvt/Makefile(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_drv.cdrivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct
Quoted 4 lines
index 83afdd0..f5209ff 100644
drivers/gpu/drm/i915/i915_drv.c +0
-0@@ -1169,6 +1169,9 @@ static void i915_driver_register(struct
drm_i915_private*dev_priv)drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct drm_i915_private *dev_priv) · line 1174
Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.c +3
-0* cannot run before the connectors are registered. */ intel_fbdev_initial_config_async (dev); + +/* Depends on sysfs having been initialized */ +i915_perf_init (dev_priv);Then please call it
i915_perf_register()andi915_perf_unregister()respectively.
Quoted 7 lines
+ struct {
drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct · line 1175
Quoted 1 line
drivers/gpu/drm/i915/i915_drv.c +1
-0+bool initialized;This is bogus. We simply cannot allow userspace to access internals before we set them up. As it stands you have no serialisation here, so the protect is moot.
Ah, previously I was initializing in i915_driver_load() and I think it should have been synchronized by requiring a drm fd to interact with the driver. I'd need to dig in to understand why, but it was previously ok to init before i915_setup_sysfs(), so this looks like I messed up the rebase, not properly appreciating I was now initializing after being visible to userspace.
Quoted 4 lines
i915_perf_init()needs to be split up into the early initialisation function to setup internals, and thei915_perf_register()function to enable userspace (with however many steps you need in between).
I think it's probably just the sysfs bits that may need to be deferred until after i915_sysfs_init(), after drm_dev_register() where we're visible to userspace.
Quoted 98 lines
drivers/gpu/drm/i915/i915_drv.c static void i915_driver_register(struct
Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.c +3
-0+struct list_head streams; + } perf; +/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
Quoted 2 lines
struct {
int (*execbuf_submit)(structi915_execbuffer_params*params,
drivers/gpu/drm/i915/i915_drv.c int i915_gem_context_setparam_ioctl(struct
Quoted 1 line
drivers/gpu/drm/i915/i915_drv.c +0
-0@@ -3421,6 +3506,9 @@ int i915_gem_context_setparam_ioctl(struct
drm_device*dev, void *data,drivers/gpu/drm/i915/i915_drv.c int i915_gem_context_setparam_ioctl(struct · line 3506
Quoted 1 line
drivers/gpu/drm/i915/i915_drv.c +0
-0int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void*data,
drivers/gpu/drm/i915/i915_drv.c int intel_engine_cmd_parser(struct
Quoted 9 lines
drivers/gpu/drm/i915/i915_drv.c +3
-0struct drm_file *file); +int i915_perf_open_ioctl (struct drm_device *dev,void *data, +struct drm_file *file); +/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct drm_device *dev, struct i915_address_space *vm,@@ -3540,6 +3628,10 @@ int intel_engine_cmd_parser(struct
intel_engine_cs*engine,Review
Quoted 11 lines
drivers/gpu/drm/i915/i915_drv.c +4
-0u32 batch_len, bool is_master); +/* i915_perf.c */ +extern void i915_perf_init (struct drm_i915_private *dev_priv); +extern void i915_perf_fini (struct drm_i915_private *dev_priv); +/* i915_suspend.c */ extern int i915_save_state (struct drm_device *dev);extern int i915_restore_state (struct drm_device *dev);(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_perf.cdrivers/gpu/drm/i915/i915_perf.c line 4
Quoted 9 lines
new file mode 100644
index 0000000..d0ed645drivers/gpu/drm/i915/i915_perf.c new file +4
-0@@ -0,0 +1,430 @@ +/* +* Copyright © 2015-2016 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a
drivers/gpu/drm/i915/i915_perf.c line 5
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c new file +1
-0+* copy of this software and associated documentation files (the "Software"),
drivers/gpu/drm/i915/i915_perf.c line 6
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c new file +1
-0+* to deal in the Software without restriction, including without limitation
drivers/gpu/drm/i915/i915_perf.c line 7
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c new file +1
-0+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
drivers/gpu/drm/i915/i915_perf.c
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c new file +4
-0+* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next
drivers/gpu/drm/i915/i915_perf.c line 12
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c new file +1
-0+* paragraph) shall be included in all copies or substantial portions of the
drivers/gpu/drm/i915/i915_perf.c
Quoted 3 lines
drivers/gpu/drm/i915/i915_perf.c new file +3
-0+* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
drivers/gpu/drm/i915/i915_perf.c line 16
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c new file +1
-0+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
drivers/gpu/drm/i915/i915_perf.c line 17
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c new file +1
-0+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
drivers/gpu/drm/i915/i915_perf.c line 18
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c new file +1
-0+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
drivers/gpu/drm/i915/i915_perf.c line 19
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c new file +1
-0+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
drivers/gpu/drm/i915/i915_perf.c line 20
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c new file +1
-0+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
Quoted 26 lines
drivers/gpu/drm/i915/i915_perf.c new file +26
-0+* IN THE SOFTWARE. +* +* Authors: +* Robert Bragg <[email protected]> +*/ + +#include <linux/anon_inodes.h> +#include <linux/sizes.h> + +#include "i915_drv.h" + +struct perf_open_properties { +u32 sample_flags; + +u64 single_context:1 ; +u64 ctx_handle; +}; + +static ssize_t i915_perf_read_locked (struct i915_perf_stream *stream, +struct file *file, +char __user *buf, +size_t count, +loff_t *ppos) +{ +struct i915_perf_read_state state = { count,0 , buf }; +int ret = stream->ops->read (stream, &state);
Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c line 52
Quoted 6 lines
drivers/gpu/drm/i915/i915_perf.c new file +6
-0+ +/* If we've successfully copied any data then reporting that +* takes precedence over any internal error status, so the +* data isn't lost +*/ +return state.read ? state.read : (ret ? ret : -EAGAIN );return state.read ?: ret ?:
-EAGAIN;
Ah, I hadn't heard of the Elvis operator before.
Quoted 4 lines
Alternatively you could follow the standard pattern for read. Dare I ask what is going to go into state that needs the obfuscation?
I had dug around a bit when I was trying to decide how to handle the corner cases here and found some precedent for prioritize reporting any data copied over an error for a read().
I've changed the comment to give an example and a reference:
/* If we've successfully copied any data then reporting that
* takes precedence over any internal error status, so the
* data isn't lost.
*
* For example ret will be -ENOSPC whenever there is more
* buffered data than can be copied to userspace, but that's
* only interesting if we weren't able to copy some data
* because it implies the userspace buffer is too small to
* receive a single record (and we never split records). *
* Another case with ret == -EFAULT is more of a grey area
* since it would seem like bad form for userspace to ask us
* to overrun its buffer, but the user knows best:
*
* http://yarchive.net/comp/linux/partial_reads_writes.html
*/
return state.read ?: (ret ?: -EAGAIN);
Searching for another reference, I also just found the linux device drivers book talks about the same kind of convention:
http://www.makelinux.net/ldd3/chp-3-sect-7
"Both the read and write methods return a negative value if an error occurs. A return value greater than or equal to 0, instead, tells the calling program how many bytes have been successfully transferred. If some data is transferred correctly and then an error happens, the return value must be the count of bytes successfully transferred, and the error does not get reported until the next time the function is called. Implementing this convention requires, of course, that your driver remember that the error has occurred so that it can return the error status in the future."
- Robert
Quoted 5 lines
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 01/11] drm/i915: Add i915 perf infrastructure
Quoted 7 lines · Robert Bragg
On Mon, Aug 15, 2016 at 3:57 PM, Chris Wilson
Alternatively you could follow the standard pattern for read. Dare I ask what is going to go into state that needs the obfuscation?I had dug around a bit when I was trying to decide how to handle the corner cases here and found some precedent for prioritize reporting any data copied over an error for a
read().
Reporting completed bytes before the error is correct. I was referring to going between passing the return value as a mixture of state and return, when it just appears to be following the usual pattern of read(). i.e. I could find anything to support why your internal read callback required a different signature. It looks unusual, so I am expecting it to do unusual things.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 2/11 drm/i915: rename OACONTROL GEN7_OACONTROL
In reply to Robert BraggOACONTROL changes quite a bit for gen8, with some bits split out into a per-context OACTXCONTROL register. Rename now before adding more gen7 OA registers
--- drivers/gpu/drm/i915/i915_cmd_parser.c | 4 ++-- drivers/gpu/drm/i915/i915_reg.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +2 -2
@@ -446,7 +446,7 @@ static const struct drm_i915_reg_descriptor gen7_render_regs[] = {REG64 (PS_INVOCATION_COUNT ),REG64 (PS_DEPTH_COUNT ),REG64_IDX (RING_TIMESTAMP ,RENDER_RING_BASE ), -REG32 (OACONTROL ),/* Only allowed for LRI and SRM. See below. */ +REG32 (GEN7_OACONTROL ),/* Only allowed for LRI and SRM. See below. */ REG64 (MI_PREDICATE_SRC0 ),REG64 (MI_PREDICATE_SRC1 ), REG32(GEN7_3DPRIM_END_OFFSET),
@@ -1097,7 +1097,7 @@ static bool check_cmd(const struct intel_engine_cs *engine,* to the register. Hence, limit OACONTROL writes to * only MI_LOAD_REGISTER_IMM commands. */ -if (reg_addr ==i915_mmio_reg_offset (OACONTROL )) { +if (reg_addr ==i915_mmio_reg_offset (GEN7_OACONTROL )) {if (desc->cmd.value ==MI_LOAD_REGISTER_MEM ) {DRM_DEBUG_DRIVER ("CMD: Rejected LRM to OACONTROL\n" );return false;
drivers/gpu/drm/i915/i915_reg.h +1 -1
@@ -616,7 +616,7 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg)#define HSW_CS_GPR (n) _MMIO(0x2600 + (n) * 8)#define HSW_CS_GPR_UDW (n) _MMIO(0x2600 + (n) * 8 + 4) -#define OACONTROL _MMIO(0x2360) +#define GEN7_OACONTROL _MMIO(0x2360)#define _GEN7_PIPEA_DE_LOAD_SL 0x70068#define _GEN7_PIPEB_DE_LOAD_SL 0x71068
Signature · 6 lines
2.9.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 3/11 drm/i915: return EACCES for check_cmd() failures
In reply to Robert Braggcheck_cmd() is checking whether a command adheres to certain restrictions that ensure it's safe to execute within a privileged batch buffer. Returning false implies a privilege problem, not that the command is invalid.
The distinction makes the difference between allowing the buffer to be executed as an unprivileged batch buffer or returning an EINVAL error to userspace without executing anything.
In a case where userspace may want to test whether it can successfully write to a register that needs privileges the distinction may be important and an EINVAL error may be considered fatal.
In particular this is currently true for Mesa, which includes a test for whether OACONTROL can be written too, but Mesa treats any error when flushing a batch buffer as fatal, calling exit(1).
As it is currently Mesa can gracefully handle a failure to write to OACONTROL if the command parser is disabled, but if we were to remove OACONTROL from the parser's whitelist then the returned EINVAL would break Mesa applications as they attempt an OACONTROL write.
--- drivers/gpu/drm/i915/i915_cmd_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +1 -1
@@ -1261,7 +1261,7 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,if (!check_cmd (engine, desc, cmd, length, is_master, &oacontrol_set)) { - ret = -EINVAL ; + ret = -EACCES ;break ; }
Signature · 6 lines
2.9.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 03/11] drm/i915: return EACCES for check_cmd() failures
Quoted 8 lines · Robert Bragg
check_cmd()is checking whether a command adheres to certain restrictions that ensure it's safe to execute within a privileged batch buffer. Returning false implies a privilege problem, not that the command is invalid.The distinction makes the difference between allowing the buffer to be executed as an unprivileged batch buffer or returning an EINVAL error to userspace without executing anything.
Ah, but you choose to actually execute it instead. We can't allow that either.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v3 03/11] drm/i915: return EACCES for check_cmd() failures
Quoted 6 lines · Chris Wilson
Quoted 5 lines · Robert Bragg
check_cmd()is checking whether a command adheres to certain restrictions that ensure it's safe to execute within a privileged batch buffer. Returning false implies a privilege problem, not that the command is invalid.
Quoted 7 lines
Quoted 3 lines
The distinction makes the difference between allowing the buffer to be executed as an unprivileged batch buffer or returning an EINVAL error to userspace without executing anything.
Ah, but you choose to actually execute it instead. We can't allow that either.
Okey, I've got myself a bit confused over this, going in circles a few times now... Initially I took this to imply the cmd parser is not only there to enable more than the HW policy allows, and there must be some stuff we're blocking that the HW policy otherwise allows (and therefore it's bad to return -EACCES here and fallback to the HW policy).
One of the things that's confusing me is that looking at the command parser code, it looks like it's possible to bail early with an MI_BATCH_BUFFER_START command, returning -EACCES and falling back to the non-privileged HW policy. If the HW policy isn't strict enough in some cases then presumably we wouldn't ever allow an early fallback to the HW policy?
oacontrol does look to be an example where it seems a little dubious that the HW considers it ok to write from a non-privileged buffer for gen8+, but for gen7 all LRIs are considered privileged afik and the -EACCES fallback should result in an oacontrol LRI becoming a NOOP.
The change appears to be having the desired effect with respect to mesa's check for oacontrol writes failing gracefully with AMD_performance_monitor not being advertised. The fallback via -EACCES to the non-privileged HW policy seems to be NOOPing the LRIs based on running gputop to capture system-wide metrics (oacontrol enabled via i915 perf interface) and then running Mesa/GL applications that that would otherwise clobber oacontrol with test LRIs when deciding to advertise AMD_performance_monitor. This would interfere with gputop by disabling the OA unit if the LRIs were successful.
Unless I've got the wrong end of the stick, I think this is ok for Haswell.
- Robert
Quoted 5 lines
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 4/11 drm/i915: don't whitelist oacontrol in cmd parser
In reply to Robert BraggBeing able to program OACONTROL from a non-privileged batch buffer is not sufficient to be able to configure the OA unit. This was originally allowed to help enable Mesa to expose OA counters via the INTEL_performance_query extension, but the current implementation based on programming OACONTROL via a batch buffer isn't able to report useable data without a more complete OA unit configuration. Mesa handles the possibility that writes to OACONTROL may not be allowed and so only advertises the extension after explicitly testing that a write to OACONTROL succeeds. Based on this; removing OACONTROL from the whitelist should be ok for userspace.
Removing this simplifies adding a new kernel api for configuring the OA unit without needing to consider the possibility that userspace might trample on OACONTROL state which we'd like to start managing within the kernel instead. In particular running any Mesa based GL application currently results in clearing OACONTROL when initializing which would disable the capturing of metrics.
--- drivers/gpu/drm/i915/i915_cmd_parser.c | 38 ++-------------------------------- 1 file changed, 2 insertions(+), 36 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +2 -36
@@ -446,7 +446,6 @@ static const struct drm_i915_reg_descriptor gen7_render_regs[] = {REG64 (PS_INVOCATION_COUNT ),REG64 (PS_DEPTH_COUNT ),REG64_IDX (RING_TIMESTAMP ,RENDER_RING_BASE ), -REG32 (GEN7_OACONTROL ),/* Only allowed for LRI and SRM. See below. */ REG64 (MI_PREDICATE_SRC0 ),REG64 (MI_PREDICATE_SRC1 ), REG32(GEN7_3DPRIM_END_OFFSET),
@@ -1049,8 +1048,7 @@ bool intel_engine_needs_cmd_parser(struct intel_engine_cs *engine)static bool check_cmd (const struct intel_engine_cs *engine,const struct drm_i915_cmd_descriptor *desc,const u32 *cmd,u32 length, -const bool is_master, -bool *oacontrol_set) +const bool is_master) {if (desc->flags &CMD_DESC_REJECT ) {DRM_DEBUG_DRIVER ("CMD: Rejected command: 0x%08X\n" , *cmd);
@@ -1088,31 +1086,6 @@ static bool check_cmd(const struct intel_engine_cs *engine, }/* -* OACONTROL requires some special handling for -* writes. We want to make sure that any batch which -* enables OA also disables it before the end of the -* batch. The goal is to prevent one process from -* snooping on the perf data from another process. To do -* that, we need to check the value that will be written -* to the register. Hence, limit OACONTROL writes to -* only MI_LOAD_REGISTER_IMM commands. -*/ -if (reg_addr ==i915_mmio_reg_offset (GEN7_OACONTROL )) { -if (desc->cmd.value ==MI_LOAD_REGISTER_MEM ) { -DRM_DEBUG_DRIVER ("CMD: Rejected LRM to OACONTROL\n" ); -return false; - } - -if (desc->cmd.value ==MI_LOAD_REGISTER_REG ) { -DRM_DEBUG_DRIVER ("CMD: Rejected LRR to OACONTROL\n" ); -return false; - } - -if (desc->cmd.value ==MI_LOAD_REGISTER_IMM (1 )) - *oacontrol_set = (cmd[offset +1 ] !=0 ); - } - -/* * Check the value written to the register against the * allowed mask/value pair given in the whitelist entry. */
@@ -1202,7 +1175,6 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine, {u32 *cmd, *batch_base, *batch_end;struct drm_i915_cmd_descriptor default_desc = {0 }; -bool oacontrol_set = false;/* OACONTROL tracking. See check_cmd() */ int ret =0 ; batch_base = copy_batch(shadow_batch_obj, batch_obj,
@@ -1259,8 +1231,7 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,break ; } -if (!check_cmd (engine, desc, cmd, length, is_master, - &oacontrol_set)) { +if (!check_cmd (engine, desc, cmd, length, is_master)) { ret = -EACCES ;break ; }
@@ -1268,11 +1239,6 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine, cmd += length; } -if (oacontrol_set) { -DRM_DEBUG_DRIVER ("CMD: batch set OACONTROL but did not clear it\n" ); - ret = -EINVAL ; - } -if (cmd >= batch_end) {DRM_DEBUG_DRIVER ("CMD: Got to the end of the buffer w/o a BBE cmd!\n" ); ret = -EINVAL ;
Signature · 6 lines
2.9.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 5/11 drm/i915: Add 'render basic' Haswell OA unit config
In reply to Robert BraggAdds a static OA unit, MUX + B Counter configuration for basic render metrics on Haswell. This is auto generated from an XML description of metric sets, currently maintained in gputop, ref:
Quoted 2 lines
gputop-data/oa-*.xmlscripts/i915-perf-kernelgen.py
$ make -C gputop-data -f Makefile.xml SYSFS=0 WHITELIST=RenderBasic
--- drivers/gpu/drm/i915/Makefile | 3 +- drivers/gpu/drm/i915/i915_drv.h | 14 ++++ drivers/gpu/drm/i915/i915_oa_hsw.c | 132 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_oa_hsw.h | 34 ++++++++++ 4 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/i915/i915_oa_hsw.c create mode 100644 drivers/gpu/drm/i915/i915_oa_hsw.h
drivers/gpu/drm/i915/Makefile +2 -1
@@ -107,7 +107,8 @@ i915-y += dvo_ch7017.o \ i915-y += i915_vgpu.o # perf code -i915-y += i915_perf.o +i915-y += i915_perf.o \ + i915_oa_hsw.o ifeq ($(CONFIG_DRM_I915_GVT),y) i915-y += intel_gvt.o
drivers/gpu/drm/i915/i915_drv.h +14 -0
@@ -1724,6 +1724,11 @@ struct intel_wm_config {bool sprites_scaled; }; +struct i915_oa_reg { +i915_reg_t addr; +u32 value; +}; +struct i915_perf_read_state {int count;ssize_t read;
@@ -2097,6 +2102,15 @@ struct drm_i915_private {bool initialized;struct mutex lock;struct list_head streams; + +struct { +u32 metrics_set; + +const struct i915_oa_reg *mux_regs; +int mux_regs_len; +const struct i915_oa_reg *b_counter_regs; +int b_counter_regs_len; + } oa; } perf;/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
drivers/gpu/drm/i915/i915_oa_hsw.c new file +132 -0
132 lines not on this page · raw message
drivers/gpu/drm/i915/i915_oa_hsw.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Autogenerated file, DO NOT EDIT manually! +* +* Copyright (c) 2015 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +* +*/ + +#ifndef __I915_OA_HSW_H__ +#define __I915_OA_HSW_H__ + +extern int i915_oa_n_builtin_metric_sets_hsw; + +extern int i915_oa_select_metric_set_hsw (struct drm_i915_private *dev_priv); + +#endif
Signature · 6 lines
2.9.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 6/11 drm/i915: Enable i915 perf stream for Haswell OA unit
In reply to Robert BraggGen graphics hardware can be set up to periodically write snapshots of performance counters into a circular buffer via its Observation Architecture and this patch exposes that capability to userspace via the i915 perf interface.
--- drivers/gpu/drm/i915/i915_drv.h | 68 ++- drivers/gpu/drm/i915/i915_gem_context.c | 22 +- drivers/gpu/drm/i915/i915_perf.c | 977 +++++++++++++++++++++++++++++++- drivers/gpu/drm/i915/i915_reg.h | 338 +++++++++++ drivers/gpu/drm/i915/intel_ringbuffer.c | 7 +- include/uapi/drm/i915_drm.h | 70 ++- 6 files changed, 1449 insertions(+), 33 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +58 -10
@@ -1724,6 +1724,11 @@ struct intel_wm_config {bool sprites_scaled; }; +struct i915_oa_format { +u32 format; +int size; +}; +struct i915_oa_reg {i915_reg_t addr;u32 value;
@@ -1750,11 +1755,6 @@ struct i915_perf_stream_ops {*/ void (*disable)(struct i915_perf_stream *stream); -/* Return: true if any i915 perf records are ready to read() -* for this stream. -*/ -bool (*can_read)(struct i915_perf_stream *stream); -/* Call poll_wait, passing a wait queue that will be woken * once there is something ready to read() for the stream */
@@ -1764,9 +1764,7 @@ struct i915_perf_stream_ops {/* For handling a blocking read, wait until there is something * to ready to read() for the stream. E.g. wait on the same -* wait queue that would be passed to poll_wait() until -* ->can_read() returns true (if its safe to call ->can_read() -* without the i915 perf lock held). +* wait queue that would be passed to poll_wait(). */ int (*wait_unlocked)(struct i915_perf_stream *stream);
@@ -1801,11 +1799,26 @@ struct i915_perf_stream {struct list_head link;u32 sample_flags; +int sample_size;struct i915_gem_context *ctx;bool enabled; -struct i915_perf_stream_ops *ops; +const struct i915_perf_stream_ops *ops; +}; + +struct i915_oa_ops { +void (*init_oa_buffer)(struct drm_i915_private *dev_priv); +int (*enable_metric_set)(struct drm_i915_private *dev_priv); +void (*disable_metric_set)(struct drm_i915_private *dev_priv); +void (*oa_enable)(struct drm_i915_private *dev_priv); +void (*oa_disable)(struct drm_i915_private *dev_priv); +void (*update_oacontrol)(struct drm_i915_private *dev_priv); +void (*update_hw_ctx_id_locked)(struct drm_i915_private *dev_priv, +u32 ctx_id); +int (*read)(struct i915_perf_stream *stream, +struct i915_perf_read_state *read_state); +bool (*oa_buffer_is_empty)(struct drm_i915_private *dev_priv); };struct drm_i915_private {
@@ -2100,16 +2113,47 @@ struct drm_i915_private {struct {bool initialized; +struct mutex lock;struct list_head streams; +spinlock_t hook_lock; +struct { -u32 metrics_set; +struct i915_perf_stream *exclusive_stream; + +u32 specific_ctx_id; + +struct hrtimer poll_check_timer; +wait_queue_head_t poll_wq; +atomic_t pollin; + +bool periodic; +int period_exponent; +int timestamp_frequency; + +int tail_margin; + +int metrics_set;const struct i915_oa_reg *mux_regs;int mux_regs_len;const struct i915_oa_reg *b_counter_regs;int b_counter_regs_len; + +struct { +struct drm_i915_gem_object *obj; +u32 gtt_offset; +u8 *addr; +int format; +int format_size; + } oa_buffer; + +u32 gen7_latched_oastatus1; + +struct i915_oa_ops ops; +const struct i915_oa_format *oa_formats; +int n_builtin_sets; } oa; } perf;
@@ -3476,6 +3520,8 @@ struct drm_i915_gem_object * i915_gem_alloc_context_obj(struct drm_device *dev, size_t size);struct i915_gem_context *i915_gem_context_create_gvt (struct drm_device *dev); +int i915_gem_context_pin_legacy_rcs_state (struct drm_i915_private *dev_priv, +struct i915_gem_context *ctx);static inline struct i915_gem_context *i915_gem_context_lookup (struct drm_i915_file_private *file_priv,u32 id)
@@ -3522,6 +3568,8 @@ int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void *data,int i915_perf_open_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +void i915_oa_legacy_context_pin_notify (struct drm_i915_private *dev_priv, +struct i915_gem_context *ctx);/* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct drm_device *dev,
drivers/gpu/drm/i915/i915_gem_context.c +19 -3
@@ -134,6 +134,24 @@ static int get_context_size(struct drm_i915_private *dev_priv)return ret; } +int i915_gem_context_pin_legacy_rcs_state (struct drm_i915_private *dev_priv, +struct i915_gem_context *ctx) +{ +int ret; + +lockdep_assert_held (&ctx->i915->drm.struct_mutex); + + ret =i915_gem_obj_ggtt_pin (ctx->engine[RCS ].state, + ctx->ggtt_alignment, +0 ); +if (ret) +return ret; + +i915_oa_legacy_context_pin_notify (dev_priv, ctx); + +return 0 ; +} +static void i915_gem_context_clean (struct i915_gem_context *ctx) {struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
@@ -752,9 +770,7 @@ static int do_rcs_switch(struct drm_i915_gem_request *req)return 0 ;/* Trying to pin first makes error handling easier. */ - ret =i915_gem_obj_ggtt_pin (to->engine[RCS ].state, - to->ggtt_alignment, -0 ); + ret =i915_gem_context_pin_legacy_rcs_state (engine->i915, to);if (ret)return ret;
drivers/gpu/drm/i915/i915_perf.c +960 -17
1,050 lines not on this page · raw message
drivers/gpu/drm/i915/i915_reg.h +338 -0
350 lines not on this page · raw message
drivers/gpu/drm/i915/intel_ringbuffer.c +6 -1
@@ -2139,7 +2139,12 @@ static int intel_ring_context_pin(struct i915_gem_context *ctx,return 0 ;if (ce->state) { - ret =i915_gem_obj_ggtt_pin (ce->state, ctx->ggtt_alignment,0 ); +if (engine->id ==RCS ) + ret =i915_gem_context_pin_legacy_rcs_state (engine->i915, + ctx); +else + ret =i915_gem_obj_ggtt_pin (ce->state, + ctx->ggtt_alignment,0 );if (ret) goto error; }
include/uapi/drm/i915_drm.h +68 -2
104 lines not on this page · raw message
Signature · 6 lines
2.9.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit
Quoted 16 lines · Robert Bragg
int
__must_checki915_gem_evict_something(structdrm_device*dev,drivers/gpu/drm/i915/i915_gem_context.c +7
-0@@ -134,6 +134,24 @@ static int get_context_size(struct drm_i915_private *dev_priv)return ret; } +int i915_gem_context_pin_legacy_rcs_state (struct drm_i915_private *dev_priv, +struct i915_gem_context *ctx) +{ +int ret; + +lockdep_assert_held (&ctx->i915->drm.struct_mutex); +
drivers/gpu/drm/i915/i915_gem_context.c static int get_context_size(struct drm_i915_private *dev_priv) · line 153
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_context.c +10
-0+ ret =i915_gem_obj_ggtt_pin (ctx->engine[RCS ].state, + ctx->ggtt_alignment, +0 ); +if (ret) +return ret; + +i915_oa_legacy_context_pin_notify (dev_priv, ctx); + +return 0 ; +}
I am still not all at all happy with this. I hope the recent changes to do the vma tracking make it clear.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 7/11 drm/i915: advertise available metrics via sysfs
In reply to Robert BraggEach metric set is given a sysfs entry like:
/sys/class/drm/card0/metrics/<guid>/id
This allows userspace to enumerate the specific sets that are available for the current system. The 'id' file contains an unsigned integer that can be used to open the associated metric set via DRM_IOCTL_I915_PERF_OPEN. The <guid> is a globally unique ID for a specific OA unit register configuration that can be reliably used by userspace as a key to lookup corresponding counter meta data and normalization equations.
The guid registry is currently maintained as part of gputop along with the XML metric set descriptions and code generation scripts, ref:
Quoted 4 lines
gputop-data/guids.xmlscripts/update-guids.pygputop-data/oa-*.xmlscripts/i915-perf-kernelgen.py
$ make -C gputop-data -f Makefile.xml SYSFS=1 WHITELIST=RenderBasic
--- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_oa_hsw.c | 45 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_oa_hsw.h | 4 ++++ drivers/gpu/drm/i915/i915_perf.c | 19 +++++++++++++++- 4 files changed, 69 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -2114,6 +2114,8 @@ struct drm_i915_private {struct {bool initialized; +struct kobject *metrics_kobj; +struct mutex lock;struct list_head streams;
drivers/gpu/drm/i915/i915_oa_hsw.c +45 -0
54 lines not on this page · raw message
drivers/gpu/drm/i915/i915_oa_hsw.h +4 -0
@@ -31,4 +31,8 @@ extern int i915_oa_n_builtin_metric_sets_hsw;extern int i915_oa_select_metric_set_hsw (struct drm_i915_private *dev_priv); +extern int i915_perf_init_sysfs_hsw (struct drm_i915_private *dev_priv); + +extern void i915_perf_deinit_sysfs_hsw (struct drm_i915_private *dev_priv); +#endif
drivers/gpu/drm/i915/i915_perf.c +18 -1
@@ -1330,6 +1330,12 @@ void i915_perf_init(struct drm_i915_private *dev_priv)if (!IS_HASWELL (dev_priv))return ; + dev_priv->perf.metrics_kobj = +kobject_create_and_add ("metrics" , + &dev_priv->drm.primary->kdev->kobj); +if (!dev_priv->perf.metrics_kobj) +return ; +hrtimer_init (&dev_priv->perf.oa.poll_check_timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); dev_priv->perf.oa.poll_check_timer.function = oa_poll_check_timer_cb;
@@ -1357,9 +1363,15 @@ void i915_perf_init(struct drm_i915_private *dev_priv) dev_priv->perf.oa.n_builtin_sets = i915_oa_n_builtin_metric_sets_hsw; - dev_priv->perf.oa.oa_formats = hsw_oa_formats; +if (i915_perf_init_sysfs_hsw (dev_priv)) { +kobject_put (dev_priv->perf.metrics_kobj); + dev_priv->perf.metrics_kobj =NULL ; +return ; + } dev_priv->perf.initialized = true; + +return ; }void i915_perf_fini (struct drm_i915_private *dev_priv)
@@ -1367,6 +1379,11 @@ void i915_perf_fini(struct drm_i915_private *dev_priv)if (!dev_priv->perf.initialized)return ; +i915_perf_deinit_sysfs_hsw (dev_priv); + +kobject_put (dev_priv->perf.metrics_kobj); + dev_priv->perf.metrics_kobj =NULL ; + dev_priv->perf.oa.ops.init_oa_buffer =NULL ; dev_priv->perf.initialized = false;
Signature · 6 lines
2.9.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 8/11 drm/i915: Add dev.i915.perf_event_paranoid sysctl option
In reply to Robert BraggConsistent with the kernel.perf_event_paranoid sysctl option that can allow non-root users to access system wide cpu metrics, this can optionally allow non-root users to access system wide OA counter metrics from Gen graphics hardware.
--- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_perf.c | 46 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -2115,6 +2115,7 @@ struct drm_i915_private {bool initialized;struct kobject *metrics_kobj; +struct ctl_table_header *sysctl_header;struct mutex lock;struct list_head streams;
drivers/gpu/drm/i915/i915_perf.c +45 -1
76 lines not on this page · raw message
Signature · 6 lines
2.9.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 9/11 drm/i915: add oa_event_min_timer_exponent sysctl
In reply to Robert BraggThe minimal sampling period is now configurable via a dev.i915.oa_min_timer_exponent sysctl parameter.
Following the precedent set by perf, the default is the minimum that won't (on its own) exceed the default kernel.perf_event_max_sample_rate default of 100000 samples/s.
--- drivers/gpu/drm/i915/i915_perf.c | 42 ++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +30 -12
@@ -74,6 +74,23 @@ static u32 i915_perf_stream_paranoid = true;*/ #define OA_EXPONENT_MAX 31 +/* for sysctl proc_dointvec_minmax of i915_oa_min_timer_exponent */ +static int zero; +static int oa_exponent_max =OA_EXPONENT_MAX ; + +/* Theoretically we can program the OA unit to sample every 160ns but don't +* allow that by default unless root... +* +* The period is derived from the exponent as: +* +* period = 80ns * 2^(exponent + 1) +* +* Referring to perf's kernel.perf_event_max_sample_rate for a precedent +* (100000 by default); with an OA exponent of 6 we get a period of 10.240 +* microseconds - just under 100000Hz +*/ +static u32 i915_oa_min_timer_exponent =6 ; +/* XXX: beware if future OA HW adds new report formats that the current * code assumes all reports have a power-of-two size and ~(size - 1) can * be used as a mask to align the OA tail pointer.
@@ -1266,21 +1283,13 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv,return -EINVAL ; } -/* NB: The exponent represents a period as follows: -* -* 80ns * 2^(period_exponent + 1) -* -* Theoretically we can program the OA unit to sample +/* Theoretically we can program the OA unit to sample * every 160ns but don't allow that by default unless * root. -* -* Referring to perf's -* kernel.perf_event_max_sample_rate for a precedent -* (100000 by default); with an OA exponent of 6 we get -* a period of 10.240 microseconds -just under 100000Hz */ -if (value <6 && !capable (CAP_SYS_ADMIN )) { -DRM_ERROR ("Sampling period too high without root privileges\n" ); +if (value < i915_oa_min_timer_exponent && + !capable (CAP_SYS_ADMIN )) { +DRM_ERROR ("OA timer exponent too low without root privileges\n" );return -EACCES ; }
@@ -1342,6 +1351,15 @@ static struct ctl_table oa_table[] = { .mode = 0644, .proc_handler = proc_dointvec, }, + { + .procname = "oa_min_timer_exponent", + .data = &i915_oa_min_timer_exponent, + .maxlen = sizeof(i915_oa_min_timer_exponent), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &oa_exponent_max, + }, {} };
Signature · 6 lines
2.9.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 10/11 drm/i915: Add more Haswell OA metric sets
In reply to Robert BraggThis adds 'compute', 'compute extended', 'memory reads', 'memory writes' and 'sampler balance' metric sets for Haswell.
The code is auto generated from an XML description of metric sets, currently maintained in gputop, ref:
Quoted 2 lines
gputop-data/oa-*.xmlscripts/i915-perf-kernelgen.py
$ make -C gputop-data -f Makefile.xml
--- drivers/gpu/drm/i915/i915_oa_hsw.c | 484 ++++++++++++++++++++++++++++++++++++- 1 file changed, 483 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_oa_hsw.c +483 -1
@@ -30,9 +30,14 @@enum metric_set_id {METRIC_SET_ID_RENDER_BASIC =1 , +METRIC_SET_ID_COMPUTE_BASIC , +METRIC_SET_ID_COMPUTE_EXTENDED , +METRIC_SET_ID_MEMORY_READS , +METRIC_SET_ID_MEMORY_WRITES , +METRIC_SET_ID_SAMPLER_BALANCE , }; -int i915_oa_n_builtin_metric_sets_hsw =1 ; +int i915_oa_n_builtin_metric_sets_hsw =6 ;static const struct i915_oa_reg b_counter_config_render_basic[] = { {_MMIO (0x2724 ),0x00800000 },
@@ -118,6 +123,333 @@ static int select_render_basic_config(struct drm_i915_private *dev_priv)return 0 ; } +static const struct i915_oa_reg b_counter_config_compute_basic[] = { + {_MMIO (0x2710 ),0x00000000 }, + {_MMIO (0x2714 ),0x00800000 }, + {_MMIO (0x2718 ),0xaaaaaaaa }, + {_MMIO (0x271c ),0xaaaaaaaa }, + {_MMIO (0x2720 ),0x00000000 }, + {_MMIO (0x2724 ),0x00800000 }, + {_MMIO (0x2728 ),0xaaaaaaaa }, + {_MMIO (0x272c ),0xaaaaaaaa }, + {_MMIO (0x2740 ),0x00000000 }, + {_MMIO (0x2744 ),0x00000000 }, + {_MMIO (0x2748 ),0x00000000 }, + {_MMIO (0x274c ),0x00000000 }, + {_MMIO (0x2750 ),0x00000000 }, + {_MMIO (0x2754 ),0x00000000 }, + {_MMIO (0x2758 ),0x00000000 }, + {_MMIO (0x275c ),0x00000000 }, + {_MMIO (0x236c ),0x00000000 }, +}; + +static const struct i915_oa_reg mux_config_compute_basic[] = { + {_MMIO (0x253a4 ),0x00000000 }, + {_MMIO (0x2681c ),0x01f00800 }, + {_MMIO (0x26820 ),0x00001000 }, + {_MMIO (0x2781c ),0x01f00800 }, + {_MMIO (0x26520 ),0x00000007 }, + {_MMIO (0x265a0 ),0x00000007 }, + {_MMIO (0x25380 ),0x00000010 }, + {_MMIO (0x2538c ),0x00300000 }, + {_MMIO (0x25384 ),0xaa8aaaaa }, + {_MMIO (0x25404 ),0xffffffff }, + {_MMIO (0x26800 ),0x00004202 }, + {_MMIO (0x26808 ),0x00605817 }, + {_MMIO (0x2680c ),0x10001005 }, + {_MMIO (0x26804 ),0x00000000 }, + {_MMIO (0x27800 ),0x00000102 }, + {_MMIO (0x27808 ),0x0c0701e0 }, + {_MMIO (0x2780c ),0x000200a0 }, + {_MMIO (0x27804 ),0x00000000 }, + {_MMIO (0x26484 ),0x44000000 }, + {_MMIO (0x26704 ),0x44000000 }, + {_MMIO (0x26500 ),0x00000006 }, + {_MMIO (0x26510 ),0x00000001 }, + {_MMIO (0x26504 ),0x88000000 }, + {_MMIO (0x26580 ),0x00000006 }, + {_MMIO (0x26590 ),0x00000020 }, + {_MMIO (0x26584 ),0x00000000 }, + {_MMIO (0x26104 ),0x55822222 }, + {_MMIO (0x26184 ),0xaa866666 }, + {_MMIO (0x25420 ),0x08320c83 }, + {_MMIO (0x25424 ),0x06820c83 }, + {_MMIO (0x2541c ),0x00000000 }, + {_MMIO (0x25428 ),0x00000c03 }, +}; + +static int select_compute_basic_config (struct drm_i915_private *dev_priv) +{ + dev_priv->perf.oa.mux_regs = + mux_config_compute_basic; + dev_priv->perf.oa.mux_regs_len = +ARRAY_SIZE (mux_config_compute_basic); + + dev_priv->perf.oa.b_counter_regs = + b_counter_config_compute_basic; + dev_priv->perf.oa.b_counter_regs_len = +ARRAY_SIZE (b_counter_config_compute_basic); + +return 0 ; +} + +static const struct i915_oa_reg b_counter_config_compute_extended[] = { + {_MMIO (0x2724 ),0xf0800000 }, + {_MMIO (0x2720 ),0x00000000 }, + {_MMIO (0x2714 ),0xf0800000 }, + {_MMIO (0x2710 ),0x00000000 }, + {_MMIO (0x2770 ),0x0007fe2a }, + {_MMIO (0x2774 ),0x0000ff00 }, + {_MMIO (0x2778 ),0x0007fe6a }, + {_MMIO (0x277c ),0x0000ff00 }, + {_MMIO (0x2780 ),0x0007fe92 }, + {_MMIO (0x2784 ),0x0000ff00 }, + {_MMIO (0x2788 ),0x0007fea2 }, + {_MMIO (0x278c ),0x0000ff00 }, + {_MMIO (0x2790 ),0x0007fe32 }, + {_MMIO (0x2794 ),0x0000ff00 }, + {_MMIO (0x2798 ),0x0007fe9a }, + {_MMIO (0x279c ),0x0000ff00 }, + {_MMIO (0x27a0 ),0x0007ff23 }, + {_MMIO (0x27a4 ),0x0000ff00 }, + {_MMIO (0x27a8 ),0x0007fff3 }, + {_MMIO (0x27ac ),0x0000fffe }, +}; + +static const struct i915_oa_reg mux_config_compute_extended[] = { + {_MMIO (0x2681c ),0x3eb00800 }, + {_MMIO (0x26820 ),0x00900000 }, + {_MMIO (0x25384 ),0x02aaaaaa }, + {_MMIO (0x25404 ),0x03ffffff }, + {_MMIO (0x26800 ),0x00142284 }, + {_MMIO (0x26808 ),0x0e629062 }, + {_MMIO (0x2680c ),0x3f6f55cb }, + {_MMIO (0x26810 ),0x00000014 }, + {_MMIO (0x26804 ),0x00000000 }, + {_MMIO (0x26104 ),0x02aaaaaa }, + {_MMIO (0x26184 ),0x02aaaaaa }, + {_MMIO (0x25420 ),0x00000000 }, + {_MMIO (0x25424 ),0x00000000 }, + {_MMIO (0x2541c ),0x00000000 }, + {_MMIO (0x25428 ),0x00000000 }, +}; + +static int select_compute_extended_config (struct drm_i915_private *dev_priv) +{ + dev_priv->perf.oa.mux_regs = + mux_config_compute_extended; + dev_priv->perf.oa.mux_regs_len = +ARRAY_SIZE (mux_config_compute_extended); + + dev_priv->perf.oa.b_counter_regs = + b_counter_config_compute_extended; + dev_priv->perf.oa.b_counter_regs_len = +ARRAY_SIZE (b_counter_config_compute_extended); + +return 0 ; +} + +static const struct i915_oa_reg b_counter_config_memory_reads[] = { + {_MMIO (0x2724 ),0xf0800000 }, + {_MMIO (0x2720 ),0x00000000 }, + {_MMIO (0x2714 ),0xf0800000 }, + {_MMIO (0x2710 ),0x00000000 }, + {_MMIO (0x274c ),0x76543298 }, + {_MMIO (0x2748 ),0x98989898 }, + {_MMIO (0x2744 ),0x000000e4 }, + {_MMIO (0x2740 ),0x00000000 }, + {_MMIO (0x275c ),0x98a98a98 }, + {_MMIO (0x2758 ),0x88888888 }, + {_MMIO (0x2754 ),0x000c5500 }, + {_MMIO (0x2750 ),0x00000000 }, + {_MMIO (0x2770 ),0x0007f81a }, + {_MMIO (0x2774 ),0x0000fc00 }, + {_MMIO (0x2778 ),0x0007f82a }, + {_MMIO (0x277c ),0x0000fc00 }, + {_MMIO (0x2780 ),0x0007f872 }, + {_MMIO (0x2784 ),0x0000fc00 }, + {_MMIO (0x2788 ),0x0007f8ba }, + {_MMIO (0x278c ),0x0000fc00 }, + {_MMIO (0x2790 ),0x0007f87a }, + {_MMIO (0x2794 ),0x0000fc00 }, + {_MMIO (0x2798 ),0x0007f8ea }, + {_MMIO (0x279c ),0x0000fc00 }, + {_MMIO (0x27a0 ),0x0007f8e2 }, + {_MMIO (0x27a4 ),0x0000fc00 }, + {_MMIO (0x27a8 ),0x0007f8f2 }, + {_MMIO (0x27ac ),0x0000fc00 }, +}; + +static const struct i915_oa_reg mux_config_memory_reads[] = { + {_MMIO (0x253a4 ),0x34300000 }, + {_MMIO (0x25440 ),0x2d800000 }, + {_MMIO (0x25444 ),0x00000008 }, + {_MMIO (0x25128 ),0x0e600000 }, + {_MMIO (0x25380 ),0x00000450 }, + {_MMIO (0x25390 ),0x00052c43 }, + {_MMIO (0x25384 ),0x00000000 }, + {_MMIO (0x25400 ),0x00006144 }, + {_MMIO (0x25408 ),0x0a418820 }, + {_MMIO (0x2540c ),0x000820e6 }, + {_MMIO (0x25404 ),0xff500000 }, + {_MMIO (0x25100 ),0x000005d6 }, + {_MMIO (0x2510c ),0x0ef00000 }, + {_MMIO (0x25104 ),0x00000000 }, + {_MMIO (0x25420 ),0x02108421 }, + {_MMIO (0x25424 ),0x00008421 }, + {_MMIO (0x2541c ),0x00000000 }, + {_MMIO (0x25428 ),0x00000000 }, +}; + +static int select_memory_reads_config (struct drm_i915_private *dev_priv) +{ + dev_priv->perf.oa.mux_regs = + mux_config_memory_reads; + dev_priv->perf.oa.mux_regs_len = +ARRAY_SIZE (mux_config_memory_reads); + + dev_priv->perf.oa.b_counter_regs = + b_counter_config_memory_reads; + dev_priv->perf.oa.b_counter_regs_len = +ARRAY_SIZE (b_counter_config_memory_reads); + +return 0 ; +} + +static const struct i915_oa_reg b_counter_config_memory_writes[] = { + {_MMIO (0x2724 ),0xf0800000 }, + {_MMIO (0x2720 ),0x00000000 }, + {_MMIO (0x2714 ),0xf0800000 }, + {_MMIO (0x2710 ),0x00000000 }, + {_MMIO (0x274c ),0x76543298 }, + {_MMIO (0x2748 ),0x98989898 }, + {_MMIO (0x2744 ),0x000000e4 }, + {_MMIO (0x2740 ),0x00000000 }, + {_MMIO (0x275c ),0xbabababa }, + {_MMIO (0x2758 ),0x88888888 }, + {_MMIO (0x2754 ),0x000c5500 }, + {_MMIO (0x2750 ),0x00000000 }, + {_MMIO (0x2770 ),0x0007f81a }, + {_MMIO (0x2774 ),0x0000fc00 }, + {_MMIO (0x2778 ),0x0007f82a }, + {_MMIO (0x277c ),0x0000fc00 }, + {_MMIO (0x2780 ),0x0007f822 }, + {_MMIO (0x2784 ),0x0000fc00 }, + {_MMIO (0x2788 ),0x0007f8ba }, + {_MMIO (0x278c ),0x0000fc00 }, + {_MMIO (0x2790 ),0x0007f87a }, + {_MMIO (0x2794 ),0x0000fc00 }, + {_MMIO (0x2798 ),0x0007f8ea }, + {_MMIO (0x279c ),0x0000fc00 }, + {_MMIO (0x27a0 ),0x0007f8e2 }, + {_MMIO (0x27a4 ),0x0000fc00 }, + {_MMIO (0x27a8 ),0x0007f8f2 }, + {_MMIO (0x27ac ),0x0000fc00 }, +}; + +static const struct i915_oa_reg mux_config_memory_writes[] = { + {_MMIO (0x253a4 ),0x34300000 }, + {_MMIO (0x25440 ),0x01500000 }, + {_MMIO (0x25444 ),0x00000120 }, + {_MMIO (0x25128 ),0x0c200000 }, + {_MMIO (0x25380 ),0x00000450 }, + {_MMIO (0x25390 ),0x00052c43 }, + {_MMIO (0x25384 ),0x00000000 }, + {_MMIO (0x25400 ),0x00007184 }, + {_MMIO (0x25408 ),0x0a418820 }, + {_MMIO (0x2540c ),0x000820e6 }, + {_MMIO (0x25404 ),0xff500000 }, + {_MMIO (0x25100 ),0x000005d6 }, + {_MMIO (0x2510c ),0x1e700000 }, + {_MMIO (0x25104 ),0x00000000 }, + {_MMIO (0x25420 ),0x02108421 }, + {_MMIO (0x25424 ),0x00008421 }, + {_MMIO (0x2541c ),0x00000000 }, + {_MMIO (0x25428 ),0x00000000 }, +}; + +static int select_memory_writes_config (struct drm_i915_private *dev_priv) +{ + dev_priv->perf.oa.mux_regs = + mux_config_memory_writes; + dev_priv->perf.oa.mux_regs_len = +ARRAY_SIZE (mux_config_memory_writes); + + dev_priv->perf.oa.b_counter_regs = + b_counter_config_memory_writes; + dev_priv->perf.oa.b_counter_regs_len = +ARRAY_SIZE (b_counter_config_memory_writes); + +return 0 ; +} + +static const struct i915_oa_reg b_counter_config_sampler_balance[] = { + {_MMIO (0x2740 ),0x00000000 }, + {_MMIO (0x2744 ),0x00800000 }, + {_MMIO (0x2710 ),0x00000000 }, + {_MMIO (0x2714 ),0x00800000 }, + {_MMIO (0x2720 ),0x00000000 }, + {_MMIO (0x2724 ),0x00800000 }, +}; + +static const struct i915_oa_reg mux_config_sampler_balance[] = { + {_MMIO (0x2eb9c ),0x01906400 }, + {_MMIO (0x2fb9c ),0x01906400 }, + {_MMIO (0x253a4 ),0x00000000 }, + {_MMIO (0x26b9c ),0x01906400 }, + {_MMIO (0x27b9c ),0x01906400 }, + {_MMIO (0x27104 ),0x00a00000 }, + {_MMIO (0x27184 ),0x00a50000 }, + {_MMIO (0x2e804 ),0x00500000 }, + {_MMIO (0x2e984 ),0x00500000 }, + {_MMIO (0x2eb04 ),0x00500000 }, + {_MMIO (0x2eb80 ),0x00000084 }, + {_MMIO (0x2eb8c ),0x14200000 }, + {_MMIO (0x2eb84 ),0x00000000 }, + {_MMIO (0x2f804 ),0x00050000 }, + {_MMIO (0x2f984 ),0x00050000 }, + {_MMIO (0x2fb04 ),0x00050000 }, + {_MMIO (0x2fb80 ),0x00000084 }, + {_MMIO (0x2fb8c ),0x00050800 }, + {_MMIO (0x2fb84 ),0x00000000 }, + {_MMIO (0x25380 ),0x00000010 }, + {_MMIO (0x2538c ),0x000000c0 }, + {_MMIO (0x25384 ),0xaa550000 }, + {_MMIO (0x25404 ),0xffffc000 }, + {_MMIO (0x26804 ),0x50000000 }, + {_MMIO (0x26984 ),0x50000000 }, + {_MMIO (0x26b04 ),0x50000000 }, + {_MMIO (0x26b80 ),0x00000084 }, + {_MMIO (0x26b90 ),0x00050800 }, + {_MMIO (0x26b84 ),0x00000000 }, + {_MMIO (0x27804 ),0x05000000 }, + {_MMIO (0x27984 ),0x05000000 }, + {_MMIO (0x27b04 ),0x05000000 }, + {_MMIO (0x27b80 ),0x00000084 }, + {_MMIO (0x27b90 ),0x00000142 }, + {_MMIO (0x27b84 ),0x00000000 }, + {_MMIO (0x26104 ),0xa0000000 }, + {_MMIO (0x26184 ),0xa5000000 }, + {_MMIO (0x25424 ),0x00008620 }, + {_MMIO (0x2541c ),0x00000000 }, + {_MMIO (0x25428 ),0x0004a54a }, +}; + +static int select_sampler_balance_config (struct drm_i915_private *dev_priv) +{ + dev_priv->perf.oa.mux_regs = + mux_config_sampler_balance; + dev_priv->perf.oa.mux_regs_len = +ARRAY_SIZE (mux_config_sampler_balance); + + dev_priv->perf.oa.b_counter_regs = + b_counter_config_sampler_balance; + dev_priv->perf.oa.b_counter_regs_len = +ARRAY_SIZE (b_counter_config_sampler_balance); + +return 0 ; +} +int i915_oa_select_metric_set_hsw (struct drm_i915_private *dev_priv) { dev_priv->perf.oa.mux_regs =NULL ;
@@ -128,6 +460,16 @@ int i915_oa_select_metric_set_hsw(struct drm_i915_private *dev_priv)switch (dev_priv->perf.oa.metrics_set) {case METRIC_SET_ID_RENDER_BASIC :return select_render_basic_config (dev_priv); +case METRIC_SET_ID_COMPUTE_BASIC : +return select_compute_basic_config (dev_priv); +case METRIC_SET_ID_COMPUTE_EXTENDED : +return select_compute_extended_config (dev_priv); +case METRIC_SET_ID_MEMORY_READS : +return select_memory_reads_config (dev_priv); +case METRIC_SET_ID_MEMORY_WRITES : +return select_memory_writes_config (dev_priv); +case METRIC_SET_ID_SAMPLER_BALANCE : +return select_sampler_balance_config (dev_priv);default :return -ENODEV ; }
@@ -155,6 +497,116 @@ static struct attribute_group group_render_basic = { .attrs = attrs_render_basic, }; +static ssize_t +show_compute_basic_id (struct device *kdev,struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"%d\n" ,METRIC_SET_ID_COMPUTE_BASIC ); +} + +static struct device_attribute dev_attr_compute_basic_id = { + .attr = { .name ="id" , .mode =S_IRUGO }, + .show = show_compute_basic_id, + .store =NULL , +}; + +static struct attribute *attrs_compute_basic[] = { + &dev_attr_compute_basic_id.attr, +NULL , +}; + +static struct attribute_group group_compute_basic = { + .name ="39ad14bc-2380-45c4-91eb-fbcb3aa7ae7b" , + .attrs = attrs_compute_basic, +}; + +static ssize_t +show_compute_extended_id (struct device *kdev,struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"%d\n" ,METRIC_SET_ID_COMPUTE_EXTENDED ); +} + +static struct device_attribute dev_attr_compute_extended_id = { + .attr = { .name ="id" , .mode =S_IRUGO }, + .show = show_compute_extended_id, + .store =NULL , +}; + +static struct attribute *attrs_compute_extended[] = { + &dev_attr_compute_extended_id.attr, +NULL , +}; + +static struct attribute_group group_compute_extended = { + .name ="3865be28-6982-49fe-9494-e4d1b4795413" , + .attrs = attrs_compute_extended, +}; + +static ssize_t +show_memory_reads_id (struct device *kdev,struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"%d\n" ,METRIC_SET_ID_MEMORY_READS ); +} + +static struct device_attribute dev_attr_memory_reads_id = { + .attr = { .name ="id" , .mode =S_IRUGO }, + .show = show_memory_reads_id, + .store =NULL , +}; + +static struct attribute *attrs_memory_reads[] = { + &dev_attr_memory_reads_id.attr, +NULL , +}; + +static struct attribute_group group_memory_reads = { + .name ="bb5ed49b-2497-4095-94f6-26ba294db88a" , + .attrs = attrs_memory_reads, +}; + +static ssize_t +show_memory_writes_id (struct device *kdev,struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"%d\n" ,METRIC_SET_ID_MEMORY_WRITES ); +} + +static struct device_attribute dev_attr_memory_writes_id = { + .attr = { .name ="id" , .mode =S_IRUGO }, + .show = show_memory_writes_id, + .store =NULL , +}; + +static struct attribute *attrs_memory_writes[] = { + &dev_attr_memory_writes_id.attr, +NULL , +}; + +static struct attribute_group group_memory_writes = { + .name ="3358d639-9b5f-45ab-976d-9b08cbfc6240" , + .attrs = attrs_memory_writes, +}; + +static ssize_t +show_sampler_balance_id (struct device *kdev,struct device_attribute *attr,char *buf) +{ +return sprintf (buf,"%d\n" ,METRIC_SET_ID_SAMPLER_BALANCE ); +} + +static struct device_attribute dev_attr_sampler_balance_id = { + .attr = { .name ="id" , .mode =S_IRUGO }, + .show = show_sampler_balance_id, + .store =NULL , +}; + +static struct attribute *attrs_sampler_balance[] = { + &dev_attr_sampler_balance_id.attr, +NULL , +}; + +static struct attribute_group group_sampler_balance = { + .name ="bc274488-b4b6-40c7-90da-b77d7ad16189" , + .attrs = attrs_sampler_balance, +}; +int i915_perf_init_sysfs_hsw (struct drm_i915_private *dev_priv) {
@@ -163,9 +615,34 @@ i915_perf_init_sysfs_hsw(struct drm_i915_private *dev_priv) ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_render_basic);if (ret) goto error_render_basic; + ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_compute_basic); +if (ret) + goto error_compute_basic; + ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_compute_extended); +if (ret) + goto error_compute_extended; + ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_memory_reads); +if (ret) + goto error_memory_reads; + ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_memory_writes); +if (ret) + goto error_memory_writes; + ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_sampler_balance); +if (ret) + goto error_sampler_balance;return 0 ; +error_sampler_balance: +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_memory_writes); +error_memory_writes: +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_memory_reads); +error_memory_reads: +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_compute_extended); +error_compute_extended: +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_compute_basic); +error_compute_basic: +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_render_basic); error_render_basic:return ret; }
@@ -174,4 +651,9 @@ void i915_perf_deinit_sysfs_hsw(struct drm_i915_private *dev_priv) {sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_render_basic); +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_compute_basic); +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_compute_extended); +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_memory_reads); +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_memory_writes); +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_sampler_balance); }
Signature · 6 lines
2.9.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 11/11 drm/i915: Add a kerneldoc summary for i915_perf.c
In reply to Robert BraggIn particular this tries to capture for posterity some of the early challenges we had with using the core perf infrastructure in case we ever want to revisit adapting perf for device metrics.
--- drivers/gpu/drm/i915/i915_perf.c | 163 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+)
drivers/gpu/drm/i915/i915_perf.c +163 -0
@@ -24,6 +24,169 @@* Robert Bragg <[email protected]> */ + +/** +* DOC: i915 Perf, streaming API for GPU metrics +* +* Gen graphics supports a large number of performance counters that can help +* driver and application developers understand and optimize their use of the +* GPU. +* +* This i915 perf interface enables userspace to configure and open a file +* descriptor representing a stream of GPU metrics which can then be read() as +* a stream of sample records. +* +* The interface is particularly suited to exposing buffered metrics that are +* captured by DMA from the GPU, unsynchronized with and unrelated to the CPU. +* +* Streams representing a single context are accessible to applications with a +* corresponding drm file descriptor, such that OpenGL can use the interface +* without special privileges. Access to system-wide metrics requires root +* privileges by default, unless changed via the dev.i915.perf_event_paranoid +* sysctl option. +* +* +* The interface was initially inspired by the core Perf infrastructure but +* some notable differences are: +* +* i915 perf file descriptors represent a "stream" instead of an "event"; where +* a perf event primarily corresponds to a single 64bit value, while a stream +* might sample sets of tightly-coupled counters, depending on the +* configuration. For example the Gen OA unit isn't designed to support +* orthogonal configurations of individual counters; it's configured for a set +* of related counters. Samples for an i915 perf stream capturing OA metrics +* will include a set of counter values packed in a compact HW specific format. +* The OA unit supports a number of different packing formats which can be +* selected by the user opening the stream. Perf has support for grouping +* events, but each event in the group is configured, validated and +* authenticated individually with separate system calls. +* +* i915 perf stream configurations are provided as an array of u64 (key,value) +* pairs, instead of a fixed struct with multiple miscellaneous config members, +* interleaved with event-type specific members. +* +* i915 perf doesn't support exposing metrics via an mmap'd circular buffer. +* The supported metrics are being written to memory by the GPU unsynchronized +* with the CPU, using HW specific packing formats for counter sets. Sometimes +* the constraints on HW configuration require reports to be filtered before it +* would be acceptable to expose them to unprivileged applications - to hide +* the metrics of other processes/contexts. For these use cases a read() based +* interface is a good fit, and provides an opportunity to filter data as it +* gets copied from the GPU mapped buffers to userspace buffers. +* +* +* Some notes regarding Linux Perf: +* -------------------------------- +* +* The first prototype of this driver was based on the core perf +* infrastructure, and while we did make that mostly work, with some changes to +* perf, we found we were breaking or working around too many assumptions baked +* into perf's currently cpu centric design. +* +* In the end we didn't see a clear benefit to making perf's implementation and +* interface more complex by changing design assumptions while we knew we still +* wouldn't be able to use any existing perf based userspace tools. +* +* Also considering the Gen specific nature of the Observability hardware and +* how userspace will sometimes need to combine i915 perf OA metrics with +* side-band OA data captured via MI_REPORT_PERF_COUNT commands; we're +* expecting the interface to be used by a platform specific userspace such as +* OpenGL or tools. This is to say; we aren't inherently missing out on having +* a standard vendor/architecture agnostic interface by not using perf. +* +* +* For posterity, in case we might re-visit trying to adapt core perf to be +* better suited to exposing i915 metrics these were the main pain points we +* hit: +* +* - The perf based OA PMU driver broke some significant design assumptions: +* +* Existing perf pmus are used for profiling work on a cpu and we were +* introducing the idea of _IS_DEVICE pmus with different security +* implications, the need to fake cpu-related data (such as user/kernel +* registers) to fit with perf's current design, and adding _DEVICE records +* as a way to forward device-specific status records. +* +* The OA unit writes reports of counters into a circular buffer, without +* involvement from the CPU, making our PMU driver the first of a kind. +* +* Given the way we were periodically forward data from the GPU-mapped, OA +* buffer to perf's buffer, those bursts of sample writes looked to perf like +* we were sampling too fast and so we had to subvert its throttling checks. +* +* Perf supports groups of counters and allows those to be read via +* transactions internally but transactions currently seem designed to be +* explicitly initiated from the cpu (say in response to a userspace read()) +* and while we could pull a report out of the OA buffer we can't +* trigger a report from the cpu on demand. +* +* Related to being report based; the OA counters are configured in HW as a +* set while perf generally expects counter configurations to be orthogonal. +* Although counters can be associated with a group leader as they are +* opened, there's no clear precedent for being able to provide group-wide +* configuration attributes (for example we want to let userspace choose the +* OA unit report format used to capture all counters in a set, or specify a +* GPU context to filter metrics on). We avoided using perf's grouping +* feature and forwarded OA reports to userspace via perf's 'raw' sample +* field. This suited our userspace well considering how coupled the counters +* are when dealing with normalizing. It would be inconvenient to split +* counters up into separate events, only to require userspace to recombine +* them. For Mesa it's also convenient to be forwarded raw, periodic reports +* for combining with the side-band raw reports it captures using +* MI_REPORT_PERF_COUNT commands. +* +* _ As a side note on perf's grouping feature; there was also some concern +* that using PERF_FORMAT_GROUP as a way to pack together counter values +* would quite drastically inflate our sample sizes, which would likely +* lower the effective sampling resolutions we could use when the available +* memory bandwidth is limited. +* +* With the OA unit's report formats, counters are packed together as 32 +* or 40bit values, with the largest report size being 256 bytes. +* +* PERF_FORMAT_GROUP values are 64bit, but there doesn't appear to be a +* documented ordering to the values, implying PERF_FORMAT_ID must also be +* used to add a 64bit ID before each value; giving 16 bytes per counter. +* +* Related to counter orthogonality; we can't time share the OA unit, while +* event scheduling is a central design idea within perf for allowing +* userspace to open + enable more events than can be configured in HW at any +* one time. The OA unit is not designed to allow re-configuration while in +* use. We can't reconfigure the OA unit without loosing internal OA unit +* state which we can't access explicitly to save and restore. Reconfiguring +* the OA unit is also relatively slow, involving ~100 register writes. From +* userspace Mesa also depends on a stable OA configuration when emitting +* MI_REPORT_PERF_COUNT commands and importantly the OA unit can't be +* disabled while there are outstanding MI_RPC commands lest we hang the +* command streamer. +* +* The contents of sample records aren't extensible by device drivers (i.e. +* the sample_type bits). As an example; Sourab Gupta had been looking to +* attach GPU timestamps to our OA samples. We were shoehorning OA reports +* into sample records by using the 'raw' field, but it's tricky to pack more +* than one thing into this field because events/core.c currently only lets a +* pmu give a single raw data pointer plus len which will be copied into the +* ring buffer. To include more than the OA report we'd have to copy the +* report into an intermediate larger buffer. I'd been considering allowing a +* vector of data+len values to be specified for copying the raw data, but +* it felt like a kludge to being using the raw field for this purpose. +* +* - It felt like our perf based PMU was making some technical compromises +* just for the sake of using perf: +* +* perf_event_open() requires events to either relate to a pid or a specific +* cpu core, while our device pmu related to neither. Events opened with a +* pid will be automatically enabled/disabled according to the scheduling of +* that process - so not appropriate for us. When an event is related to a +* cpu id, perf ensures pmu methods will be invoked via an inter process +* interrupt on that core. To avoid invasive changes our userspace opened OA +* perf events for a specific cpu. This was workable but it meant the +* majority of the OA driver ran in atomic context, including all OA report +* forwarding, which wasn't really necessary in our case and seems to make +* our locking requirements somewhat complex as we handled the interaction +* with the rest of the i915 driver. +*/ +#include <linux/anon_inodes.h> #include <linux/sizes.h>
Signature · 6 lines
2.9.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Ro.CI.BAT: failure for Enable Gen 7 Observation Architecture (rev5)
In reply to Robert Bragg== Series Details ==
== Series Details ==
Series: Enable Gen 7 Observation Architecture (rev5)
URL : https://patchwork.freedesktop.org/series/3024/
State : failure
== Summary ==
Applying: drm/i915: Add i915 perf infrastructure
Using index info to reconstruct a base tree...
M drivers/gpu/drm/i915/Makefile
M drivers/gpu/drm/i915/i915_drv.c
M drivers/gpu/drm/i915/i915_drv.h
M include/uapi/drm/i915_drm.h
Falling back to patching base and 3-way merge...
Auto-merging include/uapi/drm/i915_drm.h
Auto-merging drivers/gpu/drm/i915/i915_drv.h
Auto-merging drivers/gpu/drm/i915/i915_drv.c
Auto-merging drivers/gpu/drm/i915/Makefile
Applying: drm/i915: rename OACONTROL GEN7_OACONTROL
Applying: drm/i915: return EACCES for check_cmd() failures
Applying: drm/i915: don't whitelist oacontrol in cmd parser
Applying: drm/i915: Add 'render basic' Haswell OA unit config
Applying: drm/i915: Enable i915 perf stream for Haswell OA unit
fatal: sha1 information is lacking or useless (drivers/gpu/drm/i915/i915_drv.h).
error: could not build fake ancestor
Patch failed at 0006 drm/i915: Enable i915 perf stream for Haswell OA unit The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx