Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp51721lqp; Thu, 4 Apr 2024 07:00:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW8Lw+7FdGCrZCgg0zYPKkoZjMvfm1bZEBUd4L+ZbWdTHJfxaGzteCA8fGMjfUMT+5P4f1VnsD7FI8OgcjOTT8KH4xyt+FJwFOLGYnexQ== X-Google-Smtp-Source: AGHT+IF5+x85xLl1j4evB8NyQToDsXDdCd2zsxS1J/hYw5fT6luRUJm86ep8LKfjGhBwTuvMBYQl X-Received: by 2002:a05:622a:152:b0:432:f63f:cb83 with SMTP id v18-20020a05622a015200b00432f63fcb83mr2479883qtw.33.1712239241405; Thu, 04 Apr 2024 07:00:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712239241; cv=pass; d=google.com; s=arc-20160816; b=qBZQVWLo1xNDx1TDruzrxOuo6/8y3SmjipMZE/WjHfWk7m8DfAP+F/Wf6ivNfAsfI3 I56EKGsHwTNKH5MZ+cD7/d+aAbX3Vj5AUKpepGYwFEDcoJUSmNyVezNbweSLI7HlwPF1 l1k48G0H5qddD1y0Re30hXG+TAq3Q0mOMpAec6dcN8Taf6GMOHzlKUHNl1fMjQ0N4gJu pUvx3Nn1u8jBNj5kS4B2r1lwzHQah9Do21cXkCSPlaFn8c80hvDV9XrJy4onbWQNsCKc r2CmXQyJXFr85+FCjZ5yBk7ecBq72ZnRuPLKm4SGXsoa4nGO/bW1U5xpmD9ZbubEjabz Ox/w== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=8Fn3v1RkDzS3mSqNdK9RBwQENdcuWU8/IWMHAs0RVa8=; fh=t4hYN1H7ql8PCJxjpaJpqwgoukAsVIcGexokBzATjO0=; b=MDm9ehBxQfER8C1JAx4sgY2dnW0B+9pQx9noQxRYbKJghs3W99HTYcbrfCY4BcZhST byjTLTrCcttI61agsXeOLhSVxf8XZHTTUzlNmfcJebO0UZlkq25nN6tPq4Lz7iBE6QSm 6Oh5x04dTOBIA7IaG2qof3QicQckGBdaOy6ch/3fC0qALKHDASMm/pe+O4uZltSkrsjJ iBJse4GAFsQHkkIMJuk9ke+dicS4J8/GVkUhhWtQxUStEYq4bkAui95cg9gShSIidPol Gruc6y7nWXBWrRH9fj0Zq8RXqpW7cQIwiu/PrsmOeT06ISxB7VNeHJ+fwhZIyOec35MW sZeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GGjUUgyh; 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-131543-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131543-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l8-20020a05622a050800b00432b6d42f00si16941361qtx.344.2024.04.04.07.00.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 07:00:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131543-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GGjUUgyh; 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-131543-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131543-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C08171C20BEC for ; Thu, 4 Apr 2024 14:00:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A75AC1292D7; Thu, 4 Apr 2024 14:00:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="GGjUUgyh" 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 B460C1272BB for ; Thu, 4 Apr 2024 14:00:31 +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=1712239234; cv=none; b=JFIYZ2+QRUdqy6kgiPp4F6UTawTg084b0KX9uAyV3M/uBQZaMT9LX7diaWN8y4I2TnE5lGbMJH7maTZ8r78OQVsNDqCN08/LyG1c+SxjsXE3lPNqf9dKLdIE5RbAoE88WhtMK7uLr1M4/AvmovlZbrZ1Z00wy/HmEa43lLk+CkM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712239234; c=relaxed/simple; bh=tORiLbSgUIPtw0RzW/7izuqRT/xBH93hl3mraCm/EG4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Bdz2NwOtS20rh6HSjFmHR+qIgZz8CZFSfoWFCnr00VLZJ0BW/X3xIN8ABmHf6PsEdn2X90CaFhmj4tKbi2m+t95vtI75Qu6yHtmdLlC9iZv1ElCZWB/SXijFeTn1vBt0MsJXuSqsfxtXWlvKkroaN//JZBM7zOX3RkIRWp/804s= 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=GGjUUgyh; 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=1712239229; bh=tORiLbSgUIPtw0RzW/7izuqRT/xBH93hl3mraCm/EG4=; h=From:To:Cc:Subject:Date:From; b=GGjUUgyhHAiRBOS4ZTeGUqXCK2CyFLkVf1jPgH00ge6tqAcCwEH5kFsBJ1wXyHOBF 1GcD//kEWkDmt/VwVN669gexJLVK0RLjP+050PvEqZ56+zMeHRZ+v2SbPDjkk1+hVs K4iAx+mGEDE/2hZwWub4lsOxH/6rS5rPWLpKrsLRyPJ7c+oWvjs09dNrqC/4Z6KH8h oljuaVpCYYQT9AolDFEf7Q/qDbKNpQShuYU/gB4yCYoA75yKrtziXs9NGB4TbF3w3g Re2YXET3kkqFClr8hXpwmieDSgkWAYV1dLFuFl8Q5M/nc3/gjJp+zun0X5ylogiLSs 4r413raimUj3g== 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 1C304378000E; Thu, 4 Apr 2024 14:00:29 +0000 (UTC) From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= To: Boris Brezillon , Rob Herring , Steven Price , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: kernel@collabora.com, =?UTF-8?q?Adri=C3=A1n=20Larumbe?= , Christopher Healy , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/panfrost: Show overall GPU usage stats through sysfs knob Date: Thu, 4 Apr 2024 15:00:09 +0100 Message-ID: <20240404140014.1022816-1-adrian.larumbe@collabora.com> X-Mailer: git-send-email 2.44.0 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 This changeset is heavily inspired by commit 509433d8146c ("drm/v3d: Expose the total GPU usage stats on sysfs"). The point is making broader GPU occupancy numbers available through the sysfs interface, so that for every job slot, its number of processed jobs and total processing time are displayed. Cc: Boris Brezillon Cc: Christopher Healy Signed-off-by: Adrián Larumbe --- drivers/gpu/drm/panfrost/panfrost_device.h | 5 +++ drivers/gpu/drm/panfrost/panfrost_drv.c | 49 ++++++++++++++++++++-- drivers/gpu/drm/panfrost/panfrost_job.c | 17 +++++++- drivers/gpu/drm/panfrost/panfrost_job.h | 3 ++ 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h index cffcb0ac7c11..1d343351c634 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.h +++ b/drivers/gpu/drm/panfrost/panfrost_device.h @@ -169,6 +169,11 @@ struct panfrost_engine_usage { unsigned long long cycles[NUM_JOB_SLOTS]; }; +struct panfrost_slot_usage { + u64 enabled_ns; + u64 jobs_sent; +}; + struct panfrost_file_priv { struct panfrost_device *pfdev; diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index ef9f6c0716d5..6afcde66270f 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -524,6 +525,10 @@ static const struct drm_ioctl_desc panfrost_drm_driver_ioctls[] = { PANFROST_IOCTL(MADVISE, madvise, DRM_RENDER_ALLOW), }; +static const char * const engine_names[] = { + "fragment", "vertex-tiler", "compute-only" +}; + static void panfrost_gpu_show_fdinfo(struct panfrost_device *pfdev, struct panfrost_file_priv *panfrost_priv, struct drm_printer *p) @@ -543,10 +548,6 @@ static void panfrost_gpu_show_fdinfo(struct panfrost_device *pfdev, * job spent on the GPU. */ - static const char * const engine_names[] = { - "fragment", "vertex-tiler", "compute-only" - }; - BUILD_BUG_ON(ARRAY_SIZE(engine_names) != NUM_JOB_SLOTS); for (i = 0; i < NUM_JOB_SLOTS - 1; i++) { @@ -716,8 +717,48 @@ static ssize_t profiling_store(struct device *dev, static DEVICE_ATTR_RW(profiling); +static ssize_t +gpu_stats_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct panfrost_device *pfdev = dev_get_drvdata(dev); + struct panfrost_slot_usage stats; + u64 timestamp = local_clock(); + ssize_t len = 0; + unsigned int i; + + BUILD_BUG_ON(ARRAY_SIZE(engine_names) != NUM_JOB_SLOTS); + + len += sysfs_emit(buf, "queue timestamp jobs runtime\n"); + len += sysfs_emit_at(buf, len, "-------------------------------------------------\n"); + + for (i = 0; i < NUM_JOB_SLOTS - 1; i++) { + + stats = get_slot_stats(pfdev, i); + + /* + * Each line will display the slot name, timestamp, the number + * of jobs handled by that engine and runtime, as shown below: + * + * queue timestamp jobs runtime + * ------------------------------------------------- + * fragment 12252943467507 638 1184747640 + * vertex-tiler 12252943467507 636 121663838 + * + */ + len += sysfs_emit_at(buf, len, "%-13s%-17llu%-12llu%llu\n", + engine_names[i], + timestamp, + stats.jobs_sent, + stats.enabled_ns); + } + + return len; +} +static DEVICE_ATTR_RO(gpu_stats); + static struct attribute *panfrost_attrs[] = { &dev_attr_profiling.attr, + &dev_attr_gpu_stats.attr, NULL, }; diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c index a61ef0af9a4e..4c779e6f4cb0 100644 --- a/drivers/gpu/drm/panfrost/panfrost_job.c +++ b/drivers/gpu/drm/panfrost/panfrost_job.c @@ -31,6 +31,8 @@ struct panfrost_queue_state { struct drm_gpu_scheduler sched; u64 fence_context; u64 emit_seqno; + + struct panfrost_slot_usage stats; }; struct panfrost_job_slot { @@ -160,15 +162,20 @@ panfrost_dequeue_job(struct panfrost_device *pfdev, int slot) WARN_ON(!job); if (job->is_profiled) { + u64 job_time = ktime_to_ns(ktime_sub(ktime_get(), job->start_time)); + if (job->engine_usage) { - job->engine_usage->elapsed_ns[slot] += - ktime_to_ns(ktime_sub(ktime_get(), job->start_time)); + job->engine_usage->elapsed_ns[slot] += job_time; job->engine_usage->cycles[slot] += panfrost_cycle_counter_read(pfdev) - job->start_cycles; } + panfrost_cycle_counter_put(job->pfdev); + pfdev->js->queue[slot].stats.enabled_ns += job_time; } + pfdev->js->queue[slot].stats.jobs_sent++; + pfdev->jobs[slot][0] = pfdev->jobs[slot][1]; pfdev->jobs[slot][1] = NULL; @@ -987,3 +994,9 @@ int panfrost_job_is_idle(struct panfrost_device *pfdev) return true; } + +struct panfrost_slot_usage +get_slot_stats(struct panfrost_device *pfdev, unsigned int slot) +{ + return pfdev->js->queue[slot].stats; +} diff --git a/drivers/gpu/drm/panfrost/panfrost_job.h b/drivers/gpu/drm/panfrost/panfrost_job.h index ec581b97852b..e9e2c9db0526 100644 --- a/drivers/gpu/drm/panfrost/panfrost_job.h +++ b/drivers/gpu/drm/panfrost/panfrost_job.h @@ -50,4 +50,7 @@ void panfrost_job_enable_interrupts(struct panfrost_device *pfdev); void panfrost_job_suspend_irq(struct panfrost_device *pfdev); int panfrost_job_is_idle(struct panfrost_device *pfdev); +struct panfrost_slot_usage +get_slot_stats(struct panfrost_device *pfdev, unsigned int slot); + #endif base-commit: 45c734fdd43db14444025910b4c59dd2b8be714a prerequisite-patch-id: 06ac397dd381984bfbff2a7661320c4f05470635 -- 2.44.0