From patchwork Thu Apr 5 12:39:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10324525 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 ADC676053F for ; Thu, 5 Apr 2018 12:39:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9ECF829181 for ; Thu, 5 Apr 2018 12:39:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93D5529184; Thu, 5 Apr 2018 12:39:48 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 3A03829181 for ; Thu, 5 Apr 2018 12:39:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8871D6E772; Thu, 5 Apr 2018 12:39:47 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id B8FAA6E762 for ; Thu, 5 Apr 2018 12:39:40 +0000 (UTC) Received: by mail-wr0-x242.google.com with SMTP id n2so24818184wrj.7 for ; Thu, 05 Apr 2018 05:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oVu712TNBP4VCqjjzm53gw0EaoNJmDmqsUimoVZXO1w=; b=0Y5SdtcAIytNcLDfEAdeBEAVB+9nTME4oc8IDfXCNmt1Bb9BjNiiq08Cb+hPmHCaCI TpVj6pEt0H2XiFvCTA1i8hoH1dTdvVDZe48QkGqGlNF4FrvyuvuI9wTvXtQ9g6h+9pmV v2lNfXD9h3HR3angd1Xc1iyolIs1nHbe2R5eYSbtCz5MQPO28A7d3gsnraDK4zJzXWf+ T3Axm8HrOO4CC4j2tJTKwoL9wR7Uz1gCMWd+vj3rK0DkQrHnmpL8szQNx3bLRalGle44 B3z/X6hXWT5fmlRDqrcD9Ao0+/nOl4JuwxNyrXoJgbwuVd+Dh/qioM5ghmZgccOUa2Cu 8osA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oVu712TNBP4VCqjjzm53gw0EaoNJmDmqsUimoVZXO1w=; b=PujGMqhgSGZGXacGzeA3mi99wf8ac4Ga+vQHSQxdDrJCyFDg3hfUGV8Oqd6IagNZCZ 0SDBrdToDRT6YuvAGNkEFpdSzhrpKPWQ/HGkyMjf86bjfJHvJTkU6a4xttrK5JzVDJSM Ig06ILTt/Zq+JpbVqCZcrUd4QkdHVr1NNJdxUDMXC0i/7s/a283hEaPhPLSls77y1JqY skAzD8qIMEblJO5XxOIrzcZVGNXwpqhReCFewJ63iN53twuhd4Dalu0YyG0Bt2399cCY o8e200pDfzrW/Y2//UhvWC40X4ta8V2qcN6Gg2CIKKoRDrbT6IKOOzxPx9h+JMw0NsPa 8lxA== X-Gm-Message-State: AElRT7HD8XDx90ZqDSwDSrdd88op5Se+wuY80GwSDC1eUpi57Bj6BjyG QE7BibmPbuB+WSsI++xPoSQFHIc+ X-Google-Smtp-Source: AIpwx49U1fQ1zrwApjPyoYO+FuQRG603QghCQwIvKa3DwcERkH7uhzH7T9aztIzjkMFnin4wUKrD9Q== X-Received: by 10.223.173.72 with SMTP id p66mr16015022wrc.191.1522931979226; Thu, 05 Apr 2018 05:39:39 -0700 (PDT) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id n21sm9800333wmi.37.2018.04.05.05.39.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 05:39:38 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Thu, 5 Apr 2018 13:39:23 +0100 Message-Id: <20180405123923.22671-8-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180405123923.22671-1-tvrtko.ursulin@linux.intel.com> References: <20180405123923.22671-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH 7/7] drm/i915: Engine queues query X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 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 From: Tvrtko Ursulin As well as exposing active requests on engines via PMU, we can also export the current raw values (as tracked by i915 command submission) via a dedicated query. This is to satisfy customers who have userspace load balancing solutions implemented on top of their custom kernel patches. Userspace is now able to include DRM_I915_QUERY_ENGINE_QUEUES in their query list, pointing to initialized struct drm_i915_query_engine_queues entry. Fields describing engine class and instance userspace would like to know about need to be filled in, and i915 will fill in the rest. Multiple engines can be queried in one go by having multiple queries in the query list. v2: * Use EINVAL for reporting insufficient buffer space. (Chris Wilson) Signed-off-by: Tvrtko Ursulin Cc: Dmitry Rogozhkin Reviewed-by: Lionel Landwerlin --- drivers/gpu/drm/i915/i915_query.c | 43 +++++++++++++++++++++++++++++++++++++++ include/uapi/drm/i915_drm.h | 26 +++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c index 3ace929dd90f..798672f5c104 100644 --- a/drivers/gpu/drm/i915/i915_query.c +++ b/drivers/gpu/drm/i915/i915_query.c @@ -82,9 +82,52 @@ static int query_topology_info(struct drm_i915_private *dev_priv, return total_length; } +static int +query_engine_queues(struct drm_i915_private *i915, + struct drm_i915_query_item *query_item) +{ + struct drm_i915_query_engine_queues __user *query_ptr = + u64_to_user_ptr(query_item->data_ptr); + struct drm_i915_query_engine_queues query; + struct intel_engine_cs *engine; + const int len = sizeof(query); + unsigned int i; + + if (query_item->flags) + return -EINVAL; + + if (!query_item->length) + return len; + else if (query_item->length < len) + return -EINVAL; + + if (copy_from_user(&query, query_ptr, len)) + return -EFAULT; + + for (i = 0; i < ARRAY_SIZE(query.rsvd); i++) { + if (query.rsvd[i]) + return -EINVAL; + } + + engine = intel_engine_lookup_user(i915, query.class, query.instance); + if (!engine) + return -ENOENT; + + query.queued = atomic_read(&engine->request_stats.queued); + query.runnable = engine->request_stats.runnable; + query.running = intel_engine_last_submit(engine) - + intel_engine_get_seqno(engine); + + if (copy_to_user(query_ptr, &query, len)) + return -EFAULT; + + return len; +} + static int (* const i915_query_funcs[])(struct drm_i915_private *dev_priv, struct drm_i915_query_item *query_item) = { query_topology_info, + query_engine_queues, }; int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file) diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h index 9a00c30e4071..064c3d620286 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -1637,6 +1637,7 @@ struct drm_i915_perf_oa_config { struct drm_i915_query_item { __u64 query_id; #define DRM_I915_QUERY_TOPOLOGY_INFO 1 +#define DRM_I915_QUERY_ENGINE_QUEUES 2 /* * When set to zero by userspace, this is filled with the size of the @@ -1734,6 +1735,31 @@ struct drm_i915_query_topology_info { __u8 data[]; }; +/** + * struct drm_i915_query_engine_queues + * + * Engine queues query enables userspace to query current counts of active + * requests in their different states. + */ +struct drm_i915_query_engine_queues { + /** Engine class as in enum drm_i915_gem_engine_class. */ + __u16 class; + + /** Engine instance number. */ + __u16 instance; + + /** Number of requests with unresolved fences and dependencies. */ + __u32 queued; + + /** Number of ready requests waiting on a slot on GPU. */ + __u32 runnable; + + /** Number of requests executing on the GPU. */ + __u32 running; + + __u32 rsvd[5]; +}; + #if defined(__cplusplus) } #endif