Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cpu-info.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_UTIL_CPU_INFO_H
17 #define IMPALA_UTIL_CPU_INFO_H
18 
19 #include <string>
20 #include <boost/cstdint.hpp>
21 
22 #include "common/logging.h"
23 
24 namespace impala {
25 
30 class CpuInfo {
31  public:
32  static const int64_t SSSE3 = (1 << 1);
33  static const int64_t SSE4_1 = (1 << 2);
34  static const int64_t SSE4_2 = (1 << 3);
35  static const int64_t POPCNT = (1 << 4);
36 
38  enum CacheLevel {
39  L1_CACHE = 0,
40  L2_CACHE = 1,
41  L3_CACHE = 2,
42  };
43 
45  static void Init();
46 
49  static void VerifyCpuRequirements();
50 
52  static int64_t hardware_flags() {
53  DCHECK(initialized_);
54  return hardware_flags_;
55  }
56 
58  inline static bool IsSupported(long flag) {
59  DCHECK(initialized_);
60  return (hardware_flags_ & flag) != 0;
61  }
62 
65  static void EnableFeature(long flag, bool enable);
66 
68  static long CacheSize(CacheLevel level) {
69  DCHECK(initialized_);
70  return cache_sizes_[level];
71  }
72 
74  static int64_t cycles_per_ms() {
75  DCHECK(initialized_);
76  return cycles_per_ms_;
77  }
78 
80  static int num_cores() {
81  DCHECK(initialized_);
82  return num_cores_;
83  }
84 
86  static std::string model_name() {
87  DCHECK(initialized_);
88  return model_name_;
89  }
90 
91  static std::string DebugString();
92 
93  private:
94  static bool initialized_;
95  static int64_t hardware_flags_;
96  static int64_t original_hardware_flags_;
97  static long cache_sizes_[L3_CACHE + 1];
98  static int64_t cycles_per_ms_;
99  static int num_cores_;
100  static std::string model_name_;
101 };
102 
103 }
104 #endif
static void EnableFeature(long flag, bool enable)
Definition: cpu-info.cc:144
static const int64_t SSSE3
Definition: cpu-info.h:32
static long cache_sizes_[L3_CACHE+1]
Definition: cpu-info.h:97
static int64_t hardware_flags()
Returns all the flags for this cpu.
Definition: cpu-info.h:52
CacheLevel
Cache enums for L1 (data), L2 and L3.
Definition: cpu-info.h:38
static void VerifyCpuRequirements()
Definition: cpu-info.cc:137
static int num_cores_
Definition: cpu-info.h:99
static int64_t original_hardware_flags_
Definition: cpu-info.h:96
static long CacheSize(CacheLevel level)
Returns the size of the cache in KB at this cache level.
Definition: cpu-info.h:68
static int64_t hardware_flags_
Definition: cpu-info.h:95
static const int64_t POPCNT
Definition: cpu-info.h:35
static int64_t cycles_per_ms_
Definition: cpu-info.h:98
static std::string model_name()
Returns the model name of the cpu (e.g. Intel i7-2600)
Definition: cpu-info.h:86
static const int64_t SSE4_2
Definition: cpu-info.h:34
static std::string DebugString()
Definition: cpu-info.cc:155
static bool initialized_
Definition: cpu-info.h:94
static int64_t cycles_per_ms()
Returns the number of cpu cycles per millisecond.
Definition: cpu-info.h:74
static const int64_t SSE4_1
Definition: cpu-info.h:33
static std::string model_name_
Definition: cpu-info.h:100
static void Init()
Initialize CpuInfo.
Definition: cpu-info.cc:75
static int num_cores()
Returns the number of cores (including hyper-threaded) on this machine.
Definition: cpu-info.h:80
static bool IsSupported(long flag)
Returns whether of not the cpu supports this flag.
Definition: cpu-info.h:58
int64_t flag
Definition: cpu-info.cc:51