From patchwork Sun Jul 2 23:34:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 9821837 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B7C9D60246 for ; Sun, 2 Jul 2017 23:36:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 939C1204C1 for ; Sun, 2 Jul 2017 23:36:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87B562097A; Sun, 2 Jul 2017 23:36:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1341C204C1 for ; Sun, 2 Jul 2017 23:36:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dRoNb-0002ha-M3; Sun, 02 Jul 2017 23:34:15 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dRoNa-0002hO-GM for xen-devel@lists.xen.org; Sun, 02 Jul 2017 23:34:14 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id C5/6D-02962-5F289595; Sun, 02 Jul 2017 23:34:13 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprDIsWRWlGSWpSXmKPExsXSO6nOVfdrU2S kwcnXvBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bBj99YCraoVzRt2sTSwPhJtouRk0NIoJ1J Ytcz/y5GLiD7K6PEmVWr2CGcDYwShw++YoSo6maUuLbCAsRmE9CRmHbgFAuILSIgLXHt82WwG mYBI4mX+68xdzFycAgLuEp87mQHMVkEVCX2fgfr5BVwl1i8cyU7iC0hICdx81wnWDWngIfE+j 95EIvcJR4ufMACUWIs0Terj2UCI98CRoZVjBrFqUVlqUW6huZ6SUWZ6RkluYmZObqGBmZ6uan FxYnpqTmJScV6yfm5mxiBIcIABDsYb28MOMQoycGkJMq78lpopBBfUn5KZUZicUZ8UWlOavEh Rg0ODoG+NasvMEqx5OXnpSpJ8KY2RkYKCRalpqdWpGXmAIMYplSCg0dJhPeaD1Cat7ggMbc4M x0idYrRkuNO34YvTByrZv78xsTxasL/b0xCYPOkxHnFQeYJgDRklObBjYNF2iVGWSlhXkagY4 V4ClKLcjNLUOVfMYpzMCoJ8+5qAJrCk5lXArf1FdBBTEAHNfREgBxUkoiQkmpgjDp+5ILey8M Jux9OL2eaNF9zT42bkd739+KfPsc9EpJr/r/Ldr/4m1Af3k9Cy5a5NZ57mSztd/tw8WJLPxl3 tSR/kQzPhif5/gfvC9vt2bax98du9r8BB/Weu2j1nuFNKu7Y6Ba/vLDDv1ou/8ytFpfLXLO2G 7hM9zK9zO7+ZX9m8IcPzo/mKbEUZyQaajEXFScCANoierCvAgAA X-Env-Sender: dongli.zhang@oracle.com X-Msg-Ref: server-13.tower-21.messagelabs.com!1499038451!65459159!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 61724 invoked from network); 2 Jul 2017 23:34:12 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-13.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Jul 2017 23:34:12 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v62NY6Q2001661 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 2 Jul 2017 23:34:07 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id v62NY6BZ029623 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 2 Jul 2017 23:34:06 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id v62NY3os012576; Sun, 2 Jul 2017 23:34:04 GMT Received: from linux.cn.oracle.com (/10.182.70.224) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 02 Jul 2017 16:34:03 -0700 From: Dongli Zhang To: xen-devel@lists.xen.org Date: Mon, 3 Jul 2017 07:34:13 +0800 Message-Id: <1499038453-17050-2-git-send-email-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499038453-17050-1-git-send-email-dongli.zhang@oracle.com> References: <1499038453-17050-1-git-send-email-dongli.zhang@oracle.com> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com Subject: [Xen-devel] [PATCH v2 2/2] tools: utility to dump guest grant table info X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP As both xen-netfront and xen-blkfront support multi-queue, they would consume a lot of grant table references when there are many paravirtual devices and vcpus assigned to guest. Guest domU might panic or hang due to grant allocation failure when nr_grant_frames in guest has reached its max value. This utility would help the administrators to diagnose xen issue. There is only one command gnttab_query_size so far to monitor the guest grant table frame usage on dom0 side so that it is not required to debug on guest kernel side for crash/hang analysis anymore. It is extensible for adding new commands for more diagnostic functions and the framework of xen-diag.c is from xen-livepatch.c. Signed-off-by: Dongli Zhang Acked-by: Wei Liu --- Changed since v1: * rewrite xen-gnttab-query.c to xen-diag.c based on livepatch.c framework --- tools/misc/Makefile | 4 ++ tools/misc/xen-diag.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 tools/misc/xen-diag.c diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 8152f7b..c1113b9 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -31,6 +31,7 @@ INSTALL_SBIN += xenperf INSTALL_SBIN += xenpm INSTALL_SBIN += xenwatchdogd INSTALL_SBIN += xen-livepatch +INSTALL_SBIN += xen-diag INSTALL_SBIN += $(INSTALL_SBIN-y) # Everything to be installed in a private bin/ @@ -102,6 +103,9 @@ xenwatchdogd: xenwatchdogd.o xen-livepatch: xen-livepatch.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) +xen-diag: xen-diag.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) + xen-lowmemd: xen-lowmemd.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) diff --git a/tools/misc/xen-diag.c b/tools/misc/xen-diag.c new file mode 100644 index 0000000..1da50e1 --- /dev/null +++ b/tools/misc/xen-diag.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static xc_interface *xch; + +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) + +void show_help(void) +{ + fprintf(stderr, + "xen-diag: xen diagnostic utility\n" + "Usage: xen-diag command [args]\n" + "Commands:\n" + " help display this help\n" + " gnttab_query_size dump the current and max grant frames for \n"); +} + +/* wrapper function */ +static int help_func(int argc, char *argv[]) +{ + show_help(); + return 0; +} + +static int gnttab_query_size_func(int argc, char *argv[]) +{ + int domid, rc = 1; + struct gnttab_query_size query; + + if ( argc != 1 ) + { + show_help(); + return rc; + } + + domid = strtol(argv[0], NULL, 10); + query.dom = domid; + rc = xc_gnttab_query_size(xch, &query); + + if ( rc == 0 && (query.status == GNTST_okay) ) + printf("domid=%d: nr_frames=%d, max_nr_frames=%d\n", + query.dom, query.nr_frames, query.max_nr_frames); + + return rc == 0 && (query.status == GNTST_okay) ? 0 : 1; +} + +struct { + const char *name; + int (*function)(int argc, char *argv[]); +} main_options[] = { + { "help", help_func }, + { "gnttab_query_size", gnttab_query_size_func}, +}; + +int main(int argc, char *argv[]) +{ + int ret, i; + + /* + * Set stdout to be unbuffered to avoid having to fflush when + * printing without a newline. + */ + setvbuf(stdout, NULL, _IONBF, 0); + + if ( argc <= 1 ) + { + show_help(); + return 0; + } + + for ( i = 0; i < ARRAY_SIZE(main_options); i++ ) + if ( !strncmp(main_options[i].name, argv[1], strlen(argv[1])) ) + break; + + if ( i == ARRAY_SIZE(main_options) ) + { + show_help(); + return 0; + } + else + { + xch = xc_interface_open(0, 0, 0); + if ( !xch ) + { + fprintf(stderr, "failed to get the handler\n"); + return 0; + } + + ret = main_options[i].function(argc - 2, argv + 2); + + xc_interface_close(xch); + } + + /* + * Exitcode 0 for success. + * Exitcode 1 for an error. + * Exitcode 2 if the operation should be retried for any reason (e.g. a + * timeout or because another operation was in progress). + */ + +#define EXIT_TIMEOUT (EXIT_FAILURE + 1) + + BUILD_BUG_ON(EXIT_SUCCESS != 0); + BUILD_BUG_ON(EXIT_FAILURE != 1); + BUILD_BUG_ON(EXIT_TIMEOUT != 2); + + switch ( ret ) + { + case 0: + return EXIT_SUCCESS; + case EAGAIN: + case EBUSY: + return EXIT_TIMEOUT; + default: + return EXIT_FAILURE; + } +}