From patchwork Fri Nov 19 19:51:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Kanda X-Patchwork-Id: 12629437 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91FFEC433EF for ; Fri, 19 Nov 2021 19:53:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 19C8B61AFF for ; Fri, 19 Nov 2021 19:53:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 19C8B61AFF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:41350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mo9x5-0007C9-46 for qemu-devel@archiver.kernel.org; Fri, 19 Nov 2021 14:53:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mo9vf-0005T8-1Q for qemu-devel@nongnu.org; Fri, 19 Nov 2021 14:52:12 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:24936) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mo9vc-0001Lw-4t for qemu-devel@nongnu.org; Fri, 19 Nov 2021 14:52:10 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AJIUJB2027682; Fri, 19 Nov 2021 19:52:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=E/eaho/x5cfhPMODmzB5J7492lsQV58yWTibmFBgPQ4=; b=GeFfIcPnyDJ1ayeKJo+SmhuQIIeaumSD33Hi1y9JOyr3/cg109ENHcUmd8ebAjbYKX7T 5poATWh0bE8tD1cM1hRmx7jemW6tZYjKo0rbIMDv5f0MAY73wGp7+1IJQyKpKGRTYYhy TU/GhMP5BIE7t/30FkqAuaC1JzHE/kbwU9wxSiGR/CYUOVi9seT7PqaBjy0u65BnYp2h xres3S84dTIVp/DN7UA4wftU0/+uy8jZ7Pldm3fkDgHmFsMpfDc0crb3dANeiwql+7yS 8NhJU1ITzKk84yQiAKwlKzxaMhaMzdvlO6+JoXoBaEwon6tCKHtILkLzeakkA+PffxTg XQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3cefpbh4fb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Nov 2021 19:52:04 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1AJJlDMc112819; Fri, 19 Nov 2021 19:52:03 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2103.outbound.protection.outlook.com [104.47.58.103]) by userp3020.oracle.com with ESMTP id 3caq4ycm7c-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Nov 2021 19:52:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ak5xPl25uL1YwCEcdxOcv6Ekwz8jx2HD0BsVABSO0wb8mxSuXmaDSRMVNvq0sJOdVcTZo1P7GAVWFU1sOZOJt07Ww/IGn1RCpT4vnKUimMZxDfConmQJD7dPIfXmj5WAkszz6AgTlXZJAv71ASThaOZnYmHFALMpuIqfZYHshy7xSOWuKpSw74Tq7/dV9kwHAUQ5m/021EGTDcR77ilpzP6b8PUjF3cZCFWvSayUDd6Kya47+TLzQIvwE2iL0AYYqfZuIFbqrpzWcOySqAANUWyWoEKhnqiyu2bUYnnd65kE/jWcAs3W9iqHGwuzLKvmYsBxOUR3DGjPzJ8dOKobfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E/eaho/x5cfhPMODmzB5J7492lsQV58yWTibmFBgPQ4=; b=Vy/DPpOcijda58z9OqYUAMTZNWfddA5FugOk6WeVboa6tpuSF2Ju7SBHx0eqdfD/Kq4o3phHE5izoKu0kiJ26dA6XtMfPIBAZjnqLNBHI8jN0iu1E4LMa4OMZ0maJSz4MlcfjSZ29xeMb5ox+ixUj+bu6HfjeDkwEo/poDTeHOhPZEzT1G9cNu+u+tlpE/64WtZz8MHtQqeB0382zAvVO8enIhdVBSW+mQnhUXToaqbP8JLNNWT6AvGXHX9yPdVCyLJripQkIYoJoAmmKIiUjUD88I43AdLvFd6WkjqfJnLpe0Qu+oOmD09nTAtU0b6oWmC/JDJ33+MSpYl1lGZ03Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E/eaho/x5cfhPMODmzB5J7492lsQV58yWTibmFBgPQ4=; b=xQ1h9BFBuPULloGoZY8EIxeylhi0VJXHHDK7optaTsVi2JqxNVi/Dh78bqCuncU9bnRPFp3FrECtI7YbIEOAkbNylZKDOGsXLpAqxNAS4e+TYXuEOt/7/YhVS9vKqS5kcXg8A9Sor+gKmlF3o5ker4+uKdz8xaA6x0Js73xAcgs= Received: from SA1PR10MB5841.namprd10.prod.outlook.com (2603:10b6:806:22b::16) by SA2PR10MB4603.namprd10.prod.outlook.com (2603:10b6:806:119::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.20; Fri, 19 Nov 2021 19:52:01 +0000 Received: from SA1PR10MB5841.namprd10.prod.outlook.com ([fe80::8156:fe6f:d62c:5dd6]) by SA1PR10MB5841.namprd10.prod.outlook.com ([fe80::8156:fe6f:d62c:5dd6%7]) with mapi id 15.20.4713.022; Fri, 19 Nov 2021 19:52:01 +0000 From: Mark Kanda To: qemu-devel@nongnu.org Subject: [PATCH v2 1/3] qmp: Support for querying stats Date: Fri, 19 Nov 2021 13:51:51 -0600 Message-Id: <20211119195153.11815-2-mark.kanda@oracle.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211119195153.11815-1-mark.kanda@oracle.com> References: <20211119195153.11815-1-mark.kanda@oracle.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To SA1PR10MB5841.namprd10.prod.outlook.com (2603:10b6:806:22b::16) MIME-Version: 1.0 Received: from linux-1.us.oracle.com (137.254.7.175) by SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22 via Frontend Transport; Fri, 19 Nov 2021 19:52:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e0dfafe1-8299-4e2a-b396-08d9ab960dbd X-MS-TrafficTypeDiagnostic: SA2PR10MB4603: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oIraXwYK7ZYxPFKp0gbCNxl2k8baBpKNviPzE6h2uST2A3BUHDffczFXVGadxWr2dy243Fjgnix/dG5vQlm5KdYFrzbjIVmp07CsZtp5kY4U0vyTB5AxbuiU0JTGUubpjUTS+habSRoVweJ+MunGUhPLAR4RhenLf+05+3PkakdFdL6mrGVTdq2xvF4232i/Iwl3pZijW89m/LknN0q4wZqM19P8hYzuz1K8CxEex35YcEcCgQ+ivrbfU1f1cWbc7tDy8NoYky/F/dJXKGLMcx1B9LSDhK3wMdc0wmgMxMFRUUTpLTPRldveKRfpva+tkq/XnOBlDP1dJsMdHZN4NvflMihGfW+NXqXQXSKvzJV7YQCr/F15XE+6Fuf5tIuQWl5wTmVF4Gr4sgwO6a2t9KZ3hXPd2UF88YzQd2+HafcFVqkF+D9FhQuofEbVFpht0CTNX/QDUk1Xgg9FgYXUeuhkzrYeQqA0nBIYNtuKwt2feSYKfYY2L8M1pGDDAOAEa/TsuV3vLvzgzBlZgQz/1XhLRjygmSOsR1tEKR0J7RyMWSoLXLKoy1CHGmORRKWruWXoANUVFHyplCpsoPsOrEx8v0XJssyezZOSHkkpHDh9PQFEMnraIKBDEwQafJeidUQe4ekrX5EzIkEWMAqVWkgrtzY5b0fOG+RNf6z8nkm3homKOAzz7ym7Gwm6gtoaFyUma+TFJTq8osLrKXTkjQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA1PR10MB5841.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(107886003)(8936002)(2906002)(508600001)(86362001)(38100700002)(36756003)(316002)(5660300002)(4326008)(1076003)(6666004)(38350700002)(8676002)(26005)(66476007)(7696005)(52116002)(6916009)(44832011)(6486002)(83380400001)(186003)(66946007)(66556008)(956004)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YsjOqzxKTumYQ5kdNSMO054dz+Fn9QCk4ZFu8Pok4ng7zcFl25vbgJXw8ucA9iye3DDBgjleerRObxsW4eNf8EBsy+SJV0BOiSjlhB3ln5KLrnG7hrrhZ0z5ExH8fah0zYIZ2MpIqKrkQhFfbaT7LKQcTfLMyLPPer6mXsSLg9AeMQaem8cu1iLa0of/QWyJ2BwgFCL0bHbCDCaEdO0afStdY1ykvFfQhhPigMIGj209dqP7oI8PzuQkbyU1izaXHxGCZRozJaVo0L4V8KcwV1Se0eGDWeaYGhA0oXCAszdYGiy4+O+EFd65pemlZdZC9dd1loyLIjWeN1tgUJqFIho9GytnWbBGsXtdrJJ+9uN9zGX9NQA4+E0IyPSCw0lxKKPX5cGkbwxO2P2SxpDUW3cVAmaLckAw6fSE9s56fAleDkKi1dc9yLBE8ALIv1kgrcD6F3/8zKFn9DZY7B1G7xY5XWsQGaCIaFvUKUVixHVAUPFUWhCevg2a8DFj2iQ22AD2mDpVgs+UT9xAkxLOZsByzTWlT//0MeIRqr8Tq15G7Hz7qmisB+e0zEDn+wahIMZDsg+a1ffl7OIq+q3C5sYpVzGyR79FEcwuYbTeZ7HBRuyPtZ9KCF1lwpd87BnIwRankEPYVkpMYYaE9me1vt5QEDo1YzfOWKVFzBcukXwDurxMJ2sjrWdUhgJ9JqBet9ZHOZrKn/akbjo3H5QJw9wZqHP/UPlA8H3wpZnyNPIJAtBGp0Dn527YRybYaUmd5qO4K4jXcYocKoCBuGHEemG7YE7J8tomOTOqK8nLvfwU4USJCA8z3miX+N4vlOooHRGhNQavDaBzPIQ8nv4Hi6FOEYN0TEkwL8g4zY4cOYjPyqRGRDGsRNsarOO+31jT3cXjxkCQq0OnO3K+dvF2c2QSYI7UW8o+OIZeEdwzoX93DqmDhC6TAE+v8msJK6Ra36Emm9gcLInFgFetaTmkX8IvsQ0kJiJ+xuoHu2e9utpPEjGiDsn8HAHXAPXrOF58oJBVjUscPQR3Y/zE/7HpwcJtjakb0sMXXsZQvH4Y0uL09+22XcOT7g6LfbyWX4AL5gKLQhw/0/nUtF01Ua5vtFqTetUaIQCmpPQGApHS3OzPmhRM+RFCh+xd/+6FxhChWlJ4iMD8qTG/Qil/QA2VmY5bA2bmQP97K+nJ8TaIsZXnvoigX79ajOW5VEdkUbGicsNs3vaal9VmjaxT9QRL0tVV6ZmKoadbXa3Jtv1EQcjS1Dtq3c958Ivu/VhsBGjIVki3CARci2B11LwTESDKJ5IB3ukndiIkS3DvChgbXMB4llBdVMXkS7NOfl1aL8WZewqF08D3K6jWGoqD8wgYpB1UgaY4+lgfdu+ygXn4cWd7YFrXAZO8FpuP6E6jtwZXJSHnqVAE1tLkYv6xtT/6gGztQlZwo4hUqO++TdkgeO44GmPQWlIXZ28gkyG976QpfghMvNHO0l7XIE31Il0by01tvPL0Kl3gvbPP46Y/mCDcwsL4vF7nGULazS6nCISthfcJH75mF/umySqIro0cJ1iKmgzu9cbCxwQrPSiu64aI3/66TIrpVnbIklf76qjVf8rSDrXAbJATBZNueAHMLEyBlcTrvUQXuCEAt3cyNsQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0dfafe1-8299-4e2a-b396-08d9ab960dbd X-MS-Exchange-CrossTenant-AuthSource: SA1PR10MB5841.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 19:52:01.5955 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QBT4B/fqkf+XyemOj46AD+L9uQgDXbBftNAHykY4is/ILix0Ta/MzfoobaRNYTniqPmWAagw/UxFJ213pclJyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4603 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10173 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111190106 X-Proofpoint-ORIG-GUID: mtUjwsPd0fsbpUSIfNVjlNqOsnJjGou4 X-Proofpoint-GUID: mtUjwsPd0fsbpUSIfNVjlNqOsnJjGou4 Received-SPF: pass client-ip=205.220.177.32; envelope-from=mark.kanda@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Introduce qmp support for querying stats. Provide a framework for adding new stats and support for the following commands: - query-stats Returns a list of all stats, with options for specifying a stat name and schema type. A schema type is the set of stats associated with a given component (e.g. vm or vcpu). - query-stats-schemas Returns a list of stats included in each schema type, with an option for specifying the schema name. - query-stats-instances Returns a list of stat instances and their associated schema type. The framework provides a method to register callbacks for these qmp commands. The first usecase will be for fd-based KVM stats (in an upcoming patch). Examples (with fd-based KVM stats): { "execute": "query-stats" } { "return": [ { "name": "vcpu_1", "type": "kvm-vcpu", "stats": [ { "name": "guest_mode", "unit": "none", "base": 10, "val": [ 0 ], "exponent": 0, "type": "instant" }, { "name": "directed_yield_successful", "unit": "none", "base": 10, "val": [ 0 ], "exponent": 0, "type": "cumulative" }, ... }, { "name": "vcpu_0", "type": "kvm-vcpu", "stats": ... ... }, { "name": "vm", "type": "kvm-vm", "stats": [ { "name": "max_mmu_page_hash_collisions", "unit": "none", "base": 10, "val": [ 0 ], "exponent": 0, "type": "peak" }, ... { "execute": "query-stats-schemas" } { "return": [ { "type": "kvm-vcpu", "stats": [ { "name": "guest_mode" }, { "name": "directed_yield_successful" }, ... }, { "type": "kvm-vm", "stats": [ { "name": "max_mmu_page_hash_collisions" }, { "name": "max_mmu_rmap_size" }, ... { "execute": "query-stats-instances" } { "return": [ { "name": "vcpu_1", "type": "kvm-vcpu" }, { "name": "vcpu_0", "type": "kvm-vcpu" }, { "name": "vm", "type": "kvm-vm" } ] } Signed-off-by: Mark Kanda --- include/monitor/monitor.h | 27 ++++++++ monitor/qmp-cmds.c | 71 +++++++++++++++++++ qapi/misc.json | 142 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 12d395d62d..14d3432ade 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -56,4 +56,31 @@ void monitor_register_hmp(const char *name, bool info, void monitor_register_hmp_info_hrt(const char *name, HumanReadableText *(*handler)(Error **errp)); +/* + * Add qmp stats callbacks to the stats_callbacks list. + * + * @name: name of stats callbacks + * @stats_fn: routine to query stats - with options for name and type: + * StatsList *(*stats_fn)(StatsList *list_tail, bool has_name, + * const char *name, bool has_type, const char *type, Error **errp) + * + * @schema_fn: routine to query stat schemas - with an option for type: + * StatsSchemaList *(*schemas_fn)(StatsSchemaList *list tail, bool has_type, + * const char *type, Error **errp) + * + * @instance_fn: routine to query stat instances: + * StatsInstanceList *(*instances_fn)(StatsInstanceList *list_tail, + * Error **errp) + */ +void add_stats_callbacks(const char *name, + StatsList *(*stats_fn)(StatsList *, + bool, const char *, + bool, const char *, + Error **), + StatsSchemaList *(*schemas_fn)(StatsSchemaList *, + bool, const char *, + Error **), + StatsInstanceList *(*instances_fn)(StatsInstanceList *, + Error **)); + #endif /* MONITOR_H */ diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 343353e27a..c7bdff1e1c 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -466,3 +466,74 @@ HumanReadableText *qmp_x_query_irq(Error **errp) return human_readable_text_from_str(buf); } + +typedef struct StatsCallbacks { + char *name; + StatsList *(*stats_cb)(StatsList *, bool, const char *, bool, + const char *, Error **); + StatsSchemaList *(*schemas_cb)(StatsSchemaList *, bool, const char *, + Error **); + StatsInstanceList *(*instances_cb)(StatsInstanceList *, Error **); + QTAILQ_ENTRY(StatsCallbacks) next; +} StatsCallbacks; + +static QTAILQ_HEAD(, StatsCallbacks) stats_callbacks = + QTAILQ_HEAD_INITIALIZER(stats_callbacks); + +void add_stats_callbacks(const char *name, + StatsList *(*stats_fn)(StatsList *, + bool, const char *, + bool, const char *, + Error **), + StatsSchemaList *(*schemas_fn)(StatsSchemaList *, + bool, const char *, + Error **), + StatsInstanceList *(*instances_fn)(StatsInstanceList *, + Error **)) +{ + StatsCallbacks *entry = g_malloc0(sizeof(*entry)); + entry->name = strdup(name); + entry->stats_cb = stats_fn; + entry->schemas_cb = schemas_fn; + entry->instances_cb = instances_fn; + + QTAILQ_INSERT_TAIL(&stats_callbacks, entry, next); +} + +StatsList *qmp_query_stats(bool has_name, const char *name, bool has_type, + const char *type, Error **errp) { + StatsList *list_tail = NULL; + StatsCallbacks *entry; + + QTAILQ_FOREACH(entry, &stats_callbacks, next) { + list_tail = entry->stats_cb(list_tail, has_name, name, + has_type, type, errp); + } + + return list_tail; +} + +StatsSchemaList *qmp_query_stats_schemas(bool has_type, const char *type, + Error **errp) +{ + StatsSchemaList *list_tail = NULL; + StatsCallbacks *entry; + + QTAILQ_FOREACH(entry, &stats_callbacks, next) { + list_tail = entry->schemas_cb(list_tail, has_type, type, errp); + } + + return list_tail; +} + +StatsInstanceList *qmp_query_stats_instances(Error **errp) +{ + StatsInstanceList *list_tail = NULL; + StatsCallbacks *entry; + + QTAILQ_FOREACH(entry, &stats_callbacks, next) { + list_tail = entry->instances_cb(list_tail, errp); + } + + return list_tail; +} diff --git a/qapi/misc.json b/qapi/misc.json index 358548abe1..a0a07ef0b1 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -527,3 +527,145 @@ 'data': { '*option': 'str' }, 'returns': ['CommandLineOptionInfo'], 'allow-preconfig': true } + +## +# @StatType: +# +# Enumeration of stat types +# @cumulative: stat is cumulative; value can only increase. +# @instant: stat is instantaneous; value can increase or decrease. +# @peak: stat is the peak value; value can only increase. +# +# Since: 7.0 +## +{ 'enum' : 'StatType', + 'data' : [ 'cumulative', 'instant', 'peak' ] } + +## +# @StatUnit: +# +# Enumeration of stat units +# @bytes: stat reported in bytes. +# @seconds: stat reported in seconds. +# @cycles: stat reported in clock cycles. +# @none: no unit for this stat. +# +# Since: 7.0 +## +{ 'enum' : 'StatUnit', + 'data' : [ 'bytes', 'seconds', 'cycles', 'none' ] } + +## +# @StatData: +# +# Individual stat +# @name: Stat name +# @type: @StatType +# @unit: @StatUnit +# @base: Exponent base (2 or 10) +# @exponent: Used together with @base +# @val: List of uint64 values +# +# Since: 7.0 +## +{ 'struct': 'StatData', + 'data': { 'name': 'str', + 'type': 'StatType', + 'unit': 'StatUnit', + 'base': 'uint8', + 'exponent': 'int16', + 'val': [ 'uint64' ] } } + +## +# @Stats: +# +# Stats per resource (e.g. vm or vcpu) +# @name: Resource name +# @stats: List of @StatData +# +# Since: 7.0 +## +{ 'struct': 'Stats', + 'data': {'name': 'str', + 'type': 'StatSchemaType', + 'stats': [ 'StatData' ] } } + +## +# @query-stats: +# +# @name: Stat name (optional) +# @type: Type name (optional) +# Returns: List of @Stats +# +# Since: 7.0 +## +{ 'command': 'query-stats', + 'data': { '*name': 'str', '*type': 'str' }, + 'returns': [ 'Stats' ] } + +## +# @StatSchemaType: +# +# Enumeration of stats schema types +# +# Since: 7.0 +## +{ 'enum' : 'StatSchemaType', + 'data' : [ ] } + +## +# @StatSchemaEntry: +# +# Individual stat in a schema type +# +# Since: 7.0 +## +{ 'struct': 'StatSchemaEntry', + 'data': { 'name': 'str' } } + +## +# @StatsSchema: +# +# Stats per @StatSchemaType +# @type: @StatSchemaType +# @stats: @StatCchemaName +# +# Since: 7.0 +## +{ 'struct': 'StatsSchema', + 'data': { 'type': 'StatSchemaType', + 'stats': [ 'StatSchemaEntry' ] } } + +## +# @query-stats-schemas: +# +# @type: type name (optional) +# Returns: List of @StatsSchema +# +# Since: 7.0 +## +{ 'command': 'query-stats-schemas', + 'data': { '*type': 'str' }, + 'returns': [ 'StatsSchema' ] } + +## +# @StatsInstance: +# +# @name: resource name +# @type: @StatSchemaType +# +# Since: 7.0 +## +{ 'struct': 'StatsInstance', + 'data': { 'name': 'str', + 'type': 'StatSchemaType' } } + +## +# @query-stats-instances: +# +# Returns list of @StatsInstance +# +# Since: 7.0 +## +{ 'command': 'query-stats-instances', + 'returns': [ 'StatsInstance' ] } From patchwork Fri Nov 19 19:51:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Kanda X-Patchwork-Id: 12629439 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C004DC433F5 for ; Fri, 19 Nov 2021 19:55:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 4593C61B1E for ; Fri, 19 Nov 2021 19:55:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4593C61B1E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:43450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mo9yO-0000Av-C1 for qemu-devel@archiver.kernel.org; Fri, 19 Nov 2021 14:55:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mo9ve-0005ST-T7 for qemu-devel@nongnu.org; Fri, 19 Nov 2021 14:52:10 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:27634) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mo9vc-0001ML-51 for qemu-devel@nongnu.org; Fri, 19 Nov 2021 14:52:10 -0500 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AJIUKR4031872; Fri, 19 Nov 2021 19:52:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=5L9YWuvbQhRg9wrEJe2ycsZyG8p1IOC1GYIOrKrD0m0=; b=Je58p+USMzfSpUhl7E3FQJCySELZc8dZXOZivCJyKTntkdvkRgjY95b+InNyMAvSpQwe jTNtS3hkjn/kZUlfKne9Am3bYrtKLsJ/UXKsKQgDnI/wSgvd1A+aOy2lV8Vs9lSGThOK RHXHafkuyKTCa513C6htKGcan+X6aqqYizLV044Y5FDm05QNHet9xD8cNXPLB5qDMpaq HoFvLlnvjpEg6Tw8vf0axbMz9jLGSl6Dm2vC+TgxWYwCTSlfnBpBMyc0qJLhZ3SRZf4u GBnafVeONyAQEFKZSUZwYBiY7qHTVth6CpTTFtoA71B4TjQO1wAIovOlUDG15PSSu0jA bg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3cd4r007t3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Nov 2021 19:52:05 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1AJJkagU092459; Fri, 19 Nov 2021 19:52:04 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2108.outbound.protection.outlook.com [104.47.58.108]) by aserp3030.oracle.com with ESMTP id 3ccccty7q0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Nov 2021 19:52:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CMxSYQNRWhdQwnaPTKhXZn4JiAH6EiayF0cLdp5E3YhEdomvOGCITFe2YFbAGtnaEXbvzp9GMrM/Ec3GCK9D1Yx2z0AbpQL72F0iebesgoQkjp4xbv0SLtGJQLFW8WzX4QydUbEmKTY5t/+bfsxfEIQ7rKYZkBJbFyord0u6ManYCpi9XO78x0OLSom7j82m6iXXaNzH21uGzJ290dVnmIOWUdmrAy3myCtI0yiBnp4E4FTQpHTf/DPslqO6PFo3Z0G1xyQu8uslcG45aF1ZGWeKI2eS3QDBn5vQMWec+N/226/4Onk5WyfIODnwkls31l1ILOpGN/m3rhEI72YZ/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5L9YWuvbQhRg9wrEJe2ycsZyG8p1IOC1GYIOrKrD0m0=; b=MgpKwdhXEoXkAKiRDLztnWcZIoScCNJoeLdPKW1DWsPy8M5N8GwdyTd4nXuq1iwgighJE122bJdB+O8S8yTPlOzTi9vgOC/gmenOtpAJTaVR+niIu4qnfvwaBsTYmP2gddlNllon0gHGhjIkT32byO7aXCe/uejWrdyPfr8jptjohcCSQnYIuYdBURY5GINqrxUl601PdEs41JF175YsZ7dJm4EFMeYi/R1YnreaXcvQvHe+Tosn3lBenTcamjngzmW7Q30nAZ2cPIlD+oRGz0v6cRdDnhj1LxxKoz+gbbH0lMZPFz5qe1d1hOPv8h9AW/MjRf5j6nz2QdrSN1W01w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5L9YWuvbQhRg9wrEJe2ycsZyG8p1IOC1GYIOrKrD0m0=; b=OQMxwVliLT8GYcFsiDp/03Ix288SAjc0YGpVEhGrNdYe2+vtdhpwRHJnMQ4qkfqh78uQn3nNUo2igDzUB8t1FSPUiVKhyOfo8to7Lz21BFvIfR4oAn/j3TpOQiOoUCCiqKyrmszSbJevjO/PwW40VGW8mgeYVEl0uXxZZO14Kow= Received: from SA1PR10MB5841.namprd10.prod.outlook.com (2603:10b6:806:22b::16) by SA2PR10MB4603.namprd10.prod.outlook.com (2603:10b6:806:119::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.20; Fri, 19 Nov 2021 19:52:02 +0000 Received: from SA1PR10MB5841.namprd10.prod.outlook.com ([fe80::8156:fe6f:d62c:5dd6]) by SA1PR10MB5841.namprd10.prod.outlook.com ([fe80::8156:fe6f:d62c:5dd6%7]) with mapi id 15.20.4713.022; Fri, 19 Nov 2021 19:52:02 +0000 From: Mark Kanda To: qemu-devel@nongnu.org Subject: [PATCH v2 2/3] hmp: Support for querying stats Date: Fri, 19 Nov 2021 13:51:52 -0600 Message-Id: <20211119195153.11815-3-mark.kanda@oracle.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211119195153.11815-1-mark.kanda@oracle.com> References: <20211119195153.11815-1-mark.kanda@oracle.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To SA1PR10MB5841.namprd10.prod.outlook.com (2603:10b6:806:22b::16) MIME-Version: 1.0 Received: from linux-1.us.oracle.com (137.254.7.175) by SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22 via Frontend Transport; Fri, 19 Nov 2021 19:52:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ccb83386-3bc2-41c6-e05a-08d9ab960e4d X-MS-TrafficTypeDiagnostic: SA2PR10MB4603: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:166; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5WL8DwfayVqbNdokDZ65MPXrx0O2Fgw5dHzsPvJONrldG9k2wbmIG5ZUmhCGgdJy6prls1pD7Q/Z2ncf2EXcrJEw+K9mhc1DdFvzDOkRpC4SixEAN94gRWSFUhLFCGfj9gChIzTSc3ft5pDab3xWOx6qPuHN4QMFYFRcQ3gE5b6/Jle5ZQSIOTiZHClxjBHgqGLU++H170L6QqzNgZNGU7G6lhZS0YayW5cW0mnFQRcNo3o4jvB7BjwXi/j61yx2wMKyM7yQcoep3gAbC2/WDoXCpV4JwGmhj16SbBe8JWB+6jBE2IyhcyFp6eAXXG0LWyt0msXbrephMfOJiMJwPFAg3weaFmmRx0C6Mk9P58b2aVsvLrQV8pG2NEe1mzGO3frQcpPiqzqrhJx9kyw9mNFdflkBChVQRv5rHWHMid4WzjJFRGkuuCHTpWzfvpGU5K2mqWTmNkAlsileuvKOqxp4poAIi4ksMkZKP330NANzfuvwv2ZskuHO9rFGZMYGRUE6w++dRAvq7J4g/66Jo3M8VLtePuvOhDEeivRhO/SbG/Yx2w5srzsY/uDSSzmENIWFSjHotz1u7vgnwkpLgNk4VpDw4iz07QlZgiffbe/IIWyb4MIRjQdg+7p/y0rLBcFEQC2UnjiRggx4IVmxlIfTTNqmGK6i7lTcgl2VOnxwPb2eG0Elbc1vDMSlE85DN3xX01LO3xMLu0pKFWRSEg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA1PR10MB5841.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(107886003)(8936002)(2906002)(508600001)(86362001)(38100700002)(36756003)(316002)(5660300002)(4326008)(1076003)(6666004)(38350700002)(8676002)(26005)(66476007)(7696005)(52116002)(6916009)(44832011)(6486002)(186003)(66946007)(66556008)(956004)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Gv1Op/guPcqE9GQrGWhGzKSChfMrWsVUAi/QfkcPzyTwc5Xk4UxhK6YYwjBxm4tFopGrhN91SkIiHCQmRoea+A1wi04VDBxS8ToMPURlo1YaJn0NLQqwS6XqphxxWiiXdtc+cN8G5VzO9m+42juTDJaGGYPe6wTX2pcYvaq28E0+ICwdcSHJPOpyyOSN61eVrz8cVL/YnGlGaE3XAHsjmOIJTnV0KklFMWEOQ5k7ksVf+HZ7X3cN6RHY7m2etFYMpD36eVtSe2A97fZ8ZWduMMRCVddT1oNlnMHAeipMXZ/l2/41Qoa4ZJMe/WI82IU19oBFeuN6ooG0Z8p8Cd4sbJxH1Nla8PDWcM6EJL10P5YchCEHqsT2GrC2UAoNhXNHhLu59woIzDWn1i7gdgo3JVih86T9krb8J7mEHqDaISf35G+ZiVujbya8wqmArS7R03udwf65+yRE42gxnLn9DmOtLyC7EkFjIhvWJRF4QBRQB8t61B9dX1nQCPX6sVdfZ/WSR0vHq39bQUshlitUmfcIMsWmkCWrrSNKvrgLHaee554k3UvIc0ciuClhqyM72HN6vsqdJveYAp8L0012vXwmX4d83MCWKmc4Dw+R6FmWdChEdmA28nKe+10yyWv1ReFdFQNEF6bZeRZdme1YKxjN+JoFT/NxOxhnXlZ55d9O6U4USWbuHRl2+TcnpyYU5oyLW2Xmk0MIO3vSFlv7x5xry1wn/oXECUoPednbktFKwsFF0OLSPluEkFbOPtk2e7g3RfJnq3c12Hg9zJJrxYg2LYVkZDXW+9DeRT1HvABsE6smFy42kQdQ8Yp4XI4HgoWMv/jrT1ZqzyOnRG0mMZDCJt380hW+D7F/Ub1HV+BuVVxQUx75CYawb2ZC2opAxlpc5h9bhG3U/ko6g3k5543B7atDEVT2lwS4xGXKA9MlUuJRbd9zXn8BpqtKCT0ukQB+Qemt9jxlG6FHHiZcFB8l3fGiLoNwlczhlUtnPNdNleQYM7Y4RKnwaZdEm/8ol8O2vY3nhC8BVfojbSK16OephnakHHJXJXO79gj8U8sbDhCAldfooRlNcnIv7FaZb1gZoflr6n2zblRq46ta5XF9zl0qrY6jpKfZznp1NAj3C2I17d/zrW+Hm5yx7YCmp9pJrjt34RdpOQshLP+/FgUWsgD/d6BH2CNihs2AHQkfxDzsD5rz0HZg+IRj9251+gsb54TJiIrGCnQshsCniSb5OCPSJ0QrbwWpfJQIn8oSymsh5cdTHrlG5y278vswpy8hniVzzgcooGCRJvfywrHmmO3OIXPDvzrHAy8YLjR+VOzyFeuEoFeYSPFe0cE+aPzyfnohNhFFoKbFfNWsAsiVLKv4wlZhnIarEobqPOOYmlj/51dXo6CmM3TulE9HPAu5OXBKc7FF/qTs8dm5TIzzb2HNOQfvLrL98INhg70cWKh/z7ADGGHXCxw48uwJdbAD1kUJxctS2hGqFkvtbjYZJ38OhMWgmsm6ctZkm/XaUHj0xVn8hdLjVhTm4mqSRIaBzNaHNWybdZe8YsE6vE0VNATxcBtv9eTq6O8cwXpcmVsNiK/oK+qbHkF6TVXWSuz0On5EwvBKGGXj+r8GFBbnpg7mmvLztGrNKucGI0s= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ccb83386-3bc2-41c6-e05a-08d9ab960e4d X-MS-Exchange-CrossTenant-AuthSource: SA1PR10MB5841.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 19:52:02.7236 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: aCZTHghf15FkraswW8eAB0xi28ydX+34nDpFi03EzHX24JAhHRvPrayeHeobqliSCNkdb2vyZkizdlxtkmTvuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4603 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10173 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111190106 X-Proofpoint-ORIG-GUID: _oehiRgWcZYuA1h7FoyqIks6UvPfS-CM X-Proofpoint-GUID: _oehiRgWcZYuA1h7FoyqIks6UvPfS-CM Received-SPF: pass client-ip=205.220.177.32; envelope-from=mark.kanda@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Leverage the QMP support for querying stats. The interface supports the same arguments as the QMP interface. Examples (with fd-based KVM stats): (qemu) info stats vcpu_1 (kvm-vcpu): guest_mode (instant): 0 directed_yield_successful (cumulative): 0 ... vcpu_0 (kvm-vcpu): guest_mode (instant): 0 ... vm (kvm-vm): max_mmu_page_hash_collisions (peak): 0 max_mmu_rmap_size (peak): 0 ... (qemu) info stats-schemas kvm-vcpu: guest_mode directed_yield_successful ... kvm-vm: max_mmu_page_hash_collisions max_mmu_rmap_size ... (qemu) info stats-instances name type ---- ---- vcpu_1 kvm-vcpu vcpu_0 kvm-vcpu vm kvm-vm Signed-off-by: Mark Kanda --- hmp-commands-info.hx | 40 ++++++++++++++ include/monitor/hmp.h | 3 + monitor/hmp-cmds.c | 125 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 407a1da800..0d5f025adb 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -877,3 +877,43 @@ SRST ``info sgx`` Show intel SGX information. ERST + + { + .name = "stats", + .args_type = "name:s?,type:s?", + .params = "[name] [type]", + .help = "show statistics; optional name and type", + .cmd = hmp_info_stats, + }, + +SRST + ``stats`` + Show stats +ERST + + { + .name = "stats-schemas", + .args_type = "type:s?", + .params = "[type]", + .help = "show stats for schema type; optional type", + .cmd = hmp_info_stats_schemas, + }, + +SRST + ``stats-schemas`` + Show stats for schema type +ERST + + + { + .name = "stats-instances", + .args_type = "", + .params = "", + .help = "show current stat instances", + .cmd = hmp_info_stats_instances, + }, + +SRST + ``stats-instances`` + Show current stat instances +ERST diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 96d014826a..3670280a6b 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -133,5 +133,8 @@ void hmp_info_dirty_rate(Monitor *mon, const QDict *qdict); void hmp_calc_dirty_rate(Monitor *mon, const QDict *qdict); void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Error **)); +void hmp_info_stats(Monitor *mon, const QDict *qdict); +void hmp_info_stats_schemas(Monitor *mon, const QDict *qdict); +void hmp_info_stats_instances(Monitor *mon, const QDict *qdict); #endif diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 9c91bf93e9..9752ca6aa8 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -2165,3 +2165,128 @@ void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) } hmp_handle_error(mon, err); } + +void hmp_info_stats(Monitor *mon, const QDict *qdict) +{ + StatsList *stats_list, *stats_list_entry; + Stats *stats_entry; + StatDataList *data_entry; + StatData *stat; + uint64List *val; + const char *name, *type; + Error *err = NULL; + + name = qdict_get_try_str(qdict, "name"); + type = qdict_get_try_str(qdict, "type"); + + stats_list = qmp_query_stats(name ? TRUE : FALSE, name, + type ? TRUE : FALSE, type, &err); + + if (err) { + monitor_printf(mon, "%s\n", error_get_pretty(err)); + error_free(err); + return; + } + + for (stats_list_entry = stats_list; stats_list_entry; + stats_list_entry = stats_list_entry->next) { + stats_entry = stats_list_entry->value; + monitor_printf(mon, "\n%s (%s):\n", stats_entry->name, + StatSchemaType_str(stats_entry->type)); + + for (data_entry = stats_entry->stats; data_entry; + data_entry = data_entry->next) { + stat = data_entry->value; + monitor_printf(mon, " %s (%s):", stat->name, + StatType_str(stat->type)); + + for (val = stat->val; val; val = val->next) { + if (stat->unit == STAT_UNIT_SECONDS && + stat->exponent >= -9 && stat->exponent <= 0 && + stat->exponent % 3 == 0 && stat->base == 10) { + const char *si_prefix[] = { "", "milli", "micro", "nano" }; + monitor_printf(mon, " %lu %s", val->value, + si_prefix[stat->exponent / -3]); + } else if ( + stat->unit == STAT_UNIT_BYTES && + stat->exponent >= 0 && stat->exponent <= 40 && + stat->exponent % 10 == 0 && stat->base == 2) { + const char *si_prefix[] = { + "", "kilo", "mega", "giga", "tera" }; + monitor_printf(mon, " %lu %s", val->value, + si_prefix[stat->exponent / 10]); + } else if (stat->exponent) { + /* Print the base and exponent as "*^" */ + monitor_printf(mon, " %lu*%d^%d", val->value, + stat->base, stat->exponent); + } else { + monitor_printf(mon, " %lu", val->value); + } + + /* Don't print "none" unit type */ + monitor_printf(mon, "%s\n", stat->unit == STAT_UNIT_NONE ? + "" : StatUnit_str(stat->unit)); + } + } + } + qapi_free_StatsList(stats_list); +} + +void hmp_info_stats_schemas(Monitor *mon, const QDict *qdict) +{ + StatsSchemaList *stats_list, *stats_list_entry; + StatsSchema *stats_entry; + StatSchemaEntryList *data_entry; + StatSchemaEntry *stat; + const char *type; + Error *err = NULL; + + type = qdict_get_try_str(qdict, "type"); + + stats_list = qmp_query_stats_schemas(type ? TRUE : FALSE, type, &err); + + if (err) { + monitor_printf(mon, "%s\n", error_get_pretty(err)); + error_free(err); + return; + } + + for (stats_list_entry = stats_list; stats_list_entry; + stats_list_entry = stats_list_entry->next) { + stats_entry = stats_list_entry->value; + monitor_printf(mon, "\n%s:\n", StatSchemaType_str(stats_entry->type)); + + for (data_entry = stats_entry->stats; data_entry; + data_entry = data_entry->next) { + stat = data_entry->value; + monitor_printf(mon, " %s\n", stat->name); + } + } + qapi_free_StatsSchemaList(stats_list); +} + +void hmp_info_stats_instances(Monitor *mon, const QDict *qdict) +{ + StatsInstanceList *stats_list, *stats_list_entry; + StatsInstance *stats_entry; + Error *err = NULL; + + stats_list = qmp_query_stats_instances(&err); + + if (err) { + monitor_printf(mon, "%s\n", error_get_pretty(err)); + error_free(err); + return; + } + + monitor_printf(mon, "%-15s %s\n", "name", "type"); + monitor_printf(mon, "%-15s %s\n", "----", "----"); + + for (stats_list_entry = stats_list; stats_list_entry; + stats_list_entry = stats_list_entry->next) { + stats_entry = stats_list_entry->value; + monitor_printf(mon, "%-15s %s\n", stats_entry->name, + StatSchemaType_str(stats_entry->type)); + } + qapi_free_StatsInstanceList(stats_list); +} From patchwork Fri Nov 19 19:51:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Kanda X-Patchwork-Id: 12629441 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B77DAC433F5 for ; Fri, 19 Nov 2021 19:57:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 118E561B1E for ; Fri, 19 Nov 2021 19:57:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 118E561B1E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:47458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1moA0a-0002xI-2H for qemu-devel@archiver.kernel.org; Fri, 19 Nov 2021 14:57:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mo9vh-0005UY-4J for qemu-devel@nongnu.org; Fri, 19 Nov 2021 14:52:14 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:58216) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mo9vc-0001MR-58 for qemu-devel@nongnu.org; Fri, 19 Nov 2021 14:52:12 -0500 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AJJATbT006439; Fri, 19 Nov 2021 19:52:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=cL0jF2bbjED8d6sncU+Z+WTd7vZ546U7yZ71REWJt2s=; b=XhzPmQ0uka0+0Tpb81W6NSbWUWdUNg+FxA9zV88Q7Esp0psC2Aq09IIMbVmeU/YQlD8g YTqI7YkwJNbpfEQJRRLezPICJk78CLTNdpYVwjM2Z6MqifT02mka4UJQd4/IaToWUZ8W MvLMY0vlTXp/JKnd993sA3eiUV98kgi2KOWG/mPzoVDmK58t8eGRrFJYUQyaJkVUb+3w giuBxYq5BUm9RQXXE3T3LkbQid9IGVszYvEc7rAIGvxSLezLsDXTggKjKp5XTV6O5dpd Bn9HZ+pPvkzeCsrVZwsL0Bu4ctjnRR+jtO5gXBih6hq7OoOy9FS3IHmbUZW5BxsCG5Wv bA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3cehun06qt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Nov 2021 19:52:05 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1AJJkagV092459; Fri, 19 Nov 2021 19:52:05 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2108.outbound.protection.outlook.com [104.47.58.108]) by aserp3030.oracle.com with ESMTP id 3ccccty7q0-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Nov 2021 19:52:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bTjQsusuP5h/JzuQ84yRyRNYirOw5TYnl6Pi996e4Tdlo8p339nTvVEAqkAVUiNYU0Qupih8Dkvl/HTUeKfA7DFmPVA6osEO/3w1vp5MxRTTrqXfCCLVR9hiDdpFyGhPAm4Qqh8gV00+UhLosEdmUtx9mCmZ/LWqekp5mu73TdoWXbUU61/tgG97XNpSerdIurySJt5Kiwlvv3VpqfnoIviQYH1dw8C7ah+F2YPRErw8SZoik0evnbd1SiC2qzuvuFpMxJU7nl8duN5BW7UoQppLqUSyZS7cbtiFjwK5mkDo6moCIjZrQoJby9nHygb91nYWJVrUy3HmYg/+b72Bnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cL0jF2bbjED8d6sncU+Z+WTd7vZ546U7yZ71REWJt2s=; b=fNpQGFeULo7aQ2Dob57oni7t4oG3KC71NLeCuk7C2E8Cqra+mQOMB/cd3hF4a1Aa7CaIbAGVKbDq2Fctj3e92FFtwyORnubyKF//TRtQnUBrjQTFswQ7oWcXq4ZjAOk1/IBGIVZIuX3q/4X6TcSPHPwe42s1e8K4bDvqQ5BuPT+Punwy3k/aQnunjjJH28K1zWAiWa9PsZmKYH3EwQRPc3Mzx9yFXFkLKOx4OG9hVVN+Zk2vsFyvAMVGuAcOrhxPDO7xKnDaD/QCg0tYO/v4koCIMf99q8amp8Aady2ECMMAztUW9XXsUt4MSq7SpBQbVatQwql2K05b6e2SbB9H6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cL0jF2bbjED8d6sncU+Z+WTd7vZ546U7yZ71REWJt2s=; b=AnVchuIaqDTomOf1KPoo/LyFqbXK8X1curK4Ndvner5+m0AgxWPYrjy0AqmNpiCjsBP1+Yg5KJj+xyqRUwycy8f514qqB5g+ccDquALVB9P9JWhzlijeaRju1kIRMxXPcSeIQiF71tQ+v4+lJarlL6LXedEUjfMvdCnLAImcbGA= Received: from SA1PR10MB5841.namprd10.prod.outlook.com (2603:10b6:806:22b::16) by SA2PR10MB4603.namprd10.prod.outlook.com (2603:10b6:806:119::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.20; Fri, 19 Nov 2021 19:52:03 +0000 Received: from SA1PR10MB5841.namprd10.prod.outlook.com ([fe80::8156:fe6f:d62c:5dd6]) by SA1PR10MB5841.namprd10.prod.outlook.com ([fe80::8156:fe6f:d62c:5dd6%7]) with mapi id 15.20.4713.022; Fri, 19 Nov 2021 19:52:03 +0000 From: Mark Kanda To: qemu-devel@nongnu.org Subject: [PATCH v2 3/3] kvm: Support for querying fd-based stats Date: Fri, 19 Nov 2021 13:51:53 -0600 Message-Id: <20211119195153.11815-4-mark.kanda@oracle.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211119195153.11815-1-mark.kanda@oracle.com> References: <20211119195153.11815-1-mark.kanda@oracle.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To SA1PR10MB5841.namprd10.prod.outlook.com (2603:10b6:806:22b::16) MIME-Version: 1.0 Received: from linux-1.us.oracle.com (137.254.7.175) by SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22 via Frontend Transport; Fri, 19 Nov 2021 19:52:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e0477d15-5544-46b3-a04c-08d9ab960eff X-MS-TrafficTypeDiagnostic: SA2PR10MB4603: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Dr13tRudwdhNIQBUx4a6zH0EL77Z+x08jRsU1Oyb85jml7aSzQFVkjjqfr9TJii1pY8NDgpMa3vpYJz0IeT8T4xTQh6lMpVCMBNVQHF/nn7LgOT6txmDe6A8cyE2AcD6mRACHov6fkYaICpng2z3D0OZQzbzJtVeU0GWiyKnF4nVIvgIyye05aDamax6cWKXcDq6aGWrEm7Ji6/olXOCgWqp17EX18IQRRBtc5r8pdkIwzP4vCWezShUJNrpu5jxRh3IuPcCQ0e6z2ZZawTTyHZNiqgXvcPXtknJ/tDdzkCSHHFfzpxl6rlD18Yn/IVTGGN8KIaYGyK+Z1WDc61iyA26oH6X9wrogFuZkOe24bN6d445J/+Fy9RLLxkHOXKHfizKHj4hIIXpLblUIiGKPfBjNlgln9fI35PgxwCOGQoiLbdl4DKdQ/Ojmb6g1oEqsjmItnwUUL6qDeicni7AUDoYASe4oMx1Em+/MW01PvGZfFsTaETX92FWAen9/dmNTr9O2P7cZCTBN10xIm/zPCCM9XOQlSsggKf5pzUd15W6e9YCFje1CZqW0AzAh2Bec7xCs4rdwzcLMU9otZrTuLhi0P6W/n5ESuG/acRdTIDNS8LIbjgu33Z1ky2G1EcavUPEoQepnAkMCapCIuLHX6w76iYgxUfC5+JMTKHSs4wgxpDufbJtJN/jMwi2v4FocZOUr3id7SPKeBmHIL3PCA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA1PR10MB5841.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(30864003)(107886003)(8936002)(2906002)(508600001)(86362001)(38100700002)(36756003)(316002)(5660300002)(4326008)(1076003)(6666004)(38350700002)(8676002)(26005)(66476007)(7696005)(52116002)(6916009)(44832011)(6486002)(83380400001)(186003)(66946007)(66556008)(956004)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UtWOfgDZ8+zaLEAy4QB5UC3ZegQZ2EUSh/Cbi9RC3a+55qBfXtZgU3iK6Dj+BDl4HcDG3YvjvF7hJgCp4JAKv4DwAECD2M5OrXXukTyxdpOKyd42ISw/7oeh5KQ+9u3ji7MHD0zdV1u77OTnAD4G91duqbYaMcWgcV6+tAmw3wSFAq0QarqaxrzPjmRloZfMDNccAiO66v8TIoHlHU6HOBqWMfwsBmlFZQ9Su/oP14AK8eATp6HY2/rtYJjzhEgDR+V40QPVRJ8QCu3XTBKmx6UKJk7UrVA60seFHXoLNGXayXvvOjROgfya9e1D6xTIHCFaW5euQonbMgTMNQTMuJowliUQBlJLvXMSYGCrJR1P5FqcYx2wTeh3frkHG8JxAMqZK6BfrxLq/t4bPduJ16XXOOBsCsqNTG/Kl9xovwicXgNBZ8+1mSs2yJSajd+4Rv1fv7ZrOOlvykWWM4e83Sx6yFrtLaZwWKnRVfzCeb00fQdDUiIrUDpc90XIJnlwgvFUjo2LV7B1XbPNlLtR1cbI54NuF6LLXjiJPizsdfkZbn9FQkbbs6jiPZMYdlZpNZCLsiuZLcY3Ah0LT+FV8KlscuWe3UGD3JG3oZaWjLD6iIxlTWz30c2qEu+JLY87Kb4VnyU+UDFy4aK5oU8Lm1PXA3gIeq3x7dedztDFHZ4WrbOKnvEXuLT91iuaqEgd1I8qlrHzd2HbMWlyerhAMz+3g53siJsrco1M1TJQdlnwxGtNREgQChMqeab1yxMxKaQnx+MNu+meEUZ76nFsOlepQUMFAjwQnum9/YqumfaBkHsdtzI4ucPavpTMDC5egD9ygoI7S4P3PR5JdJceIxIf9+s+C9iSohVvS7Dms9hFMxTfLmyk251ZqigRi+ol1Nk9k6IIAEDRDPMoOA0zLDbCLS0z0ReuuXK8cdOPbDPXywuq7lWEMMk3EbfEzBT53ESeuqS77LpXStDNEs2UdDWaAkA70uh++g1dTVmjNe5S1IZY2bVrbxIZDi2dPKK6//QTpBbLIeb3dWZBetQVR1nvX8zaczR54qG96CPdb0XHOD8UGAeYyR/O4mSYqphyECSIB2VV/JbUpYYfMQ4BcRHxd7ZgKCI9PhIKSkpIWfGEE+tl2qalXd13W2qXtvW6Uzw8dWcNZohIMzRTUyBXL7JwRV+oOGay6nKHVxohbTGv5QwCAkIzSEXteiNks3gXOA6bbsbOm9DL9MAdpkUQ9QVzqSdeSYqZu8tunqDqcrE2SCe4ljJ6EuyHgLyKTkQKRGJFOLmpb4xJUzRSNhVhAcj+QpZXUo8z1kslhSeAXMN2R3Z1ZfXb/+z3TMtSzO0ftP++rDv9Ra706QB85JOLbJ/R7TfKUHEn5RB6dCkKdmusDZTL2vzx0VoqfpPBU+r9p2uusv5rnl4ZCZo9hhG7ce1ApkW41JM8ji4pYRy4lJ9YS3oODJLtnk3v7CksVbG/2T/MII2dcXvURNk6zJQopVkO22xKN76MtPcvV+p7Csa28LVwud9Yeflj7/YHy4UEYSGICYJQi9qQiLArXos7nqVY0tvjByDh6BBbI+l9uTamazgWXNO9yCmtVC0HBTzD/pbtNSDGM03tVXu8ea1o/y9TMW0GUqwss1v5y7sIGRc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0477d15-5544-46b3-a04c-08d9ab960eff X-MS-Exchange-CrossTenant-AuthSource: SA1PR10MB5841.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2021 19:52:03.6485 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: esYsFrOo0Fv8ZinnVdpYXMqMWfMk9/LACuz6Er4PSbuqMIbifsZmAlACfX6SftvzGJRlnAOHVd51ahdZnbQQwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4603 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10173 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111190106 X-Proofpoint-GUID: BHpNQFJxYLwN-a9BBUAz6tDL3-JYqHf8 X-Proofpoint-ORIG-GUID: BHpNQFJxYLwN-a9BBUAz6tDL3-JYqHf8 Received-SPF: pass client-ip=205.220.165.32; envelope-from=mark.kanda@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add support for querying fd-based KVM stats - as introduced by Linux kernel commit: cb082bfab59a ("KVM: stats: Add fd-based API to read binary stats data") Signed-off-by: Mark Kanda --- accel/kvm/kvm-all.c | 399 ++++++++++++++++++++++++++++++++++++++++++++ qapi/misc.json | 2 +- 2 files changed, 400 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index eecd8031cf..10e8b8ed5c 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -47,6 +47,8 @@ #include "kvm-cpus.h" #include "hw/boards.h" +#include "qapi/qapi-commands-misc.h" +#include "monitor/monitor.h" /* This check must be after config-host.h is included */ #ifdef CONFIG_EVENTFD @@ -2303,6 +2305,15 @@ bool kvm_dirty_ring_enabled(void) return kvm_state->kvm_dirty_ring_size ? true : false; } +static StatsList *query_stats_cb(StatsList *, bool, const char *, bool, + const char *, Error **); + +static StatsSchemaList *query_stats_schemas_cb(StatsSchemaList *, bool, + const char *, Error **); + +static StatsInstanceList *query_stats_instances_cb(StatsInstanceList *, + Error **); + static int kvm_init(MachineState *ms) { MachineClass *mc = MACHINE_GET_CLASS(ms); @@ -2612,6 +2623,11 @@ static int kvm_init(MachineState *ms) } } + if (kvm_check_extension(kvm_state, KVM_CAP_BINARY_STATS_FD)) { + add_stats_callbacks("kvm", &query_stats_cb, &query_stats_schemas_cb, + &query_stats_instances_cb); + } + return 0; err: @@ -3667,3 +3683,386 @@ static void kvm_type_init(void) } type_init(kvm_type_init); + +typedef struct StatsArgs { + void *kvm_stat; + char *name; + bool query_schema; + Error **errp; +} StatsArgs; + +static StatDataList *add_kvmstat_entry(struct kvm_stats_desc *pdesc, + uint64_t *stats_data, + StatDataList *data_list, + Error **errp) +{ + StatDataList *data_entry; + uint64List *val_list = NULL; + int i; + + data_entry = g_malloc0(sizeof(*data_entry)); + data_entry->value = g_malloc0(sizeof(*data_entry->value)); + data_entry->value->name = g_strdup(pdesc->name); + + /* Convert flags to type, unit and base (QAPI auto-generated enums) */ + switch (pdesc->flags & KVM_STATS_TYPE_MASK) { + case KVM_STATS_TYPE_CUMULATIVE: + data_entry->value->type = STAT_TYPE_CUMULATIVE; + break; + case KVM_STATS_TYPE_INSTANT: + data_entry->value->type = STAT_TYPE_INSTANT; + break; + case KVM_STATS_TYPE_PEAK: + data_entry->value->type = STAT_TYPE_PEAK; + break; + default: + /* Unknown type - skip */ + goto exit; + } + + switch (pdesc->flags & KVM_STATS_UNIT_MASK) { + case KVM_STATS_UNIT_NONE: + data_entry->value->unit = STAT_UNIT_NONE; + break; + case KVM_STATS_UNIT_BYTES: + data_entry->value->unit = STAT_UNIT_BYTES; + break; + case KVM_STATS_UNIT_CYCLES: + data_entry->value->unit = STAT_UNIT_CYCLES; + break; + case KVM_STATS_UNIT_SECONDS: + data_entry->value->unit = STAT_UNIT_SECONDS; + break; + default: + /* Unknown unit - skip */ + goto exit; + } + + switch (pdesc->flags & KVM_STATS_BASE_MASK) { + case KVM_STATS_BASE_POW10: + data_entry->value->base = 10; + break; + case KVM_STATS_BASE_POW2: + data_entry->value->base = 2; + break; + default: + /* Unknown base - skip */ + goto exit; + } + + data_entry->value->exponent = pdesc->exponent; + + /* Alloc and populate data list */ + for (i = 0; i < pdesc->size; i++) { + uint64List *val_entry = g_malloc0(sizeof(*val_entry)); + val_entry->value = stats_data[i]; + val_entry->next = val_list; + val_list = val_entry; + } + data_entry->value->val = val_list; + data_entry->next = data_list; + data_list = data_entry; + + return data_list; + +exit: + g_free(data_entry->value->name); + g_free(data_entry->value); + g_free(data_entry); + + return data_list; +} + +static StatSchemaEntryList *add_kvmschema_entry(struct kvm_stats_desc *pdesc, + StatSchemaEntryList *data_list, + Error **errp) +{ + StatSchemaEntryList *data_entry; + + data_entry = g_malloc0(sizeof(*data_entry)); + data_entry->value = g_malloc0(sizeof(*data_entry->value)); + data_entry->value->name = g_strdup(pdesc->name); + + data_entry->next = data_list; + data_list = data_entry; + + return data_list; +} + +static void query_stats(StatsArgs *kvm_stat_args, int stats_fd) +{ + size_t size_desc, size_data; + struct kvm_stats_header *header; + struct kvm_stats_desc *stats_desc = NULL; + Error *local_err = NULL; + void *data_list = NULL; + char *id = NULL; + ssize_t ret; + int i; + + /* Read kvm stats header */ + header = g_malloc(sizeof(*header)); + ret = read(stats_fd, header, sizeof(*header)); + if (ret != sizeof(*header)) { + error_setg(&local_err, "KVM stats: failed to read stats header: " + "expected %zu actual %zu", sizeof(*header), ret); + goto exit; + } + size_desc = sizeof(*stats_desc) + header->name_size; + + /* Read kvm stats id string */ + id = g_malloc(header->name_size); + ret = read(stats_fd, id, header->name_size); + if (ret != header->name_size) { + error_setg(&local_err, "KVM stats: failed to read id string: " + "expected %zu actual %zu", (size_t) header->name_size, ret); + goto exit; + } + + /* Read kvm stats descriptors */ + stats_desc = g_malloc0(header->num_desc * size_desc); + ret = pread(stats_fd, stats_desc, + size_desc * header->num_desc, header->desc_offset); + + if (ret != size_desc * header->num_desc) { + error_setg(&local_err, "KVM stats: failed to read stats descriptors: " + "expected %zu actual %zu", + size_desc * header->num_desc, ret); + goto exit; + } + + for (i = 0; i < header->num_desc; ++i) { + struct kvm_stats_desc *pdesc = (void *)stats_desc + i * size_desc; + size_data = pdesc->size * sizeof(uint64_t); + uint64_t *stats_data = g_malloc(size_data); + + ret = pread(stats_fd, stats_data, size_data, + header->data_offset + pdesc->offset); + + if (ret != pdesc->size * sizeof(*stats_data)) { + error_setg(&local_err, "KVM stats: failed to read data: " + "expected %zu actual %zu", + pdesc->size * sizeof(*stats_data), ret); + g_free(stats_data); + goto exit; + } + + if (kvm_stat_args->name) { + if (g_strcmp0(kvm_stat_args->name, pdesc->name)) { + g_free(stats_data); + continue; + } + } + + /* Add entry to the list */ + if (kvm_stat_args->query_schema) { + data_list = add_kvmschema_entry(pdesc, (StatSchemaEntryList *) + data_list, &local_err); + } else { + data_list = add_kvmstat_entry(pdesc, stats_data, (StatDataList *) + data_list, &local_err); + } + g_free(stats_data); + } + + if (kvm_stat_args->query_schema) { + struct StatsSchema *kvm_stat = + (struct StatsSchema *) kvm_stat_args->kvm_stat; + + kvm_stat->stats = (StatSchemaEntryList *)data_list; + } else { + struct Stats *kvm_stat = (struct Stats *) kvm_stat_args->kvm_stat; + + kvm_stat->stats = (StatDataList *)data_list; + } +exit: + error_propagate(kvm_stat_args->errp, local_err); + g_free(stats_desc); + g_free(id); + g_free(header); +} + +static void query_stats_vcpu(CPUState *cpu, run_on_cpu_data data) +{ + StatsArgs *kvm_stats_args = (StatsArgs *) data.host_ptr; + int stats_fd = kvm_vcpu_ioctl(cpu, KVM_GET_STATS_FD, NULL); + Error *local_err = NULL; + + if (stats_fd == -1) { + error_setg(&local_err, "KVM stats: ioctl failed"); + error_propagate(kvm_stats_args->errp, local_err); + return; + } + query_stats(kvm_stats_args, stats_fd); + close(stats_fd); +} + +static StatsSchemaList *add_stats_schema(StatsSchemaList *list_tail, + StatsArgs *stats_args, + const char *type) +{ + StatsSchema *value = g_malloc0(sizeof(*value)); + + for (int i = 0; i < STAT_SCHEMA_TYPE__MAX; i++) { + if (!g_strcmp0(type, StatSchemaType_str(i))) { + value->type = i; + } + } + + QAPI_LIST_PREPEND(list_tail, value); + stats_args->kvm_stat = value; + stats_args->query_schema = TRUE; + + return list_tail; +} + +static StatsList *add_stats(StatsList *list_tail, + StatsArgs *stats_args, + const char *name, + const char *type) +{ + Stats *value = g_malloc0(sizeof(*value)); + value->name = g_strdup(name); + + for (int i = 0; i < STAT_SCHEMA_TYPE__MAX; i++) { + if (!g_strcmp0(type, StatSchemaType_str(i))) { + value->type = i; + } + } + + QAPI_LIST_PREPEND(list_tail, value); + stats_args->kvm_stat = value; + + return list_tail; +} + +static StatsArgs *prepare_stats_args(const char *name, Error **errp) +{ + StatsArgs *stats_args; + KVMState *s = kvm_state; + Error *local_err = NULL; + + if (!kvm_enabled()) { + error_setg(&local_err, "KVM stats: KVM not enabled"); + error_propagate(errp, local_err); + return NULL; + } + + if (!kvm_check_extension(s, KVM_CAP_BINARY_STATS_FD)) { + error_setg(&local_err, "KVM stats: not supported"); + error_propagate(errp, local_err); + return NULL; + } + + stats_args = g_malloc0(sizeof(*stats_args)); + stats_args->errp = errp; + stats_args->name = g_strdup(name); + + return stats_args; +} + +static StatsList *query_stats_cb(StatsList *list_tail, + bool has_name, const char *name, + bool has_type, const char *type, + Error **errp) +{ + KVMState *s = kvm_state; + CPUState *cpu; + int stats_fd; + StatsArgs *stats_args = NULL; + StatSchemaType schema_type; + + /* Query vm stats */ + stats_fd = kvm_vm_ioctl(s, KVM_GET_STATS_FD, NULL); + if (stats_fd == -1) { + error_setg(errp, "KVM stats: ioctl failed"); + return NULL; + } + + stats_args = prepare_stats_args(name, errp); + if (!stats_args) { + return NULL; + } + + schema_type = STAT_SCHEMA_TYPE_KVM_VM; + if (!type || !g_strcmp0(StatSchemaType_str(schema_type), type)) { + list_tail = add_stats(list_tail, stats_args, "vm", + StatSchemaType_str(schema_type)); + query_stats(stats_args, stats_fd); + } + + /* Query vcpu stats */ + CPU_FOREACH(cpu) { + schema_type = STAT_SCHEMA_TYPE_KVM_VCPU; + if (type && g_strcmp0(StatSchemaType_str(schema_type), type)) { + continue; + } + char *resname = g_strdup_printf("vcpu_%d", cpu->cpu_index); + list_tail = add_stats(list_tail, stats_args, resname, + StatSchemaType_str(schema_type)); + run_on_cpu(cpu, query_stats_vcpu, RUN_ON_CPU_HOST_PTR(stats_args)); + } + + g_free(stats_args); + return list_tail; +} + +static StatsSchemaList *query_stats_schemas_cb(StatsSchemaList *list_tail, + bool has_type, const char *type, + Error **errp) +{ + KVMState *s = kvm_state; + int stats_fd; + StatsArgs *stats_args = NULL; + StatSchemaType schema_type; + + stats_fd = kvm_vm_ioctl(s, KVM_GET_STATS_FD, NULL); + if (stats_fd == -1) { + error_setg(errp, "KVM stats: ioctl failed"); + return NULL; + } + + stats_args = prepare_stats_args(NULL, errp); + if (!stats_args) { + return NULL; + } + + /* Query vm */ + schema_type = STAT_SCHEMA_TYPE_KVM_VM; + if (!type || !g_strcmp0(StatSchemaType_str(schema_type), type)) { + list_tail = add_stats_schema(list_tail, stats_args, + StatSchemaType_str(schema_type)); + query_stats(stats_args, stats_fd); + } + + /* Query vcpu */ + schema_type = STAT_SCHEMA_TYPE_KVM_VCPU; + if (type && g_strcmp0(StatSchemaType_str(schema_type), type)) { + return list_tail; + } + list_tail = add_stats_schema(list_tail, stats_args, + StatSchemaType_str(schema_type)); + run_on_cpu(first_cpu, query_stats_vcpu, RUN_ON_CPU_HOST_PTR(stats_args)); + + g_free(stats_args); + return list_tail; +} + +static StatsInstanceList *query_stats_instances_cb(StatsInstanceList *list_tail, + Error **errp) +{ + CPUState *cpu; + + StatsInstance *value = g_malloc0(sizeof(*value)); + value->name = g_strdup("vm"); + value->type = STAT_SCHEMA_TYPE_KVM_VM; + QAPI_LIST_PREPEND(list_tail, value); + + CPU_FOREACH(cpu) { + value = g_malloc0(sizeof(*value)); + value->name = g_strdup_printf("vcpu_%d", cpu->cpu_index); + value->type = STAT_SCHEMA_TYPE_KVM_VCPU; + QAPI_LIST_PREPEND(list_tail, value); + } + return list_tail; +} diff --git a/qapi/misc.json b/qapi/misc.json index a0a07ef0b1..77e3962a1d 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -611,7 +611,7 @@ # Since: 7.0 ## { 'enum' : 'StatSchemaType', - 'data' : [ ] } + 'data' : [ 'kvm-vm', 'kvm-vcpu' ] } ## # @StatSchemaEntry: