提交 9549a896 编写于 作者: W Wang Huaqiang 提交者: Michal Privoznik

util: Extend virresctl API to retrieve multiple monitor statistics

Export virResctrlMonitorGetStats and make
virResctrlMonitorGetCacheOccupancy obsoleted.
Signed-off-by: NWang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 c09a14e5
......@@ -2835,6 +2835,7 @@ virResctrlMonitorCreate;
virResctrlMonitorDeterminePath;
virResctrlMonitorGetCacheOccupancy;
virResctrlMonitorGetID;
virResctrlMonitorGetStats;
virResctrlMonitorNew;
virResctrlMonitorRemove;
virResctrlMonitorSetAlloc;
......
......@@ -20710,6 +20710,7 @@ qemuDomainFreeResctrlMonData(virQEMUResctrlMonDataPtr resdata)
/**
* qemuDomainGetResctrlMonData:
* @dom: Pointer for the domain that the resctrl monitors reside in
* @driver: Pointer to qemu driver
* @resdata: Pointer of virQEMUResctrlMonDataPtr pointer for receiving the
* virQEMUResctrlMonDataPtr array. Caller is responsible for
* freeing the array.
......@@ -20727,16 +20728,32 @@ qemuDomainFreeResctrlMonData(virQEMUResctrlMonDataPtr resdata)
* Returns -1 on failure, or 0 on success.
*/
static int
qemuDomainGetResctrlMonData(virDomainObjPtr dom,
qemuDomainGetResctrlMonData(virQEMUDriverPtr driver,
virDomainObjPtr dom,
virQEMUResctrlMonDataPtr **resdata,
size_t *nresdata,
virResctrlMonitorType tag)
{
virDomainResctrlDefPtr resctrl = NULL;
virQEMUResctrlMonDataPtr res = NULL;
char **features = NULL;
virCapsPtr caps = NULL;
size_t i = 0;
size_t j = 0;
caps = virQEMUDriverGetCapabilities(driver, false);
if (tag == VIR_RESCTRL_MONITOR_TYPE_CACHE) {
features = caps->host.cache.monitor->features;
} else {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("Unsupported resctrl monitor type"));
return -1;
}
if (virStringListLength((const char * const *)features) == 0)
return 0;
for (i = 0; i < dom->def->nresctrls; i++) {
resctrl = dom->def->resctrls[i];
......@@ -20763,9 +20780,8 @@ qemuDomainGetResctrlMonData(virDomainObjPtr dom,
if (VIR_STRDUP(res->name, virResctrlMonitorGetID(monitor)) < 0)
goto error;
if (virResctrlMonitorGetCacheOccupancy(monitor,
&res->stats,
&res->nstats) < 0)
if (virResctrlMonitorGetStats(monitor, (const char **)features,
&res->stats, &res->nstats) < 0)
goto error;
if (VIR_APPEND_ELEMENT(*resdata, *nresdata, res) < 0)
......@@ -20782,7 +20798,8 @@ qemuDomainGetResctrlMonData(virDomainObjPtr dom,
static int
qemuDomainGetStatsCpuCache(virDomainObjPtr dom,
qemuDomainGetStatsCpuCache(virQEMUDriverPtr driver,
virDomainObjPtr dom,
virDomainStatsRecordPtr record,
int *maxparams)
{
......@@ -20796,7 +20813,7 @@ qemuDomainGetStatsCpuCache(virDomainObjPtr dom,
if (!virDomainObjIsActive(dom))
return 0;
if (qemuDomainGetResctrlMonData(dom, &resdata, &nresdata,
if (qemuDomainGetResctrlMonData(driver, dom, &resdata, &nresdata,
VIR_RESCTRL_MONITOR_TYPE_CACHE) < 0)
goto cleanup;
......@@ -20897,7 +20914,7 @@ qemuDomainGetStatsCpuCgroup(virDomainObjPtr dom,
static int
qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
qemuDomainGetStatsCpu(virQEMUDriverPtr driver,
virDomainObjPtr dom,
virDomainStatsRecordPtr record,
int *maxparams,
......@@ -20906,7 +20923,7 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
if (qemuDomainGetStatsCpuCgroup(dom, record, maxparams) < 0)
return -1;
if (qemuDomainGetStatsCpuCache(dom, record, maxparams) < 0)
if (qemuDomainGetStatsCpuCache(driver, dom, record, maxparams) < 0)
return -1;
return 0;
......
......@@ -2669,8 +2669,7 @@ virResctrlMonitorStatsSorter(const void *a,
* virResctrlMonitorGetStats
*
* @monitor: The monitor that the statistic data will be retrieved from.
* @resource: The name for resource name. 'llc_occupancy' for cache resource.
* "mbm_total_bytes" and "mbm_local_bytes" for memory bandwidth resource.
* @resources: A string list for the monitor feature names.
* @stats: Pointer of of virResctrlMonitorStatsPtr array for holding cache or
* memory bandwidth usage data.
* @nstats: A size_t pointer to hold the returned array length of @stats
......@@ -2679,14 +2678,15 @@ virResctrlMonitorStatsSorter(const void *a,
*
* Returns 0 on success, -1 on error.
*/
static int
int
virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
const char *resource,
const char **resources,
virResctrlMonitorStatsPtr **stats,
size_t *nstats)
{
int rv = -1;
int ret = -1;
size_t i = 0;
unsigned int val = 0;
DIR *dirp = NULL;
char *datapath = NULL;
......@@ -2744,21 +2744,23 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
if (virStrToLong_uip(node_id, NULL, 0, &stat->id) < 0)
goto cleanup;
rv = virFileReadValueUint(&val, "%s/%s/%s", datapath,
ent->d_name, resource);
if (rv == -2) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("File '%s/%s/%s' does not exist."),
datapath, ent->d_name, resource);
}
if (rv < 0)
goto cleanup;
for (i = 0; resources[i]; i++) {
rv = virFileReadValueUint(&val, "%s/%s/%s", datapath,
ent->d_name, resources[i]);
if (rv == -2) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("File '%s/%s/%s' does not exist."),
datapath, ent->d_name, resources[i]);
}
if (rv < 0)
goto cleanup;
if (VIR_APPEND_ELEMENT(stat->vals, stat->nvals, val) < 0)
goto cleanup;
if (VIR_APPEND_ELEMENT(stat->vals, stat->nvals, val) < 0)
goto cleanup;
if (virStringListAdd(&stat->features, resource) < 0)
goto cleanup;
if (virStringListAdd(&stat->features, resources[i]) < 0)
goto cleanup;
}
if (VIR_APPEND_ELEMENT(*stats, *nstats, stat) < 0)
goto cleanup;
......@@ -2808,6 +2810,10 @@ virResctrlMonitorGetCacheOccupancy(virResctrlMonitorPtr monitor,
virResctrlMonitorStatsPtr **stats,
size_t *nstats)
{
return virResctrlMonitorGetStats(monitor, "llc_occupancy",
stats, nstats);
int ret = -1;
const char *features[2] = {"llc_occupancy", NULL};
ret = virResctrlMonitorGetStats(monitor, features, stats, nstats);
return ret;
}
......@@ -234,6 +234,12 @@ virResctrlMonitorSetAlloc(virResctrlMonitorPtr monitor,
int
virResctrlMonitorRemove(virResctrlMonitorPtr monitor);
int
virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
const char **resources,
virResctrlMonitorStatsPtr **stats,
size_t *nstats);
int
virResctrlMonitorGetCacheOccupancy(virResctrlMonitorPtr monitor,
virResctrlMonitorStatsPtr **stats,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册