Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp937533lqg; Sat, 2 Mar 2024 07:49:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX3yeFq8wPH1tzsBNjKFEk/nuf3IINwJ8d0WPblI91KS1twp+Uj4kTr+Z6bQzJnUjQFJ5KwVIcBVYgdagJwokXnHeG2X22tK0XlnAOJyg== X-Google-Smtp-Source: AGHT+IGBSWtAMFUrA/wkDZI6844WK5pteqdwBcYGvSCVcKLtVvn3FHlI4v7o2Tyf2LlXrvH1Jmwb X-Received: by 2002:a05:6808:1a0f:b0:3c0:3189:d9e2 with SMTP id bk15-20020a0568081a0f00b003c03189d9e2mr6129769oib.20.1709394595534; Sat, 02 Mar 2024 07:49:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709394595; cv=pass; d=google.com; s=arc-20160816; b=JcUoLSNEhLkVTQvi+wv7dOKNQu2feu2Ka6zNAHLTtDncw4LpuKl1g1HjYq+A1X+Xzx HTodx0VsB8M5bIoCAI8FlD8PmP+fG0brwXsQPM9AAZsWzEFeWQnZ6gdoLo5XjIhVYc/p 0AFNseTx1/yAVMwwTrf4DegnogsBdGYymQVs/CgFepNhfTQOmAnn+pLKAmqrcHAbZ87r NTaU4lHwAmdntR1h1ZDXfhKBKbV6TiWdDbooUox6J/Q4i7W+csG4IKs87o5zSGkNIU5Y nET6yHgM1NG4enFRtghD5pA9EemONcQN970QQ3VmRWsyeqU7E057bKD3jWMIU9xNMMT+ xF9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FFSX8euKO2iIKNfDvEbT2z+JbUzJRreiRGCif9OyZPA=; fh=bI8mYZxs9jz9jxpDpcrXa/ST+1S4mEjWvnZWMNzpdY8=; b=wG/2uhj2CwqVhmkgsU4oASr7ifCQBL5OpDRosDo7yLd0RegcyysakwV929RdHzRk06 Sw/pAG8GSp0GXVzqbAQ2KBR4h4a7N73xkslCizZLqAhghJjS6cmOH/XRdLbEiqQxqKR6 VJooLaTWH/INQvTOoDFPJUqh94nhcAO36nrG7MgT+H2tUdWuMDRFxB32ZWnkolTrzM0X k8v4cLEvhomdk/dh0wUItrTcgNt+X1pXEg1fkMUXbtgGIC6m3NEOYh+Bye9ta1qTZGf8 TEzfVqwg/Z9uOlMMwYKbILyV1RbmtgxpBtFerxaNsxKw6lNBJKfxNgp7mL97dBmRi33z F9Ug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Q7+2ok62; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-89485-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89485-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q11-20020a63e94b000000b005cf5895bfa6si5509374pgj.814.2024.03.02.07.49.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Mar 2024 07:49:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89485-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Q7+2ok62; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-89485-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89485-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2E59D2823E8 for ; Sat, 2 Mar 2024 15:49:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1ADC720DC5; Sat, 2 Mar 2024 15:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="Q7+2ok62" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED01018C08; Sat, 2 Mar 2024 15:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709394576; cv=none; b=r65T+muq8VmkPO4OCSWacVClM79SDqhhl/t6DoEpLG+GdrA4BgLlbAmcKo66VT9Czy8GXuz9A1YzuYX49Ck7BrANfqGt1sODUngkEmyWzvRfG7p43mc63iWdjTBOxz1Vm2UyHQ2v2VpAwEFx5GqTSbjQCdU37l3weyC0gVjgcM0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709394576; c=relaxed/simple; bh=pVdbaVjIIA20Bjg3c6GsLHOmOo/dWqiDf6i0eRkE78c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oBbba+NQWVsw6qrFZSXDdVcPLivg6kJXBRT4fe4084WI+IHngZearKLRLSm/63KCPPnScGnuEaCk5FE/rDCMpXPPUWboq4aRYP6lSMv1J3w2n7PGnbBUoN/wtDn+r++53uFBx+xdaaO+2zbyp0piURvNs2MqsJYPH3bsb5akjLU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=Q7+2ok62; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1709394573; bh=pVdbaVjIIA20Bjg3c6GsLHOmOo/dWqiDf6i0eRkE78c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q7+2ok625bLrkH3ObT64vZxoMSGrYnzdkt2J6ct9diCtRTHf9116ukA7dAfR4Jmel yKgid/5g+4UR6amFRnAwgJxdnpi1aFpi5pvs4me18uanPOHnHslJZHljf0LqQO2vUm GO3vB9SAqn3+5Gr6FYdsXDQBpt5DHEB23dK/ChC4kles4CWEOam59fJshn7+isRSh5 2TsvlMZCEQofX2h8uZ+zV437kMHIGg34mlYdPG+LPcwdX7lQnOxUhxlRtdnQhdckYM GzsKMSrZdpHp8Zy5ZIwMotvyF+G3S4TmJHknOFoaL2K6bSb7MMM2hiT9T/iT2wrbn+ Y99P5bpocz2WA== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: alarumbe) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 5455F378208D; Sat, 2 Mar 2024 15:49:32 +0000 (UTC) From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= To: Boris Brezillon , Rob Herring , Steven Price , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Jonathan Corbet Cc: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org Subject: [PATCH v2 1/1] drm/panfrost: Replace fdinfo's profiling debugfs knob with sysfs Date: Sat, 2 Mar 2024 15:48:41 +0000 Message-ID: <20240302154845.3223223-3-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240302154845.3223223-2-adrian.larumbe@collabora.com> References: <20240302154845.3223223-2-adrian.larumbe@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Debugfs isn't always available in production builds that try to squeeze every single byte out of the kernel image, but we still need a way to toggle the timestamp and cycle counter registers so that jobs can be profiled for fdinfo's drm engine and cycle calculations. Drop the debugfs knob and replace it with a sysfs file that accomplishes the same functionality, and document its ABI in a separate file. Signed-off-by: Adrián Larumbe --- .../testing/sysfs-driver-panfrost-profiling | 10 +++ Documentation/gpu/panfrost.rst | 9 +++ drivers/gpu/drm/panfrost/Makefile | 5 +- drivers/gpu/drm/panfrost/panfrost_debugfs.c | 21 ------ drivers/gpu/drm/panfrost/panfrost_debugfs.h | 14 ---- drivers/gpu/drm/panfrost/panfrost_device.h | 5 +- drivers/gpu/drm/panfrost/panfrost_drv.c | 14 ++-- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/panfrost/panfrost_sysfs.c | 70 +++++++++++++++++++ drivers/gpu/drm/panfrost/panfrost_sysfs.h | 15 ++++ 10 files changed, 120 insertions(+), 45 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-panfrost-profiling delete mode 100644 drivers/gpu/drm/panfrost/panfrost_debugfs.c delete mode 100644 drivers/gpu/drm/panfrost/panfrost_debugfs.h create mode 100644 drivers/gpu/drm/panfrost/panfrost_sysfs.c create mode 100644 drivers/gpu/drm/panfrost/panfrost_sysfs.h diff --git a/Documentation/ABI/testing/sysfs-driver-panfrost-profiling b/Documentation/ABI/testing/sysfs-driver-panfrost-profiling new file mode 100644 index 000000000000..889527b71b9d --- /dev/null +++ b/Documentation/ABI/testing/sysfs-driver-panfrost-profiling @@ -0,0 +1,10 @@ +What: /sys/bus/.../drivers/panfrost/.../drm/../profiling/status +Date: February 2024 +KernelVersion: 6.8.0 +Contact: Adrian Larumbe +Description: + Get/set drm fdinfo's engine and cycles profiling status. + Valid values are: + 0: Don't enable fdinfo job profiling sources. + 1: Enable fdinfo job profiling sources, this enables both the GPU's + timestamp and cycle counter registers. \ No newline at end of file diff --git a/Documentation/gpu/panfrost.rst b/Documentation/gpu/panfrost.rst index b80e41f4b2c5..be4ac282ef63 100644 --- a/Documentation/gpu/panfrost.rst +++ b/Documentation/gpu/panfrost.rst @@ -38,3 +38,12 @@ the currently possible format options: Possible `drm-engine-` key names are: `fragment`, and `vertex-tiler`. `drm-curfreq-` values convey the current operating frequency for that engine. + +Users must bear in mind that engine and cycle sampling are disabled by default, +because of power saving concerns. `fdinfo` users and benchmark applications which +query the fdinfo file must make sure to toggle the job profiling status of the +driver by writing into the appropriate sysfs node:: + + echo > /sys/bus/platform/drivers/panfrost/[a-f0-9]*.gpu/drm/card1/profiling + +Where `N` is either `0` or `1`, depending on the desired enablement status. diff --git a/drivers/gpu/drm/panfrost/Makefile b/drivers/gpu/drm/panfrost/Makefile index 2c01c1e7523e..6e718595d8a6 100644 --- a/drivers/gpu/drm/panfrost/Makefile +++ b/drivers/gpu/drm/panfrost/Makefile @@ -10,8 +10,7 @@ panfrost-y := \ panfrost_job.o \ panfrost_mmu.o \ panfrost_perfcnt.o \ - panfrost_dump.o - -panfrost-$(CONFIG_DEBUG_FS) += panfrost_debugfs.o + panfrost_dump.o \ + panfrost_sysfs.o obj-$(CONFIG_DRM_PANFROST) += panfrost.o diff --git a/drivers/gpu/drm/panfrost/panfrost_debugfs.c b/drivers/gpu/drm/panfrost/panfrost_debugfs.c deleted file mode 100644 index 72d4286a6bf7..000000000000 --- a/drivers/gpu/drm/panfrost/panfrost_debugfs.c +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* Copyright 2023 Collabora ltd. */ -/* Copyright 2023 Amazon.com, Inc. or its affiliates. */ - -#include -#include -#include -#include -#include - -#include "panfrost_device.h" -#include "panfrost_gpu.h" -#include "panfrost_debugfs.h" - -void panfrost_debugfs_init(struct drm_minor *minor) -{ - struct drm_device *dev = minor->dev; - struct panfrost_device *pfdev = platform_get_drvdata(to_platform_device(dev->dev)); - - debugfs_create_atomic_t("profile", 0600, minor->debugfs_root, &pfdev->profile_mode); -} diff --git a/drivers/gpu/drm/panfrost/panfrost_debugfs.h b/drivers/gpu/drm/panfrost/panfrost_debugfs.h deleted file mode 100644 index c5af5f35877f..000000000000 --- a/drivers/gpu/drm/panfrost/panfrost_debugfs.h +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright 2023 Collabora ltd. - * Copyright 2023 Amazon.com, Inc. or its affiliates. - */ - -#ifndef PANFROST_DEBUGFS_H -#define PANFROST_DEBUGFS_H - -#ifdef CONFIG_DEBUG_FS -void panfrost_debugfs_init(struct drm_minor *minor); -#endif - -#endif /* PANFROST_DEBUGFS_H */ diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h index 62f7e3527385..2f3580c7ba0d 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.h +++ b/drivers/gpu/drm/panfrost/panfrost_device.h @@ -130,7 +130,10 @@ struct panfrost_device { struct list_head scheduled_jobs; struct panfrost_perfcnt *perfcnt; - atomic_t profile_mode; + struct kobj_profiling { + struct kobject base; + bool profile_mode; + } profiling; struct mutex sched_lock; diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index a926d71e8131..6db1ea453514 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -20,7 +20,7 @@ #include "panfrost_job.h" #include "panfrost_gpu.h" #include "panfrost_perfcnt.h" -#include "panfrost_debugfs.h" +#include "panfrost_sysfs.h" static bool unstable_ioctls; module_param_unsafe(unstable_ioctls, bool, 0600); @@ -600,10 +600,6 @@ static const struct drm_driver panfrost_drm_driver = { .gem_create_object = panfrost_gem_create_object, .gem_prime_import_sg_table = panfrost_gem_prime_import_sg_table, - -#ifdef CONFIG_DEBUG_FS - .debugfs_init = panfrost_debugfs_init, -#endif }; static int panfrost_probe(struct platform_device *pdev) @@ -663,8 +659,14 @@ static int panfrost_probe(struct platform_device *pdev) if (err) goto err_out2; + err = panfrost_sysfs_init(pfdev); + if (err) + goto err_out3; + return 0; +err_out3: + panfrost_gem_shrinker_cleanup(ddev); err_out2: drm_dev_unregister(ddev); err_out1: @@ -681,6 +683,8 @@ static void panfrost_remove(struct platform_device *pdev) struct panfrost_device *pfdev = platform_get_drvdata(pdev); struct drm_device *ddev = pfdev->ddev; + panfrost_sysfs_cleanup(pfdev); + drm_dev_unregister(ddev); panfrost_gem_shrinker_cleanup(ddev); diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c index 0c2dbf6ef2a5..1be9c31b2b61 100644 --- a/drivers/gpu/drm/panfrost/panfrost_job.c +++ b/drivers/gpu/drm/panfrost/panfrost_job.c @@ -243,7 +243,7 @@ static void panfrost_job_hw_submit(struct panfrost_job *job, int js) subslot = panfrost_enqueue_job(pfdev, js, job); /* Don't queue the job if a reset is in progress */ if (!atomic_read(&pfdev->reset.pending)) { - if (atomic_read(&pfdev->profile_mode)) { + if (pfdev->profiling.profile_mode) { panfrost_cycle_counter_get(pfdev); job->is_profiled = true; job->start_time = ktime_get(); diff --git a/drivers/gpu/drm/panfrost/panfrost_sysfs.c b/drivers/gpu/drm/panfrost/panfrost_sysfs.c new file mode 100644 index 000000000000..380d74e61611 --- /dev/null +++ b/drivers/gpu/drm/panfrost/panfrost_sysfs.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright 2023 Collabora ltd. */ +/* Copyright 2023 Amazon.com, Inc. or its affiliates. */ + +#include +#include +#include + +#include "panfrost_device.h" +#include "panfrost_gpu.h" +#include "panfrost_sysfs.h" + +static ssize_t +profiling_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + bool *profile_mode = + &container_of(kobj, struct panfrost_device, + profiling.base)->profiling.profile_mode; + + return sysfs_emit(buf, "%d\n", *profile_mode); +} + +static ssize_t +profiling_store(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count) +{ + bool *profile_mode = + &container_of(kobj, struct panfrost_device, + profiling.base)->profiling.profile_mode; + int err, value; + + err = kstrtoint(buf, 0, &value); + if (err) + return err; + + *profile_mode = !!value; + + return count; +} + +static const struct kobj_attribute profiling_status = +__ATTR(status, 0644, profiling_show, profiling_store); + +static const struct kobj_type kobj_profile_type = { + .sysfs_ops = &kobj_sysfs_ops, +}; + +int panfrost_sysfs_init(struct panfrost_device *pfdev) +{ + struct device *kdev = pfdev->ddev->primary->kdev; + int err; + + kobject_init(&pfdev->profiling.base, &kobj_profile_type); + + err = kobject_add(&pfdev->profiling.base, &kdev->kobj, "%s", "profiling"); + if (err) + return err; + + err = sysfs_create_file(&pfdev->profiling.base, &profiling_status.attr); + if (err) + kobject_del(&pfdev->profiling.base); + + return err; +} + +void panfrost_sysfs_cleanup(struct panfrost_device *pfdev) +{ + sysfs_remove_file(&pfdev->profiling.base, &profiling_status.attr); + kobject_del(&pfdev->profiling.base); +} diff --git a/drivers/gpu/drm/panfrost/panfrost_sysfs.h b/drivers/gpu/drm/panfrost/panfrost_sysfs.h new file mode 100644 index 000000000000..5fc9c8c1091a --- /dev/null +++ b/drivers/gpu/drm/panfrost/panfrost_sysfs.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright 2023 Collabora ltd. + * Copyright 2023 Amazon.com, Inc. or its affiliates. + */ + +#ifndef PANFROST_SYSFS_H +#define PANFROST_SYSFS_H + +struct panfrost_device; + +int panfrost_sysfs_init(struct panfrost_device *pfdev); +void panfrost_sysfs_cleanup(struct panfrost_device *pfdev); + +#endif /* PANFROST_SYSFS_H */ -- 2.43.0