From: Reinette Chatre <reinette.chatre@intel.com>
To: shuah@kernel.org, linux-kselftest@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com,
sandipan@linux.ibm.com, fweimer@redhat.com,
desnesn@linux.vnet.ibm.com, mingo@kernel.org,
bauerman@linux.ibm.com, mpe@ellerman.id.au, msuchanek@suse.de,
linux-mm@kvack.org, chang.seok.bae@intel.com, bp@suse.de,
tglx@linutronix.de, hpa@zytor.com, x86@kernel.org,
luto@kernel.org
Subject: [PATCH V2 1/4] selftests: Provide local define of __cpuid_count()
Date: Tue, 15 Mar 2022 09:44:25 -0700 [thread overview]
Message-ID: <7c49dbfe5bab04389ed84c516fcbfe31d66df880.1647360971.git.reinette.chatre@intel.com> (raw)
In-Reply-To: <cover.1647360971.git.reinette.chatre@intel.com>
Some selftests depend on information provided by the CPUID instruction.
To support this dependency the selftests implement private wrappers for
CPUID.
Duplication of the CPUID wrappers should be avoided.
Both gcc and clang/LLVM provide __cpuid_count() macros but neither
the macro nor its header file are available in all the compiler
versions that need to be supported by the selftests. __cpuid_count()
as provided by gcc is available starting with gcc v4.4, so it is
not available if the latest tests need to be run in all the
environments required to support kernels v4.9 and v4.14 that
have the minimal required gcc v3.2.
Provide a centrally defined macro for __cpuid_count() to help
eliminate the duplicate CPUID wrappers while continuing to
compile in older environments.
Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
Note to maintainers:
- Macro is identical to the one provided by gcc, but not liked by
checkpatch.pl with message "Macros with complex values should
be enclosed in parentheses". Similar style is used in kernel,
for example in arch/x86/kernel/fpu/xstate.h.
tools/testing/selftests/kselftest.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index f1180987492c..898d7b2fac6c 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -52,6 +52,21 @@
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
+/*
+ * gcc cpuid.h provides __cpuid_count() since v4.4.
+ * Clang/LLVM cpuid.h provides __cpuid_count() since v3.4.0.
+ *
+ * Provide local define for tests needing __cpuid_count() because
+ * selftests need to work in older environments that do not yet
+ * have __cpuid_count().
+ */
+#ifndef __cpuid_count
+#define __cpuid_count(level, count, a, b, c, d) \
+ __asm__ __volatile__ ("cpuid\n\t" \
+ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
+ : "0" (level), "2" (count))
+#endif
+
/* define kselftest exit codes */
#define KSFT_PASS 0
#define KSFT_FAIL 1
--
2.25.1
next prev parent reply other threads:[~2022-03-15 16:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-15 16:44 [PATCH V2 0/4] selftests: Remove duplicate CPUID wrappers Reinette Chatre
2022-03-15 16:44 ` Reinette Chatre [this message]
2022-04-16 7:52 ` [PATCH V2 1/4] selftests: Provide local define of __cpuid_count() Pengfei Xu
2022-04-18 16:04 ` Reinette Chatre
2022-04-19 4:31 ` Pengfei Xu
2022-04-19 22:34 ` Reinette Chatre
2022-04-20 7:22 ` Pengfei Xu
2022-03-15 16:44 ` [PATCH V2 2/4] selftests/vm/pkeys: Use provided __cpuid_count() macro Reinette Chatre
2022-03-15 16:44 ` [PATCH V2 3/4] selftests/x86/amx: " Reinette Chatre
2022-03-15 16:44 ` [PATCH V2 4/4] selftests/x86/corrupt_xstate_header: " Reinette Chatre
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=7c49dbfe5bab04389ed84c516fcbfe31d66df880.1647360971.git.reinette.chatre@intel.com \
--to=reinette.chatre@intel.com \
--cc=bauerman@linux.ibm.com \
--cc=bp@suse.de \
--cc=chang.seok.bae@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=desnesn@linux.vnet.ibm.com \
--cc=fweimer@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=msuchanek@suse.de \
--cc=sandipan@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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