From nobody Mon Feb 9 01:16:29 2026 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=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532758325514541.1975989948565; Fri, 27 Jul 2018 23:12:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EB794E4CA; Sat, 28 Jul 2018 06:12:03 +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 2ADCE5B680; Sat, 28 Jul 2018 06:12:03 +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 C6FA818037F5; Sat, 28 Jul 2018 06:12:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6S6BZEX031634 for ; Sat, 28 Jul 2018 02:11:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE51D16D32; Sat, 28 Jul 2018 06:11:35 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C3CFA19486 for ; Sat, 28 Jul 2018 06:11:35 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BBF43001766 for ; Sat, 28 Jul 2018 06:11:34 +0000 (UTC) Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2018 23:11:34 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by fmsmga008.fm.intel.com with ESMTP; 27 Jul 2018 23:11:32 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,412,1526367600"; d="scan'208";a="58575311" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 13:48:33 +0800 Message-Id: <1532756921-6814-10-git-send-email-bing.niu@intel.com> In-Reply-To: <1532756921-6814-1-git-send-email-bing.niu@intel.com> References: <1532756921-6814-1-git-send-email-bing.niu@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 209 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 28 Jul 2018 06:11:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 28 Jul 2018 06:11:34 +0000 (UTC) for IP:'192.55.52.88' DOMAIN:'mga01.intel.com' HELO:'mga01.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -5.001 (RCVD_IN_DNSWL_HI, SPF_PASS) 192.55.52.88 mga01.intel.com 192.55.52.88 mga01.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [PATCH v2 09/17] util: Introduce virResctrlAllocForeachMemory 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 28 Jul 2018 06:12:04 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Introduce an API that will traverse the memory bandwidth data calling a callback function for each defined bandwidth entry. Signed-off-by: Bing Niu --- src/libvirt_private.syms | 1 + src/util/virresctrl.c | 33 +++++++++++++++++++++++++++++++++ src/util/virresctrl.h | 9 +++++++++ 3 files changed, 43 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bc489cb..cd598f9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2649,6 +2649,7 @@ virResctrlAllocAddPID; virResctrlAllocCreate; virResctrlAllocDeterminePath; virResctrlAllocForeachCache; +virResctrlAllocForeachMemory; virResctrlAllocFormat; virResctrlAllocGetID; virResctrlAllocGetUnused; diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index c22b30f..dc57c89 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -965,6 +965,39 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc, } =20 =20 +/* virResctrlAllocForeachMemory + * @alloc: Pointer to an active allocation + * @cb: Callback function + * @opaque: Opaque data to be passed to @cb + * + * If available, traverse the defined memory bandwidth allocations and + * call the @cb function. + * + * Returns 0 on success, -1 and immediate failure if the @cb has any failu= re. + */ +int +virResctrlAllocForeachMemory(virResctrlAllocPtr alloc, + virResctrlAllocForeachMemoryCallback cb, + void *opaque) +{ + size_t i =3D 0; + virResctrlAllocMemBWPtr mem_bw; + + if (!alloc || !alloc->mem_bw) + return 0; + + mem_bw =3D alloc->mem_bw; + for (i =3D 0; i < mem_bw->nbandwidths; i++) { + if (mem_bw->bandwidths[i]) { + if (cb(i, *mem_bw->bandwidths[i], opaque) < 0) + return -1; + } + } + + return 0; +} + + int virResctrlAllocSetID(virResctrlAllocPtr alloc, const char *id) diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index d657c06..5ea5b27 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -73,6 +73,10 @@ typedef int virResctrlAllocForeachCacheCallback(unsigned= int level, unsigned long long size, void *opaque); =20 +typedef int virResctrlAllocForeachMemoryCallback(unsigned int id, + unsigned int size, + void *opaque); + virResctrlAllocPtr virResctrlAllocNew(void); =20 @@ -92,6 +96,11 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc, void *opaque); =20 int +virResctrlAllocForeachMemory(virResctrlAllocPtr resctrl, + virResctrlAllocForeachMemoryCallback cb, + void *opaque); + +int virResctrlAllocSetID(virResctrlAllocPtr alloc, const char *id); const char * --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list