From: Nikhil Kumar Singh <nikhilks@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org, Shivang Upadhyay <shivangu@linux.ibm.com>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
Subject: Re: [PATCH v2] powerpc/powernv: Cache OPAL check_token() results
Date: Tue, 7 Jul 2026 12:36:58 +0530 [thread overview]
Message-ID: <1be96e32-ac9c-4160-9f2b-23eb29c22893@linux.ibm.com> (raw)
In-Reply-To: <20260626123534.396456-1-shivangu@linux.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 1791 bytes --]
On 26/06/26 18:05, Shivang Upadhyay wrote:
> 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) {
Hi Shivang,
Thanks for the v2 patch. This is a great optimization and definitely
helps reduce unnecessary overhead. I have one small suggestion.
You can wrap the if (token_cache[token] == SUPP_UNKNOWN) check, as well
as the if (token > OPAL_LAST) check above it, with unlikely(), since
this function is in the hot path. Out-of-bounds tokens are very rare,
and after the cache is populated, the SUPP_UNKNOWN condition is expected
to be false in almost all cases. Wrapping these checks with unlikely()
will help the compiler optimize branch prediction.
Thanks,
~ Nikhil
> + /* 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 */
[-- Attachment #2: Type: text/html, Size: 2386 bytes --]
next prev parent reply other threads:[~2026-07-07 7:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 12:35 [PATCH v2] powerpc/powernv: Cache OPAL check_token() results Shivang Upadhyay
2026-06-30 13:50 ` Sourabh Jain
2026-07-07 7:06 ` Nikhil Kumar Singh [this message]
2026-07-08 8:32 ` Shivang Upadhyay
2026-07-09 6:04 ` Nikhil Kumar Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1be96e32-ac9c-4160-9f2b-23eb29c22893@linux.ibm.com \
--to=nikhilks@linux.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=shivangu@linux.ibm.com \
--cc=sourabhjain@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox