Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Markus Metzger <markus.t.metzger@intel.com>
To: palves@redhat.com
Cc: gdb-patches@sourceware.org
Subject: [PATCH v4 8/9] btrace: identify cpu
Date: Thu, 05 Feb 2015 15:28:00 -0000	[thread overview]
Message-ID: <1423150072-21229-9-git-send-email-markus.t.metzger@intel.com> (raw)
In-Reply-To: <1423150072-21229-1-git-send-email-markus.t.metzger@intel.com>

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-02-05  Markus Metzger  <markus.t.metzger@intel.com>

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 bb15109..ba99a06 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 62c0acf..3093a5c 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


  parent reply	other threads:[~2015-02-05 15:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-05 15:27 [PATCH v4 0/9] record btrace: prepare for a new trace format Markus Metzger
2015-02-05 15:28 ` [PATCH v4 7/9] btrace: extend struct btrace_insn Markus Metzger
2015-02-05 15:28 ` Markus Metzger [this message]
2015-02-05 18:31   ` [PATCH v4 8/9] btrace: identify cpu Pedro Alves
2015-02-05 15:28 ` [PATCH v4 3/9] btrace, linux: add perf event buffer abstraction Markus Metzger
2015-02-05 15:28 ` [PATCH v4 1/9] btrace: add struct btrace_data Markus Metzger
2015-02-05 15:28 ` [PATCH v4 4/9] record btrace: add configuration struct Markus Metzger
2015-02-05 16:27   ` Eli Zaretskii
2015-02-05 18:31   ` Pedro Alves
2015-02-05 15:28 ` [PATCH v4 6/9] btrace: update btrace_compute_ftrace parameters Markus Metzger
2015-02-05 15:28 ` [PATCH v4 9/9] record-btrace: indicate gaps Markus Metzger
2015-02-05 15:28 ` [PATCH v4 2/9] btrace: add format argument to supports_btrace Markus Metzger
2015-02-05 15:28 ` [PATCH v4 5/9] record-btrace: add bts buffer size configuration option Markus Metzger
2015-02-05 16:25   ` Eli Zaretskii
2015-02-05 18:33 ` [PATCH v4 0/9] record btrace: prepare for a new trace format Pedro Alves

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=1423150072-21229-9-git-send-email-markus.t.metzger@intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /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