From patchwork Tue Oct 19 20:29:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Kanda X-Patchwork-Id: 12571003 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 7FB01C433EF for ; Tue, 19 Oct 2021 20:34:05 +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 EA87B61212 for ; Tue, 19 Oct 2021 20:34:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EA87B61212 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]:45594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcvo9-000795-8w for qemu-devel@archiver.kernel.org; Tue, 19 Oct 2021 16:34:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcvjb-00039X-1J for qemu-devel@nongnu.org; Tue, 19 Oct 2021 16:29:19 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:21182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcvjX-0008CS-J9 for qemu-devel@nongnu.org; Tue, 19 Oct 2021 16:29:18 -0400 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19JKPnSW005524; Tue, 19 Oct 2021 20:29:12 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=rpWiPpYoZLs1P/iG9UGWOlvpFHzz9smq7H+rUl3ZmHg=; b=AWFI8TsiIS3qNlSGbLKJWGlts5XtqZpZ5kqbI4KXnkoHNCqQpgyfZOQ2HwbFk334dltt MPvA7ShDSWEk7OA2KLNHEpCAdx/rtyisWuemjYZ+U9hB4CNRRTBDeGWvwQPEG/F71uhv g2oPR2YZwib3O1uFIY4kMHyNR2vDs30cQyh3Jvjs1B5FM+IpXVf+T7B7S1DVt8cKNE4d C/MYi/CLy+VWt9tcZ+TN2UhNrWIWyGnxjnBAVEQtgnJa+7MdQSEOWSYJooKjk1PH8LPm uTFKiRWtwpYcZB0gnbNTroX/yOWux5EC2sfL9XbFirTOF0Lw1LRP/zkEj+xDEPqkAIn5 OA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3bsqgmn1g9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Oct 2021 20:29:11 +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 19JKGn0U182179; Tue, 19 Oct 2021 20:29:10 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2170.outbound.protection.outlook.com [104.47.57.170]) by aserp3030.oracle.com with ESMTP id 3bqmsfc8vm-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Oct 2021 20:29:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FIv+8JKSKnRbcX+AMzcrQkeChL/2SkwgVtpqa3LbkVVtofXmQQoNJFnQwHyOyd3T7bCClaBhQksl6I3jKkjWmt+6PcRvKtXLb2uw3Im6o1dATYMVe0Tv78neB/VbASPXH0kE+Y9L6Km935tqP1NFEQWZO07jbQgREWfMb7hSofIGfrOlW/bpj5xaZxO3pFHAmzidUxPh9Nx+PMpcLQed3fbpRGDD/tLaFehaVhwdEKD/eHxauR9nLGlVdGeQkiwE7TajI77HuEYrpveZNNnfdTjXqyTf8dSKuv1KpZZw6OixCfvLva2u+abPJ9k4zv4kar5Fmo5mF66k4CDctsbSWQ== 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=rpWiPpYoZLs1P/iG9UGWOlvpFHzz9smq7H+rUl3ZmHg=; b=j5jzTxiXeB3Vy8o++rOz/YLxtFSYaWkbCJmT4+EbQJhDBneKvVnBs5Z7HBqc0iv7NIC/yExOFcSq3ANJaXA5cqy3Z0nRnpo4sF+upXYyOKU+GrnILyksj4RFX2+kalfnRCncsWbs9pGVTK+DheoES8GB3Gd99E68NCO4s6wZpsbmtZ6LrqnTay07QWVFOg2gwGIW0s3pAHNLje+NLZhEhscDN8EoIwCfXkWflbiPbPuXwh/OhcCsEuc9d41wnJSdcN2Ls20JKgPkgbbVYJSr1A3+BhmQdV9sWU9N4m15MUwZjWa39k5JyTqBj4mdoTvdz/5M/enp5bWmtFIdjAnXEg== 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=rpWiPpYoZLs1P/iG9UGWOlvpFHzz9smq7H+rUl3ZmHg=; b=MHhu/ZUy25G2nn6h4IL5jHNXe+yHMQ5RI7ZSG9sjGeK/Ce1Pw9BI/CVPT06YQqsftTChX/gnkWJosirNuKYWGbQbRJc+kX156pAoX2N00ZCwuAL0f2j6rCaO1Rlhzt2DOG9ctnnDICRl+YJYJGrGilPgqK7CiKXgT8I1o2vcbdE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from SN6PR10MB2448.namprd10.prod.outlook.com (2603:10b6:805:41::18) by SA2PR10MB4681.namprd10.prod.outlook.com (2603:10b6:806:fb::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Tue, 19 Oct 2021 20:29:09 +0000 Received: from SN6PR10MB2448.namprd10.prod.outlook.com ([fe80::2c40:de5b:9f20:4604]) by SN6PR10MB2448.namprd10.prod.outlook.com ([fe80::2c40:de5b:9f20:4604%5]) with mapi id 15.20.4608.018; Tue, 19 Oct 2021 20:29:09 +0000 From: Mark Kanda To: qemu-devel@nongnu.org Subject: [PATCH 1/2] qmp: Support fd-based KVM stats query Date: Tue, 19 Oct 2021 15:29:03 -0500 Message-Id: <20211019202904.4857-2-mark.kanda@oracle.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211019202904.4857-1-mark.kanda@oracle.com> References: <20211019202904.4857-1-mark.kanda@oracle.com> X-ClientProxiedBy: SN7P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:806:123::31) To SN6PR10MB2448.namprd10.prod.outlook.com (2603:10b6:805:41::18) MIME-Version: 1.0 Received: from linux-1.us.oracle.com (137.254.7.181) by SN7P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:806:123::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 20:29:08 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f6ee0c1c-5474-4bb0-687d-08d9933f1a96 X-MS-TrafficTypeDiagnostic: SA2PR10MB4681: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:40; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BDRQdG6sMiUDwKuOTCSgxrvwTqWPvfxd2T+tGWQz4DM3oAZN26pZOdTo4SD5xAJBdAkh8s5SyXhuLqMzi0xBEmfD6orgiMv2zOZUvR3gppFlrikpT7exVWbpt+yvWH8OTDyaZBUdncs/XCK6Y3pcPzWYqIOUNSI28kjDG0zlGAZb+W8gqA/PaIi9Tf40YKOAhwrxa9nOUY9pxuImjj1Hc69n9mf+QLzlQ7upj6RcrpFZeksriexZuvbdKyZ0DZGtmMCvsplUkyeL6ZGYezHlFoIcoGxQ9myJ0QFKekpH0/fvEQ1hDhXYlSp3bxSIfGd0CqhnZgJe1W97PLJMNGosvSvWXAhzbFdpEb8JOvAZNoqASZLRnBzZr5b6r6KaJG240dFpVlx5Hvs9m4EFAX+4tqkcRTVde/0plF6E79bFfLgENrNmrxBwBbmbPspj2OcaW8JP7gNuYlOM1LW8iYuzCetD8oH9V+8MKRomPZdEB6Gw1Wc1WJQ12BVBQTb8x8PsGa/ztwGElHL+oPswkpvLGIGL5j6Ea7QBVCCNizxNaVGApPHntYEwo1x1HnCM7WgKoSRi+gG7ihyrTmaLU9uIOZTyCah3vHr5CBFFB5g8Z+Rej8KmnBuY33S4AQcW/Kr7kcDiBPs/ioJ4z9MZzGdW0XnY2qSyhFhEtGB5SXXOiJEwojP8ubuWzbGJnLr4IyvyMI+M/t/a4110UGplD0WTbg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR10MB2448.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(6916009)(86362001)(316002)(8936002)(52116002)(7696005)(956004)(66946007)(6666004)(83380400001)(186003)(6486002)(66476007)(2906002)(38350700002)(26005)(44832011)(30864003)(5660300002)(2616005)(4326008)(508600001)(36756003)(66556008)(107886003)(1076003)(38100700002)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 42JlzrNq0NKP5t7TNaq7pH8yDRihuuCY8YnvNMGEDHuil1xn2ykLzbCUMITuKM7b1XTphWglXkzycit4hNk4dNNPxfXwMSBPNudEZbWpi+atVcEL8XLyql6tqDvSxxLe9KgPVXnQjGJK2FsaXn98SYebY7bm3p6vPP8bo32zGQU6SfnFDQjfD3At6VpWzJGq9EChGQC8K60rlep7pQjeMgmfBmPbXC2yFRBKiGk9xHf9rdO///lPHbz+mTOpmbfHvqySA/HYCWTcl2NgvYrAC1vGjR8gjNox20rfprqH7lQgyy/p4egLURP8zF7D57wPIVWGFPaGYNNqnZhaK0WVIteMiiupJecaer7J1RFVqy3dCfxT6VW8kDOjvcl84KQp3MZHFus86IgYgQgX55uuCbm4NgwGmenCI2POxUkHajCASWTsosvrKkexq7ri++Xbimcac+PeZHANU9wQ2xE3IElzlXScmV713sNNUGxHLq3mG/o7owP6I7S7zF6GXlzpHaYOFlu/ZYzKLuhxzHsT9D+1efR9afNnfRjh8IX+bqJutB6lTwejY2GiPYwM2Upo4KiJMZwsok30hCsso98efKu+mQtBFJBxME4HOfUSGTi83a9b8DGdksPSJQtyzuO7WzfERnPxPCC655zThlSL448fFNWUyAJu+5rDaAOINo5NwY0IHhOmTgzZZmXGKDRA1szRv3DeGrYupeGEQkGfSeUP3Px66Nya7n0pxjMiLDgHIV2ZBt6YTZitnWOQ2Mq28A22xlaRKjCdkBIB/utt7yQv2s8GiFu8EbRA1WxxKauEubpe4ZS8r5HmiQ3Nlzp1UzpJpbESrskU6SEmvCKktVkAx8tjcA30DT1mLDp3h0vpwownl0PQBsmXbpkjsEg0CSJOYfCwDuGzdaWL6pNpUOCM66RA9G4YIFpwng9/7zgISI0IN5hWK+T3s5/Td/9KCRyMlnJcszCEjgHkAVXHVVpuoZQXLOR7yqdTnMsGnE+5cdFgIG0Tk3qC3D0+lev+yEtM6jsB5e82Dj9TX4RbGO6E9IqJOmp4b0njhETQpBxaU4Yaozz+6iSp/039nqEzkbEHDxMWY2YWJ/e7RcgsUjAzQaHy+s8BDPnkWXHeKldKfcUSFLn5vbfU60umP1R2TX/2kAX8JrDTmCz/SL0zpNAz2ymNOjcAHf1RTNplf0iOZOm3zEmHtSXn1s4G4Nl2tAEGyUuOnN0grI0GLQE66B6ZSi/VLT4RnjEzYfzwqI4SWFQIVLzAOFogyWK73OyQWS8T5IHWoaFXnRAV2OIDSAGbORNmW2eONESfkaqZZFfDzHwOvxRUzKh861QUWxI5 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6ee0c1c-5474-4bb0-687d-08d9933f1a96 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB2448.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 20:29:09.0351 (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: japw0nEqwZoOED2hVONPv66v+rs4FquE2cBMDqQ3iNm7np3TujoBcJpgABFhSghwrGQ+IF6nzYDc1Ma4v10yYg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4681 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10142 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110190117 X-Proofpoint-GUID: uluVTsuG2yTSg_wHgc4KXACnxryBOrDM X-Proofpoint-ORIG-GUID: uluVTsuG2yTSg_wHgc4KXACnxryBOrDM Received-SPF: pass client-ip=205.220.165.32; envelope-from=mark.kanda@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) 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.23 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 a QMP command 'query-kvmstats' to query KVM for vm and vcpu fd-based statistics. The kernel support is provided by commit: cb082bfab59a ("KVM: stats: Add fd-based API to read binary stats data") The interface supports an optional 'filter' argument to specify a particular stat to query. Examples: { "execute": "query-kvmstats" } { "return": [ { "name": "vm", "stats": [ { "name": "max_mmu_page_hash_collisions", "unit": "none", "base": 10, "val": [ 0 ], "exponent": 0, "type": "peak" }, { "name": "nx_lpage_splits", "unit": "none", "base": 10, "val": [ 120 ], "exponent": 0, "type": "instant" }, ... } ] }, { "name": "vcpu_0", "stats": [ { "name": "req_event", "unit": "none", "base": 10, "val": [ 500 ], "exponent": 0, "type": "cumulative" }, ... { "execute": "query-kvmstats", "arguments" : { "filter" : "req_event" } } { "return": [ { "name": "vm", "stats": [] }, { "name": "vcpu_0", "stats": [ { "name": "req_event", "unit": "none", "base": 10, "val": [ 500 ], "exponent": 0, "type": "cumulative" } ] }, { "name": "vcpu_1", "stats": [ { "name": "req_event", "unit": "none", "base": 10, "val": [ 61 ], "exponent": 0, "type": "cumulative" } ] } ] } Signed-off-by: Mark Kanda --- accel/kvm/kvm-all.c | 246 ++++++++++++++++++++++++++++++++++++++++++++ qapi/misc.json | 73 +++++++++++++ 2 files changed, 319 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index db8d83b137..597d0c7a09 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -47,6 +47,7 @@ #include "kvm-cpus.h" #include "hw/boards.h" +#include "qapi/qapi-commands-misc.h" /* This check must be after config-host.h is included */ #ifdef CONFIG_EVENTFD @@ -3406,6 +3407,251 @@ int kvm_on_sigbus(int code, void *addr) #endif } +typedef struct KvmStatsArgs { + KvmStats *kvm_stat; /* QAPI auto-generated struct */ + char *filter; + Error **errp; +} KvmStatsArgs; + +static KvmStatDataList *add_kvmstat_entry(struct kvm_stats_desc *pdesc, + uint64_t *stats_data, + KvmStatDataList *data_list, + Error **errp) +{ + KvmStatDataList *data_entry; + uint64List *val_list = NULL; + Error *local_err = 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 = KVM_STAT_TYPE_CUMULATIVE; + break; + case KVM_STATS_TYPE_INSTANT: + data_entry->value->type = KVM_STAT_TYPE_INSTANT; + break; + case KVM_STATS_TYPE_PEAK: + data_entry->value->type = KVM_STAT_TYPE_PEAK; + break; + default: + error_setg(&local_err, "KVM stats: invalid type %u", + (pdesc->flags & KVM_STATS_TYPE_MASK) + >> KVM_STATS_TYPE_SHIFT); + goto exit; + } + + switch (pdesc->flags & KVM_STATS_UNIT_MASK) { + case KVM_STATS_UNIT_NONE: + data_entry->value->unit = KVM_STAT_UNIT_NONE; + break; + case KVM_STATS_UNIT_BYTES: + data_entry->value->unit = KVM_STAT_UNIT_BYTES; + break; + case KVM_STATS_UNIT_CYCLES: + data_entry->value->unit = KVM_STAT_UNIT_CYCLES; + break; + case KVM_STATS_UNIT_SECONDS: + data_entry->value->unit = KVM_STAT_UNIT_SECONDS; + break; + default: + error_setg(&local_err, "KVM stats: invalid unit %u", + (pdesc->flags & KVM_STATS_UNIT_MASK) + >> KVM_STATS_UNIT_SHIFT); + 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: + error_setg(&local_err, "KVM stats: invalid base %u", + (pdesc->flags & KVM_STATS_BASE_MASK) + >> KVM_STATS_BASE_SHIFT); + 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: + error_propagate(errp, local_err); + g_free(data_entry->value->name); + g_free(data_entry->value); + g_free(data_entry); + + return data_list; +} + +static void query_kvmstats(KvmStatsArgs *kvm_stat_args, int stats_fd) +{ + size_t size_desc, size_data; + struct kvm_stats_header *header; + char *id = NULL; + struct kvm_stats_desc *stats_desc = NULL; + Error *local_err = NULL; + ssize_t ret; + int i; + KvmStatDataList *data_list = NULL; /* QAPI auto-generated struct */ + + /* 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->filter) { + if (g_strcmp0(kvm_stat_args->filter, pdesc->name)) { + g_free(stats_data); + continue; + } + } + + /* Add stats entry to the list */ + data_list = add_kvmstat_entry(pdesc, stats_data, data_list, &local_err); + g_free(stats_data); + } + kvm_stat_args->kvm_stat->stats = data_list; + +exit: + error_propagate(kvm_stat_args->errp, local_err); + g_free(stats_desc); + g_free(id); + g_free(header); +} + +static void query_kvmstats_vcpu(CPUState *cpu, run_on_cpu_data data) +{ + KvmStatsArgs *kvm_stats_args = (KvmStatsArgs *) 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_kvmstats(kvm_stats_args, stats_fd); + close(stats_fd); +} + +KvmStatsList *qmp_query_kvmstats(bool has_filter, const char *filter, + Error **errp) +{ + KvmStatsList *stats_list_head, **stats_list_tail = &stats_list_head; + KvmStatsArgs *stats_args; + CPUState *cpu; + KVMState *s = kvm_state; + KvmStats *value; + int stats_fd; + + if (!kvm_enabled()) { + error_setg(errp, "KVM stats: KVM not enabled"); + return NULL; + } + + if (!kvm_check_extension(s, KVM_CAP_BINARY_STATS_FD)) { + error_setg(errp, "KVM stats: not supported"); + return NULL; + } + + stats_args = g_malloc0(sizeof(*stats_args)); + stats_args->errp = errp; + + if (has_filter) { + stats_args->filter = g_strdup(filter); + } + + /* 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"); + g_free(stats_args); + return NULL; + } + value = g_malloc0(sizeof(*value)); + value->name = g_strdup("vm"); + QAPI_LIST_APPEND(stats_list_tail, value); + + stats_args->kvm_stat = value; + query_kvmstats(stats_args, stats_fd); + close(stats_fd); + + /* Query vcpu stats */ + CPU_FOREACH(cpu) { + KvmStats *value = g_malloc0(sizeof(*value)); + value->name = g_strdup_printf("vcpu_%d", cpu->cpu_index); + QAPI_LIST_APPEND(stats_list_tail, value); + + stats_args->kvm_stat = value; + run_on_cpu(cpu, query_kvmstats_vcpu, RUN_ON_CPU_HOST_PTR(stats_args)); + } + + g_free(stats_args); + return stats_list_head; +} + int kvm_create_device(KVMState *s, uint64_t type, bool test) { int ret; diff --git a/qapi/misc.json b/qapi/misc.json index 5c2ca3b556..0ced6a856c 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -523,3 +523,76 @@ 'data': { '*option': 'str' }, 'returns': ['CommandLineOptionInfo'], 'allow-preconfig': true } + +## +# @KvmStatType: +# +# Enumeration of KVM 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: 6.2 +## +{ 'enum' : 'KvmStatType', + 'data' : [ 'cumulative', 'instant', 'peak' ] } + +## +# @KvmStatUnit: +# +# Enumeration of KVM 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: 6.2 +## +{ 'enum' : 'KvmStatUnit', + 'data' : [ 'bytes', 'seconds', 'cycles', 'none' ] } + +## +# @KvmStatData: +# +# Individual KVM stat +# @name: Stat name +# @type: @KvmStatType +# @unit: @KvmStatUnit +# @base: Exponent base (2 or 10) +# @exponent: Used together with @base +# @val: List of uint64 values +# +# Since: 6.2 +## +{ 'struct': 'KvmStatData', + 'data': { 'name': 'str', + 'type': 'KvmStatType', + 'unit': 'KvmStatUnit', + 'base': 'uint8', + 'exponent': 'int16', + 'val': [ 'uint64' ] } } + +## +# @KvmStats: +# +# KvmStats per vm or vcpu +# @name: vm or vcpu_ +# @stats: List of @KvmStatData +# +# Since: 6.2 +## +{ 'struct': 'KvmStats', + 'data': {'name': 'str', + 'stats': [ 'KvmStatData' ] } } + +## +# @query-kvmstats: +# +# @filter: KVM stat name (optional) +# Returns: List of @KvmStats +# +# Since: 6.2 +## +{ 'command': 'query-kvmstats', + 'data': { '*filter': 'str' }, + 'returns': [ 'KvmStats' ] } From patchwork Tue Oct 19 20:29:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Kanda X-Patchwork-Id: 12570999 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 F3895C433EF for ; Tue, 19 Oct 2021 20:31:37 +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 4ECF9611CB for ; Tue, 19 Oct 2021 20:31:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4ECF9611CB 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]:41990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcvlo-0004Qb-A8 for qemu-devel@archiver.kernel.org; Tue, 19 Oct 2021 16:31:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcvjZ-00038k-2E for qemu-devel@nongnu.org; Tue, 19 Oct 2021 16:29:17 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:32250) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcvjW-0008A4-PE for qemu-devel@nongnu.org; Tue, 19 Oct 2021 16:29:16 -0400 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 19JKKARE029622; Tue, 19 Oct 2021 20:29:12 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=xJEIy3rw1rjyK/wnZmEL826a9Pef7rV2Ys7dNYvT+po=; b=mvQMfUpUcPi3bXYzUy8lpYCQVw3gv3Uo+uUDMZpmr7U21/31Fgfw2ECoIle8CxxcpJFO 94J/3A39aiBb8TrVsvd+CvKiCqWl2F4rqbx6xYUrTYV8bskbOaXC19q0dzcMjktift/+ /GFRujGcV/8v9ZwHOJn3BKRYpVnt0rmU1BjPTc80GVl3mkIMlypJtDsP+mgf7XpSHyle /q9KO0ua7MdAyKReg1mdUifYHjNjsFI6it6npCmWcCOvAbkEK/olQm565+is5WlMSSiJ gUHNnogrE7Fm9LWEhnPU3BjwEz7fSwKRKjk8wOyJWhF7Uk8Lxm5NTCavtr/T9hNaft6l 5w== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3bsrefd1yr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Oct 2021 20:29:11 +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 19JKGn0V182179; Tue, 19 Oct 2021 20:29:11 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2170.outbound.protection.outlook.com [104.47.57.170]) by aserp3030.oracle.com with ESMTP id 3bqmsfc8vm-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Oct 2021 20:29:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qkrh/i5wS9OVxEZQgkWWtmFhA16lzCc1zDT+bTGbkNvcUBcRng2wYQQR13dVUq92itTQOLyqiILq1TpejS/4BoKrBbSOmOq2973f76l0Nf+4bABbDhC0GDDYxBKLF4YTeGQt7Zr0lS6FD9jEce+m15zmEEH+P+gVsUTha3hPDaXD784VpVheP6sBCkAeKNp4GWIsLGks2gu9BdGmgS+F+i+r7fM6d5LZV7UaO097tmCnos+5Xf5sTXFRJSfqm0ZDa08Dx8DW7fjRq7WzBs7R3iigs4jYz3Wc5I/j3AAlbgBoWb/zud6iuoQ9WpjoIP+3EF0cKsR14X+1GrqwdCmsCg== 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=xJEIy3rw1rjyK/wnZmEL826a9Pef7rV2Ys7dNYvT+po=; b=inI86T6UbJ8vFkcc4Qd5ljqt/gMi57WeNLNNQNZyl6y3fFNBFeNHJG7JXYYSsxk/35ZW2TdL8n8DkRb+IAl7lUX9BCCZwUmdImniDhBBkWHaeSwqE/5YsMmiX9ZoPusU/fjDfWiApacwregwOY5N5dD5G/z8LCGM5pjtz1CC1oJlLyzvqlHqEFkJbuf4zsB+cHf7d4G3x4rtD6tMBndkO0ME6S1yhcw/ChMdYaCtJecK6eZcoGizO9CffueKxkb/rc/iZaUmTPlsojHHb10xMxVdtLG+PiHVPflojyhnzeDWFZZTcqjWyi+2DuyIOFu4rWGwRUMBhfP5cP5RFmCU4Q== 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=xJEIy3rw1rjyK/wnZmEL826a9Pef7rV2Ys7dNYvT+po=; b=xN4l2KDf217+ntLfI0WoDLgKMD2h0tvjeZO9H+8Xu5qBFFQLoJw4JL4c1QAM2m6olQ7lFo8+xhJtdxk9hAKlIVAIYsiHr3ivvgMx2zmsnC+Dg9z1UkmD7slgh7d/sb2rvE1K2hIbm2OeXvHpy0kEyGeaIz1F7uhjw2w84rhvlwI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from SN6PR10MB2448.namprd10.prod.outlook.com (2603:10b6:805:41::18) by SA2PR10MB4681.namprd10.prod.outlook.com (2603:10b6:806:fb::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Tue, 19 Oct 2021 20:29:09 +0000 Received: from SN6PR10MB2448.namprd10.prod.outlook.com ([fe80::2c40:de5b:9f20:4604]) by SN6PR10MB2448.namprd10.prod.outlook.com ([fe80::2c40:de5b:9f20:4604%5]) with mapi id 15.20.4608.018; Tue, 19 Oct 2021 20:29:09 +0000 From: Mark Kanda To: qemu-devel@nongnu.org Subject: [PATCH 2/2] hmp: Support fd-based KVM stats query Date: Tue, 19 Oct 2021 15:29:04 -0500 Message-Id: <20211019202904.4857-3-mark.kanda@oracle.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211019202904.4857-1-mark.kanda@oracle.com> References: <20211019202904.4857-1-mark.kanda@oracle.com> X-ClientProxiedBy: SN7P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:806:123::31) To SN6PR10MB2448.namprd10.prod.outlook.com (2603:10b6:805:41::18) MIME-Version: 1.0 Received: from linux-1.us.oracle.com (137.254.7.181) by SN7P220CA0026.NAMP220.PROD.OUTLOOK.COM (2603:10b6:806:123::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 20:29:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b6589c44-a79c-4367-5309-08d9933f1b11 X-MS-TrafficTypeDiagnostic: SA2PR10MB4681: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:510; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bjUFWGtqCMv1EjTv5FVZtvCd1mdGseuZeiotVLp5H4E+e4cn8SSExNgOIbUaxuHHIouw4nwwbY/Fh5tyC/hEZkiJfPqJF3MQAfKLuIxxowQjuPn9N5VK8XJO0ezanHgaiT5BFMI2OxPSx7hMscWZsYhs2QyvCLYwI26yr9RjnC4SbG0uOHIN2bUWEpkzkJXBuhObZTKn77FnpvPL6/13THpr2w3SlFedL7MtfyUX9KiMdSSG6SqXveZlsQps+7ebiJObpMsxTV7OyQgzN9nKlElwdN5OOPyaTmrBezzk4gtb7jBy5miW57xI3NjBDoeCKVfgG7yUXCAfevG5ME7HQJyuFY31SdmrR8O30zNyYwde8cOb91EcQKOkyhjwZytP/1+L89Rl/53BhMEaXmlTqTH6S8r/wVzkH4WPwwquJZ2xP2GtDJkYjw+XWz5rPgbFw/fFMxAys9Wv4gwOO+8NAKqsDxtR1csA8uK79e/NzxDPZ7+bjpRnDlv9QftvO878N8/+wyEZGSU5fVs1YOB/w7Krv1zPWE/ZizLkcl2pPr70Oji1+Zs+ED5CIxbHIZd7m98gU7rTx4UBi7rDQxPZOCzWRafsZseX5hUpR9T9Hjaig5t3BrxprXk5z83Rnuigz5ZH22hWBmSEOYk1yu87A6wcHKHql/Niwz2Si3yybod2sBus2I3xwCOhxR7lC8wxVh9uxYupEqYAUeFVFkT9NA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR10MB2448.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(6916009)(86362001)(316002)(8936002)(52116002)(7696005)(956004)(66946007)(6666004)(186003)(6486002)(66476007)(2906002)(38350700002)(26005)(44832011)(5660300002)(2616005)(4326008)(508600001)(36756003)(66556008)(107886003)(1076003)(38100700002)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: L34kOj6FvQakrdMqLglmANjLxbIrmN9ZmwK+r/HJ6q2j5UR8GncO/rv0L7AzeKzFSbHNeczawHDnScUzRsW7t19iPZSodHhbQ/ySMMktTW42LsByeDCljW+63+t4bQGbLkLYKvgyK3a6phXecA3Mgrii0B/ZuTlq/rZsZvFG0oxtn8fTPhMcHb5fK+K25ZD5H9GGH84Nd/ViR8BW9jYf5I/QpCkVDFZ0yP1gr+qLAxMuA9mPRYBXeKVoRcW104nQuFQgPeFEhIsV7lKwvwg8EFMrNjscTEFx+QVhQACep0WN6wHN+U54HPA0RnJ2/kWaxXDwbPuBYby/Jhe2/YlEDWZsDQ1HyvpGuu41xfoVt5k+YKt3GAeqL1hlk1dU67xLi5i95L4P6dlcdyUCs3KWAb+9fdiywOYTB7ERG8WHmduP+Rovx+2rU612T1mOBhHOcv91swHmLlhnuRDAdg598dpoP3l9bTedTZifqAfnu6bi9BBXluEyWa1jLVzYaZxAXaAvaBc5amg9bTD2ayIRDAA3UE0sfRx9Ci50E0zX0RAZUX26r6RfMb0p8MihlnRxL1IIDBbj28KitWN37A2ORYAKpSk3u3ZApL+xsd+8b2wWG/b4XMd7yr8KtPF+VD2EjEX00b5nHMHLdiSvYq/AuCPqOV+jylJJXzfO3jWd7LoYHypTh9uTqqseX0go/NYFs3bKOiBuznmmI+CrfSPrgbMegXt3CEBlgsc9zNaFx+THYuZbVObObUoFmoWN5EyNTn2z0ARf3teMxsvvkj2csbSifyhOQIKlUEyDYgnEY/TkAq9GlFd2hwtt3WxBXwNR+LOyqIFA/OixrFehDy5SnceRCiVBDSP6Z+K1DsYm821pX/BYXwoDIvYTqpjlkNtraR/xJIDoGPV6FzUYp89WnW4YfjVp7wXurs2oyONC+lLJOPry7G7SjasuaBcIybmQm2fZ1LHP8mZU+0eOxGm0EXoe8i1FY+EcX48ZINzZq1ZX8111RauhWOxwNeE310CAjZqu49IjJDJ7NqPqG2GHUd+wdK6nns1yLaJ/0F4YhC43FyggBbjMSURp0nKHrL0IR3SBn8rru9INreFssKkqyGnUdlmnp1CHTKw2MvmfSpEkN1Q4xbH8ABgnTY3RStiloEEBWcLIspZtejyoUePVHaTSg7V3eYgbyGp0F6cdGaKWeWHyITz3map2djTe5uieLlvPCy0IKSgDOX6j5XByZSxKEZbirYaIoRkAU7pFMRR+rj5m5TQ1gkRWCg8eUOJC9PWod0z4PhdWzw17vfRWsPPXRkDuqiOPJqoRVt61iyn8D05dJrWh1GbQGjd1lbk8 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b6589c44-a79c-4367-5309-08d9933f1b11 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB2448.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 20:29:09.8267 (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: 7rWAO7PdT45UmTmOBqkWxNZf0H0LrIC/NNAxscEJcrxSE8t/cbR+YDf3WKCPUB7+YJOfNCn+X2vAiRXwT4xyjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4681 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10142 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110190117 X-Proofpoint-GUID: Oh_3XePygcYN1zCo7yAWHCynUHmEXJOc X-Proofpoint-ORIG-GUID: Oh_3XePygcYN1zCo7yAWHCynUHmEXJOc 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, 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.23 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 fd-based KVM stats. The interface supports an optional 'filter' argument to specify a particular stat to query. Base and exponent are displayed in human readable format. Examples: (qemu) info kvmstats vm: max_mmu_page_hash_collisions (peak): 0 nx_lpage_splits (instant): 114 lpages (instant): 193 mmu_unsync (instant): 0 mmu_cache_miss (cumulative): 293 mmu_recycled (cumulative): 0 mmu_flooded (cumulative): 0 mmu_pde_zapped (cumulative): 0 mmu_pte_write (cumulative): 0 mmu_shadow_zapped (cumulative): 178 remote_tlb_flush (cumulative): 63 vcpu_0: req_event (cumulative): 538 nmi_injections (cumulative): 0 ... (qemu) info kvmstats halt_poll_fail_ns vm: vcpu_0: halt_poll_fail_ns (cumulative): 20*10^-9 seconds vcpu_1: halt_poll_fail_ns (cumulative): 30*10^-9 seconds Signed-off-by: Mark Kanda --- hmp-commands-info.hx | 13 +++++++++++ include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 4c966e8a6b..ef5bca01d9 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -335,6 +335,19 @@ SRST Show KVM information. ERST + { + .name = "kvmstats", + .args_type = "filter:s?", + .params = "filter", + .help = "show KVM statistics; optional filter for stat name", + .cmd = hmp_info_kvmstats, + }, + +SRST + ``info kvmstats`` + Show KVM statistics. +ERST + { .name = "numa", .args_type = "", diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 6bc27639e0..20be8f8586 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -21,6 +21,7 @@ void hmp_handle_error(Monitor *mon, Error *err); void hmp_info_name(Monitor *mon, const QDict *qdict); void hmp_info_version(Monitor *mon, const QDict *qdict); void hmp_info_kvm(Monitor *mon, const QDict *qdict); +void hmp_info_kvmstats(Monitor *mon, const QDict *qdict); void hmp_info_status(Monitor *mon, const QDict *qdict); void hmp_info_uuid(Monitor *mon, const QDict *qdict); void hmp_info_chardev(Monitor *mon, const QDict *qdict); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index bcaa41350e..24a545a66b 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -134,6 +134,58 @@ void hmp_info_kvm(Monitor *mon, const QDict *qdict) qapi_free_KvmInfo(info); } +void hmp_info_kvmstats(Monitor *mon, const QDict *qdict) +{ + KvmStatsList *stats_list, *stats_list_entry; + KvmStats *stats_entry; + KvmStatDataList *data_entry; + KvmStatData *kvm_stat; + uint64List *val; + const char *filter; + Error *err = NULL; + + filter = qdict_get_try_str(qdict, "filter"); + if (filter) { + stats_list = qmp_query_kvmstats(TRUE, filter, &err); + } else { + stats_list = qmp_query_kvmstats(FALSE, NULL, &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", stats_entry->name); + + for (data_entry = stats_entry->stats; data_entry; + data_entry = data_entry->next) { + kvm_stat = data_entry->value; + monitor_printf(mon, " %s (%s):", kvm_stat->name, + KvmStatType_str(kvm_stat->type)); + + for (val = kvm_stat->val; val; val = val->next) { + if (kvm_stat->exponent) { + /* Print the base and exponent as "*^" */ + monitor_printf(mon, " %lu*%d^%d", val->value, + kvm_stat->base, kvm_stat->exponent); + } else { + monitor_printf(mon, " %lu", val->value); + } + } + + /* Don't print "none" unit type */ + monitor_printf(mon, " %s\n", kvm_stat->unit == KVM_STAT_UNIT_NONE ? + "" : KvmStatUnit_str(kvm_stat->unit)); + } + } + qapi_free_KvmStatsList(stats_list); +} + void hmp_info_status(Monitor *mon, const QDict *qdict) { StatusInfo *info;