From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 913 invoked by alias); 29 Jan 2015 16:28:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 838 invoked by uid 89); 29 Jan 2015 16:28:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mga09.intel.com Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Jan 2015 16:28:28 +0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 29 Jan 2015 08:25:08 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by FMSMGA003.fm.intel.com with ESMTP; 29 Jan 2015 08:14:34 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t0TGSMi4020051; Thu, 29 Jan 2015 16:28:23 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id t0TGSMim010120; Thu, 29 Jan 2015 17:28:22 +0100 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with œ id t0TGSMIw010116; Thu, 29 Jan 2015 17:28:22 +0100 From: Markus Metzger To: palves@redhat.com Cc: gdb-patches@sourceware.org Subject: [PATCH v3 08/15] btrace: identify cpu Date: Thu, 29 Jan 2015 16:29:00 -0000 Message-Id: <1422548899-9789-9-git-send-email-markus.t.metzger@intel.com> In-Reply-To: <1422548899-9789-1-git-send-email-markus.t.metzger@intel.com> References: <1422548899-9789-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes X-SW-Source: 2015-01/txt/msg00766.txt.bz2 Add a struct for identifying a processor and use it in linux-btrace.c when identifying the processor we're running on. We will need this feature for the new btrace format. 2015-01-29 Markus Metzger gdb/ * common/btrace-common.h (btrace_cpu_vendor, btrace_cpu): New. * nat/linux-btrace.c: Include x86-cpuid.h. (btrace_this_cpu): New. (cpu_supports_bts): Call btrace_this_cpu. (intel_supports_bts): Add cpu parameter. --- gdb/common/btrace-common.h | 28 +++++++++++++++++++ gdb/nat/linux-btrace.c | 70 +++++++++++++++++++++++++++++++--------------- 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/gdb/common/btrace-common.h b/gdb/common/btrace-common.h index 69e223c..5e67e52 100644 --- a/gdb/common/btrace-common.h +++ b/gdb/common/btrace-common.h @@ -61,6 +61,34 @@ enum btrace_format BTRACE_FORMAT_BTS }; +/* An enumeration of cpu vendors. */ + +enum btrace_cpu_vendor +{ + /* We do not know this vendor. */ + CV_UNKNOWN, + + /* Intel. */ + CV_INTEL +}; + +/* A cpu identifier. */ + +struct btrace_cpu +{ + /* The processor vendor. */ + enum btrace_cpu_vendor vendor; + + /* The cpu family. */ + unsigned short family; + + /* The cpu model. */ + unsigned char model; + + /* The cpu stepping. */ + unsigned char stepping; +}; + /* A BTS configuration. */ struct btrace_config_bts diff --git a/gdb/nat/linux-btrace.c b/gdb/nat/linux-btrace.c index c7db313..3376a0f 100644 --- a/gdb/nat/linux-btrace.c +++ b/gdb/nat/linux-btrace.c @@ -59,6 +59,41 @@ struct perf_event_sample struct perf_event_bts bts; }; +/* Identify the cpu we're running on. */ +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) + { + 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; + cpu.model = (cpuid >> 4) & 0xf; + + if (cpu.family == 0x6) + cpu.model += (cpuid >> 12) & 0xf0; + } + } + } + + return cpu; +} + /* Return non-zero if there is new data in PEVENT; zero otherwise. */ static int @@ -302,22 +337,12 @@ kernel_supports_bts (void) /* Check whether an Intel cpu supports BTS. */ static int -intel_supports_bts (void) +intel_supports_bts (const struct btrace_cpu *cpu) { - unsigned int cpuid, model, family; - - if (!x86_cpuid (1, &cpuid, NULL, NULL, NULL)) - return 0; - - family = (cpuid >> 8) & 0xf; - model = (cpuid >> 4) & 0xf; - - switch (family) + switch (cpu->family) { case 0x6: - model += (cpuid >> 12) & 0xf0; - - switch (model) + switch (cpu->model) { case 0x1a: /* Nehalem */ case 0x1f: @@ -345,17 +370,18 @@ intel_supports_bts (void) static int cpu_supports_bts (void) { - unsigned int ebx, ecx, edx; + struct btrace_cpu cpu; - if (!x86_cpuid (0, NULL, &ebx, &ecx, &edx)) - return 0; - - if (ebx == signature_INTEL_ebx && ecx == signature_INTEL_ecx - && edx == signature_INTEL_edx) - return intel_supports_bts (); + cpu = btrace_this_cpu (); + switch (cpu.vendor) + { + default: + /* Don't know about others. Let's assume they do. */ + return 1; - /* Don't know about others. Let's assume they do. */ - return 1; + case CV_INTEL: + return intel_supports_bts (&cpu); + } } /* Check whether the linux target supports BTS. */ -- 1.8.3.1