All of lore.kernel.org
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: shuah@kernel.org, linux-kselftest@vger.kernel.org
Cc: 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, mingo@redhat.com, hpa@zytor.com,
	luto@kernel.org, x86@kernel.org
Subject: [PATCH V3 1/4] selftests: Provide local define of __cpuid_count()
Date: Mon, 25 Apr 2022 14:01:11 -0700	[thread overview]
Message-ID: <c6c0aaf08f6ef541c33c8b40e422fcd618b4d817.1650918160.git.reinette.chatre@intel.com> (raw)
In-Reply-To: <cover.1650918160.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.

Duplicate gcc's __cpuid_count() macro to 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.

Changes since V2:
- Highlight in changelog that macro is copied from gcc.

 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 b8f248018174..33a0dbd26bd3 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -53,6 +53,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


  reply	other threads:[~2022-04-25 21:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-25 21:01 [PATCH V3 0/4] selftests: Remove duplicate CPUID wrappers Reinette Chatre
2022-04-25 21:01 ` Reinette Chatre [this message]
2022-04-25 21:01 ` [PATCH V3 2/4] selftests/vm/pkeys: Use provided __cpuid_count() macro Reinette Chatre
2022-04-25 21:01 ` [PATCH V3 3/4] selftests/x86/amx: " Reinette Chatre
2022-04-25 21:01 ` [PATCH V3 4/4] selftests/x86/corrupt_xstate_header: " Reinette Chatre
2022-04-25 21:08 ` [PATCH V3 0/4] selftests: Remove duplicate CPUID wrappers Shuah Khan

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=c6c0aaf08f6ef541c33c8b40e422fcd618b4d817.1650918160.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-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --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 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.