From patchwork Fri Jun 9 12:11:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13273785 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3470CC7EE25 for ; Fri, 9 Jun 2023 12:12:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 282EA10E6A6; Fri, 9 Jun 2023 12:11:56 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 75B7110E6A4; Fri, 9 Jun 2023 12:11:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686312713; x=1717848713; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k2u68uLaytbU9h5AePwzc9VLikp1n7IigFMkwxC4lR0=; b=kmiiAVvpVoqiMHKsN0nNX3uKNKg4dgWrOwAQzJoAJjoTTiQR/Qip0aSN QXWONBO91/30SiR8oGl2gnSPy/L8MF6ir2xzcpCoX3WwXJk1o8gE/fTKk W7WS3mTcT+YzoBhPU+O+VmRAmVym7XQnSqHB6SwTaRB0VDDazS8gxycwu +9xsuueiBYV4nHrQk/2nyXjAl8JbtE1cVAE/VyNCAKUKWITD+pUIsRe/S DJ4/WJ/YhqzBboay4u2EJRPi2Zza41+2TXxnKBsCDLinK7yIRhch1eoag ItiKJEDmtafmPm7nPYG55CZ4e783JKHogF7GZfzoidUfm5e/AbjUGdQBC g==; X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="356474742" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="356474742" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="740150834" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="740150834" Received: from pjdillon-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.210.241]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:51 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 1/8] dma-fence: Bypass signaling annotation from dma_fence_is_signaled Date: Fri, 9 Jun 2023 13:11:36 +0100 Message-Id: <20230609121143.1232420-2-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> References: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , Tvrtko Ursulin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tvrtko Ursulin For dma_fence_is_signaled signaling critical path annotations are an annoying cause of false positives when using dma_fence_is_signaled and indirectly higher level helpers such as dma_resv_test_signaled etc. Drop the critical path annotation since the "is signaled" API does not guarantee to ever change the signaled status anyway. We do that by adding a low level _dma_fence_signal helper and use it from dma_fence_is_signaled. Signed-off-by: Tvrtko Ursulin Cc: Christian König Cc: Daniel Vetter --- drivers/dma-buf/dma-fence.c | 26 ++++++++++++++++++++------ include/linux/dma-fence.h | 3 ++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index f177c56269bb..f216a189a755 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c @@ -444,6 +444,25 @@ int dma_fence_signal_locked(struct dma_fence *fence) } EXPORT_SYMBOL(dma_fence_signal_locked); +/** + * _dma_fence_signal - signal completion of a fence bypassing critical section annotation + * @fence: the fence to signal + * + * This low-level helper should not be used by code external to dma-fence.h|c! + */ +int _dma_fence_signal(struct dma_fence *fence) +{ + unsigned long flags; + int ret; + + spin_lock_irqsave(fence->lock, flags); + ret = dma_fence_signal_timestamp_locked(fence, ktime_get()); + spin_unlock_irqrestore(fence->lock, flags); + + return ret; +} +EXPORT_SYMBOL(_dma_fence_signal); + /** * dma_fence_signal - signal completion of a fence * @fence: the fence to signal @@ -459,7 +478,6 @@ EXPORT_SYMBOL(dma_fence_signal_locked); */ int dma_fence_signal(struct dma_fence *fence) { - unsigned long flags; int ret; bool tmp; @@ -467,11 +485,7 @@ int dma_fence_signal(struct dma_fence *fence) return -EINVAL; tmp = dma_fence_begin_signalling(); - - spin_lock_irqsave(fence->lock, flags); - ret = dma_fence_signal_timestamp_locked(fence, ktime_get()); - spin_unlock_irqrestore(fence->lock, flags); - + ret = _dma_fence_signal(fence); dma_fence_end_signalling(tmp); return ret; diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index d54b595a0fe0..d94768ad70e4 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -387,6 +387,7 @@ static inline void dma_fence_end_signalling(bool cookie) {} static inline void __dma_fence_might_wait(void) {} #endif +int _dma_fence_signal(struct dma_fence *fence); int dma_fence_signal(struct dma_fence *fence); int dma_fence_signal_locked(struct dma_fence *fence); int dma_fence_signal_timestamp(struct dma_fence *fence, ktime_t timestamp); @@ -452,7 +453,7 @@ dma_fence_is_signaled(struct dma_fence *fence) return true; if (fence->ops->signaled && fence->ops->signaled(fence)) { - dma_fence_signal(fence); + _dma_fence_signal(fence); return true; } From patchwork Fri Jun 9 12:11:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13273787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 21B09C7EE43 for ; Fri, 9 Jun 2023 12:12:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 74D9410E6A9; Fri, 9 Jun 2023 12:11:59 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3ABA110E6A7; Fri, 9 Jun 2023 12:11:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686312715; x=1717848715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k4pCJCqaYKvPWaPUSKBkgJuqDWhvzWnRq4tE+feAalk=; b=MZ41+F38H/WUci/lO0iS0SF614l8bYrHh2jvKjUHht4lvqLXiVhRPGzV If9w4YI9hVGNeckdUhhXf4N08ftuzzTRINBPiooUiFmssKpd/r6/wAOBT +/JiOBl+OhX9KXFuAsJ/kwlciHjAo3sWo56FQij/V7X2KYsS7teA/lXHS lzBYoXvU3WwBh0vHEHNZ9N3sRAHC8O+BB4ZL3JiUQeKkGgcDc4V710SfD JtGOL3prBMcScPA6vltlCFX8scH+MT9RZlsBq5JZrYXnbigrTLHSITynH gjdN4aRSbh9W09DlrE8IbITUnRUsefnEsyQr/8njGKI228ayVgPIMNHvB A==; X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="356474748" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="356474748" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="740150848" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="740150848" Received: from pjdillon-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.210.241]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:53 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 2/8] drm/i915: Track buffer objects belonging to clients Date: Fri, 9 Jun 2023 13:11:37 +0100 Message-Id: <20230609121143.1232420-3-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> References: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tvrtko Ursulin In order to show per client memory usage lets start tracking which objects belong to which clients. We start with objects explicitly created by object creation UAPI and track it on a new per client lists, protected by a new per client lock. In order for delayed destruction (post client exit), we make tracked objects hold references to the owning client. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/gem/i915_gem_create.c | 32 +++++++++++++-- drivers/gpu/drm/i915/gem/i915_gem_object.c | 6 +++ .../gpu/drm/i915/gem/i915_gem_object_types.h | 12 ++++++ drivers/gpu/drm/i915/i915_drm_client.c | 39 ++++++++++++++++++- drivers/gpu/drm/i915/i915_drm_client.h | 36 ++++++++++++++++- drivers/gpu/drm/i915/i915_gem.c | 2 +- 6 files changed, 121 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c b/drivers/gpu/drm/i915/gem/i915_gem_create.c index d24c0ce8805c..4f1957638207 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_create.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c @@ -11,6 +11,7 @@ #include "gem/i915_gem_region.h" #include "pxp/intel_pxp.h" +#include "i915_drm_client.h" #include "i915_drv.h" #include "i915_gem_create.h" #include "i915_trace.h" @@ -164,6 +165,14 @@ __i915_gem_object_create_user(struct drm_i915_private *i915, u64 size, n_placements, 0); } +static void add_file_obj(struct drm_file *file, + struct drm_i915_gem_object *obj) +{ + struct drm_i915_file_private *fpriv = file->driver_priv; + + i915_drm_client_add_object(fpriv->client, obj); +} + int i915_gem_dumb_create(struct drm_file *file, struct drm_device *dev, @@ -174,6 +183,7 @@ i915_gem_dumb_create(struct drm_file *file, enum intel_memory_type mem_type; int cpp = DIV_ROUND_UP(args->bpp, 8); u32 format; + int ret; switch (cpp) { case 1: @@ -212,7 +222,12 @@ i915_gem_dumb_create(struct drm_file *file, if (IS_ERR(obj)) return PTR_ERR(obj); - return i915_gem_publish(obj, file, &args->size, &args->handle); + ret = i915_gem_publish(obj, file, &args->size, &args->handle); + + if (!ret) + add_file_obj(file, obj); + + return ret; } /** @@ -229,6 +244,7 @@ i915_gem_create_ioctl(struct drm_device *dev, void *data, struct drm_i915_gem_create *args = data; struct drm_i915_gem_object *obj; struct intel_memory_region *mr; + int ret; mr = intel_memory_region_by_type(i915, INTEL_MEMORY_SYSTEM); @@ -236,7 +252,12 @@ i915_gem_create_ioctl(struct drm_device *dev, void *data, if (IS_ERR(obj)) return PTR_ERR(obj); - return i915_gem_publish(obj, file, &args->size, &args->handle); + ret = i915_gem_publish(obj, file, &args->size, &args->handle); + + if (!ret) + add_file_obj(file, obj); + + return ret; } struct create_ext { @@ -494,5 +515,10 @@ i915_gem_create_ext_ioctl(struct drm_device *dev, void *data, obj->pat_set_by_user = true; } - return i915_gem_publish(obj, file, &args->size, &args->handle); + ret = i915_gem_publish(obj, file, &args->size, &args->handle); + + if (!ret) + add_file_obj(file, obj); + + return ret; } diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c b/drivers/gpu/drm/i915/gem/i915_gem_object.c index 97ac6fb37958..46de9b1b3f1d 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c @@ -105,6 +105,10 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj, INIT_LIST_HEAD(&obj->mm.link); +#ifdef CONFIG_PROC_FS + INIT_LIST_HEAD(&obj->client_link); +#endif + INIT_LIST_HEAD(&obj->lut_list); spin_lock_init(&obj->lut_lock); @@ -441,6 +445,8 @@ static void i915_gem_free_object(struct drm_gem_object *gem_obj) GEM_BUG_ON(i915_gem_object_is_framebuffer(obj)); + i915_drm_client_remove_object(obj); + /* * Before we free the object, make sure any pure RCU-only * read-side critical sections are complete, e.g. diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h index e72c57716bee..8de2b91b3edf 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h @@ -300,6 +300,18 @@ struct drm_i915_gem_object { */ struct i915_address_space *shares_resv_from; +#ifdef CONFIG_PROC_FS + /** + * @client: @i915_drm_client which created the object + */ + struct i915_drm_client *client; + + /** + * @client_link: Link into @i915_drm_client.objects_list + */ + struct list_head client_link; +#endif + union { struct rcu_head rcu; struct llist_node freed; diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 2a44b3876cb5..b0b35bcdd2b3 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -17,7 +17,8 @@ #include "i915_gem.h" #include "i915_utils.h" -struct i915_drm_client *i915_drm_client_alloc(void) +struct i915_drm_client * +i915_drm_client_alloc(struct drm_i915_file_private *fpriv) { struct i915_drm_client *client; @@ -28,6 +29,12 @@ struct i915_drm_client *i915_drm_client_alloc(void) kref_init(&client->kref); spin_lock_init(&client->ctx_lock); INIT_LIST_HEAD(&client->ctx_list); +#ifdef CONFIG_PROC_FS + spin_lock_init(&client->objects_lock); + INIT_LIST_HEAD(&client->objects_list); + + client->fpriv = fpriv; +#endif return client; } @@ -108,4 +115,34 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++) show_client_class(p, i915, file_priv->client, i); } + +void i915_drm_client_add_object(struct i915_drm_client *client, + struct drm_i915_gem_object *obj) +{ + unsigned long flags; + + GEM_WARN_ON(obj->client); + GEM_WARN_ON(!list_empty(&obj->client_link)); + + spin_lock_irqsave(&client->objects_lock, flags); + obj->client = i915_drm_client_get(client); + list_add_tail(&obj->client_link, &client->objects_list); + spin_unlock_irqrestore(&client->objects_lock, flags); +} + +void i915_drm_client_remove_object(struct drm_i915_gem_object *obj) +{ + struct i915_drm_client *client = fetch_and_zero(&obj->client); + unsigned long flags; + + /* Object may not be associated with a client. */ + if (!client || list_empty(&obj->client_link)) + return; + + spin_lock_irqsave(&client->objects_lock, flags); + list_del(&obj->client_link); + spin_unlock_irqrestore(&client->objects_lock, flags); + + i915_drm_client_put(client); +} #endif diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h index 4c18b99e10a4..dfeaaf204c00 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.h +++ b/drivers/gpu/drm/i915/i915_drm_client.h @@ -12,6 +12,9 @@ #include +#include "i915_file_private.h" +#include "gem/i915_gem_object_types.h" + #define I915_LAST_UABI_ENGINE_CLASS I915_ENGINE_CLASS_COMPUTE struct drm_file; @@ -25,6 +28,22 @@ struct i915_drm_client { spinlock_t ctx_lock; /* For add/remove from ctx_list. */ struct list_head ctx_list; /* List of contexts belonging to client. */ +#ifdef CONFIG_PROC_FS + struct drm_i915_file_private *fpriv; + + /** + * @objects_lock: lock protecting @objects_list + */ + spinlock_t objects_lock; + + /** + * @objects_list: list of objects created by this client + * + * Protected by @objects_lock. + */ + struct list_head objects_list; +#endif + /** * @past_runtime: Accumulation of pphwsp runtimes from closed contexts. */ @@ -45,10 +64,25 @@ static inline void i915_drm_client_put(struct i915_drm_client *client) kref_put(&client->kref, __i915_drm_client_free); } -struct i915_drm_client *i915_drm_client_alloc(void); +struct i915_drm_client *i915_drm_client_alloc(struct drm_i915_file_private *fpriv); #ifdef CONFIG_PROC_FS void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file); + +void i915_drm_client_add_object(struct i915_drm_client *client, + struct drm_i915_gem_object *obj); +void i915_drm_client_remove_object(struct drm_i915_gem_object *obj); +#else +static inline void i915_drm_client_add_object(struct i915_drm_client *client, + struct drm_i915_gem_object *obj) +{ + +} + +static inline void i915_drm_client_remove_object(struct drm_i915_gem_object *obj) +{ + +} #endif #endif /* !__I915_DRM_CLIENT_H__ */ diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 1f65bb33dd21..7ae42f746cc2 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -1325,7 +1325,7 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file) if (!file_priv) goto err_alloc; - client = i915_drm_client_alloc(); + client = i915_drm_client_alloc(file_priv); if (!client) goto err_client; From patchwork Fri Jun 9 12:11:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13273786 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6C59C7EE29 for ; Fri, 9 Jun 2023 12:12:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 25F2A10E6A8; Fri, 9 Jun 2023 12:11:59 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id C472410E6A1; Fri, 9 Jun 2023 12:11:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686312716; x=1717848716; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W42oHvoPm8QrXUat2i8O9CbrGmzOCt0DO6zFyYyiCsE=; b=I5KRK7c6lXRtWXAijViq4sPYI9ZBQ19QWjOII0yM10m6Ep5MDGIGkmhz PVaXQDKmgiUXCLdsZqCC8cAowBxz6pIZuj2FjqEIp1b5fkjSJSJFNfjnQ TDsN9zq/Ylu/MPr3BwjB4bJ/4rVJK9TOVTItYO66Qo5m6PJblnUATPQq0 N3h7LOifztzN2m5e6kX+2nSZ00NrfdjRwCz3ke1AFXyBFXFW1QwcQRKMl JdVZxRwXd3TLAC5+BlWSafJuO1ImOX0QF4XTvcBE5bmShmNvnjcwHv5VF visPuPC2GGcF94zuF2P00RBdgMMveYmCzgoJ9C61TmAPcKOdDFocquYv0 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="356474750" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="356474750" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="740150859" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="740150859" Received: from pjdillon-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.210.241]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:55 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 3/8] drm/i915: Record which clients own a VM Date: Fri, 9 Jun 2023 13:11:38 +0100 Message-Id: <20230609121143.1232420-4-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> References: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tvrtko Ursulin To enable accounting of indirect client memory usage (such as page tables) in the following patch, lets start recording the creator of each PPGTT. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 11 ++++++++--- drivers/gpu/drm/i915/gem/i915_gem_context_types.h | 3 +++ drivers/gpu/drm/i915/gem/selftests/mock_context.c | 4 ++-- drivers/gpu/drm/i915/gt/intel_gtt.h | 1 + 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index 9a9ff84c90d7..35cf6608180e 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -279,7 +279,8 @@ static int proto_context_set_protected(struct drm_i915_private *i915, } static struct i915_gem_proto_context * -proto_context_create(struct drm_i915_private *i915, unsigned int flags) +proto_context_create(struct drm_i915_file_private *fpriv, + struct drm_i915_private *i915, unsigned int flags) { struct i915_gem_proto_context *pc, *err; @@ -287,6 +288,7 @@ proto_context_create(struct drm_i915_private *i915, unsigned int flags) if (!pc) return ERR_PTR(-ENOMEM); + pc->fpriv = fpriv; pc->num_user_engines = -1; pc->user_engines = NULL; pc->user_flags = BIT(UCONTEXT_BANNABLE) | @@ -1621,6 +1623,7 @@ i915_gem_create_context(struct drm_i915_private *i915, err = PTR_ERR(ppgtt); goto err_ctx; } + ppgtt->vm.fpriv = pc->fpriv; vm = &ppgtt->vm; } if (vm) @@ -1740,7 +1743,7 @@ int i915_gem_context_open(struct drm_i915_private *i915, /* 0 reserved for invalid/unassigned ppgtt */ xa_init_flags(&file_priv->vm_xa, XA_FLAGS_ALLOC1); - pc = proto_context_create(i915, 0); + pc = proto_context_create(file_priv, i915, 0); if (IS_ERR(pc)) { err = PTR_ERR(pc); goto err; @@ -1822,6 +1825,7 @@ int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data, GEM_BUG_ON(id == 0); /* reserved for invalid/unassigned ppgtt */ args->vm_id = id; + ppgtt->vm.fpriv = file_priv; return 0; err_put: @@ -2284,7 +2288,8 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, return -EIO; } - ext_data.pc = proto_context_create(i915, args->flags); + ext_data.pc = proto_context_create(file->driver_priv, i915, + args->flags); if (IS_ERR(ext_data.pc)) return PTR_ERR(ext_data.pc); diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h index cb78214a7dcd..c573c067779f 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h @@ -188,6 +188,9 @@ struct i915_gem_proto_engine { * CONTEXT_CREATE_SET_PARAM during GEM_CONTEXT_CREATE. */ struct i915_gem_proto_context { + /** @fpriv: Client which creates the context */ + struct drm_i915_file_private *fpriv; + /** @vm: See &i915_gem_context.vm */ struct i915_address_space *vm; diff --git a/drivers/gpu/drm/i915/gem/selftests/mock_context.c b/drivers/gpu/drm/i915/gem/selftests/mock_context.c index 8ac6726ec16b..125584ada282 100644 --- a/drivers/gpu/drm/i915/gem/selftests/mock_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/mock_context.c @@ -83,7 +83,7 @@ live_context(struct drm_i915_private *i915, struct file *file) int err; u32 id; - pc = proto_context_create(i915, 0); + pc = proto_context_create(fpriv, i915, 0); if (IS_ERR(pc)) return ERR_CAST(pc); @@ -152,7 +152,7 @@ kernel_context(struct drm_i915_private *i915, struct i915_gem_context *ctx; struct i915_gem_proto_context *pc; - pc = proto_context_create(i915, 0); + pc = proto_context_create(NULL, i915, 0); if (IS_ERR(pc)) return ERR_CAST(pc); diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.h b/drivers/gpu/drm/i915/gt/intel_gtt.h index 4d6296cdbcfd..7192a534a654 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.h +++ b/drivers/gpu/drm/i915/gt/intel_gtt.h @@ -248,6 +248,7 @@ struct i915_address_space { struct drm_mm mm; struct intel_gt *gt; struct drm_i915_private *i915; + struct drm_i915_file_private *fpriv; struct device *dma; u64 total; /* size addr space maps (ex. 2GB for ggtt) */ u64 reserved; /* size addr space reserved */ From patchwork Fri Jun 9 12:11:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13273790 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E47AC7EE25 for ; Fri, 9 Jun 2023 12:12:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7C13B10E6AE; Fri, 9 Jun 2023 12:12:04 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 25F0310E6A8; Fri, 9 Jun 2023 12:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686312718; x=1717848718; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OPJBprVC5iXgAgBnq9kGwl3ZibpT5X7opxpZm+7qmFc=; b=adlTrBzWPZbEHapeQ+mPKy8XLnCiT5k9DmSWwTCm5BONZ1WU9qPz+VwZ AB0jevPPiI+Ri/j11HJGaoeYBshhjEBHPSljHY03R7VKLef3hZk3Ucqrj J1vem8ui+VwFhvBwwlk+zx3K6XZV9Av8Q/1rwVwvYpVjj/WDMwC7ZraJx a2bwYO0T6X0xyVzVnpHM81p4TjQ5ClSwcZaNJB9+42bgvMmbtO76igyjC JVo0L8EW3nsL4jRykMNEHR7ehH1NZwXYbtNjik0LD9joX8KoTu2MU6N05 CFTNZ5lEyLiTHnoJ9Y4SRsy4xRcweVGVsA1V4TlZBuvTFU9SWX+wim0o2 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="356474753" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="356474753" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="740150872" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="740150872" Received: from pjdillon-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.210.241]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:56 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 4/8] drm/i915: Track page table backing store usage Date: Fri, 9 Jun 2023 13:11:39 +0100 Message-Id: <20230609121143.1232420-5-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> References: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tvrtko Ursulin Account page table backing store against the owning client memory usage stats. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/gt/intel_gtt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.c b/drivers/gpu/drm/i915/gt/intel_gtt.c index 2f6a9be0ffe6..126269a0d728 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.c +++ b/drivers/gpu/drm/i915/gt/intel_gtt.c @@ -58,6 +58,9 @@ struct drm_i915_gem_object *alloc_pt_lmem(struct i915_address_space *vm, int sz) if (!IS_ERR(obj)) { obj->base.resv = i915_vm_resv_get(vm); obj->shares_resv_from = vm; + + if (vm->fpriv) + i915_drm_client_add_object(vm->fpriv->client, obj); } return obj; @@ -79,6 +82,9 @@ struct drm_i915_gem_object *alloc_pt_dma(struct i915_address_space *vm, int sz) if (!IS_ERR(obj)) { obj->base.resv = i915_vm_resv_get(vm); obj->shares_resv_from = vm; + + if (vm->fpriv) + i915_drm_client_add_object(vm->fpriv->client, obj); } return obj; From patchwork Fri Jun 9 12:11:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13273788 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D90B8C83003 for ; Fri, 9 Jun 2023 12:12:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6537F10E6AB; Fri, 9 Jun 2023 12:12:02 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id B9BD210E6AB; Fri, 9 Jun 2023 12:11:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686312719; x=1717848719; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u16cA1catl/aRkwsypx6kmoePe8SsYbgiNfEw7q+5LE=; b=DlXKHpC41pPEDuIQ4XJE0WqYk0e5GSEYSNook8bHW/txhQkveR43RI0E bOArSCQC2ts4r9mFYv+//bIQDC1pDaoGjByNL4hGnSYyvxPTOC4cKAwVO 5Kj5eP/7+XNjecKfDOyRYhJOJeMTu7ny9hY743eMKebvOfDhzRod2TQFO 7bRQl4ddu4cn87LlnG2RZ9tSRbdBVOAksQzQEq3ddcDRrJgEALcW5QK/m hZ1zJtRYq2I/kfuks6jlaz1tGUp3tJ3oKAsF7qWhdabiWkY/h0I4ClkbG IV5z/TXk7osjqUF9tiaQzZ0b6y/XeqiYTlw3ulne+m1ZoVVAla67ZIVJ5 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="356474755" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="356474755" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="740150883" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="740150883" Received: from pjdillon-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.210.241]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:58 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 5/8] drm/i915: Account ring buffer and context state storage Date: Fri, 9 Jun 2023 13:11:40 +0100 Message-Id: <20230609121143.1232420-6-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> References: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tvrtko Ursulin Account ring buffers and logical context space against the owning client memory usage stats. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 6 ++++++ drivers/gpu/drm/i915/i915_drm_client.c | 10 ++++++++++ drivers/gpu/drm/i915/i915_drm_client.h | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index 35cf6608180e..3f4c74aed3c5 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -1703,6 +1703,8 @@ static void gem_context_register(struct i915_gem_context *ctx, u32 id) { struct drm_i915_private *i915 = ctx->i915; + struct i915_gem_engines_iter it; + struct intel_context *ce; void *old; ctx->file_priv = fpriv; @@ -1721,6 +1723,10 @@ static void gem_context_register(struct i915_gem_context *ctx, list_add_tail(&ctx->link, &i915->gem.contexts.list); spin_unlock(&i915->gem.contexts.lock); + for_each_gem_engine(ce, i915_gem_context_lock_engines(ctx), it) + i915_drm_client_add_context(fpriv->client, ce); + i915_gem_context_unlock_engines(ctx); + /* And finally expose ourselves to userspace via the idr */ old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL); WARN_ON(old); diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index b0b35bcdd2b3..31316edbf30b 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -145,4 +145,14 @@ void i915_drm_client_remove_object(struct drm_i915_gem_object *obj) i915_drm_client_put(client); } + +void i915_drm_client_add_context(struct i915_drm_client *client, + struct intel_context *ce) +{ + if (ce->state) + i915_drm_client_add_object(client, ce->state->obj); + + if (ce->ring != ce->engine->legacy.ring && ce->ring->vma) + i915_drm_client_add_object(client, ce->ring->vma->obj); +} #endif diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h index dfeaaf204c00..e1e2a7cca1b1 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.h +++ b/drivers/gpu/drm/i915/i915_drm_client.h @@ -14,6 +14,7 @@ #include "i915_file_private.h" #include "gem/i915_gem_object_types.h" +#include "gt/intel_context_types.h" #define I915_LAST_UABI_ENGINE_CLASS I915_ENGINE_CLASS_COMPUTE @@ -72,6 +73,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file); void i915_drm_client_add_object(struct i915_drm_client *client, struct drm_i915_gem_object *obj); void i915_drm_client_remove_object(struct drm_i915_gem_object *obj); +void i915_drm_client_add_context(struct i915_drm_client *client, + struct intel_context *ce); #else static inline void i915_drm_client_add_object(struct i915_drm_client *client, struct drm_i915_gem_object *obj) @@ -82,6 +85,12 @@ static inline void i915_drm_client_add_object(struct i915_drm_client *client, static inline void i915_drm_client_remove_object(struct drm_i915_gem_object *obj) { +} + +static inline void i915_drm_client_add_context(struct i915_drm_client *client, + struct intel_context *ce) +{ + } #endif From patchwork Fri Jun 9 12:11:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13273789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3ED4C7EE29 for ; Fri, 9 Jun 2023 12:12:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DCC5D10E6B0; Fri, 9 Jun 2023 12:12:02 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 335DC10E6AD; Fri, 9 Jun 2023 12:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686312721; x=1717848721; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cUBLkvTpbUMIeIekgGGrKHjYcQ/G0tZeuASBPvxWLeI=; b=mKNLG4GMDa+Ca4ISiF2w3gUsQpYGDmbRMgsYVMAWhwZMpis6wftQi8ux 9XwytISSTZ68Hg9Cs1JUH+1/Ul4OpPKw7PdZniHfsmI1Km1m+MLaLL21O HziMjvaFVnll8ckgFbJrQBaK+yE1Q/m2fJ98sUORsfXX9MlERy3SzfImj 3eWLv7++6ZTnjQllHt68gKSQb8aHkNwKQ+LjdGw1QNBqaal4jKazcR9wD G72VDUJWLG3jRgNoOVwvdBUgSQMHgeuqaw8tTTQkYMuhFEPvh5tYBW+uY eOlANIevNmHO1y+HPF5UChyXTqFpf/9kU620I4gNJUMi24mAhBSsqOKOj g==; X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="356474760" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="356474760" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:12:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="740150892" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="740150892" Received: from pjdillon-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.210.241]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:11:59 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 6/8] drm: Add drm_gem_prime_fd_to_handle_obj Date: Fri, 9 Jun 2023 13:11:41 +0100 Message-Id: <20230609121143.1232420-7-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> References: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tvrtko Ursulin I need a new flavour of the drm_gem_prime_fd_to_handle helper, one which will return a reference to a newly created GEM objects (if created), in order to enable tracking of imported i915 GEM objects in the following patch. Minor code reshuffule and only trivial additions on top of drm_gem_prime_fd_to_handle. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/drm_prime.c | 41 ++++++++++++++++++++++++++++++++----- include/drm/drm_prime.h | 4 ++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index d29dafce9bb0..ef75f67e3057 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -284,11 +284,12 @@ void drm_gem_dmabuf_release(struct dma_buf *dma_buf) EXPORT_SYMBOL(drm_gem_dmabuf_release); /** - * drm_gem_prime_fd_to_handle - PRIME import function for GEM drivers + * drm_gem_prime_fd_to_handle_obj - PRIME import function for GEM drivers * @dev: drm_device to import into * @file_priv: drm file-private structure * @prime_fd: fd id of the dma-buf which should be imported * @handle: pointer to storage for the handle of the imported buffer object + * @objp: optional pointer in which reference to created GEM object can be returned * * This is the PRIME import function which must be used mandatorily by GEM * drivers to ensure correct lifetime management of the underlying GEM object. @@ -297,9 +298,10 @@ EXPORT_SYMBOL(drm_gem_dmabuf_release); * * Returns 0 on success or a negative error code on failure. */ -int drm_gem_prime_fd_to_handle(struct drm_device *dev, - struct drm_file *file_priv, int prime_fd, - uint32_t *handle) +int drm_gem_prime_fd_to_handle_obj(struct drm_device *dev, + struct drm_file *file_priv, int prime_fd, + uint32_t *handle, + struct drm_gem_object **objp) { struct dma_buf *dma_buf; struct drm_gem_object *obj; @@ -336,7 +338,8 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, /* _handle_create_tail unconditionally unlocks dev->object_name_lock. */ ret = drm_gem_handle_create_tail(file_priv, obj, handle); - drm_gem_object_put(obj); + if (!objp) + drm_gem_object_put(obj); if (ret) goto out_put; @@ -348,6 +351,9 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, dma_buf_put(dma_buf); + if (objp) + *objp = obj; + return 0; fail: @@ -356,6 +362,8 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, */ drm_gem_handle_delete(file_priv, *handle); dma_buf_put(dma_buf); + if (objp) + drm_gem_object_put(obj); return ret; out_unlock: @@ -365,6 +373,29 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, dma_buf_put(dma_buf); return ret; } +EXPORT_SYMBOL(drm_gem_prime_fd_to_handle_obj); + +/** + * drm_gem_prime_fd_to_handle - PRIME import function for GEM drivers + * @dev: drm_device to import into + * @file_priv: drm file-private structure + * @prime_fd: fd id of the dma-buf which should be imported + * @handle: pointer to storage for the handle of the imported buffer object + * + * This is the PRIME import function which must be used mandatorily by GEM + * drivers to ensure correct lifetime management of the underlying GEM object. + * The actual importing of GEM object from the dma-buf is done through the + * &drm_driver.gem_prime_import driver callback. + * + * Returns 0 on success or a negative error code on failure. + */ +int drm_gem_prime_fd_to_handle(struct drm_device *dev, + struct drm_file *file_priv, int prime_fd, + uint32_t *handle) +{ + return drm_gem_prime_fd_to_handle_obj(dev, file_priv, prime_fd, handle, + NULL); +} EXPORT_SYMBOL(drm_gem_prime_fd_to_handle); int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data, diff --git a/include/drm/drm_prime.h b/include/drm/drm_prime.h index 2a1d01e5b56b..10d145ce6586 100644 --- a/include/drm/drm_prime.h +++ b/include/drm/drm_prime.h @@ -69,6 +69,10 @@ void drm_gem_dmabuf_release(struct dma_buf *dma_buf); int drm_gem_prime_fd_to_handle(struct drm_device *dev, struct drm_file *file_priv, int prime_fd, uint32_t *handle); +int drm_gem_prime_fd_to_handle_obj(struct drm_device *dev, + struct drm_file *file_priv, int prime_fd, + uint32_t *handle, + struct drm_gem_object **obj); int drm_gem_prime_handle_to_fd(struct drm_device *dev, struct drm_file *file_priv, uint32_t handle, uint32_t flags, int *prime_fd); From patchwork Fri Jun 9 12:11:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13273791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20ACCC7EE29 for ; Fri, 9 Jun 2023 12:12:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD40C10E6B1; Fri, 9 Jun 2023 12:12:04 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id D9B8E10E6AE; Fri, 9 Jun 2023 12:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686312722; x=1717848722; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ywvx/2h5rwvS+9qioVyn96tY4G/yGhwuqOC09z1IttA=; b=MaiF769UssYLM7zhbDh628/hOcsrrgc5KqL9mFc5Ikj/IE6zUllcwvAW hxcI/uPoPYLUd4mxGiZvy6z/qcSLOhi3YOD4DJRhKFXpYh0XisXl9UTOV suwlsx0JYkC94AvSjL6O3JlWOA2v4ODUwV2Guc514Sw5E9bANbzJUn5NS hscL2Lcz5u858qnyYD008EXAcTvFYCHyX3LTf9/MqkbabAP3kIqkrvLjN 26zOoP8smJWT2dAoj+TGDSeNQhHXQUGxv9f47IrXTRNyNv/H/NIyD0Tx9 hhhD2PE018hpPaHEVkrC4F5GnXfz0n2Xh07ntVSK9VTZFrZ5F0fo1ZU26 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="356474766" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="356474766" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:12:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="740150907" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="740150907" Received: from pjdillon-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.210.241]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:12:01 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 7/8] drm/i915: Track imported dma-buf objects in memory stats Date: Fri, 9 Jun 2023 13:11:42 +0100 Message-Id: <20230609121143.1232420-8-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> References: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aravind Iddamsetty , Tvrtko Ursulin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tvrtko Ursulin We want to be able to show memory usage of imported dma-buf opjects in the fdinfo stats. To achieve this we wrap drm_gem_prime_fd_to_handle(_obj) in i915_gem_prime_fd_to_handle and append some client management at the end. Signed-off-by: Tvrtko Ursulin Cc: Aravind Iddamsetty --- drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 32 ++++++++++++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_dmabuf.h | 7 +++++ drivers/gpu/drm/i915/i915_driver.c | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c index fd556a076d05..2e2d9d7c1992 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c @@ -11,7 +11,10 @@ #include +#include + #include "gem/i915_gem_dmabuf.h" +#include "i915_drm_client.h" #include "i915_drv.h" #include "i915_gem_object.h" #include "i915_scatterlist.h" @@ -344,6 +347,35 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, return ERR_PTR(ret); } +int i915_gem_prime_fd_to_handle(struct drm_device *dev, + struct drm_file *file_priv, int prime_fd, + uint32_t *handle) +{ + struct drm_gem_object *gem_obj = NULL; + int ret; + + if (IS_ENABLED(CONFIG_PROC_FS)) + ret = drm_gem_prime_fd_to_handle_obj(dev, file_priv, prime_fd, + handle, &gem_obj); + else + ret = drm_gem_prime_fd_to_handle(dev, file_priv, prime_fd, + handle); + if (ret) + return ret; + + if (gem_obj) { + struct drm_i915_file_private *fpriv = file_priv->driver_priv; + struct drm_i915_gem_object *obj = to_intel_bo(gem_obj); + + /* Really imported and not just alias? */ + if (obj->ops == &i915_gem_object_dmabuf_ops) + i915_drm_client_add_object(fpriv->client, obj); + i915_gem_object_put(obj); + } + + return 0; +} + #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) #include "selftests/mock_dmabuf.c" #include "selftests/i915_gem_dmabuf.c" diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.h b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.h index 6e0405d47ce1..63635c221c7c 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.h @@ -6,8 +6,11 @@ #ifndef __I915_GEM_DMABUF_H__ #define __I915_GEM_DMABUF_H__ +#include + struct drm_gem_object; struct drm_device; +struct drm_file; struct dma_buf; struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, @@ -15,4 +18,8 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags); +int i915_gem_prime_fd_to_handle(struct drm_device *dev, + struct drm_file *file_priv, int prime_fd, + uint32_t *handle); + #endif /* __I915_GEM_DMABUF_H__ */ diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c index ace8534b6cc5..03f3157371bf 100644 --- a/drivers/gpu/drm/i915/i915_driver.c +++ b/drivers/gpu/drm/i915/i915_driver.c @@ -1806,7 +1806,7 @@ static const struct drm_driver i915_drm_driver = { .show_fdinfo = i915_drm_client_fdinfo, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, - .prime_fd_to_handle = drm_gem_prime_fd_to_handle, + .prime_fd_to_handle = i915_gem_prime_fd_to_handle, .gem_prime_import = i915_gem_prime_import, .dumb_create = i915_gem_dumb_create, From patchwork Fri Jun 9 12:11:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13273792 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED9A4C7EE29 for ; Fri, 9 Jun 2023 12:12:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7E20710E6B7; Fri, 9 Jun 2023 12:12:13 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id DF20510E6B3; Fri, 9 Jun 2023 12:12:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686312724; x=1717848724; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XxM48JLbh6fd5vGsrYZF3dxVKUvVebS2DRtwsnvqZto=; b=EsdtCeucn/fqXipT1/p3X+quNs1KL58g0kwwrlx/sgCEcDXLB6r1TOBS JLoXa1+c1YMeY1VXTTj5yt2ztzid5H2yDuBm67tZ4Y3y/0QeUL9928q1F UDkVnMqSjVQNOrFv8JwpO6dhinU177Au0zsIvWT2BHvyCSDLLyNG1uioc DPv0mu5i9FljnyGZEFCQ2ya6k1tM/Kh+RKFihtZqIh+2j5yKrXWMxpwu4 PfcgMRGOx6AgT3DA3DWRATucnf5T8q8zbXEY5ZOI+8UbQ3DYfXspenq6C qV62jg7j9ITznmeHhFYeFU8nq4VUToBipQj58FDQJFyxzWv2YYjsY/pDn A==; X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="356474770" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="356474770" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:12:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10735"; a="740150928" X-IronPort-AV: E=Sophos;i="6.00,229,1681196400"; d="scan'208";a="740150928" Received: from pjdillon-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.210.241]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2023 05:12:02 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 8/8] drm/i915: Implement fdinfo memory stats printing Date: Fri, 9 Jun 2023 13:11:43 +0100 Message-Id: <20230609121143.1232420-9-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> References: <20230609121143.1232420-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aravind Iddamsetty , Tvrtko Ursulin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tvrtko Ursulin Use the newly added drm_print_memory_stats helper to show memory utilisation of our objects in drm/driver specific fdinfo output. To collect the stats we walk the per memory regions object lists and accumulate object size into the respective drm_memory_stats categories. Objects with multiple possible placements are reported in multiple regions for total and shared sizes, while other categories are counted only for the currently active region. Signed-off-by: Tvrtko Ursulin Cc: Aravind Iddamsetty Cc: Rob Clark --- drivers/gpu/drm/i915/i915_drm_client.c | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 31316edbf30b..596de36ee09c 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -48,6 +48,68 @@ void __i915_drm_client_free(struct kref *kref) } #ifdef CONFIG_PROC_FS +static void +obj_meminfo(struct drm_i915_gem_object *obj, + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) +{ + struct intel_memory_region *mr; + u64 sz = obj->base.size; + enum intel_region_id id; + unsigned int i; + + /* Attribute size and shared to all possible memory regions. */ + for (i = 0; i < obj->mm.n_placements; i++) { + mr = obj->mm.placements[i]; + id = mr->id; + + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + } + + /* Attribute other categories to only the current region. */ + mr = obj->mm.region; + if (mr) + id = mr->id; + else + id = INTEL_REGION_SMEM; + + if (i915_gem_object_has_pages(obj)) { + stats[id].resident += sz; + + if (!dma_resv_test_signaled(obj->base.resv, + dma_resv_usage_rw(true))) + stats[id].active += sz; + else if (i915_gem_object_is_shrinkable(obj) && + obj->mm.madv == I915_MADV_DONTNEED) + stats[id].purgeable += sz; + } +} + +static void show_meminfo(struct drm_printer *p, struct drm_file *file) +{ + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; + struct drm_i915_file_private *fpriv = file->driver_priv; + struct i915_drm_client *client = fpriv->client; + struct drm_i915_private *i915 = fpriv->i915; + struct drm_i915_gem_object *obj; + struct intel_memory_region *mr; + unsigned int id; + + spin_lock_irq(&client->objects_lock); + list_for_each_entry(obj, &client->objects_list, client_link) + obj_meminfo(obj, stats); + spin_unlock_irq(&client->objects_lock); + + for_each_memory_region(mr, i915, id) + drm_print_memory_stats(p, + &stats[id], + DRM_GEM_OBJECT_RESIDENT | + DRM_GEM_OBJECT_PURGEABLE, + mr->name); +} + static const char * const uabi_class_names[] = { [I915_ENGINE_CLASS_RENDER] = "render", [I915_ENGINE_CLASS_COPY] = "copy", @@ -109,6 +171,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) * ****************************************************************** */ + show_meminfo(p, file); + if (GRAPHICS_VER(i915) < 8) return;