public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Markus Metzger <markus.t.metzger@intel.com>
To: palves@redhat.com
Cc: gdb-patches@sourceware.org
Subject: [PATCH 08/12] btrace: identify cpu
Date: Mon, 14 Jul 2014 13:56:00 -0000	[thread overview]
Message-ID: <1405346196-1804-9-git-send-email-markus.t.metzger@intel.com> (raw)
In-Reply-To: <1405346196-1804-1-git-send-email-markus.t.metzger@intel.com>

Add a struct for identifying a processor and a function to identify the
processor we're running on.

We will need this feature for the new btrace format.

2014-07-14  Markus Metzger  <markus.t.metzger@intel.com>

	* common/btrace-common.h (btrace_cpu_vendor, btrace_cpu)
	(btrace_this_cpu): New.
	* common/btrace-common.c: Include i386-cpuid.h.
	(btrace_this_cpu): New.


---
 gdb/common/btrace-common.c | 37 +++++++++++++++++++++++++++++++++++++
 gdb/common/btrace-common.h | 30 ++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/gdb/common/btrace-common.c b/gdb/common/btrace-common.c
index 90774a2..178ad35 100644
--- a/gdb/common/btrace-common.c
+++ b/gdb/common/btrace-common.c
@@ -18,10 +18,47 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "btrace-common.h"
+#include "nat/i386-cpuid.h"
 
 
 /* See btrace-common.h.  */
 
+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 = i386_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 = i386_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;
+}
+
+/* See btrace-common.h.  */
+
 const char *
 btrace_format_string (enum btrace_format format)
 {
diff --git a/gdb/common/btrace-common.h b/gdb/common/btrace-common.h
index 3629736..5fa9806 100644
--- a/gdb/common/btrace-common.h
+++ b/gdb/common/btrace-common.h
@@ -74,6 +74,34 @@ enum btrace_error
   BTRACE_ERR_OVERFLOW
 };
 
+/* 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
@@ -147,6 +175,8 @@ struct btrace_data
   } variant;
 };
 
+/* Identify the cpu we're running on.  */
+extern struct btrace_cpu btrace_this_cpu (void);
 
 /* Return a string representation of FORMAT.  */
 extern const char *btrace_format_string (enum btrace_format format);
-- 
1.8.3.1

  reply	other threads:[~2014-07-14 13:56 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-14 13:56 [PATCH 00/12] record btrace: prepare for a new trace format Markus Metzger
2014-07-14 13:56 ` Markus Metzger [this message]
2014-11-05 20:47   ` [PATCH 08/12] btrace: identify cpu Pedro Alves
2014-07-14 13:56 ` [PATCH 02/12] btrace: add format argument to supports_btrace Markus Metzger
2014-11-05 20:45   ` Pedro Alves
2014-11-14 12:36     ` Metzger, Markus T
2014-11-14 13:36       ` Pedro Alves
2014-11-14 13:47         ` Metzger, Markus T
2014-11-14 13:50           ` Metzger, Markus T
2014-11-14 13:50           ` Pedro Alves
2014-07-14 13:56 ` [PATCH 09/12] btrace: use the new cpu identifier Markus Metzger
2014-07-14 13:56 ` [PATCH 06/12] btrace: update btrace_compute_ftrace parameters Markus Metzger
2014-07-14 13:57 ` [PATCH 07/12] btrace: extend struct btrace_insn Markus Metzger
2014-11-05 20:46   ` Pedro Alves
2014-07-14 13:57 ` [PATCH 10/12] record-btrace: indicate gaps Markus Metzger
2014-07-14 13:57 ` [PATCH 03/12] btrace, linux: add perf event buffer abstraction Markus Metzger
2014-07-14 13:57 ` [PATCH 05/12] record-btrace: add bts buffer size configuration option Markus Metzger
2014-07-14 15:44   ` Eli Zaretskii
2014-11-05 20:46   ` Pedro Alves
2014-07-14 13:57 ` [PATCH 04/12] record btrace: add configuration struct Markus Metzger
2014-07-14 15:06   ` Eli Zaretskii
2014-11-05 20:45   ` Pedro Alves
2014-07-14 13:57 ` [PATCH 11/12] configure: check for libipt Markus Metzger
2014-07-14 13:57 ` [PATCH 12/12] [wip] btrace: support Intel(R) Processor Trace Markus Metzger
2014-07-14 14:48 ` [PATCH 01/12] btrace: add struct btrace_data Markus Metzger
2014-11-05 20:44   ` Pedro Alves
2014-10-28 14:35 ` [PATCH 00/12] record btrace: prepare for a new trace format Metzger, Markus T
2014-11-05 20:50   ` Pedro Alves
2014-11-06  9:04     ` Metzger, Markus T
2014-11-07 11:27       ` 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=1405346196-1804-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).