Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: Expose the architectural performance monitoring CPUID leaf

Provide a CPUID leaf that describes the emulated PMU.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>

authored by

Gleb Natapov and committed by
Avi Kivity
a6c06ed1 fee84b07

+29 -1
+29 -1
arch/x86/kvm/cpuid.c
··· 327 327 } 328 328 case 9: 329 329 break; 330 + case 0xa: { /* Architectural Performance Monitoring */ 331 + struct x86_pmu_capability cap; 332 + union cpuid10_eax eax; 333 + union cpuid10_edx edx; 334 + 335 + perf_get_x86_pmu_capability(&cap); 336 + 337 + /* 338 + * Only support guest architectural pmu on a host 339 + * with architectural pmu. 340 + */ 341 + if (!cap.version) 342 + memset(&cap, 0, sizeof(cap)); 343 + 344 + eax.split.version_id = min(cap.version, 2); 345 + eax.split.num_counters = cap.num_counters_gp; 346 + eax.split.bit_width = cap.bit_width_gp; 347 + eax.split.mask_length = cap.events_mask_len; 348 + 349 + edx.split.num_counters_fixed = cap.num_counters_fixed; 350 + edx.split.bit_width_fixed = cap.bit_width_fixed; 351 + edx.split.reserved = 0; 352 + 353 + entry->eax = eax.full; 354 + entry->ebx = cap.events_mask; 355 + entry->ecx = 0; 356 + entry->edx = edx.full; 357 + break; 358 + } 330 359 /* function 0xb has additional index. */ 331 360 case 0xb: { 332 361 int i, level_type; ··· 456 427 case 3: /* Processor serial number */ 457 428 case 5: /* MONITOR/MWAIT */ 458 429 case 6: /* Thermal management */ 459 - case 0xA: /* Architectural Performance Monitoring */ 460 430 case 0x80000007: /* Advanced power management */ 461 431 case 0xC0000002: 462 432 case 0xC0000003: