Skip to content

Commit

Permalink
acrn-driver: add vCPU info for acrn:cpu_affinity
Browse files Browse the repository at this point in the history
vCPU allocated by `acrn:cpu_affinity` is delivered to acrn-dm
directly, and vCPU preparation processs is bypassed. So add vCPU
info which used to record durring vCPU preparation in this patch:
1. Set vCPU online state of the util configuration (struct virDomainDef).
2. Add the vCPU to allocMap.

Tracked-On: #19
Signed-off-by: Yuanyuan Zhao <[email protected]>
  • Loading branch information
YuanyuanZhao609 authored and liuhang-bit committed May 5, 2022
1 parent c3842b6 commit 1bc03e4
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/acrn/acrn_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,65 @@ acrnSetOnlineVcpus(virDomainDefPtr def, virBitmapPtr vcpus)
return virDomainDefSetVcpus(def, virBitmapCountBits(vcpus));
}

static int
acrnSetVcpuAffinityInfo(virDomainObjPtr vm, size_t *allocMap)
{
virDomainDefPtr def;
acrnDomainObjPrivatePtr priv;
char *src, *token, *str;
int ret = 0, i;
int apicid;

if (!vm || !(def = vm->def))
return -1;

src = acrnGetCpuAffinity(def);

if (VIR_ALLOC_N(str, strlen(src)) < 0) {
virReportError(VIR_ERR_NO_MEMORY, NULL);
ret = -ENOMEM;
goto cleanup;
}
strcpy(str, src);

priv = vm->privateData;
if (priv->cpuAffinitySet)
virBitmapFree(priv->cpuAffinitySet);


if (!(priv->cpuAffinitySet = virBitmapNew(acrn_driver->nodeInfo.cpus))) {
virReportError(VIR_ERR_NO_MEMORY, NULL);
ret = -ENOMEM;
goto cleanup;
}

token = strtok(str, ",");
if (token == NULL) {
ret = -1;
goto cleanup;
}

do {
apicid = atoi(token);
for (i = 0; i < acrn_driver->nodeInfo.cpus; i++) {
if (apicid == acrn_driver->apicidMap[i]) {
allocMap[i] += 1;
virBitmapSetBit(priv->cpuAffinitySet, i);
break;
}
}
} while ((token = strtok(NULL, ",")) != NULL);

if (!virBitmapIsAllClear(priv->cpuAffinitySet)) {
acrnSetOnlineVcpus(def, priv->cpuAffinitySet);
}
cleanup:
if (str) {
free(str);
}
return ret;
}

static int
acrnSetCpumask(virDomainDefPtr def, size_t *allocMap)
{
Expand Down Expand Up @@ -298,6 +357,7 @@ acrnProcessPrepareDomain(virDomainObjPtr vm, size_t *allocMap)
return -1;

if (acrnGetCpuAffinity(def)) {
acrnSetVcpuAffinityInfo(vm, allocMap);
return 0;
}

Expand Down

0 comments on commit 1bc03e4

Please sign in to comment.