From patchwork Mon Jan 15 14:41:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lionel Landwerlin X-Patchwork-Id: 10164615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 99C33601C0 for ; Mon, 15 Jan 2018 14:42:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A52E284B9 for ; Mon, 15 Jan 2018 14:42:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7ECBD2850E; Mon, 15 Jan 2018 14:42:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CC74E284B9 for ; Mon, 15 Jan 2018 14:42:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 373CD6E113; Mon, 15 Jan 2018 14:42:15 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id DEBFA6E10F for ; Mon, 15 Jan 2018 14:42:10 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2018 06:42:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,364,1511856000"; d="scan'208";a="10281980" Received: from napetrov-mobl1.ccr.corp.intel.com (HELO delly.ger.corp.intel.com) ([10.252.2.50]) by fmsmga007.fm.intel.com with ESMTP; 15 Jan 2018 06:42:09 -0800 From: Lionel Landwerlin To: intel-gfx@lists.freedesktop.org Date: Mon, 15 Jan 2018 14:41:59 +0000 Message-Id: <20180115144159.25913-7-lionel.g.landwerlin@intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180115144159.25913-1-lionel.g.landwerlin@intel.com> References: <20180115144159.25913-1-lionel.g.landwerlin@intel.com> Subject: [Intel-gfx] [PATCH v4 6/6] drm/i915: expose rcs topology through query uAPI X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP With the introduction of asymmetric slices in CNL, we cannot rely on the previous SUBSLICE_MASK getparam to tell userspace what subslices are available. Here we introduce a more detailed way of querying the Gen's GPU topology that doesn't aggregate numbers. This is essential for monitoring parts of the GPU with the OA unit, because counters need to be normalized to the number of EUs/subslices/slices. The current aggregated numbers like EU_TOTAL do not gives us sufficient information. As a bonus we can draw representations of the GPU : https://imgur.com/a/vuqpa v2: Rename uapi struct s/_mask/_info/ (Tvrtko) Report max_slice/subslice/eus_per_subslice rather than strides (Tvrtko) Add uapi macros to read data from *_info structs (Tvrtko) v3: Use !!(v & DRM_I915_BIT()) for uapi macros instead of custom shifts (Tvrtko) Signed-off-by: Lionel Landwerlin --- drivers/gpu/drm/i915/i915_query.c | 134 ++++++++++++++++++++++++++++++++++++++ include/uapi/drm/i915_drm.h | 53 +++++++++++++++ 2 files changed, 187 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c index 5694cfea4553..465ec18a472f 100644 --- a/drivers/gpu/drm/i915/i915_query.c +++ b/drivers/gpu/drm/i915/i915_query.c @@ -25,8 +25,129 @@ #include "i915_drv.h" #include +static int query_slices_info(struct drm_i915_private *dev_priv, + struct drm_i915_query_item *query_item) +{ + const struct sseu_dev_info *sseu = &INTEL_INFO(dev_priv)->sseu; + struct drm_i915_query_slices_info slices_info; + u32 data_length, length; + + if (sseu->max_slices == 0) + return -ENODEV; + + data_length = sizeof(sseu->slice_mask); + length = sizeof(slices_info) + data_length; + + /* + * If we ever change the internal slice mask data type, we'll need to + * update this function. + */ + BUILD_BUG_ON(sizeof(u8) != sizeof(sseu->slice_mask)); + + if (query_item->length == 0) { + query_item->length = length; + return 0; + } + + if (query_item->length != length) + return -EINVAL; + + memset(&slices_info, 0, sizeof(slices_info)); + slices_info.max_slices = sseu->max_slices; + + if (copy_to_user(u64_to_user_ptr(query_item->data_ptr), &slices_info, + sizeof(slices_info))) + return -EFAULT; + + if (copy_to_user(u64_to_user_ptr(query_item->data_ptr + + offsetof(struct drm_i915_query_slices_info, data)), + &sseu->slice_mask, data_length)) + return -EFAULT; + + return 0; +} + +static int query_subslices_info(struct drm_i915_private *dev_priv, + struct drm_i915_query_item *query_item) +{ + const struct sseu_dev_info *sseu = &INTEL_INFO(dev_priv)->sseu; + struct drm_i915_query_subslices_info subslices_info; + u32 data_length, length; + + if (sseu->max_slices == 0) + return -ENODEV; + + memset(&subslices_info, 0, sizeof(subslices_info)); + subslices_info.max_slices = sseu->max_slices; + subslices_info.max_subslices = sseu->max_subslices; + + data_length = subslices_info.max_slices * + DIV_ROUND_UP(subslices_info.max_subslices, + sizeof(sseu->subslice_mask[0]) * BITS_PER_BYTE); + length = sizeof(subslices_info) + data_length; + + if (query_item->length == 0) { + query_item->length = length; + return 0; + } + + if (query_item->length != length) + return -EINVAL; + + if (copy_to_user(u64_to_user_ptr(query_item->data_ptr), &subslices_info, + sizeof(subslices_info))) + return -EFAULT; + + if (copy_to_user(u64_to_user_ptr(query_item->data_ptr + + offsetof(struct drm_i915_query_subslices_info, data)), + sseu->subslice_mask, data_length)) + return -EFAULT; + + return 0; +} + +static int query_eus_info(struct drm_i915_private *dev_priv, + struct drm_i915_query_item *query_item) +{ + const struct sseu_dev_info *sseu = &INTEL_INFO(dev_priv)->sseu; + struct drm_i915_query_eus_info eus_info; + u32 data_length, length; + + if (sseu->max_slices == 0) + return -ENODEV; + + memset(&eus_info, 0, sizeof(eus_info)); + eus_info.max_slices = sseu->max_slices; + eus_info.max_subslices = sseu->max_subslices; + eus_info.max_eus_per_subslice = sseu->max_eus_per_subslice; + + data_length = eus_info.max_slices * eus_info.max_subslices * + DIV_ROUND_UP(eus_info.max_eus_per_subslice, BITS_PER_BYTE); + length = sizeof(eus_info) + data_length; + + if (query_item->length == 0) { + query_item->length = length; + return 0; + } + + if (query_item->length != length) + return -EINVAL; + + if (copy_to_user(u64_to_user_ptr(query_item->data_ptr), &eus_info, + sizeof(eus_info))) + return -EFAULT; + + if (copy_to_user(u64_to_user_ptr(query_item->data_ptr + + offsetof(struct drm_i915_query_eus_info, data)), + sseu->eu_mask, data_length)) + return -EFAULT; + + return 0; +} + int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file) { + struct drm_i915_private *dev_priv = to_i915(dev); struct drm_i915_query *args = data; struct drm_i915_query_item __user *user_item_ptr = u64_to_user_ptr(args->items_ptr); @@ -34,15 +155,28 @@ int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file) for (i = 0; i < args->num_items; i++, user_item_ptr++) { struct drm_i915_query_item item; + int ret; if (copy_from_user(&item, user_item_ptr, sizeof(item))) return -EFAULT; switch (item.query_id) { + case DRM_I915_QUERY_ID_SLICES_INFO: + ret = query_slices_info(dev_priv, &item); + break; + case DRM_I915_QUERY_ID_SUBSLICES_INFO: + ret = query_subslices_info(dev_priv, &item); + break; + case DRM_I915_QUERY_ID_EUS_INFO: + ret = query_eus_info(dev_priv, &item); + break; default: return -EINVAL; } + if (ret) + return ret; + if (copy_to_user(user_item_ptr, &item, sizeof(item))) return -EFAULT; } diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h index 39e93f10f2cd..d25f21e3c107 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -1618,6 +1618,9 @@ struct drm_i915_perf_oa_config { struct drm_i915_query_item { __u64 query_id; +#define DRM_I915_QUERY_ID_SLICES_INFO 0x01 +#define DRM_I915_QUERY_ID_SUBSLICES_INFO 0x02 +#define DRM_I915_QUERY_ID_EUS_INFO 0x03 /* * When set to zero by userspace, this is filled with the size of the @@ -1644,6 +1647,56 @@ struct drm_i915_query { __u64 items_ptr; }; +#define DRM_I915_BIT(bit) (1 << (bit)) + +/* Data written by the kernel with query DRM_I915_QUERY_ID_SLICES_INFO : + * + * data: each bit indicates whether a slice is available (1) or fused off (0). + * Use DRM_I915_QUERY_SLICE_AVAILABLE() to query a given slice's + * availability. + */ +struct drm_i915_query_slices_info { + __u32 max_slices; + +#define DRM_I915_QUERY_SLICE_AVAILABLE(info, slice) \ + !!((info)->data[(slice) / 8] & DRM_I915_BIT((slice) % 8)) + __u8 data[]; +}; + +/* Data written by the kernel with query DRM_I915_QUERY_ID_SUBSLICES_INFO : + * + * data: each bit indicates whether a subslice is available (1) or fused off + * (0). Use DRM_I915_QUERY_SUBSLICE_AVAILABLE() to query a given + * subslice's availability. + */ +struct drm_i915_query_subslices_info { + __u32 max_slices; + __u32 max_subslices; + +#define DRM_I915_QUERY_SUBSLICE_AVAILABLE(info, slice, subslice) \ + !!((info)->data[(slice) * ALIGN((info)->max_subslices, 8) / 8 + \ + (subslice) / 8] & DRM_I915_BIT((subslice) % 8)) + __u8 data[]; +}; + +/* Data written by the kernel with query DRM_I915_QUERY_ID_EUS_INFO : + * + * data: Each bit indicates whether a subslice is available (1) or fused off + * (0). Use DRM_I915_QUERY_EU_AVAILABLE() to query a given EU's + * availability. + */ +struct drm_i915_query_eus_info { + __u32 max_slices; + __u32 max_subslices; + __u32 max_eus_per_subslice; + +#define DRM_I915_QUERY_EU_AVAILABLE(info, slice, subslice, eu) \ + !!((info)->data[(slice) * ALIGN((info)->max_eus_per_subslice, 8) / 8 * (info)->max_subslices + \ + (subslice) * ALIGN((info)->max_eus_per_subslice, 8) / 8 + \ + (eu) / 8] & DRM_I915_BIT((eu) % 8)) + __u8 data[]; +}; + #if defined(__cplusplus) } #endif