From: Andrii Anisov <andrii.anisov@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
Andrii Anisov <andrii_anisov@epam.com>, Wei Liu <wl@xen.org>
Subject: [Xen-devel] [RFC 3/9] xentop: show CPU load information
Date: Wed, 11 Sep 2019 13:32:16 +0300 [thread overview]
Message-ID: <1568197942-15374-4-git-send-email-andrii.anisov@gmail.com> (raw)
In-Reply-To: <1568197942-15374-1-git-send-email-andrii.anisov@gmail.com>
From: Andrii Anisov <andrii_anisov@epam.com>
Let xentop request and show information about CPU load provided
by new time accounting infrastructure.
Signed-off-by: Andrii Anisov <andrii_anisov@epam.com>
---
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 ",
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-09-11 10:33 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-11 10:32 [Xen-devel] [RFC 0/9] Changes to time accounting Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 1/9] schedule: Introduce per-pcpu " Andrii Anisov
2019-09-11 18:01 ` Volodymyr Babchuk
2019-09-12 10:26 ` Andrii Anisov
2019-10-28 14:28 ` Julien Grall
2019-11-06 11:24 ` Andrii Anisov
2020-05-26 2:27 ` Volodymyr Babchuk
2020-05-29 8:48 ` Dario Faggioli
2020-06-02 1:12 ` Volodymyr Babchuk
2020-06-03 15:22 ` Dario Faggioli
2019-09-11 10:32 ` [Xen-devel] [RFC 2/9] sysctl: extend XEN_SYSCTL_getcpuinfo interface Andrii Anisov
2019-10-28 14:52 ` Julien Grall
2019-11-06 11:25 ` Andrii Anisov
2019-09-11 10:32 ` Andrii Anisov [this message]
2019-09-11 10:32 ` [Xen-devel] [RFC 4/9] arm64: utilize time accounting Andrii Anisov
2019-09-11 17:48 ` Volodymyr Babchuk
2019-09-12 12:09 ` Andrii Anisov
2019-09-12 12:17 ` Julien Grall
2019-09-12 12:29 ` Andrii Anisov
2019-10-28 14:47 ` Julien Grall
2019-11-06 11:31 ` Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 5/9] tacc: Introduce a lockless interface for guest time Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 6/9] sched:rtds: get guest time from time accounting code Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 7/9] tacc: Introduce a locked interface for guest time Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 8/9] sched:credit: get guest time from time accounting code Andrii Anisov
2019-09-11 10:32 ` [Xen-devel] [RFC 9/9] sched:credit2: " Andrii Anisov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1568197942-15374-4-git-send-email-andrii.anisov@gmail.com \
--to=andrii.anisov@gmail.com \
--cc=andrii_anisov@epam.com \
--cc=ian.jackson@eu.citrix.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).