mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
Add a new function vshPrintPinInfo.
This is a helper function to print vcpu pin info.
This commit is contained in:
parent
ca5c99aecb
commit
272570dffb
@ -4577,6 +4577,45 @@ static const vshCmdOptDef opts_vcpupin[] = {
|
|||||||
{NULL, 0, 0, NULL}
|
{NULL, 0, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper function to print vcpupin info.
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
vshPrintPinInfo(unsigned char *cpumaps, size_t cpumaplen,
|
||||||
|
int maxcpu, int vcpuindex)
|
||||||
|
{
|
||||||
|
int cpu, lastcpu;
|
||||||
|
bool bit, lastbit, isInvert;
|
||||||
|
|
||||||
|
if (!cpumaps || cpumaplen <= 0 || maxcpu <= 0 || vcpuindex < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bit = lastbit = isInvert = false;
|
||||||
|
lastcpu = -1;
|
||||||
|
|
||||||
|
for (cpu = 0; cpu < maxcpu; cpu++) {
|
||||||
|
bit = VIR_CPU_USABLE(cpumaps, cpumaplen, vcpuindex, cpu);
|
||||||
|
|
||||||
|
isInvert = (bit ^ lastbit);
|
||||||
|
if (bit && isInvert) {
|
||||||
|
if (lastcpu == -1)
|
||||||
|
vshPrint(ctl, "%d", cpu);
|
||||||
|
else
|
||||||
|
vshPrint(ctl, ",%d", cpu);
|
||||||
|
lastcpu = cpu;
|
||||||
|
}
|
||||||
|
if (!bit && isInvert && lastcpu != cpu - 1)
|
||||||
|
vshPrint(ctl, "-%d", cpu - 1);
|
||||||
|
lastbit = bit;
|
||||||
|
}
|
||||||
|
if (bit && !isInvert) {
|
||||||
|
vshPrint(ctl, "-%d", maxcpu - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
||||||
{
|
{
|
||||||
@ -4589,7 +4628,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
unsigned char *cpumap = NULL;
|
unsigned char *cpumap = NULL;
|
||||||
unsigned char *cpumaps = NULL;
|
unsigned char *cpumaps = NULL;
|
||||||
size_t cpumaplen;
|
size_t cpumaplen;
|
||||||
bool bit, lastbit, isInvert;
|
|
||||||
int i, cpu, lastcpu, maxcpu, ncpus;
|
int i, cpu, lastcpu, maxcpu, ncpus;
|
||||||
bool unuse = false;
|
bool unuse = false;
|
||||||
const char *cur;
|
const char *cur;
|
||||||
@ -4674,30 +4712,11 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vcpu != -1 && i != vcpu)
|
if (vcpu != -1 && i != vcpu)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bit = lastbit = isInvert = false;
|
|
||||||
lastcpu = -1;
|
|
||||||
|
|
||||||
vshPrint(ctl, "%4d: ", i);
|
vshPrint(ctl, "%4d: ", i);
|
||||||
for (cpu = 0; cpu < maxcpu; cpu++) {
|
ret = vshPrintPinInfo(cpumaps, cpumaplen, maxcpu, i);
|
||||||
|
|
||||||
bit = VIR_CPU_USABLE(cpumaps, cpumaplen, i, cpu);
|
|
||||||
|
|
||||||
isInvert = (bit ^ lastbit);
|
|
||||||
if (bit && isInvert) {
|
|
||||||
if (lastcpu == -1)
|
|
||||||
vshPrint(ctl, "%d", cpu);
|
|
||||||
else
|
|
||||||
vshPrint(ctl, ",%d", cpu);
|
|
||||||
lastcpu = cpu;
|
|
||||||
}
|
|
||||||
if (!bit && isInvert && lastcpu != cpu - 1)
|
|
||||||
vshPrint(ctl, "-%d", cpu - 1);
|
|
||||||
lastbit = bit;
|
|
||||||
}
|
|
||||||
if (bit && !isInvert) {
|
|
||||||
vshPrint(ctl, "-%d", maxcpu - 1);
|
|
||||||
}
|
|
||||||
vshPrint(ctl, "\n");
|
vshPrint(ctl, "\n");
|
||||||
|
if (!ret)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user