From nobody Wed May 14 03:46:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152837968656619.467781061039545; Thu, 7 Jun 2018 06:54:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1ED993082136; Thu, 7 Jun 2018 13:54:45 +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 CFA992007FE0; Thu, 7 Jun 2018 13:54:44 +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 429E7180BA82; Thu, 7 Jun 2018 13:54:44 +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 w57DsaIS000452 for ; Thu, 7 Jun 2018 09:54:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4303C2035725; Thu, 7 Jun 2018 13:54:36 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 201FA2035721 for ; Thu, 7 Jun 2018 13:54:36 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 3301B120072 for ; Thu, 7 Jun 2018 15:54:33 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:30 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/10] util: Remove cbm_mask from virResctrlInfoPerType 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 07 Jun 2018 13:54:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It was used just temporarily to do a calculation, no need to keep that arou= nd. Also use virBitmap in the code instead of reimplementing two of its existing functions. And move the counting part next to where the value is read. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/util/virresctrl.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 481577bbb9f6..2b72a3b36bae 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -24,8 +24,6 @@ #include =20 #include "virresctrlpriv.h" -#include "c-ctype.h" -#include "count-one-bits.h" #include "viralloc.h" #include "virfile.h" #include "virlog.h" @@ -97,7 +95,6 @@ static virClassPtr virResctrlAllocClass; /* virResctrlInfo */ struct _virResctrlInfoPerType { /* Kernel-provided information */ - char *cbm_mask; unsigned int min_cbm_bits; =20 /* Our computed information from the above */ @@ -142,11 +139,8 @@ virResctrlInfoDispose(void *obj) continue; =20 if (level->types) { - for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) { - if (level->types[j]) - VIR_FREE(level->types[j]->cbm_mask); + for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) VIR_FREE(level->types[j]); - } } VIR_FREE(level->types); VIR_FREE(level); @@ -334,6 +328,7 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) int type =3D 0; struct dirent *ent =3D NULL; unsigned int level =3D 0; + virBitmapPtr tmp_map =3D NULL; virResctrlInfoPerLevelPtr i_level =3D NULL; virResctrlInfoPerTypePtr i_type =3D NULL; =20 @@ -378,7 +373,7 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) goto cleanup; } =20 - rv =3D virFileReadValueString(&i_type->cbm_mask, + rv =3D virFileReadValueString(&tmp_str, SYSFS_RESCTRL_PATH "/info/%s/cbm_mask", ent->d_name); @@ -393,7 +388,19 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) if (rv < 0) goto cleanup; =20 - virStringTrimOptionalNewline(i_type->cbm_mask); + virStringTrimOptionalNewline(tmp_str); + + tmp_map =3D virBitmapNewString(tmp_str); + VIR_FREE(tmp_str); + if (!tmp_map) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse cbm_mask from resctrl cache inf= o")); + goto cleanup; + } + + i_type->bits =3D virBitmapCountBits(tmp_map); + virBitmapFree(tmp_map); + tmp_map =3D NULL; =20 rv =3D virFileReadValueUint(&i_type->min_cbm_bits, SYSFS_RESCTRL_PATH "/info/%s/min_cbm_bit= s", @@ -431,24 +438,12 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) goto cleanup; } =20 - for (tmp_str =3D i_type->cbm_mask; *tmp_str !=3D '\0'; tmp_str++) { - if (!c_isxdigit(*tmp_str)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse cbm_mask from resctrl cache= info")); - goto cleanup; - } - - i_type->bits +=3D count_one_bits(virHexToBin(*tmp_str)); - } - VIR_STEAL_PTR(i_level->types[type], i_type); } =20 ret =3D 0; cleanup: VIR_DIR_CLOSE(dirp); - if (i_type) - VIR_FREE(i_type->cbm_mask); VIR_FREE(i_type); return ret; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list