--- src/nodeinfo.c | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 7d26b2b..15877ed 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -55,11 +55,14 @@ #ifdef __linux__ #define CPUINFO_PATH "/proc/cpuinfo" +#define SCALINGMAXFREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" /* NB, these are not static as we need to call them from testsuite */ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr nodeinfo); +int linuxNodeInfoConsiderCPUScaling(FILE *scalingmaxfreq, virNodeInfoPtr nodeinfo); + int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr nodeinfo) { char line[1024]; @@ -132,6 +135,27 @@ int linuxNodeInfoCPUPopulate(virConnectPtr conn, FILE *cpuinfo, virNodeInfoPtr n return 0; } +int linuxNodeInfoConsiderCPUScaling(FILE *scalingmaxfreq, virNodeInfoPtr nodeinfo) { + char line[1024]; + + while (fgets(line, sizeof(line), scalingmaxfreq) != NULL) { + char *buf = line; + char *p; + unsigned int khz; + + if (virStrToLong_ui(buf, &p, 10, &khz) == 0) + { + if(khz/1000 > nodeinfo->mhz) + { + nodeinfo->mhz = khz/1000; + return 0; + } + } + } + return 1; +} + + #endif int nodeGetInfo(virConnectPtr conn, @@ -164,6 +188,18 @@ int nodeGetInfo(virConnectPtr conn, if (ret < 0) return -1; + FILE *scalingmaxfreq = fopen(SCALINGMAXFREQ_PATH, "r"); + if (scalingmaxfreq != NULL) { + // TODO: some logging information that cpufreq was detected? + ret = linuxNodeInfoConsiderCPUScaling(scalingmaxfreq, nodeinfo); + if(ret == 0) { + // TODO: logging: nodeinfo->mhz was updated + } else if(ret == 1) { + // TODO: logging: cpufreq was detected, but information available didn't make sense + } + fclose(scalingmaxfreq); + } + /* Convert to KB. */ nodeinfo->memory = physmem_total () / 1024; -- 1.5.4.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list