提交 a551dd5f 编写于 作者: J Jiri Denemark

hostcpu: Introduce virHostCPUGetSignature

The purpose of this function is to give a short description that would
be change when a host CPU is replaced with a different model. This is
currently implemented by reading /proc/cpuinfo.

It should be implemented for all architectures for which the QEMU driver
stores host CPU data in the capabilities cache. In other words for archs
that support host-model CPUs.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 8cb9d249
......@@ -2218,9 +2218,11 @@ virHostCPUGetMSR;
virHostCPUGetOnline;
virHostCPUGetOnlineBitmap;
virHostCPUGetPresentBitmap;
virHostCPUGetSignature;
virHostCPUGetStats;
virHostCPUGetThreadsPerSubcore;
virHostCPUHasBitmap;
virHostCPUReadSignature;
virHostCPUStatsAssign;
......
......@@ -1416,3 +1416,40 @@ virHostCPUGetTscInfo(void)
#endif /* HAVE_LINUX_KVM_H && defined(KVM_GET_MSRS) && \
(defined(__i386__) || defined(__x86_64__)) && \
(defined(__linux__) || defined(__FreeBSD__)) */
int
virHostCPUReadSignature(virArch arch G_GNUC_UNUSED,
FILE *cpuinfo G_GNUC_UNUSED,
char **signature G_GNUC_UNUSED)
{
return 0;
}
#ifdef __linux__
int
virHostCPUGetSignature(char **signature)
{
g_autoptr(FILE) cpuinfo = NULL;
*signature = NULL;
if (!(cpuinfo = fopen(CPUINFO_PATH, "r"))) {
virReportSystemError(errno, _("Failed to open cpuinfo file '%s'"),
CPUINFO_PATH);
return -1;
}
return virHostCPUReadSignature(virArchFromHost(), cpuinfo, signature);
}
#else
int
virHostCPUGetSignature(char **signature)
{
*signature = NULL;
return 0;
}
#endif /* __linux__ */
......@@ -79,3 +79,5 @@ int virHostCPUGetMSR(unsigned long index,
uint64_t *msr);
virHostCPUTscInfoPtr virHostCPUGetTscInfo(void);
int virHostCPUGetSignature(char **signature);
......@@ -42,3 +42,7 @@ int virHostCPUGetStatsLinux(FILE *procstat,
virNodeCPUStatsPtr params,
int *nparams);
#endif
int virHostCPUReadSignature(virArch arch,
FILE *cpuinfo,
char **signature);
#include <config.h>
#include <unistd.h>
#include <fcntl.h>
#include "testutils.h"
#include "internal.h"
......@@ -193,6 +194,38 @@ linuxTestHostCPU(const void *opaque)
return result;
}
static int
hostCPUSignature(const void *opaque)
{
const struct linuxTestHostCPUData *data = opaque;
const char *arch = virArchToString(data->arch);
g_autofree char *cpuinfo = NULL;
g_autofree char *expected = NULL;
g_autofree char *signature = NULL;
g_autoptr(FILE) f = NULL;
cpuinfo = g_strdup_printf("%s/virhostcpudata/linux-%s-%s.cpuinfo",
abs_srcdir, arch, data->testName);
expected = g_strdup_printf("%s/virhostcpudata/linux-%s-%s.signature",
abs_srcdir, arch, data->testName);
if (!(f = fopen(cpuinfo, "r"))) {
virReportSystemError(errno,
"Failed to open cpuinfo file '%s'", cpuinfo);
return -1;
}
if (virHostCPUReadSignature(data->arch, f, &signature) < 0)
return -1;
if (!signature && !virFileExists(expected))
return 0;
return virTestCompareToFile(signature, expected);
}
struct nodeCPUStatsData {
const char *name;
int ncpus;
......@@ -268,10 +301,17 @@ mymain(void)
if (virInitialize() < 0)
return EXIT_FAILURE;
for (i = 0; i < G_N_ELEMENTS(nodeData); i++)
for (i = 0; i < G_N_ELEMENTS(nodeData); i++) {
g_autofree char *sigTest = NULL;
if (virTestRun(nodeData[i].testName, linuxTestHostCPU, &nodeData[i]) != 0)
ret = -1;
sigTest = g_strdup_printf("%s CPU signature", nodeData[i].testName);
if (virTestRun(sigTest, hostCPUSignature, &nodeData[i]) != 0)
ret = -1;
}
# define DO_TEST_CPU_STATS(name, ncpus, shouldFail) \
do { \
static struct nodeCPUStatsData data = { name, ncpus, shouldFail}; \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册