From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 452FBC43219 for ; Wed, 19 Oct 2022 17:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231281AbiJSRer (ORCPT ); Wed, 19 Oct 2022 13:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231397AbiJSReM (ORCPT ); Wed, 19 Oct 2022 13:34:12 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CDD41D3765; Wed, 19 Oct 2022 10:34: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=1666200850; x=1697736850; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=57xevMaPNuTYw9loIK3v8HjbtAVBJSLqQ4lTiTCwMqQ=; b=b403/DjIO2r0FckCx6SOM0koAAHJZ2j5vZVUjwN7GcB6jJf6KNBKeme3 opYJEwTVl6Ge+palbio+0/ishxAb71+4mJiJILJnrJHMRv2DPN70P7zP4 KW2AiNyfdnBjyxQw8eevt6AKaCztGm6N0F1BMKd68k3F4ADNmdJQ1QvTT fKsESVkZiBuoDyiUF7/iH+1c5Ozzh0ZBDtQka7YH64PPIafL3TAZt5EDu 5NaUXct4Hga8uQjwgkx5vkx7jeRV06UYkUony3vaJ8cbl61i8xwtmkg2j k1bRLEd3er4WtEKSC7WpM29VRiVeh4OJ0YEyYjX7g1jfgqb2D8qVHH2Fi w==; X-IronPort-AV: E=McAfee;i="6500,9779,10505"; a="306474511" X-IronPort-AV: E=Sophos;i="5.95,196,1661842800"; d="scan'208";a="306474511" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2022 10:33:53 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10505"; a="607204806" X-IronPort-AV: E=Sophos;i="5.95,196,1661842800"; d="scan'208";a="607204806" Received: from mjmcener-mobl1.amr.corp.intel.com (HELO localhost.localdomain) ([10.213.233.40]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2022 10:33:50 -0700 From: Tvrtko Ursulin To: Intel-gfx@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 Subject: [RFC 10/17] drm: Add ability to query drm cgroup GPU time Date: Wed, 19 Oct 2022 18:32:47 +0100 Message-Id: <20221019173254.3361334-11-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019173254.3361334-1-tvrtko.ursulin@linux.intel.com> References: <20221019173254.3361334-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 Add a driver callback and core helper which allow querying the time spent on GPUs for processes belonging to a group. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/drm_cgroup.c | 24 ++++++++++++++++++++++++ include/drm/drm_clients.h | 1 + include/drm/drm_drv.h | 9 +++++++++ 3 files changed, 34 insertions(+) diff --git a/drivers/gpu/drm/drm_cgroup.c b/drivers/gpu/drm/drm_cgroup.c index 59b730ed1334..e0cadb5e5659 100644 --- a/drivers/gpu/drm/drm_cgroup.c +++ b/drivers/gpu/drm/drm_cgroup.c @@ -206,3 +206,27 @@ void drm_pid_update_priority(struct pid *pid, int priority) rcu_read_unlock(); } EXPORT_SYMBOL_GPL(drm_pid_update_priority); + +u64 drm_pid_get_active_time_us(struct pid *pid) +{ + struct drm_pid_clients *clients; + u64 total = 0; + + rcu_read_lock(); + clients = xa_load(&drm_pid_clients, (unsigned long)pid); + if (clients) { + struct drm_file *fpriv; + + list_for_each_entry_rcu(fpriv, &clients->file_list, clink) { + const struct drm_cgroup_ops *cg_ops = + fpriv->minor->dev->driver->cg_ops; + + if (cg_ops && cg_ops->active_time_us) + total += cg_ops->active_time_us(fpriv); + } + } + rcu_read_unlock(); + + return total; +} +EXPORT_SYMBOL_GPL(drm_pid_get_active_time_us); diff --git a/include/drm/drm_clients.h b/include/drm/drm_clients.h index 3a0b1cdb338f..f25e09ed5feb 100644 --- a/include/drm/drm_clients.h +++ b/include/drm/drm_clients.h @@ -37,5 +37,6 @@ static inline void drm_clients_migrate(struct drm_file *file_priv) unsigned int drm_pid_priority_levels(struct pid *pid, bool *non_uniform); void drm_pid_update_priority(struct pid *pid, int priority); +u64 drm_pid_get_active_time_us(struct pid *pid); #endif diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 2371d73e12cf..0f1802df01fe 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -183,6 +183,15 @@ struct drm_cgroup_ops { * priorities of already running workloads. */ void (*update_priority) (struct drm_file *, int priority); + + /** + * @active_time_us: + * + * Optional callback for reporting the GPU time consumed by this client. + * + * Used by the DRM core when queried by the DRM cgroup controller. + */ + u64 (*active_time_us) (struct drm_file *); }; /** -- 2.34.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 72D93C433FE for ; Wed, 19 Oct 2022 17:36:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A32810EB45; Wed, 19 Oct 2022 17:36:19 +0000 (UTC) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 97B4D10F2A3 for ; Wed, 19 Oct 2022 17:33: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=1666200833; x=1697736833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=57xevMaPNuTYw9loIK3v8HjbtAVBJSLqQ4lTiTCwMqQ=; b=nsoP9adQIPM0XUDzfaTVp2l91hMzBOSEjHl0+2T+a1xBPbq/9Q65Fvou NUemIX5ld2s7PcCFMrJ/OMcprdyNpC+2mNW1mpGFlrXxpeBV14Le966Z2 7Arzlajjywkdm9iSV/IET19dmeN52VL6rBTMAjHtT/0nxgGGHh4YIE33b +ifiPr7RyBYfaAaUlecW1IWaOiHsgPhyZPQsiF/IgBLL6H5cEBBSOOqdS STMlNP+JRXHLGk4hPOmmUEwSOCCeFuwCQ59UTTaWu11z5gTGn1y37FUxn 2Wjv0FkikC8uAjlB2R3lwgdeOywNOrFTuHhQ6fnFWygBNLoLAi0KNrX9E Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10505"; a="286201741" X-IronPort-AV: E=Sophos;i="5.95,196,1661842800"; d="scan'208";a="286201741" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2022 10:33:53 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10505"; a="607204806" X-IronPort-AV: E=Sophos;i="5.95,196,1661842800"; d="scan'208";a="607204806" Received: from mjmcener-mobl1.amr.corp.intel.com (HELO localhost.localdomain) ([10.213.233.40]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2022 10:33:50 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Wed, 19 Oct 2022 18:32:47 +0100 Message-Id: <20221019173254.3361334-11-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019173254.3361334-1-tvrtko.ursulin@linux.intel.com> References: <20221019173254.3361334-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Intel-gfx] [RFC 10/17] drm: Add ability to query drm cgroup GPU time X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Kenny.Ho@amd.com, Daniel Vetter , Johannes Weiner , linux-kernel@vger.kernel.org, =?UTF-8?q?St=C3=A9phane=20Marchesin?= , =?UTF-8?q?Christian=20K=C3=B6nig?= , Zefan Li , Dave Airlie , Tejun Heo , cgroups@vger.kernel.org, "T . J . Mercier" Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Tvrtko Ursulin Add a driver callback and core helper which allow querying the time spent on GPUs for processes belonging to a group. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/drm_cgroup.c | 24 ++++++++++++++++++++++++ include/drm/drm_clients.h | 1 + include/drm/drm_drv.h | 9 +++++++++ 3 files changed, 34 insertions(+) diff --git a/drivers/gpu/drm/drm_cgroup.c b/drivers/gpu/drm/drm_cgroup.c index 59b730ed1334..e0cadb5e5659 100644 --- a/drivers/gpu/drm/drm_cgroup.c +++ b/drivers/gpu/drm/drm_cgroup.c @@ -206,3 +206,27 @@ void drm_pid_update_priority(struct pid *pid, int priority) rcu_read_unlock(); } EXPORT_SYMBOL_GPL(drm_pid_update_priority); + +u64 drm_pid_get_active_time_us(struct pid *pid) +{ + struct drm_pid_clients *clients; + u64 total = 0; + + rcu_read_lock(); + clients = xa_load(&drm_pid_clients, (unsigned long)pid); + if (clients) { + struct drm_file *fpriv; + + list_for_each_entry_rcu(fpriv, &clients->file_list, clink) { + const struct drm_cgroup_ops *cg_ops = + fpriv->minor->dev->driver->cg_ops; + + if (cg_ops && cg_ops->active_time_us) + total += cg_ops->active_time_us(fpriv); + } + } + rcu_read_unlock(); + + return total; +} +EXPORT_SYMBOL_GPL(drm_pid_get_active_time_us); diff --git a/include/drm/drm_clients.h b/include/drm/drm_clients.h index 3a0b1cdb338f..f25e09ed5feb 100644 --- a/include/drm/drm_clients.h +++ b/include/drm/drm_clients.h @@ -37,5 +37,6 @@ static inline void drm_clients_migrate(struct drm_file *file_priv) unsigned int drm_pid_priority_levels(struct pid *pid, bool *non_uniform); void drm_pid_update_priority(struct pid *pid, int priority); +u64 drm_pid_get_active_time_us(struct pid *pid); #endif diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 2371d73e12cf..0f1802df01fe 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -183,6 +183,15 @@ struct drm_cgroup_ops { * priorities of already running workloads. */ void (*update_priority) (struct drm_file *, int priority); + + /** + * @active_time_us: + * + * Optional callback for reporting the GPU time consumed by this client. + * + * Used by the DRM core when queried by the DRM cgroup controller. + */ + u64 (*active_time_us) (struct drm_file *); }; /** -- 2.34.1 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tvrtko Ursulin Subject: [RFC 10/17] drm: Add ability to query drm cgroup GPU time Date: Wed, 19 Oct 2022 18:32:47 +0100 Message-ID: <20221019173254.3361334-11-tvrtko.ursulin@linux.intel.com> References: <20221019173254.3361334-1-tvrtko.ursulin@linux.intel.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666200850; x=1697736850; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=57xevMaPNuTYw9loIK3v8HjbtAVBJSLqQ4lTiTCwMqQ=; b=b403/DjIO2r0FckCx6SOM0koAAHJZ2j5vZVUjwN7GcB6jJf6KNBKeme3 opYJEwTVl6Ge+palbio+0/ishxAb71+4mJiJILJnrJHMRv2DPN70P7zP4 KW2AiNyfdnBjyxQw8eevt6AKaCztGm6N0F1BMKd68k3F4ADNmdJQ1QvTT fKsESVkZiBuoDyiUF7/iH+1c5Ozzh0ZBDtQka7YH64PPIafL3TAZt5EDu 5NaUXct4Hga8uQjwgkx5vkx7jeRV06UYkUony3vaJ8cbl61i8xwtmkg2j k1bRLEd3er4WtEKSC7WpM29VRiVeh4OJ0YEyYjX7g1jfgqb2D8qVHH2Fi w==; In-Reply-To: <20221019173254.3361334-1-tvrtko.ursulin-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> List-ID: Content-Type: text/plain; charset="us-ascii" To: Intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.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-5C7GfCeVMHo@public.gmane.org, =?UTF-8?q?Christian=20K=C3=B6nig?= , Brian Welty , Tvrtko Ursulin From: Tvrtko Ursulin Add a driver callback and core helper which allow querying the time spent on GPUs for processes belonging to a group. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/drm_cgroup.c | 24 ++++++++++++++++++++++++ include/drm/drm_clients.h | 1 + include/drm/drm_drv.h | 9 +++++++++ 3 files changed, 34 insertions(+) diff --git a/drivers/gpu/drm/drm_cgroup.c b/drivers/gpu/drm/drm_cgroup.c index 59b730ed1334..e0cadb5e5659 100644 --- a/drivers/gpu/drm/drm_cgroup.c +++ b/drivers/gpu/drm/drm_cgroup.c @@ -206,3 +206,27 @@ void drm_pid_update_priority(struct pid *pid, int priority) rcu_read_unlock(); } EXPORT_SYMBOL_GPL(drm_pid_update_priority); + +u64 drm_pid_get_active_time_us(struct pid *pid) +{ + struct drm_pid_clients *clients; + u64 total = 0; + + rcu_read_lock(); + clients = xa_load(&drm_pid_clients, (unsigned long)pid); + if (clients) { + struct drm_file *fpriv; + + list_for_each_entry_rcu(fpriv, &clients->file_list, clink) { + const struct drm_cgroup_ops *cg_ops = + fpriv->minor->dev->driver->cg_ops; + + if (cg_ops && cg_ops->active_time_us) + total += cg_ops->active_time_us(fpriv); + } + } + rcu_read_unlock(); + + return total; +} +EXPORT_SYMBOL_GPL(drm_pid_get_active_time_us); diff --git a/include/drm/drm_clients.h b/include/drm/drm_clients.h index 3a0b1cdb338f..f25e09ed5feb 100644 --- a/include/drm/drm_clients.h +++ b/include/drm/drm_clients.h @@ -37,5 +37,6 @@ static inline void drm_clients_migrate(struct drm_file *file_priv) unsigned int drm_pid_priority_levels(struct pid *pid, bool *non_uniform); void drm_pid_update_priority(struct pid *pid, int priority); +u64 drm_pid_get_active_time_us(struct pid *pid); #endif diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 2371d73e12cf..0f1802df01fe 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -183,6 +183,15 @@ struct drm_cgroup_ops { * priorities of already running workloads. */ void (*update_priority) (struct drm_file *, int priority); + + /** + * @active_time_us: + * + * Optional callback for reporting the GPU time consumed by this client. + * + * Used by the DRM core when queried by the DRM cgroup controller. + */ + u64 (*active_time_us) (struct drm_file *); }; /** -- 2.34.1