All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sourabh Jain <sourabhjain@linux.ibm.com>
To: Shivang Upadhyay <shivangu@linux.ibm.com>
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
Subject: Re: [PATCH v2] powerpc/powernv: Cache OPAL check_token() results
Date: Tue, 30 Jun 2026 19:20:19 +0530	[thread overview]
Message-ID: <c246ce30-73f5-4beb-a47b-e771f294842e@linux.ibm.com> (raw)
In-Reply-To: <20260626123534.396456-1-shivangu@linux.ibm.com>



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 <sourabhjain@linux.ibm.com>

>
> Signed-off-by: Shivang Upadhyay <shivangu@linux.ibm.com>
> ---
> 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 */



  reply	other threads:[~2026-06-30 13:50 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 [this message]
2026-07-07  7:06 ` Nikhil Kumar Singh
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=c246ce30-73f5-4beb-a47b-e771f294842e@linux.ibm.com \
    --to=sourabhjain@linux.ibm.com \
    --cc=adityag@linux.ibm.com \
    --cc=chleroy@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mahesh@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=shivangu@linux.ibm.com \
    --cc=thuth@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.