summaryrefslogtreecommitdiffstats
path: root/base/cpu.cc
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-24 03:27:50 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-24 03:27:50 +0000
commit949a88f5c96cbe5ab8b4494aaf980795731ec3d1 (patch)
treef651cae621d7a37f9910a739435c343b3f5bd175 /base/cpu.cc
parentd0a01f18de2315d078336f1209f23b1c05fbebf6 (diff)
downloadchromium_src-949a88f5c96cbe5ab8b4494aaf980795731ec3d1.zip
chromium_src-949a88f5c96cbe5ab8b4494aaf980795731ec3d1.tar.gz
chromium_src-949a88f5c96cbe5ab8b4494aaf980795731ec3d1.tar.bz2
Create a class for getting at processor information via the
CPUID instruction. These will get used and integrated into the build in a future changelist. I debated on the naming of these. They are x86 processor specific. Suggestions on naming is welcome. Review URL: http://codereview.chromium.org/3199 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2542 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/cpu.cc')
-rw-r--r--base/cpu.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/base/cpu.cc b/base/cpu.cc
new file mode 100644
index 0000000..d227d9a
--- /dev/null
+++ b/base/cpu.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/cpu.h"
+#include <intrin.h>
+#include <string>
+
+namespace base {
+
+CPU::CPU()
+ : type_(0),
+ family_(0),
+ model_(0),
+ stepping_(0),
+ ext_model_(0),
+ ext_family_(0),
+ cpu_vendor_("unknown") {
+ Initialize();
+}
+
+void CPU::Initialize() {
+ int cpu_info[4] = {-1};
+ char cpu_string[0x20];
+
+ // __cpuid with an InfoType argument of 0 returns the number of
+ // valid Ids in CPUInfo[0] and the CPU identification string in
+ // the other three array elements. The CPU identification string is
+ // not in linear order. The code below arranges the information
+ // in a human readable form.
+ //
+ // More info can be found here:
+ // http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
+ __cpuid(cpu_info, 0);
+ int num_ids = cpu_info[0];
+ memset(cpu_string, 0, sizeof(cpu_string));
+ *(reinterpret_cast<int*>(cpu_string)) = cpu_info[1];
+ *(reinterpret_cast<int*>(cpu_string+4)) = cpu_info[3];
+ *(reinterpret_cast<int*>(cpu_string+8)) = cpu_info[2];
+
+ // Interpret CPU feature information.
+ __cpuid(cpu_info, 1);
+ stepping_ = cpu_info[0] & 0xf;
+ model_ = (cpu_info[0] >> 4) & 0xf;
+ family_ = (cpu_info[0] >> 8) & 0xf;
+ type_ = (cpu_info[0] >> 12) & 0x3;
+ ext_model_ = (cpu_info[0] >> 16) & 0xf;
+ ext_family_ = (cpu_info[0] >> 20) & 0xff;
+ cpu_vendor_ = cpu_string;
+}
+
+} // namespace base