mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-25 14:05:18 +00:00
util: introduce virHostCPUGetMicrocodeVersion
This new API reads host's CPU microcode version from /proc/cpuinfo. Unfortunately, there is no other way of reading microcode version which would be usable from both system and session daemon. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
40fc85e796
commit
04502fd54f
@ -1869,6 +1869,7 @@ virHostCPUGetCount;
|
|||||||
virHostCPUGetInfo;
|
virHostCPUGetInfo;
|
||||||
virHostCPUGetKVMMaxVCPUs;
|
virHostCPUGetKVMMaxVCPUs;
|
||||||
virHostCPUGetMap;
|
virHostCPUGetMap;
|
||||||
|
virHostCPUGetMicrocodeVersion;
|
||||||
virHostCPUGetOnline;
|
virHostCPUGetOnline;
|
||||||
virHostCPUGetOnlineBitmap;
|
virHostCPUGetOnlineBitmap;
|
||||||
virHostCPUGetPresentBitmap;
|
virHostCPUGetPresentBitmap;
|
||||||
|
@ -1206,3 +1206,50 @@ virHostCPUGetKVMMaxVCPUs(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_LINUX_KVM_H */
|
#endif /* HAVE_LINUX_KVM_H */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns 0 if the microcode version is unknown or cannot be read for
|
||||||
|
* some reason.
|
||||||
|
*/
|
||||||
|
unsigned int
|
||||||
|
virHostCPUGetMicrocodeVersion(void)
|
||||||
|
{
|
||||||
|
char *outbuf = NULL;
|
||||||
|
char *cur;
|
||||||
|
unsigned int version = 0;
|
||||||
|
|
||||||
|
if (virFileReadHeaderQuiet(CPUINFO_PATH, 4096, &outbuf) < 0) {
|
||||||
|
char ebuf[1024];
|
||||||
|
VIR_DEBUG("Failed to read microcode version from %s: %s",
|
||||||
|
CPUINFO_PATH, virStrerror(errno, ebuf, sizeof(ebuf)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Account for format 'microcode : XXXX'*/
|
||||||
|
if (!(cur = strstr(outbuf, "microcode")) ||
|
||||||
|
!(cur = strchr(cur, ':')))
|
||||||
|
goto cleanup;
|
||||||
|
cur++;
|
||||||
|
|
||||||
|
/* Linux places the microcode revision in a 32-bit integer, so
|
||||||
|
* ui is fine for us too. */
|
||||||
|
if (virStrToLong_ui(cur, &cur, 0, &version) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(outbuf);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
virHostCPUGetMicrocodeVersion(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __linux__ */
|
||||||
|
@ -66,4 +66,6 @@ virBitmapPtr virHostCPUGetSiblingsList(unsigned int cpu);
|
|||||||
|
|
||||||
int virHostCPUGetOnline(unsigned int cpu, bool *online);
|
int virHostCPUGetOnline(unsigned int cpu, bool *online);
|
||||||
|
|
||||||
|
unsigned int virHostCPUGetMicrocodeVersion(void);
|
||||||
|
|
||||||
#endif /* __VIR_HOSTCPU_H__*/
|
#endif /* __VIR_HOSTCPU_H__*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user