mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 19:45:21 +00:00
qemu: monitor: Extract qemu cpu id along with other data
Storing of the ID will allow simpler extraction of data present only in query-cpus without the need to call qemuMonitorGetCPUInfo in statistics paths.
This commit is contained in:
parent
2e0d6cdec4
commit
3f71c79768
@ -6318,6 +6318,7 @@ qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
|
|||||||
VIR_FREE(vcpupriv->alias);
|
VIR_FREE(vcpupriv->alias);
|
||||||
VIR_STEAL_PTR(vcpupriv->alias, info[i].alias);
|
VIR_STEAL_PTR(vcpupriv->alias, info[i].alias);
|
||||||
vcpupriv->enable_id = info[i].id;
|
vcpupriv->enable_id = info[i].id;
|
||||||
|
vcpupriv->qemu_id = info[i].qemu_id;
|
||||||
|
|
||||||
if (hotplug && state) {
|
if (hotplug && state) {
|
||||||
vcpu->online = info[i].online;
|
vcpu->online = info[i].online;
|
||||||
|
@ -322,6 +322,7 @@ struct _qemuDomainVcpuPrivate {
|
|||||||
|
|
||||||
pid_t tid; /* vcpu thread id */
|
pid_t tid; /* vcpu thread id */
|
||||||
int enable_id; /* order in which the vcpus were enabled in qemu */
|
int enable_id; /* order in which the vcpus were enabled in qemu */
|
||||||
|
int qemu_id; /* ID reported by qemu as 'CPU' in query-cpus */
|
||||||
char *alias;
|
char *alias;
|
||||||
bool halted;
|
bool halted;
|
||||||
|
|
||||||
|
@ -392,6 +392,7 @@ int qemuMonitorSystemReset(qemuMonitorPtr mon);
|
|||||||
int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);
|
int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);
|
||||||
|
|
||||||
struct qemuMonitorQueryCpusEntry {
|
struct qemuMonitorQueryCpusEntry {
|
||||||
|
int qemu_id; /* id of the cpu as reported by qemu */
|
||||||
pid_t tid;
|
pid_t tid;
|
||||||
char *qom_path;
|
char *qom_path;
|
||||||
bool halted;
|
bool halted;
|
||||||
@ -422,6 +423,7 @@ void qemuMonitorQueryHotpluggableCpusFree(struct qemuMonitorQueryHotpluggableCpu
|
|||||||
struct _qemuMonitorCPUInfo {
|
struct _qemuMonitorCPUInfo {
|
||||||
pid_t tid;
|
pid_t tid;
|
||||||
int id; /* order of enabling of the given cpu */
|
int id; /* order of enabling of the given cpu */
|
||||||
|
int qemu_id; /* identifier of the cpu as reported by query-cpus */
|
||||||
|
|
||||||
/* state data */
|
/* state data */
|
||||||
bool online;
|
bool online;
|
||||||
|
@ -1344,6 +1344,7 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
|
|||||||
|
|
||||||
for (i = 0; i < ncpus; i++) {
|
for (i = 0; i < ncpus; i++) {
|
||||||
virJSONValuePtr entry = virJSONValueArrayGet(data, i);
|
virJSONValuePtr entry = virJSONValueArrayGet(data, i);
|
||||||
|
int cpuid = -1;
|
||||||
int thread = 0;
|
int thread = 0;
|
||||||
bool halted = false;
|
bool halted = false;
|
||||||
const char *qom_path;
|
const char *qom_path;
|
||||||
@ -1354,10 +1355,12 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
|
|||||||
|
|
||||||
/* Some older qemu versions don't report the thread_id so treat this as
|
/* Some older qemu versions don't report the thread_id so treat this as
|
||||||
* non-fatal, simply returning no data */
|
* non-fatal, simply returning no data */
|
||||||
|
ignore_value(virJSONValueObjectGetNumberInt(entry, "CPU", &cpuid));
|
||||||
ignore_value(virJSONValueObjectGetNumberInt(entry, "thread_id", &thread));
|
ignore_value(virJSONValueObjectGetNumberInt(entry, "thread_id", &thread));
|
||||||
ignore_value(virJSONValueObjectGetBoolean(entry, "halted", &halted));
|
ignore_value(virJSONValueObjectGetBoolean(entry, "halted", &halted));
|
||||||
qom_path = virJSONValueObjectGetString(entry, "qom_path");
|
qom_path = virJSONValueObjectGetString(entry, "qom_path");
|
||||||
|
|
||||||
|
cpus[i].qemu_id = cpuid;
|
||||||
cpus[i].tid = thread;
|
cpus[i].tid = thread;
|
||||||
cpus[i].halted = halted;
|
cpus[i].halted = halted;
|
||||||
if (VIR_STRDUP(cpus[i].qom_path, qom_path) < 0)
|
if (VIR_STRDUP(cpus[i].qom_path, qom_path) < 0)
|
||||||
|
@ -528,8 +528,18 @@ qemuMonitorTextQueryCPUs(qemuMonitorPtr mon,
|
|||||||
do {
|
do {
|
||||||
char *offset = NULL;
|
char *offset = NULL;
|
||||||
char *end = NULL;
|
char *end = NULL;
|
||||||
|
int cpuid = -1;
|
||||||
int tid = 0;
|
int tid = 0;
|
||||||
|
|
||||||
|
/* extract cpu number */
|
||||||
|
if ((offset = strstr(line, "#")) == NULL)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virStrToLong_i(offset + strlen("#"), &end, 10, &cpuid) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
if (end == NULL || *end != ':')
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
/* Extract host Thread ID */
|
/* Extract host Thread ID */
|
||||||
if ((offset = strstr(line, "thread_id=")) == NULL)
|
if ((offset = strstr(line, "thread_id=")) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -539,6 +549,7 @@ qemuMonitorTextQueryCPUs(qemuMonitorPtr mon,
|
|||||||
if (end == NULL || !c_isspace(*end))
|
if (end == NULL || !c_isspace(*end))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
cpu.qemu_id = cpuid;
|
||||||
cpu.tid = tid;
|
cpu.tid = tid;
|
||||||
|
|
||||||
/* Extract halted indicator */
|
/* Extract halted indicator */
|
||||||
|
@ -1338,10 +1338,10 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
struct qemuMonitorQueryCpusEntry *cpudata = NULL;
|
struct qemuMonitorQueryCpusEntry *cpudata = NULL;
|
||||||
struct qemuMonitorQueryCpusEntry expect[] = {
|
struct qemuMonitorQueryCpusEntry expect[] = {
|
||||||
{17622, (char *) "/machine/unattached/device[0]", true},
|
{0, 17622, (char *) "/machine/unattached/device[0]", true},
|
||||||
{17624, (char *) "/machine/unattached/device[1]", true},
|
{1, 17624, (char *) "/machine/unattached/device[1]", true},
|
||||||
{17626, (char *) "/machine/unattached/device[2]", true},
|
{2, 17626, (char *) "/machine/unattached/device[2]", true},
|
||||||
{17628, NULL, true},
|
{3, 17628, NULL, true},
|
||||||
};
|
};
|
||||||
size_t ncpudata = 0;
|
size_t ncpudata = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
Loading…
Reference in New Issue
Block a user