From nobody Sun Feb 8 03:33:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1593209493; cv=none; d=zohomail.com; s=zohoarc; b=mIs6Vvx83sjvr+KUcJ/q9g38xccHTMpDbXTe4kQMPafvqKtdaMkkiSOxAOyr3xEVJbjh+fwtSAyseYPvmu1rQl4xBfo1ZX7Sif10YfeG6wL9h0PYvWV7//2oBf0oPG6mAY2cFL+jh3qM05L3pVXPs7ZmjFabACBYOvrHN0P+7P4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593209493; 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=Dwk1q8zU5qgN5Xih1CGdig4KvEQdHCCxv6On2z5sztk=; b=bjLakuijncH6JF0aIgEtn5Y9xZFnMgsxdwQA/Fy9PTzDwXs7gwnsxq6YQIPpR8udxn4FQPGRuXpy/mEuYQPJnsR42n97Ej64HQD1qPOLntmQhqwo3bftIz2/e3z4AKImNfv6mvEeGkpS/ahIBOhxB5/xj2JXK2ChoZxVWb8VDHc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1593209493254343.9691770311397; Fri, 26 Jun 2020 15:11:33 -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-268-ByY4lJJ_MOWqP2X-QABYjQ-1; Fri, 26 Jun 2020 18:11:29 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EAAE3BFD1; Fri, 26 Jun 2020 22:11:19 +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 82E46612BA; Fri, 26 Jun 2020 22:11:19 +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 57418875BF; Fri, 26 Jun 2020 22:11:19 +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 05QMB3wn015694 for ; Fri, 26 Jun 2020 18:11:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6CCE020110C7; Fri, 26 Jun 2020 22:11:03 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 68F6B20182A5 for ; Fri, 26 Jun 2020 22:11:03 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.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 4EE6C8007C8 for ; Fri, 26 Jun 2020 22:11:03 +0000 (UTC) Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-442-HHqihAQSOnC8OkmU2bWexA-1; Fri, 26 Jun 2020 18:11:01 -0400 Received: by mail-qk1-f176.google.com with SMTP id 80so10231458qko.7 for ; Fri, 26 Jun 2020 15:11:00 -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.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 15:10:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593209492; 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=Dwk1q8zU5qgN5Xih1CGdig4KvEQdHCCxv6On2z5sztk=; b=dYIxfako9NcEyaCtFJHSkytiELhF+sVw785drKHE1lFEWPED4owstChjFt1s8Un0UkWcp6 hv9ToIREhJK+YLOX13a4Atek+9c1Nu2z7qXFbEvDJoL2rNKg2vTULzDzo/B1kzuCy+crD6 6ucKjvs3753oomo5GRxkUy7ANNSL3mc= X-MC-Unique: ByY4lJJ_MOWqP2X-QABYjQ-1 X-MC-Unique: HHqihAQSOnC8OkmU2bWexA-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=Dwk1q8zU5qgN5Xih1CGdig4KvEQdHCCxv6On2z5sztk=; b=hPvvJ8Xn45MFAeYnwNQpbMIyHEc/DUsPJv59KjJ3kYdAVmNRTXHzZLcTTvt/YSpTq5 ZvBtThSq2aCr4E7ibB/OQ9rfOMbx4HGgW0n5D+t9TBmJXG6YOd9ykPI8shjt1LDlNm+L 6AYTsfQ4F7HnG1YqooEY+9uvMk8ymkFKH6gI+iCJGGU6I6dL/zl2XlSS18V+mfVIzsC+ f2kjV1tFU2TfqANcXlocVkONele4rrvHPDRR+RW2PD1IZQQiliRKe3LSLArSk8GzInP2 9dvJMX/lC66cjZm2naWESEnCEUKDPNA9T/3nnP5bgEtD+gFGa4ej3KQOL2JK/D8OI2we 4FIQ== X-Gm-Message-State: AOAM532O3wo6eL+j7+r57o9GsEdPTVQQreERrfYzFv0sij7zdmr9uP/3 Bwa+9SMhP1fWZLKmEQntaF/qnnFH X-Google-Smtp-Source: ABdhPJw5wYcCZz8U7H6dIH7LLU3/oHWPZWDm49gjdKbP3qGia4z/2KBjKBeBzmKcyMlDSKPK4AtxpQ== X-Received: by 2002:a05:620a:2282:: with SMTP id o2mr4768193qkh.402.1593209460315; Fri, 26 Jun 2020 15:11:00 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 5/7] virhostcpu.c: refactor virHostCPUParseCountLinux() Date: Fri, 26 Jun 2020 19:10:42 -0300 Message-Id: <20200626221044.631749-6-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.79 on 10.5.11.14 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" This function reads the string in sysfspath/cpu/present and parses it manually to retrieve the number of present CPUs. virHostCPUGetPresentBitmap() reads and parses the same file, using a more robust parser via virBitmapParseUnlimited(), but returns a bitmap. Let's drop all the manual parsing done here and simply return the size of the resulting bitmap from virHostCPUGetPresentBitmap(). Given that no more parsing is being done manually in the function, rename it to virHostCPUCountLinux(). Signed-off-by: Daniel Henrique Barboza --- src/util/virhostcpu.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 3023bca831..615250d05d 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -856,33 +856,17 @@ virHostCPUGetStatsLinux(FILE *procstat, } =20 =20 -/* Determine the number of CPUs (maximum CPU id + 1) from a file containing - * a list of CPU ids, like the Linux sysfs cpu/present file */ +/* Determine the number of CPUs (maximum CPU id + 1) present in + * the host. */ static int -virHostCPUParseCountLinux(void) +virHostCPUCountLinux(void) { - char *str =3D NULL; - char *tmp; - int ret =3D -1; + g_autoptr(virBitmap) present =3D virHostCPUGetPresentBitmap(); =20 - if (virFileReadValueString(&str, "%s/cpu/present", SYSFS_SYSTEM_PATH) = < 0) + if (!present) return -1; =20 - tmp =3D str; - do { - if (virStrToLong_i(tmp, &tmp, 10, &ret) < 0 || - !strchr(",-", *tmp)) { - virReportError(VIR_ERR_NO_SUPPORT, - _("failed to parse %s"), str); - ret =3D -1; - goto cleanup; - } - } while (*tmp++ && *tmp); - ret++; - - cleanup: - VIR_FREE(str); - return ret; + return virBitmapSize(present); } #endif =20 @@ -1031,7 +1015,7 @@ int virHostCPUGetCount(void) { #if defined(__linux__) - return virHostCPUParseCountLinux(); + return virHostCPUCountLinux(); #elif defined(__FreeBSD__) || defined(__APPLE__) return virHostCPUGetCountAppleFreeBSD(); #else --=20 2.26.2