From patchwork Wed Mar 15 14:50:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13175980 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 37C6FC6FD1D for ; Wed, 15 Mar 2023 14:52:33 +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=I+Wpd6AY+kUSAU fE3NDcjwUxNu2jvhSHJJBmt3d0zs0q+B1jJnQLFTwc7wQMdBgLq7lLkN/o9gQJW1ADdmZVfq0on+a DPwb1DrP9ZCV+t6x1w/dQZCn+sFLCaiqM4aoON2NGbNh/5OrhSNMbLf3wWAMeF1LSWwJC1rKvdUwg 3hDiIgRO48vPTNWcn0kMfaEb6RaXLM5MgAxj00ce3B7Gtt55z+c53L32T2ISDp5OGdz7afrZ4tZpx V2VLp4u3I+zuFIt3tJu8Or3vcs/Sc0HPfhbaJNCH4xX48gi2cnnXLPAGnLQ8W06peSlTfOQO0o6l8 B26teFTL8+UP+vSRtDNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTf-00Df81-2N; Wed, 15 Mar 2023 14:51:43 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTc-00Df63-2X for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:51:42 +0000 Received: by mail-pl1-x631.google.com with SMTP id a2so20301462plm.4 for ; Wed, 15 Mar 2023 07:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891896; 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=KZugxK1LyG7HAO7IqFjdN3jXvQsOjnRWzVpP1xL1Tkj+buVGEEfOWxmIeEWzSDvzmK ms1ChOuszpzDA+GTPp/cavDKlnHwnrbJg9aWEbONC8gCP4h9AIZXNdfdmIIU7PgS699C u+XvdrXbhxfDPsFJN08NVERlQD2BKD2nmG8abbH0x+v/k9xl6AqASAFL7+0vfO3Hjt7k bERWmLGJs6VPNa2I4JateIzEU26/E6faw4Ave7It1UOcVjHkD04K/7lOGh4LHpR15J6k AlWwjdIIPAaPJ0Q4V6r39X5q1fYtVug/G0lghp1RvBo1PdU2CPiviKq0RN8I5hNQQPKR ZuIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891896; 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=udjvamUnircgArqfO94UY2oAnMwM1CLgXbXv4tNSQA5Ad1Qlh6xP70TMXCI4Nv4kzX PNJYc54DQCb865bVuBoYaEbuA0CPu3yvNQ2P1VdKqGn4p/ei+vbsZ/v3vqq/UrqeOZb0 1WPkE0DOzhBT5YJEwe6udzizbDbAiUV5XocXw7mT/qGb2sAHo9OVKIiYrBW+0b1nXF1Y CHLnnUnRavZboMqw/lOTTN8rjfQYbTIedv9k3DjuFV28kvRnsWZwdBgKD8btk8/jLIr3 5zYkzYDN7aXxenzIqN2SQ2G3BbAbRMO6M2RCovEaKSqMg7WaeXBh9XinKn2ODSXKXDgN kdUA== X-Gm-Message-State: AO0yUKVWzqd0zaMfjBQKwI24PzsyqcusYIhDHIWEwf2C6205+65NO66G 3UyTKeIhL17vlYkCeJ6WB9y2nA== X-Google-Smtp-Source: AK7set8qMbJAPIuXCdVoB6UCNz7/oT7SO0QBq/H+qHjAhlwX1P6E2qUM6KgqjzOFIiqFu/nUM+XJAg== X-Received: by 2002:a17:903:283:b0:1a1:78e6:d600 with SMTP id j3-20020a170903028300b001a178e6d600mr2650897plr.10.1678891895802; Wed, 15 Mar 2023 07:51:35 -0700 (PDT) Received: from leoy-huanghe.lan ([107.151.177.133]) by smtp.gmail.com with ESMTPSA id kh3-20020a170903064300b0019926c77577sm3781587plb.90.2023.03.15.07.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:51:35 -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 v5 01/16] perf kvm: Refactor overall statistics Date: Wed, 15 Mar 2023 22:50:57 +0800 Message-Id: <20230315145112.186603-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315145112.186603-1-leo.yan@linaro.org> References: <20230315145112.186603-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-20230315_075140_827210_69699DF2 X-CRM114-Status: GOOD ( 13.92 ) 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); }