From patchwork Tue Jun 21 07:20:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 12888739 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 B2EB4C433EF for ; Tue, 21 Jun 2022 07:21:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DABAE112434; Tue, 21 Jun 2022 07:21:17 +0000 (UTC) Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5D582112434; Tue, 21 Jun 2022 07:21:16 +0000 (UTC) Received: by mail-ej1-x62e.google.com with SMTP id ay16so6155013ejb.6; Tue, 21 Jun 2022 00:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0/EcOWoOuIse/hvQ+oqlKU0lIbd1LkUUo/9oXAhtRbA=; b=LbqdqeXvHaDpcKkgE/5jv+iHaxhFG8nHt/LObC0/wQM2dlGqKWQOjxpybNl5ITV3iq x1Q21GlBZTG7ZRClnkl/fwWPfdFoVI6CEVRgLoOZIWpXmF/dC9slhtFk8kouyhUVDAsM afEUozQ9hP7y5yXYOx0YTjKr9uRDE2mvy1J7CGdIqPHY0ohi53Qny8COHRDq3l0ARJdG 12/Gs94gSu6Ku1rAh3V7dWRL4xuk+UGyqh2hJqu0lAdXrQHwiWI/UOt+j4KM4w5jUg4Y DIAeoPToqPDmBke/w9hrwvmD3qn6L2zggRtq+yt646Z1mOnLwW3AZUD37Qk113pKiMsk bmIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0/EcOWoOuIse/hvQ+oqlKU0lIbd1LkUUo/9oXAhtRbA=; b=yaTFKw+6sPdXS9iTFkEw/Gka1pCDVyTz7Zo0MY4HkPwpTMTgP1V6QauZNFhXYinF5/ lQGuv8sDq34LWZrP35NaUS3v+WX3avK+0qjlvsMT6YZyTYHSVD6AYV0vK6efuI5sGn5s yaHc7w9XPEHpBINN6x62ac6wZn0rI7Vj//ESBiU9hJ5k2npVpNPvRPpzO3QXbcC8/Hz0 ydUZECDFN+D34tNgLzDKQpSS5cdjd4hXIlUxOwnR9zLqpcefIC982PlbewuPvjVTXTPN Y7AX3w9qxOoRqkSVbJpFYnqaUyOQL7D07LJepYzwpuc7MfyahXQxsz9/y2aBVJAv6iTX DUBQ== X-Gm-Message-State: AJIora9lUzwTtcBCdFeKy06EwGcDJ5MmiKibLh+t2qgqWI/J1B+uUpQH IElNA6xzNCr7+5l+wO0V7zI= X-Google-Smtp-Source: AGRyM1vmykp6H3Y7haeFNYSTgDp2SeGPwB5hGbzrZ2Avqa/HZIDol+cs2KIbjm2MU5/hGGmzXs8DNQ== X-Received: by 2002:a17:906:51d6:b0:712:c9:8a1b with SMTP id v22-20020a17090651d600b0071200c98a1bmr25086132ejk.656.1655796074886; Tue, 21 Jun 2022 00:21:14 -0700 (PDT) Received: from localhost.localdomain.info (62-178-82-229.cable.dynamic.surfer.at. [62.178.82.229]) by smtp.gmail.com with ESMTPSA id p1-20020a17090653c100b00722e771007fsm50711ejo.37.2022.06.21.00.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 00:21:14 -0700 (PDT) From: Christian Gmeiner To: linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] drm/etnaviv: add simple moving average (SMA) Date: Tue, 21 Jun 2022 09:20:47 +0200 Message-Id: <20220621072050.76229-2-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621072050.76229-1-christian.gmeiner@gmail.com> References: <20220621072050.76229-1-christian.gmeiner@gmail.com> 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: David Airlie , "moderated list:DRM DRIVERS FOR VIVANTE GPU IP" , "open list:DRM DRIVERS FOR VIVANTE GPU IP" , Russell King Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This adds a SMA algorithm inspired by Exponentially weighted moving average (EWMA) algorithm found in the kernel. Signed-off-by: Christian Gmeiner --- drivers/gpu/drm/etnaviv/etnaviv_sma.h | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 drivers/gpu/drm/etnaviv/etnaviv_sma.h diff --git a/drivers/gpu/drm/etnaviv/etnaviv_sma.h b/drivers/gpu/drm/etnaviv/etnaviv_sma.h new file mode 100644 index 000000000000..81564d5cbdc3 --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_sma.h @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020 Etnaviv Project + */ + +#ifndef __ETNAVIV_SMA_H__ +#define __ETNAVIV_SMA_H__ + +#include +#include + +/* + * Simple moving average (SMA) + * + * This implements a fixed-size SMA algorithm. + * + * The first argument to the macro is the name that will be used + * for the struct and helper functions. + * + * The second argument, the samples, expresses how many samples are + * used for the SMA algorithm. + */ + +#define DECLARE_SMA(name, _samples) \ + struct sma_##name { \ + unsigned long pos; \ + unsigned long sum; \ + unsigned long samples[_samples]; \ + }; \ + static inline void sma_##name##_init(struct sma_##name *s) \ + { \ + BUILD_BUG_ON(!__builtin_constant_p(_samples)); \ + memset(s, 0, sizeof(struct sma_##name)); \ + } \ + static inline unsigned long sma_##name##_read(struct sma_##name *s) \ + { \ + BUILD_BUG_ON(!__builtin_constant_p(_samples)); \ + return s->sum / _samples; \ + } \ + static inline void sma_##name##_add(struct sma_##name *s, unsigned long val) \ + { \ + unsigned long pos = READ_ONCE(s->pos); \ + unsigned long sum = READ_ONCE(s->sum); \ + unsigned long sample = READ_ONCE(s->samples[pos]); \ + \ + BUILD_BUG_ON(!__builtin_constant_p(_samples)); \ + \ + WRITE_ONCE(s->sum, sum - sample + val); \ + WRITE_ONCE(s->samples[pos], val); \ + WRITE_ONCE(s->pos, pos + 1 == _samples ? 0 : pos + 1); \ + } + +#endif /* __ETNAVIV_SMA_H__ */ From patchwork Tue Jun 21 07:20:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 12888741 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 092D8C433EF for ; Tue, 21 Jun 2022 07:21:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C23E21126DD; Tue, 21 Jun 2022 07:21:24 +0000 (UTC) Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by gabe.freedesktop.org (Postfix) with ESMTPS id 059ED1126A2; Tue, 21 Jun 2022 07:21:23 +0000 (UTC) Received: by mail-ej1-x636.google.com with SMTP id kq6so25475912ejb.11; Tue, 21 Jun 2022 00:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M7igW8eszoZT6WZ3jDv76+6QMOtlL+86zPzbbKCOfSA=; b=eCQeZXQB7xHXjg5HtLoVc2TBHIMAHPj9t7+hAnRAUCOSZy4FapwHBeTK+seVoxtqJJ 6rQCKTF7n8sOSOPNBoEGJHgc2aJ+9EA3RVcEaK2772ILxOAXVcyIRraQ8zkW9EWmKjDZ ass9XC8I659suvHKM+CGqadKqHljxn3TK4m6VMMOeYr3mUI/Ski0gWDlvSyuZQo+MwEx 7wsF7oWJRcnn3srgcQGIYSPH+jOstEl/RLIvzrr8AlYA3SViC21qMIR83sJmHQEDf9Fb bvxfFZAR64p7yuW2pPJtgVU7dQUOGU+pKb5aEc9JeIFR3Skd0i2Px8D82jm8TSEgff14 YhYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M7igW8eszoZT6WZ3jDv76+6QMOtlL+86zPzbbKCOfSA=; b=lKBIZVbKh+WGqoZfDHT4hxP9meb1Tyy26h+urSumM2UPQbeNRaSe7Wtbj9WImt6JUZ 2wRGs6aMgAN8u1F1lbjdc6atF0CsL1VvXqdEGJwdwe7zhSj3kneBZ/oMyhll9hkl93tn 1ye+ZlUTxnaR7NZ6O4hg6tqwtjQP6de4wZH7Fd8brU9ZcLtpYMbsCMU/w1kZ9tM2ku3h rFG3oYZeSEw9oUMEGtQ8Tsy2dnCgHtm2fZD+0IK5C4GXfzwNu6gk7HwL4+11keRpdsL3 e0IGduDgeKowKwCMXh+owhx2cspc/kjniFgY5rP3gI4azXn2va7hGMO9q+YOklsr9kaz Uicg== X-Gm-Message-State: AJIora+zbW9ntu2PduwieacjbsN9iuVI2VhG+o4n6Qs2ja1C0Z3ZAHfu VD4roorcfn1TvQ9eRaCdIsI= X-Google-Smtp-Source: AGRyM1v1tW2mODL88pIyRoU3mVOnBn6xxAxaFrLbYGlVQ9TPCoJgVAwG+uQU40Icvlmuf14MrGxgFA== X-Received: by 2002:a17:906:5187:b0:712:477:df9b with SMTP id y7-20020a170906518700b007120477df9bmr24526440ejk.424.1655796076836; Tue, 21 Jun 2022 00:21:16 -0700 (PDT) Received: from localhost.localdomain.info (62-178-82-229.cable.dynamic.surfer.at. [62.178.82.229]) by smtp.gmail.com with ESMTPSA id p1-20020a17090653c100b00722e771007fsm50711ejo.37.2022.06.21.00.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 00:21:15 -0700 (PDT) From: Christian Gmeiner To: linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] drm/etnaviv: add loadavg accounting Date: Tue, 21 Jun 2022 09:20:48 +0200 Message-Id: <20220621072050.76229-3-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621072050.76229-1-christian.gmeiner@gmail.com> References: <20220621072050.76229-1-christian.gmeiner@gmail.com> 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: David Airlie , "moderated list:DRM DRIVERS FOR VIVANTE GPU IP" , "open list:DRM DRIVERS FOR VIVANTE GPU IP" , Russell King Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The GPU has an idle state register where each bit represents the idle state of a sub-GPU component like FE or TX. Sample this register every 10ms and calculate a simple moving average over the sub-GPU component idle states with a total observation time frame of 1s. This provides us with a percentage based load of each sub-GPU component. Signed-off-by: Christian Gmeiner --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 14 ++++++ drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 64 ++++++++++++++++++++++++++- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 37 ++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 1d2b4fb4bcf8..d5c6115e56bd 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -46,6 +46,19 @@ static void load_gpu(struct drm_device *dev) } } +static void unload_gpu(struct drm_device *dev) +{ + struct etnaviv_drm_private *priv = dev->dev_private; + unsigned int i; + + for (i = 0; i < ETNA_MAX_PIPES; i++) { + struct etnaviv_gpu *g = priv->gpu[i]; + + if (g) + etnaviv_gpu_shutdown(g); + } +} + static int etnaviv_open(struct drm_device *dev, struct drm_file *file) { struct etnaviv_drm_private *priv = dev->dev_private; @@ -557,6 +570,7 @@ static void etnaviv_unbind(struct device *dev) struct drm_device *drm = dev_get_drvdata(dev); struct etnaviv_drm_private *priv = drm->dev_private; + unload_gpu(drm); drm_dev_unregister(drm); component_unbind_all(dev, drm); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 37018bc55810..202002ae75ee 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -27,6 +27,8 @@ #include "state_hi.xml.h" #include "cmdstream.xml.h" +static const ktime_t loadavg_polling_frequency = 10 * NSEC_PER_MSEC; + static const struct platform_device_id gpu_ids[] = { { .name = "etnaviv-gpu,2d" }, { }, @@ -745,6 +747,32 @@ static void etnaviv_gpu_hw_init(struct etnaviv_gpu *gpu) gpu_write(gpu, VIVS_HI_INTR_ENBL, ~0U); } +static enum hrtimer_restart etnaviv_loadavg_function(struct hrtimer *t) +{ + struct etnaviv_gpu *gpu = container_of(t, struct etnaviv_gpu, loadavg_timer); + const u32 idle = gpu_read(gpu, VIVS_HI_IDLE_STATE); + int i; + + gpu->loadavg_last_sample_time = ktime_get(); + + for (i = 0; i < ARRAY_SIZE(etna_idle_module_names); i++) + if ((idle & etna_idle_module_names[i].bit)) + sma_loadavg_add(&gpu->loadavg_value[i], 0); + else + sma_loadavg_add(&gpu->loadavg_value[i], 100); + + spin_lock(&gpu->loadavg_spinlock); + + for (i = 0; i < ARRAY_SIZE(etna_idle_module_names); i++) + gpu->loadavg_percentage[i] = sma_loadavg_read(&gpu->loadavg_value[i]); + + spin_unlock(&gpu->loadavg_spinlock); + + hrtimer_forward_now(t, loadavg_polling_frequency); + + return HRTIMER_RESTART; +} + int etnaviv_gpu_init(struct etnaviv_gpu *gpu) { struct etnaviv_drm_private *priv = gpu->drm->dev_private; @@ -839,6 +867,11 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu) for (i = 0; i < ARRAY_SIZE(gpu->event); i++) complete(&gpu->event_free); + /* Setup loadavg timer */ + hrtimer_init(&gpu->loadavg_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_SOFT); + gpu->loadavg_timer.function = etnaviv_loadavg_function; + hrtimer_start(&gpu->loadavg_timer, loadavg_polling_frequency, HRTIMER_MODE_ABS_SOFT); + /* Now program the hardware */ mutex_lock(&gpu->lock); etnaviv_gpu_hw_init(gpu); @@ -859,6 +892,11 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu) return ret; } +void etnaviv_gpu_shutdown(struct etnaviv_gpu *gpu) +{ + hrtimer_cancel(&gpu->loadavg_timer); +} + #ifdef CONFIG_DEBUG_FS struct dma_debug { u32 address[2]; @@ -1585,6 +1623,8 @@ int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms) static int etnaviv_gpu_hw_suspend(struct etnaviv_gpu *gpu) { if (gpu->initialized && gpu->fe_running) { + hrtimer_cancel(&gpu->loadavg_timer); + /* Replace the last WAIT with END */ mutex_lock(&gpu->lock); etnaviv_buffer_end(gpu); @@ -1608,7 +1648,8 @@ static int etnaviv_gpu_hw_suspend(struct etnaviv_gpu *gpu) #ifdef CONFIG_PM static int etnaviv_gpu_hw_resume(struct etnaviv_gpu *gpu) { - int ret; + s64 missing_samples; + int ret, i, j; ret = mutex_lock_killable(&gpu->lock); if (ret) @@ -1617,7 +1658,27 @@ static int etnaviv_gpu_hw_resume(struct etnaviv_gpu *gpu) etnaviv_gpu_update_clock(gpu); etnaviv_gpu_hw_init(gpu); + /* Update loadavg based on delta of suspend and resume ktime. + * + * Our SMA algorithm uses a fixed size of 100 items to be able + * to calculate the mean over one second as we sample every 10ms. + */ + missing_samples = div_s64(ktime_ms_delta(ktime_get(), gpu->loadavg_last_sample_time), 10); + missing_samples = min(missing_samples, (s64)100); + + spin_lock_bh(&gpu->loadavg_spinlock); + + for (i = 0; i < ARRAY_SIZE(etna_idle_module_names); i++) { + struct sma_loadavg *loadavg = &gpu->loadavg_value[i]; + + for (j = 0; j < missing_samples; j++) + sma_loadavg_add(loadavg, 0); + } + + spin_unlock_bh(&gpu->loadavg_spinlock); + mutex_unlock(&gpu->lock); + hrtimer_start(&gpu->loadavg_timer, loadavg_polling_frequency, HRTIMER_MODE_ABS_SOFT); return 0; } @@ -1787,6 +1848,7 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) gpu->dev = &pdev->dev; mutex_init(&gpu->lock); mutex_init(&gpu->fence_lock); + spin_lock_init(&gpu->loadavg_spinlock); /* Map registers: */ gpu->mmio = devm_platform_ioremap_resource(pdev, 0); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h index 85eddd492774..881f071f640e 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -10,6 +10,8 @@ #include "etnaviv_gem.h" #include "etnaviv_mmu.h" #include "etnaviv_drv.h" +#include "etnaviv_sma.h" +#include "state_hi.xml.h" struct etnaviv_gem_submit; struct etnaviv_vram_mapping; @@ -91,6 +93,33 @@ struct clk; #define ETNA_NR_EVENTS 30 +DECLARE_SMA(loadavg, 100) + +static const struct { + const char *name; + u32 bit; +} etna_idle_module_names[] = { + { "FE", VIVS_HI_IDLE_STATE_FE }, + { "DE", VIVS_HI_IDLE_STATE_DE }, + { "PE", VIVS_HI_IDLE_STATE_PE }, + { "SH", VIVS_HI_IDLE_STATE_SH }, + { "PA", VIVS_HI_IDLE_STATE_PA }, + { "SE", VIVS_HI_IDLE_STATE_SE }, + { "RA", VIVS_HI_IDLE_STATE_RA }, + { "TX", VIVS_HI_IDLE_STATE_TX }, + { "VG", VIVS_HI_IDLE_STATE_VG }, + { "IM", VIVS_HI_IDLE_STATE_IM }, + { "FP", VIVS_HI_IDLE_STATE_FP }, + { "TS", VIVS_HI_IDLE_STATE_TS }, + { "BL", VIVS_HI_IDLE_STATE_BL }, + { "ASYNCFE", VIVS_HI_IDLE_STATE_ASYNCFE }, + { "MC", VIVS_HI_IDLE_STATE_MC }, + { "PPA", VIVS_HI_IDLE_STATE_PPA }, + { "WD", VIVS_HI_IDLE_STATE_WD }, + { "NN", VIVS_HI_IDLE_STATE_NN }, + { "TP", VIVS_HI_IDLE_STATE_TP }, +}; + struct etnaviv_gpu { struct drm_device *drm; struct thermal_cooling_device *cooling; @@ -147,6 +176,13 @@ struct etnaviv_gpu { unsigned int freq_scale; unsigned long base_rate_core; unsigned long base_rate_shader; + + /* Loadavg: */ + struct hrtimer loadavg_timer; + spinlock_t loadavg_spinlock; + ktime_t loadavg_last_sample_time; + struct sma_loadavg loadavg_value[ARRAY_SIZE(etna_idle_module_names)]; + unsigned int loadavg_percentage[ARRAY_SIZE(etna_idle_module_names)]; }; static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data) @@ -162,6 +198,7 @@ static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg) int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value); int etnaviv_gpu_init(struct etnaviv_gpu *gpu); +void etnaviv_gpu_shutdown(struct etnaviv_gpu *gpu); bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu); #ifdef CONFIG_DEBUG_FS From patchwork Tue Jun 21 07:20:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 12888740 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 45415C433EF for ; Tue, 21 Jun 2022 07:21:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7CF1A11265F; Tue, 21 Jun 2022 07:21:22 +0000 (UTC) Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2A4FF11252F; Tue, 21 Jun 2022 07:21:21 +0000 (UTC) Received: by mail-ej1-x633.google.com with SMTP id n20so18751779ejz.10; Tue, 21 Jun 2022 00:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ujXg7tbiFKFG9Xv1lpmXMbIqHNMRftScv0fuP2to1p4=; b=mR7SSvzxKBsVGWmW7rKMKm11PMO2JzWQjOvgSCKOXzUg76jvtygFg5Ko/iBLe/V5YM qEnz0PtDiVTbLZx2GOQDDGhJuxgco2xipCkiF1Snhg/1/sGCA9d8964K1JqVJG1d5gyi XBubX7jmbgcsPTuJ+Ll442ofRMaJoAwFI5nyCTm1Cw+XnTgZms5IVuJA/brnu1jG5XyA XvKRmT9CSL/9+Xziz1C5p63hIIuZSayprT+g1+uLzd+TJrhW30vVobsB1qZJnYf6XFIN c9E2RkMqxJwoROp9op4RIbSwNQfOZ47tSX74h3knzx2GIQNdn24NvgRGIFzWqP2oAjE9 fXYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ujXg7tbiFKFG9Xv1lpmXMbIqHNMRftScv0fuP2to1p4=; b=fbD7pWMo8zb6pFLKnNsGkVQuzHr9SREoMQhPXkckh6oOvgnx0iIw3FDh8rjP1Fb+9a +gWHUh85EZeMc4PSj+yTq0bNFt98nHlXDNyEHbJY06yLU/FF2Sk+Fqc7yPEW/dQI1uCG KEzQyqpWZKatg1Z8W8S5VBOP5JbIIn0Sj+J8c8Fu2iypluLz9qmwMC2au6jucSkJndM/ ZoNWyEWulRJou6sVenhYAQiz6DC75XsntV9XTrHhrUcqATKcD8QdSK0bfqWYMqUCVQzh fMrREhNkS7tP2u2RvEv+DNupQP9cUStQHGSzEI1J761LyqJ8et2DwxsXfN3Dp8GknCY7 x9Sg== X-Gm-Message-State: AJIora94WzzmBtWFEnLI5ghcQW7ucySdbE9OEGbeRD3EnJs5j2DX3pHt HQWHO6rb9fTCJzIn+JwRxYw= X-Google-Smtp-Source: AGRyM1vCyhurjoTwHqtO0qcT9zB5pBmZ/2iCYJki53eJ3YCFskGqaVpFKRg+a2h4X0orIH6PALuMag== X-Received: by 2002:a17:907:7daa:b0:720:b3e1:12b7 with SMTP id oz42-20020a1709077daa00b00720b3e112b7mr14304301ejc.11.1655796079661; Tue, 21 Jun 2022 00:21:19 -0700 (PDT) Received: from localhost.localdomain.info (62-178-82-229.cable.dynamic.surfer.at. [62.178.82.229]) by smtp.gmail.com with ESMTPSA id p1-20020a17090653c100b00722e771007fsm50711ejo.37.2022.06.21.00.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 00:21:19 -0700 (PDT) From: Christian Gmeiner To: linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] drm/etnaviv: show loadavg in debugfs Date: Tue, 21 Jun 2022 09:20:49 +0200 Message-Id: <20220621072050.76229-4-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621072050.76229-1-christian.gmeiner@gmail.com> References: <20220621072050.76229-1-christian.gmeiner@gmail.com> 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: David Airlie , "moderated list:DRM DRIVERS FOR VIVANTE GPU IP" , "open list:DRM DRIVERS FOR VIVANTE GPU IP" , Russell King Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Might be helpful to see the loadavg in debugfs. Signed-off-by: Christian Gmeiner --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 202002ae75ee..113faff9b02e 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -926,7 +926,7 @@ int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m) { struct dma_debug debug; u32 dma_lo, dma_hi, axi, idle; - int ret; + int ret, i; seq_printf(m, "%s Status:\n", dev_name(gpu->dev)); @@ -1044,6 +1044,16 @@ int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m) if (idle & VIVS_HI_IDLE_STATE_AXI_LP) seq_puts(m, "\t AXI low power mode\n"); + seq_printf(m, "\tload:\n"); + spin_lock_bh(&gpu->loadavg_spinlock); + + for (i = 0; i < ARRAY_SIZE(etna_idle_module_names); i++) + seq_printf(m, "\t %s: %u%%\n", + etna_idle_module_names[i].name, + gpu->loadavg_percentage[i]); + + spin_unlock_bh(&gpu->loadavg_spinlock); + if (gpu->identity.features & chipFeatures_DEBUG_MODE) { u32 read0 = gpu_read(gpu, VIVS_MC_DEBUG_READ0); u32 read1 = gpu_read(gpu, VIVS_MC_DEBUG_READ1); From patchwork Tue Jun 21 07:20:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 12888742 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 8E11EC43334 for ; Tue, 21 Jun 2022 07:21:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A7A631126C7; Tue, 21 Jun 2022 07:21:25 +0000 (UTC) Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by gabe.freedesktop.org (Postfix) with ESMTPS id EF06611267D; Tue, 21 Jun 2022 07:21:23 +0000 (UTC) Received: by mail-ed1-x52c.google.com with SMTP id e2so7163475edv.3; Tue, 21 Jun 2022 00:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C/NKEAt2Er4quLZ5gjnADzbiK7ybSix+76D1rb8z9Fw=; b=Aosb52+hrSp+NPKOBpkKo+HEpLAjK6Cy41ZXxhSPtBSqnk3xiW5XK+YkC1wTawZ3PX Rg0witFuSx8IGBu5tFPCDFIbRKZWIN6OEc60DpQLjXdIOtPdpZ+9tk1hsR8vmpK9Oqb+ qzYFblMRhzKHKrgWXx48VO1dgBn7weLem/f+BIetEfiZNBlOfeKAbR560Dw+l8usmNFx zDqNU63Wd7veZo9Y0bODMqID/93UPNX7JmMvzuusJvJT5h7SZlV4kAxZ6RChrclrzwUB cRk+nJnExHGPX9Ll71IH+4hfgMpqXQ5u5CiTTdepjp1vYvEtV5bR4SfiVgE6u5YpPPdY hZgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C/NKEAt2Er4quLZ5gjnADzbiK7ybSix+76D1rb8z9Fw=; b=ZONKtzDr01Lcmh9H0DxvZsqIn7XV9GkrCn1qIxmUig4TUY82NZP+NOai+6/siUYzPl inIJiv/oYOby+Ed7LY7+zRReEa/k1gOu1mmsJvfA0gWrOmIuf4vwXr7mWAxnwxp/RGov bDbkZlFAJK+VjaVCoOP004JWYT40gC0tmMGN4wk24oowEqsMSJDuR80kqqdaStyotMAR GSE8THhV27MeAmYj6CkELvztcMudpPblE80XD1yK1KEefwCfvbBFgDr6wmnyHUdXquFc kuvZuYqKWIxk3rM6MVvMH8Gvw3coveSRww1Z6qb5R3MGU/CRzxvfsXm+X1BWg7uq45Ji +qXw== X-Gm-Message-State: AJIora8cR0+QlxbgOyy0tm41MAlNP/dzzhWTz2sKo7VkmIdPjbTU6N5J 82mAIrpFcncG7rFpuyAGRtk= X-Google-Smtp-Source: AGRyM1v2Ep/cdmiqnkH6Ncpgbtcv2HEnrlZXGr9tHs+YsIyubDQfduplz2GQ4Wt6a/8Lw+p3B4StFw== X-Received: by 2002:aa7:d294:0:b0:435:5d12:867f with SMTP id w20-20020aa7d294000000b004355d12867fmr25960856edq.147.1655796082489; Tue, 21 Jun 2022 00:21:22 -0700 (PDT) Received: from localhost.localdomain.info (62-178-82-229.cable.dynamic.surfer.at. [62.178.82.229]) by smtp.gmail.com with ESMTPSA id p1-20020a17090653c100b00722e771007fsm50711ejo.37.2022.06.21.00.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 00:21:22 -0700 (PDT) From: Christian Gmeiner To: linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] drm/etnaviv: export loadavg via perfmon Date: Tue, 21 Jun 2022 09:20:50 +0200 Message-Id: <20220621072050.76229-5-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220621072050.76229-1-christian.gmeiner@gmail.com> References: <20220621072050.76229-1-christian.gmeiner@gmail.com> 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: David Airlie , "moderated list:DRM DRIVERS FOR VIVANTE GPU IP" , "open list:DRM DRIVERS FOR VIVANTE GPU IP" , Russell King Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Make it possible to access the sub-GPU component load value from user space with the perfmon infrastructure. Signed-off-by: Christian Gmeiner --- drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 79 +++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c index bafdfe49c1d8..d65d9af3a74a 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c @@ -120,6 +120,19 @@ static u32 hi_total_idle_cycle_read(struct etnaviv_gpu *gpu, return gpu_read(gpu, reg); } +static u32 load_read(struct etnaviv_gpu *gpu, + const struct etnaviv_pm_domain *domain, + const struct etnaviv_pm_signal *signal) +{ + u32 load; + + spin_lock_bh(&gpu->loadavg_spinlock); + load = gpu->loadavg_percentage[signal->data]; + spin_unlock_bh(&gpu->loadavg_spinlock); + + return load; +} + static const struct etnaviv_pm_domain doms_3d[] = { { .name = "HI", @@ -419,6 +432,72 @@ static const struct etnaviv_pm_domain doms_3d[] = { &perf_reg_read } } + }, + { + .name = "LOAD", + .nr_signals = 12, + .signal = (const struct etnaviv_pm_signal[]) { + { + "FE", + 0, + &load_read + }, + { + "DE", + 1, + &load_read + }, + { + "PE", + 2, + &load_read + }, + { + "SH", + 3, + &load_read + }, + { + "PA", + 4, + &load_read + }, + { + "SE", + 5, + &load_read + }, + { + "RA", + 6, + &load_read + }, + { + "TX", + 7, + &load_read + }, + { + "VG", + 8, + &load_read + }, + { + "IM", + 9, + &load_read + }, + { + "FP", + 10, + &load_read + }, + { + "TS", + 11, + &load_read + } + } } };