libmsr  0.3.0
A friendlier interface to accessing MSRs on Intel platforms
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
cpuid.h
Go to the documentation of this file.
1 /* cpuid.h
2  *
3  * Copyright (c) 2011-2016, Lawrence Livermore National Security, LLC.
4  * LLNL-CODE-645430
5  *
6  * Produced at Lawrence Livermore National Laboratory
7  * Written by Barry Rountree, rountree@llnl.gov
8  * Scott Walker, walker91@llnl.gov
9  * Kathleen Shoga, shoga1@llnl.gov
10  *
11  * All rights reserved.
12  *
13  * This file is part of libmsr.
14  *
15  * libmsr is free software: you can redistribute it and/or modify it under the
16  * terms of the GNU Lesser General Public License as published by the Free
17  * Software Foundation, either version 3 of the License, or (at your option)
18  * any later version.
19  *
20  * libmsr is distributed in the hope that it will be useful, but WITHOUT ANY
21  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
23  * details.
24  *
25  * You should have received a copy of the GNU Lesser General Public License
26  * along with libmsr. If not, see <http://www.gnu.org/licenses/>.
27  *
28  * This material is based upon work supported by the U.S. Department of
29  * Energy's Lawrence Livermore National Laboratory. Office of Science, under
30  * Award number DE-AC52-07NA27344.
31  *
32  */
33 
34 #ifndef CPUID_H_INCLUDE
35 #define CPUID_H_INCLUDE
36 
37 #include <stdbool.h>
38 #include <stdint.h>
39 #include <stdio.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
52 #define MASK_RANGE(m,n) ((((uint64_t)1<<((m)-(n)+1))-1)<<(n))
53 
57 #define MASK_VAL(x,m,n) (((uint64_t)(x)&MASK_RANGE((m),(n)))>>(n))
58 
71 void cpuid(uint64_t leaf,
72  uint64_t *rax,
73  uint64_t *rbx,
74  uint64_t *rcx,
75  uint64_t *rdx);
76 
88 void cpuid_detect_core_conf(uint64_t *coresPerSocket,
89  uint64_t *hyperThreads,
90  uint64_t *sockets,
91  int *HTenabled);
92 
96 void cpuid_get_model(uint64_t *model);
97 
111 void cpuidInput_rax_rcx(uint64_t leafa,
112  uint64_t leafc,
113  uint64_t *rax,
114  uint64_t *rbx,
115  uint64_t *rcx,
116  uint64_t *rdx);
117 
122 bool cpuid_mperf_and_aperf_avail(void);
123 
128 
129 /*****************************************/
130 /* Performance Monitoring Counters (PMC) */
131 /*****************************************/
132 
140 int cpuid_num_pmc(void);
141 
142 /*****************************************/
143 /* Performance Event Select (PerfEvtSel) */
144 /* (0x186, 0x187, 0x188, 0x189) */
145 /*****************************************/
146 
156 int cpuid_num_perfevtsel(void);
157 
158 /***************************/
159 /* PERF_GLOBAL_CTL (0x38f) */
160 /***************************/
161 
167 
174 
175 /***************/
176 /* MISC_ENABLE */
177 /***************/
178 
183 
188 
193 
194 /*************/
195 /* CLOCK_MOD */
196 /*************/
197 
202 
203 /*********************/
204 /* THERMAL Functions */
205 /*********************/
206 
212 
218 
223 
229 
236 
237 /************************/
238 /* General Machine Info */
239 /************************/
240 
244 uint64_t cpuid_MaxLeaf(void);
245 
247 void cpuid_printVendorID(void);
248 
254 
260 
264 int cpuid_num_fixed_counters(void);
265 
270 
271 #ifdef __cplusplus
272 }
273 #endif
274 #endif