Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3831607pxb; Mon, 4 Oct 2021 10:31:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw24cXt1gmC0+ZnWjls3yDks0NgudmLt5BG8wZxD4eY1TEY00JpCuEOzt8WjfSR/FbL8XDe X-Received: by 2002:aa7:db52:: with SMTP id n18mr20610446edt.17.1633368713966; Mon, 04 Oct 2021 10:31:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633368713; cv=none; d=google.com; s=arc-20160816; b=TkDO398/M3stP73ETRmYpiOGLNsPsYAZ9aAlyWQZZ600+O+H5JYC5mOB3lRcx0jxMc U96NFIu5nhw8rlM6IYGxM37RnvyW2mZucv6o+q2gplk3qN8+q3apsmhxfMQbJQWHl2ji If3tGNkPvfJgLFw13TxeU0oeOLEXh7mRnU2ML+jC72hFipoFW+C+/qhrGoNrCimLPLh6 cvDf2n8tpvuYPgbDroyk1zD1SXpX7kx0yC4X7dNNTlo6NgHWIle8X7JdrrdnY5kCAwcP BgeunA8hCjp2BtLphB8srlEhSiGnpyiigc5edyx+fI0QNkBetjjaqIbhiwbpQnHj4+vc CHZw== 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; bh=NAulcI2mn7XWH0AuXzm8OduW7dB5F91pKsRQPIoqoMY=; b=QOkyqxJl1LUyRQnZBtPi5KnprNgJG81x89raAj+l/aOn/PYLDqq8IYYpxdbXRerm0f Bnfe3beT56c3cQYVgy1BqZ+J3x4eLC6nJsGAmEYu6RjLwELXcEzB1sUPUhNR1Caci2YZ LRpez7QQ8D5XnCnkAmbU6XG0xkWcmsjvoAhg06QvKwdXThXQ7ofJlT/DivSfmEXk8fy5 b94ggABW7Snygjj/g9E0gmMp8nVeBY6AC9d64hJ+tToJP2m98J+v2891MILgYk5WHyGI QUKZsBmbWxVvGWdqy/4aRDrhmpNyGln2jld53uanB33FKFVmgNkKlUANbdZDri7G/bV2 uCzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y8si23967684eda.141.2021.10.04.10.31.28; Mon, 04 Oct 2021 10:31:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234998AbhJDOrN (ORCPT + 99 others); Mon, 4 Oct 2021 10:47:13 -0400 Received: from mga01.intel.com ([192.55.52.88]:16798 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234927AbhJDOrJ (ORCPT ); Mon, 4 Oct 2021 10:47:09 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10126"; a="248714001" X-IronPort-AV: E=Sophos;i="5.85,346,1624345200"; d="scan'208";a="248714001" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 07:37:18 -0700 X-IronPort-AV: E=Sophos;i="5.85,346,1624345200"; d="scan'208";a="622303676" Received: from shearne-mobl.ger.corp.intel.com (HELO tursulin-mobl2.home) ([10.213.208.122]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 07:37:16 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Tvrtko Ursulin , Aravind Iddamsetty , Chris Wilson Subject: [RFC 4/8] drm/i915: Track all user contexts per client Date: Mon, 4 Oct 2021 15:36:46 +0100 Message-Id: <20211004143650.699120-5-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211004143650.699120-1-tvrtko.ursulin@linux.intel.com> References: <20211004143650.699120-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tvrtko Ursulin We soon want to start answering questions like how much GPU time is the context belonging to a client which exited still using. To enable this we start tracking all context belonging to a client on a separate list. Signed-off-by: Tvrtko Ursulin Reviewed-by: Aravind Iddamsetty Reviewed-by: Chris Wilson Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 12 ++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_context_types.h | 3 +++ drivers/gpu/drm/i915/i915_drm_client.c | 2 ++ drivers/gpu/drm/i915/i915_drm_client.h | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index 9296d69681d7..d1992ba59ed8 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -1169,6 +1169,7 @@ static void set_closed_name(struct i915_gem_context *ctx) static void context_close(struct i915_gem_context *ctx) { + struct i915_drm_client *client; struct i915_address_space *vm; /* Flush any concurrent set_engines() */ @@ -1205,6 +1206,13 @@ static void context_close(struct i915_gem_context *ctx) list_del(&ctx->link); spin_unlock(&ctx->i915->gem.contexts.lock); + client = ctx->client; + if (client) { + spin_lock(&client->ctx_lock); + list_del_rcu(&ctx->client_link); + spin_unlock(&client->ctx_lock); + } + mutex_unlock(&ctx->mutex); /* @@ -1385,6 +1393,10 @@ static void gem_context_register(struct i915_gem_context *ctx, old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL); WARN_ON(old); + spin_lock(&ctx->client->ctx_lock); + list_add_tail_rcu(&ctx->client_link, &ctx->client->ctx_list); + spin_unlock(&ctx->client->ctx_lock); + spin_lock(&i915->gem.contexts.lock); list_add_tail(&ctx->link, &i915->gem.contexts.list); spin_unlock(&i915->gem.contexts.lock); 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 598c57ac5cdf..b878e1b13b38 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h @@ -280,6 +280,9 @@ struct i915_gem_context { /** @client: struct i915_drm_client */ struct i915_drm_client *client; + /** link: &drm_client.context_list */ + struct list_head client_link; + /** * @ref: reference count * diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index e61e9ba15256..91a8559bebf7 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -38,6 +38,8 @@ struct i915_drm_client *i915_drm_client_add(struct i915_drm_clients *clients) goto err; kref_init(&client->kref); + spin_lock_init(&client->ctx_lock); + INIT_LIST_HEAD(&client->ctx_list); client->clients = clients; return client; diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h index e8986ad51176..0207dfad4568 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.h +++ b/drivers/gpu/drm/i915/i915_drm_client.h @@ -7,6 +7,8 @@ #define __I915_DRM_CLIENT_H__ #include +#include +#include #include struct drm_i915_private; @@ -23,6 +25,9 @@ struct i915_drm_client { unsigned int id; + spinlock_t ctx_lock; /* For add/remove from ctx_list. */ + struct list_head ctx_list; /* List of contexts belonging to client. */ + struct i915_drm_clients *clients; }; -- 2.30.2