Thread (8 messages) flat view 8 messages, 4 authors, 3d ago

Re: [PATCH v2] powerpc/powernv: Cache OPAL check_token() results

From: Nikhil Kumar Singh <hidden>
Date: 2026-07-07 07:07:12

On 26/06/26 18:05, Shivang Upadhyay wrote:
quoted hunk ↗ jump to hunk
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 */
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help