From patchwork Tue Nov 8 05:45:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Metzger, Markus T" X-Patchwork-Id: 60163 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DE63F38582A8 for ; Tue, 8 Nov 2022 06:49:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE63F38582A8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667890195; bh=aL+fTpxN0b1X8MEPFZEayLvvpClC7NRN6u/tQZYyBiY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=JnvZjZty+4OtpmWPybQjbudFrH38oT+Ha9s8C80xuo/1RgwWGDvgcemmekG6caKwM j2KY1+ujZBcsCARvilw0qX7vFFk715Wo5q/yxLbBbIrHVXpf9r065N4SCHtT+6nnyp /C8ZlVDmWM6Cdm6feDw09uYdNFtccBxQsSHl43lw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by sourceware.org (Postfix) with ESMTPS id 984CC3858C2D; Tue, 8 Nov 2022 06:49:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 984CC3858C2D X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="396916975" X-IronPort-AV: E=Sophos;i="5.96,147,1665471600"; d="scan'208";a="396916975" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 22:49:28 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="699805744" X-IronPort-AV: E=Sophos;i="5.96,147,1665471600"; d="scan'208";a="699805744" Received: from labpc2407.iul.intel.com (HELO localhost) ([172.28.48.175]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 22:49:27 -0800 To: gdb-patches@sourceware.org, binutils@sourceware.org Subject: [PATCH 1/2] gprofng: make cpu identification available to others Date: Tue, 8 Nov 2022 06:45:29 +0100 Message-Id: <20221108054530.796968-1-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Markus Metzger via Gdb-patches From: "Metzger, Markus T" Reply-To: Markus Metzger Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I ran gprofng.display/display.exp on Fedora 36 x86-64 and I got UNSUPPORTED: jsynprog ERROR: comparison of results in mttest failed UNRESOLVED: mttest ERROR: comparison of results in mttest failed UNRESOLVED: mttest PASS: synprog PASS: synprog with and without this patch. --- gprofng/common/hwcdrv.c | 2 +- gprofng/common/cpuid.c => include/cpuident.h | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) rename gprofng/common/cpuid.c => include/cpuident.h (96%) diff --git a/gprofng/common/hwcdrv.c b/gprofng/common/hwcdrv.c index 03c3a71c8e2..115638aa623 100644 --- a/gprofng/common/hwcdrv.c +++ b/gprofng/common/hwcdrv.c @@ -32,7 +32,7 @@ /* macros */ #define IS_GLOBAL /* Mark global symbols */ -#include "cpuid.c" /* ftns for identifying a chip */ +#include "cpuident.h" /* ftns for identifying a chip */ static hdrv_pcbe_api_t hdrv_pcbe_core_api; static hdrv_pcbe_api_t hdrv_pcbe_opteron_api; diff --git a/gprofng/common/cpuid.c b/include/cpuident.h similarity index 96% rename from gprofng/common/cpuid.c rename to include/cpuident.h index 211e09aa8ac..7ab6fc1f2b1 100644 --- a/gprofng/common/cpuid.c +++ b/include/cpuident.h @@ -18,6 +18,11 @@ Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ +#ifndef _CPUIDENT_H +#define _CPUIDENT_H + +#include + #if defined(__i386__) || defined(__x86_64) #include /* GCC-provided */ #elif defined(__aarch64__) @@ -85,7 +90,7 @@ typedef struct #if defined(__i386__) || defined(__x86_64) -static uint_t +static unsigned int cpuid_vendorstr_to_vendorcode (char *vendorstr) { if (strcmp (vendorstr, X86_VENDORSTR_Intel) == 0) @@ -101,8 +106,10 @@ my_cpuid (unsigned int op, cpuid_regs_t *regs) { regs->eax = regs->ebx = regs->ecx = regs->edx = 0; int ret = __get_cpuid (op, ®s->eax, ®s->ebx, ®s->ecx, ®s->edx); +#ifdef DBG_LT1 TprintfT (DBG_LT1, "my_cpuid: __get_cpuid(0x%x, 0x%x, 0x%x, 0x%x, 0x%x) returns %d\n", op, regs->eax, regs->ebx, regs->ecx, regs->edx, ret); +#endif return ret; } #endif @@ -184,20 +191,22 @@ get_cpuid_info () return cpi; } -static inline uint_t +static inline unsigned int cpuid_getvendor () { return get_cpuid_info ()->cpi_vendor; } -static inline uint_t +static inline unsigned int cpuid_getfamily () { return get_cpuid_info ()->cpi_family; } -static inline uint_t +static inline unsigned int cpuid_getmodel () { return get_cpuid_info ()->cpi_model; } + +#endif /* _CPUIDENT_H */ From patchwork Tue Nov 8 05:45:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Metzger, Markus T" X-Patchwork-Id: 60164 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A2063858021 for ; Tue, 8 Nov 2022 06:51:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A2063858021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667890287; bh=I07iuiYNXfAXDRyLhfpX0zJFyIG+PyytPi5l3FaDlM8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=yrwPFCJV00kUJCubkgYaHtCv/C1nqx/PBF2I12yzMlg+Hhf07HHYjuVeaAjdu05Ct jE87Z1MCPpbZgLUKiKQ+YkDEu9T/yueHP2T48MmhmCC1Q1bYTjQ2Y0u9PxVFo7yOb3 5A2MSio/JNRqUqYtSCF14gMhM9RVfL304o9BYl5w= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by sourceware.org (Postfix) with ESMTPS id 46016385843D; Tue, 8 Nov 2022 06:49:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 46016385843D X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="290341159" X-IronPort-AV: E=Sophos;i="5.96,147,1665471600"; d="scan'208";a="290341159" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 22:49:35 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="811130978" X-IronPort-AV: E=Sophos;i="5.96,147,1665471600"; d="scan'208";a="811130978" Received: from labpc2407.iul.intel.com (HELO localhost) ([172.28.48.175]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 22:49:34 -0800 To: gdb-patches@sourceware.org, binutils@sourceware.org Subject: [PATCH 2/2] gdb, btrace: use cpuident.h to implement btrace_this_cpu Date: Tue, 8 Nov 2022 06:45:30 +0100 Message-Id: <20221108054530.796968-2-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221108054530.796968-1-markus.t.metzger@intel.com> References: <20221108054530.796968-1-markus.t.metzger@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Markus Metzger via Gdb-patches From: "Metzger, Markus T" Reply-To: Markus Metzger Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" --- gdb/nat/linux-btrace.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c index a951f3b56aa..108a4a10ecb 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -23,7 +23,7 @@ #include "linux-btrace.h" #include "gdbsupport/common-regcache.h" #include "gdbsupport/gdb_wait.h" -#include "x86-cpuid.h" +#include "include/cpuident.h" #include "gdbsupport/filestuff.h" #include "gdbsupport/scoped_fd.h" #include "gdbsupport/scoped_mmap.h" @@ -65,38 +65,23 @@ static struct btrace_cpu btrace_this_cpu (void) { struct btrace_cpu cpu; - unsigned int eax, ebx, ecx, edx; - int ok; - memset (&cpu, 0, sizeof (cpu)); - ok = x86_cpuid (0, &eax, &ebx, &ecx, &edx); - if (ok != 0) + unsigned int vendor = cpuid_getvendor (); + switch (vendor) { - if (ebx == signature_INTEL_ebx && ecx == signature_INTEL_ecx - && edx == signature_INTEL_edx) - { - unsigned int cpuid, ignore; - - ok = x86_cpuid (1, &cpuid, &ignore, &ignore, &ignore); - if (ok != 0) - { - cpu.vendor = CV_INTEL; - - cpu.family = (cpuid >> 8) & 0xf; - if (cpu.family == 0xf) - cpu.family += (cpuid >> 20) & 0xff; + case X86_VENDOR_Intel: + cpu.vendor = CV_INTEL; + break; - cpu.model = (cpuid >> 4) & 0xf; - if ((cpu.family == 0x6) || ((cpu.family & 0xf) == 0xf)) - cpu.model += (cpuid >> 12) & 0xf0; - } - } - else if (ebx == signature_AMD_ebx && ecx == signature_AMD_ecx - && edx == signature_AMD_edx) - cpu.vendor = CV_AMD; + case X86_VENDOR_AMD: + cpu.vendor = CV_AMD; + break; } + cpu.family = (unsigned short) cpuid_getfamily (); + cpu.model = (unsigned char) cpuid_getmodel (); + return cpu; }