Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp38217586rwd; Wed, 12 Jul 2023 04:58:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlHOlLZmQ5i/NpwQs1P9GKKNG2X0FQEZk8AFC9bnZRJTSnZMdBWV7biNqWo2Un9msIoTP9P7 X-Received: by 2002:a50:fe93:0:b0:51a:5a25:6631 with SMTP id d19-20020a50fe93000000b0051a5a256631mr16295923edt.3.1689163136892; Wed, 12 Jul 2023 04:58:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689163136; cv=none; d=google.com; s=arc-20160816; b=MiFgqPpa2W0qsc3lO1UdReR831FJDISCYUMIOrs+CrfJvWMoK51WEn/pkDUGX9+48y oW/c9ipF9+/uAhxR1wyzzR2B/W9BcIcSm+QPw6egaJO8x/86fxbrVoLpCbeAyqRPIJMA jvaWzxYkGmXOJjOftn1nigD5Qg9iF+ebPijLMJDPK/IN0E93qxWJWFhfUcQ3NlbF/2ae 6+nNmMq1dpImYvT9N48JV3g6vifiJ+jNfXwjRJ54dk4yLXrVugGwNTxCnuMkYL8iFQkr rqFcGnPPgZ5qGT6k91ykCCzQsqXkrrMtBD66hwHEYBk5yezxbnSG5hfpuy5IsTaG/8np jLyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jA+pa1W4L6pW6Ns9EG6fpAnLHRxUqWuF0YnP+e/RZu8=; fh=UsT/IYsmrHK8Tj61E3lO7dmEfkPySLWlJpEUULEmP7s=; b=zuvxoJgnGCFZPF4/rtIw7mCIEr8AUzl1xpMX7IM3b0MReoyCWkI8x9skhdfqMMeZjd 0R/9T53LiN6YwA0R1AGICUOxQRHQTrZcbL+9x85wjJO44g9jLsPR+Lze8At/eeqXEK+/ ZnaW87k3uvBqZS8vrFIbV4Ugj70QBV9KLcQE7Z2NC4f8hNdiP3uGjBu8jd12OMoDBCGI ZKEQh5teqE8GdxjjtikgwMBdDegPDpRe/4vBteMpe5AAVfCLwoDyx2EFy5X2hfChXDaH AkMOAiLm+Jk+KQ4tysvsc29PpvJmN/RoyK8d+4f/UoFszvmRe267sUG79IzQLLUw6nsD tD9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SJBW9F8v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m6-20020aa7d346000000b0051e1644fd3dsi4498301edr.635.2023.07.12.04.58.33; Wed, 12 Jul 2023 04:58:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SJBW9F8v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232968AbjGLLtW (ORCPT + 99 others); Wed, 12 Jul 2023 07:49:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233266AbjGLLs7 (ORCPT ); Wed, 12 Jul 2023 07:48:59 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF8AA1BFB; Wed, 12 Jul 2023 04:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689162489; x=1720698489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OMEwk0X8NNrrJfGShu2S3rKH+WcQr9i/VJ2no0E2OfU=; b=SJBW9F8v+uAp/pG5A19UfaoeZPZvfZKNm57KRc6PGOJkNen+MegSbNQK TBINv575PuPMweUUT1iIMR5teEdFpQnd8/OevGhx09iaiHbuQR0lBHaG4 At4B6j40YZ9OL8AEjosXQSyaMOkBvpNJC52rBDIL6Vl7eeCz2gSDB1cDi hduTnlPlLHu/Z0iNn3YuknNErPwSYLLgvnoONbZR3jxxhov1aCoLaA8Y4 cQlsqkm2XTtPjFJDRSLceT2WPrX8s7RgsBzEAhX8z+BnuaoqV8k5fgP6D 6frPjY310HiHXx/FqAu2VS/vB83W/oKrNj1eC59eJFfalxoBFPh5Qm5TZ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="344469113" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="344469113" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 04:46:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="866094078" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="866094078" Received: from eamonnob-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.237.202]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 04:46:27 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Tejun Heo , Johannes Weiner , Zefan Li , Dave Airlie , Daniel Vetter , Rob Clark , =?UTF-8?q?St=C3=A9phane=20Marchesin?= , "T . J . Mercier" , Kenny.Ho@amd.com, =?UTF-8?q?Christian=20K=C3=B6nig?= , Brian Welty , Tvrtko Ursulin , Aravind Iddamsetty Subject: [PATCH 04/17] drm/i915: Account ring buffer and context state storage Date: Wed, 12 Jul 2023 12:45:52 +0100 Message-Id: <20230712114605.519432-5-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230712114605.519432-1-tvrtko.ursulin@linux.intel.com> References: <20230712114605.519432-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tvrtko Ursulin Account ring buffers and logical context space against the owning client memory usage stats. Signed-off-by: Tvrtko Ursulin Reviewed-by: Aravind Iddamsetty --- drivers/gpu/drm/i915/gt/intel_context.c | 14 ++++++++++++++ drivers/gpu/drm/i915/i915_drm_client.c | 10 ++++++++++ drivers/gpu/drm/i915/i915_drm_client.h | 9 +++++++++ 3 files changed, 33 insertions(+) diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c index a53b26178f0a..a2f1245741bb 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.c +++ b/drivers/gpu/drm/i915/gt/intel_context.c @@ -6,6 +6,7 @@ #include "gem/i915_gem_context.h" #include "gem/i915_gem_pm.h" +#include "i915_drm_client.h" #include "i915_drv.h" #include "i915_trace.h" @@ -50,6 +51,7 @@ intel_context_create(struct intel_engine_cs *engine) int intel_context_alloc_state(struct intel_context *ce) { + struct i915_gem_context *ctx; int err = 0; if (mutex_lock_interruptible(&ce->pin_mutex)) @@ -66,6 +68,18 @@ int intel_context_alloc_state(struct intel_context *ce) goto unlock; set_bit(CONTEXT_ALLOC_BIT, &ce->flags); + + rcu_read_lock(); + ctx = rcu_dereference(ce->gem_context); + if (ctx && !kref_get_unless_zero(&ctx->ref)) + ctx = NULL; + rcu_read_unlock(); + if (ctx) { + if (ctx->client) + i915_drm_client_add_context_objects(ctx->client, + ce); + i915_gem_context_put(ctx); + } } unlock: diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 2e5e69edc0f9..a61356012df8 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -144,4 +144,14 @@ bool i915_drm_client_remove_object(struct drm_i915_gem_object *obj) return true; } + +void i915_drm_client_add_context_objects(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 5f58fdf7dcb8..69cedfcd3d69 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 @@ -70,6 +71,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); bool i915_drm_client_remove_object(struct drm_i915_gem_object *obj); +void i915_drm_client_add_context_objects(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) @@ -79,6 +82,12 @@ static inline void i915_drm_client_add_object(struct i915_drm_client *client, static inline bool i915_drm_client_remove_object(struct drm_i915_gem_object *obj) { } + +static inline void +i915_drm_client_add_context_objects(struct i915_drm_client *client, + struct intel_context *ce) +{ +} #endif #endif /* !__I915_DRM_CLIENT_H__ */ -- 2.39.2