提交 44f826e4 编写于 作者: J Jiri Denemark

hostcpu: Implement virHostCPUGetSignature for x86

Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 a551dd5f
......@@ -1418,10 +1418,54 @@ virHostCPUGetTscInfo(void)
(defined(__linux__) || defined(__FreeBSD__)) */
int
virHostCPUReadSignature(virArch arch G_GNUC_UNUSED,
FILE *cpuinfo G_GNUC_UNUSED,
char **signature G_GNUC_UNUSED)
virHostCPUReadSignature(virArch arch,
FILE *cpuinfo,
char **signature)
{
size_t lineLen = 1024;
g_autofree char *line = g_new0(char, lineLen);
g_autofree char *vendor = NULL;
g_autofree char *name = NULL;
g_autofree char *family = NULL;
g_autofree char *model = NULL;
g_autofree char *stepping = NULL;
if (!ARCH_IS_X86(arch))
return 0;
while (fgets(line, lineLen, cpuinfo)) {
g_auto(GStrv) parts = g_strsplit(line, ": ", 2);
if (g_strv_length(parts) != 2)
continue;
g_strstrip(parts[0]);
g_strstrip(parts[1]);
if (STREQ(parts[0], "vendor_id")) {
if (!vendor)
vendor = g_steal_pointer(&parts[1]);
} else if (STREQ(parts[0], "model name")) {
if (!name)
name = g_steal_pointer(&parts[1]);
} else if (STREQ(parts[0], "cpu family")) {
if (!family)
family = g_steal_pointer(&parts[1]);
} else if (STREQ(parts[0], "model")) {
if (!model)
model = g_steal_pointer(&parts[1]);
} else if (STREQ(parts[0], "stepping")) {
if (!stepping)
stepping = g_steal_pointer(&parts[1]);
}
if (vendor && name && family && model && stepping) {
*signature = g_strdup_printf("%s, %s, family: %s, model: %s, stepping: %s",
vendor, name, family, model, stepping);
return 0;
}
}
return 0;
}
......
GenuineIntel, Intel(R) Xeon(TM) CPU 2.80GHz, family: 15, model: 4, stepping: 8
GenuineIntel, Intel(R) Core(TM)2 Duo CPU T9600 @ 2.80GHz, family: 6, model: 23, stepping: 10
AuthenticAMD, AMD Opteron(tm) Processor 6172, family: 16, model: 9, stepping: 1
GenuineIntel, Intel(R) Xeon(R) CPU E7- 8837 @ 2.67GHz, family: 6, model: 47, stepping: 2
GenuineIntel, Intel(R) Xeon(R) CPU E5320 @ 1.86GHz, family: 6, model: 15, stepping: 7
GenuineIntel, Intel(R) Xeon(R) CPU E5640 @ 2.67GHz, family: 6, model: 44, stepping: 2
AuthenticAMD, AMD Opteron(tm) Processor 6174, family: 16, model: 9, stepping: 1
AuthenticAMD, AMD Opteron(tm) Processor 6282 SE, family: 21, model: 1, stepping: 2
GenuineIntel, QEMU Virtual CPU version 2.5+, family: 6, model: 6, stepping: 3
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册