Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp229352rdb; Thu, 8 Feb 2024 04:32:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUdBfN2dszfD/lhtvXqwQ1BpGewLtc//3KMoJJvhdZhG8ZPKn22/vaxLBWOBySG7550oBg0qkkeJhp64/JZrd3+wpZJb6VAH4cKpCc8eQ== X-Google-Smtp-Source: AGHT+IF60fa/m3UKZsk+pybnrqEOtcOGcLiXjg+j49o8Lr6H1OM16sIhQYyIi9YhxzqGdjUPrxqn X-Received: by 2002:a05:6a20:d80a:b0:19e:987b:1171 with SMTP id iv10-20020a056a20d80a00b0019e987b1171mr7766607pzb.16.1707395524138; Thu, 08 Feb 2024 04:32:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707395524; cv=pass; d=google.com; s=arc-20160816; b=bN39eDWZmW5A5d0eN5XgizflRwa17vem0HemmM5L2ZYi0hsuzLiB3mVGZx+h+NYbQY BHVwmXRnJzfaWicoJlLgg5Ks09UJtxPUVYXW88qAy+SIQhTOxxpbblOIEtUScecFM2UT VOUJ92Ed42MXeCLFf6xWzkm9AcV1ey/Kitam8+Zx1v1QppzbDdysclf9effq3/kukhuV qNuYURT1EFzOb/7H8rib4LQKjcB8PU1u2vN+/UexYI3EujL/PX0ptgYRPkMVJxJraXs5 GwV1uFkiZOmQQZB6sXj7bw0QD79AtDLlbNhK/xACEofxvuhoNmaJCwQDnSz5bxmbI2cC /m1Q== 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; bh=vMCAbN6FWrAVVTpWWUeQRCqOvp55YwzptftZbKiA1Ck=; fh=kZSc11bcPI+MALD7Z7xFl3mbRXZb4pzPQhdplzPglxQ=; b=TVZAZ3yZo4rowbImwhEI7i7Onzwvv1KkKbydPJuFQoxn/2yS9JApNy9pL+HWsKfXyh yOzwC3No6ixM5gaYj7zCDdRCF/RpMy+MQMNkkHAvWHAavTJ1NLvOgXGiDpNSfE8WgL3S BMUlfEb3i8pw8RKTNYgrVdztcRXeouaYBJojjz3ud911PfzyjSOPp9GT8pB6dZJ6p6Kr vZrSxdayrOytRUppFZJUvCily7XhzaD++LLhwS68ItI6aw+f6WXj2SR7bIYR+tGtwB6B NESNeqf93s3J1nTQ6l6X8L4DFozuo7YmV8YQFIxDmDnV1sG2I53/EjjGJg1qEvQ5iS9z rG7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58014-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58014-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUulV0zJDl4E4Y48Qf+6I/VB93h4HH5UlEh64DeujYIFsBysiPfZd/JIF3ZebBX9pfupBNCA96JgPxMneDnDnVkjMIxfpwDvBO4zlgDnQ== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y191-20020a638ac8000000b005dc1b73dd16si3705359pgd.372.2024.02.08.04.32.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:32:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58014-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58014-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58014-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B1BBBB22782 for ; Thu, 8 Feb 2024 12:02:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52DD37EF1C; Thu, 8 Feb 2024 11:57:08 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE4047EF01; Thu, 8 Feb 2024 11:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393427; cv=none; b=TTDZW8PF7g11GqM9Ykj5u54QSBqcA/8fXFgQHoeE6eH56xG6LxXrFMLh31YQDX/146qUQBCiWLQ4GZAS6GOWOHY6tFsXM5/difGyfxh2riksJYP1CxHIxqvyzZE/Qlr2pL1Z5w+ZcFgWHADuDTraD7sNKRMCducEwRrz1NchOWU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393427; c=relaxed/simple; bh=jF9xvV+ffyDXEcEQmXtChRdRJUYNKBG4fWdMvZO8qKc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YKM4RXpawkxUU+qbfbrJnQfClnXoG0MO36xgrwmYzWvvpsve4lmO4xR6A0ilxoQQIrqnVL3Liu8yqcosCPCwCflYHw1MLmsQUPShRSkWjEXOmlanyW8EHzvJ/ag+fBvRu1TJKmtYb6pQGm6FvSdVU4OJg1O9Cand+gSN45oiWxU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A88E3DA7; Thu, 8 Feb 2024 03:57:47 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C8A8B3F5A1; Thu, 8 Feb 2024 03:57:02 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 20/23] PM: EM: Change debugfs configuration to use runtime EM table data Date: Thu, 8 Feb 2024 11:55:54 +0000 Message-Id: <20240208115557.1273962-21-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Dump the runtime EM table values which can be modified in time. In order to do that allocate chunk of debug memory which can be later freed automatically thanks to devm_kcalloc(). This design can handle the fact that the EM table memory can change after EM update, so debug code cannot use the pointer from initialization phase. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 67 ++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index a631d7d52c40..548908e686ed 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -37,20 +37,65 @@ static bool _is_cpu_device(struct device *dev) #ifdef CONFIG_DEBUG_FS static struct dentry *rootdir; -static void em_debug_create_ps(struct em_perf_state *ps, struct dentry *pd) +struct em_dbg_info { + struct em_perf_domain *pd; + int ps_id; +}; + +#define DEFINE_EM_DBG_SHOW(name, fname) \ +static int em_debug_##fname##_show(struct seq_file *s, void *unused) \ +{ \ + struct em_dbg_info *em_dbg = s->private; \ + struct em_perf_state *table; \ + unsigned long val; \ + \ + rcu_read_lock(); \ + table = em_perf_state_from_pd(em_dbg->pd); \ + val = table[em_dbg->ps_id].name; \ + rcu_read_unlock(); \ + \ + seq_printf(s, "%lu\n", val); \ + return 0; \ +} \ +DEFINE_SHOW_ATTRIBUTE(em_debug_##fname) + +DEFINE_EM_DBG_SHOW(frequency, frequency); +DEFINE_EM_DBG_SHOW(power, power); +DEFINE_EM_DBG_SHOW(cost, cost); +DEFINE_EM_DBG_SHOW(performance, performance); +DEFINE_EM_DBG_SHOW(flags, inefficiency); + +static void em_debug_create_ps(struct em_perf_domain *em_pd, + struct em_dbg_info *em_dbg, int i, + struct dentry *pd) { + struct em_perf_state *table; + unsigned long freq; struct dentry *d; char name[24]; - snprintf(name, sizeof(name), "ps:%lu", ps->frequency); + em_dbg[i].pd = em_pd; + em_dbg[i].ps_id = i; + + rcu_read_lock(); + table = em_perf_state_from_pd(em_pd); + freq = table[i].frequency; + rcu_read_unlock(); + + snprintf(name, sizeof(name), "ps:%lu", freq); /* Create per-ps directory */ d = debugfs_create_dir(name, pd); - debugfs_create_ulong("frequency", 0444, d, &ps->frequency); - debugfs_create_ulong("power", 0444, d, &ps->power); - debugfs_create_ulong("cost", 0444, d, &ps->cost); - debugfs_create_ulong("performance", 0444, d, &ps->performance); - debugfs_create_ulong("inefficient", 0444, d, &ps->flags); + debugfs_create_file("frequency", 0444, d, &em_dbg[i], + &em_debug_frequency_fops); + debugfs_create_file("power", 0444, d, &em_dbg[i], + &em_debug_power_fops); + debugfs_create_file("cost", 0444, d, &em_dbg[i], + &em_debug_cost_fops); + debugfs_create_file("performance", 0444, d, &em_dbg[i], + &em_debug_performance_fops); + debugfs_create_file("inefficient", 0444, d, &em_dbg[i], + &em_debug_inefficiency_fops); } static int em_debug_cpus_show(struct seq_file *s, void *unused) @@ -73,6 +118,7 @@ DEFINE_SHOW_ATTRIBUTE(em_debug_flags); static void em_debug_create_pd(struct device *dev) { + struct em_dbg_info *em_dbg; struct dentry *d; int i; @@ -86,9 +132,14 @@ static void em_debug_create_pd(struct device *dev) debugfs_create_file("flags", 0444, d, dev->em_pd, &em_debug_flags_fops); + em_dbg = devm_kcalloc(dev, dev->em_pd->nr_perf_states, + sizeof(*em_dbg), GFP_KERNEL); + if (!em_dbg) + return; + /* Create a sub-directory for each performance state */ for (i = 0; i < dev->em_pd->nr_perf_states; i++) - em_debug_create_ps(&dev->em_pd->table[i], d); + em_debug_create_ps(dev->em_pd, em_dbg, i, d); } -- 2.25.1