drm/i915: Add i915 perf infrastructure
PATCH v6 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.
v4:
s/DRM_IORW/DRM_IOW/ - Emil Velikov
v3:
update read() interface to avoid passing state struct - Chris Wilson fix some rebase fallout, with i915-perf init/deinit
v2:
use i915_gem_context_get() - Chris Wilson
--- drivers/gpu/drm/i915/Makefile | 3 + drivers/gpu/drm/i915/i915_drv.c | 4 + drivers/gpu/drm/i915/i915_drv.h | 91 ++++++++ drivers/gpu/drm/i915/i915_perf.c | 443 +++++++++++++++++++++++++++++++++++++++ include/uapi/drm/i915_drm.h | 67 ++++++ 5 files changed, 608 insertions(+) create mode 100644 drivers/gpu/drm/i915/i915_perf.c
drivers/gpu/drm/i915/Makefile +3 -0
@@ -113,6 +113,9 @@ i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.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 +4 -0
@@ -836,6 +836,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,intel_detect_preproduction_hw (dev_priv); +i915_perf_init (dev_priv); +return 0 ; err_workqueues:
@@ -849,6 +851,7 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,*/ static void i915_driver_cleanup_early (struct drm_i915_private *dev_priv) { +i915_perf_fini (dev_priv);i915_gem_load_cleanup (&dev_priv->drm);i915_workqueues_cleanup (dev_priv); }
@@ -2575,6 +2578,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 +91 -0
115 lines not on this page · raw message
drivers/gpu/drm/i915/i915_perf.c new file +443 -0
443 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.10.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 2/11 drm/i915: rename OACONTROL GEN7_OACONTROL
OACONTROL 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/gvt/handlers.c | 2 +- drivers/gpu/drm/i915/i915_cmd_parser.c | 4 ++-- drivers/gpu/drm/i915/i915_reg.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gvt/handlers.c +1 -1
@@ -2159,7 +2159,7 @@ static int init_generic_mmio_info(struct intel_gvt *gvt)MMIO_DFH (0x1217c ,D_ALL ,F_CMD_ACCESS ,NULL ,NULL );MMIO_F (0x2290 ,8 ,0 ,0 ,0 ,D_HSW_PLUS ,NULL ,NULL ); -MMIO_D (OACONTROL ,D_HSW ); +MMIO_D (GEN7_OACONTROL ,D_HSW );MMIO_D (0x2b00 ,D_BDW_PLUS );MMIO_D (0x2360 ,D_BDW_PLUS );MMIO_F (0x5200 ,32 ,0 ,0 ,0 ,D_ALL ,NULL ,NULL );
drivers/gpu/drm/i915/i915_cmd_parser.c +2 -2
@@ -450,7 +450,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),
@@ -1108,7 +1108,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
@@ -615,7 +615,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.10.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v6 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.
This bumps the command parser version from 7 to 8, as the change is visible to userspace.
--- drivers/gpu/drm/i915/i915_cmd_parser.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_cmd_parser.c +5 -2
@@ -1272,7 +1272,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 ; }
@@ -1333,6 +1333,9 @@ int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv)* 5. GPGPU dispatch compute indirect registers. * 6. TIMESTAMP register and Haswell CS GPR registers * 7. Allow MI_LOAD_REGISTER_REG between whitelisted registers. +* 8. Don't report cmd_check() failures as EINVAL errors to userspace; +* rely on the HW to NOOP disallowed commands as it would without +* the parser enabled. */ -return 7 ; +return 8 ; }
Signature · 6 lines
2.10.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v6 03/11] drm/i915: return EACCES for check_cmd() failures
drivers/gpu/drm/i915/i915_cmd_parser.c int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv) · line 1338
Quoted 7 lines · Robert Bragg
drivers/gpu/drm/i915/i915_cmd_parser.c +3
-0@@ -1333,6 +1333,9 @@ int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv)* 5. GPGPU dispatch compute indirect registers. * 6. TIMESTAMP register and Haswell CS GPR registers * 7. Allow MI_LOAD_REGISTER_REG between whitelisted registers. +* 8. Don't report cmd_check() failures as EINVAL errors to userspace; +* rely on the HW to NOOP disallowed commands as it would without +* the parser enabled.
I added a test case to exercise this and at least for OACONTROL we are fine. That test can supercede the negative BAT in gem_exec_parse. -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 1/1 igt/gem_exec_parse: update for version 8 changes
Just wanted to show how I'd been looking at updating gem_exec_parse considering my interface change to stop returning EINVAL to userspace. I think maybe it'd be good to split the patch up since I moved things around a bit, but hopefully it's not too bad to skim for now.
I wasn't quite sure what to make of the recentl stray_lri change, since it seems to accept returning EINVAL to userspace which for OACONTROL specifically is a condition we ultimately want to be sure we don't allow because it's liable to cause Mesa applications to abort.
The reason stray_lri should currently see an acceptable EINVAL is because OACONTROL is is a very special case register for the command parser and OACONTROL needs to be disabled before the end of a batch, but that's checked for in oacontrol-tracking.
Something else I was unsure of with the stray_lri test is that it's using 0xdeadbeef as a debug value, which seems a bit risky for OACONTROL as it will enable the OA unit with periodic sampling.
--- >8 ---
This adapts the tests to account for the parser no longer reporting privilege violations back to userspace as EINVAL errors (they are left to the HW command parser to squash the commands to NOOPS).
The interface change isn't expected to affect userspace and in fact it looks like the previous behaviour was liable to break userspace, such as Mesa which explicitly tries to observe whether OACONTROL LRIs are squashed to NOOPs but Mesa will abort for execbuffer errors.
--- tests/gem_exec_parse.c | 368 +++++++++++++++++++++++++++---------------------- 1 file changed, 200 insertions(+), 168 deletions(-)
tests/gem_exec_parse.c +200 -168
@@ -34,7 +34,24 @@#define I915_PARAM_CMD_PARSER_VERSION 28#endif +#define ARRAY_LEN (A ) (sizeof(A) / sizeof(A[0])) + +#define OACONTROL 0x2360#define DERRMR 0x44050 +#define SO_WRITE_OFFSET_0 0x5280 +#define HSW_CS_GPR (n) (0x2600 + 8*(n)) +#define HSW_CS_GPR0 HSW_CS_GPR(0) +#define HSW_CS_GPR1 HSW_CS_GPR(1) + +#define MI_LOAD_REGISTER_REG (0x2a << 23) +#define MI_STORE_REGISTER_MEM (0x24 << 23) +#define MI_ARB_ON_OFF (0x8 << 23) +#define MI_DISPLAY_FLIP ((0x14 << 23) | 1) + +#define GFX_OP_PIPE_CONTROL ((0x3<<29)|(0x3<<27)|(0x2<<24)|2) +#define PIPE_CONTROL_QW_WRITE (1<<14) +#define PIPE_CONTROL_LRI_POST_OP (1<<23) +static int command_parser_version (int fd) {
@@ -50,101 +67,8 @@ static int command_parser_version(int fd)return -1 ; } -#define HSW_CS_GPR (n) (0x2600 + 8*(n)) -#define HSW_CS_GPR0 HSW_CS_GPR(0) -#define HSW_CS_GPR1 HSW_CS_GPR(1) - -#define MI_LOAD_REGISTER_REG (0x2a << 23) -#define MI_STORE_REGISTER_MEM (0x24 << 23) -static void hsw_load_register_reg (void ) -{ -uint32_t buf[16 ] = { -MI_LOAD_REGISTER_IMM | (5 -2 ), -HSW_CS_GPR0 , -0xabcdabcd , -HSW_CS_GPR1 , -0xdeadbeef , - -MI_STORE_REGISTER_MEM | (3 -2 ), -HSW_CS_GPR1 , -0 ,/* address0 */ - -MI_LOAD_REGISTER_REG | (3 -2 ), -HSW_CS_GPR0 , -HSW_CS_GPR1 , - -MI_STORE_REGISTER_MEM | (3 -2 ), -HSW_CS_GPR1 , -4 ,/* address1 */ - -MI_BATCH_BUFFER_END , - }; -struct drm_i915_gem_execbuffer2 execbuf; -struct drm_i915_gem_exec_object2 obj[2 ]; -struct drm_i915_gem_relocation_entry reloc[2 ]; -int fd; - -/* Open again to get a non-master file descriptor */ - fd =drm_open_driver (DRIVER_INTEL ); - -igt_require (IS_HASWELL (intel_get_drm_devid (fd))); -igt_require (command_parser_version (fd) >=7 ); - -memset (obj,0 ,sizeof (obj)); - obj[0 ].handle =gem_create (fd,4096 ); - obj[1 ].handle =gem_create (fd,4096 ); -gem_write (fd, obj[1 ].handle,0 , buf,sizeof (buf)); - -memset (reloc,0 ,sizeof (reloc)); - reloc[0 ].offset =7 *sizeof (uint32_t ); - reloc[0 ].target_handle = obj[0 ].handle; - reloc[0 ].delta =0 ; - reloc[0 ].read_domains =I915_GEM_DOMAIN_INSTRUCTION ; - reloc[0 ].write_domain =I915_GEM_DOMAIN_INSTRUCTION ; - reloc[1 ].offset =13 *sizeof (uint32_t ); - reloc[1 ].target_handle = obj[0 ].handle; - reloc[1 ].delta =sizeof (uint32_t ); - reloc[1 ].read_domains =I915_GEM_DOMAIN_INSTRUCTION ; - reloc[1 ].write_domain =I915_GEM_DOMAIN_INSTRUCTION ; - obj[1 ].relocs_ptr = (uintptr_t )&reloc; - obj[1 ].relocation_count =2 ; - -memset (&execbuf,0 ,sizeof (execbuf)); - execbuf.buffers_ptr = (uintptr_t )obj; - execbuf.buffer_count =2 ; - execbuf.batch_len =sizeof (buf); - execbuf.flags =I915_EXEC_RENDER ; -gem_execbuf (fd, &execbuf); -gem_close (fd, obj[1 ].handle); - -gem_read (fd, obj[0 ].handle,0 , buf,2 *sizeof (buf[0 ])); -igt_assert_eq_u32 (buf[0 ],0xdeadbeef );/* before copy */ -igt_assert_eq_u32 (buf[1 ],0xabcdabcd );/* after copy */ - -/* Now a couple of negative tests that should be filtered */ - execbuf.buffer_count =1 ; - execbuf.batch_len =4 *sizeof (buf[0 ]); - - buf[0 ] =MI_LOAD_REGISTER_REG | (3 -2 ); - buf[1 ] =HSW_CS_GPR0 ; - buf[2 ] =0 ; - buf[3 ] =MI_BATCH_BUFFER_END ; -gem_write (fd, obj[0 ].handle,0 , buf, execbuf.batch_len); -igt_assert_eq (__gem_execbuf (fd, &execbuf), -EINVAL ); - - buf[2 ] =DERRMR ;/* master only */ -gem_write (fd, obj[0 ].handle,0 , buf, execbuf.batch_len); -igt_assert_eq (__gem_execbuf (fd, &execbuf), -EINVAL ); - - buf[2 ] =0x2038 ;/* RING_START: invalid */ -gem_write (fd, obj[0 ].handle,0 , buf, execbuf.batch_len); -igt_assert_eq (__gem_execbuf (fd, &execbuf), -EINVAL ); - -close (fd); -} - -static void exec_batch_patched (int fd,uint32_t cmd_bo,uint32_t *cmds, -int size,int patch_offset,uint64_t expected_value) +static uint64_t __exec_batch_patched (int fd,uint32_t cmd_bo,uint32_t *cmds, +int size,int patch_offset) {struct drm_i915_gem_execbuffer2 execbuf;struct drm_i915_gem_exec_object2 objs[2 ];
@@ -155,50 +79,43 @@ static void exec_batch_patched(int fd, uint32_t cmd_bo, uint32_t *cmds,gem_write (fd, cmd_bo,0 , cmds, size); - reloc[0 ].offset = patch_offset; - reloc[0 ].delta =0 ; - reloc[0 ].target_handle = target_bo; - reloc[0 ].read_domains =I915_GEM_DOMAIN_RENDER ; - reloc[0 ].write_domain =I915_GEM_DOMAIN_RENDER ; - reloc[0 ].presumed_offset =0 ; +memset (objs,0 ,sizeof (objs)); objs[0 ].handle = target_bo; - objs[0 ].relocation_count =0 ; - objs[0 ].relocs_ptr =0 ; - objs[0 ].alignment =0 ; - objs[0 ].offset =0 ; - objs[0 ].flags =0 ; - objs[0 ].rsvd1 =0 ; - objs[0 ].rsvd2 =0 ; - objs[1 ].handle = cmd_bo; - objs[1 ].relocation_count =1 ; + +memset (reloc,0 ,sizeof (reloc)); + reloc[0 ].offset = patch_offset; + reloc[0 ].target_handle = objs[0 ].handle; + reloc[0 ].delta =0 ; + reloc[0 ].read_domains =I915_GEM_DOMAIN_COMMAND ; + reloc[0 ].write_domain =I915_GEM_DOMAIN_COMMAND ; objs[1 ].relocs_ptr = (uintptr_t )reloc; - objs[1 ].alignment =0 ; - objs[1 ].offset =0 ; - objs[1 ].flags =0 ; - objs[1 ].rsvd1 =0 ; - objs[1 ].rsvd2 =0 ; + objs[1 ].relocation_count =1 ; +memset (&execbuf,0 ,sizeof (execbuf)); execbuf.buffers_ptr = (uintptr_t )objs; execbuf.buffer_count =2 ; - execbuf.batch_start_offset =0 ; execbuf.batch_len = size; - execbuf.cliprects_ptr =0 ; - execbuf.num_cliprects =0 ; - execbuf.DR1 =0 ; - execbuf.DR4 =0 ; execbuf.flags =I915_EXEC_RENDER ; -i915_execbuffer2_set_context_id (execbuf,0 ); - execbuf.rsvd2 =0 ;gem_execbuf (fd, &execbuf);gem_sync (fd, cmd_bo);gem_read (fd,target_bo,0 , &actual_value,sizeof (actual_value)); -igt_assert_eq (expected_value, actual_value);gem_close (fd, target_bo); + +return actual_value; +} + +static void exec_batch_patched (int fd,uint32_t cmd_bo,uint32_t *cmds, +int size,int patch_offset, +uint64_t expected_value) +{ +igt_assert_eq (__exec_batch_patched (fd, cmd_bo, cmds, + size, patch_offset), + expected_value); } static int __exec_batch(int fd, uint32_t cmd_bo, uint32_t *cmds,
@@ -320,14 +237,14 @@ static void exec_batch_chained(int fd, uint32_t cmd_bo, uint32_t *cmds, reloc.offset = patch_offset; reloc.delta =0 ; reloc.target_handle = target_bo; - reloc.read_domains =I915_GEM_DOMAIN_RENDER ; - reloc.write_domain =I915_GEM_DOMAIN_RENDER ; + reloc.read_domains =I915_GEM_DOMAIN_COMMAND ; + reloc.write_domain =I915_GEM_DOMAIN_COMMAND ; reloc.presumed_offset =0 ; first_level_reloc.offset =4 ; first_level_reloc.delta =0 ; first_level_reloc.target_handle = cmd_bo; - first_level_reloc.read_domains =I915_GEM_DOMAIN_INSTRUCTION ; + first_level_reloc.read_domains =I915_GEM_DOMAIN_COMMAND ; first_level_reloc.write_domain =0 ; first_level_reloc.presumed_offset =0 ;
@@ -380,15 +297,91 @@ static void exec_batch_chained(int fd, uint32_t cmd_bo, uint32_t *cmds,gem_close (fd, target_bo); } -uint32_t handle; -int fd; +static void hsw_load_register_reg (void ) +{ +uint32_t init_gpr0[16 ] = { +MI_LOAD_REGISTER_IMM | (3 -2 ), +HSW_CS_GPR0 , +0xabcdabc0 ,/* leave [1:0] zero */ +MI_BATCH_BUFFER_END , + }; +uint32_t store_gpr0[16 ] = { +MI_STORE_REGISTER_MEM | (3 -2 ), +HSW_CS_GPR0 , +0 ,/* reloc*/ +MI_BATCH_BUFFER_END , + }; +uint32_t do_lrr[16 ] = { +MI_LOAD_REGISTER_REG | (3 -2 ), +0 ,/* [1] = src */ +HSW_CS_GPR0 ,/* dst */ +MI_BATCH_BUFFER_END , + }; +uint32_t allowed_regs[] = { +HSW_CS_GPR1 , +SO_WRITE_OFFSET_0 , + }; +uint32_t disallowed_regs[] = { +0 , +DERRMR ,/* master only */ +0x2038 ,/* RING_START: invalid */ + }; +int fd; +uint32_t handle; -#define MI_ARB_ON_OFF (0x8 << 23) -#define MI_DISPLAY_FLIP ((0x14 << 23) | 1) +/* Open again to get a non-master file descriptor */ + fd =drm_open_driver (DRIVER_INTEL ); + +igt_require (IS_HASWELL (intel_get_drm_devid (fd))); +igt_require (command_parser_version (fd) >=7 ); + + handle =gem_create (fd,4096 ); + +for (int i =0 ; i <ARRAY_LEN (allowed_regs); i++) { +uint32_t var; + +exec_batch (fd, handle, init_gpr0,sizeof (init_gpr0), +I915_EXEC_RENDER , +0 ); +exec_batch_patched (fd, handle, + store_gpr0,sizeof (store_gpr0), +2 *sizeof (uint32_t ),/* reloc */ +0xabcdabc0 ); + do_lrr[1 ] = allowed_regs[i]; +exec_batch (fd, handle, do_lrr,sizeof (do_lrr), +I915_EXEC_RENDER , +0 ); + var =__exec_batch_patched (fd, handle, + store_gpr0,sizeof (store_gpr0), +2 *sizeof (uint32_t ));/* reloc */ +igt_assert_neq (var,0xabcdabc0 ); + + } + +for (int i =0 ; i <ARRAY_LEN (disallowed_regs); i++) { +exec_batch (fd, handle, init_gpr0,sizeof (init_gpr0), +I915_EXEC_RENDER , +0 ); +exec_batch_patched (fd, handle, + store_gpr0,sizeof (store_gpr0), +2 *sizeof (uint32_t ),/* reloc */ +0xabcdabc0 ); + do_lrr[1 ] = disallowed_regs[i]; +exec_batch (fd, handle, do_lrr,sizeof (do_lrr), +I915_EXEC_RENDER , +0 ); +exec_batch_patched (fd, handle, + store_gpr0,sizeof (store_gpr0), +2 *sizeof (uint32_t ),/* reloc */ +0xabcdabc0 ); + } + +close (fd); +} -#define GFX_OP_PIPE_CONTROL ((0x3<<29)|(0x3<<27)|(0x2<<24)|2) -#define PIPE_CONTROL_QW_WRITE (1<<14) -#define PIPE_CONTROL_LRI_POST_OP (1<<23) + +uint32_t handle; +int fd; igt_main {
@@ -428,57 +421,93 @@ igt_main } igt_subtest("basic-rejected") { -uint32_t arb_on_off[] = { -MI_ARB_ON_OFF , +uint32_t invalid_cmd[] = { + (0x7 <<29 ),/* Reserved command type, +across all engines */ MI_BATCH_BUFFER_END , }; -uint32_t display_flip[] = { -MI_DISPLAY_FLIP , -0 ,0 ,0 , +uint32_t invalid_set_context[] = { +MI_SET_CONTEXT |32 ,/* invalid length */ MI_BATCH_BUFFER_END , -0 };exec_batch (fd, handle, - arb_on_off,sizeof (arb_on_off), + invalid_cmd,sizeof (invalid_cmd),I915_EXEC_RENDER , -EINVAL );exec_batch (fd, handle, - arb_on_off,sizeof (arb_on_off), + invalid_cmd,sizeof (invalid_cmd),I915_EXEC_BSD , -EINVAL ); +exec_batch (fd, handle, + invalid_cmd,sizeof (invalid_cmd), +I915_EXEC_BLT , + -EINVAL );if (gem_has_vebox (fd)) { -exec_batch (fd, handle, - arb_on_off,sizeof (arb_on_off), -I915_EXEC_VEBOX , - -EINVAL ); +exec_batch (fd, handle, + invalid_cmd,sizeof (invalid_cmd), +I915_EXEC_BLT , + -EINVAL ); } +exec_batch (fd, handle, - display_flip,sizeof (display_flip), -I915_EXEC_BLT , + invalid_set_context,sizeof (invalid_set_context), +I915_EXEC_RENDER , -EINVAL ); } igt_subtest("registers") { -uint32_t lri_bad[] = { -MI_LOAD_REGISTER_IMM , -0 ,/* disallowed register address */ -0x12000000 , -MI_BATCH_BUFFER_END , - }; +uint32_t lri_bad[] = { +MI_LOAD_REGISTER_IMM , +OACONTROL ,/* disallowed register address */ +0x31337000 , +MI_BATCH_BUFFER_END , + };uint32_t lri_ok[] = { -MI_LOAD_REGISTER_IMM , -0x5280 ,/* allowed register address (SO_WRITE_OFFSET[0]) */ -0x1 , +MI_LOAD_REGISTER_IMM | (3 -2 ), +SO_WRITE_OFFSET_0 ,/* allowed register address */ +0xabcdabc0 ,/* [1:0] MBZ */ MI_BATCH_BUFFER_END , }; -exec_batch (fd, handle, - lri_bad,sizeof (lri_bad), -I915_EXEC_RENDER , - -EINVAL ); -exec_batch (fd, handle, - lri_ok,sizeof (lri_ok), -I915_EXEC_RENDER , -0 ); +uint32_t store_reg[] = { +MI_STORE_REGISTER_MEM | (3 -2 ), +0 ,/* reg */ +0 ,/* reloc */ +MI_BATCH_BUFFER_END , + }; +uint64_t val; + +/* Note: we intentionally pick OACONTROL as the disallowed +* register to test here since it used to be white listed by +* the command parser. +* +* It's especially important to check that an LRI to OACONTROL +* doesn't result in an EINVAL error because Mesa attempts +* writing to OACONTROL to determine what extensions to expose +* and will abort() for execbuffer() errors. +* +* Mesa can gracefully recognise and handle the LRI becoming +* a NOOP. +*/ +exec_batch (fd, handle, + lri_bad,sizeof (lri_bad), +I915_EXEC_RENDER , +0 ); + store_reg[1 ] =OACONTROL ; + val =__exec_batch_patched (fd, handle, + store_reg,sizeof (store_reg), +8 );/* reloc offset */ +igt_assert_neq (val,0x31337000 ); + +exec_batch (fd, handle, + lri_ok,sizeof (lri_ok), +I915_EXEC_RENDER , +0 ); + store_reg[1 ] =SO_WRITE_OFFSET_0 ; +exec_batch_patched (fd, handle, + store_reg, +sizeof (store_reg), +2 *sizeof (uint32_t ),/* reloc offset */ +0xabcdabc0 ); } igt_subtest("bitmasks") {
@@ -491,10 +520,13 @@ igt_main0 , MI_BATCH_BUFFER_END, }; -exec_batch (fd, handle, - pc,sizeof (pc), -I915_EXEC_RENDER , - -EINVAL ); +/* Expect to read back zero since the command should be +* squashed to a NOOP +*/ +exec_batch_patched (fd, handle, + pc,sizeof (pc), +8 ,/* patch offset, */ +0x0 ); } igt_subtest("batch-without-end") {
Signature · 6 lines
2.10.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 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
@@ -450,7 +450,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),
@@ -1060,8 +1059,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_SKIP )return true;
@@ -1099,31 +1097,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. */
@@ -1214,7 +1187,6 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,u32 *cmd, *batch_end;struct drm_i915_cmd_descriptor default_desc = noop_desc;const struct drm_i915_cmd_descriptor *desc = &default_desc; -bool oacontrol_set = false;/* OACONTROL tracking. See check_cmd() */ bool needs_clflush_after = false;int ret =0 ;
@@ -1270,8 +1242,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 ; }
@@ -1279,11 +1250,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.10.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 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 | 144 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_oa_hsw.h | 34 +++++++++ 4 files changed, 194 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
@@ -114,7 +114,8 @@ i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.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
@@ -1760,6 +1760,11 @@ struct intel_wm_config {bool sprites_scaled; }; +struct i915_oa_reg { +i915_reg_t addr; +u32 value; +}; +struct i915_perf_stream ;struct i915_perf_stream_ops {
@@ -2142,6 +2147,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 +144 -0
144 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.10.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 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.
v2:
Make sure to initialize ->specific_ctx_id when opening, without relying on _pin_notify hook, in case ctx already pinned.
factor out init_specific_ctx_id func
--- drivers/gpu/drm/i915/i915_drv.h | 72 ++- drivers/gpu/drm/i915/i915_gem_context.c | 22 +- drivers/gpu/drm/i915/i915_perf.c | 1034 ++++++++++++++++++++++++++++++- drivers/gpu/drm/i915/i915_reg.h | 338 ++++++++++ drivers/gpu/drm/i915/intel_ringbuffer.c | 11 +- include/uapi/drm/i915_drm.h | 70 ++- 6 files changed, 1515 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +62 -10
@@ -1760,6 +1760,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;
@@ -1780,11 +1785,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 */
@@ -1794,9 +1794,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);
@@ -1836,11 +1834,28 @@ 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, +char __user *buf, +size_t count, +size_t *offset); +bool (*oa_buffer_is_empty)(struct drm_i915_private *dev_priv); };struct drm_i915_private {
@@ -2145,16 +2160,48 @@ 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; +struct i915_vma *vma; +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;
@@ -3525,6 +3572,9 @@ 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, +u64 flags);static inline struct i915_gem_context *i915_gem_context_lookup (struct drm_i915_file_private *file_priv,u32 id)
@@ -3571,6 +3621,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 i915_address_space *vm,
drivers/gpu/drm/i915/i915_gem_context.c +21 -1
@@ -134,6 +134,25 @@ 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, +u64 flags) +{ +int ret; + +lockdep_assert_held (&ctx->i915->drm.struct_mutex); + + ret =i915_vma_pin (ctx->engine[RCS ].state,0 , + ctx->ggtt_alignment, + flags); +if (ret) +return ret; + +i915_oa_legacy_context_pin_notify (dev_priv, ctx); + +return 0 ; +} +void i915_gem_context_free (struct kref *ctx_ref) {struct i915_gem_context *ctx =container_of (ctx_ref,typeof (*ctx), ref);
@@ -772,7 +791,8 @@ static int do_rcs_switch(struct drm_i915_gem_request *req) }/* Trying to pin first makes error handling easier. */ - ret =i915_vma_pin (vma,0 , to->ggtt_alignment,PIN_GLOBAL ); + ret =i915_gem_context_pin_legacy_rcs_state (engine->i915, to, +PIN_GLOBAL );if (ret)return ret;
drivers/gpu/drm/i915/i915_perf.c +1017 -17
1,108 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 +9 -2
@@ -1985,12 +1985,19 @@ static int intel_ring_context_pin(struct i915_gem_context *ctx,return 0 ;if (ce->state) { +u64 vma_flags =PIN_GLOBAL |PIN_HIGH ; + ret =i915_gem_object_set_to_gtt_domain (ce->state->obj, false);if (ret) goto error; - ret =i915_vma_pin (ce->state,0 , ctx->ggtt_alignment, -PIN_GLOBAL |PIN_HIGH ); +if (engine->id ==RCS ) { + ret =i915_gem_context_pin_legacy_rcs_state (engine->i915, + ctx, + vma_flags); + }else + ret =i915_vma_pin (ce->state,0 , ctx->ggtt_alignment, + vma_flags);if (ret) goto error; }
include/uapi/drm/i915_drm.h +68 -2
104 lines not on this page · raw message
Signature · 6 lines
2.10.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v6 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit
drivers/gpu/drm/i915/i915_gem_context.c static int get_context_size(struct drm_i915_private *dev_priv) · line 139
Quoted 3 lines · Robert Bragg
drivers/gpu/drm/i915/i915_gem_context.c +3
-0+int i915_gem_context_pin_legacy_rcs_state (struct drm_i915_private *dev_priv, +struct i915_gem_context *ctx, +u64 flags)
This is still no.
Quoted 27 lines
drivers/gpu/drm/i915/i915_perf.c +27
-0+static int alloc_oa_buffer (struct drm_i915_private *dev_priv) +{ +struct drm_i915_gem_object *bo; +enum i915_map_type map; +struct i915_vma *vma; +int ret; + +BUG_ON (dev_priv->perf.oa.oa_buffer.obj); + + ret =i915_mutex_lock_interruptible (&dev_priv->drm); +if (ret) +return ret; + +BUILD_BUG_ON_NOT_POWER_OF_2 (OA_BUFFER_SIZE ); +BUILD_BUG_ON (OA_BUFFER_SIZE <SZ_128K ||OA_BUFFER_SIZE >SZ_16M ); + + bo =i915_gem_object_create (&dev_priv->drm,OA_BUFFER_SIZE ); +if (IS_ERR (bo)) { +DRM_ERROR ("Failed to allocate OA buffer\n" ); + ret =PTR_ERR (bo); + goto unlock; + } + dev_priv->perf.oa.oa_buffer.obj = bo; + + ret =i915_gem_object_set_cache_level (bo,I915_CACHE_LLC ); +if (ret) + goto err_unref;
drivers/gpu/drm/i915/i915_perf.c line 565
Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +10
-0+ +/* PreHSW required 512K alignment, HSW requires 16M */ + vma =i915_gem_object_ggtt_pin (bo,NULL ,0 ,SZ_16M ,PIN_MAPPABLE ); +if (IS_ERR (vma)) { + ret =PTR_ERR (vma); + goto err_unref; + } + dev_priv->perf.oa.oa_buffer.vma = vma; + + map =HAS_LLC (dev_priv) ?I915_MAP_WB :I915_MAP_WC ;
You set the hw up to do coherent writes into the CPU cache, and then you request WC access to the pages? With set_cache_level(LLC) you can use MAP_WB on both llc and snoop based architectures. Fortunately this is only HSW!
drivers/gpu/drm/i915/i915_perf.c line 567
Quoted 1 line
drivers/gpu/drm/i915/i915_perf.c +1
-0+ dev_priv->perf.oa.oa_buffer.gtt_offset =i915_ggtt_offset (vma);
I haven't spotted the advantage of storing both the ggtt_offset in addition to the vma (or the bo as well as the vma).
Quoted 5 lines
drivers/gpu/drm/i915/i915_perf.c +5
-0+ dev_priv->perf.oa.oa_buffer.addr =i915_gem_object_pin_map (bo, map); +if (IS_ERR (dev_priv->perf.oa.oa_buffer.addr)) { + ret =PTR_ERR (dev_priv->perf.oa.oa_buffer.addr); + goto err_unpin; + }
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 v6 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit
Quoted 8 lines · Chris Wilson
Quoted 1 line · Robert Bragg
+int i915_gem_context_pin_legacy_rcs_state(struct
drm_i915_private
*dev_priv,drivers/gpu/drm/i915/i915_gem_context.c static int get_context_size(struct drm_i915_private *dev_priv) · line 139
Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_context.c +2
-0+struct i915_gem_context *ctx, + u64 flags)This is still no.
Okay, but it's a little frustrating for me to go in circles here :-/
I didn't originally do it this way; I originally looked at pinning the context when opening the stream so I didn't have to consider it being relocated. The feedback from Daniel Vetter was to look at doing it this way I think because of some concern to do with some shrinker corner cases.
... just dug up the archive:
https://lists.freedesktop.org/archives/intel-gfx/2014-November/055385.html
Can you maybe please explain what's wrong with the current approach and provide some justification for a different approach with some reassurance that Daniel's original concern with the shrinker unpinning contexts isn't actually a problem? I don't currently understand the concern with this, and this approach seems to have been working well for quite a long time now.
- Robert
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH v6 06/11] drm/i915: Enable i915 perf stream for Haswell OA unit
In reply to Chris WilsonQuoted 42 lines · Chris Wilson
Quoted 1 line · Robert Bragg
+int i915_gem_context_pin_legacy_rcs_state(struct
drm_i915_private
*dev_priv,drivers/gpu/drm/i915/i915_gem_context.c static int get_context_size(struct drm_i915_private *dev_priv) · line 139
Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_context.c +2
-0+struct i915_gem_context *ctx, + u64 flags)This is still no.
Quoted 34 lines
drivers/gpu/drm/i915/i915_perf.c +34
-0+static int alloc_oa_buffer (struct drm_i915_private *dev_priv) +{ +struct drm_i915_gem_object *bo; +enum i915_map_type map; +struct i915_vma *vma; +int ret; + +BUG_ON (dev_priv->perf.oa.oa_buffer.obj); + + ret =i915_mutex_lock_interruptible (&dev_priv->drm); +if (ret) +return ret; + +BUILD_BUG_ON_NOT_POWER_OF_2 (OA_BUFFER_SIZE ); +BUILD_BUG_ON (OA_BUFFER_SIZE <SZ_128K ||OA_BUFFER_SIZE >SZ_16M ); + + bo =i915_gem_object_create (&dev_priv->drm,OA_BUFFER_SIZE ); +if (IS_ERR (bo)) { +DRM_ERROR ("Failed to allocate OA buffer\n" ); + ret =PTR_ERR (bo); + goto unlock; + } + dev_priv->perf.oa.oa_buffer.obj = bo; + + ret =i915_gem_object_set_cache_level (bo,I915_CACHE_LLC ); +if (ret) + goto err_unref; + +/* PreHSW required 512K alignment, HSW requires 16M */ + vma =i915_gem_object_ggtt_pin (bo,NULL ,0 ,SZ_16M ,PIN_MAPPABLE ); +if (IS_ERR (vma)) { + ret =PTR_ERR (vma); + goto err_unref; + }
Quoted 9 lines
drivers/gpu/drm/i915/i915_perf.c line 565
Quoted 3 lines
drivers/gpu/drm/i915/i915_perf.c +3
-0+ dev_priv->perf.oa.oa_buffer.vma = vma; + + map =HAS_LLC (dev_priv) ?I915_MAP_WB :I915_MAP_WC ;You set the hw up to do coherent writes into the CPU cache, and then you request WC access to the pages? With
set_cache_level(LLC)you can useMAP_WBon both llc and snoop based architectures. Fortunately this is only HSW!
hmm, yeah it looks like I unwittingly added this recently as part of a rebase, I think from lazily copying some similar code from intel_ringbuffer.c when I hit a conflict, without thinking more carefully, sorry.
Quoted 6 lines
Quoted 2 lines
+
dev_priv->perf.oa.oa_buffer.gtt_offset=i915_ggtt_offset(vma);I haven't spotted the advantage of storing both the
ggtt_offsetin addition to the vma (or the bo as well as the vma).
right, it looks like this can be cleaned up.
Quoted 11 lines
Quoted 2 lines
+
dev_priv->perf.oa.oa_buffer.addr= i915_gem_object_pin_map(bo,map);
drivers/gpu/drm/i915/i915_perf.c line 572
Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +4
-0+if (IS_ERR (dev_priv->perf.oa.oa_buffer.addr)) { + ret =PTR_ERR (dev_priv->perf.oa.oa_buffer.addr); + goto err_unpin; + }--
Chris Wilson, Intel Open Source Technology Centre
Thanks,
- Robert
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/1 drm/i915: Enable i915 perf stream for Haswell OA unit
Gen 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.
v2:
Make sure to initialize ->specific_ctx_id when opening, without relying on _pin_notify hook, in case ctx already pinned.
--- drivers/gpu/drm/i915/i915_drv.h | 70 ++- drivers/gpu/drm/i915/i915_gem_context.c | 22 +- drivers/gpu/drm/i915/i915_perf.c | 1028 ++++++++++++++++++++++++++++++- drivers/gpu/drm/i915/i915_reg.h | 338 ++++++++++ drivers/gpu/drm/i915/intel_ringbuffer.c | 11 +- include/uapi/drm/i915_drm.h | 70 ++- 6 files changed, 1507 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +60 -10
@@ -1760,6 +1760,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;
@@ -1780,11 +1785,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 */
@@ -1794,9 +1794,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);
@@ -1836,11 +1834,28 @@ 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, +char __user *buf, +size_t count, +size_t *offset); +bool (*oa_buffer_is_empty)(struct drm_i915_private *dev_priv); };struct drm_i915_private {
@@ -2145,16 +2160,46 @@ 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 i915_vma *vma; +u8 *vaddr; +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;
@@ -3525,6 +3570,9 @@ 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, +u64 flags);static inline struct i915_gem_context *i915_gem_context_lookup (struct drm_i915_file_private *file_priv,u32 id)
@@ -3571,6 +3619,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 i915_address_space *vm,
drivers/gpu/drm/i915/i915_gem_context.c +21 -1
@@ -134,6 +134,25 @@ 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, +u64 flags) +{ +int ret; + +lockdep_assert_held (&ctx->i915->drm.struct_mutex); + + ret =i915_vma_pin (ctx->engine[RCS ].state,0 , + ctx->ggtt_alignment, + flags); +if (ret) +return ret; + +i915_oa_legacy_context_pin_notify (dev_priv, ctx); + +return 0 ; +} +void i915_gem_context_free (struct kref *ctx_ref) {struct i915_gem_context *ctx =container_of (ctx_ref,typeof (*ctx), ref);
@@ -772,7 +791,8 @@ static int do_rcs_switch(struct drm_i915_gem_request *req) }/* Trying to pin first makes error handling easier. */ - ret =i915_vma_pin (vma,0 , to->ggtt_alignment,PIN_GLOBAL ); + ret =i915_gem_context_pin_legacy_rcs_state (engine->i915, to, +PIN_GLOBAL );if (ret)return ret;
drivers/gpu/drm/i915/i915_perf.c +1011 -17
1,102 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 +9 -2
@@ -1985,12 +1985,19 @@ static int intel_ring_context_pin(struct i915_gem_context *ctx,return 0 ;if (ce->state) { +u64 vma_flags =PIN_GLOBAL |PIN_HIGH ; + ret =i915_gem_object_set_to_gtt_domain (ce->state->obj, false);if (ret) goto error; - ret =i915_vma_pin (ce->state,0 , ctx->ggtt_alignment, -PIN_GLOBAL |PIN_HIGH ); +if (engine->id ==RCS ) { + ret =i915_gem_context_pin_legacy_rcs_state (engine->i915, + ctx, + vma_flags); + }else + ret =i915_vma_pin (ce->state,0 , ctx->ggtt_alignment, + vma_flags);if (ret) goto error; }
include/uapi/drm/i915_drm.h +68 -2
104 lines not on this page · raw message
Signature · 6 lines
2.10.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 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.c | 5 ++++ drivers/gpu/drm/i915/i915_drv.h | 4 +++ drivers/gpu/drm/i915/i915_oa_hsw.c | 51 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_oa_hsw.h | 4 +++ drivers/gpu/drm/i915/i915_perf.c | 52 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +5 -0
@@ -1115,6 +1115,9 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)if (drm_dev_register (dev,0 ) ==0 ) {i915_debugfs_register (dev_priv);i915_setup_sysfs (dev_priv); + +/* Depends on sysfs having been initialized */ +i915_perf_register (dev_priv); }else DRM_ERROR ("Failed to register driver for userspace access!\n" );
@@ -1151,6 +1154,8 @@ static void i915_driver_unregister(struct drm_i915_private *dev_priv)acpi_video_unregister ();intel_opregion_unregister (dev_priv); +i915_perf_unregister (dev_priv); +i915_teardown_sysfs (dev_priv);i915_debugfs_unregister (dev_priv);drm_dev_unregister (&dev_priv->drm);
drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -2161,6 +2161,8 @@ struct drm_i915_private {struct {bool initialized; +struct kobject *metrics_kobj; +struct mutex lock;struct list_head streams;
@@ -3752,6 +3754,8 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,/* 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); +extern void i915_perf_register (struct drm_i915_private *dev_priv); +extern void i915_perf_unregister (struct drm_i915_private *dev_priv);/* i915_suspend.c */ extern int i915_save_state (struct drm_device *dev);
drivers/gpu/drm/i915/i915_oa_hsw.c +51 -0
60 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_register_sysfs_hsw (struct drm_i915_private *dev_priv); + +extern void i915_perf_unregister_sysfs_hsw (struct drm_i915_private *dev_priv); +#endif
drivers/gpu/drm/i915/i915_perf.c +52 -0
64 lines not on this page · raw message
Signature · 6 lines
2.10.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 8/11 drm/i915: Add dev.i915.perf_stream_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 | 50 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -2162,6 +2162,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 +49 -1
80 lines not on this page · raw message
Signature · 6 lines
2.10.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v6 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 | 41 ++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +29 -12
@@ -82,6 +82,22 @@ static u32 i915_perf_stream_paranoid = true;#define INVALID_CTX_ID 0xffffffff +/* for sysctl proc_dointvec_minmax of i915_oa_min_timer_exponent */ +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.
@@ -1349,21 +1365,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 ; }
@@ -1471,6 +1479,15 @@ static struct ctl_table oa_table[] = { .extra1 = &zero, .extra2 = &one, }, + { + .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.10.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 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 | 559 ++++++++++++++++++++++++++++++++++++- 1 file changed, 558 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_oa_hsw.c +558 -1
@@ -31,9 +31,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 },
@@ -112,6 +117,298 @@ get_render_basic_mux_config(struct drm_i915_private *dev_priv,return mux_config_render_basic; } +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 const struct i915_oa_reg * +get_compute_basic_mux_config (struct drm_i915_private *dev_priv, +int *len) +{ + *len =ARRAY_SIZE (mux_config_compute_basic); +return mux_config_compute_basic; +} + +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 const struct i915_oa_reg * +get_compute_extended_mux_config (struct drm_i915_private *dev_priv, +int *len) +{ + *len =ARRAY_SIZE (mux_config_compute_extended); +return mux_config_compute_extended; +} + +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 const struct i915_oa_reg * +get_memory_reads_mux_config (struct drm_i915_private *dev_priv, +int *len) +{ + *len =ARRAY_SIZE (mux_config_memory_reads); +return mux_config_memory_reads; +} + +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 const struct i915_oa_reg * +get_memory_writes_mux_config (struct drm_i915_private *dev_priv, +int *len) +{ + *len =ARRAY_SIZE (mux_config_memory_writes); +return mux_config_memory_writes; +} + +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 const struct i915_oa_reg * +get_sampler_balance_mux_config (struct drm_i915_private *dev_priv, +int *len) +{ + *len =ARRAY_SIZE (mux_config_sampler_balance); +return mux_config_sampler_balance; +} +int i915_oa_select_metric_set_hsw (struct drm_i915_private *dev_priv) { dev_priv->perf.oa.mux_regs =NULL ;
@@ -140,6 +437,106 @@ int i915_oa_select_metric_set_hsw(struct drm_i915_private *dev_priv)ARRAY_SIZE (b_counter_config_render_basic);return 0 ; +case METRIC_SET_ID_COMPUTE_BASIC : + dev_priv->perf.oa.mux_regs = +get_compute_basic_mux_config (dev_priv, + &dev_priv->perf.oa.mux_regs_len); +if (!dev_priv->perf.oa.mux_regs) { +DRM_DEBUG_DRIVER ("No suitable MUX config for \"COMPUTE_BASIC\" metric set" ); + +/* EINVAL because *_register_sysfs already checked this +* and so it wouldn't have been advertised so userspace and +* so shouldn't have been requested +*/ +return -EINVAL ; + } + + 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 ; +case METRIC_SET_ID_COMPUTE_EXTENDED : + dev_priv->perf.oa.mux_regs = +get_compute_extended_mux_config (dev_priv, + &dev_priv->perf.oa.mux_regs_len); +if (!dev_priv->perf.oa.mux_regs) { +DRM_DEBUG_DRIVER ("No suitable MUX config for \"COMPUTE_EXTENDED\" metric set" ); + +/* EINVAL because *_register_sysfs already checked this +* and so it wouldn't have been advertised so userspace and +* so shouldn't have been requested +*/ +return -EINVAL ; + } + + 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 ; +case METRIC_SET_ID_MEMORY_READS : + dev_priv->perf.oa.mux_regs = +get_memory_reads_mux_config (dev_priv, + &dev_priv->perf.oa.mux_regs_len); +if (!dev_priv->perf.oa.mux_regs) { +DRM_DEBUG_DRIVER ("No suitable MUX config for \"MEMORY_READS\" metric set" ); + +/* EINVAL because *_register_sysfs already checked this +* and so it wouldn't have been advertised so userspace and +* so shouldn't have been requested +*/ +return -EINVAL ; + } + + 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 ; +case METRIC_SET_ID_MEMORY_WRITES : + dev_priv->perf.oa.mux_regs = +get_memory_writes_mux_config (dev_priv, + &dev_priv->perf.oa.mux_regs_len); +if (!dev_priv->perf.oa.mux_regs) { +DRM_DEBUG_DRIVER ("No suitable MUX config for \"MEMORY_WRITES\" metric set" ); + +/* EINVAL because *_register_sysfs already checked this +* and so it wouldn't have been advertised so userspace and +* so shouldn't have been requested +*/ +return -EINVAL ; + } + + 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 ; +case METRIC_SET_ID_SAMPLER_BALANCE : + dev_priv->perf.oa.mux_regs = +get_sampler_balance_mux_config (dev_priv, + &dev_priv->perf.oa.mux_regs_len); +if (!dev_priv->perf.oa.mux_regs) { +DRM_DEBUG_DRIVER ("No suitable MUX config for \"SAMPLER_BALANCE\" metric set" ); + +/* EINVAL because *_register_sysfs already checked this +* and so it wouldn't have been advertised so userspace and +* so shouldn't have been requested +*/ +return -EINVAL ; + } + + 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 ;default :return -ENODEV ; }
@@ -167,6 +564,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_register_sysfs_hsw (struct drm_i915_private *dev_priv) {
@@ -178,9 +685,49 @@ i915_perf_register_sysfs_hsw(struct drm_i915_private *dev_priv)if (ret) goto error_render_basic; } +if (get_compute_basic_mux_config (dev_priv, &mux_len)) { + ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_compute_basic); +if (ret) + goto error_compute_basic; + } +if (get_compute_extended_mux_config (dev_priv, &mux_len)) { + ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_compute_extended); +if (ret) + goto error_compute_extended; + } +if (get_memory_reads_mux_config (dev_priv, &mux_len)) { + ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_memory_reads); +if (ret) + goto error_memory_reads; + } +if (get_memory_writes_mux_config (dev_priv, &mux_len)) { + ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_memory_writes); +if (ret) + goto error_memory_writes; + } +if (get_sampler_balance_mux_config (dev_priv, &mux_len)) { + ret =sysfs_create_group (dev_priv->perf.metrics_kobj, &group_sampler_balance); +if (ret) + goto error_sampler_balance; + }return 0 ; +error_sampler_balance: +if (get_sampler_balance_mux_config (dev_priv, &mux_len)) +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_memory_writes); +error_memory_writes: +if (get_sampler_balance_mux_config (dev_priv, &mux_len)) +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_memory_reads); +error_memory_reads: +if (get_sampler_balance_mux_config (dev_priv, &mux_len)) +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_compute_extended); +error_compute_extended: +if (get_sampler_balance_mux_config (dev_priv, &mux_len)) +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_compute_basic); +error_compute_basic: +if (get_sampler_balance_mux_config (dev_priv, &mux_len)) +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_render_basic); error_render_basic:return ret; }
@@ -192,4 +739,14 @@ i915_perf_unregister_sysfs_hsw(struct drm_i915_private *dev_priv)if (get_render_basic_mux_config (dev_priv, &mux_len))sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_render_basic); +if (get_compute_basic_mux_config (dev_priv, &mux_len)) +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_compute_basic); +if (get_compute_extended_mux_config (dev_priv, &mux_len)) +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_compute_extended); +if (get_memory_reads_mux_config (dev_priv, &mux_len)) +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_memory_reads); +if (get_memory_writes_mux_config (dev_priv, &mux_len)) +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_memory_writes); +if (get_sampler_balance_mux_config (dev_priv, &mux_len)) +sysfs_remove_group (dev_priv->perf.metrics_kobj, &group_sampler_balance); }
Signature · 6 lines
2.10.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v6 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 losing 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.10.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Patchwork
CI✗ Fi.CI.BAT: failure for series starting with [v6,01/11] drm/i915: Add i915 perf infrastructure
In reply to Robert Bragg== Series Details ==
== Series Details ==
Series: series starting with [v6,01/11] drm/i915: Add i915 perf infrastructure
URL : https://patchwork.freedesktop.org/series/14135/
State : failure
== Summary ==
Series 14135v1 Series without cover letter
https://patchwork.freedesktop.org/api/1.0/series/14135/revisions/1/mbox/
Test drv_module_reload_basic:
dmesg-warn -> PASS (fi-skl-6700hq)
skip -> PASS (fi-skl-6770hq)
Test gem_exec_parse:
Subgroup basic-rejected:
pass -> FAIL (fi-ivb-3770)
pass -> FAIL (fi-byt-j1900)
pass -> FAIL (fi-byt-n2820)
pass -> FAIL (fi-hsw-4770)
pass -> FAIL (fi-hsw-4770r)
pass -> FAIL (fi-ivb-3520m)
Test gem_exec_suspend:
Subgroup basic-s3:
pass -> DMESG-WARN (fi-skl-6700hq)
Test kms_pipe_crc_basic:
Subgroup suspend-read-crc-pipe-a:
pass -> DMESG-WARN (fi-skl-6700hq)
pass -> FAIL (fi-skl-6700k)
Subgroup suspend-read-crc-pipe-b:
pass -> DMESG-WARN (fi-skl-6700hq)
Subgroup suspend-read-crc-pipe-c:
pass -> DMESG-WARN (fi-skl-6700hq)fi-bdw-5557u total:246 pass:231 dwarn:0 dfail:0 fail:0 skip:15 fi-bsw-n3050 total:246 pass:204 dwarn:0 dfail:0 fail:0 skip:42 fi-bxt-t5700 total:246 pass:216 dwarn:0 dfail:0 fail:0 skip:30 fi-byt-j1900 total:246 pass:214 dwarn:0 dfail:0 fail:1 skip:31 fi-byt-n2820 total:246 pass:210 dwarn:0 dfail:0 fail:1 skip:35 fi-hsw-4770 total:246 pass:223 dwarn:0 dfail:0 fail:1 skip:22 fi-hsw-4770r total:246 pass:223 dwarn:0 dfail:0 fail:1 skip:22 fi-ilk-650 total:246 pass:185 dwarn:0 dfail:0 fail:1 skip:60 fi-ivb-3520m total:246 pass:220 dwarn:0 dfail:0 fail:1 skip:25 fi-ivb-3770 total:246 pass:220 dwarn:0 dfail:0 fail:1 skip:25 fi-kbl-7200u total:246 pass:222 dwarn:0 dfail:0 fail:0 skip:24 fi-skl-6260u total:246 pass:232 dwarn:0 dfail:0 fail:0 skip:14 fi-skl-6700hq total:246 pass:219 dwarn:4 dfail:0 fail:0 skip:23 fi-skl-6700k total:246 pass:220 dwarn:1 dfail:0 fail:1 skip:24 fi-skl-6770hq total:246 pass:232 dwarn:0 dfail:0 fail:0 skip:14 fi-snb-2520m total:246 pass:210 dwarn:0 dfail:0 fail:0 skip:36 fi-snb-2600 total:246 pass:209 dwarn:0 dfail:0 fail:0 skip:37
Results at /archive/results/CI_IGT_test/Patchwork_2779/
5113d7495dab3ea4d14a7698368c6be80f6c045c drm-intel-nightly: 2016y-10m-20d-13h-31m-16s UTC integration manifest 1e4473e drm/i915: Add a kerneldoc summary for i915_perf.c
0c023de drm/i915: Add more Haswell OA metric sets
d3bea6a drm/i915: add oa_event_min_timer_exponent sysctl
42e8dc5 drm/i915: Add dev.i915.perf_stream_paranoid sysctl option
8fd324f drm/i915: advertise available metrics via sysfs
86a39c6 drm/i915: Enable i915 perf stream for Haswell OA unit
3838098 drm/i915: Add 'render basic' Haswell OA unit config
77b1c48 drm/i915: don't whitelist oacontrol in cmd parser
18aba00 drm/i915: return EACCES for check_cmd() failures
de403c1 drm/i915: rename OACONTROL GEN7_OACONTROL
4710663 drm/i915: Add i915 perf infrastructure
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.BAT: failure for series starting with [v6,01/11] drm/i915: Add i915 perf infrastructure (rev2)
In reply to Robert Bragg== Series Details ==
== Series Details ==
Series: series starting with [v6,01/11] drm/i915: Add i915 perf infrastructure (rev2)
URL : https://patchwork.freedesktop.org/series/14135/
State : failure
== Summary ==
Series 14135v2 Series without cover letter
https://patchwork.freedesktop.org/api/1.0/series/14135/revisions/2/mbox/
Test drv_module_reload_basic:
pass -> DMESG-WARN (fi-skl-6700hq)
Test gem_exec_parse:
Subgroup basic-rejected:
pass -> FAIL (fi-byt-n2820)
pass -> FAIL (fi-hsw-4770)
pass -> FAIL (fi-ivb-3770)
pass -> FAIL (fi-hsw-4770r)
pass -> FAIL (fi-byt-j1900)
pass -> FAIL (fi-ivb-3520m)
Test gem_exec_suspend:
Subgroup basic-s3:
dmesg-warn -> PASS (fi-skl-6700hq)
Test kms_pipe_crc_basic:
Subgroup suspend-read-crc-pipe-a:
dmesg-warn -> PASS (fi-skl-6700hq)
Subgroup suspend-read-crc-pipe-b:
incomplete -> PASS (fi-snb-2600)
dmesg-warn -> PASS (fi-skl-6700hq)
Subgroup suspend-read-crc-pipe-c:
dmesg-warn -> PASS (fi-skl-6700hq)fi-bdw-5557u total:246 pass:231 dwarn:0 dfail:0 fail:0 skip:15 fi-bsw-n3050 total:246 pass:204 dwarn:0 dfail:0 fail:0 skip:42 fi-bxt-t5700 total:246 pass:216 dwarn:0 dfail:0 fail:0 skip:30 fi-byt-j1900 total:246 pass:214 dwarn:0 dfail:0 fail:1 skip:31 fi-byt-n2820 total:246 pass:210 dwarn:0 dfail:0 fail:1 skip:35 fi-hsw-4770 total:246 pass:223 dwarn:0 dfail:0 fail:1 skip:22 fi-hsw-4770r total:246 pass:223 dwarn:0 dfail:0 fail:1 skip:22 fi-ilk-650 total:246 pass:185 dwarn:0 dfail:0 fail:1 skip:60 fi-ivb-3520m total:246 pass:220 dwarn:0 dfail:0 fail:1 skip:25 fi-ivb-3770 total:246 pass:220 dwarn:0 dfail:0 fail:1 skip:25 fi-kbl-7200u total:246 pass:222 dwarn:0 dfail:0 fail:0 skip:24 fi-skl-6260u total:246 pass:232 dwarn:0 dfail:0 fail:0 skip:14 fi-skl-6700hq total:246 pass:222 dwarn:1 dfail:0 fail:0 skip:23 fi-skl-6700k total:246 pass:222 dwarn:1 dfail:0 fail:0 skip:23 fi-skl-6770hq total:246 pass:232 dwarn:0 dfail:0 fail:0 skip:14 fi-snb-2520m total:246 pass:210 dwarn:0 dfail:0 fail:0 skip:36 fi-snb-2600 total:246 pass:209 dwarn:0 dfail:0 fail:0 skip:37
Results at /archive/results/CI_IGT_test/Patchwork_2793/
872cf096a16c7d7ce37175ed0b902940cec66319 drm-intel-nightly: 2016y-10m-21d-17h-54m-44s UTC integration manifest a8acfb8 drm/i915: Add a kerneldoc summary for i915_perf.c
600220d drm/i915: Add more Haswell OA metric sets
49a3128 drm/i915: add oa_event_min_timer_exponent sysctl
fa8a349 drm/i915: Add dev.i915.perf_stream_paranoid sysctl option
191e190 drm/i915: advertise available metrics via sysfs
d867552 drm/i915: Enable i915 perf stream for Haswell OA unit
61a1dd8 drm/i915: Add 'render basic' Haswell OA unit config
1d92ccf drm/i915: don't whitelist oacontrol in cmd parser
3f9c010 drm/i915: return EACCES for check_cmd() failures
74b7ec3 drm/i915: rename OACONTROL GEN7_OACONTROL
cc44124 drm/i915: Add i915 perf infrastructure
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: ✗ Fi.CI.BAT: failure for series starting with [v6,01/11] drm/i915: Add i915 perf infrastructure (rev2)
Quoted 13 lines
== Series Details ==
Series: series starting with [v6,01/11] drm/i915: Add i915 perf infrastructure (rev2)
URL : https://patchwork.freedesktop.org/series/14135/
State : failure== Summary ==
Series 14135v2 Series without cover letter
https://patchwork.freedesktop.org/api/1.0/series/14135/revisions/2/mbox/Test
drv_module_reload_basic:
Quoted 9 lines
pass -> DMESG-WARN (fi-skl-6700hq)
Test gem_exec_parse:
Subgroup basic-rejected:
pass -> FAIL (fi-byt-n2820)
pass -> FAIL (fi-hsw-4770)
pass -> FAIL (fi-ivb-3770)
pass -> FAIL (fi-hsw-4770r)
pass -> FAIL (fi-byt-j1900)
pass -> FAIL (fi-ivb-3520m)Stdout
IGT-Version: 1.16-gf7408bf (x86_64) (Linux: 4.9.0-rc1-CI-Patchwork_2793+ x86_64) Stack trace:
#0 [__igt_fail_assert+0x101]
#1 [__real_main398+0x1468]
#2 [main+0x30]
Subtest basic-rejected: FAIL (0.003s)
Stderr
(gem_exec_parse:8528) CRITICAL: Test assertion failure function __real_main398, file gem_exec_parse.c:449:
(gem_exec_parse:8528) CRITICAL: Failed assertion: __exec_batch(fd, handle, arb_on_off, sizeof(arb_on_off), (1<<0)) == -22 (gem_exec_parse:8528) CRITICAL: error: 0 != -22
Subtest basic-rejected failed.
**** DEBUG ****
(gem_exec_parse:8528) CRITICAL: Test assertion failure function __real_main398, file gem_exec_parse.c:449:
(gem_exec_parse:8528) CRITICAL: Failed assertion: __exec_batch(fd, handle, arb_on_off, sizeof(arb_on_off), (1<<0)) == -22 (gem_exec_parse:8528) CRITICAL: error: 0 != -22
**** END ****
Quoted 32 lines
Test
gem_exec_suspend:Subgroup basic-s3: dmesg-warn -> PASS (fi-skl-6700hq) Test kms_pipe_crc_basic: Subgroup suspend-read-crc-pipe-a: dmesg-warn -> PASS (fi-skl-6700hq) Subgroup suspend-read-crc-pipe-b: incomplete -> PASS (fi-snb-2600) dmesg-warn -> PASS (fi-skl-6700hq) Subgroup suspend-read-crc-pipe-c: dmesg-warn -> PASS (fi-skl-6700hq)fi-bdw-5557u total:246 pass:231 dwarn:0 dfail:0 fail:0 skip:15 fi-bsw-n3050 total:246 pass:204 dwarn:0 dfail:0 fail:0 skip:42 fi-bxt-t5700 total:246 pass:216 dwarn:0 dfail:0 fail:0 skip:30 fi-byt-j1900 total:246 pass:214 dwarn:0 dfail:0 fail:1 skip:31 fi-byt-n2820 total:246 pass:210 dwarn:0 dfail:0 fail:1 skip:35 fi-hsw-4770 total:246 pass:223 dwarn:0 dfail:0 fail:1 skip:22 fi-hsw-4770r total:246 pass:223 dwarn:0 dfail:0 fail:1 skip:22 fi-ilk-650 total:246 pass:185 dwarn:0 dfail:0 fail:1 skip:60 fi-ivb-3520m total:246 pass:220 dwarn:0 dfail:0 fail:1 skip:25 fi-ivb-3770 total:246 pass:220 dwarn:0 dfail:0 fail:1 skip:25 fi-kbl-7200u total:246 pass:222 dwarn:0 dfail:0 fail:0 skip:24 fi-skl-6260u total:246 pass:232 dwarn:0 dfail:0 fail:0 skip:14 fi-skl-6700hq total:246 pass:222 dwarn:1 dfail:0 fail:0 skip:23 fi-skl-6700k total:246 pass:222 dwarn:1 dfail:0 fail:0 skip:23 fi-skl-6770hq total:246 pass:232 dwarn:0 dfail:0 fail:0 skip:14 fi-snb-2520m total:246 pass:210 dwarn:0 dfail:0 fail:0 skip:36 fi-snb-2600 total:246 pass:209 dwarn:0 dfail:0 fail:0 skip:37Results at /archive/results/CI_IGT_test/Patchwork_2793/
Quoted 14 lines
872cf096a16c7d7ce37175ed0b902940cec66319drm-intel-nightly: 2016y-10m- 21d-17h-54m-44s UTC integration manifest
a8acfb8 drm/i915: Add a kerneldoc summary fori915_perf.c600220d drm/i915:
Add more Haswell OA metric sets
49a3128 drm/i915: addoa_event_min_timer_exponentsysctl
fa8a349 drm/i915: Add dev.i915.perf_stream_paranoid sysctl option 191e190 drm/i915: advertise available metrics via sysfs
d867552 drm/i915: Enable i915 perf stream for Haswell OA unit 61a1dd8 drm/i915: Add 'render basic' Haswell OA unit config 1d92ccf drm/i915:
don't whitelist oacontrol in cmd parser
3f9c010 drm/i915: return EACCES forcheck_cmd()failures
74b7ec3 drm/i915: rename OACONTROLGEN7_OACONTROL
cc44124 drm/i915: Add i915 perf infrastructure
Jani Saarinen
Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx