hwpmc_x86.c (184205) | hwpmc_x86.c (184802) |
---|---|
1/*- 2 * Copyright (c) 2005,2008 Joseph Koshy 3 * Copyright (c) 2007 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * Portions of this software were developed by A. Joseph Koshy under 7 * sponsorship from the FreeBSD Foundation and Google, Inc. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2005,2008 Joseph Koshy 3 * Copyright (c) 2007 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * Portions of this software were developed by A. Joseph Koshy under 7 * sponsorship from the FreeBSD Foundation and Google, Inc. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_x86.c 184205 2008-10-23 15:53:51Z des $"); | 32__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_x86.c 184802 2008-11-09 17:37:54Z jkoshy $"); |
33 34#include <sys/param.h> 35#include <sys/bus.h> 36#include <sys/pmc.h> 37#include <sys/proc.h> 38#include <sys/systm.h> 39 40#include <machine/cpu.h> --- 194 unchanged lines hidden (view full) --- 235 break; 236 pc = *(uintptr_t *) r; 237 fp = *(uintptr_t *) fp; 238 } 239 240 return (n); 241} 242 | 33 34#include <sys/param.h> 35#include <sys/bus.h> 36#include <sys/pmc.h> 37#include <sys/proc.h> 38#include <sys/systm.h> 39 40#include <machine/cpu.h> --- 194 unchanged lines hidden (view full) --- 235 break; 236 pc = *(uintptr_t *) r; 237 fp = *(uintptr_t *) fp; 238 } 239 240 return (n); 241} 242 |
243static struct pmc_mdep * 244pmc_intel_initialize(void) 245{ 246 struct pmc_mdep *pmc_mdep; 247 enum pmc_cputype cputype; 248 int error, model; 249 250 KASSERT(strcmp(cpu_vendor, "GenuineIntel") == 0, 251 ("[intel,%d] Initializing non-intel processor", __LINE__)); 252 253 PMCDBG(MDP,INI,0, "intel-initialize cpuid=0x%x", cpu_id); 254 255 cputype = -1; 256 257 switch (cpu_id & 0xF00) { 258#if defined(__i386__) 259 case 0x500: /* Pentium family processors */ 260 cputype = PMC_CPU_INTEL_P5; 261 break; 262 case 0x600: /* Pentium Pro, Celeron, Pentium II & III */ 263 switch ((cpu_id & 0xF0) >> 4) { /* model number field */ 264 case 0x1: 265 cputype = PMC_CPU_INTEL_P6; 266 break; 267 case 0x3: case 0x5: 268 cputype = PMC_CPU_INTEL_PII; 269 break; 270 case 0x6: 271 cputype = PMC_CPU_INTEL_CL; 272 break; 273 case 0x7: case 0x8: case 0xA: case 0xB: 274 cputype = PMC_CPU_INTEL_PIII; 275 break; 276 case 0x9: case 0xD: 277 cputype = PMC_CPU_INTEL_PM; 278 break; 279 } 280 break; 281#endif 282#if defined(__i386__) || defined(__amd64__) 283 case 0xF00: /* P4 */ 284 model = ((cpu_id & 0xF0000) >> 12) | ((cpu_id & 0xF0) >> 4); 285 if (model >= 0 && model <= 6) /* known models */ 286 cputype = PMC_CPU_INTEL_PIV; 287 break; 288 } 289#endif 290 291 if ((int) cputype == -1) { 292 printf("pmc: Unknown Intel CPU.\n"); 293 return NULL; 294 } 295 296 pmc_mdep = malloc(sizeof(struct pmc_mdep), 297 M_PMC, M_WAITOK|M_ZERO); 298 299 pmc_mdep->pmd_cputype = cputype; 300 pmc_mdep->pmd_nclass = 2; 301 pmc_mdep->pmd_classes[0].pm_class = PMC_CLASS_TSC; 302 pmc_mdep->pmd_classes[0].pm_caps = PMC_CAP_READ; 303 pmc_mdep->pmd_classes[0].pm_width = 64; 304 pmc_mdep->pmd_nclasspmcs[0] = 1; 305 306 error = 0; 307 308 switch (cputype) { 309 310#if defined(__i386__) || defined(__amd64__) 311 312 /* 313 * Intel Pentium 4 Processors, and P4/EMT64 processors. 314 */ 315 316 case PMC_CPU_INTEL_PIV: 317 error = pmc_initialize_p4(pmc_mdep); 318 break; 319#endif 320 321#if defined(__i386__) 322 /* 323 * P6 Family Processors 324 */ 325 326 case PMC_CPU_INTEL_P6: 327 case PMC_CPU_INTEL_CL: 328 case PMC_CPU_INTEL_PII: 329 case PMC_CPU_INTEL_PIII: 330 case PMC_CPU_INTEL_PM: 331 332 error = pmc_initialize_p6(pmc_mdep); 333 break; 334 335 /* 336 * Intel Pentium PMCs. 337 */ 338 339 case PMC_CPU_INTEL_P5: 340 error = pmc_initialize_p5(pmc_mdep); 341 break; 342#endif 343 344 default: 345 KASSERT(0,("[intel,%d] Unknown CPU type", __LINE__)); 346 } 347 348 if (error) { 349 free(pmc_mdep, M_PMC); 350 pmc_mdep = NULL; 351 } 352 353 return pmc_mdep; 354} 355 356 | |
357/* 358 * Machine dependent initialization for x86 class platforms. 359 */ 360 361struct pmc_mdep * 362pmc_md_initialize() 363{ 364 int i; 365 struct pmc_mdep *md; 366 367 /* determine the CPU kind */ 368 md = NULL; 369 if (strcmp(cpu_vendor, "AuthenticAMD") == 0) 370 md = pmc_amd_initialize(); 371 else if (strcmp(cpu_vendor, "GenuineIntel") == 0) 372 md = pmc_intel_initialize(); | 243/* 244 * Machine dependent initialization for x86 class platforms. 245 */ 246 247struct pmc_mdep * 248pmc_md_initialize() 249{ 250 int i; 251 struct pmc_mdep *md; 252 253 /* determine the CPU kind */ 254 md = NULL; 255 if (strcmp(cpu_vendor, "AuthenticAMD") == 0) 256 md = pmc_amd_initialize(); 257 else if (strcmp(cpu_vendor, "GenuineIntel") == 0) 258 md = pmc_intel_initialize(); |
259 else 260 KASSERT(0, ("[x86,%d] Unknown vendor", __LINE__)); |
|
373 374 /* disallow sampling if we do not have an LAPIC */ 375 if (md != NULL && lapic == NULL) 376 for (i = 1; i < md->pmd_nclass; i++) | 261 262 /* disallow sampling if we do not have an LAPIC */ 263 if (md != NULL && lapic == NULL) 264 for (i = 1; i < md->pmd_nclass; i++) |
377 md->pmd_classes[i].pm_caps &= ~PMC_CAP_INTERRUPT; | 265 md->pmd_classdep[i].pcd_caps &= ~PMC_CAP_INTERRUPT; |
378 | 266 |
379 return md; | 267 return (md); |
380} | 268} |
269 270void 271pmc_md_finalize(struct pmc_mdep *md) 272{ 273 if (strcmp(cpu_vendor, "AuthenticAMD") == 0) 274 pmc_amd_finalize(md); 275 else if (strcmp(cpu_vendor, "GenuineIntel") == 0) 276 pmc_intel_finalize(md); 277 else 278 KASSERT(0, ("[x86,%d] Unknown vendor", __LINE__)); 279} |
|