From patchwork Mon Apr 25 21:01:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 12826253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F9EDC4332F for ; Mon, 25 Apr 2022 21:01:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D9946B00B2; Mon, 25 Apr 2022 17:01:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B97A6B00B3; Mon, 25 Apr 2022 17:01:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 478266B00B4; Mon, 25 Apr 2022 17:01:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 37B2D6B00B2 for ; Mon, 25 Apr 2022 17:01:22 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 0A03E61BAF for ; Mon, 25 Apr 2022 21:01:22 +0000 (UTC) X-FDA: 79396622004.03.7B668AC Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by imf31.hostedemail.com (Postfix) with ESMTP id C700620050 for ; Mon, 25 Apr 2022 21:01:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650920481; x=1682456481; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=amodz0QpZv9gbKyt4lmRvYPhlmutS/vrHNqvwdpUV/U=; b=YYejLkzo8QvgAbioP8n8/D4FsX1IOdI3KW14j2WSGh+TbckhLmzXZl18 4C6bL2h+j3vSMyORQ8OPauvguyzkIsGHMxIjULx2kpf4DFkuzGgyxNwB8 6kp3dB+CLmrYhxG+E5xgcvfmEBXYdx/GqcF0Ef9ZawcXtPi0vymJZlS2E ox34fW3tG/HWZmODj/Omz+TncThUbtV7aUAemH34999nEwFPRYl4rtgHL Bcn2j52KDLhxa1I7Yknla2IZu4nmsAvHplWO5nkR1ak/CzZVy3O5BwihW KjHTyDb+E76kXqcpgLP4O4fudBV8J5AY4gu7M0nzQbYzYOU0RPOoxG5lx A==; X-IronPort-AV: E=McAfee;i="6400,9594,10328"; a="328304049" X-IronPort-AV: E=Sophos;i="5.90,289,1643702400"; d="scan'208";a="328304049" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 14:01:19 -0700 X-IronPort-AV: E=Sophos;i="5.90,289,1643702400"; d="scan'208";a="579499491" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 14:01:19 -0700 From: Reinette Chatre 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 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C700620050 X-Stat-Signature: ne7nsud7rftkcj7jijdwad1bohz5uret X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YYejLkzo; spf=none (imf31.hostedemail.com: domain of reinette.chatre@intel.com has no SPF policy when checking 134.134.136.100) smtp.mailfrom=reinette.chatre@intel.com; dmarc=pass (policy=none) header.from=intel.com X-HE-Tag: 1650920473-511833 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Signed-off-by: Reinette Chatre --- 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