From nobody Tue Nov 26 09:42:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1581975026155228.58734376346592; Mon, 17 Feb 2020 13:30:26 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-365-gbqmqmnxPS63D4BF0RhOwQ-1; Mon, 17 Feb 2020 16:30:20 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C6738017DF; Mon, 17 Feb 2020 21:30:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DBA458B55D; Mon, 17 Feb 2020 21:30:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 828A8180887A; Mon, 17 Feb 2020 21:30:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01HLTc4Z032004 for ; Mon, 17 Feb 2020 16:29:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id A375F2166B2A; Mon, 17 Feb 2020 21:29:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F35C2166B27 for ; Mon, 17 Feb 2020 21:29:38 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 852E2900844 for ; Mon, 17 Feb 2020 21:29:38 +0000 (UTC) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-419-3NgwwkvlPki9ZeGVUHUacg-1; Mon, 17 Feb 2020 16:29:34 -0500 Received: by mail-qk1-f196.google.com with SMTP id o28so16256481qkj.9; Mon, 17 Feb 2020 13:29:34 -0800 (PST) Received: from rekt.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id i7sm872284qki.83.2020.02.17.13.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:29:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581975025; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ySyM0t+4MgRf9rcFPrQ8tebUBkBV/CKDtL1kbGAV8v4=; b=aOzpIfJuxKnJRagv8z1hq4ENqjEOT7K1JqcMb7NLgsAf+fe2g6nVr60GjhNpEAXegKjPsn 4Ees7EUZ5HGwpFafY5k/wcqsHS7zo5TKq9VSqbLvFI5nQxrImeJ8Jq1+lck7sTILkpMWow /CBHysDzD45tsWgSSk6TavSMzOtocqs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZbEFjeF9eWNoGNeJXO5J9Dk8wFwp7h/XvaIBNMEUTZ0=; b=MBljEVYUMGKsVL5HqMvt6p/b8PdbEuXzHALl6S0JCy1rgw69TbBDXI6SilKZzLfxDC EeeOhqTJNlt2QL1cnz+HjPHYU2cdgAFEFBjxJJwojWha/4fqht0jjfoxyrZ1FQla6Eai bLzGkEYVd/MIwtbmI6L3LdrZQKM7YFSfYSdLkUEVmLcOu54WnhaMH7H6AoVaPh1f87zX R61G9xfSbC9A2s/hLFE4U7bwtm4l9UR1g3IY/AhK/Mir7XJ445DRObcYhJro7KxSsyFg A2V4UuKPjLEXAbAw9usm1qAqYgIBbERBpG1czYZnJu3qC+HR6S4zJvaAaKbeQwV3CtX+ fPnQ== X-Gm-Message-State: APjAAAWiA5t/g59MUTlrI7Z0ek/oOO2Pt8RorvWaqY3l+L0MkA0qeaaG cdH89TBvZ5RRbhSe3nB38qylVxeR/cs= X-Google-Smtp-Source: APXvYqzpJJe7xWwRE5lyAi8QSDrazxdcKSefB9vo3qTnbR5HNZE3WyGf3KyqGHvmQlqlzIhIQgSTvQ== X-Received: by 2002:a37:aa8c:: with SMTP id t134mr15799415qke.243.1581974973695; Mon, 17 Feb 2020 13:29:33 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 07/14] vircgroup.c: add virCgroupSetupCpuShares() Date: Mon, 17 Feb 2020 16:29:14 -0500 Message-Id: <20200217212921.251616-8-danielhb413@gmail.com> In-Reply-To: <20200217212921.251616-1-danielhb413@gmail.com> References: <20200217212921.251616-1-danielhb413@gmail.com> MIME-Version: 1.0 X-MC-Unique: 3NgwwkvlPki9ZeGVUHUacg-1 X-MC-Unique: gbqmqmnxPS63D4BF0RhOwQ-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01HLTc4Z032004 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com, crobinso@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The code that calls virCgroupSetCpuShares() and virCgroupGetCpuShares() is repeated in 4 different places. Let's put it in a new virCgroupSetupCpuShares() to avoid code repetition. There's a reason of why we execute a Get in the same value we just executed Set, explained in detail by commit 97814d8ab3. Let's add a gist of the reasoning behind it as a comment in this new function as well. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/lxc/lxc_cgroup.c | 5 +---- src/lxc/lxc_driver.c | 6 ++---- src/qemu/qemu_cgroup.c | 5 ++--- src/qemu/qemu_driver.c | 5 +---- src/util/vircgroup.c | 20 ++++++++++++++++++++ src/util/vircgroup.h | 2 ++ 7 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a58a5ed78b..8be5fe7d9f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1731,6 +1731,7 @@ virCgroupSetupBlkioDeviceWeight; virCgroupSetupBlkioDeviceWriteBps; virCgroupSetupBlkioDeviceWriteIops; virCgroupSetupCpusetCpus; +virCgroupSetupCpuShares; virCgroupSupportsCpuBW; virCgroupTerminateMachine; =20 diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 618063bf43..4c8464bd97 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -40,10 +40,7 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def, { if (def->cputune.sharesSpecified) { unsigned long long val; - if (virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0) - return -1; - - if (virCgroupGetCpuShares(cgroup, &val) < 0) + if (virCgroupSetupCpuShares(cgroup, def->cputune.shares, &val) < 0) return -1; def->cputune.shares =3D val; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 439cc317c6..e66aa7b8f5 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1959,10 +1959,8 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr do= m, if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) { if (def) { unsigned long long val; - if (virCgroupSetCpuShares(priv->cgroup, params[i].value.ul= ) < 0) - goto endjob; - - if (virCgroupGetCpuShares(priv->cgroup, &val) < 0) + if (virCgroupSetupCpuShares(priv->cgroup, params[i].value.= ul, + &val) < 0) goto endjob; =20 def->cputune.shares =3D val; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index ee08b99064..f969469931 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -894,11 +894,10 @@ qemuSetupCpuCgroup(virDomainObjPtr vm) =20 if (vm->def->cputune.sharesSpecified) { unsigned long long val; - if (virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) <= 0) + if (virCgroupSetupCpuShares(priv->cgroup, vm->def->cputune.shares, + &val) < 0) return -1; =20 - if (virCgroupGetCpuShares(priv->cgroup, &val) < 0) - return -1; if (vm->def->cputune.shares !=3D val) { vm->def->cputune.shares =3D val; if (virTypedParamsAddULLong(&eventParams, &eventNparams, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c1a79dcda6..e9feb50220 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10648,10 +10648,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr= dom, if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) { if (def) { unsigned long long val; - if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0) - goto endjob; - - if (virCgroupGetCpuShares(priv->cgroup, &val) < 0) + if (virCgroupSetupCpuShares(priv->cgroup, value_ul, &val) = < 0) goto endjob; =20 def->cputune.shares =3D val; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index dcbd55c0f1..a1093e410d 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3681,3 +3681,23 @@ virCgroupSetupCpusetCpus(virCgroupPtr cgroup, virBit= mapPtr cpumask) =20 return 0; } + + +/* Per commit 97814d8ab3, the Linux kernel can consider a 'shares' + * value of '0' and '1' as 2, and any value larger than a maximum + * is reduced to maximum. + * + * The 'realValue' pointer holds the actual 'shares' value set by + * the kernel if the function returned success. */ +int +virCgroupSetupCpuShares(virCgroupPtr cgroup, unsigned long long shares, + unsigned long long *realValue) +{ + if (virCgroupSetCpuShares(cgroup, shares) < 0) + return -1; + + if (virCgroupGetCpuShares(cgroup, realValue) < 0) + return -1; + + return 0; +} diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 55132dedb6..305d5c9853 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -222,6 +222,8 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group, =20 int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares); int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares); +int virCgroupSetupCpuShares(virCgroupPtr cgroup, unsigned long long shares, + unsigned long long *realValue); =20 int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_pe= riod); int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_p= eriod); --=20 2.24.1