From patchwork Tue May 17 14:33:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matias Ezequiel Vara Larsen X-Patchwork-Id: 12852573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A883CC433EF for ; Tue, 17 May 2022 14:33:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.330964.554393 (Exim 4.92) (envelope-from ) id 1nqyGX-00088x-Bk; Tue, 17 May 2022 14:33:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 330964.554393; Tue, 17 May 2022 14:33:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nqyGX-00088q-7n; Tue, 17 May 2022 14:33:37 +0000 Received: by outflank-mailman (input) for mailman id 330964; Tue, 17 May 2022 14:33:36 +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 1nqyGV-0007sV-VR for xen-devel@lists.xenproject.org; Tue, 17 May 2022 14:33:36 +0000 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [2a00:1450:4864:20::429]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5534f158-d5ee-11ec-bd2c-47488cf2e6aa; Tue, 17 May 2022 16:33:35 +0200 (CEST) Received: by mail-wr1-x429.google.com with SMTP id w4so25008058wrg.12 for ; Tue, 17 May 2022 07:33:35 -0700 (PDT) Received: from horizon.home (amontsouris-681-1-37-131.w90-87.abo.wanadoo.fr. [90.87.156.131]) by smtp.gmail.com with ESMTPSA id f21-20020a7bcd15000000b003942a244f30sm2544884wmj.9.2022.05.17.07.33.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 07:33:34 -0700 (PDT) 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: 5534f158-d5ee-11ec-bd2c-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l4FmmyqLRGvXYMIUa3VVLSfEZOS+ge14yndz9u2uerk=; b=IS5MuXI3qTk9KdMKhqyLjBHPVSrMbj2lq9dkP7aZ7vmpTjwpb4NUhLpNSF8eRl93Z3 4VsNwupqYxWgD1qgDty7nfcR8H3aa9YObZHBMUxD7cqth+cuHw6pKvt+xBM/MAza3NCD B06IQKBD2wLhxAf/tH9ZSPYOYBGYW0xaHk6Fe5Syt40hRzsxIDqYQ616sqKvMSWhDUGV tSrKmDbAkBNLgSxR/gHY/Ay1AltSJMXB+uASi5oaR6YCYPsUuL6qIs+BBDgZoUd1h6Qr kjjRKc7Mi+reUNFQvBhyIrJVCjVe0jIDP6CvwEz6IeIaHximoQo+FouFMdZ5latBaZnw uzJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l4FmmyqLRGvXYMIUa3VVLSfEZOS+ge14yndz9u2uerk=; b=t2YpfVOhjpJ83qbzhlsu1FmRfFv7INA57MVEX+Dn/Ug0iDzoKUC9Sm6aLHNpaFR1vh 4OnwZlBFSVff13D/M3OWIm4EgevnhVRqO9mtelvkffh/XQYh/nTsQ3+8w2LK4lBazE27 sl35Oh9ERHFZXKIkxduNEP+AkcmSVWfLJDFHiuwdrtbc17LZelE6tldq5hZV5wFMc0ot +rmUSCURzss1hnwxXZDCWhMFHsq/Vy9rN31dTRvqLJZ38y6ymL109cFbc88SmEfDz9oZ kT0X46t7PzxmkJpokBxywUCI8XV+HIVEcmuyBojrDMJNt/BI66GfHgx+BzmpcdKv1eRp vaFQ== X-Gm-Message-State: AOAM531vblwQx7TDPThcagZXNUArxFBQbr/ZsVII0uT1kQu2gExMqj4k mfmjkBeW5bixlCucvqf8BmstcRTonSf+rA== X-Google-Smtp-Source: ABdhPJw/qHReIodTGVvX1U8v9An9YMCdZfTdwsfD+29R58e1Kpell1NJ2y3X1Szyh4jZjUdVVzEZzQ== X-Received: by 2002:adf:f152:0:b0:20d:740:beba with SMTP id y18-20020adff152000000b0020d0740bebamr10075439wro.512.1652798014404; Tue, 17 May 2022 07:33:34 -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 , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Dario Faggioli Subject: [RFC PATCH 1/2] xen/memory : Add stats_table resource type Date: Tue, 17 May 2022 16:33:14 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Allow to map vcpu stats using acquire_resource(). Signed-off-by: Matias Ezequiel Vara Larsen --- xen/common/domain.c | 42 +++++++++++++++++++++++++++++++++++++ xen/common/memory.c | 29 +++++++++++++++++++++++++ xen/common/sched/core.c | 5 +++++ xen/include/public/memory.h | 1 + xen/include/xen/sched.h | 5 +++++ 5 files changed, 82 insertions(+) diff --git a/xen/common/domain.c b/xen/common/domain.c index 17cc32fde3..ddd9f88874 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -132,6 +132,42 @@ static void vcpu_info_reset(struct vcpu *v) v->vcpu_info_mfn = INVALID_MFN; } +static void stats_free_buffer(struct vcpu * v) +{ + struct page_info *pg = v->stats.pg; + + if ( !pg ) + return; + + v->stats.va = NULL; + + if ( v->stats.va ) + unmap_domain_page_global(v->stats.va); + + v->stats.va = NULL; + + free_domheap_page(pg); +} + +static int stats_alloc_buffer(struct vcpu *v) +{ + struct domain *d = v->domain; + struct page_info *pg; + + pg = alloc_domheap_page(d, MEMF_no_refcount); + + if ( !pg ) + return -ENOMEM; + + v->stats.va = __map_domain_page_global(pg); + if ( !v->stats.va ) + return -ENOMEM; + + v->stats.pg = pg; + clear_page(v->stats.va); + return 0; +} + static void vmtrace_free_buffer(struct vcpu *v) { const struct domain *d = v->domain; @@ -203,6 +239,9 @@ static int vmtrace_alloc_buffer(struct vcpu *v) */ static int vcpu_teardown(struct vcpu *v) { + + stats_free_buffer(v); + vmtrace_free_buffer(v); return 0; @@ -269,6 +308,9 @@ struct vcpu *vcpu_create(struct domain *d, unsigned int vcpu_id) if ( vmtrace_alloc_buffer(v) != 0 ) goto fail_wq; + if ( stats_alloc_buffer(v) != 0 ) + goto fail_wq; + if ( arch_vcpu_create(v) != 0 ) goto fail_sched; diff --git a/xen/common/memory.c b/xen/common/memory.c index 297b98a562..39de6d9d05 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1099,6 +1099,10 @@ static unsigned int resource_max_frames(const struct domain *d, case XENMEM_resource_vmtrace_buf: return d->vmtrace_size >> PAGE_SHIFT; + // WIP: to figure out the correct size of the resource + case XENMEM_resource_stats_table: + return 1; + default: return -EOPNOTSUPP; } @@ -1162,6 +1166,28 @@ static int acquire_vmtrace_buf( return nr_frames; } +static int acquire_stats_table(struct domain *d, + unsigned int id, + unsigned int frame, + unsigned int nr_frames, + xen_pfn_t mfn_list[]) +{ + const struct vcpu *v = domain_vcpu(d, id); + mfn_t mfn; + + if ( !v ) + return -ENOENT; + + if ( !v->stats.pg ) + return -EINVAL; + + mfn = page_to_mfn(v->stats.pg); + mfn_list[0] = mfn_x(mfn); + + printk("acquire_perf_table: id: %d, nr_frames: %d, %p, domainid: %d\n", id, nr_frames, v->stats.pg, d->domain_id); + return 1; +} + /* * 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 +1208,9 @@ static int _acquire_resource( case XENMEM_resource_vmtrace_buf: return acquire_vmtrace_buf(d, id, frame, nr_frames, mfn_list); + 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..2a8b534977 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -264,6 +264,7 @@ static inline void vcpu_runstate_change( { s_time_t delta; struct sched_unit *unit = v->sched_unit; + uint64_t * runstate; ASSERT(spin_is_locked(get_sched_res(v->processor)->schedule_lock)); if ( v->runstate.state == new_state ) @@ -287,6 +288,10 @@ static inline void vcpu_runstate_change( } v->runstate.state = new_state; + + // WIP: use a different interface + runstate = (uint64_t*)v->stats.va; + memcpy(runstate, &v->runstate.time[0], sizeof(v->runstate.time[0])); } 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..752fd0be0f 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 /* * IN - a type-specific resource identifier, which must be zero diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 5485d08afb..bc99adea7e 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -284,6 +284,11 @@ struct vcpu struct page_info *pg; /* One contiguous allocation of d->vmtrace_size */ } vmtrace; + struct { + struct page_info *pg; + void * va; + } stats; + struct arch_vcpu arch; #ifdef CONFIG_IOREQ_SERVER From patchwork Tue May 17 14:33:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matias Ezequiel Vara Larsen X-Patchwork-Id: 12852574 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1BFC8C4332F for ; Tue, 17 May 2022 14:33:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.330965.554405 (Exim 4.92) (envelope-from ) id 1nqyGZ-0008Qs-Lj; Tue, 17 May 2022 14:33:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 330965.554405; Tue, 17 May 2022 14:33:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nqyGZ-0008Qg-H9; Tue, 17 May 2022 14:33:39 +0000 Received: by outflank-mailman (input) for mailman id 330965; Tue, 17 May 2022 14:33:38 +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 1nqyGY-0007sV-1O for xen-devel@lists.xenproject.org; Tue, 17 May 2022 14:33:38 +0000 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [2a00:1450:4864:20::42c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5676ab00-d5ee-11ec-bd2c-47488cf2e6aa; Tue, 17 May 2022 16:33:37 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id j24so9790354wrb.1 for ; Tue, 17 May 2022 07:33:37 -0700 (PDT) Received: from horizon.home (amontsouris-681-1-37-131.w90-87.abo.wanadoo.fr. [90.87.156.131]) by smtp.gmail.com with ESMTPSA id f21-20020a7bcd15000000b003942a244f30sm2544884wmj.9.2022.05.17.07.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 07:33:36 -0700 (PDT) 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: 5676ab00-d5ee-11ec-bd2c-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gpzhC736ZCcknGHWj7xlGwQP3KKn5gNkOz0b71J0xEk=; b=b/jhAljctA8SSJZRjApK/ajrQuLJdVc/6RBDV3owMBNa3Fc4Dr/YNdXXQ5DHjl3mzB LhA9T7p3TNvdWiUkRXIAdRoyNJhSpy4NZMF4X4gqJTFzUXv2aVsKLGP+Bp1/l5/5Fw+e fNTtR1ZoESUJh2P/c3cvB0JRgnQK3rcdjqaqkcPhtRFARx4gHr4L8Vb9xGIGhsquH80B 4vfnuvkyREGSdNGEOMLbbw70a0OriT1kYOLF5jzN88SGc+V0hegLx34nd1rXHqaAkzIm zlBpUVUmD8z11TlWSKMDQpvft8iLx7K3GGnb/XRZEWk6arT3eTd5pgeBfskfddhXWZr4 gtmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gpzhC736ZCcknGHWj7xlGwQP3KKn5gNkOz0b71J0xEk=; b=ks8kzvpm/hURk9rZdT03A020FbRyNtFQukNsIQXbsMdwG53za2FxarIOKuudbre4BN d3qrK5F5A/MqtcxomSnCkdCPPy2vldDnvIEn0DUKKqlOqbrEds1BcsnfmxwA1tRyHile +fNKH3Il2+vgD6hI0cbJ/u906ejJHBNQh9cJVC8weoRakTKRV0RP6QkdsYTxv6QqZ4PU xqW4JbKXMGSXxLY+gSfXmZdyi/yl2/FWalt6Sau+NbuWRj8LTBhJYFIUyhumFt4z25n/ e1q+bCdOLmKLq8kB27B+QMmsbwJcdV8UkhpqsBX8e6cUNUf5Y9ytiQ1PNCM8ThC9JIeC 01yA== X-Gm-Message-State: AOAM533zn53bRo7hm3kpPoQgyxnnEloXLgQwoqHU2AtUa8J1qAyx5AMW mf3pOXsbhmZvT7tVQAx+pdX7RcTcWIUjGQ== X-Google-Smtp-Source: ABdhPJy00iSU9MGY4ElHHizz5q64eggXdUyF8ugDubELNhWZeMFlJKgjswaZAjB2s8FXFaicvsp6kQ== X-Received: by 2002:adf:eb4b:0:b0:20c:dfe2:bed7 with SMTP id u11-20020adfeb4b000000b0020cdfe2bed7mr18409036wrn.672.1652798016532; Tue, 17 May 2022 07:33:36 -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 2/2] tools/misc: Add xen-stats tool Date: Tue, 17 May 2022 16:33:15 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Add a demostration tool that uses the stats_table resource to query vcpu time for a DomU. Signed-off-by: Matias Ezequiel Vara Larsen --- tools/misc/Makefile | 5 +++ tools/misc/xen-stats.c | 83 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tools/misc/xen-stats.c diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 2b683819d4..b510e3aceb 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -135,4 +135,9 @@ xencov: xencov.o xen-ucode: xen-ucode.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) +xen-stats.o: CFLAGS += $(CFLAGS_libxenforeginmemory) + +xen-stats: xen-stats.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenforeignmemory) $(APPEND_LDFLAGS) + -include $(DEPS_INCLUDE) diff --git a/tools/misc/xen-stats.c b/tools/misc/xen-stats.c new file mode 100644 index 0000000000..5d4a3239cc --- /dev/null +++ b/tools/misc/xen-stats.c @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +static sig_atomic_t interrupted; +static void close_handler(int signum) +{ + interrupted = 1; +} + +int main(int argc, char **argv) +{ + xenforeignmemory_handle *fh; + xenforeignmemory_resource_handle *res; + size_t size; + int rc, nr_frames, domid, frec, vcpu; + uint64_t * info; + struct sigaction act; + + if (argc != 4 ) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + // TODO: this depends on the resource + nr_frames = 1; + + domid = atoi(argv[1]); + frec = atoi(argv[3]); + vcpu = atoi(argv[2]); + + act.sa_handler = close_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + sigaction(SIGHUP, &act, NULL); + sigaction(SIGTERM, &act, NULL); + sigaction(SIGINT, &act, NULL); + sigaction(SIGALRM, &act, NULL); + + fh = xenforeignmemory_open(NULL, 0); + + if ( !fh ) + err(1, "xenforeignmemory_open"); + + rc = xenforeignmemory_resource_size( + fh, domid, XENMEM_resource_stats_table, + vcpu, &size); + + if ( rc ) + err(1, " Fail: Get size: %d - %s\n", errno, strerror(errno)); + + if ( (size >> XC_PAGE_SHIFT) != nr_frames ) + err(1, " Fail: Get size: expected %u frames, got %zu\n", + nr_frames, size >> XC_PAGE_SHIFT); + + res = xenforeignmemory_map_resource( + fh, domid, XENMEM_resource_stats_table, + vcpu, 0, size >> XC_PAGE_SHIFT, + (void **)&info, PROT_READ, 0); + + if ( !res ) + err(1, " Fail: Map %d - %s\n", errno, strerror(errno)); + + while ( !interrupted ) { + sleep(frec); + printf("running cpu_time: %ld\n", *info); + } + + rc = xenforeignmemory_unmap_resource(fh, res); + if ( rc ) + err(1, " Fail: Unmap %d - %s\n", errno, strerror(errno)); + + return 0; +}