From patchwork Thu Feb 4 12:11:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 12067245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72948C433E0 for ; Thu, 4 Feb 2021 12:11:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 005AA64E8C for ; Thu, 4 Feb 2021 12:11:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 005AA64E8C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=chris-wilson.co.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C3EDF6EC9D; Thu, 4 Feb 2021 12:11:36 +0000 (UTC) Received: from fireflyinternet.com (unknown [77.68.26.236]) by gabe.freedesktop.org (Postfix) with ESMTPS id 60A3D6EC98; Thu, 4 Feb 2021 12:11:35 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.69.177; Received: from build.alporthouse.com (unverified [78.156.69.177]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 23785959-1500050 for multiple; Thu, 04 Feb 2021 12:11:29 +0000 From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [RFC 3/3] drm/i915/gt: Export device and per-process runtimes via procfs Date: Thu, 4 Feb 2021 12:11:21 +0000 Message-Id: <20210204121121.2660-3-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210204121121.2660-1-chris@chris-wilson.co.uk> References: <20210204121121.2660-1-chris@chris-wilson.co.uk> 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: intel-gfx@lists.freedesktop.org, Chris Wilson Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Register with /proc/gpu to provide the client runtimes for generic top-like overview, e.g. gnome-system-monitor can use this information to show the per-process multi-GPU usage. Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/Makefile | 1 + drivers/gpu/drm/i915/gt/intel_gt.c | 5 ++ drivers/gpu/drm/i915/gt/intel_gt_proc.c | 66 ++++++++++++++++++++++++ drivers/gpu/drm/i915/gt/intel_gt_proc.h | 14 +++++ drivers/gpu/drm/i915/gt/intel_gt_types.h | 3 ++ 5 files changed, 89 insertions(+) create mode 100644 drivers/gpu/drm/i915/gt/intel_gt_proc.c create mode 100644 drivers/gpu/drm/i915/gt/intel_gt_proc.h diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile index ce01634d4ea7..16171f65f5d1 100644 --- a/drivers/gpu/drm/i915/Makefile +++ b/drivers/gpu/drm/i915/Makefile @@ -104,6 +104,7 @@ gt-y += \ gt/intel_gt_irq.o \ gt/intel_gt_pm.o \ gt/intel_gt_pm_irq.o \ + gt/intel_gt_proc.o \ gt/intel_gt_requests.o \ gt/intel_gtt.o \ gt/intel_llc.o \ diff --git a/drivers/gpu/drm/i915/gt/intel_gt.c b/drivers/gpu/drm/i915/gt/intel_gt.c index ca76f93bc03d..72199c13330d 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt.c +++ b/drivers/gpu/drm/i915/gt/intel_gt.c @@ -12,6 +12,7 @@ #include "intel_gt_buffer_pool.h" #include "intel_gt_clock_utils.h" #include "intel_gt_pm.h" +#include "intel_gt_proc.h" #include "intel_gt_requests.h" #include "intel_mocs.h" #include "intel_rc6.h" @@ -373,6 +374,8 @@ void intel_gt_driver_register(struct intel_gt *gt) intel_rps_driver_register(>->rps); debugfs_gt_register(gt); + + intel_gt_driver_register__proc(gt); } static int intel_gt_init_scratch(struct intel_gt *gt, unsigned int size) @@ -656,6 +659,8 @@ void intel_gt_driver_unregister(struct intel_gt *gt) { intel_wakeref_t wakeref; + intel_gt_driver_unregister__proc(gt); + intel_rps_driver_unregister(>->rps); /* diff --git a/drivers/gpu/drm/i915/gt/intel_gt_proc.c b/drivers/gpu/drm/i915/gt/intel_gt_proc.c new file mode 100644 index 000000000000..42db22326c7c --- /dev/null +++ b/drivers/gpu/drm/i915/gt/intel_gt_proc.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2020 Intel Corporation + */ + +#include + +#include "i915_drm_client.h" +#include "i915_drv.h" +#include "intel_gt.h" +#include "intel_gt_pm.h" +#include "intel_gt_proc.h" + +static void proc_runtime_pid(struct intel_gt *gt, + struct pid *pid, + struct proc_gpu_runtime *rt) +{ + struct i915_drm_clients *clients = >->i915->clients; + + BUILD_BUG_ON(MAX_ENGINE_CLASS >= ARRAY_SIZE(rt->channel)); + + rt->device = i915_drm_clients_get_runtime(clients, pid, rt->channel); + rt->nchannel = MAX_ENGINE_CLASS + 1; +} + +static void proc_runtime_device(struct intel_gt *gt, + struct pid *pid, + struct proc_gpu_runtime *rt) +{ + struct intel_engine_cs *engine; + enum intel_engine_id id; + ktime_t dummy; + + rt->nchannel = 0; + for_each_engine(engine, gt, id) { + rt->channel[rt->nchannel++] = + intel_engine_get_busy_time(engine, &dummy); + if (rt->nchannel == ARRAY_SIZE(rt->channel)) + break; + } + rt->device = intel_gt_get_awake_time(gt); +} + +static void proc_runtime(struct proc_gpu *pg, + struct pid *pid, + struct proc_gpu_runtime *rt) +{ + struct intel_gt *gt = container_of(pg, typeof(*gt), proc); + + strscpy(rt->name, dev_name(gt->i915->drm.dev), sizeof(rt->name)); + if (pid) + proc_runtime_pid(gt, pid, rt); + else + proc_runtime_device(gt, pid, rt); +} + +void intel_gt_driver_register__proc(struct intel_gt *gt) +{ + gt->proc.fn = proc_runtime; + proc_gpu_register(>->proc); +} + +void intel_gt_driver_unregister__proc(struct intel_gt *gt) +{ + proc_gpu_unregister(>->proc); +} diff --git a/drivers/gpu/drm/i915/gt/intel_gt_proc.h b/drivers/gpu/drm/i915/gt/intel_gt_proc.h new file mode 100644 index 000000000000..7a9bff0fb020 --- /dev/null +++ b/drivers/gpu/drm/i915/gt/intel_gt_proc.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2020 Intel Corporation + */ + +#ifndef INTEL_GT_PROC_H +#define INTEL_GT_PROC_H + +struct intel_gt; + +void intel_gt_driver_register__proc(struct intel_gt *gt); +void intel_gt_driver_unregister__proc(struct intel_gt *gt); + +#endif /* INTEL_GT_PROC_H */ diff --git a/drivers/gpu/drm/i915/gt/intel_gt_types.h b/drivers/gpu/drm/i915/gt/intel_gt_types.h index 626af37c7790..3fc6d9741764 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_types.h +++ b/drivers/gpu/drm/i915/gt/intel_gt_types.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -135,6 +136,8 @@ struct intel_gt { struct i915_vma *scratch; + struct proc_gpu proc; + struct intel_gt_info { intel_engine_mask_t engine_mask; u8 num_engines;