From nobody Tue Feb 10 09:57:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=edu.unito.it ARC-Seal: i=1; a=rsa-sha256; t=1659374696; cv=none; d=zohomail.com; s=zohoarc; b=GPsHNb0lo/jgp3gq72l1oocK3RhbB8OZk3Bx9hXqu+zdfpuJb20oXqhTyVWJvCuIjYGSYieDQtEV7vAKOr3cRawPlfl7k5RRJn7e+JKDQ3cZDk7KQ04PQPXq8ChcFMkuNAKgzuYzdQswX9yDmWF8oQMHmt1GkFbJA+/IQ0UG8y8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659374696; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ndq0n6mEEoCxzK0i+2vgXLdThjSXTayofTKBNVpxo7g=; b=S+MyD3udUG8h3+4aIzxxsoU93V7s65jHsiVaa/VN46LHL+dFVA4kcSY3VMSZ8rpwIVOGSoIvv9uQKouMY2HdIeGBf+R1RZh9OHFA2BaToO4/QSP8Mn3OrA1JXQCkSOiYazhC3VUWzLAqNfyrevhiAGt9dmSut7liEiZvI8BV1sg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1659374696314491.2038045975637; Mon, 1 Aug 2022 10:24:56 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-104-XEMtkbcDNRG-ur7UBYC0yg-1; Mon, 01 Aug 2022 13:24:53 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9CCCF2813D27; Mon, 1 Aug 2022 17:24:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 832A340CFD0E; Mon, 1 Aug 2022 17:24:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A1CB01946A50; Mon, 1 Aug 2022 17:24:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5590A1946A40 for ; Mon, 1 Aug 2022 17:12:34 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 4640D492CA2; Mon, 1 Aug 2022 17:12:34 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast09.extmail.prod.ext.rdu2.redhat.com [10.11.55.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 42714492C3B for ; Mon, 1 Aug 2022 17:12:34 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2655E2999B25 for ; Mon, 1 Aug 2022 17:12:34 +0000 (UTC) Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-398-EtVY2GafOkqYQqbs4vL53w-1; Mon, 01 Aug 2022 13:12:32 -0400 Received: by mail-ed1-f65.google.com with SMTP id z18so14593974edb.10 for ; Mon, 01 Aug 2022 10:12:32 -0700 (PDT) Received: from localhost.localdomain (host-82-54-212-97.retail.telecomitalia.it. [82.54.212.97]) by smtp.gmail.com with ESMTPSA id f5-20020a170906c08500b0072b36cbcdaasm5387863ejz.92.2022.08.01.10.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 10:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659374695; 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=ndq0n6mEEoCxzK0i+2vgXLdThjSXTayofTKBNVpxo7g=; b=eHS7/oCfbpZK2814MtLGVQQDwMtFjqu0CRu2wUfhdneote2ZLUwx8bKnffmZQi/1rHxOn3 XPVB6sktI7Q/HLxpcOC+GgqxX8KT9kn+0hPNjG4DUJO553B+EwTnroLUltCya8izf+FB0X VN2cGRv6FSyGuAp+XEivSzoVWMePF7w= X-MC-Unique: XEMtkbcDNRG-ur7UBYC0yg-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: EtVY2GafOkqYQqbs4vL53w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ndq0n6mEEoCxzK0i+2vgXLdThjSXTayofTKBNVpxo7g=; b=Gc7fj8jJ8GyH9MCmSefyXvcy2zTMHnsYSs81gD3K/jrqEZ68EG3AE1Fo9CRFpWAtei dHrxHHD8x5ONbxrE3YNcWbt9wltV14zVIvKivNDsXnHTDWSbQrzuUssAqdFt3BFLrQNI M+JD/8cX5TLk0+eB/N7WVdHv3uBiOaJs832PrPpynA1ABpmDJ9yK37igkwd4oiUhC/WR W01Rlf0ajpaoNaeKHNsm8zfHTbpz07fF6c9qaHsnEJdwfs2SDP5eV6PaxWkmZJgy4vip qvCZwRqN9EoESyOuIa2LPu5WSm8dL/EV0prFEdbMMHy8digfO+ir56IFz0qBAnspxwhO dt/g== X-Gm-Message-State: AJIora99C0H8c2O/eq20Pg3ejn0zNJ9gTngqBWWAGGbSUK0wy7rzglVx JU4BW6xZWknbGMbtBR+eUYCsB7AQu2Iqfj3w1uE7OHBblI+9zuH2oOYu/L7LBYkwxxiWHJZot/9 QHsjR9RHR+t6PrA/FS4Z4y100yCN5IJHwYkWmT5nzEptSyN5iy0Hci3+LyPoKFwoKalO++fwzbN mxUMIZ X-Google-Smtp-Source: AGRyM1vVm1Zrkx9GI2ujDM20sO7eOIGBEDO3wFjEeCECAJce3sqMOqqhmJduDsCLGkVxh4qJbJb47g== X-Received: by 2002:a05:6402:484:b0:43b:6e02:71af with SMTP id k4-20020a056402048400b0043b6e0271afmr17130160edv.176.1659373951079; Mon, 01 Aug 2022 10:12:31 -0700 (PDT) From: Sasha Algisi To: libvir-list@redhat.com Subject: [PATCH 2/3] virprocess: add the SCHED_DEADLINE scheduling policy Date: Mon, 1 Aug 2022 19:11:45 +0200 Message-Id: <20220801171146.4413-3-sasha.algisi@edu.unito.it> In-Reply-To: <20220801171146.4413-1-sasha.algisi@edu.unito.it> References: <20220801171146.4413-1-sasha.algisi@edu.unito.it> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mailman-Approved-At: Mon, 01 Aug 2022 17:24:48 +0000 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Algisi , Dario Faggioli Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1659374698970100001 Content-Type: text/plain; charset="utf-8" Tasks associated to virtual CPUs, IO Threads and Emulator processes can be created with the SCHED_DEADLINE policy. The policy is described in details here: https://docs.kernel.org/scheduler/sched-deadline.html It requires the following parameters (all in nanoseconds): 1) runtime 2) deadline 3) period It must always holds that: runtime <=3D deadline <=3D period. The kernel enforces that the values stay within [1024, 2^63-1]. Note, however, that a smaller range could be set (or be already set by default) via sysctl (see kernel.sched_deadline_period_max_us and kernel.sched_deadline_period_min_us). All the three parameters are mandatory but period can be set to 0, in which case it will set to the same value of deadline. Signed-off-by: Sasha Algisi Signed-off-by: Dario Faggioli --- src/ch/ch_process.c | 3 +- src/conf/domain_conf.h | 3 ++ src/qemu/qemu_process.c | 8 +++- src/util/virprocess.c | 84 +++++++++++++++++++++++++++++++++++++++-- src/util/virprocess.h | 6 ++- 5 files changed, 97 insertions(+), 7 deletions(-) diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 77f55e777b..a40d188aac 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -293,7 +293,8 @@ virCHProcessSetupPid(virDomainObj *vm, /* Set scheduler type and priority, but not for the main thread. */ if (sched && nameval !=3D VIR_CGROUP_THREAD_EMULATOR && - virProcessSetScheduler(pid, sched->policy, sched->priority) < 0) + virProcessSetScheduler(pid, sched->policy, sched->priority, + sched->runtime, sched->deadline, sched->per= iod) < 0) goto cleanup; =20 ret =3D 0; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 060c395943..c3d1a1b65d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2454,6 +2454,9 @@ typedef enum { struct _virDomainThreadSchedParam { virProcessSchedPolicy policy; int priority; + uint64_t runtime; + uint64_t deadline; + uint64_t period; }; =20 struct _virDomainTimerCatchupDef { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 137dcf5cf4..7586e0538a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2728,7 +2728,8 @@ qemuProcessSetupPid(virDomainObj *vm, /* Set scheduler type and priority, but not for the main thread. */ if (sched && nameval !=3D VIR_CGROUP_THREAD_EMULATOR && - virProcessSetScheduler(pid, sched->policy, sched->priority) < 0) + virProcessSetScheduler(pid, sched->policy, sched->priority, + sched->runtime, sched->deadline, sched->per= iod) < 0) goto cleanup; =20 ret =3D 0; @@ -7813,7 +7814,10 @@ qemuProcessLaunch(virConnectPtr conn, if (vm->def->cputune.emulatorsched && virProcessSetScheduler(vm->pid, vm->def->cputune.emulatorsched->policy, - vm->def->cputune.emulatorsched->priority) <= 0) + vm->def->cputune.emulatorsched->priority, + vm->def->cputune.emulatorsched->runtime, + vm->def->cputune.emulatorsched->deadline, + vm->def->cputune.emulatorsched->period) < 0) goto cleanup; =20 VIR_DEBUG("Setting any required VM passwords"); diff --git a/src/util/virprocess.c b/src/util/virprocess.c index a8f86784e1..c96bfc45fd 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -84,6 +84,7 @@ VIR_ENUM_IMPL(virProcessSchedPolicy, "idle", "fifo", "rr", + "deadline", ); =20 =20 @@ -1610,6 +1611,13 @@ virProcessSchedTranslatePolicy(virProcessSchedPolicy= policy) case VIR_PROC_POLICY_RR: return SCHED_RR; =20 + case VIR_PROC_POLICY_DEADLINE: +# ifdef SCHED_DEADLINE + return SCHED_DEADLINE; +# else + return -1; +# endif + case VIR_PROC_POLICY_LAST: /* nada */ break; @@ -1621,13 +1629,20 @@ virProcessSchedTranslatePolicy(virProcessSchedPolic= y policy) int virProcessSetScheduler(pid_t pid, virProcessSchedPolicy policy, - int priority) + int priority, + uint64_t runtime G_GNUC_UNUSED, + uint64_t deadline G_GNUC_UNUSED, + uint64_t period G_GNUC_UNUSED) { struct sched_param param =3D {0}; int pol =3D virProcessSchedTranslatePolicy(policy); =20 - VIR_DEBUG("pid=3D%lld, policy=3D%d, priority=3D%u", - (long long) pid, policy, priority); + VIR_DEBUG("pid=3D%lld, policy=3D%d, priority=3D%u, " + "runtime=3D%llu, deadline=3D%llu, period=3D%llu", + (long long) pid, policy, priority, + (unsigned long long) runtime, + (unsigned long long) deadline, + (unsigned long long) period); =20 if (!policy) return 0; @@ -1667,6 +1682,69 @@ virProcessSetScheduler(pid_t pid, param.sched_priority =3D priority; } =20 +# ifdef SCHED_DEADLINE + if (pol =3D=3D SCHED_DEADLINE) { + struct sched_attr attr =3D {0}; + /* + * The range is enforced in the kernel. + * See: https://man7.org/linux/man-pages/man7/sched.7.html + */ + uint64_t min_value =3D 1024; + uint64_t max_value =3D (1ULL << 63) - 1; + + if (runtime < min_value || runtime > max_value) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Scheduler runtime %llu out of range " + "[%llu, %llu]"), + (unsigned long long) runtime, + (unsigned long long) min_value, + (unsigned long long) max_value); + return -1; + } + + if (deadline < runtime || deadline > max_value) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Scheduler deadline %llu out of range " + "[%llu, %llu]"), + (unsigned long long) deadline, + (unsigned long long) runtime, + (unsigned long long) max_value); + return -1; + } + + if ((period < deadline || period > max_value) && period !=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Invalid scheduler period %llu, " + "possible correct values are 0 " + "or [%llu, %llu]"), + (unsigned long long) period, + (unsigned long long) deadline, + (unsigned long long) max_value); + return -1; + } + + attr.size =3D sizeof(attr); + attr.sched_policy =3D pol; + /* + * Setting reset-on-fork is necessary as SCHED_DEADLINE + * tasks cannot fork. See: + * https://docs.kernel.org/scheduler/sched-deadline.html#default-b= ehavior + */ + attr.sched_flags =3D SCHED_FLAG_RESET_ON_FORK; + attr.sched_runtime =3D runtime; + attr.sched_deadline =3D deadline; + attr.sched_period =3D period; + + if (sched_setattr(pid, &attr, 0) =3D=3D 0) { + return 0; + } else { + virReportSystemError(errno, + _("Cannot set scheduler parameters for pi= d %lld"), + (long long) pid); + return -1; + } + } +# endif if (sched_setscheduler(pid, pol, ¶m) < 0) { virReportSystemError(errno, _("Cannot set scheduler parameters for pid %l= ld"), diff --git a/src/util/virprocess.h b/src/util/virprocess.h index 30b6981c73..84fdf00fdf 100644 --- a/src/util/virprocess.h +++ b/src/util/virprocess.h @@ -33,6 +33,7 @@ typedef enum { VIR_PROC_POLICY_IDLE, VIR_PROC_POLICY_FIFO, VIR_PROC_POLICY_RR, + VIR_PROC_POLICY_DEADLINE, =20 VIR_PROC_POLICY_LAST } virProcessSchedPolicy; @@ -116,7 +117,10 @@ int virProcessSetupPrivateMountNS(void); =20 int virProcessSetScheduler(pid_t pid, virProcessSchedPolicy policy, - int priority); + int priority, + uint64_t runtime, + uint64_t deadline, + uint64_t period); =20 GStrv virProcessGetStat(pid_t pid, pid_t tid); =20 --=20 2.37.1 --=20 ------------------------ Indirizzo istituzionale di posta elettronica=20 degli studenti e dei laureati dell'Universit=C3=A0 di TorinoOfficial=C2=A0U= niversity=20 of Turin=C2=A0email address=C2=A0for students and graduates=C2=A0