From patchwork Wed Sep 11 10:32:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Anisov X-Patchwork-Id: 11140867 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D27417E6 for ; Wed, 11 Sep 2019 10:34:10 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 688192082C for ; Wed, 11 Sep 2019 10:34:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fRMTOSwJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 688192082C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7zvY-00009s-VW; Wed, 11 Sep 2019 10:32:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7zvX-00009C-9Q for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 10:32:43 +0000 X-Inumbo-ID: 75f7655c-d47f-11e9-a337-bc764e2007e4 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 75f7655c-d47f-11e9-a337-bc764e2007e4; Wed, 11 Sep 2019 10:32:32 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id u14so19450462ljj.11 for ; Wed, 11 Sep 2019 03:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AC9kNkmArPC3CzG+J65Zgd+nHkAn9+JKqJkWk1/eavM=; b=fRMTOSwJNbVaQuzqiIUP2BxsXXEOPY35/+4BhqAAYesK6QvtpW7qJYOOel8W6OK9mb H6pYZiaPM/5FtLOmukohyjNEcnKN+nqlyBHvCASq2li02l9iI2a67mwd6oppFu2pyOci FnZVgIwa91FTLb3tO7xOj75GB1UV0YNliifzVhIB+0GwMRTokC4yBK7eNQ/+I/bphYjs e5fpt1bYOx9OimcQ4RXs38vpiozBLGwUQ4f4SYHDl7oL9tOGXqTEVnD7QS6m8RpaGIJT rjiiZpqYkZ3xlptInbh6paUW9BNUs/E2OQ/pYepQLdxu2iA+b8/yOhKu+wcLFplvt3xQ EiSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AC9kNkmArPC3CzG+J65Zgd+nHkAn9+JKqJkWk1/eavM=; b=g7nXkAROIwEeB/N+iAlBiJ4s6Ql0m70B6zs0vQGDbVojUN8/CXr1YM4IQFuigtVgOI CBKeNo2nElqXBdw0pMaKh1WlFIcQ0emXofcg9aC8CZGkGNBa2vdghHuZGyiJv65q3LbA Ek0LpNjbpLefT0ItTODiGnZl5XLWdmRBs/Q0rdUsYr9JO59YaqbnAjMHw1p+2z4HZ2Ll p5F0ziTwH/SwcYgxscRUtsTIA0h1MKy2xJOHiTJv/cgoNjL/kX80PynrK4BCA6xmVbPT 3+iSVz0fPnKakI20Kc8NYbfPImsBBc9UNr+wYfd074GpKDHZPL5LQjPA+8dbhR+3yq0X YX/w== X-Gm-Message-State: APjAAAXNA4RL3PaZUDPDaWvqYfSXpmk+ISVJIbV26YPxMvA7Oj4isJYW xvYFmRd1m+tZlovCiUPvgp3qKgun4mE= X-Google-Smtp-Source: APXvYqzks7WvwhsxPXamr1i/FvYqbuwkN9K8Ylqe93xKrQE6r7f1nYgJpT93k1dnj/RYpmNZdd9+Jg== X-Received: by 2002:a2e:9586:: with SMTP id w6mr21889348ljh.47.1568197950711; Wed, 11 Sep 2019 03:32:30 -0700 (PDT) Received: from aanisov-work.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id w27sm4585275ljd.55.2019.09.11.03.32.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Sep 2019 03:32:30 -0700 (PDT) From: Andrii Anisov To: xen-devel@lists.xenproject.org Date: Wed, 11 Sep 2019 13:32:16 +0300 Message-Id: <1568197942-15374-4-git-send-email-andrii.anisov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1568197942-15374-1-git-send-email-andrii.anisov@gmail.com> References: <1568197942-15374-1-git-send-email-andrii.anisov@gmail.com> Subject: [Xen-devel] [RFC 3/9] xentop: show CPU load information X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Andrii Anisov , Wei Liu MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Andrii Anisov Let xentop request and show information about CPU load provided by new time accounting infrastructure. Signed-off-by: Andrii Anisov --- tools/xenstat/libxenstat/src/xenstat.c | 50 +++++++++++++++++++++++++++++ tools/xenstat/libxenstat/src/xenstat.h | 15 +++++++++ tools/xenstat/libxenstat/src/xenstat_priv.h | 5 +++ tools/xenstat/xentop/xentop.c | 36 +++++++++++++++++++++ 4 files changed, 106 insertions(+) diff --git a/tools/xenstat/libxenstat/src/xenstat.c b/tools/xenstat/libxenstat/src/xenstat.c index 6f93d4e..cfb6504 100644 --- a/tools/xenstat/libxenstat/src/xenstat.c +++ b/tools/xenstat/libxenstat/src/xenstat.c @@ -134,6 +134,9 @@ void xenstat_uninit(xenstat_handle * handle) xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) { #define DOMAIN_CHUNK_SIZE 256 + xc_cpuinfo_t *cpuinfo; + int max_cpus, nr_cpus; + xenstat_node *node; xc_physinfo_t physinfo = { 0 }; xc_domaininfo_t domaininfo[DOMAIN_CHUNK_SIZE]; @@ -163,6 +166,28 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) * handle->page_size; node->freeable_mb = 0; + + max_cpus = node->num_cpus; + + cpuinfo = calloc(max_cpus, sizeof(xc_cpuinfo_t)); + if (!cpuinfo) + return NULL; + + if (xc_getcpuinfo(handle->xc_handle, max_cpus, cpuinfo, &nr_cpus) < 0) { + free(cpuinfo); + return NULL; + } + + for ( i = 0; i < nr_cpus; i++) { + node->idle_time += cpuinfo[i].idletime; + node->hyp_time += cpuinfo[i].hyptime; + node->guest_time += cpuinfo[i].guesttime; + node->gsync_time += cpuinfo[i].gsynctime; + node->irq_time += cpuinfo[i].irqtime; + } + + free(cpuinfo); + /* malloc(0) is not portable, so allocate a single domain. This will * be resized below. */ node->domains = malloc(sizeof(xenstat_domain)); @@ -332,6 +357,31 @@ unsigned long long xenstat_node_cpu_hz(xenstat_node * node) return node->cpu_hz; } +unsigned long long xenstat_node_idle_time(xenstat_node * node) +{ + return node->idle_time; +} + +unsigned long long xenstat_node_guest_time(xenstat_node * node) +{ + return node->guest_time; +} + +unsigned long long xenstat_node_hyp_time(xenstat_node * node) +{ + return node->hyp_time; +} + +unsigned long long xenstat_node_gsync_time(xenstat_node * node) +{ + return node->gsync_time; +} + +unsigned long long xenstat_node_irq_time(xenstat_node * node) +{ + return node->irq_time; +} + /* Get the domain ID for this domain */ unsigned xenstat_domain_id(xenstat_domain * domain) { diff --git a/tools/xenstat/libxenstat/src/xenstat.h b/tools/xenstat/libxenstat/src/xenstat.h index 76a660f..9881ce5 100644 --- a/tools/xenstat/libxenstat/src/xenstat.h +++ b/tools/xenstat/libxenstat/src/xenstat.h @@ -80,6 +80,21 @@ unsigned int xenstat_node_num_cpus(xenstat_node * node); /* Get information about the CPU speed */ unsigned long long xenstat_node_cpu_hz(xenstat_node * node); +/* Get information about the CPU idle time */ +unsigned long long xenstat_node_idle_time(xenstat_node * node); + +/* Get information about the CPU guest execution time */ +unsigned long long xenstat_node_guest_time(xenstat_node * node); + +/* Get information about the CPU hypervisor execution time */ +unsigned long long xenstat_node_hyp_time(xenstat_node * node); + +/* Get information about the CPU guest syncronous trap execution time */ +unsigned long long xenstat_node_gsync_time(xenstat_node * node); + +/* Get information about the CPU IRQ serving time */ +unsigned long long xenstat_node_irq_time(xenstat_node * node); + /* * Domain functions - extract information from a xenstat_domain */ diff --git a/tools/xenstat/libxenstat/src/xenstat_priv.h b/tools/xenstat/libxenstat/src/xenstat_priv.h index 4eb44a8..64387cd 100644 --- a/tools/xenstat/libxenstat/src/xenstat_priv.h +++ b/tools/xenstat/libxenstat/src/xenstat_priv.h @@ -45,6 +45,11 @@ struct xenstat_node { unsigned int flags; unsigned long long cpu_hz; unsigned int num_cpus; + unsigned long long hyp_time; + unsigned long long guest_time; + unsigned long long idle_time; + unsigned long long gsync_time; + unsigned long long irq_time; unsigned long long tot_mem; unsigned long long free_mem; unsigned int num_domains; diff --git a/tools/xenstat/xentop/xentop.c b/tools/xenstat/xentop/xentop.c index af11ebf..7514559 100644 --- a/tools/xenstat/xentop/xentop.c +++ b/tools/xenstat/xentop/xentop.c @@ -930,6 +930,40 @@ void adjust_field_widths(xenstat_domain *domain) fields[FIELD_VBD_WSECT-1].default_width = length; } +void do_utilization(void) +{ + double us_elapsed = 0.0, + us_hyp = 0.0, + us_guest = 0.0, + us_idle = 0.0, + us_gsync = 0.0, + us_irq = 0.0; + + /* Can't calculate CPU percentage without a current and a previous sample.*/ + if(prev_node != NULL && cur_node != NULL) { + + /* Calculate the time elapsed in microseconds */ + us_elapsed = ((curtime.tv_sec-oldtime.tv_sec)*1000000.0 + +(curtime.tv_usec - oldtime.tv_usec)); + + /* In the following, nanoseconds must be multiplied by 1000.0 to + * convert to microseconds, then divided by 100.0 to get a percentage, + * resulting in a multiplication by 10.0 */ + us_idle = ((xenstat_node_idle_time(cur_node) - + xenstat_node_idle_time(prev_node))/10.0)/us_elapsed; + us_guest = ((xenstat_node_guest_time(cur_node) - + xenstat_node_guest_time(prev_node))/10.0)/us_elapsed; + us_hyp = ((xenstat_node_hyp_time(cur_node) - + xenstat_node_hyp_time(prev_node))/10.0)/us_elapsed; + us_gsync = ((xenstat_node_gsync_time(cur_node) - + xenstat_node_gsync_time(prev_node))/10.0)/us_elapsed; + us_irq = ((xenstat_node_irq_time(cur_node) - + xenstat_node_irq_time(prev_node))/10.0)/us_elapsed; + } + + print("%%CPU(s): %6.1f gu, %6.1f gs, %6.1f ir, %6.1f hy, %6.1f id \n", + us_guest, us_gsync, us_irq, us_hyp, us_idle); +} /* Section printing functions */ /* Prints the top summary, above the domain table */ @@ -972,6 +1006,8 @@ void do_summary(void) used = xenstat_node_tot_mem(cur_node); freeable_mb = 0; + do_utilization(); + /* Dump node memory and cpu information */ if ( freeable_mb <= 0 ) print("Mem: %lluk total, %lluk used, %lluk free ",