From nobody Sun Feb 8 11:25:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1593209484; cv=none; d=zohomail.com; s=zohoarc; b=Ab6boAmIidlbh99YuU6t0uktM68jcRxmIWeslDANToxYZto4kCFcxdm0kMt0biwDG27p4LcjJCWVtHBwDtsRdIQLawsveu4qJaZgtjEhatj6AetZr3XlouWLWzxZRlPdbyrzyj45mbn5QsD7MuaCly4IDNG8GYsige2uHkI/e/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593209484; 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=k5xHGan138AcKXcpqBja9m+giQvmODWGp8LpDevEMIM=; b=KWdsgQ+nZ65zT/HHSxfeLQodU91DtMvtcbvb9cHXludq6Q5P+U3RgT7KcEPCe/NJhxinpeiXZOM3qxJDWoflGyxLlwk+rwx/ZzT2fegYqd9mEfvsbrDgcMSJMvJc+JFbaQd4STyV+W+NIU10CnTGT3Rt5eNgVX2igS1GjZzuk8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1593209484116122.55272633769096; Fri, 26 Jun 2020 15:11:24 -0700 (PDT) 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-273-QicSVuMXO6i0P-qIANhLsw-1; Fri, 26 Jun 2020 18:11:20 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 07A121005513; Fri, 26 Jun 2020 22:11:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8B4119C58; Fri, 26 Jun 2020 22:11:14 +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 AA1F8104903; Fri, 26 Jun 2020 22:11:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05QMB56o015737 for ; Fri, 26 Jun 2020 18:11:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D0F820110C7; Fri, 26 Jun 2020 22:11:05 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78F312029F6F for ; Fri, 26 Jun 2020 22:11:05 +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-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E1BE185A797 for ; Fri, 26 Jun 2020 22:11:05 +0000 (UTC) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-478-sx-etTTKPgC5oP0kevbVJA-1; Fri, 26 Jun 2020 18:11:02 -0400 Received: by mail-qt1-f193.google.com with SMTP id e12so8640374qtr.9 for ; Fri, 26 Jun 2020 15:11:02 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:4951:b792:3278:7364:91bd]) by smtp.gmail.com with ESMTPSA id v10sm7159090qtk.14.2020.06.26.15.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 15:11:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593209482; 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=k5xHGan138AcKXcpqBja9m+giQvmODWGp8LpDevEMIM=; b=Dkf2pvxvKdvEl+NlO482nngwwqJAF7QHrZ0cV5JiZbwJdNanMQeYCq3AfiZMMIVPKUxHN7 7JkAdLBuxe0/vvd+Ge+yfn+T3tUmicSJONOu/SR+9385XbV72ueKGIOML6dZv/qPaKkLMR eFnogmVMHPjdytRX2z6jI40ueH2v7JY= X-MC-Unique: QicSVuMXO6i0P-qIANhLsw-1 X-MC-Unique: sx-etTTKPgC5oP0kevbVJA-1 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=k5xHGan138AcKXcpqBja9m+giQvmODWGp8LpDevEMIM=; b=f5ITnsZHm48Y7YzGnAwCy8SuJgNsc125MrOvLn/zHVSQU8Y36VGSg1qmJrRMm1HP7+ cTS0Zt3eDaxWirzom/BnL1XERQzyqim+TEyxOYmS6a7yA4jxbcPg82iE/nU3kpLncT+n GePa4YnSqRQD0pn/mkK0Grw1Dp3AJZD8FZaj4K5aEFJlHdE+G/XQoA1Qei+KrE5CroaS 0XBwsa7BhzEhs+EPjT5P7OqN2IPoAVOdHnjqOkfqLrveNjsQ0kgcMSaSYsafI/S0tQnJ CZyTKtjll7I+DD8fAIbDpAHZJw30yHRnZsmMLWeIpQKp87Zc3DYg/h//QnZmCGboFUHZ 2sXQ== X-Gm-Message-State: AOAM5303LVbTP8PBT6pD9sVHL9vHge1s1w2id3IsXZqhk8UseOapJD9q HdiCowO5osadkWuRJBU78l0z070p X-Google-Smtp-Source: ABdhPJw+pSt+wQx2QTslSwj51WvYoEzE0fIgg1hsLM0HWQoVP1/ahOal/S+lBgNRR9tLcWXfYARdVw== X-Received: by 2002:ac8:4892:: with SMTP id i18mr5154917qtq.344.1593209461860; Fri, 26 Jun 2020 15:11:01 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 6/7] virhostcpu.c: introduce virHostCPUGetAvailableCPUsBitmap() Date: Fri, 26 Jun 2020 19:10:43 -0300 Message-Id: <20200626221044.631749-7-danielhb413@gmail.com> In-Reply-To: <20200626221044.631749-1-danielhb413@gmail.com> References: <20200626221044.631749-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.84 on 10.5.11.23 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 idea is to have a function that calls virHostCPUGetOnlineBitmap() but, instead of returning NULL if the host does not have CPU offlining capabilities, fall back to a bitmap containing all present CPUs. Next patch will use this helper in two other places. Signed-off-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/util/virhostcpu.c | 30 ++++++++++++++++++++++++++++++ src/util/virhostcpu.h | 2 ++ 3 files changed, 33 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ae0e253ab9..f120e200cb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2211,6 +2211,7 @@ virHookPresent; =20 =20 # util/virhostcpu.h +virHostCPUGetAvailableCPUsBitmap; virHostCPUGetCount; virHostCPUGetInfo; virHostCPUGetKVMMaxVCPUs; diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 615250d05d..8ca67e357d 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -1099,6 +1099,36 @@ virHostCPUGetMap(unsigned char **cpumap, } =20 =20 +/* virHostCPUGetAvailableCPUsBitmap(): + * + * Returns a virBitmap object with all available host CPUs. + * + * This is a glorified wrapper of virHostCPUGetOnlineBitmap() + * that, instead of returning NULL when 'ifndef __linux__' and + * the caller having to handle it outside the function, returns + * a virBitmap with all the possible CPUs in the host, up to + * virHostCPUGetCount(). */ +virBitmapPtr +virHostCPUGetAvailableCPUsBitmap(void) +{ + g_autoptr(virBitmap) bitmap =3D NULL; + + if (!(bitmap =3D virHostCPUGetOnlineBitmap())) { + int hostcpus; + + if ((hostcpus =3D virHostCPUGetCount()) < 0) + return NULL; + + if (!(bitmap =3D virBitmapNew(hostcpus))) + return NULL; + + virBitmapSetAll(bitmap); + } + + return g_steal_pointer(&bitmap); +} + + #if HAVE_LINUX_KVM_H && defined(KVM_CAP_PPC_SMT) =20 /* Get the number of threads per subcore. diff --git a/src/util/virhostcpu.h b/src/util/virhostcpu.h index 48b1431ca4..d07503857e 100644 --- a/src/util/virhostcpu.h +++ b/src/util/virhostcpu.h @@ -43,6 +43,8 @@ int virHostCPUGetStats(int cpuNum, bool virHostCPUHasBitmap(void); virBitmapPtr virHostCPUGetPresentBitmap(void); virBitmapPtr virHostCPUGetOnlineBitmap(void); +virBitmapPtr virHostCPUGetAvailableCPUsBitmap(void); + int virHostCPUGetCount(void); int virHostCPUGetThreadsPerSubcore(virArch arch) G_GNUC_NO_INLINE; =20 --=20 2.26.2