From nobody Tue May 21 21:09:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1661347700; cv=none; d=zohomail.com; s=zohoarc; b=UGPD4HTtvHlx5VMWulYAVdY8FfYDgtBI51UWhZPAl1d/zIvOIpRnxSRUjwtHePFiLnj5SbX7RMx4A3AGsXPq/4RJvwJ8ftYd4I+P9PbWWQQSa1gtxkruFq6gsI5eIwnJyJYvC02J/qRPkhrEtoNXc10qdj806vBaIJg5YgHSG8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661347700; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pw5RzS4fR34yGT1sriXGAKDAXLaP3XNaTymjtCTCC0c=; b=iGIAoYcR8CAE/WDJiotDlH2ArYtWd0iOVdbd7hLhXxwEltNRMQzLa90kpAHb0yOpp/SGZMK0Ds3LKwtRl/g6lCY88z5OLIpP+sBUtXem+IyMTf4WmYRc/YKvEDddjmlEWt4OBoQ0nK9aQ8a+fgWiA5Gx8mTV6dOItpZVi5f+I8A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1661347700147145.37056769045864; Wed, 24 Aug 2022 06:28:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.392604.631071 (Exim 4.92) (envelope-from ) id 1oQqQI-0006YU-VF; Wed, 24 Aug 2022 13:27:58 +0000 Received: by outflank-mailman (output) from mailman id 392604.631071; Wed, 24 Aug 2022 13:27:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oQqQI-0006YL-SP; Wed, 24 Aug 2022 13:27:58 +0000 Received: by outflank-mailman (input) for mailman id 392604; Wed, 24 Aug 2022 13:27:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oQqQH-0006FJ-8N for xen-devel@lists.xenproject.org; Wed, 24 Aug 2022 13:27:57 +0000 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [2a00:1450:4864:20::32d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 90548926-23b0-11ed-bd2e-47488cf2e6aa; Wed, 24 Aug 2022 15:27:56 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id v7-20020a1cac07000000b003a6062a4f81so931829wme.1 for ; Wed, 24 Aug 2022 06:27:56 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:19f:35f0:dde5:d55a:20f5:7ef5]) by smtp.gmail.com with ESMTPSA id j27-20020a05600c1c1b00b003a5ce167a68sm2220599wms.7.2022.08.24.06.27.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 06:27:54 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 90548926-23b0-11ed-bd2e-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=pw5RzS4fR34yGT1sriXGAKDAXLaP3XNaTymjtCTCC0c=; b=UDFGJewEWl9ca+suNsoGL6+nTE8+RxeJ72gEJZN+GcV0lSndo8BkNZgMzAoY+EOXAt Kr0onwPpbWLOlnzB2skDBaq9c0n2FO24QF4jEtWbqoczRdZlua3qH8UMMiMKdc5nqto3 o81pVlxYn+UQiAgfz4LkS8+hh8IU9IfvExhE8GeXeZxZFj3Df3/1WRklWFh/vAEv7p3+ 3aFXZXGfafwJweWqgM7G2qxZQOP39e+fcWMDJ3w0tPPzDGK109o1ZYTQGPwoosojSeya QDDdhvfxZC9+h7c9axos9eROtMB676H8EqhCa/yDPNGb3bzF/kRDiSavRRGQfWsD59ag ex7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=pw5RzS4fR34yGT1sriXGAKDAXLaP3XNaTymjtCTCC0c=; b=Mmq7tfwBdPTnC64gYB0wocUogxR/Ai2t4vL8zcytAI7Q6XnrQf876JstSqZg6VzRxa wGu4hTgb2a03mATnObsA4bQk5gkrSJ6M8zFP3y0fnxqaZ1YEs/4GTHtbM47TKxhMAXjk 3q6lLNE46rgCY+vhGD3Q4Ap13W2npScMP1pSIeFTWyVkgomTfMNjtNvHXV+9M4eUN0rP mr8WOvfahuZsym1XDGw9rN8qn9QnnEDUbv2d0ap1en1myAU8CByOXlZ5ht1c/ul80GpN atTfWjo/bjVwgTO6st9LTC8qCv1GiRrVl1L4FDsDODHRez2Po4sO+S4HNd7sqpr8Gpxu PWdA== X-Gm-Message-State: ACgBeo08olokhjMqkj+wyDzeMKt8mG+XHPUnATNQxfg6hNIlAOzy6VVF sdD8bAQ2tGPBdckrW7/XUBt6lBYHLZ592g== X-Google-Smtp-Source: AA6agR7wuEdoPj++WDlmOddN8eWXOKj8NW3I34cKii9XYP87GsZwwoY6VRNNR2dVk8yMKRxF+AvQxA== X-Received: by 2002:a05:600c:350:b0:3a5:3473:1c23 with SMTP id u16-20020a05600c035000b003a534731c23mr5448443wmd.9.1661347675214; Wed, 24 Aug 2022 06:27:55 -0700 (PDT) From: Matias Ezequiel Vara Larsen X-Google-Original-From: Matias Ezequiel Vara Larsen To: xen-devel@lists.xenproject.org Cc: Matias Ezequiel Vara Larsen , Jan Beulich , Andrew Cooper , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Dario Faggioli Subject: [RFC PATCH v1 1/2] xen/memory : Add a stats_table resource type Date: Wed, 24 Aug 2022 15:27:30 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1661347700664100003 Content-Type: text/plain; charset="utf-8" This commit proposes a new mechanism to query the RUNSTATE_running counter = for a given vcpu from a dom0 userspace application. This commit proposes to exp= ose that counter by using the acquire_resource interface. The current mechanism relies on the XEN_DOMCTL_getvcpuinfo and holds a single global domctl_lock = for the entire hypercall; and iterate over every vcpu in the system for every update thus impacting operations that share that lock. This commit proposes to expose vcpu RUNSTATE_running via the xenforeignmemory interface thus preventing to issue the hypercall and holdi= ng the lock. For that purpose, a new resource type named stats_table is added.= The first frame of this resource stores per-vcpu counters. The frame has one en= try of type struct vcpu_stats per vcpu. The allocation of this frame only happe= ns if the resource is requested. The frame is released after the domain is destroyed. Note that the updating of this counter is in a hot path, thus, in this comm= it, copying only happens if it is specifically required. Note that the exposed structure is extensible in two ways. First, the struc= ture vcpu_stats can be extended with new per-vcpu counters while it fits in a fr= ame. Second, new frames can be added in case new counters are required. Signed-off-by: Matias Ezequiel Vara Larsen --- Changes in v1: - rework the allocation and releasing of the frames - use the zero frame for per-vcpu counters that are listed as an array - allocate vcpu stats frames only when the resource is requested - rewrite commit message - add the vcpu_stats structure to keep per-vcpu counters - add the shared_vcpustatspage to keep an array of per-vcpu counters for a given domain - declare the structures in a public header=20 - define the vcpustats_page in the domain structure --- xen/arch/x86/hvm/hvm.c | 2 + xen/common/memory.c | 94 +++++++++++++++++++++++++++++++++++++ xen/common/sched/core.c | 7 +++ xen/include/public/memory.h | 3 ++ xen/include/public/vcpu.h | 10 ++++ xen/include/xen/mm.h | 2 + xen/include/xen/sched.h | 5 ++ 7 files changed, 123 insertions(+) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index ddd001a6ad..1ef6cb5ff0 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -741,6 +741,8 @@ void hvm_domain_relinquish_resources(struct domain *d) =20 ioreq_server_destroy_all(d); =20 + stats_free_vcpu_mfn(d); + msixtbl_pt_cleanup(d); =20 /* Stop all asynchronous timer actions. */ diff --git a/xen/common/memory.c b/xen/common/memory.c index 297b98a562..749486d5d4 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1078,6 +1078,12 @@ unsigned int ioreq_server_max_frames(const struct do= main *d) return nr; } =20 +unsigned int stats_table_max_frames(const struct domain *d) +{ + /* One frame per 512 vcpus. */ + return 1; +} + /* * Return 0 on any kind of error. Caller converts to -EINVAL. * @@ -1099,6 +1105,9 @@ static unsigned int resource_max_frames(const struct = domain *d, case XENMEM_resource_vmtrace_buf: return d->vmtrace_size >> PAGE_SHIFT; =20 + case XENMEM_resource_stats_table: + return stats_table_max_frames(d); + default: return -EOPNOTSUPP; } @@ -1162,6 +1171,88 @@ static int acquire_vmtrace_buf( return nr_frames; } =20 +void stats_free_vcpu_mfn(struct domain * d) +{ + struct page_info *pg =3D d->vcpustats_page.pg; + + if ( !pg ) + return; + + d->vcpustats_page.pg =3D NULL; + + if ( d->vcpustats_page.va ) + unmap_domain_page_global(d->vcpustats_page.va); + + d->vcpustats_page.va =3D NULL; + + put_page_alloc_ref(pg); + put_page_and_type(pg); +} + +static int stats_vcpu_alloc_mfn(struct domain *d) +{ + struct page_info *pg; + + pg =3D alloc_domheap_page(d, MEMF_no_refcount); + + if ( !pg ) + return -ENOMEM; + + if ( !get_page_and_type(pg, d, PGT_writable_page) ) { + put_page_alloc_ref(pg); + return -ENODATA; + } + + d->vcpustats_page.va =3D __map_domain_page_global(pg); + if ( !d->vcpustats_page.va ) + goto fail; + + d->vcpustats_page.pg =3D pg; + clear_page(d->vcpustats_page.va); + return 1; + +fail: + put_page_alloc_ref(pg); + put_page_and_type(pg); + + return -ENOMEM; +} + +static int acquire_stats_table(struct domain *d, + unsigned int id, + unsigned int frame, + unsigned int nr_frames, + xen_pfn_t mfn_list[]) +{ + mfn_t mfn; + int rc; + unsigned int i; + + if ( !d ) + return -ENOENT; + + for ( i =3D 0; i < nr_frames; i++ ) + { + switch ( i ) + { + case XENMEM_resource_stats_frame_vcpustats: + if ( !d->vcpustats_page.pg ) { + rc =3D stats_vcpu_alloc_mfn(d); + if ( rc < 1 ) + return rc; + } + mfn =3D page_to_mfn(d->vcpustats_page.pg); + mfn_list[i] =3D mfn_x(mfn); + break; + + default: + return -EINVAL; + } + } + + return nr_frames; +} + /* * Returns -errno on error, or positive in the range [1, nr_frames] on * success. Returning less than nr_frames contitutes a request for a @@ -1182,6 +1273,9 @@ static int _acquire_resource( case XENMEM_resource_vmtrace_buf: return acquire_vmtrace_buf(d, id, frame, nr_frames, mfn_list); =20 + case XENMEM_resource_stats_table: + return acquire_stats_table(d, id, frame, nr_frames, mfn_list); + default: return -EOPNOTSUPP; } diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index 8f4b1ca10d..87cfa172ad 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -264,6 +264,8 @@ static inline void vcpu_runstate_change( { s_time_t delta; struct sched_unit *unit =3D v->sched_unit; + shared_vcpustatspage_t * vcpustats_va; + struct domain *d =3D v->domain; =20 ASSERT(spin_is_locked(get_sched_res(v->processor)->schedule_lock)); if ( v->runstate.state =3D=3D new_state ) @@ -287,6 +289,11 @@ static inline void vcpu_runstate_change( } =20 v->runstate.state =3D new_state; + + vcpustats_va =3D (shared_vcpustatspage_t*)d->vcpustats_page.va; + if ( vcpustats_va ) + memcpy(&vcpustats_va->vcpu_info[v->vcpu_id].runstate_running_time, + &v->runstate.time[RUNSTATE_running], sizeof(v->runstate.tim= e[RUNSTATE_running])); } =20 void sched_guest_idle(void (*idle) (void), unsigned int cpu) diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 50e73eef98..e1a10b8b97 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -626,6 +626,7 @@ struct xen_mem_acquire_resource { #define XENMEM_resource_ioreq_server 0 #define XENMEM_resource_grant_table 1 #define XENMEM_resource_vmtrace_buf 2 +#define XENMEM_resource_stats_table 3 =20 /* * IN - a type-specific resource identifier, which must be zero @@ -683,6 +684,8 @@ struct xen_mem_acquire_resource { typedef struct xen_mem_acquire_resource xen_mem_acquire_resource_t; DEFINE_XEN_GUEST_HANDLE(xen_mem_acquire_resource_t); =20 +#define XENMEM_resource_stats_frame_vcpustats 0 + /* * XENMEM_get_vnumainfo used by guest to get * vNUMA topology from hypervisor. diff --git a/xen/include/public/vcpu.h b/xen/include/public/vcpu.h index 3623af932f..57a5ca777c 100644 --- a/xen/include/public/vcpu.h +++ b/xen/include/public/vcpu.h @@ -235,6 +235,16 @@ struct vcpu_register_time_memory_area { typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_ar= ea_t; DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t); =20 +struct vcpu_stats{ + uint64_t runstate_running_time; +}; + +struct shared_vcpustatspage { + struct vcpu_stats vcpu_info[1]; +}; + +typedef struct shared_vcpustatspage shared_vcpustatspage_t; + #endif /* __XEN_PUBLIC_VCPU_H__ */ =20 /* diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 667f9dac83..d1ca8b9aa8 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -134,6 +134,8 @@ int assign_pages( /* Dump info to serial console */ void arch_dump_shared_mem_info(void); =20 +void stats_free_vcpu_mfn(struct domain * d); + /* * Extra fault info types which are used to further describe * the source of an access violation. diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 5485d08afb..d9551ce35f 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -577,6 +577,11 @@ struct domain struct ioreq_server *server[MAX_NR_IOREQ_SERVERS]; } ioreq_server; #endif + /* Page that hosts vcpu stats */ + struct { + struct page_info *pg; + void *va; + } vcpustats_page; }; =20 static inline struct page_list_head *page_to_list( --=20 2.25.1 From nobody Tue May 21 21:09:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1661347711; cv=none; d=zohomail.com; s=zohoarc; b=hI9OpEBpd3lhlr1t1KIx5Fx3L6ZvomKlPPWM6p8Mz6x1Q8l+GZduncI6h1YE2vnahgaMSRBlQtq60dcGTdJP2+3pwQQOzIxQWctkx9qn95wzaE1ttfUPpJ/CZ4AjArmGjwBEnTP5w0KCYAIkCOmbaCE4a3v3G3B+9C6KFXSXPKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661347711; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=59izKsatWx93ZlS9Q48JeXcPM/kkJK4lT2iqQF0AUr8=; b=Qn+0CWIXQwATwo5zMsjgteIK2eN5EApfV8jBSLwRSsANV0wMJW4JYOuZ/TOzaVs6XSzGSVA9e4PutCMocoxXkAGBp9vEBPYW79gWyWdV+eipNp04wuh8QhDXxQGToh6PmosUfxsZsnZdd+GLl0Df9/cG+6WC2lzS5LPuy5TsdQY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1661347711942151.02527775848102; Wed, 24 Aug 2022 06:28:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.392605.631082 (Exim 4.92) (envelope-from ) id 1oQqQT-0006xJ-6c; Wed, 24 Aug 2022 13:28:09 +0000 Received: by outflank-mailman (output) from mailman id 392605.631082; Wed, 24 Aug 2022 13:28:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oQqQT-0006xA-3G; Wed, 24 Aug 2022 13:28:09 +0000 Received: by outflank-mailman (input) for mailman id 392605; Wed, 24 Aug 2022 13:28:07 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oQqQR-0006FJ-On for xen-devel@lists.xenproject.org; Wed, 24 Aug 2022 13:28:07 +0000 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [2a00:1450:4864:20::32f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 96bb7103-23b0-11ed-bd2e-47488cf2e6aa; Wed, 24 Aug 2022 15:28:07 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id ay39-20020a05600c1e2700b003a5503a80cfso860701wmb.2 for ; Wed, 24 Aug 2022 06:28:07 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:19f:35f0:dde5:d55a:20f5:7ef5]) by smtp.gmail.com with ESMTPSA id j27-20020a05600c1c1b00b003a5ce167a68sm2220599wms.7.2022.08.24.06.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 06:28:05 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 96bb7103-23b0-11ed-bd2e-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=59izKsatWx93ZlS9Q48JeXcPM/kkJK4lT2iqQF0AUr8=; b=li+lc8LIPUN0y7KhIgvxw2Bp602rvWMjswmCVPydIJo1NS3XJKnMY8HJsvYuoj3JMZ nbO6IMp4JNK+kDCc/ei9BjBa8+gEvgaEBbaA+cGc2czklox+3m6H1U8awwq2hAWeX99x 0oU4HbE4akgfQuWuoqVgidlPpEtEApdpYFqQSgzS8m+MmYPm0/duKEjn5NMDyZMyF0bS JmaXSfYOHXA5yhUR2p1bVC/wW54a2Anch17u8A6ulLLe2EbF0uGUzLzyXLumYzCkzLMu AjrjKjN456qPfoqEkXDfV9ODshm6n9Ut1SWXBJs+rPTqiFXdOzLB48cFzakhowQ2xwm6 XALQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=59izKsatWx93ZlS9Q48JeXcPM/kkJK4lT2iqQF0AUr8=; b=q1D0kBBf1uFlmr2IgYm246otj90quHb79740jzH+Uy4e4KOZUddIInYFWlS3SxcQgI BuiKlspAqnVb+VyD7yiOZFd3UaEPl7MemawAe6rhwKjNpzfBpY0KIUNaOxgOfqCPKl0r y6vbm0O/qn+99810rRcygh4h8hfI396c/7/8r3XpcEeaJ2RIZvGHyKqKlQ4yKVUZfqeI 3p8TgbQW6CIIJD4e5D5vXXdFlcoMxbSAzgPfkU2be51XJ5md7AgsqZRL6Y0DsIp9tFay ovtSOHTVCJkIULF7f83dHw92Fr22oFDfbXj2LAGmCEzioyOD+dWowKr9wElE1kanCGsv 2LSA== X-Gm-Message-State: ACgBeo0T2uUAYeyNERd23gi6HnzJY9wFH3SuiysbmpTcSDmNp7yBHWfJ QEhJCxbBTBpNYP6+Tkww+eCWbCjXt0rVJQ== X-Google-Smtp-Source: AA6agR7ndbWxAHEobxliUdBG3EnIJEGWqWn/Wx4e+XiZTaMrK+K4/Y6YLhUNj5Kbxta/z/L32dD0dQ== X-Received: by 2002:a05:600c:5023:b0:3a6:3f9:a031 with SMTP id n35-20020a05600c502300b003a603f9a031mr5091369wmr.131.1661347686216; Wed, 24 Aug 2022 06:28:06 -0700 (PDT) From: Matias Ezequiel Vara Larsen X-Google-Original-From: Matias Ezequiel Vara Larsen To: xen-devel@lists.xenproject.org Cc: Matias Ezequiel Vara Larsen , Wei Liu , Anthony PERARD Subject: [RFC PATCH v1 2/2] tools/misc: Add xen-vcpus-stats tool Date: Wed, 24 Aug 2022 15:27:31 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1661347712703100003 Content-Type: text/plain; charset="utf-8" Add a demostration tool that uses the stats_table resource to query vcpus' RUNSTATE_running counter for a DomU. Signed-off-by: Matias Ezequiel Vara Larsen --- Changes in v1: - change the name of the tool to xen-vcpus-stats - set command line parameters in the same order that are passed - remove header libs.h - build by default - remove errno, strerrno, "\n", and identation - use errx when errno is not needed - address better the number of pages requested and error msgs - use the shared_vcpustatspage_t structure - use the correct frame id when requesting the resource --- tools/misc/Makefile | 6 +++ tools/misc/xen-vcpus-stats.c | 76 ++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 tools/misc/xen-vcpus-stats.c diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 2b683819d4..837e4b50da 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -49,6 +49,7 @@ TARGETS_COPY +=3D xenpvnetboot =20 # Everything which needs to be built TARGETS_BUILD :=3D $(filter-out $(TARGETS_COPY),$(TARGETS_ALL)) +TARGETS_BUILD +=3D xen-vcpus-stats =20 # ... including build-only targets TARGETS_BUILD-$(CONFIG_X86) +=3D xen-vmtrace @@ -135,4 +136,9 @@ xencov: xencov.o xen-ucode: xen-ucode.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) =20 +xen-vcpus-stats.o: CFLAGS +=3D $(CFLAGS_libxenforeginmemory) + +xen-vcpus-stats: xen-vcpus-stats.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenforeignmemo= ry) $(APPEND_LDFLAGS) + -include $(DEPS_INCLUDE) diff --git a/tools/misc/xen-vcpus-stats.c b/tools/misc/xen-vcpus-stats.c new file mode 100644 index 0000000000..d56d1493e4 --- /dev/null +++ b/tools/misc/xen-vcpus-stats.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +static sig_atomic_t interrupted; +static void close_handler(int signum) +{ + interrupted =3D 1; +} + +int main(int argc, char **argv) +{ + xenforeignmemory_handle *fh; + xenforeignmemory_resource_handle *res; + size_t size; + int rc, domid, frec, vcpu; + shared_vcpustatspage_t * info; + struct sigaction act; + + if (argc !=3D 4 ) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + domid =3D atoi(argv[1]); + vcpu =3D atoi(argv[2]); + frec =3D atoi(argv[3]); + + act.sa_handler =3D close_handler; + act.sa_flags =3D 0; + sigemptyset(&act.sa_mask); + sigaction(SIGHUP, &act, NULL); + sigaction(SIGTERM, &act, NULL); + sigaction(SIGINT, &act, NULL); + sigaction(SIGALRM, &act, NULL); + + fh =3D xenforeignmemory_open(NULL, 0); + + if ( !fh ) + err(1, "xenforeignmemory_open"); + + rc =3D xenforeignmemory_resource_size( + fh, domid, XENMEM_resource_stats_table, + 0, &size); + + if ( rc ) + err(1, "Fail: Get size"); + + res =3D xenforeignmemory_map_resource( + fh, domid, XENMEM_resource_stats_table, + 0, XENMEM_resource_stats_frame_vcpustats, size >> XC_PAGE_SHIFT, + (void **)&info, PROT_READ, 0); + + if ( !res ) + err(1, "Fail: Map"); + + while ( !interrupted ) { + sleep(frec); + printf("running cpu_time: %ld\n", info->vcpu_info[vcpu].runstate_r= unning_time); + } + + rc =3D xenforeignmemory_unmap_resource(fh, res); + if ( rc ) + err(1, "Fail: Unmap"); + + return 0; +} --=20 2.25.1