From patchwork Mon Mar 13 11:40:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13172300 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8F58BC6FD1C for ; Mon, 13 Mar 2023 11:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WxYHaArlSWQDNVWb0Q+HiD792dCrF+E0oMk/PcZfjaA=; b=bKArHGu9VgatQD L96x18SZy8JdMGvVJByQL/hgefkfyWtdxBUb+hA+MvFN1HXqXvHU1ExQxchiACDkVue6kkwTKeJJ6 ZF9NnO7GZBLsUwkkGN/UhhHdSBHxEhVvGrOX0ktWe+nav0DAdysYho0f5ruPlwOmL4Mlve96amGZ1 aowXjShYoqzVkheOODmNlGKjxqwc9sw1tnopVnG0g3363CzRBcOncCRnWpLc4/gnuiii8lC+3cVW8 qkHugCsuQ7NBK5JAxAbTsvrNV0JRVM5T07TFs4YeHJ1ngqsyXFMvMSnyrHnKpBwvg3Uy3oCmAspz4 chC0G9v408xTuexCfe/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgXr-005S1A-Rw; Mon, 13 Mar 2023 11:40:51 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgXj-005Ryk-Sm for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:40:45 +0000 Received: by mail-pj1-x1031.google.com with SMTP id u3-20020a17090a450300b00239db6d7d47so11348730pjg.4 for ; Mon, 13 Mar 2023 04:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707641; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EfFwm9/whD1jR/5n6DKKR8V6Fa945UAISwsDPx5HLJU=; b=UKMSaTwrX/iAEgtNVLYK1CXWlwTqjnwE629XOSX71tKhB6T3cAOlOXRTt3LvlrWi5X FqlTeRl98HKQVTHqKqa29/tAnEmIxP09oGP9/8q3Gu/uMR3E1dnVkTr0nDcF/SOpIkoP K1tgzxVrbtc398A2UEIShZ3XaBB3OyZkCx12EVsY2GMx99hts27vPZWdKGe1VXBA+1u6 DikXAAaaBuGfS5cSKOLPHhi/GvbKi1EyuN0dErkJI4ai+P/eewM/XyDHcbX41FIesMjC bUSF2i+E4x58EQP94dSS6NFDlKbrBcYM7VPl7vL5Hx53Uoj3uCKZWCJSVqDlOx0icC9N HmzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707641; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EfFwm9/whD1jR/5n6DKKR8V6Fa945UAISwsDPx5HLJU=; b=jWVg8ToflzKfPlZfFRsQsQBMgqim38TapRIxqEd/4tFzmBboPUt2gzYU5+/E5u4YH3 PnIvrKAGGxxWaeXzBTfcoeMfYALmhkuU8Fn7w144y+MvdhMdwSyicx5dUORuwN1kPE0z Q5P/wDz3BqjHYUfF8NnJPKhsVXSNH36YlqMX9kBW/eTjEZu+j1yHrg9CGjeAUbj+KH+D S4Fmc4KZ1s700k8Gfh1ehFxa9L17gM5/0UJirpGKQ706QuEccK7jzWIVb1ysm4D/xAQi RZhTSeJyoabAEJHfw5KHgGa7Zxsn+YXf3YDHflY0LA/d6vWQHHx5LaatWwwAPX/35GAz e8CQ== X-Gm-Message-State: AO0yUKUUk6q5lBzjnUUyfq1VZ7dR8zdNABdSqgtbAaHTj6k4rE1SCJo8 FqFAk2dCO/fABS9BOsVosvFwvw== X-Google-Smtp-Source: AK7set9Qn3N/Y7oeDr4/exTQKdkEWr0ZNpz0BljQKMTsO0FQUS1zMkn4oSsJkGhlLxsW10/KuXmQFQ== X-Received: by 2002:a17:902:a986:b0:19d:297:f30b with SMTP id bh6-20020a170902a98600b0019d0297f30bmr26907234plb.19.1678707641163; Mon, 13 Mar 2023 04:40:41 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:40:40 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 01/16] perf kvm: Refactor overall statistics Date: Mon, 13 Mar 2023 19:40:03 +0800 Message-Id: <20230313114018.543254-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044043_937462_1120FF4C X-CRM114-Status: GOOD ( 14.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently the tool computes overall statistics when sort the results. This patch refactors overall statistics during events processing, therefore, the function update_total_coun() is not needed anymore, an extra benefit is we can de-couple code between the statistics and the sorting. This patch is not expected any functionality changes. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 641e739c717c..0172e5b0d26e 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -278,9 +278,14 @@ static double kvm_event_rel_stddev(int vcpu_id, struct kvm_event *event) avg_stats(&kvm_stats->stats)); } -static bool update_kvm_event(struct kvm_event *event, int vcpu_id, +static bool update_kvm_event(struct perf_kvm_stat *kvm, + struct kvm_event *event, int vcpu_id, u64 time_diff) { + /* Update overall statistics */ + kvm->total_count++; + kvm->total_time += time_diff; + if (vcpu_id == -1) { kvm_update_event_stats(&event->total, time_diff); return true; @@ -399,7 +404,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, } } - return update_kvm_event(event, vcpu, time_diff); + return update_kvm_event(kvm, event, vcpu, time_diff); } static @@ -526,15 +531,6 @@ static void insert_to_result(struct rb_root *result, struct kvm_event *event, rb_insert_color(&event->rb, result); } -static void -update_total_count(struct perf_kvm_stat *kvm, struct kvm_event *event) -{ - int vcpu = kvm->trace_vcpu; - - kvm->total_count += get_event_count(event, vcpu); - kvm->total_time += get_event_time(event, vcpu); -} - static bool event_is_valid(struct kvm_event *event, int vcpu) { return !!get_event_count(event, vcpu); @@ -549,7 +545,6 @@ static void sort_result(struct perf_kvm_stat *kvm) for (i = 0; i < EVENTS_CACHE_SIZE; i++) { list_for_each_entry(event, &kvm->kvm_events_cache[i], hash_entry) { if (event_is_valid(event, vcpu)) { - update_total_count(kvm, event); insert_to_result(&kvm->result, event, kvm->compare, vcpu); }