mirror of https://gitee.com/openkylin/libvirt.git
virhostcpu: Add virHostCPUGetCPUID
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
85c339955c
commit
cb79953b88
|
@ -2398,6 +2398,7 @@ virHookPresent;
|
||||||
# util/virhostcpu.h
|
# util/virhostcpu.h
|
||||||
virHostCPUGetAvailableCPUsBitmap;
|
virHostCPUGetAvailableCPUsBitmap;
|
||||||
virHostCPUGetCount;
|
virHostCPUGetCount;
|
||||||
|
virHostCPUGetCPUID;
|
||||||
virHostCPUGetHaltPollTime;
|
virHostCPUGetHaltPollTime;
|
||||||
virHostCPUGetInfo;
|
virHostCPUGetInfo;
|
||||||
virHostCPUGetKVMMaxVCPUs;
|
virHostCPUGetKVMMaxVCPUs;
|
||||||
|
|
|
@ -1336,6 +1336,41 @@ virHostCPUGetMSR(unsigned long index,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct kvm_cpuid2 *
|
||||||
|
virHostCPUGetCPUID(void)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
VIR_AUTOCLOSE fd = open(KVM_DEVICE, O_RDONLY);
|
||||||
|
|
||||||
|
if (fd < 0) {
|
||||||
|
virReportSystemError(errno, _("Unable to open %s"), KVM_DEVICE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 1; i < INT32_MAX; i *= 2) {
|
||||||
|
g_autofree struct kvm_cpuid2 *kvm_cpuid = NULL;
|
||||||
|
kvm_cpuid = g_malloc0(sizeof(struct kvm_cpuid2) +
|
||||||
|
sizeof(struct kvm_cpuid_entry2) * i);
|
||||||
|
kvm_cpuid->nent = i;
|
||||||
|
|
||||||
|
if (ioctl(fd, KVM_GET_SUPPORTED_CPUID, kvm_cpuid) == 0) {
|
||||||
|
/* filter out local apic id */
|
||||||
|
for (i = 0; i < kvm_cpuid->nent; ++i) {
|
||||||
|
struct kvm_cpuid_entry2 *entry = &kvm_cpuid->entries[i];
|
||||||
|
if (entry->function == 0x01 && entry->index == 0x00)
|
||||||
|
entry->ebx &= 0x00ffffff;
|
||||||
|
if (entry->function == 0x0b)
|
||||||
|
entry->edx &= 0xffffff00;
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_steal_pointer(&kvm_cpuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virReportSystemError(errno, "%s", _("Cannot read host CPUID"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function should only be called when the host CPU supports invariant TSC
|
* This function should only be called when the host CPU supports invariant TSC
|
||||||
* (invtsc CPUID feature).
|
* (invtsc CPUID feature).
|
||||||
|
@ -1391,6 +1426,14 @@ virHostCPUGetTscInfo(void)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
struct kvm_cpuid2 *
|
||||||
|
virHostCPUGetCPUID(void)
|
||||||
|
{
|
||||||
|
virReportSystemError(ENOSYS, "%s",
|
||||||
|
_("Reading CPUID is not supported on this platform"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
virHostCPUGetMSR(unsigned long index G_GNUC_UNUSED,
|
virHostCPUGetMSR(unsigned long index G_GNUC_UNUSED,
|
||||||
uint64_t *msr G_GNUC_UNUSED)
|
uint64_t *msr G_GNUC_UNUSED)
|
||||||
|
|
|
@ -80,6 +80,8 @@ virHostCPUGetMicrocodeVersion(virArch hostArch) G_GNUC_NO_INLINE;
|
||||||
int virHostCPUGetMSR(unsigned long index,
|
int virHostCPUGetMSR(unsigned long index,
|
||||||
uint64_t *msr);
|
uint64_t *msr);
|
||||||
|
|
||||||
|
struct kvm_cpuid2 *virHostCPUGetCPUID(void);
|
||||||
|
|
||||||
virHostCPUTscInfo *virHostCPUGetTscInfo(void);
|
virHostCPUTscInfo *virHostCPUGetTscInfo(void);
|
||||||
|
|
||||||
int virHostCPUGetSignature(char **signature);
|
int virHostCPUGetSignature(char **signature);
|
||||||
|
|
Loading…
Reference in New Issue