From patchwork Mon Mar 19 18:16:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10293877 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 627E560386 for ; Mon, 19 Mar 2018 18:16:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 506E228AB1 for ; Mon, 19 Mar 2018 18:16:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 450A129314; Mon, 19 Mar 2018 18:16:52 +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 DEC7528AB1 for ; Mon, 19 Mar 2018 18:16:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 543966E5F7; Mon, 19 Mar 2018 18:16:49 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 663606E5EF for ; Mon, 19 Mar 2018 18:16:42 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id s18so19546541wrg.9 for ; Mon, 19 Mar 2018 11:16:42 -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=rxlL0xwjL5hP4qp2D9RaCkVexOdvvgy/TcNG+YwqCJU=; b=TNLATVqcsvykJFW3jlcDnThjBrYs0+HJ+VSLuc6FzYVtC70BnnZu854z7VfbBQYb6F dhEnCFVZSUowkteDvEqLqRJUDWylsyUegvJY8q2eouawR9og3lKO+2RB8FsgKhUOX8// zE9p+clwxHTbTg2XCkhXZFEBnfUnE4zmm6g1rIXokNVYKrjAKArHEFZmCab/ywbptc/5 mLVRpJw6jI8R4e/CEWpYXU6IuWwUwAP5U4LTdE54Vnj0RwERqKkPdF7V81oP2oNb64Kw EF56gTFHZ4j0HrDC6wDfGfICXsrG7ieWAFZD4PxAi6VLUHn63KtTX5+BbmoMSgnJ7l3O DRmw== 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=rxlL0xwjL5hP4qp2D9RaCkVexOdvvgy/TcNG+YwqCJU=; b=E7mP91hL0mGu+cjtSRNEo9EtX9O/fwfhuF5JH8maEv9d9/9hxSYccGGhoYo4gPsj7l eufkILR9EvZYstOXltWYk5oVyOeJzDG406rYRw+g00ELV3IsPo6RnwmdDL9Ca8uLnv0i cpaOL37VEsrmvHew9IM73T6GFWFh0LopaSb/S2Ljlh7zsTjf+YkBw+bHPO0srJ0Nxm3u 8wJxPuKZUl0NHmrrkosgXiJGHn8rZ7VQcSLEC1GPnH3wFes3nbTZsvgWA5iLi2gRElc5 Q3SomqZbuWS/C1TJAruWZgASAquqFqayHB/qj36vgVWuZiQn/tmrVlbvIYuT9WXa+jbH +vNg== X-Gm-Message-State: AElRT7Gb20BZ+9+VkXMQ/XaLAx1sXrFwRoAwTOFz8wLJyDOGXOrYPU2w uMOn8YeLrT9CiQGy3CbNvQfgrkE8 X-Google-Smtp-Source: AG47ELs75pKXiMZx4USkiQy3GeRvI2gV6ePLjDe0Y1wABRtmb96imlZbFxNHCJ++S8rJuZ7Nd1O2CA== X-Received: by 10.223.163.87 with SMTP id d23mr5917811wrb.103.1521483400568; Mon, 19 Mar 2018 11:16:40 -0700 (PDT) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id r19sm1234030wmd.48.2018.03.19.11.16.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Mar 2018 11:16:40 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Mon, 19 Mar 2018 18:16:25 +0000 Message-Id: <20180319181625.29292-8-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180319181625.29292-1-tvrtko.ursulin@linux.intel.com> References: <20180319181625.29292-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. Signed-off-by: Tvrtko Ursulin Cc: Dmitry Rogozhkin --- 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..b3bc69e8deb7 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 -ENOSPC; + + 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