From nobody Wed May 1 19:00:32 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 1491902746769262.6856446049288; Tue, 11 Apr 2017 02:25:46 -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 1C49E7E9DB; Tue, 11 Apr 2017 09:25:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8A2218EC3; Tue, 11 Apr 2017 09:25: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 8C8055EC65; Tue, 11 Apr 2017 09:25:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3B9PhQj012949 for ; Tue, 11 Apr 2017 05:25:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 63A63189AA; Tue, 11 Apr 2017 09:25:43 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59AEF80691; Tue, 11 Apr 2017 09:25:41 +0000 (UTC) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 8E3F319CF90; Tue, 11 Apr 2017 09:25:39 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP; 11 Apr 2017 02:25:39 -0700 Received: from s2600wt.sh.intel.com ([10.239.48.158]) by fmsmga002.fm.intel.com with ESMTP; 11 Apr 2017 02:25:38 -0700 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1C49E7E9DB Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=intel.com Authentication-Results: ext-mx02.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 1C49E7E9DB DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8E3F319CF90 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=liyong.qiao@intel.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8E3F319CF90 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,184,1488873600"; d="scan'208";a="1154278384" From: Eli Qiao To: libvir-list@redhat.com Date: Tue, 11 Apr 2017 17:28:19 +0800 Message-Id: <1491902899-38727-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.29]); Tue, 11 Apr 2017 09:25:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 11 Apr 2017 09:25:40 +0000 (UTC) for IP:'192.55.52.43' DOMAIN:'mga05.intel.com' HELO:'mga05.intel.com' FROM:'liyong.qiao@intel.com' RCPT:'' X-RedHat-Spam-Score: -1.902 (BAYES_50, DCC_REPUT_00_12, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, SPF_PASS) 192.55.52.43 mga05.intel.com 192.55.52.43 mga05.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: mkletzan@redhat.com, pkrempa@redhat.com, liyong.qiao@intel.com Subject: [libvirt] [RFC] RFC: Reimplement cache allocation for a VM 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.26]); Tue, 11 Apr 2017 09:25:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is a RFC patch for the reimplement of `support cache tune(CAT) in libvirt`[1]. There are already patch sets[2] to address it, and functional works, but people doesn't like it cause it has global variable, and missing unit test case for new added capabilites, etc. Martin has proposed a test infra to do vircaps2xmltest, and I extened it on top of it to extend resctrl control[3], this is kinds of new desiged apart from [2], so I propose this RFC patch to do some rework on it. [] https://www.redhat.com/archives/libvir-list/2017-January/msg00683.html [] https://www.redhat.com/archives/libvir-list/2017-March/msg00181.html [] https://www.redhat.com/archives/libvir-list/2017-April/msg00516.html --- src/util/virresctrl.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ src/util/virresctrl.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 167 insertions(+) create mode 100644 src/util/virresctrl.c create mode 100644 src/util/virresctrl.h diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c new file mode 100644 index 0000000..f555eb8 --- /dev/null +++ b/src/util/virresctrl.c @@ -0,0 +1,81 @@ +/* + * virresctrl.c: methods for managing resource control + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Authors: + * Eli Qiao + */ + +#include +#include +#include +#include +#include + +#include "virresctrl.h" +#include "viralloc.h" +#include "virerror.h" +#include "virfile.h" +#include "virhostcpu.h" +#include "virlog.h" +#include "virstring.h" +#include "virarch.h" + +VIR_LOG_INIT("util.resctrl"); + +#define VIR_FROM_THIS VIR_FROM_RESCTRL + +VIR_ENUM_IMPL(virResctrl, VIR_RESCTRL_TYPE_LAST, + "L3", + "L3CODE", + "L3DATA", + "L2") + +/** + * a virResctrlDomain represents a resource control group, it's a directory + * under /sys/fs/resctrl. + * eg: /sys/fs/resctrl/CG1 + * |-- cpus + * |-- schemata + * `-- tasks + * # cat schemata + * L3DATA:0=3Dfffff;1=3Dfffff + * L3CODE:0=3Dfffff;1=3Dfffff + * + * Besides, it can also represent the default resource control group of the + * host. + */ + +typedef struct _virResctrlGroup virResctrlGroup; +typedef virResctrlGroup *virResctrlGroupPtr; +struct _virResctrlGroup { + char *name; /* resource group name, eg: CG1. If it represent host's + default resource group name, should be a NULL pointer */ + size_t n_tasks; /* number of task assigned to the resource group */ + char **tasks; /* task list which contains task id eg: 77454 */ + + size_t n_schematas; /* number of schemata the resource group contains, + eg: 2 */ + virResctrlSchemataPtr *schematas; /* scheamta list */ +}; + +/* All resource control groups on this host, including default resource gr= oup */ +typedef struct _virResCtrlDomain virResCtrlDomain; +typedef virResCtrlDomain *virResCtrlDomainPtr; +struct _virResCtrlDomain { + size_t n_groups; /* number of resource control group */ + virResctrlGroupPtr groups; /* list of resource control group */ +}; diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h new file mode 100644 index 0000000..da89542 --- /dev/null +++ b/src/util/virresctrl.h @@ -0,0 +1,86 @@ +/* + * virresctrl.h: header for managing resctrl control + * + * Copyright (C) 2016 Intel, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Authors: + * Eli Qiao + */ + +#ifndef __VIR_RESCTRL_H__ +# define __VIR_RESCTRL_H__ + +typedef enum { + VIR_RESCTRL_TYPE_L3, + VIR_RESCTRL_TYPE_L3_CODE, + VIR_RESCTRL_TYPE_L3_DATA, + VIR_RESCTRL_TYPE_L2, + + VIR_RESCTRL_TYPE_LAST +} virResctrlType; + +VIR_ENUM_DECL(virResctrl); + +/* + * a virResctrlSchemataItem represents one of schemata object in a + * resource control group. + * eg: 0=3Df + */ +typedef struct _virResCtrlSchemataItem virResctrlSchemataItem; +typedef virResctrlSchemataItem *virResctrlSchemataItemPtr; +struct _virResctrlSchemataItem { + unsigned int cache_id; /* cache resource id, eg: 0 */ + unsigned int continuous_schemata; /* schemata, should be a continuous = bits, + eg: f, this schemata can be persi= sted + to sysfs */ + unsigned int schemata; /* schemata eg: f0f, a schemata which is calcul= ated + at running time */ + unsigned long long size; /* the cache size schemata represented in B, + eg: (min * bits of continuous_schemata) */ +}; + +/* + * a virResctrlSchemata represents schemata objects of specific type of + * resource in a resource control group. + * eg: L3:0=3Df,1=3Dff + */ +typedef struct _virResctrlSchemata virResctrlSchemata; +typedef virResctrlSchemata *virResctrlSchemataPtr; +struct _virResctrlSchemata { + virResctrlType type; /* resource control type, eg: L3 */ + size_t n_schemata_items; /* number of schemata item, eg: 2 */ + virResctrlSchemataItemPtr *schemata_items; /* pointer list of schemata= item */ +}; + +/* Get free cache of the host, result saved in schemata */ +int virResctrlGetFreeCache(virResctrlType type, + virResctrlSchemataPtr *schemata); + +/* Get free cache of specific cache id of the host, result saved in + schemataitem */ +int virResctrlGetFreeCacheByCacheId(virResctrlType type, + virResctrlSchemataItemPtr *schemataite= m); + +/* Set cache allocation for a VM domain */ +int virResctrlSetCacheBanks(virDomainCachetunePtr cachetune, + unsigned char *group_name, + size_t n_pids, + pid_t *pids); + +/* remove cache allocation for a VM domain */ +int virResctrlRemoveCacheBanks(unsigned char *group_name); +#endif --=20 1.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list