Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2337143pxp; Mon, 21 Mar 2022 17:20:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDT+xiAlSeWP8d8jXV3IGJR6PNLZIW/ZXlDQzSCnRiltikn5zyvjcBGkReigXgRrc4/FdK X-Received: by 2002:a17:903:20d:b0:154:8227:a389 with SMTP id r13-20020a170903020d00b001548227a389mr1129822plh.142.1647908414021; Mon, 21 Mar 2022 17:20:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647908414; cv=none; d=google.com; s=arc-20160816; b=uLXOpD2EWsbBfIDyTvItqQLhgheoE3Wyp78iM3FFoIVI+IywlROZLA2N0BoO4PNyEn BiKBGbsNYQKjNUQEssAbEmMGBjtZm6PjBx907kZLC7MsscVlRGwhbu1vs2ttP0GR8Omf gJhIIG6zvl5jSLON6TYyzylBcUUPs7svil29yh8T1E3abVJji3f/UW+1jF/XHbQltLpm BzrZxXbCXn3HdWMlckcwbAMhrXPokVXoDAb0FNhrBbvtLReYTEG74Jvh/MEgNWIRKI+E cmGxia1D8hRps/dRvt1bBhSXLPBFJzQpOUpNykhYHV08LVDlkIm7vKhNWGMdsE0DRb7v rLsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=vceLiNWOfgM+5bZss9O1SDm7c/HCij832g8/4XdcLhY=; b=PizKEmK3y0IszNU60ZevWCfp+wFM4NGAQoYGK9znCSVzrjHl5cBQ6yLDZ7Vur2EMtG 3icqso5lByGvpsAFcNYxHQwsYOe3xBUT/KtfQvpw3NHG7b6VIwBXSeLxZ9lSMsrFFvdv I1uG2CwR1aVW4UJNEGGKJil7oYXSETKz/ZRWtue23gfMeJHiAd50goaT2HsVOagpOr/r UelzD6zbEgK+5ThHx0n/FO7YFSx+2crKJ5dY+xYxyaA8EbdkqpQrN5zOV9w75VxIXFJa 5MN6T/Th5Bu64EI/Srr4CwqhtwjgjUq5RXa1mvBfBBTr3rHR25oojNxyqtbhRDzOkxLS OgOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gOUf58e0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j7-20020a63fc07000000b003824583a8efsi9758139pgi.440.2022.03.21.17.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 17:20:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gOUf58e0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B569E1DE6D4; Mon, 21 Mar 2022 16:50:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233627AbiCUXvB (ORCPT + 99 others); Mon, 21 Mar 2022 19:51:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233530AbiCUXur (ORCPT ); Mon, 21 Mar 2022 19:50:47 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 324F61945F1 for ; Mon, 21 Mar 2022 16:49:05 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2e61c5a0eb7so43174117b3.22 for ; Mon, 21 Mar 2022 16:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=vceLiNWOfgM+5bZss9O1SDm7c/HCij832g8/4XdcLhY=; b=gOUf58e0daRwmwx8DRK2eUSK5+zZf9GQPSJOfKC67oaYE3xePJFLGmdzaNCesrM9eE rEJPaBHcY1L6gbvJz/09zE+1rtp90gQsxFXPgpDGak3SWNV7Wds38W2rjqqpLe0hM56Y DDxgBag+C57xsgqih9yYR9isCG1GSWLkDrff1HMjU9JDb+DSq8Q2CtH4ppJl1dY85CLh 3SfIbroo9mTvlYS4CwdBB6yBzi7bgfGAcE+6JWeehG5eRR6ilb9al2Jqdy4Crv8alUsD KjQxttR8idAMjjKExSlWDaeXQfp2p3Cmh4lyvGy9ql/5wwCHX6YycP1/wAB6eHbOiRNT GF7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=vceLiNWOfgM+5bZss9O1SDm7c/HCij832g8/4XdcLhY=; b=kvJeB7TNywqDMWtx1zBgYHiedsWSapRXkXR07GGqPCPb2yTLDjlr70wXr2HBVncq47 pNL5ubiMAlDUA6k0N6cFU2w++aOvWSBQOQzzUP69ukzEO6g8wN6vcsyGP9lRHQYLGaPU r7qSC4LuYgaUuNNvflR1T4UbfKIdUIlK3cmqkDwXI2xND+atC2sUfzS8N8LL7hakivY5 pYv/pE4NEC6FH6IR0Ld5opTRKIrm4xXoru9ySI1/WjyPsirpsAhJcC98gU4ZEKFzh+lG g8mrzCyVtBIMghGdssEdaJVTWm4CWwMqE64bAO5Fc1u+WJtTMwQlyA0OFtoqEanb56pK jWYw== X-Gm-Message-State: AOAM5312nVB1/5+1xo1/AjzBi0cidtgdKxBOIpCkhALywSO3AjjokeWJ wQwkg1fzNfZcbzl2fWCSjMd+IyGPpHPG2qrJ78SODItv36Poe0ok9jUreiqz4+IDYsfzOuKWoLw s0sgNScI/Pbj3aacx/yAw7txYGoiSJmGCaxVVT0TtXAs/6Wwr2kfZVR8v6KzdA0xBvKOw09y9 X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:b76a:f152:cb5e:5cd2]) (user=bgardon job=sendgmr) by 2002:a81:784b:0:b0:2e5:9f35:a90f with SMTP id t72-20020a81784b000000b002e59f35a90fmr27076925ywc.278.1647906538729; Mon, 21 Mar 2022 16:48:58 -0700 (PDT) Date: Mon, 21 Mar 2022 16:48:36 -0700 In-Reply-To: <20220321234844.1543161-1-bgardon@google.com> Message-Id: <20220321234844.1543161-4-bgardon@google.com> Mime-Version: 1.0 References: <20220321234844.1543161-1-bgardon@google.com> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog Subject: [PATCH v2 03/11] KVM: selftests: Test reading a single stat From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Peter Xu , Sean Christopherson , David Matlack , Jim Mattson , David Dunn , Jing Zhang , Junaid Shahid , Ben Gardon Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Retrieve the value of a single stat by name in the binary stats test to ensure the kvm_util library functions work. CC: Jing Zhang Signed-off-by: Ben Gardon --- .../selftests/kvm/include/kvm_util_base.h | 1 + .../selftests/kvm/kvm_binary_stats_test.c | 3 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 53 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 4783fd1cd4cf..78c4407f36b4 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -402,6 +402,7 @@ void assert_on_unhandled_exception(struct kvm_vm *vm, uint32_t vcpuid); int vm_get_stats_fd(struct kvm_vm *vm); int vcpu_get_stats_fd(struct kvm_vm *vm, uint32_t vcpuid); void dump_vm_stats(struct kvm_vm *vm); +uint64_t vm_get_single_stat(struct kvm_vm *vm, const char *stat_name); uint32_t guest_get_vcpuid(void); diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c index afc4701ce8dd..97bde355f105 100644 --- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c +++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c @@ -177,6 +177,9 @@ static void vm_stats_test(struct kvm_vm *vm) /* Dump VM stats */ dump_vm_stats(vm); + + /* Read a single stat. */ + printf("remote_tlb_flush: %lu\n", vm_get_single_stat(vm, "remote_tlb_flush")); } static void vcpu_stats_test(struct kvm_vm *vm, int vcpu_id) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index f87df68b150d..9c4574381daa 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -2705,3 +2705,56 @@ void dump_vm_stats(struct kvm_vm *vm) close(stats_fd); } +static int vm_get_stat_data(struct kvm_vm *vm, const char *stat_name, + uint64_t **data) +{ + struct kvm_stats_desc *stats_desc; + struct kvm_stats_header *header; + struct kvm_stats_desc *desc; + size_t size_desc; + int stats_fd; + int ret = -EINVAL; + int i; + + *data = NULL; + + stats_fd = vm_get_stats_fd(vm); + + header = read_vm_stats_header(stats_fd); + + stats_desc = read_vm_stats_desc(stats_fd, header); + + size_desc = stats_desc_size(header); + + /* Read kvm stats data one by one */ + for (i = 0; i < header->num_desc; ++i) { + desc = (void *)stats_desc + (i * size_desc); + + if (strcmp(desc->name, stat_name)) + continue; + + ret = read_stat_data(stats_fd, header, desc, data); + } + + free(stats_desc); + free(header); + + close(stats_fd); + + return ret; +} + +uint64_t vm_get_single_stat(struct kvm_vm *vm, const char *stat_name) +{ + uint64_t *data; + uint64_t value; + int ret; + + ret = vm_get_stat_data(vm, stat_name, &data); + TEST_ASSERT(ret == 1, "Stat %s expected to have 1 element, but has %d", + stat_name, ret); + value = *data; + free(data); + return value; +} + -- 2.35.1.894.gb6a874cedc-goog