Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp379180pxp; Fri, 11 Mar 2022 06:11:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzf1dFmQ5rIXZKU2Zy8fq3r4GGLwxFLJgVdpcYE+iqUTUsAogMLh8UtMhfaiqcGAEBm/ttN X-Received: by 2002:a17:907:97c7:b0:6da:b3ba:6d9f with SMTP id js7-20020a17090797c700b006dab3ba6d9fmr9114547ejc.256.1647007884244; Fri, 11 Mar 2022 06:11:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647007884; cv=none; d=google.com; s=arc-20160816; b=D1lSSlBmSxrWthfw34X+0aPO8DeUACARSXFPis+5TrAoBqh6381oMHCW86Rcx9e6AJ J+OwCnyiN4jq4+lWMWC7b1yiUq5j/5R9cUdDVSxDlDG0a75w1GkvJF+Kar8AFI6kc11d tljBoNrbxJi+1uX5vjmSTYhoY3yujzpdyRqpJIADJUMCxwQXHOI9SWNunLlMEPutKGQf WOUXrgAQO18M50yct43yfewZyfpDeOmQV5salsqUoixGbG8jkdrVUWq1CAKNN1xrlJf/ V65oNVMffSZlC4eP4vZv7merOEIUXEL15NHNl2cFH1YbMQNHIocbn6jhx8DzBAVIUyrh PRDA== 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=gPwG39gBAUjKtpb2sx5C4T1tsCVeZ7jn+l4C/lt8u+0=; b=0G/9uqUw+el/9zu3ENzm+TNuBYZ6+M+kSQIlH/hUJIU2NxQuC2iRWa9IYeEA/YKmBO /De8OqFDftTKAXKWCK9TK8kBL0l0drWdQviIGdsSdbGyp08VWBvaTlRLvdE+GQyC15n0 E5ZKwxD6mddajJP+CosToOYQmRoLolGMmorxXUKCvTsxiv9MKnhOxMMfFbKdRuQk9N9w D8RFl8hKNELlz27q4AOVQWMyaRJc0NlZxr0QGTHunytZckPPx7ttM68qPv50swJLzpC5 RQr7YKhSF+W8p89wIj8d0P4bWy/gzN4W4AfV+g7cxlBj8l96RavOO47X6Fl8QP0G62o2 YhYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FOOfmLQ0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf8-20020a1709077f0800b006da8444208esi5770435ejc.135.2022.03.11.06.10.57; Fri, 11 Mar 2022 06:11:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FOOfmLQ0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243685AbiCJQq6 (ORCPT + 99 others); Thu, 10 Mar 2022 11:46:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243143AbiCJQqx (ORCPT ); Thu, 10 Mar 2022 11:46:53 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33C9D15FC9A for ; Thu, 10 Mar 2022 08:45:51 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id r11-20020a63440b000000b0038068f34b0cso3248181pga.0 for ; Thu, 10 Mar 2022 08:45:51 -0800 (PST) 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=gPwG39gBAUjKtpb2sx5C4T1tsCVeZ7jn+l4C/lt8u+0=; b=FOOfmLQ0SfEB+1d0/7eVQI9GNQ5Hpb5D1dfnEUhLlO3eyswC3yFNrbrfft+TSB/TVt FyFTD1TNgHH9i5vsdNzHCRSMkbE+ei471JEthPSYWqAF2VkVCabSEovcvUROpLDTan26 DCX97C2bipVAcqij0csXVdincPZZBfnqraghTHlQihBrSGQzaHUH1S3vNV/H0PmbsvYQ xPUY3FF4bf4ot+CPRBZGa6lmzuswtyGehDx/AR0/Lfb3iIndJ7XWGYbvOuG55/tk8Sm1 /hfb3OrXQ62TYF3GUBCySrFYOSHtyxvJSgacZOFNM1XoGnvB0pcmxmEa7+mD5VsvCU6v +I0A== 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=gPwG39gBAUjKtpb2sx5C4T1tsCVeZ7jn+l4C/lt8u+0=; b=FSSJ7sEAxffqsuFss0f/7sXylxUJ5Ii+ap6JIHeJrWsw+hDWU20yfe4tCExf1vDtwH ik90CjxHmLBWPSpumr6F8xYn7oN04yYs895n07/iy9cDQqy/TsDpeXNhbYRaMNtJPWMJ 7L26pqvOOZGdgBULqddW6kkKheU+7iPmnKi/Wtj45eigSII4x2ooubiYEdLLGqVBLIK1 Feu8X59wU0x1h2VQDlmiD+gTRLWUGXFlUIYHtfZiydzZR1dopYLDPnLSCxxiLOgj0e/7 rfKOAtC2QzpVFJiZGykT2UhWxctboJC+l1/VkKwqWUFQSBAIFw4ms5sEhiFiWZsmIjCi uewQ== X-Gm-Message-State: AOAM533G3df55CqI7PT5YsTjmEJHlwe/ABfKc0fNF5lfrDH10Ix+S2/J ErtlulmGc7kNQyOcfKVSL0ChH8U2IMP3E4zkHed/p3FKJJZNB53x8JtJeJw+W5JVTTkaBlTmMGa Ic7OAaDCNaydMTbXzsEvWOlPEZw2xgv1nfsCVB5w0ymmIXxtQinzYzkUUVSAgatdghHIJry14 X-Received: from bgardon.sea.corp.google.com ([2620:15c:100:202:2d58:733f:1853:8e86]) (user=bgardon job=sendgmr) by 2002:a17:90a:2b0f:b0:1bf:37d6:a49d with SMTP id x15-20020a17090a2b0f00b001bf37d6a49dmr6032803pjc.30.1646930750607; Thu, 10 Mar 2022 08:45:50 -0800 (PST) Date: Thu, 10 Mar 2022 08:45:21 -0800 In-Reply-To: <20220310164532.1821490-1-bgardon@google.com> Message-Id: <20220310164532.1821490-3-bgardon@google.com> Mime-Version: 1.0 References: <20220310164532.1821490-1-bgardon@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH 02/13] selftests: KVM: 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.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 c5f4a67772cb..09ee70c0df26 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -401,6 +401,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 4d21c3b46780..1d3493d7fd55 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -2699,3 +2699,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.616.g0bdcbb4464-goog