Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:olh:xen-4.11
libvirt-7.0.0
libvirt.bdbd902722152bf436488e88a3ce812e2a1ee05...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File libvirt.bdbd902722152bf436488e88a3ce812e2a1ee05a.patch of Package libvirt-7.0.0
From: Olaf Hering <olaf@aepfle.de> Date: Wed, 5 May 2021 16:06:32 +0200 Subject: bdbd902722152bf436488e88a3ce812e2a1ee05a libxl: set vcpu affinity during domain creation Since Xen 4.5 libxl allows to set affinities during domain creation. This enables Xen to allocate the domain memory on NUMA systems close to the specified pcpus. Libvirt can now handle <domain/cputune/vcpupin> in domU.xml correctly. Without this change, Xen will create the domU and assign NUMA memory and vcpu affinities on its own. Later libvirt will adjust the affinity, which may move the vcpus away from the assigned NUMA node. Signed-off-by: Olaf Hering <olaf@aepfle.de> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Jim Fehlig <jfehlig@suse.com> --- src/libxl/libxl_conf.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/libxl/libxl_domain.c | 46 ---------------------------------------------- src/libxl/libxl_domain.h | 4 ---- 3 files changed, 53 insertions(+), 50 deletions(-) --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -273,24 +273,74 @@ libxlMakeChrdevStr(virDomainChrDefPtr def, char **buf) srcdef->data.nix.listen ? ",server,nowait" : ""); break; default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported chardev '%s'"), type); return -1; } return 0; } +static int +libxlSetVcpuAffinities(virDomainDefPtr def, + libxl_ctx *ctx, + libxl_domain_build_info *b_info) +{ + libxl_bitmap *vcpu_affinity_array; + unsigned int vcpuid; + unsigned int vcpu_idx = 0; + virDomainVcpuDefPtr vcpu; + bool has_vcpu_pin = false; + + /* Get highest vcpuid with cpumask */ + for (vcpuid = 0; vcpuid < b_info->max_vcpus; vcpuid++) { + vcpu = virDomainDefGetVcpu(def, vcpuid); + if (!vcpu) + continue; + if (!vcpu->cpumask) + continue; + vcpu_idx = vcpuid; + has_vcpu_pin = true; + } + /* Nothing to do */ + if (!has_vcpu_pin) + return 0; + + /* Adjust index */ + vcpu_idx++; + + b_info->num_vcpu_hard_affinity = vcpu_idx; + /* Will be released by libxl_domain_config_dispose */ + b_info->vcpu_hard_affinity = g_new0(libxl_bitmap, vcpu_idx); + vcpu_affinity_array = b_info->vcpu_hard_affinity; + + for (vcpuid = 0; vcpuid < vcpu_idx; vcpuid++) { + libxl_bitmap *map = &vcpu_affinity_array[vcpuid]; + libxl_bitmap_init(map); + /* libxl owns the bitmap */ + if (libxl_cpu_bitmap_alloc(ctx, map, 0)) + return -1; + vcpu = virDomainDefGetVcpu(def, vcpuid); + /* Apply the given mask, or allow unhandled vcpus to run anywhere */ + if (vcpu && vcpu->cpumask) + virBitmapToDataBuf(vcpu->cpumask, map->map, map->size); + else + libxl_bitmap_set_any(map); + } + libxl_defbool_set(&b_info->numa_placement, false); + return 0; +} + static int libxlMakeDomBuildInfo(virDomainDefPtr def, libxlDriverConfigPtr cfg, virCapsPtr caps, libxl_domain_config *d_config) { virDomainClockDef clock = def->clock; libxl_ctx *ctx = cfg->ctx; libxl_domain_build_info *b_info = &d_config->b_info; bool hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM; bool pvh = def->os.type == VIR_DOMAIN_OSTYPE_XENPVH; size_t i; @@ -310,24 +360,27 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, #endif } else { libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PV); } b_info->max_vcpus = virDomainDefGetVcpusMax(def); if (libxl_cpu_bitmap_alloc(ctx, &b_info->avail_vcpus, b_info->max_vcpus)) return -1; libxl_bitmap_set_none(&b_info->avail_vcpus); for (i = 0; i < virDomainDefGetVcpus(def); i++) libxl_bitmap_set((&b_info->avail_vcpus), i); + if (libxlSetVcpuAffinities(def, ctx, b_info)) + return -1; + switch ((virDomainClockOffsetType) clock.offset) { case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE: if (clock.data.variable.basis == VIR_DOMAIN_CLOCK_BASIS_LOCALTIME) libxl_defbool_set(&b_info->localtime, true); b_info->rtc_timeoffset = clock.data.variable.adjustment; break; case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: libxl_defbool_set(&b_info->localtime, true); break; /* Nothing to do since UTC is the default in libxl */ --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -959,67 +959,24 @@ libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver, dumpfile = g_strdup_printf("%s/%s-%s", cfg->autoDumpDir, vm->def->name, nowstr); /* Unlock virDomainObj while dumping core */ virObjectUnlock(vm); libxl_domain_core_dump(cfg->ctx, vm->def->id, dumpfile, NULL); virObjectLock(vm); VIR_FREE(dumpfile); return 0; } -int -libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm) -{ - g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver); - virDomainVcpuDefPtr vcpu; - libxl_bitmap map; - virBitmapPtr cpumask = NULL; - size_t i; - int ret = -1; - - libxl_bitmap_init(&map); - - for (i = 0; i < virDomainDefGetVcpus(vm->def); ++i) { - vcpu = virDomainDefGetVcpu(vm->def, i); - - if (!vcpu->online) - continue; - - if (!(cpumask = vcpu->cpumask)) - cpumask = vm->def->cpumask; - - if (!cpumask) - continue; - - if (virBitmapToData(cpumask, &map.map, (int *)&map.size) < 0) - goto cleanup; - - if (libxl_set_vcpuaffinity(cfg->ctx, vm->def->id, i, &map, NULL) != 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to pin vcpu '%zu' with libxenlight"), i); - goto cleanup; - } - - libxl_bitmap_dispose(&map); /* Also returns to freshly-init'd state */ - } - - ret = 0; - - cleanup: - libxl_bitmap_dispose(&map); - return ret; -} - static int libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config) { uint64_t needed_mem; uint64_t free_mem; uint64_t target_mem; int tries = 3; int wait_secs = 10; if (libxlDomainNeedMemoryWrapper(ctx, d_config, &needed_mem) < 0) goto error; @@ -1452,27 +1409,24 @@ libxlDomainStart(libxlDriverPrivatePtr driver, #endif if ((dom_xml = virDomainDefFormat(vm->def, driver->xmlopt, 0)) == NULL) goto destroy_dom; if (libxl_userdata_store(cfg->ctx, domid, "libvirt-xml", (uint8_t *)dom_xml, strlen(dom_xml) + 1)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("libxenlight failed to store userdata")); goto destroy_dom; } - if (libxlDomainSetVcpuAffinities(driver, vm) < 0) - goto destroy_dom; - if (!start_paused) { libxlDomainUnpauseWrapper(cfg->ctx, domid); virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED); } else { virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER); } if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto destroy_dom; if (g_atomic_int_add(&driver->nactive, 1) == 0 && driver->inhibitCallback) driver->inhibitCallback(true, driver->inhibitOpaque); --- a/src/libxl/libxl_domain.h +++ b/src/libxl/libxl_domain.h @@ -127,28 +127,24 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, #else # define VIR_LIBXL_EVENT_CONST const #endif void libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event); int libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver, virDomainObjPtr vm); -int -libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, - virDomainObjPtr vm); - int libxlDomainStartNew(libxlDriverPrivatePtr driver, virDomainObjPtr vm, bool start_paused); int libxlDomainStartRestore(libxlDriverPrivatePtr driver, virDomainObjPtr vm, bool start_paused, int restore_fd, uint32_t restore_ver);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor