From nobody Wed May 1 00:41:17 2024 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.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149078081848463.86219234787893; Wed, 29 Mar 2017 02:46:58 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A978115552; Wed, 29 Mar 2017 09:46:56 +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 1F66617ADB; Wed, 29 Mar 2017 09:46:56 +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 E595D18523C6; Wed, 29 Mar 2017 09:46:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2T9gCEK019271 for ; Wed, 29 Mar 2017 05:42:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id DC1ADA09D9; Wed, 29 Mar 2017 09:42:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2051A3A72; Wed, 29 Mar 2017 09:42:11 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 A3D5980469; Wed, 29 Mar 2017 09:42:09 +0000 (UTC) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Mar 2017 02:42:09 -0700 Received: from s2600wt.sh.intel.com ([10.239.48.158]) by orsmga004.jf.intel.com with ESMTP; 29 Mar 2017 02:42:08 -0700 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A978115552 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=intel.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A978115552 Authentication-Results: mx1.redhat.com; dkim=fail reason="key not found in DNS" (0-bit key) header.d=intel.com header.i=@intel.com header.b="rsuoxwzx" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A3D5980469 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=intel.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=liyong.qiao@intel.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A3D5980469 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490780530; x=1522316530; h=from:to:cc:subject:date:message-id; bh=ssP4S/2WoK6fKn2j6/fxRy4/pHfMghIv0j5hLJheF6o=; b=rsuoxwzxL42ldoqc0LxR+RiY1fu+iPHrdoQ9zvrDYQAea7kNdZYgs2gA Wi2Hu1y1dmA6j5jdCilo43/hL4ITLQ==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,240,1486454400"; d="scan'208";a="71541196" From: Eli Qiao To: libvir-list@redhat.com Date: Wed, 29 Mar 2017 17:44:36 +0800 Message-Id: <1490780676-24661-1-git-send-email-liyong.qiao@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 29 Mar 2017 09:42:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 29 Mar 2017 09:42:10 +0000 (UTC) for IP:'192.55.52.120' DOMAIN:'mga04.intel.com' HELO:'mga04.intel.com' FROM:'liyong.qiao@intel.com' RCPT:'' X-RedHat-Spam-Score: -1.792 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, SPF_PASS, T_DKIM_INVALID) 192.55.52.120 mga04.intel.com 192.55.52.120 mga04.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: mkletzan@redhat.com Subject: [libvirt] [PATCH] util: Add more virsysfs functions for handling resctrl sysfs 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 29 Mar 2017 09:46:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Extended /sys/fs/resctrl sysfs handling. Signed-off-by: Eli Qiao --- src/libvirt_private.syms | 4 ++ src/util/virsysfs.c | 98 ++++++++++++++++++++++++++++++++++++++++++++= +++- src/util/virsysfs.h | 15 ++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b551cb8..e07ae79 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2631,6 +2631,10 @@ virSysfsGetValueBitmap; virSysfsGetValueInt; virSysfsGetValueString; virSysfsSetSystemPath; +virSysfsGetResctrlString; +virSysfsGetResctrlUint; +virSysfsGetResctrlInfoString; +virSysfsGetResCtrInfoUint; =20 =20 # util/virsysinfo.h diff --git a/src/util/virsysfs.c b/src/util/virsysfs.c index 7a98b48..d1be289 100644 --- a/src/util/virsysfs.c +++ b/src/util/virsysfs.c @@ -36,8 +36,10 @@ VIR_LOG_INIT("util.sysfs"); =20 #define VIR_SYSFS_VALUE_MAXLEN 8192 #define SYSFS_SYSTEM_PATH "/sys/devices/system" +#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl" =20 static const char *sysfs_system_path =3D SYSFS_SYSTEM_PATH; +static const char *sysfs_resctrl_path =3D SYSFS_RESCTRL_PATH; =20 =20 void virSysfsSetSystemPath(const char *path) @@ -48,13 +50,26 @@ void virSysfsSetSystemPath(const char *path) sysfs_system_path =3D SYSFS_SYSTEM_PATH; } =20 - const char * virSysfsGetSystemPath(void) { return sysfs_system_path; } =20 +void virSysfsSetResctrlPath(const char *path) +{ + if (path) + sysfs_resctrl_path =3D path; + else + sysfs_resctrl_path =3D SYSFS_RESCTRL_PATH; +} + +const char * +virSysfsGetResctrlPath(void) +{ + return sysfs_resctrl_path; +} + int virSysfsGetValueInt(const char *file, int *value) @@ -227,3 +242,84 @@ virSysfsGetNodeValueBitmap(unsigned int node, VIR_FREE(path); return ret; } + +int +virSysfsGetResctrlString(const char* file, + char **value) +{ + chat *path =3D NULL; + int ret =3D -1; + if (virAsprintf(&path, "%s/%s", sysfs_resctrl_path, file) < 0) + if (!virFileExists(path)) { + ret =3D -2; + goto cleanup; + } + + if (virFileReadAll(path, VIR_SYSFS_VALUE_MAXLEN, value) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(path); + return ret; +} + +int +virSysfsGetResctrlUint(const char* file, + unsigned int **value) +{ + chat *path =3D NULL; + int ret =3D -1; + if (virAsprintf(&path, "%s/%s", sysfs_resctrl_path, file) < 0) + if (!virFileExists(path)) { + ret =3D -2; + goto cleanup; + } + + ret =3D virFileReadValueUint(path, value); + + cleanup: + VIR_FREE(path); + return ret; +} + +int +virSysfsGetResctrlInfoString(const char* file, + char **value) +{ + chat *path =3D NULL; + int ret =3D -1; + if (virAsprintf(&path, "%s/info/%s", sysfs_resctrl_path, file) < 0) + return -1; + + if (!virFileExists(path)) { + ret =3D -2; + goto cleanup; + } + + if (virFileReadAll(path, VIR_SYSFS_VALUE_MAXLEN, value) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(path); + return ret; +} + +int +virSysfsGetResCtrInfoUint(const char *file, + unsigned int *value) +{ + char *path =3D NULL; + int ret =3D -1; + + if (virAsprintf(&path, "%s/info/%s", sysfs_resctrl_path, file) < 0) + return -1; + + ret =3D virFileReadValueUint(path, value); + + VIR_FREE(path); + return ret; +} diff --git a/src/util/virsysfs.h b/src/util/virsysfs.h index cd871ff..81a27c2 100644 --- a/src/util/virsysfs.h +++ b/src/util/virsysfs.h @@ -67,4 +67,19 @@ virSysfsGetNodeValueBitmap(unsigned int cpu, const char *file, virBitmapPtr *value); =20 +int +virSysfsGetResctrlString(const char* file, + char **value); + +int +virSysfsGetResctrlUint(const char* file, + unsigned int **value); + +int +virSysfsGetResctrlInfoString(const char* file, + char **value); + +int +virSysfsGetResCtrInfoUint(const char *file, + unsigned int *value); #endif /* __VIR_SYSFS_H__*/ --=20 1.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list