From patchwork Mon Feb 12 12:32:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 199728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2398370dyd; Mon, 12 Feb 2024 04:38:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXKhxtAOB/cshC6Ala7A+Mpkcs1WXztcpTUU5fn6gEBbSX0V5q8ejwwtK5ctUckXc+7XxfhuzhLNFXcXEfLcVpCXpD4ZQ== X-Google-Smtp-Source: AGHT+IFeF6UAWXTSLLZCIt1ZRzCAPblIpsUKOPEJgruExwCtWd4f19opk4APshfrPpURiaq3PF9E X-Received: by 2002:a05:6871:1cd:b0:219:2d1a:90ab with SMTP id q13-20020a05687101cd00b002192d1a90abmr6315060oad.59.1707741510015; Mon, 12 Feb 2024 04:38:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707741509; cv=pass; d=google.com; s=arc-20160816; b=h4l0ayQjkDhgZEUT/OPYcAXMi8+KGeQ2hBrLcMHeFlEQyOMxmXF7+O8nSjobunxMRs jjN+hIOUpHmupj3jYXALgaMUWqsBthKCNPatN7IPb0wdN/RlYc+DEp15YMeJjdRaikYO v5krkq8lZC+k+40rUav8p0GFh6lcuV1VPAQl5StxQrlLz8hrrFxpUCM0rObnVQLbhfym DJ71Zto8Mk6Z8qUdR3NbNUvyUh6pu5IeDlWaUH9TklKDJ97lWY3Xn/0gC+qWkRlWZC5h JNeGzHj0XXbfaFFXKT3GXwLUHKELoF7iNT80Mvc+dl4KftQU5OBp2iUBSa1HWPLpGPUz x03g== 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=7BNqAQHUbs/omZNvLE7Yml10kLoDj2gTRisUZztZnsE=; fh=ey5bSgSzYEmLAyXeFVco+2RBWBcNYGGU+CvscjrjyCE=; b=FZGjj2m8nH4M49mlGZW5JnXBCVX6vKKC1DsmcBtsp0+1qUIyv5rtFiIQpd9hcFqRUQ Pe+MOZh5UqCR3lRPAtSvxmhB+QL4MjxbdDMPpG+v6x5N23aiIL3hvJz2FioVM4EyOsh+ huZ1HMQj7kzB2Qr6dsdsqMwckQCXqvmW+piQGZPUpn6SA0hWPQ7v9RnAK3tLtAq2zLgs 0NWzWt+u9c4AcYEx+f094yRMAACSsmEnHOAfgwFT5NxEmdJ3JIK7WeS4Y54GWV0L2TSA /QGmar5EKYoA5O6viI61Sr9OYi1IofpSwPqPZ8DYdG+GiU98mCZSY1sPP9VaT6hY2dwG pL8A==; 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-61558-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61558-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWS7uWTCtf53MBsKEXZUMrRGLFugZ/9uz0xLJSirOqXxwEJLrML+/tZl98eoVqQjWgdMseLMB1eHOa6a5Nz8G4q2+vFKA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c9-20020a6566c9000000b005dc5070656csi187295pgw.785.2024.02.12.04.38.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 04:38:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61558-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-61558-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61558-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DED0C28739C for ; Mon, 12 Feb 2024 12:35:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE0703CF47; Mon, 12 Feb 2024 12:33:23 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 793EA3C680 for ; Mon, 12 Feb 2024 12:33:20 +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=1707741202; cv=none; b=uah3FQ8G9TciA6DCmSjKNi85L2ZoF81cjUrBJrKhsoFthIrkZeo1yIlGpo019mAqg7d2TFV+sZZQcB+JRsbqK75/EWE2M3fFIkL5+Bae292YCWQQyjK4qF3P/Tc+fOrf/Lz27idRzAD+IqRtNtNnHbhUyX8IGur6A7I+PZkRTrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707741202; c=relaxed/simple; bh=Vq/13jyMTK0Hthb91RLpCC6/kQOlazmQH58gWq/rq14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QbLPJ42jchclUbziFNQaNWMc+pz1IKQvO+Ln4RJR+LzttDx4ohY5dxjDOqQkbHLE/wpqIM5J+FUXbiXXQ74fpaUGIkABj2cCxbHUgHVrvOVRtfpYXx9gs3wJ5JMais2d4D7HZx2Ktgif3jdoUpOt328ccIKGZ870UKt9ewVpiog= 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 4FF1B139F; Mon, 12 Feb 2024 04:34:01 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 60AFF3F7BD; Mon, 12 Feb 2024 04:33:18 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH 11/11] firmware: arm_scmi: Report frequencies in Perf notifications Date: Mon, 12 Feb 2024 12:32:33 +0000 Message-ID: <20240212123233.1230090-12-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212123233.1230090-1-cristian.marussi@arm.com> References: <20240212123233.1230090-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790696761466655165 X-GMAIL-MSGID: 1790696761466655165 Extend the Perf notification report to include pre-calculated frequencies corresponding to the reported limits/levels event; such frequencies are properly computed based on the stored known OPPs information taking into consideration if the current operating mode is level indexed or not. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/perf.c | 69 ++++++++++++++++++++++++++++++++ include/linux/scmi_protocol.h | 3 ++ 2 files changed, 72 insertions(+) diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c index e20d137a92f6..981e327e63e3 100644 --- a/drivers/firmware/arm_scmi/perf.c +++ b/drivers/firmware/arm_scmi/perf.c @@ -1055,18 +1055,47 @@ static int scmi_perf_set_notify_enabled(const struct scmi_protocol_handle *ph, return ret; } +static int +scmi_perf_xlate_opp_to_freq(struct perf_dom_info *dom, + unsigned int index, unsigned long *freq) +{ + struct scmi_opp *opp; + + if (!dom || !freq) + return -EINVAL; + + if (!dom->level_indexing_mode) { + opp = xa_load(&dom->opps_by_lvl, index); + if (!opp) + return -ENODEV; + + *freq = opp->perf * dom->mult_factor; + } else { + opp = xa_load(&dom->opps_by_idx, index); + if (!opp) + return -ENODEV; + + *freq = opp->indicative_freq * dom->mult_factor; + } + + return 0; +} + static void *scmi_perf_fill_custom_report(const struct scmi_protocol_handle *ph, u8 evt_id, ktime_t timestamp, const void *payld, size_t payld_sz, void *report, u32 *src_id) { + int ret; void *rep = NULL; + struct perf_dom_info *dom; switch (evt_id) { case SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED: { const struct scmi_perf_limits_notify_payld *p = payld; struct scmi_perf_limits_report *r = report; + unsigned long freq_min, freq_max; if (sizeof(*p) != payld_sz) break; @@ -1076,14 +1105,36 @@ static void *scmi_perf_fill_custom_report(const struct scmi_protocol_handle *ph, r->domain_id = le32_to_cpu(p->domain_id); r->range_max = le32_to_cpu(p->range_max); r->range_min = le32_to_cpu(p->range_min); + /* Check if the reported domain exist at all */ + dom = scmi_perf_domain_lookup(ph, r->domain_id); + if (IS_ERR(dom)) + break; + /* + * Event will be reported from this point on... + * ...even if, later, xlated frequencies were not retrieved. + */ *src_id = r->domain_id; rep = r; + + ret = scmi_perf_xlate_opp_to_freq(dom, r->range_max, &freq_max); + if (ret) + break; + + ret = scmi_perf_xlate_opp_to_freq(dom, r->range_min, &freq_min); + if (ret) + break; + + /* Report translated freqs ONLY if both available */ + r->range_max_freq = freq_max; + r->range_min_freq = freq_min; + break; } case SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED: { const struct scmi_perf_level_notify_payld *p = payld; struct scmi_perf_level_report *r = report; + unsigned long freq; if (sizeof(*p) != payld_sz) break; @@ -1091,9 +1142,27 @@ static void *scmi_perf_fill_custom_report(const struct scmi_protocol_handle *ph, r->timestamp = timestamp; r->agent_id = le32_to_cpu(p->agent_id); r->domain_id = le32_to_cpu(p->domain_id); + /* Report translated freqs ONLY if available */ r->performance_level = le32_to_cpu(p->performance_level); + /* Check if the reported domain exist at all */ + dom = scmi_perf_domain_lookup(ph, r->domain_id); + if (IS_ERR(dom)) + break; + /* + * Event will be reported from this point on... + * ...even if, later, xlated frequencies were not retrieved. + */ *src_id = r->domain_id; rep = r; + + /* Report translated freqs ONLY if available */ + ret = scmi_perf_xlate_opp_to_freq(dom, r->performance_level, + &freq); + if (ret) + break; + + r->performance_level_freq = freq; + break; } default: diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 0cc40af5519a..9b9351e07a11 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -956,6 +956,8 @@ struct scmi_perf_limits_report { unsigned int domain_id; unsigned int range_max; unsigned int range_min; + unsigned long range_max_freq; + unsigned long range_min_freq; }; struct scmi_perf_level_report { @@ -963,6 +965,7 @@ struct scmi_perf_level_report { unsigned int agent_id; unsigned int domain_id; unsigned int performance_level; + unsigned long performance_level_freq; }; struct scmi_sensor_trip_point_report {