From nobody Thu Oct 30 22:53:22 2025 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; 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=fail(p=none dis=none) header.from=renesas.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1756895041723454.16129264062306; Wed, 3 Sep 2025 03:24:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1108054.1458197 (Exim 4.92) (envelope-from ) id 1utkeb-0001R5-DF; Wed, 03 Sep 2025 10:23:49 +0000 Received: by outflank-mailman (output) from mailman id 1108054.1458197; Wed, 03 Sep 2025 10:23:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1utkeb-0001Qw-AD; Wed, 03 Sep 2025 10:23:49 +0000 Received: by outflank-mailman (input) for mailman id 1108054; Wed, 03 Sep 2025 10:23:47 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1utkeZ-0001Ah-Km for xen-devel@lists.xenproject.org; Wed, 03 Sep 2025 10:23:47 +0000 Received: from rein-hpcbdc09 (unknown [1.6.89.6]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 120b53b1-88b0-11f0-9809-7dc792cee155; Wed, 03 Sep 2025 12:23:45 +0200 (CEST) Received: by rein-hpcbdc09 (Postfix, from userid 1000) id 6175880C06CE; Wed, 3 Sep 2025 15:53:44 +0530 (IST) 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: 120b53b1-88b0-11f0-9809-7dc792cee155 From: Jahan Murudi To: xen-devel@lists.xenproject.org Cc: Jahan Murudi , Anthony PERARD Subject: [PATCH v4 1/4] xentop: add pcpu header and basic infrastructure Date: Wed, 3 Sep 2025 15:53:20 +0530 Message-Id: <20250903102323.2553142-2-jahan.murudi.zg@renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250903102323.2553142-1-jahan.murudi.zg@renesas.com> References: <20250903102323.2553142-1-jahan.murudi.zg@renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1756895044762124100 Content-Type: text/plain; charset="utf-8" Introduce a new header (pcpu.h) which defines the interfaces for physical CPU statistics collection. This provides the basic infrastructure needed to track per-CPU usage and will be used in subsequent patches. Signed-off-by: Jahan Murudi --- tools/xentop/pcpu.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tools/xentop/pcpu.h diff --git a/tools/xentop/pcpu.h b/tools/xentop/pcpu.h new file mode 100644 index 0000000000..a528177476 --- /dev/null +++ b/tools/xentop/pcpu.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2025 Renesas Electronics Corporation + */ + +#ifndef __XENTOP_PCPU_H__ +#define __XENTOP_PCPU_H__ + +#include + +int update_pcpu_stats(const struct timeval *now, unsigned int delay); +int get_pcpu_count(void); +float get_pcpu_usage(int cpu_index); +int has_pcpu_data(void); +void free_pcpu_stats(void); + +#endif /* __XENTOP_PCPU_H__ */ --=20 2.34.1 From nobody Thu Oct 30 22:53:22 2025 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; 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=fail(p=none dis=none) header.from=renesas.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1756895054504296.78838518182874; Wed, 3 Sep 2025 03:24:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1108060.1458207 (Exim 4.92) (envelope-from ) id 1utkeo-0001wH-KR; Wed, 03 Sep 2025 10:24:02 +0000 Received: by outflank-mailman (output) from mailman id 1108060.1458207; Wed, 03 Sep 2025 10:24:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1utkeo-0001w6-Hd; Wed, 03 Sep 2025 10:24:02 +0000 Received: by outflank-mailman (input) for mailman id 1108060; Wed, 03 Sep 2025 10:24:01 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1utkem-0001Ah-Ua for xen-devel@lists.xenproject.org; Wed, 03 Sep 2025 10:24:00 +0000 Received: from rein-hpcbdc09 (unknown [1.6.89.6]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 19e2120a-88b0-11f0-9809-7dc792cee155; Wed, 03 Sep 2025 12:23:59 +0200 (CEST) Received: by rein-hpcbdc09 (Postfix, from userid 1000) id 871E680C0822; Wed, 3 Sep 2025 15:53:57 +0530 (IST) 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: 19e2120a-88b0-11f0-9809-7dc792cee155 From: Jahan Murudi To: xen-devel@lists.xenproject.org Cc: Jahan Murudi , Anthony PERARD Subject: [PATCH v4 2/4] xentop: add pcpu implementation with proper error handling Date: Wed, 3 Sep 2025 15:53:21 +0530 Message-Id: <20250903102323.2553142-3-jahan.murudi.zg@renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250903102323.2553142-1-jahan.murudi.zg@renesas.com> References: <20250903102323.2553142-1-jahan.murudi.zg@renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1756895054986116600 Content-Type: text/plain; charset="utf-8" Introduce pcpu.c which implements physical CPU statistics collection using xc_getcpuinfo(). The code handles allocation and reallocation of statistics buffers, maintains previous idle times, and calculates usage percentages. Proper error handling and cleanup are provided to ensure robustness in the face of allocation or hypervisor API failures. Signed-off-by: Jahan Murudi --- tools/xentop/pcpu.c | 141 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 tools/xentop/pcpu.c diff --git a/tools/xentop/pcpu.c b/tools/xentop/pcpu.c new file mode 100644 index 0000000000..cdb4cb2131 --- /dev/null +++ b/tools/xentop/pcpu.c @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2025 Renesas Electronics Corporation + */ + +#include +#include +#include +#include +#include +#include +#include "pcpu.h" + +#define MAX_PCPUS 128 + +typedef struct { + float usage_pct; +} pcpu_stat_t; + +static pcpu_stat_t *pcpu_stats =3D NULL; +static uint64_t *prev_idle =3D NULL; +static int allocated_pcpus =3D 0; +static xc_interface *xc_handle =3D NULL; +static uint64_t prev_global_time =3D 0; + +static void report_pcpu_error(const char *context) +{ + fprintf(stderr, "PCPU error: %s (%s)\n", context, strerror(errno)); +} + +int update_pcpu_stats(const struct timeval *now, unsigned int delay_sec) +{ + struct xen_sysctl_cpuinfo info[MAX_PCPUS]; + int detected_cpus =3D 0; + int ret, i; + uint64_t current_time =3D (uint64_t)now->tv_sec * 1000000ULL + now->tv= _usec; + uint64_t time_diff; + + if (!xc_handle) { + xc_handle =3D xc_interface_open(NULL, NULL, 0); + if (!xc_handle) { + report_pcpu_error("xc_interface_open failed"); + return -1; + } + } + + ret =3D xc_getcpuinfo(xc_handle, MAX_PCPUS, info, &detected_cpus); + if (ret < 0) { + report_pcpu_error("xc_getcpuinfo failed"); + return -1; + } + + /* Allocate/reallocate memory if needed */ + if (!pcpu_stats || detected_cpus > allocated_pcpus) { + pcpu_stat_t *new_stats =3D realloc(pcpu_stats, + detected_cpus * sizeof(*pcpu_stats)); + if (!new_stats) goto alloc_error; + + pcpu_stats =3D new_stats; + + uint64_t *new_prev_idle =3D realloc(prev_idle, + detected_cpus * sizeof(*prev_idle)); + if (!new_prev_idle) goto alloc_error; + + prev_idle =3D new_prev_idle; + allocated_pcpus =3D detected_cpus; + + /* Initialize new entries */ + for (i =3D 0; i < detected_cpus; i++) { + prev_idle[i] =3D info[i].idletime / 1000; /* ns->us */ + pcpu_stats[i].usage_pct =3D 0.0; + } + + /* Set initial global time reference */ + prev_global_time =3D current_time; + return 0; + } + + /* Calculate time difference since last update */ + time_diff =3D current_time - prev_global_time; + + /* Calculate CPU usage for each core */ + for (i =3D 0; i < detected_cpus; i++) { + uint64_t current_idle =3D info[i].idletime / 1000; + uint64_t idle_diff =3D current_idle - prev_idle[i]; + + if (time_diff > 0) { + double usage =3D 100.0 * (1.0 - ((double)idle_diff / time_diff= )); + /* Clamp between 0-100% */ + pcpu_stats[i].usage_pct =3D (usage < 0) ? 0.0 : + (usage > 100) ? 100.0 : usage; + } else { + pcpu_stats[i].usage_pct =3D 0.0; + } + + prev_idle[i] =3D current_idle; + } + + /* Update global time reference for next calculation */ + prev_global_time =3D current_time; + + return 0; + +alloc_error: + free_pcpu_stats(); + errno =3D ENOMEM; + report_pcpu_error("memory allocation failed"); + return -1; +} + +/* Accessor functions for xentop.c */ +int get_pcpu_count(void) +{ + return allocated_pcpus; +} + +float get_pcpu_usage(int cpu_index) +{ + if (!pcpu_stats || cpu_index < 0 || cpu_index >=3D allocated_pcpus) { + return 0.0; + } + return pcpu_stats[cpu_index].usage_pct; +} + +int has_pcpu_data(void) +{ + return (pcpu_stats !=3D NULL && allocated_pcpus > 0); +} + +void free_pcpu_stats(void) +{ + if (xc_handle) { + xc_interface_close(xc_handle); + xc_handle =3D NULL; + } + free(pcpu_stats); + pcpu_stats =3D NULL; + free(prev_idle); + prev_idle =3D NULL; + allocated_pcpus =3D 0; +} --=20 2.34.1 From nobody Thu Oct 30 22:53:22 2025 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; 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=fail(p=none dis=none) header.from=renesas.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 175689505612221.281799390658648; Wed, 3 Sep 2025 03:24:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1108061.1458218 (Exim 4.92) (envelope-from ) id 1utkep-0002Bx-SF; Wed, 03 Sep 2025 10:24:03 +0000 Received: by outflank-mailman (output) from mailman id 1108061.1458218; Wed, 03 Sep 2025 10:24:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1utkep-0002Bo-Nl; Wed, 03 Sep 2025 10:24:03 +0000 Received: by outflank-mailman (input) for mailman id 1108061; Wed, 03 Sep 2025 10:24:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1utken-0001Ah-Uo for xen-devel@lists.xenproject.org; Wed, 03 Sep 2025 10:24:01 +0000 Received: from rein-hpcbdc09 (unknown [1.6.89.6]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1a6421f5-88b0-11f0-9809-7dc792cee155; Wed, 03 Sep 2025 12:23:59 +0200 (CEST) Received: by rein-hpcbdc09 (Postfix, from userid 1000) id 5F18480C094C; Wed, 3 Sep 2025 15:53:58 +0530 (IST) 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: 1a6421f5-88b0-11f0-9809-7dc792cee155 From: Jahan Murudi To: xen-devel@lists.xenproject.org Cc: Jahan Murudi , Anthony PERARD Subject: [PATCH v4 3/4] xentop: update Makefile to link against libxenctrl Date: Wed, 3 Sep 2025 15:53:22 +0530 Message-Id: <20250903102323.2553142-4-jahan.murudi.zg@renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250903102323.2553142-1-jahan.murudi.zg@renesas.com> References: <20250903102323.2553142-1-jahan.murudi.zg@renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1756895080487124100 Content-Type: text/plain; charset="utf-8" Update the build system so that xentop links against libxenctrl, which is required for retrieving per-CPU statistics via the hypervisor API. Also update the build rule to include the new pcpu.o object file. Signed-off-by: Jahan Murudi --- tools/xentop/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/xentop/Makefile b/tools/xentop/Makefile index 70cc2211c5..f514a6f7a8 100644 --- a/tools/xentop/Makefile +++ b/tools/xentop/Makefile @@ -15,6 +15,7 @@ include $(XEN_ROOT)/tools/Rules.mk =20 CFLAGS +=3D -DGCC_PRINTF $(CFLAGS_libxenstat) LDLIBS +=3D $(LDLIBS_libxenstat) $(CURSES_LIBS) $(TINFO_LIBS) $(SOCKET_LIB= S) -lm +LDLIBS +=3D $(LDLIBS_libxenctrl) CFLAGS +=3D -DHOST_$(XEN_OS) =20 # Include configure output (config.h) @@ -25,8 +26,8 @@ TARGETS :=3D xentop .PHONY: all all: $(TARGETS) =20 -xentop: xentop.o - $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS) $(APPEND_LDFLAGS) +xentop: xentop.o pcpu.o + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(APPEND_LDFLAGS) =20 .PHONY: install install: all --=20 2.34.1 From nobody Thu Oct 30 22:53:22 2025 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; 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=fail(p=none dis=none) header.from=renesas.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1756895058579138.86878231935532; Wed, 3 Sep 2025 03:24:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1108066.1458227 (Exim 4.92) (envelope-from ) id 1utkes-0002Tf-3f; Wed, 03 Sep 2025 10:24:06 +0000 Received: by outflank-mailman (output) from mailman id 1108066.1458227; Wed, 03 Sep 2025 10:24:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1utker-0002TW-V1; Wed, 03 Sep 2025 10:24:05 +0000 Received: by outflank-mailman (input) for mailman id 1108066; Wed, 03 Sep 2025 10:24:05 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1utker-0001Ah-Jm for xen-devel@lists.xenproject.org; Wed, 03 Sep 2025 10:24:05 +0000 Received: from rein-hpcbdc09 (unknown [1.6.89.6]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1ca9427b-88b0-11f0-9809-7dc792cee155; Wed, 03 Sep 2025 12:24:03 +0200 (CEST) Received: by rein-hpcbdc09 (Postfix, from userid 1000) id 3254980C094F; Wed, 3 Sep 2025 15:54:02 +0530 (IST) 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: 1ca9427b-88b0-11f0-9809-7dc792cee155 From: Jahan Murudi To: xen-devel@lists.xenproject.org Cc: Jahan Murudi , Anthony PERARD Subject: [PATCH v4 4/4] xentop: integrate pcpu support into main program Date: Wed, 3 Sep 2025 15:53:23 +0530 Message-Id: <20250903102323.2553142-5-jahan.murudi.zg@renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250903102323.2553142-1-jahan.murudi.zg@renesas.com> References: <20250903102323.2553142-1-jahan.murudi.zg@renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1756895058920116600 Content-Type: text/plain; charset="utf-8" Integrate physical CPU usage statistics into xentop. This patch adds: - a new command-line option (-p, --pcpus) - display of per-CPU usage statistics - cleanup of pcpu resources on exit This allows users to monitor host physical CPU utilization alongside existing domain metrics. Signed-off-by: Jahan Murudi --- tools/xentop/xentop.c | 79 +++++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 18 deletions(-) diff --git a/tools/xentop/xentop.c b/tools/xentop/xentop.c index f5d6c19cf9..addb1c70c9 100644 --- a/tools/xentop/xentop.c +++ b/tools/xentop/xentop.c @@ -37,6 +37,7 @@ #endif =20 #include +#include "pcpu.h" =20 #define XENTOP_VERSION "1.0" =20 @@ -205,6 +206,7 @@ field_id sort_field =3D FIELD_DOMID; unsigned int first_domain_index =3D 0; unsigned int delay =3D 3; unsigned int batch =3D 0; +static unsigned int show_pcpus =3D 0; unsigned int loop =3D 1; unsigned int iterations =3D 0; int show_vcpus =3D 0; @@ -230,22 +232,23 @@ static WINDOW *cwin; /* Print usage message, using given program name */ static void usage(const char *program) { - printf("Usage: %s [OPTION]\n" - "Displays ongoing information about xen vm resources \n\n" - "-h, --help display this help and exit\n" - "-V, --version output version information and exit\n" - "-d, --delay=3DSECONDS seconds between updates (default 3)\n" - "-n, --networks output vif network data\n" - "-x, --vbds output vbd block device data\n" - "-r, --repeat-header repeat table header before each domain\n" - "-v, --vcpus output vcpu data\n" - "-b, --batch output in batch mode, no user input accepted\n" - "-i, --iterations number of iterations before exiting\n" - "-f, --full-name output the full domain name (not truncated)\= n" - "-z, --dom0-first display dom0 first (ignore sorting)\n" - "\n" XENTOP_BUGSTO, - program); - return; + printf("Usage: %s [OPTION]\n" + "Displays ongoing information about xen vm resources \n\n" + "-h, --help display this help and exit\n" + "-V, --version output version information and exit\n" + "-d, --delay=3DSECONDS seconds between updates (default 3)\n" + "-n, --networks output vif network data\n" + "-x, --vbds output vbd block device data\n" + "-r, --repeat-header repeat table header before each domain\n" + "-v, --vcpus output vcpu data\n" + "-b, --batch output in batch mode, no user input accep= ted\n" + "-p, --pcpus show physical CPU stats\n" + "-i, --iterations number of iterations before exiting\n" + "-f, --full-name output the full domain name (not truncate= d)\n" + "-z, --dom0-first display dom0 first (ignore sorting)\n" + "\n" XENTOP_BUGSTO, + program); + return; } =20 /* Print program version information */ @@ -267,6 +270,8 @@ static void cleanup(void) xenstat_free_node(cur_node); if(xhandle !=3D NULL) xenstat_uninit(xhandle); + + free_pcpu_stats(); } =20 /* Display the given message and gracefully exit */ @@ -313,6 +318,32 @@ static void print(const char *fmt, ...) } } =20 +/* PCPU statistics display function */ +static void print_pcpu_stats_display(void) +{ + int i; + int num_cpus; + + if (!has_pcpu_data()) { + print("\nNo PCPU data available\n"); + return; + } + + num_cpus =3D get_pcpu_count(); + + /* Use the existing print() function which handles cursor bounds */ + print("\nPhysical CPU Usage:\n"); + print("+-------+--------+\n"); + print("| Core | Usage |\n"); + print("+-------+--------+\n"); + + for (i =3D 0; i < num_cpus; i++) { + print("| %-5d | %5.1f%% |\n", i, get_pcpu_usage(i)); + } + + print("+-------+--------+\n"); +} + static void xentop_attron(int attr) { if (!batch) @@ -1245,6 +1276,14 @@ static void top(void) do_vbd(domains[i]); } =20 + if (show_pcpus) { + if (update_pcpu_stats(&curtime, delay) =3D=3D 0) { + print_pcpu_stats_display(); + } else { + fail("Error getting PCPU stats\n"); + } + } + if (!batch) do_bottom_line(); =20 @@ -1271,13 +1310,14 @@ int main(int argc, char **argv) { "repeat-header", no_argument, NULL, 'r' }, { "vcpus", no_argument, NULL, 'v' }, { "delay", required_argument, NULL, 'd' }, - { "batch", no_argument, NULL, 'b' }, + { "batch", no_argument, NULL, 'b' }, + { "pcpus", no_argument, NULL, 'p' }, { "iterations", required_argument, NULL, 'i' }, { "full-name", no_argument, NULL, 'f' }, { "dom0-first", no_argument, NULL, 'z' }, { 0, 0, 0, 0 }, }; - const char *sopts =3D "hVnxrvd:bi:fz"; + const char *sopts =3D "hVnxrvd:bpi:fz"; =20 if (atexit(cleanup) !=3D 0) fail("Failed to install cleanup handler.\n"); @@ -1312,6 +1352,9 @@ int main(int argc, char **argv) case 'b': batch =3D 1; break; + case 'p': + show_pcpus =3D 1; + break; case 'i': iterations =3D atoi(optarg); loop =3D 0; --=20 2.34.1