From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 8E86E17A2E8 for ; Tue, 30 Jun 2026 13:50:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782827447; cv=none; b=sfAIbk+b2Hf7BXgvK229xTPw6RQWRntyXkCeVBpRxiQReLa3ho49ZEvatPvtWd7iUB7VwEENWMLzCiQjnfhM1bLnIk+0N/c96MgsPQWHpCngQXCdTM/6idgJtvU1HUc6y+02QMCYHuGH/PLb/jP/fy3ZYQpB3J5MrfHWRxZbO3o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782827447; c=relaxed/simple; bh=jfQn8+1DlhJmtzxCnpMHEEI0ZHJqZR6gVKkh5dSU/Yc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Zjdkrp33B9giTWjTDMoXbOyctXLzz+BmGLx9iQAlxgtuKDjhKpb8J+dOWZA4mdSt2dNJXkdit2Btdf5P44L5OI9blF5XvenVam1UJqlvSqbjQ36V3BVZjS5uIlvGQC5D/7KDUzTTJxCmmJQG/OAkVUcFIWjk4Rj/GtSdmoOu4lM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=UdExCywZ; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="UdExCywZ" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65U9nE7w1581685; Tue, 30 Jun 2026 13:50:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=V40Qtn ZDhQBQa28QwJzOPXjsbSwis5CZKSxFgN4nazg=; b=UdExCywZpYWCKvrSa4taD4 /GtvZJ98jlFcBmkyiBuuoQc3BkVibNZH//T3jYCcnUXajUabAc6CCU9wx+QQEhRN 4zTvycoMPT0/al04Zhq6tv77ymJ4i/Rx17jailtS0tgkoOZTVhSVGXWQWBrIEF4s qATC91RNkNMCqQgGzaDHJVn9+UjZ54FhFFBhY7zeW6VFzGGoXeGwxlUrcsAZVab1 NJKwHsW4V3EiNM+Niistg9b+it2a00eMYuzRKxrBjRcjc9c9pcINvMrZATWvyOE+ fPZn1vssaYAKVqU/iiZww3y0CzOEG4oF/2EQTuUXPruQx17GD392RebnKj8Jr5Xg == Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4f26q9xue0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Jun 2026 13:50:28 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 65UDnvbE032252; Tue, 30 Jun 2026 13:50:27 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4f2tbhaeat-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Jun 2026 13:50:27 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 65UDoN3E15794468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Jun 2026 13:50:23 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 69D5B2004B; Tue, 30 Jun 2026 13:50:23 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4221420040; Tue, 30 Jun 2026 13:50:21 +0000 (GMT) Received: from [9.123.14.142] (unknown [9.123.14.142]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 30 Jun 2026 13:50:20 +0000 (GMT) Message-ID: Date: Tue, 30 Jun 2026 19:20:19 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] powerpc/powernv: Cache OPAL check_token() results To: Shivang Upadhyay Cc: adityag@linux.ibm.com, chleroy@kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, maddy@linux.ibm.com, mahesh@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, thuth@redhat.com References: <20260626123534.396456-1-shivangu@linux.ibm.com> Content-Language: en-US From: Sourabh Jain In-Reply-To: <20260626123534.396456-1-shivangu@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1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:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-30_03,2026-06-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 phishscore=0 clxscore=1015 bulkscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606300129 On 26/06/26 18:05, Shivang Upadhyay wrote: > `opal_check_token()` function is used to determine if a specific > OPAL firmware call is supported on the current platform. This check > is performed frequently during boot and runtime, resulting in > unnecessary firmware calls for the same token values. > > Add a caching layer for the opal_check_token() OPAL call to avoid > repeated firmware calls for token availability checks. This reduces > firmware call overhead during boot. > > Testing with buildroot images shows OPAL calls reduced from > 35578 to 28983, before console bring-up. My testing shows similar statistics. As per my testing, the upstream kernel (without this patch) at commit 840ef6c78e6a2f694b578, compiled with powernv_defconfig, shows ~7K CHECK_TOKEN OPAL calls to boot the kernel and reach the console. With this patch included, there are only 8 CHECK_TOKEN opal calls. There is a significant reduction in CHECK_TOKEN OPAL calls with this patch. Thanks for working on this improvement. The changes look good to me. Feel free to add: Reviewed-by: Sourabh Jain > > Signed-off-by: Shivang Upadhyay > --- > Changelog: > * v1: https://lore.kernel.org/all/20260601112520.161605-1-shivangu@linux.ibm.com/ > - implemented tri-state check as suggestd by Sourabh. > - made the implementation more clear. > > --- > arch/powerpc/include/asm/opal.h | 1 + > arch/powerpc/platforms/powernv/opal-call.c | 2 +- > arch/powerpc/platforms/powernv/opal.c | 30 ++++++++++++++++++++++ > 3 files changed, 32 insertions(+), 1 deletion(-) > > diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h > index 0a398265ba04..e7e11479122b 100644 > --- a/arch/powerpc/include/asm/opal.h > +++ b/arch/powerpc/include/asm/opal.h > @@ -156,6 +156,7 @@ int64_t opal_pci_next_error(uint64_t phb_id, __be64 *first_frozen_pe, > int64_t opal_pci_poll(uint64_t id); > int64_t opal_return_cpu(void); > int64_t opal_check_token(uint64_t token); > +int64_t opal_check_token_call(uint64_t token); > int64_t opal_reinit_cpus(uint64_t flags); > > int64_t opal_xscom_read(uint32_t gcid, uint64_t pcb_addr, __be64 *val); > diff --git a/arch/powerpc/platforms/powernv/opal-call.c b/arch/powerpc/platforms/powernv/opal-call.c > index 021b0ec29e24..00325c189e69 100644 > --- a/arch/powerpc/platforms/powernv/opal-call.c > +++ b/arch/powerpc/platforms/powernv/opal-call.c > @@ -207,7 +207,7 @@ OPAL_CALL(opal_validate_flash, OPAL_FLASH_VALIDATE); > OPAL_CALL(opal_manage_flash, OPAL_FLASH_MANAGE); > OPAL_CALL(opal_update_flash, OPAL_FLASH_UPDATE); > OPAL_CALL(opal_resync_timebase, OPAL_RESYNC_TIMEBASE); > -OPAL_CALL(opal_check_token, OPAL_CHECK_TOKEN); > +OPAL_CALL(opal_check_token_call, OPAL_CHECK_TOKEN); > OPAL_CALL(opal_dump_init, OPAL_DUMP_INIT); > OPAL_CALL(opal_dump_info, OPAL_DUMP_INFO); > OPAL_CALL(opal_dump_info2, OPAL_DUMP_INFO2); > diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c > index 1946dbdc9fa1..1e9cb5271ee7 100644 > --- a/arch/powerpc/platforms/powernv/opal.c > +++ b/arch/powerpc/platforms/powernv/opal.c > @@ -1125,6 +1125,36 @@ EXPORT_SYMBOL_GPL(opal_flash_read); > EXPORT_SYMBOL_GPL(opal_flash_write); > EXPORT_SYMBOL_GPL(opal_flash_erase); > EXPORT_SYMBOL_GPL(opal_prd_msg); > + > +/** > + * opal_check_token - Check if an OPAL call token is supported > + * @token: OPAL token number to check > + * > + * Returns 1 if supported, 0 if not. > + */ > +int64_t opal_check_token(uint64_t token) > +{ > + static u8 token_cache[OPAL_LAST]; > + enum { > + SUPP_UNKNOWN = 0, > + PRESENT, > + ABSENT > + }; > + > + if (token > OPAL_LAST) > + return 0; > + > + if (token_cache[token] == SUPP_UNKNOWN) { > + /* Do the actual opal_call here */ > + if (opal_check_token_call(token)) { > + token_cache[token] = PRESENT; > + } else { > + token_cache[token] = ABSENT; > + } > + } > + > + return (token_cache[token] == PRESENT); > +} > EXPORT_SYMBOL_GPL(opal_check_token); > > /* Convert a region of vmalloc memory to an opal sg list */