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); } From patchwork Wed Mar 15 14:50:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13175981 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 68201C7618B for ; Wed, 15 Mar 2023 14:52:38 +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=4iX7SjBmKLIcTiSdt44/VFCtU1Qj7bba7gqVoZtyZIA=; b=xHvbbrQSwzW59t J7RR3HAD4LgXH5tJ8/J0GSdHGJfzNd6GpZAU88s7AJVpVS43ZgW6GfQTv4nUFP5Y42JPXYdytbweu 8S5mKbJCzcEcIRhz5pHDs3zwRo0hyGe1kizc7EUCh5oH4fCiQtqMsWvUpWiCrLb44/2gNFztexNpU /fB49TsaYBdDsCj9cjc1xhmFBeazgSK/8unqpHedXu9UEoZPIMI953bTX7/TpAhQBT5MBCoqJAG/U 0UwEN1SCpapUFKXUco2wdh5MXbom7XaTsxvFJb8RM2pzMEPx/UkoA6hWEJx/ZZtK3RxkL2a1qMSBK SkOHvh7b6b0RreigCgqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTl-00DfBU-0d; Wed, 15 Mar 2023 14:51:49 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTh-00Df7t-0g for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:51:47 +0000 Received: by mail-pj1-x1031.google.com with SMTP id nn12so19069636pjb.5 for ; Wed, 15 Mar 2023 07:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891902; 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=uN7zwUTTarFdEEyI4xavpEstkRipyyWqLXdanEnFXps=; b=dz9O6X6Lyg1W6HzzKFOyVtSVCtOcOjX8KUPSQGJc8jHxSUKbFkz/hVeQ0IeO06vNJg mdjLv5xdlHfxTFYU/l2wMFk6fROQORw9f+TdY+DE/sAZ0crV5vSB73uh2yg2zN10YTvh xVasUftypDkWRNQIu3RitoOknFgaKUxPyubkvgnjtLbhz+rHg3v7VQRqfx+TNBYL5Odu HP32DoZ0l++hvqej4Nr9VAXfhQ5G1LsoSoDWqNN0XKHEPG0uxa6+NmguqPg5R8NBVqEt EvDpy5BRxuliKIwnNrlkfIjTfxGwpNNVfg40LxE94KDTI91OspTkLzwXiQGu7vtLGkM8 OGqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891902; 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=uN7zwUTTarFdEEyI4xavpEstkRipyyWqLXdanEnFXps=; b=M1nsqW4MjS2Knt3Q+sG57R2iyuJcLgAlR5IgFGlfgabHj9+dr1c46d95PWIEZFhxFe UKroIp6mZump2Ri5q0yP6iU3fGaVSx7z+FoR0tJQNO2nf5YP/GkJ5TmmA5jqcYV9vPM2 CYH1X6BG5v30GWjYTAAYGK+yYrpAV9R5TuzFeNNkAr61Z/qHab79q4cA1HAkIOwX0Apf WBcpYSyEpr8gfEVsH7cT15pQE0AmZ9n3PHcLdKoKHRLW8JLACJt+pvuIsl3J//Duz1tW VXQifMkk2+41c08Q63z299egVXH/4E8gqrwECh+Dx3YodA4T4BqwQ6zTmXNFXQ5bJ+o/ KQ1Q== X-Gm-Message-State: AO0yUKUIw+SoQ3QmFnXoDMfRheV25j62ObYBKgdwNaccl5EFbwXsvwmx nheqwWdsA4x7BCeu59KyYwSXXw== X-Google-Smtp-Source: AK7set+18F9Edl6g6CLpmAfVo4MglOMwc0eTGR01kSD+KJBuN3gDndbDDHajhADj2FlU+Vq8nRzdUA== X-Received: by 2002:a17:903:cc:b0:1a0:75bb:2803 with SMTP id x12-20020a17090300cc00b001a075bb2803mr2319315plc.63.1678891901947; Wed, 15 Mar 2023 07:51:41 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:51:41 -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 02/16] perf kvm: Add pointer to 'perf_kvm_stat' in kvm event Date: Wed, 15 Mar 2023 22:50:58 +0800 Message-Id: <20230315145112.186603-3-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_075145_252002_3C50C3EF X-CRM114-Status: GOOD ( 14.43 ) 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 Sometimes, handling kvm events needs to base on global variables, e.g. when read event counts we need to know the target vcpu ID; the global variables are stored in structure perf_kvm_stat. This patch adds add a 'perf_kvm_stat' pointer in kvm event structure, it is to be used by later refactoring. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 6 ++++-- tools/perf/util/kvm-stat.h | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 0172e5b0d26e..3d2560ec6b37 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -209,7 +209,8 @@ static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) return true; } -static struct kvm_event *kvm_alloc_init_event(struct event_key *key) +static struct kvm_event *kvm_alloc_init_event(struct perf_kvm_stat *kvm, + struct event_key *key) { struct kvm_event *event; @@ -219,6 +220,7 @@ static struct kvm_event *kvm_alloc_init_event(struct event_key *key) return NULL; } + event->perf_kvm = kvm; event->key = *key; init_stats(&event->total.stats); return event; @@ -238,7 +240,7 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, return event; } - event = kvm_alloc_init_event(key); + event = kvm_alloc_init_event(kvm, key); if (!event) return NULL; diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 6f0fa05b62b6..40a4b66cfee6 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -24,10 +24,13 @@ struct kvm_event_stats { struct stats stats; }; +struct perf_kvm_stat; + struct kvm_event { struct list_head hash_entry; struct rb_node rb; + struct perf_kvm_stat *perf_kvm; struct event_key key; struct kvm_event_stats total; @@ -44,8 +47,6 @@ struct kvm_event_key { key_cmp_fun key; }; -struct perf_kvm_stat; - struct child_event_ops { void (*get_key)(struct evsel *evsel, struct perf_sample *sample, From patchwork Wed Mar 15 14:50:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13175982 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 F0713C6FD1D for ; Wed, 15 Mar 2023 14:52:40 +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=4CmB8kIvjg1Us3HAKhr0mHDnjk0Icl+j7Ztkbwz8JU0=; b=L8InnQrNGvY2+t Nn791QNZyOWfzWM1T9pgiRpgBRfkz0KnPud/FUZ3sd5jiQrjAD44eBlP7VVPEDOJPHA5pV6rG3asq 2jW2vmdFXkwKXZsE8dERSONap/SiHTWBUrGr4S306/Cc8xpw8csTRnEHNKOjTywM7FaU9Kk45Czb2 rnkv9X3B27xWcv21nXYr/LIffKCnAwro+g9T6hVYbDexXWRZx7rjtAJRQswswQ+1D6sW5Nz1xNG/p 53s5fDpG+ZDK5Q7Jjjy8Ac8mYQW//DggEnDQW/gG92nzgQNESVZcivJLJ2Q/bKtA53wG0FZU2LTmE /eyiTWs4fFmcbLP0Wg0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTq-00DfDx-2V; Wed, 15 Mar 2023 14:51:54 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTm-00DfBD-2X for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:51:52 +0000 Received: by mail-pj1-x102a.google.com with SMTP id p13-20020a17090a284d00b0023d2e945aebso3623114pjf.0 for ; Wed, 15 Mar 2023 07:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891907; 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=F9P/WNNNsLKtkXIlBizDtRA5HEUxXu0PrB/8N0zALdo=; b=kERtE0PayCcJQ3g8DvP/DKEm+wnQqWdaSqaR2NerLnXK+yX4pdUdXXbun86NaJWPip NaNxyTI5DDE93i1z0boAD2DCj4A/Q+JH5zKZBF+AtgiDmsI6LhKtHZRo3UmfqxaZkv4S gt0TLHk4YAc1EW2Y6k2KGJeQ/NUCeaiHOVq+qZ1LAkCDYUmjGguiHLs9W+i9MFdfzYXq bcW5anC2HFx14u31bHEJqluO8X8Rd2yETVU6V587+UuzxZ7KlZvv021+tcLpAjqeDRXn X8OnO6jDOEg9ifMzxC9reG7xPjJdBeEUWaXxO1oRVEkrJdrHYfZWWf+9xqxAp1gXnU/x Zq0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891907; 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=F9P/WNNNsLKtkXIlBizDtRA5HEUxXu0PrB/8N0zALdo=; b=kSgeoxRsE1mXxg/yksqziavIcdDWgHDvEHoTMqTH6eba6Xc0arYd5i4bBr2AYTO7HN oKsoY4x4X6Tp97gkd/UiJXf+J1T+zL8vdcmYcfTi5IYTpO67OQZG7Hy/oSe/VynALB3C G+avn7/PHFSTx1PGrMX0qt0R5z6SLo8iQFi2bg6ZMAlRc2pCMWpUZ3x8b79OXX/GwyWn R6dyEraotouEQir7XVdXAMyRUQ/GTsRIz0Wyl0piwYLEtO70olPGVSPER1v7nR0eIeh0 zsf5XuSbN//ZnkNju5w9sAWqIOKNgVLXbdUczLc3Mr8zNajFJg2+ZZgnNktWQDGBLNRZ zklQ== X-Gm-Message-State: AO0yUKVbp06EejVpjN/ks2kTCeHyWu+2L80WI5pVU7y0iOuvgmR8EsX7 xwJl1N1bF8/ZwzkKoCwTTBTW7w== X-Google-Smtp-Source: AK7set9dml+fP8oxdvMnQArrcIveUFrdND0WQlnru3pW0iTofhwwc7D4RzHBKBI+q2LgpbbPbzhF4Q== X-Received: by 2002:a17:902:d4d0:b0:19f:30be:ea06 with SMTP id o16-20020a170902d4d000b0019f30beea06mr3274410plg.50.1678891907507; Wed, 15 Mar 2023 07:51:47 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:51:47 -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 03/16] perf kvm: Move up metrics helpers Date: Wed, 15 Mar 2023 22:50:59 +0800 Message-Id: <20230315145112.186603-4-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_075150_828133_1D43837B X-CRM114-Status: GOOD ( 14.23 ) 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 This patch moves up the helper functions of event's metrics for later adding code to call them. No any functionality changes, but has a function renaming from compare_kvm_event_{metric}() to cmp_event_{metric}(). Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 72 ++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 3d2560ec6b37..62c097a37da9 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -49,6 +49,42 @@ #include #include +#define GET_EVENT_KEY(func, field) \ +static u64 get_event_ ##func(struct kvm_event *event, int vcpu) \ +{ \ + if (vcpu == -1) \ + return event->total.field; \ + \ + if (vcpu >= event->max_vcpu) \ + return 0; \ + \ + return event->vcpu[vcpu].field; \ +} + +#define COMPARE_EVENT_KEY(func, field) \ +GET_EVENT_KEY(func, field) \ +static int cmp_event_ ## func(struct kvm_event *one, \ + struct kvm_event *two, int vcpu) \ +{ \ + return get_event_ ##func(one, vcpu) > \ + get_event_ ##func(two, vcpu); \ +} + +GET_EVENT_KEY(time, time); +GET_EVENT_KEY(max, stats.max); +GET_EVENT_KEY(min, stats.min); +COMPARE_EVENT_KEY(count, stats.n); +COMPARE_EVENT_KEY(mean, stats.mean); + +#define DEF_SORT_NAME_KEY(name, compare_key) \ + { #name, cmp_event_ ## compare_key } + +static struct kvm_event_key keys[] = { + DEF_SORT_NAME_KEY(sample, count), + DEF_SORT_NAME_KEY(time, mean), + { NULL, NULL } +}; + static const char *get_filename_for_perf_kvm(void) { const char *filename; @@ -461,42 +497,6 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, return true; } -#define GET_EVENT_KEY(func, field) \ -static u64 get_event_ ##func(struct kvm_event *event, int vcpu) \ -{ \ - if (vcpu == -1) \ - return event->total.field; \ - \ - if (vcpu >= event->max_vcpu) \ - return 0; \ - \ - return event->vcpu[vcpu].field; \ -} - -#define COMPARE_EVENT_KEY(func, field) \ -GET_EVENT_KEY(func, field) \ -static int compare_kvm_event_ ## func(struct kvm_event *one, \ - struct kvm_event *two, int vcpu)\ -{ \ - return get_event_ ##func(one, vcpu) > \ - get_event_ ##func(two, vcpu); \ -} - -GET_EVENT_KEY(time, time); -COMPARE_EVENT_KEY(count, stats.n); -COMPARE_EVENT_KEY(mean, stats.mean); -GET_EVENT_KEY(max, stats.max); -GET_EVENT_KEY(min, stats.min); - -#define DEF_SORT_NAME_KEY(name, compare_key) \ - { #name, compare_kvm_event_ ## compare_key } - -static struct kvm_event_key keys[] = { - DEF_SORT_NAME_KEY(sample, count), - DEF_SORT_NAME_KEY(time, mean), - { NULL, NULL } -}; - static bool select_key(struct perf_kvm_stat *kvm) { int i; From patchwork Wed Mar 15 14:51:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13175983 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 2EE73C6FD1D for ; Wed, 15 Mar 2023 14:52:48 +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=PJGapw9uA+hjxTx8SHSM/Lls3Hh8kio0/yVeV1a4LLE=; b=pl3Ok8q1IKAgbh f7GyMFDNVT44YIq5qLxdVc9CHik7rub662PMVbXlY2oUBA52CNnuD5jf517Nj2R2IZdPjO8FIeuzB 0zgpUYurv2XvQa+in3qnxejPi8VwTazVg1g55M2gHWaIFiE7oCedW7s/MO53hYFuT7kkoPnzq5Gk7 yQ+oXqy9u1R8whdIZn2N9Ocq/L9GM+C4r+lqTBYbXjfDWAqLES/iqsoHlrutF9lZADRb41QJoXFHX 0NKOCJDlMSBP/LhkUSxnZKCICP4/fFbHd5nrOkONbZCq8ouXyOQH47jLAfiCFJPrwb1hBOLYvEpyJ sfRzh7Azx+Hdcg047cJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTw-00DfG8-1J; Wed, 15 Mar 2023 14:52:00 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTq-00DfDT-0H for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:51:55 +0000 Received: by mail-pl1-x633.google.com with SMTP id x11so20265289pln.12 for ; Wed, 15 Mar 2023 07:51:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891913; 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=Cd+dkas2glmconcA3nZgOv1IgDvFJOrEFeQZRwvRr9Q=; b=YfMLFLfFXMW5NCpCaRGVHpsK7tI9UBEjIKHVIzaHfGrbedKISm9IE63szUmP0A5hXc R89hHVJJt+esMau2kph4nwZrNEcq8uYxo6x2zXz/r+d7/1Okwxl+v3WF2xwrIDLWcdbs rKjbrgvUGpiPsxhu3jCpASTHDCYRUxlQkQZL/UpPYcesmaXrfepoteyH7ey556AoKLcV kgVebWHBYJbNVH6hI0+VGA6MgvbltWc4xx+/j9J3eeyRFLH5gEKiC5Atg7pquz8y8K4h oQyFyszZGeEd0EK8lsiKu8mQFMxAZsbFmp/dtszSePeLqEOnyuglHR6oSJuvjfqXPNPr M3Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891913; 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=Cd+dkas2glmconcA3nZgOv1IgDvFJOrEFeQZRwvRr9Q=; b=kh1jyRS4NTxV8jKIZ45l++L1gZj54Z57SEvFZ6eRR4+KYzzGLvnrgQUWIrMJeF5E0j ZLDW0pP5hwFHs5h1uKWD1xcVLjQRzObkn60jODb38KxC1FvpqX2gvUenzM1qvBcufyDV 0DPG5LTy4W4m64qJJPxAfGzfKZh0pBza1gJoCRzlb1qDhciKyc2BdLi8LfKnN4N/7yxF cNuJsZEMQ0XJzUw+G/WrRj8e9cKzfkDpyuAVKb5kSbgkaW4ZxnhzH4TT0f9+yjfhs6D7 ZimGfcAoZ+RIbt3chOaPbf4FY6TieUz/J2ZbV0QUVdPwUqQ94XULwt29TOIs3EaR/SjM CcBg== X-Gm-Message-State: AO0yUKV07ROMB7QNFFn/G6C0VS9xylsXNZwBSAw8C3IAccG8l1RARPVd QnV0bsEJvKKgOqr8tVtKpuF8lA== X-Google-Smtp-Source: AK7set+OD/ekdbUPyKgmlJavsWyrlHgkyNT+r7p946TYxjT0XL2xAzkm0EgeNF4uEnXoKDJhxpAPAQ== X-Received: by 2002:a17:903:234a:b0:19f:3797:d8de with SMTP id c10-20020a170903234a00b0019f3797d8demr3589747plh.9.1678891913436; Wed, 15 Mar 2023 07:51:53 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:51:53 -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 04/16] perf kvm: Use subtraction for comparison metrics Date: Wed, 15 Mar 2023 22:51:00 +0800 Message-Id: <20230315145112.186603-5-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_075154_124504_4EBC71CF X-CRM114-Status: GOOD ( 15.60 ) 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 metrics comparison uses greater operator (>), it returns the boolean value (0 or 1). This patch changes to use subtraction as comparison result, which can be used by histograms sorting. Since the subtraction result is u64 type, we change key_cmp_fun's return type to int64_t to avoid overflow. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 6 +++--- tools/perf/util/kvm-stat.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 62c097a37da9..4e9519390da6 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -63,10 +63,10 @@ static u64 get_event_ ##func(struct kvm_event *event, int vcpu) \ #define COMPARE_EVENT_KEY(func, field) \ GET_EVENT_KEY(func, field) \ -static int cmp_event_ ## func(struct kvm_event *one, \ +static int64_t cmp_event_ ## func(struct kvm_event *one, \ struct kvm_event *two, int vcpu) \ { \ - return get_event_ ##func(one, vcpu) > \ + return get_event_ ##func(one, vcpu) - \ get_event_ ##func(two, vcpu); \ } @@ -523,7 +523,7 @@ static void insert_to_result(struct rb_root *result, struct kvm_event *event, p = container_of(*rb, struct kvm_event, rb); parent = *rb; - if (bigger(event, p, vcpu)) + if (bigger(event, p, vcpu) > 0) rb = &(*rb)->rb_left; else rb = &(*rb)->rb_right; diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 40a4b66cfee6..0c2400d9b227 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -40,7 +40,7 @@ struct kvm_event { struct kvm_event_stats *vcpu; }; -typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); +typedef int64_t (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); struct kvm_event_key { const char *name; From patchwork Wed Mar 15 14:51:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13175984 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 3DA32C6FD1D for ; Wed, 15 Mar 2023 14:52:56 +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=5pdmhOn3rzobbY2U7g3AmkIVfI30DOucPEPs8ePo6K0=; b=0HJV03lLidzTGq 8LOwuhvUpFUv6hFc/hcy0T4YKlAYmaj6x0aMrW1C/cpfyJjeGleXF5eMOTzuAqiNqtegtySORKDf1 JOb/yK0iEFTkAYCOeSiW/NZ83DBIflMGrpH/2uWAVxeQFIGtj3N+ZsPv3vG+lhdW6DwnxZ0jUMIIP k7vCWpEtCv+1tw+8KTGnepaCr4xYpSydJKpEaZqMJ8gRRwD87S+h9qPDLAhKXgnjTDvzGIO61WhM+ c8KN7t0B2t1qPL5OJEyA+ypYY91SnU+xo8486wuEFrC3WkvLBEQ2A4TPKa2yporGSpUqB3FU5gQNg Qi2iDv8ZAbumYeXv+Djw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSU2-00DfJC-2Z; Wed, 15 Mar 2023 14:52:06 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTz-00DfFv-38 for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:05 +0000 Received: by mail-pl1-x630.google.com with SMTP id i5so20312843pla.2 for ; Wed, 15 Mar 2023 07:51:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891919; 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=/ZjK+hr7JcZKa/bO3cuF+Qb3HZ2OSLLueCbPuYXRIsQ=; b=IyU4UgiasNb7sQ+9KfUeWXj6x+B0edjXQNGe8p+rVaNpm3PkPUswmR2xSxu6v9CbGo ptmsIxMZdIs0kdw7wuZso4xmCS/3F8XVS6Fh4rfbBPYJxu6u/xrucec9brj/wt6f4unx NCJdJ65y3Wqe0hQJQ4mTSbxEeIHMZS+Y2HgMQsH52BwTO7bVP4vzQBkdXxdtHuXAxAb/ 6aAN+phPK7GVEESezJOzxgnZ/h2Boigz7qIcV6Jkx9CRdzYVQdTcFVzJP+XfY0caiSop 0O4wTIxTdlX8z+OVpkTapRmaGlZQJAxDSQFOE+s7MLSEfRBSFsNDG7elDlsvmXtLnoM4 0Vlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891919; 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=/ZjK+hr7JcZKa/bO3cuF+Qb3HZ2OSLLueCbPuYXRIsQ=; b=oN9+Tzt/An8VoX1wIDh/LUKG7fw2cFVfaY2tpvGOwNeluJNw+PjCVawZStqFIw6kWr 1zcQ1Ls8XNHfU4/paGrYNqjRg9mEnGzZK1vQg7QT09uOphksULWq7+zN12l00kyaOj0m qU/KmjKt+94l2sylrPfqmo1MNfqWAyV/prD+DWlqGMwN23V0dz3jO9XeoJRgJytSAT92 UaiJdvATyE4l+kStnF73wzUzWkNOAO/VSgeFHLo1TT+m0NH4suXLKNEVxnWKbUgOLTge oY0rPR3qgfJDWfibswtCIM0jkGt7gRj3HY8Q0H0XxWfn1IprzP4EVfZQGQFikXLjqf1L Hvwg== X-Gm-Message-State: AO0yUKVldlNQd7iXcGpWx+XIbd42X+N/lrSF7ZdSXmaCIwa8t+z4TUzq z8xEHD6xPkzF69DFzg+aooaNTQ== X-Google-Smtp-Source: AK7set8Yh2PYaPUVuTnwTRUWOSUJd8SHurhxbIimvPTgXecs/zyq/ORsGmnyEvsiBWGfEbATml+14g== X-Received: by 2002:a17:902:fb4c:b0:1a0:53f3:3762 with SMTP id lf12-20020a170902fb4c00b001a053f33762mr2708370plb.46.1678891919097; Wed, 15 Mar 2023 07:51:59 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:51:58 -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 05/16] perf kvm: Use macro to replace variable 'decode_str_len' Date: Wed, 15 Mar 2023 22:51:01 +0800 Message-Id: <20230315145112.186603-6-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_075204_022159_D3250B8A X-CRM114-Status: GOOD ( 15.82 ) 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 The variable 'decode_str_len' defines the string length for KVM event name and every arch defines its own values. This introduces complexity that the variable definition are spreading in multiple source files under arch folder. This patch refactors code to use a macro KVM_EVENT_NAME_LEN to define event name length and thus remove the definitions in arch files. Signed-off-by: Leo Yan --- tools/perf/arch/arm64/util/kvm-stat.c | 1 - tools/perf/arch/powerpc/util/kvm-stat.c | 3 +-- tools/perf/arch/s390/util/kvm-stat.c | 1 - tools/perf/arch/x86/util/kvm-stat.c | 7 +++---- tools/perf/builtin-kvm.c | 10 +++++----- tools/perf/util/kvm-stat.h | 3 ++- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/tools/perf/arch/arm64/util/kvm-stat.c b/tools/perf/arch/arm64/util/kvm-stat.c index 73d18e0ed6f6..72ca9bb45804 100644 --- a/tools/perf/arch/arm64/util/kvm-stat.c +++ b/tools/perf/arch/arm64/util/kvm-stat.c @@ -11,7 +11,6 @@ define_exit_reasons_table(arm64_trap_exit_reasons, kvm_arm_exception_class); const char *kvm_trap_exit_reason = "esr_ec"; const char *vcpu_id_str = "id"; -const int decode_str_len = 20; const char *kvm_exit_reason = "ret"; const char *kvm_entry_trace = "kvm:kvm_entry"; const char *kvm_exit_trace = "kvm:kvm_exit"; diff --git a/tools/perf/arch/powerpc/util/kvm-stat.c b/tools/perf/arch/powerpc/util/kvm-stat.c index 1a9b40ea92a5..d04a08c9fd19 100644 --- a/tools/perf/arch/powerpc/util/kvm-stat.c +++ b/tools/perf/arch/powerpc/util/kvm-stat.c @@ -14,7 +14,6 @@ #define NR_TPS 4 const char *vcpu_id_str = "vcpu_id"; -const int decode_str_len = 40; const char *kvm_entry_trace = "kvm_hv:kvm_guest_enter"; const char *kvm_exit_trace = "kvm_hv:kvm_guest_exit"; @@ -80,7 +79,7 @@ static void hcall_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, { const char *hcall_reason = get_hcall_exit_reason(key->key); - scnprintf(decode, decode_str_len, "%s", hcall_reason); + scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", hcall_reason); } static struct kvm_events_ops hcall_events = { diff --git a/tools/perf/arch/s390/util/kvm-stat.c b/tools/perf/arch/s390/util/kvm-stat.c index 34da89ced29a..0aed92df51ba 100644 --- a/tools/perf/arch/s390/util/kvm-stat.c +++ b/tools/perf/arch/s390/util/kvm-stat.c @@ -19,7 +19,6 @@ define_exit_reasons_table(sie_diagnose_codes, diagnose_codes); define_exit_reasons_table(sie_icpt_prog_codes, icpt_prog_codes); const char *vcpu_id_str = "id"; -const int decode_str_len = 40; const char *kvm_exit_reason = "icptcode"; const char *kvm_entry_trace = "kvm:kvm_s390_sie_enter"; const char *kvm_exit_trace = "kvm:kvm_s390_sie_exit"; diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c index c5dd54f6ef5e..ef513def03ba 100644 --- a/tools/perf/arch/x86/util/kvm-stat.c +++ b/tools/perf/arch/x86/util/kvm-stat.c @@ -18,7 +18,6 @@ static struct kvm_events_ops exit_events = { }; const char *vcpu_id_str = "vcpu_id"; -const int decode_str_len = 20; const char *kvm_exit_reason = "exit_reason"; const char *kvm_entry_trace = "kvm:kvm_entry"; const char *kvm_exit_trace = "kvm:kvm_exit"; @@ -77,7 +76,7 @@ static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, struct event_key *key, char *decode) { - scnprintf(decode, decode_str_len, "%#lx:%s", + scnprintf(decode, KVM_EVENT_NAME_LEN, "%#lx:%s", (unsigned long)key->key, key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R"); } @@ -121,7 +120,7 @@ static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, struct event_key *key, char *decode) { - scnprintf(decode, decode_str_len, "%#llx:%s", + scnprintf(decode, KVM_EVENT_NAME_LEN, "%#llx:%s", (unsigned long long)key->key, key->info ? "POUT" : "PIN"); } @@ -165,7 +164,7 @@ static void msr_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, struct event_key *key, char *decode) { - scnprintf(decode, decode_str_len, "%#llx:%s", + scnprintf(decode, KVM_EVENT_NAME_LEN, "%#llx:%s", (unsigned long long)key->key, key->info ? "W" : "R"); } diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 4e9519390da6..d400434aa137 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -159,7 +159,7 @@ void exit_event_decode_key(struct perf_kvm_stat *kvm, const char *exit_reason = get_exit_reason(kvm, key->exit_reasons, key->key); - scnprintf(decode, decode_str_len, "%s", exit_reason); + scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason); } static bool register_kvm_events_ops(struct perf_kvm_stat *kvm) @@ -432,7 +432,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, time_diff = sample->time - time_begin; if (kvm->duration && time_diff > kvm->duration) { - char decode[decode_str_len]; + char decode[KVM_EVENT_NAME_LEN]; kvm->events_ops->decode_key(kvm, &event->key, decode); if (!skip_event(decode)) { @@ -603,7 +603,7 @@ static void show_timeofday(void) static void print_result(struct perf_kvm_stat *kvm) { - char decode[decode_str_len]; + char decode[KVM_EVENT_NAME_LEN]; struct kvm_event *event; int vcpu = kvm->trace_vcpu; @@ -614,7 +614,7 @@ static void print_result(struct perf_kvm_stat *kvm) pr_info("\n\n"); print_vcpu_info(kvm); - pr_info("%*s ", decode_str_len, kvm->events_ops->name); + pr_info("%*s ", KVM_EVENT_NAME_LEN, kvm->events_ops->name); pr_info("%10s ", "Samples"); pr_info("%9s ", "Samples%"); @@ -633,7 +633,7 @@ static void print_result(struct perf_kvm_stat *kvm) min = get_event_min(event, vcpu); kvm->events_ops->decode_key(kvm, &event->key, decode); - pr_info("%*s ", decode_str_len, decode); + pr_info("%*s ", KVM_EVENT_NAME_LEN, decode); pr_info("%10llu ", (unsigned long long)ecount); pr_info("%8.2f%% ", (double)ecount / kvm->total_count * 100); pr_info("%8.2f%% ", (double)etime / kvm->total_time * 100); diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 0c2400d9b227..841b3174c211 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -8,6 +8,8 @@ #include "stat.h" #include "record.h" +#define KVM_EVENT_NAME_LEN 40 + struct evsel; struct evlist; struct perf_session; @@ -143,7 +145,6 @@ extern const char *kvm_events_tp[]; extern struct kvm_reg_events_ops kvm_reg_events_ops[]; extern const char * const kvm_skip_events[]; extern const char *vcpu_id_str; -extern const int decode_str_len; extern const char *kvm_exit_reason; extern const char *kvm_entry_trace; extern const char *kvm_exit_trace; From patchwork Wed Mar 15 14:51:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13175985 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 CDB27C6FD1D for ; Wed, 15 Mar 2023 14:53:02 +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=LFJMCzYuRRl8EffW28XSis7DKeg1ibC7nUZuHf+8YiU=; b=apqWuMCt9C0zuI va9PCamvxBSnxcpCg+wxCGVosAkHg9HelqN45EMKV+oHbpfjnKOcbS5CyHVIWZVH+hgF3ypbhuqKp /AzOanyxeo2FfDMqSTQAA19WSr09YcoRrVZaDpG3I6qLChPyuqdZ91XnJ4MAJHjKIkifnTVDb4WDO G4xk8dpb/Xt9FOPHyUBMcAU54smk+veLJ0aCuTgJKELNW0mC3kRElhlBv8xHwCuYdeydhoyQW9d+U BPl2z4od4V4lI0+BX8gDPo3OAfW7RIg2qCN2wdSTm4+frbS9yQkq+J4K3rhrGmDSl3O/efQn9g2Dg etM20QQ434dNtBOjmu3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUA-00DfNV-1Q; Wed, 15 Mar 2023 14:52:14 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSU3-00DfIO-2w for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:09 +0000 Received: by mail-pj1-x1035.google.com with SMTP id e15-20020a17090ac20f00b0023d1b009f52so2087442pjt.2 for ; Wed, 15 Mar 2023 07:52:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891924; 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=6dWIAjzu4GgQ80mkmjPpe056TgbhyOFnv3PTrWVTdCA=; b=fUzax12tR1jc4yHd7um52yUFMB4DBpD59HmSPy6v2+XXoKDz2q9k8Miwh7oLSR05Ub kQfqCFoaWtwiET3HLUD/Wwm8NHCtxZh0xOND0EfXTSfXPpB9pax5H2wFZYq33eiXrmv6 c6mEMagKB5KyibDwg2fnwH9zaUA5HURAgvayY2vZQxIfDVH72qUu0yQTVQHqlS5hGlUL cKYTKOYL64ufrUHf6+wk7p/Yc0egjNySxbPTxDIHVPr/ND3KoG1O28AREWQc2Y58wW0u QkIZ0p/3GfJVJUcv7u3S+AMTtkX46ac8IgOv7uniyAL2SYqSO53BEK3knnVNxFoSzZOq JX6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891924; 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=6dWIAjzu4GgQ80mkmjPpe056TgbhyOFnv3PTrWVTdCA=; b=21muBsvRK17zQz06bzFWB+DJ4YGrMRjt7KFLapngKWE5fArTrqJoaye6Ssmn2EQ/Xn 7JUVI0RbY+U3ymkIIHrjEPULa7YJa/OKIRuUwAFr2vRXpY2erIIa2BmGTxZp1k+toBZB qXUhwSp2rsRa1MCMxzxf7IaXbwSciBRFEsM+JSkZ57IqfppSVwNGqmrb+C4nR8j3ZtLM kPDAbflWQ9RtlYTQ1XFOvOkUKWEWA3VJxAUCEkWtThiqJZqiskS5k5MTVbhN4E5y40RG uaFIo4IG8KV6nFLRuT+QvQA7NPQspCSh9EYfnqu8yra1w3wgGtO7PdSktALBMN8iwsJ+ wUTA== X-Gm-Message-State: AO0yUKWYwJTEQ+JlTMWGBb+7Tj3N7GVVlNUC1ZnazuwhswkqmuKhxHfm leSzJmiHRyHqPBIonIuGwaKAsQ== X-Google-Smtp-Source: AK7set+0vZiNilSAoQVttsUGF4dFlIy3XJFLbztvrLMK/BPFXynFDi8kiNCSEB7dOrxUJzH4eKLQ0w== X-Received: by 2002:a17:903:410a:b0:19f:2b42:5d01 with SMTP id r10-20020a170903410a00b0019f2b425d01mr2475678pld.9.1678891924631; Wed, 15 Mar 2023 07:52:04 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:04 -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 06/16] perf kvm: Introduce histograms data structures Date: Wed, 15 Mar 2023 22:51:02 +0800 Message-Id: <20230315145112.186603-7-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_075207_970970_D579A931 X-CRM114-Status: GOOD ( 13.14 ) 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 This is a preparation to support histograms in perf kvm tool. As first step, this patch defines histograms data structures and initialize them. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 18 ++++++++++++++++++ tools/perf/util/kvm-stat.h | 1 + 2 files changed, 19 insertions(+) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index d400434aa137..384992c8a01a 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -85,6 +85,20 @@ static struct kvm_event_key keys[] = { { NULL, NULL } }; +struct kvm_hists { + struct hists hists; + struct perf_hpp_list list; +}; + +static struct kvm_hists kvm_hists; + +static int kvm_hists__init(void) +{ + __hists__init(&kvm_hists.hists, &kvm_hists.list); + perf_hpp_list__init(&kvm_hists.list); + return 0; +} + static const char *get_filename_for_perf_kvm(void) { const char *filename; @@ -957,6 +971,8 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm) set_term_quiet_input(&save); init_kvm_event_record(kvm); + kvm_hists__init(); + signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); @@ -1152,6 +1168,8 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) init_kvm_event_record(kvm); setup_pager(); + kvm_hists__init(); + ret = read_events(kvm); if (ret) goto exit; diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 841b3174c211..e2c17662bac7 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -5,6 +5,7 @@ #ifdef HAVE_KVM_STAT_SUPPORT #include "tool.h" +#include "sort.h" #include "stat.h" #include "record.h" From patchwork Wed Mar 15 14:51: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: 13175987 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 E0B7AC76195 for ; Wed, 15 Mar 2023 14:53:11 +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=5y5oEQVKFbLVTsye6xdv3mZgAfUbatPDH3ykig8+Xq4=; b=XFpTewUb3LTwOT XwGeLZYPTDPZbHDPTEb6YKsGQHoKRn7TLRZipDHEnTgu0TquWHNAavXv9AcHd8p8tM3nuv8bo71lt oZNERM0EXGMPM6HvWxlvTGBAMB++qyAkH4WWLgUNv6Mkh3NUQ+GTWQyWU+9fL4ZKBduNV3JukmA2s in7XjFBmHLIFr3CQwwL/O1nOgy+QSQAkuCv61ib4QMcfPtyPZRa/5foMMZ7BxiPC3MBSthWz6fgCp 8zEaGAWKxHuhtw4/tXQKhX+0XvLfH5/l0WkA4DhPUAC962x7OzJUluaNJLmJqwAfv28OSzPFOeQRX NjODGQsujwNkNefung5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUH-00DfSN-2D; Wed, 15 Mar 2023 14:52:21 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUA-00DfLr-0k for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:18 +0000 Received: by mail-pl1-x62f.google.com with SMTP id ix20so13784107plb.3 for ; Wed, 15 Mar 2023 07:52:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891930; 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=5IYKqlpTPvf4B9W/g9ZH0t1bS6GpjcqsifmwRVPlTPE=; b=x26vR0cXHAFQU/OylVs2A3pi9LFcSWhxlTPtYlnieFE6JRYXKgGQjVDkwSz7QBu5Nx sdvHxXI6FCFLlxlORUkFmaDzo7e2JKoejjxpI77bGeCaGT0aJvgzeTyTIGuslcdclVi5 4TyBRDLbeYmM30AYhhN/tIRqhmY1rOQoI7Qh2igwUxOgE9q+zNEal4k+XrYiYA/wFEbX GpLqe98MM+jvGMhcu0NygeMstpsEtut5+Ln4qooWLr4XER7qNB8BAn5pYP21IUt7Cr0h JnvhBx0OLd+HHK3BremRi9jiXeD9D5mWzW4fGYvXak1SBax78tZKH4CZ8TItk5jLYUlB GL2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891930; 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=5IYKqlpTPvf4B9W/g9ZH0t1bS6GpjcqsifmwRVPlTPE=; b=MI2zhc5tUmMFyoI5e/WH9S6vIbsOOR361LWJ8mmrWGskkAQXOGZmy+US8jJSXChJOy DF+TFcQ+Gpi9z5c8n3zITUGSOZ9T9/71YMYb+gZGWFo1HCcH57KK5l7G4cqQFSVKT2In JEFbJI5Z+YLhz+eBrDlwLm7oBX4DXx9jNX40OSl1atxV8k0VuW4Ag37AxtXDhfrPk9VI +RWYZXbQ6tNM2qec4g44cy7B77Ic+w2PkHwf5yEBOfav9XORyqSzVEETJo/eFCHKccdZ 7Xm/JHgef5BWZzk1m5eqpj2O2P0JHmPbo0Ge/7XU2Ry38iMYvqMMeW89eW8AQY+2jTil eOnQ== X-Gm-Message-State: AO0yUKXY9IMhRylxpFbeMsaBZ7MZShhDT1mJHbG6dkJUEBNlIaGjezXD oRi1Nw7innTtOAV+1bQ6KAXwAA== X-Google-Smtp-Source: AK7set9VmJ9JazfbYgtFRf8oYUnPBYBITGOROjQDD6rD7Vh7Iej4zmzLmmZrN85pIp3yfHORhfPzng== X-Received: by 2002:a17:903:283:b0:19c:e0fe:ed2b with SMTP id j3-20020a170903028300b0019ce0feed2bmr3360060plr.54.1678891930227; Wed, 15 Mar 2023 07:52:10 -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.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:09 -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 07/16] perf kvm: Pass argument 'sample' to kvm_alloc_init_event() Date: Wed, 15 Mar 2023 22:51:03 +0800 Message-Id: <20230315145112.186603-8-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_075214_292645_A74EFEAF X-CRM114-Status: GOOD ( 14.83 ) 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 This patch adds an argument 'sample' for kvm_alloc_init_event(), and its caller functions are updated as well for passing down the 'sample' pointer. This is a preparation change to allow later patch to create histograms entries for kvm event, no any functionality changes. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 384992c8a01a..5ea723fd45a4 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -260,7 +260,8 @@ static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) } static struct kvm_event *kvm_alloc_init_event(struct perf_kvm_stat *kvm, - struct event_key *key) + struct event_key *key, + struct perf_sample *sample __maybe_unused) { struct kvm_event *event; @@ -277,7 +278,8 @@ static struct kvm_event *kvm_alloc_init_event(struct perf_kvm_stat *kvm, } static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, - struct event_key *key) + struct event_key *key, + struct perf_sample *sample) { struct kvm_event *event; struct list_head *head; @@ -290,7 +292,7 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, return event; } - event = kvm_alloc_init_event(kvm, key); + event = kvm_alloc_init_event(kvm, key, sample); if (!event) return NULL; @@ -300,15 +302,16 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, static bool handle_begin_event(struct perf_kvm_stat *kvm, struct vcpu_event_record *vcpu_record, - struct event_key *key, u64 timestamp) + struct event_key *key, + struct perf_sample *sample) { struct kvm_event *event = NULL; if (key->key != INVALID_KEY) - event = find_create_kvm_event(kvm, key); + event = find_create_kvm_event(kvm, key, sample); vcpu_record->last_event = event; - vcpu_record->start_time = timestamp; + vcpu_record->start_time = sample->time; return true; } @@ -375,12 +378,12 @@ static bool is_child_event(struct perf_kvm_stat *kvm, static bool handle_child_event(struct perf_kvm_stat *kvm, struct vcpu_event_record *vcpu_record, struct event_key *key, - struct perf_sample *sample __maybe_unused) + struct perf_sample *sample) { struct kvm_event *event = NULL; if (key->key != INVALID_KEY) - event = find_create_kvm_event(kvm, key); + event = find_create_kvm_event(kvm, key, sample); vcpu_record->last_event = event; @@ -429,7 +432,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, return true; if (!event) - event = find_create_kvm_event(kvm, key); + event = find_create_kvm_event(kvm, key, sample); if (!event) return false; @@ -500,7 +503,7 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, return true; if (kvm->events_ops->is_begin_event(evsel, sample, &key)) - return handle_begin_event(kvm, vcpu_record, &key, sample->time); + return handle_begin_event(kvm, vcpu_record, &key, sample); if (is_child_event(kvm, evsel, sample, &key)) return handle_child_event(kvm, vcpu_record, &key, sample); From patchwork Wed Mar 15 14:51:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13175986 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 7C219C61DA4 for ; Wed, 15 Mar 2023 14:53:10 +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=fG5ALFEx9mWhB/4voCzIDe9SPRqab+1zrpu5oUzpfjU=; b=UpsXolF6GSOAWf TSrovsFbeVazGEQfbn6bblk74TAW5pb6DGJpREGqQx3VcWlwFqggx69tuKeuuTw8sEN/kahWU6r4o 4oQV0oNIFZ6Uyo0YyIQUWmqhihLRb7E4WkLMECCMNaidn2fC0pERfTzaBO34RopF+j+GN+3iVcHmt 2oM2BQQc39abJjemoB+n0Zq+z7AwY54HWoAA+TAcCIEJbk91O5xjjgZL1d7xskOToddIFXO1X6680 vjLRschy9nBzcB+vVuZy5rEE7M/piuyIjwy2mPxX0rar1mwWPsrAGzr5N4fPWUWoTRPZpqR9Yyy26 NSOICRnZKleFuO+unr/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUG-00DfRS-08; Wed, 15 Mar 2023 14:52:20 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUC-00DfOw-1g for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:18 +0000 Received: by mail-pl1-x62b.google.com with SMTP id ix20so13784416plb.3 for ; Wed, 15 Mar 2023 07:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891936; 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=BxPULJO486xqHJLRx8ubmkrWzwK0iscBf1dUdchHcWA=; b=ZG/EslB6f9/yZgtygYyLalr/i45+cTyqD6wRGVjTxOdd7TWk/8vE9TdItJGBNewgvh 3KbsUsgRWQXrncEp3I3jNl3GYazW55VQF/E1YK7YcNix0tfCf+T4GCHgNBOTkIoeavo5 152APIwoh4PuPEuyfV2T+1L0ZlK9MmzttdZHQATRNTyFQ9JzwrIl7bBMLnV1DdGZvk7R n0MiLIGN+11YRriy+F6haDjrxnbBu2fXfDIp2XP/rlLlZL1dFunykx1yMhHmEU02sriM W9dPj2mht+HhvdEYnC+8cqXLqvyIDe/sfVGBaxlezH+Nh0T14MX4032pNzqW9nstfYDD MBBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891936; 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=BxPULJO486xqHJLRx8ubmkrWzwK0iscBf1dUdchHcWA=; b=6KVBrG5F6wNcDm90MTUVcFYYkx/sY+fCIIwE8Rv2JWC/M+f962P2a0cFSYYD57eBEH p91irHHYbrxPO+w5ToblvAUAe92wwbXs/k1FMtXecAr6WLnaPc00on9H1egji1sCFBNC 7blcjQ7yk9NXO8YGW3fSZfPd0AcuNE2l4E5fKJcWZku3ldXFsxtEsya/52tkUC7i8qQE JcwLnqT1aItcpbCS6HpjdD/A+GN46wADYuW+vXAvGe1OWQB4C1UIF99aHEPCZYPZKnpT 1czwr9XDDM0bdappbdlVYYkZMO/HaByxCznLNH7LArVI//R9Ihjnf4ROqadqPyQgREOC YJ2g== X-Gm-Message-State: AO0yUKUj6MvrpgiNGVmedeWUrNG6mPQI2hlCSsCQqLoU3EvIWTJ+X8K/ da7iejf5wbOo6HBzVjOIoiwitw== X-Google-Smtp-Source: AK7set8ko9n4ei4Die1EmIH61gaaEgOSpmUg0Rela+nxsidAZyB6jjslXFnUZTGMDc+45BGJhugZOQ== X-Received: by 2002:a17:902:da8d:b0:1a0:6bd4:ea78 with SMTP id j13-20020a170902da8d00b001a06bd4ea78mr3242115plx.31.1678891935892; Wed, 15 Mar 2023 07:52:15 -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.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:15 -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 08/16] perf kvm: Parse address location for samples Date: Wed, 15 Mar 2023 22:51:04 +0800 Message-Id: <20230315145112.186603-9-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_075216_599620_757970F9 X-CRM114-Status: GOOD ( 14.94 ) 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 Parse address location for samples and save it into the structure 'perf_kvm_stat', it is to be used by histograms entry. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 5 +++++ tools/perf/util/kvm-stat.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 5ea723fd45a4..fa91c8deb628 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -704,6 +704,11 @@ static int process_sample_event(struct perf_tool *tool, if (skip_sample(kvm, sample)) return 0; + if (machine__resolve(machine, &kvm->al, sample) < 0) { + pr_warning("Fail to resolve address location, skip sample.\n"); + return 0; + } + thread = machine__findnew_thread(machine, sample->pid, sample->tid); if (thread == NULL) { pr_debug("problem processing %d event, skipping it.\n", diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index e2c17662bac7..3b2eab91a9be 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -7,6 +7,7 @@ #include "tool.h" #include "sort.h" #include "stat.h" +#include "symbol.h" #include "record.h" #define KVM_EVENT_NAME_LEN 40 @@ -88,6 +89,9 @@ struct perf_kvm_stat { const char *sort_key; int trace_vcpu; + /* Used when process events */ + struct addr_location al; + struct exit_reasons_table *exit_reasons; const char *exit_reasons_isa; From patchwork Wed Mar 15 14:51:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13176007 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 64A2DC7618B for ; Wed, 15 Mar 2023 14:53:27 +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=5YnMPw0N/j/qy4yL3Q1HhSnktq905rQFiayXFYoC6oA=; b=DEDJysR0mN4ptb Noj3AqTPTKlRmiNGtkK/Jv35IUp6y5a0HTqNRXEHZeK4zujF8iwwrfq/hQUCc10WwlCw0jj/nY9vy OGs07LgEwrrPc5ixHk78hw7gyozyEdsTLVzZJUPzE0wDsGGG3y15Z40dQeibMgupcwe+kuYcwiqeQ pAUb8yWikyT5aqAshBQcwWxcVxNekw7aCoJsfNeBvcb13qrikKShxxTJDpO3T4omP/99JxpJcyhWt 9JxAygdLyPRl0/Rtz6/ZxOQFpa/ECwPQoFfbRpXcwZ++Z3v8BjpheB+UAgSZsIblO0Lek3ZSsGxBC DWZ1zZBJ9P3vDdv8eZdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUS-00Dfac-0e; Wed, 15 Mar 2023 14:52:32 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUI-00DfDT-0x for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:24 +0000 Received: by mail-pl1-x633.google.com with SMTP id x11so20266839pln.12 for ; Wed, 15 Mar 2023 07:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891942; 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=YOhDhOeWOQtkq+0QLxaT0/TQ7BTr5as+8gQwmfBvXqw=; b=TngLGB6L6ILQc34i1+/kEMvmtO3rUcdAmtiaYwUcBgsg4DkDGO48NRqelWeBrGvlhi 2i+0jaEhzK8Rsyu/KGM37oc1z6LN+5l8e4J/OZF6J1mkfG5EAyDGFgth1GkIQa0J/qP/ S7hz8FNFUSsDJfo5pXbeyjJAD7OpY3m9hvz3Dvy3wGiLk22C59B69D2Lmj6Cbs67QP7c HPrk/lfrpntgICDtHRZ3rmpAPLSw6JaAP+MRUnpY3mNdjr9EobJtVU2pCOHW2Jo+lXcO l9ko1DwQ+fjatv4sVNaws+qOHFABRLpJHyI0jwnLyCuy+8mh5KOGWRCHo2fAJ/jzlw8X wKXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891942; 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=YOhDhOeWOQtkq+0QLxaT0/TQ7BTr5as+8gQwmfBvXqw=; b=BCeYTvGXi+zHav6wW2D5eXiAkGgyKPpXAEiaPKKbhsZlL0VPVnCKcp1TkJxeqSKcPN sl39dLig+O1FG5/qce/5e56vFLI/Gb7wkO9ukOpWcMhPstP/xC9Nade1eNdxCnLKl0N6 iS/+3DjpCQFuH7YZgeE2Et7Zhi6qzQJkn9Whf8hBhbYCDYplNe0s12bv6jY9YoqV+n8s vXp2txDDGKMVedl8xnV9BwsSXu9Xy9oyq/gFRF2+L8RvUJBWwiVhKGV1rB2oZOkIdj/h xp4vk2JP+9cc1gzA3pDHgbDx2dl0wHULSR0XSV4vQbA26ngKRg8wV4o7P1rfM69/L+j8 zr5w== X-Gm-Message-State: AO0yUKXB5RU0mFCVTRWTlgEJvFUzfso00D5lFWznoP5ThNVj3fAuVfVE 01J+Vv71Cil+NNXzgLRypDSjfg== X-Google-Smtp-Source: AK7set/l0vxrdJxH7nQnaR7my1pa6tnW6WzcM4kLAXzBh173dJl9bXMppIl+ho3Oa3BoN+kPmPv1Bw== X-Received: by 2002:a17:903:1108:b0:19e:8075:5545 with SMTP id n8-20020a170903110800b0019e80755545mr3402214plh.54.1678891941739; Wed, 15 Mar 2023 07:52:21 -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.52.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:21 -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 09/16] perf hist: Add 'kvm_info' field in histograms entry Date: Wed, 15 Mar 2023 22:51:05 +0800 Message-Id: <20230315145112.186603-10-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_075222_369337_C3379765 X-CRM114-Status: GOOD ( 20.70 ) 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 __hists__add_entry() creates a temporary entry and compare it with existed histograms entries, if any existed entry equals to the temporary entry it skips to allocation to avoid duplication. The problem for support KVM event in histograms is it doesn't contain any info to identify KVM event and can be used for comparison entries. This patch adds 'kvm_info' field in the histograms entry which contains the KVM event's key, this identifier will be used for comparison histograms entries in later change. Signed-off-by: Leo Yan --- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-c2c.c | 4 ++-- tools/perf/builtin-diff.c | 4 ++-- tools/perf/tests/hists_link.c | 4 ++-- tools/perf/util/hist.c | 19 ++++++++++++------- tools/perf/util/hist.h | 3 +++ tools/perf/util/kvm-stat.h | 4 ++++ tools/perf/util/sort.h | 1 + 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 90458ca6933f..4750fac7bf93 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -252,7 +252,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, if (ann->has_br_stack && has_annotation(ann)) return process_branch_callback(evsel, sample, al, ann, machine); - he = hists__add_entry(hists, al, NULL, NULL, NULL, sample, true); + he = hists__add_entry(hists, al, NULL, NULL, NULL, NULL, sample, true); if (he == NULL) return -ENOMEM; diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 56974eae0638..d3181fee4d3d 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -315,7 +315,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, c2c_decode_stats(&stats, mi); he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, - &al, NULL, NULL, mi, + &al, NULL, NULL, mi, NULL, sample, true); if (he == NULL) goto free_mi; @@ -349,7 +349,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, goto free_mi; he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, - &al, NULL, NULL, mi, + &al, NULL, NULL, mi, NULL, sample, true); if (he == NULL) goto free_mi; diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index ed07cc6cca56..22b526766e14 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -423,7 +423,7 @@ static int diff__process_sample_event(struct perf_tool *tool, switch (compute) { case COMPUTE_CYCLES: if (!hists__add_entry_ops(hists, &block_hist_ops, &al, NULL, - NULL, NULL, sample, true)) { + NULL, NULL, NULL, sample, true)) { pr_warning("problem incrementing symbol period, " "skipping event\n"); goto out_put; @@ -442,7 +442,7 @@ static int diff__process_sample_event(struct perf_tool *tool, break; default: - if (!hists__add_entry(hists, &al, NULL, NULL, NULL, sample, + if (!hists__add_entry(hists, &al, NULL, NULL, NULL, NULL, sample, true)) { pr_warning("problem incrementing symbol period, " "skipping event\n"); diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c index 14b2ff808b5e..e7e4ee57ce04 100644 --- a/tools/perf/tests/hists_link.c +++ b/tools/perf/tests/hists_link.c @@ -87,7 +87,7 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine) goto out; he = hists__add_entry(hists, &al, NULL, - NULL, NULL, &sample, true); + NULL, NULL, NULL, &sample, true); if (he == NULL) { addr_location__put(&al); goto out; @@ -106,7 +106,7 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine) goto out; he = hists__add_entry(hists, &al, NULL, - NULL, NULL, &sample, true); + NULL, NULL, NULL, &sample, true); if (he == NULL) { addr_location__put(&al); goto out; diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index b6e4b4edde43..3670136a0074 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -4,6 +4,7 @@ #include "dso.h" #include "build-id.h" #include "hist.h" +#include "kvm-stat.h" #include "map.h" #include "map_symbol.h" #include "branch.h" @@ -698,6 +699,7 @@ __hists__add_entry(struct hists *hists, struct symbol *sym_parent, struct branch_info *bi, struct mem_info *mi, + struct kvm_info *ki, struct block_info *block_info, struct perf_sample *sample, bool sample_self, @@ -733,6 +735,7 @@ __hists__add_entry(struct hists *hists, .hists = hists, .branch_info = bi, .mem_info = mi, + .kvm_info = ki, .block_info = block_info, .transaction = sample->transaction, .raw_data = sample->raw_data, @@ -756,10 +759,11 @@ struct hist_entry *hists__add_entry(struct hists *hists, struct symbol *sym_parent, struct branch_info *bi, struct mem_info *mi, + struct kvm_info *ki, struct perf_sample *sample, bool sample_self) { - return __hists__add_entry(hists, al, sym_parent, bi, mi, NULL, + return __hists__add_entry(hists, al, sym_parent, bi, mi, ki, NULL, sample, sample_self, NULL); } @@ -769,10 +773,11 @@ struct hist_entry *hists__add_entry_ops(struct hists *hists, struct symbol *sym_parent, struct branch_info *bi, struct mem_info *mi, + struct kvm_info *ki, struct perf_sample *sample, bool sample_self) { - return __hists__add_entry(hists, al, sym_parent, bi, mi, NULL, + return __hists__add_entry(hists, al, sym_parent, bi, mi, ki, NULL, sample, sample_self, ops); } @@ -846,7 +851,7 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al */ sample->period = cost; - he = hists__add_entry(hists, al, iter->parent, NULL, mi, + he = hists__add_entry(hists, al, iter->parent, NULL, mi, NULL, sample, true); if (!he) return -ENOMEM; @@ -949,7 +954,7 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a sample->period = 1; sample->weight = bi->flags.cycles ? bi->flags.cycles : 1; - he = hists__add_entry(hists, al, iter->parent, &bi[i], NULL, + he = hists__add_entry(hists, al, iter->parent, &bi[i], NULL, NULL, sample, true); if (he == NULL) return -ENOMEM; @@ -987,7 +992,7 @@ iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location struct hist_entry *he; he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, - sample, true); + NULL, sample, true); if (he == NULL) return -ENOMEM; @@ -1047,7 +1052,7 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter, struct hist_entry *he; int err = 0; - he = hists__add_entry(hists, al, iter->parent, NULL, NULL, + he = hists__add_entry(hists, al, iter->parent, NULL, NULL, NULL, sample, true); if (he == NULL) return -ENOMEM; @@ -1148,7 +1153,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, } he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, - sample, false); + NULL, sample, false); if (he == NULL) return -ENOMEM; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index d93a4e510dc7..86a677954279 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -14,6 +14,7 @@ struct hist_entry_ops; struct addr_location; struct map_symbol; struct mem_info; +struct kvm_info; struct branch_info; struct branch_stack; struct block_info; @@ -150,6 +151,7 @@ struct hist_entry *hists__add_entry(struct hists *hists, struct symbol *parent, struct branch_info *bi, struct mem_info *mi, + struct kvm_info *ki, struct perf_sample *sample, bool sample_self); @@ -159,6 +161,7 @@ struct hist_entry *hists__add_entry_ops(struct hists *hists, struct symbol *sym_parent, struct branch_info *bi, struct mem_info *mi, + struct kvm_info *ki, struct perf_sample *sample, bool sample_self); diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 3b2eab91a9be..0cf704333c4c 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -23,6 +23,10 @@ struct event_key { struct exit_reasons_table *exit_reasons; }; +struct kvm_info { + char name[KVM_EVENT_NAME_LEN]; +}; + struct kvm_event_stats { u64 time; struct stats stats; diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index d79a100e5999..22f437c3476f 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -144,6 +144,7 @@ struct hist_entry { struct hists *hists; struct mem_info *mem_info; struct block_info *block_info; + struct kvm_info *kvm_info; void *raw_data; u32 raw_size; int num_res; From patchwork Wed Mar 15 14:51:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13176008 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 D902CC7618B for ; Wed, 15 Mar 2023 14:53:29 +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=r1iHtzLnMJJHHpd9QLeseRoXgI/02g62dXn/DTFWkzU=; b=Q5okABhp9h+5EI drQsofue1g0BkdkdEcg+V8+VGLul6w0r/Plu+Fk+owEE910xhTLUUwkEs2Bkq8VENPiDYhwJAx6E6 WVxQRsg02mj0HjyKIEB4whFiGZficbLuyHFc0uYp3anP1nUceRkEr1GFrCKeAyxp+qAarX18/7j5d OxOjlvPjPySLzvF+AkYYZr+4pzjimFejg1Y+Aeczkgkttqw1fwd2Dc4aa2kFlbmhqrplKPD5AWyVJ rrbYUDgG9JfJyDVHlul7YppWk3/qAVxMtPogJex00akTnKtGOToRy5C3s6hCgzGXBwPxQ6LbdPI1T dY6LqpvCePe6I7F7S96g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUY-00Dff3-1E; Wed, 15 Mar 2023 14:52:38 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUQ-00DfXw-2O for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:33 +0000 Received: by mail-pl1-x62d.google.com with SMTP id p6so20352152plf.0 for ; Wed, 15 Mar 2023 07:52:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891947; 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=WVnvf3zk72qzgXgdIPbzoctQ9SQ7bt/Ml2Z1pGndq/0=; b=h9lHKPyNbnYbq3F6NSGv0JQNKcWgzxoUGZioCn02L8zidZZGjbjzFE2KyTr2FWd4iO W3gUzXZlNcyraP+QiNBGGADuv/Ib/+MvWL77YVrvJgx8zXkTXIzSOt4AcjMsLBYHJua1 RKBQ7HZrX6eHG4zbh3neC2IMvVXzrMuOV/rIg/xJG26nQPeFQfW9OMhRQAXoJdtgRgVa dJ8uWYLp9PzoJ5K7FNBMekCKj5uff/77qY9pv3Nm9TbjD/X5gcwKULbJilcoiY85q/tT pNZX2Dp37+qdq0Rggr0+QoC4crqurSdnN1wARdFMCs8fD8eJLRmnJ7gbEQ7ceVIOcnbj y07A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891947; 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=WVnvf3zk72qzgXgdIPbzoctQ9SQ7bt/Ml2Z1pGndq/0=; b=rGAMZYKdvHpeBfalaXbeHmta+ueh1PYeA1yejioDH6hFHbj6Jxh+aJU5TJ+jRaACbF RqD6TP9OJ289fK5cADquEfIBXaYgdxnYkavDDjZ5XNVAH7puSVQuv5Cm2EiTEKS3egCl BD3mMvm9hc/+y/naORtrGbHMqYjPiC5sJ01phMzon5MfH33u5efkibhNKNER4oCNPSCl bcrT2tUiqj462CHcLpKF3/7Cjo0uAY0U3TPN0EzP9fdkC3f6BfDFIaXFkTYwgJJqlyJI GNY/iGipUlXGKIvTPXwvFORg58S6SkNx9k6Mmy5lPxTiolKaDhf2tnq48bI001nbGbcS VXHQ== X-Gm-Message-State: AO0yUKWW97jbMKKccRVtTO4jK+dUumdN0OfqHSYrjyvCik9ivgV8rVj4 W50muaNkqdGnxv1zoENbXYP7iQ== X-Google-Smtp-Source: AK7set+r3FQC59prCXVymFb4gV98LN3zPEPCcwLVumwG0uMonMH8J/HeeF0K6uziPkWIrIXYO+fYrQ== X-Received: by 2002:a17:902:c70b:b0:19d:abd:bb7e with SMTP id p11-20020a170902c70b00b0019d0abdbb7emr2195040plp.34.1678891947352; Wed, 15 Mar 2023 07:52:27 -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.52.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:27 -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 10/16] perf kvm: Add dimensions for KVM event statistics Date: Wed, 15 Mar 2023 22:51:06 +0800 Message-Id: <20230315145112.186603-11-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_075230_817339_E98091CA X-CRM114-Status: GOOD ( 21.33 ) 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 To support KVM event statistics, this patch firstly registers histograms columns and sorting fields; every column or field has its own format structure, the format structure is dereferenced to access the dimension, finally the dimension provides the comparison callback for sorting result. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 232 ++++++++++++++++++++++++++++++++++++- tools/perf/util/kvm-stat.h | 2 + 2 files changed, 230 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index fa91c8deb628..3f601ccb7aab 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -70,9 +70,9 @@ static int64_t cmp_event_ ## func(struct kvm_event *one, \ get_event_ ##func(two, vcpu); \ } -GET_EVENT_KEY(time, time); -GET_EVENT_KEY(max, stats.max); -GET_EVENT_KEY(min, stats.min); +COMPARE_EVENT_KEY(time, time); +COMPARE_EVENT_KEY(max, stats.max); +COMPARE_EVENT_KEY(min, stats.min); COMPARE_EVENT_KEY(count, stats.n); COMPARE_EVENT_KEY(mean, stats.mean); @@ -90,13 +90,237 @@ struct kvm_hists { struct perf_hpp_list list; }; +struct kvm_dimension { + const char *name; + int64_t (*cmp)(struct perf_hpp_fmt *fmt, struct hist_entry *left, + struct hist_entry *right); +}; + +struct kvm_fmt { + struct perf_hpp_fmt fmt; + struct kvm_dimension *dim; +}; + static struct kvm_hists kvm_hists; +static int64_t ev_name_cmp(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left, + struct hist_entry *right) +{ + /* Return opposite number for sorting in alphabetical order */ + return -strcmp(left->kvm_info->name, right->kvm_info->name); +} + +static struct kvm_dimension dim_event = { + .name = "ev_name", + .cmp = ev_name_cmp, +}; + +#define EV_METRIC_CMP(metric) \ +static int64_t ev_cmp_##metric(struct perf_hpp_fmt *fmt __maybe_unused, \ + struct hist_entry *left, \ + struct hist_entry *right) \ +{ \ + struct kvm_event *event_left; \ + struct kvm_event *event_right; \ + struct perf_kvm_stat *perf_kvm; \ + \ + event_left = container_of(left, struct kvm_event, he); \ + event_right = container_of(right, struct kvm_event, he); \ + \ + perf_kvm = event_left->perf_kvm; \ + return cmp_event_##metric(event_left, event_right, \ + perf_kvm->trace_vcpu); \ +} + +EV_METRIC_CMP(time) +EV_METRIC_CMP(count) +EV_METRIC_CMP(max) +EV_METRIC_CMP(min) +EV_METRIC_CMP(mean) + +static struct kvm_dimension dim_time = { + .name = "time", + .cmp = ev_cmp_time, +}; + +static struct kvm_dimension dim_count = { + .name = "sample", + .cmp = ev_cmp_count, +}; + +static struct kvm_dimension dim_max_time = { + .name = "max_t", + .cmp = ev_cmp_max, +}; + +static struct kvm_dimension dim_min_time = { + .name = "min_t", + .cmp = ev_cmp_min, +}; + +static struct kvm_dimension dim_mean_time = { + .name = "mean_t", + .cmp = ev_cmp_mean, +}; + +static struct kvm_dimension *dimensions[] = { + &dim_event, + &dim_time, + &dim_count, + &dim_max_time, + &dim_min_time, + &dim_mean_time, + NULL, +}; + +static bool fmt_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b) +{ + struct kvm_fmt *kvm_fmt_a = container_of(a, struct kvm_fmt, fmt); + struct kvm_fmt *kvm_fmt_b = container_of(b, struct kvm_fmt, fmt); + + return kvm_fmt_a->dim == kvm_fmt_b->dim; +} + +static void fmt_free(struct perf_hpp_fmt *fmt) +{ + struct kvm_fmt *kvm_fmt; + + kvm_fmt = container_of(fmt, struct kvm_fmt, fmt); + free(kvm_fmt); +} + +static struct kvm_dimension *get_dimension(const char *name) +{ + unsigned int i; + + for (i = 0; dimensions[i] != NULL; i++) { + if (!strcmp(dimensions[i]->name, name)) + return dimensions[i]; + } + + return NULL; +} + +static struct kvm_fmt *get_format(const char *name) +{ + struct kvm_dimension *dim = get_dimension(name); + struct kvm_fmt *kvm_fmt; + struct perf_hpp_fmt *fmt; + + if (!dim) + return NULL; + + kvm_fmt = zalloc(sizeof(*kvm_fmt)); + if (!kvm_fmt) + return NULL; + + kvm_fmt->dim = dim; + + fmt = &kvm_fmt->fmt; + INIT_LIST_HEAD(&fmt->list); + INIT_LIST_HEAD(&fmt->sort_list); + fmt->cmp = dim->cmp; + fmt->sort = dim->cmp; + fmt->color = NULL; + fmt->entry = NULL; + fmt->header = NULL; + fmt->width = NULL; + fmt->collapse = dim->cmp; + fmt->equal = fmt_equal; + fmt->free = fmt_free; + + return kvm_fmt; +} + +static int kvm_hists__init_output(struct perf_hpp_list *hpp_list, char *name) +{ + struct kvm_fmt *kvm_fmt = get_format(name); + + if (!kvm_fmt) { + pr_warning("Fail to find format for output field %s.\n", name); + return -EINVAL; + } + + perf_hpp_list__column_register(hpp_list, &kvm_fmt->fmt); + return 0; +} + +static int kvm_hists__init_sort(struct perf_hpp_list *hpp_list, char *name) +{ + struct kvm_fmt *kvm_fmt = get_format(name); + + if (!kvm_fmt) { + pr_warning("Fail to find format for sorting %s.\n", name); + return -EINVAL; + } + + perf_hpp_list__register_sort_field(hpp_list, &kvm_fmt->fmt); + return 0; +} + +static int kvm_hpp_list__init(char *list, + struct perf_hpp_list *hpp_list, + int (*fn)(struct perf_hpp_list *hpp_list, + char *name)) +{ + char *tmp, *tok; + int ret; + + if (!list || !fn) + return 0; + + for (tok = strtok_r(list, ", ", &tmp); tok; + tok = strtok_r(NULL, ", ", &tmp)) { + ret = fn(hpp_list, tok); + if (!ret) + continue; + + /* Handle errors */ + if (ret == -EINVAL) + pr_err("Invalid field key: '%s'", tok); + else if (ret == -ESRCH) + pr_err("Unknown field key: '%s'", tok); + else + pr_err("Fail to initialize for field key: '%s'", tok); + + break; + } + + return ret; +} + +static int kvm_hpp_list__parse(struct perf_hpp_list *hpp_list, + const char *output_, const char *sort_) +{ + char *output = output_ ? strdup(output_) : NULL; + char *sort = sort_ ? strdup(sort_) : NULL; + int ret; + + ret = kvm_hpp_list__init(output, hpp_list, kvm_hists__init_output); + if (ret) + goto out; + + ret = kvm_hpp_list__init(sort, hpp_list, kvm_hists__init_sort); + if (ret) + goto out; + + /* Copy sort keys to output fields */ + perf_hpp__setup_output_field(hpp_list); + + /* and then copy output fields to sort keys */ + perf_hpp__append_sort_keys(hpp_list); +out: + free(output); + free(sort); + return ret; +} + static int kvm_hists__init(void) { __hists__init(&kvm_hists.hists, &kvm_hists.list); perf_hpp_list__init(&kvm_hists.list); - return 0; + return kvm_hpp_list__parse(&kvm_hists.list, NULL, "ev_name"); } static const char *get_filename_for_perf_kvm(void) diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 0cf704333c4c..fc30a72dfac1 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -46,6 +46,8 @@ struct kvm_event { #define DEFAULT_VCPU_NUM 8 int max_vcpu; struct kvm_event_stats *vcpu; + + struct hist_entry he; }; typedef int64_t (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); From patchwork Wed Mar 15 14:51:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13176009 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 E8C6DC7618D for ; Wed, 15 Mar 2023 14:53:42 +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=Je1z9GjHGDnrbMdMNDSWjr1oA8P+gcWNsrIXMGQvre0=; b=DwmTIRMRd8Osit iu167Uxs/1k1HhA1XQ13CsOClT/Z8tSDmAtTWWaAQ1pr9a3JWLzYbIW3DSPMDt47ehzHcw+bhykTc +d2phBTwIH4WW2YMHXpRlcZyJEnXBdhNmYBcTfc3VZ+Ai/VazfSTc18WAgB5cHo69L7O6Wz8fijV2 mxcwQiTerzQEN20dI5u9Njcsw9kouAM4jF3g6WgXA0KfliG6wQZngb9hSfMEDurWpE5g4RBddxHYy UffiigGJ6bf5BNgWY5cDbSU6sw4/ccp/Hnc9mcmAv4vbxmvUWvv0IuojYjfPaXGX1KaATBMaLbUAg wouy/OfhIZDBV8onarmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUf-00DfkL-2c; Wed, 15 Mar 2023 14:52:45 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUW-00Dfbh-1V for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:38 +0000 Received: by mail-pj1-x1034.google.com with SMTP id l9-20020a17090a3f0900b0023d32684e7fso3601726pjc.1 for ; Wed, 15 Mar 2023 07:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891953; 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=VpX5eG5BICdwUiyxxIOGXbe9ltJnRnUa5/qhb/BObdw=; b=IhD7gDtNXKpVqae6GrAVGJREdsRwLhQsCsDulpzLIHFujBKus4mwz/k7gzrvWaBg6t 3RL6+nTh1GLVE6A2rK/wCg2omf4nbnbsD0ctSsaN4KQcxbI12FlDnPuKfhxi5D23MnWV girZAy8wsHPYv5HtGqa0660B/9C7tWbeJ5QU6dlBDcKdlKzo1IcZdoAYsDnSMB2Ah1Sc 4KKtdkHcNlEhKfJgS8BhRMwt8evU0PG5PfiYnBlcqxrbhhmS7oKvOuumOko6m6CPTQgv j4XRD94+3vTLrgb70Pa837uPY3ZY8uaMdJlGFNh7e4SLeS+beSOV+koYUx5fTinTfwDo TC3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891953; 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=VpX5eG5BICdwUiyxxIOGXbe9ltJnRnUa5/qhb/BObdw=; b=Cgx5XtaAjFHhCig9EoFGLJBv6nqC33PTlkMxipamIX3qx3kjB/kYNK4SvayzO9yb+I oFl26TjCr5cSl4aE1sObfn0N6lQqneKD1YjSDxEsLTOaxpqvBDWGDf8eUvy5f5Alj42M STSvsSFodRJF/JYE4zw2rZ6uHMDkrhjonybK+veJB073sxo9eqdtHG0UwrNIaHOKzPcq 0wht8gpYMM+rjVget9mkfJ5pEKCJCH5BBm1WZXewjuxoQnIiV8t9yBXPDkfAjFsWkECa 9lnZj1FAY5r50/S8G07+O9EYiYacossRq8lqUp13tCP6x+acxFXKty7FBwNMuJ+3CFd+ ak7Q== X-Gm-Message-State: AO0yUKVM7aWUwSa0JuYQBybA7TiuZ25VBphqBBhMokQCs9WXQbsWP6MI k2+AVjxJZshyaadUNdeiHPNBmw== X-Google-Smtp-Source: AK7set988SHmFCSkIwmVtr0pBg1nX7tBBXroJ6DfZCJ0oeOUVVX0GAEi1459Qr46+KRJVUaE+ctlWg== X-Received: by 2002:a17:903:886:b0:1a0:4526:3535 with SMTP id kt6-20020a170903088600b001a045263535mr2789903plb.57.1678891953208; Wed, 15 Mar 2023 07:52:33 -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.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:32 -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 11/16] perf kvm: Use histograms list to replace cached list Date: Wed, 15 Mar 2023 22:51:07 +0800 Message-Id: <20230315145112.186603-12-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_075236_512745_206048FE X-CRM114-Status: GOOD ( 25.99 ) 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 perf kvm tool defines its own cached list which is managed with RB tree, histograms also provide RB tree to manage data entries. Since now we have introduced histograms in the tool, it's not necessary to use the self defined list and we can directly use histograms list to manage KVM events. This patch changes to use histograms list to track KVM events, and it invokes the common function hists__output_resort_cb() to sort result, this also give us flexibility to extend more sorting key words easily. After histograms list supported, the cached list is redundant so remove the relevant code for it. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 189 +++++++++++++++++++------------------ tools/perf/util/kvm-stat.h | 7 -- 2 files changed, 95 insertions(+), 101 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 3f601ccb7aab..ba3134613bcb 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -323,6 +323,12 @@ static int kvm_hists__init(void) return kvm_hpp_list__parse(&kvm_hists.list, NULL, "ev_name"); } +static int kvm_hists__reinit(const char *output, const char *sort) +{ + perf_hpp__reset_output_field(&kvm_hists.list); + return kvm_hpp_list__parse(&kvm_hists.list, output, sort); +} + static const char *get_filename_for_perf_kvm(void) { const char *filename; @@ -420,44 +426,37 @@ struct vcpu_event_record { struct kvm_event *last_event; }; - -static void init_kvm_event_record(struct perf_kvm_stat *kvm) -{ - unsigned int i; - - for (i = 0; i < EVENTS_CACHE_SIZE; i++) - INIT_LIST_HEAD(&kvm->kvm_events_cache[i]); -} - #ifdef HAVE_TIMERFD_SUPPORT -static void clear_events_cache_stats(struct list_head *kvm_events_cache) +static void clear_events_cache_stats(void) { - struct list_head *head; + struct rb_root_cached *root; + struct rb_node *nd; struct kvm_event *event; - unsigned int i; - int j; - - for (i = 0; i < EVENTS_CACHE_SIZE; i++) { - head = &kvm_events_cache[i]; - list_for_each_entry(event, head, hash_entry) { - /* reset stats for event */ - event->total.time = 0; - init_stats(&event->total.stats); - - for (j = 0; j < event->max_vcpu; ++j) { - event->vcpu[j].time = 0; - init_stats(&event->vcpu[j].stats); - } + int i; + + if (hists__has(&kvm_hists.hists, need_collapse)) + root = &kvm_hists.hists.entries_collapsed; + else + root = kvm_hists.hists.entries_in; + + for (nd = rb_first_cached(root); nd; nd = rb_next(nd)) { + struct hist_entry *he; + + he = rb_entry(nd, struct hist_entry, rb_node_in); + event = container_of(he, struct kvm_event, he); + + /* reset stats for event */ + event->total.time = 0; + init_stats(&event->total.stats); + + for (i = 0; i < event->max_vcpu; ++i) { + event->vcpu[i].time = 0; + init_stats(&event->vcpu[i].stats); } } } #endif -static int kvm_events_hash_fn(u64 key) -{ - return key & (EVENTS_CACHE_SIZE - 1); -} - static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) { int old_max_vcpu = event->max_vcpu; @@ -483,44 +482,64 @@ static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) return true; } -static struct kvm_event *kvm_alloc_init_event(struct perf_kvm_stat *kvm, - struct event_key *key, - struct perf_sample *sample __maybe_unused) +static void *kvm_he_zalloc(size_t size) { - struct kvm_event *event; + struct kvm_event *kvm_ev; - event = zalloc(sizeof(*event)); - if (!event) { - pr_err("Not enough memory\n"); + kvm_ev = zalloc(size + sizeof(*kvm_ev)); + if (!kvm_ev) return NULL; - } - event->perf_kvm = kvm; - event->key = *key; - init_stats(&event->total.stats); - return event; + init_stats(&kvm_ev->total.stats); + hists__inc_nr_samples(&kvm_hists.hists, 0); + return &kvm_ev->he; +} + +static void kvm_he_free(void *he) +{ + struct kvm_event *kvm_ev; + + free(((struct hist_entry *)he)->kvm_info); + kvm_ev = container_of(he, struct kvm_event, he); + free(kvm_ev); } +static struct hist_entry_ops kvm_ev_entry_ops = { + .new = kvm_he_zalloc, + .free = kvm_he_free, +}; + static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, struct event_key *key, struct perf_sample *sample) { struct kvm_event *event; - struct list_head *head; + struct hist_entry *he; + struct kvm_info *ki; BUG_ON(key->key == INVALID_KEY); - head = &kvm->kvm_events_cache[kvm_events_hash_fn(key->key)]; - list_for_each_entry(event, head, hash_entry) { - if (event->key.key == key->key && event->key.info == key->info) - return event; + ki = zalloc(sizeof(*ki)); + if (!ki) { + pr_err("Failed to allocate kvm info\n"); + return NULL; } - event = kvm_alloc_init_event(kvm, key, sample); - if (!event) + kvm->events_ops->decode_key(kvm, key, ki->name); + he = hists__add_entry_ops(&kvm_hists.hists, &kvm_ev_entry_ops, + &kvm->al, NULL, NULL, NULL, ki, sample, true); + if (he == NULL) { + pr_err("Failed to allocate hist entry\n"); + free(ki); return NULL; + } + + event = container_of(he, struct kvm_event, he); + if (!event->perf_kvm) { + event->perf_kvm = kvm; + event->key = *key; + } - list_add(&event->hash_entry, head); return event; } @@ -753,58 +772,32 @@ static bool select_key(struct perf_kvm_stat *kvm) return false; } -static void insert_to_result(struct rb_root *result, struct kvm_event *event, - key_cmp_fun bigger, int vcpu) -{ - struct rb_node **rb = &result->rb_node; - struct rb_node *parent = NULL; - struct kvm_event *p; - - while (*rb) { - p = container_of(*rb, struct kvm_event, rb); - parent = *rb; - - if (bigger(event, p, vcpu) > 0) - rb = &(*rb)->rb_left; - else - rb = &(*rb)->rb_right; - } - - rb_link_node(&event->rb, parent, rb); - rb_insert_color(&event->rb, result); -} - static bool event_is_valid(struct kvm_event *event, int vcpu) { return !!get_event_count(event, vcpu); } -static void sort_result(struct perf_kvm_stat *kvm) +static int filter_cb(struct hist_entry *he, void *arg __maybe_unused) { - unsigned int i; - int vcpu = kvm->trace_vcpu; struct kvm_event *event; + struct perf_kvm_stat *perf_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)) { - insert_to_result(&kvm->result, event, - kvm->compare, vcpu); - } - } - } + event = container_of(he, struct kvm_event, he); + perf_kvm = event->perf_kvm; + if (!event_is_valid(event, perf_kvm->trace_vcpu)) + he->filtered = 1; + else + he->filtered = 0; + return 0; } -/* returns left most element of result, and erase it */ -static struct kvm_event *pop_from_result(struct rb_root *result) +static void sort_result(struct perf_kvm_stat *kvm) { - struct rb_node *node = rb_first(result); - - if (!node) - return NULL; + const char *output_columns = "ev_name,sample,time,max_t,min_t,mean_t"; - rb_erase(node, result); - return container_of(node, struct kvm_event, rb); + kvm_hists__reinit(output_columns, kvm->sort_key); + hists__collapse_resort(&kvm_hists.hists, NULL); + hists__output_resort_cb(&kvm_hists.hists, NULL, filter_cb); } static void print_vcpu_info(struct perf_kvm_stat *kvm) @@ -847,6 +840,7 @@ static void print_result(struct perf_kvm_stat *kvm) char decode[KVM_EVENT_NAME_LEN]; struct kvm_event *event; int vcpu = kvm->trace_vcpu; + struct rb_node *nd; if (kvm->live) { puts(CONSOLE_CLEAR); @@ -865,9 +859,15 @@ static void print_result(struct perf_kvm_stat *kvm) pr_info("%16s ", "Avg time"); pr_info("\n\n"); - while ((event = pop_from_result(&kvm->result))) { + for (nd = rb_first_cached(&kvm_hists.hists.entries); nd; nd = rb_next(nd)) { + struct hist_entry *he; u64 ecount, etime, max, min; + he = rb_entry(nd, struct hist_entry, rb_node); + if (he->filtered) + continue; + + event = container_of(he, struct kvm_event, he); ecount = get_event_count(event, vcpu); etime = get_event_time(event, vcpu); max = get_event_max(event, vcpu); @@ -1144,8 +1144,11 @@ static int perf_kvm__handle_timerfd(struct perf_kvm_stat *kvm) sort_result(kvm); print_result(kvm); + /* Reset sort list to "ev_name" */ + kvm_hists__reinit(NULL, "ev_name"); + /* reset counts */ - clear_events_cache_stats(kvm->kvm_events_cache); + clear_events_cache_stats(); kvm->total_count = 0; kvm->total_time = 0; kvm->lost_events = 0; @@ -1201,7 +1204,6 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm) } set_term_quiet_input(&save); - init_kvm_event_record(kvm); kvm_hists__init(); @@ -1397,7 +1399,6 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) if (!register_kvm_events_ops(kvm)) goto exit; - init_kvm_event_record(kvm); setup_pager(); kvm_hists__init(); diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index fc30a72dfac1..3f0cbecb862c 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -36,7 +36,6 @@ struct perf_kvm_stat; struct kvm_event { struct list_head hash_entry; - struct rb_node rb; struct perf_kvm_stat *perf_kvm; struct event_key key; @@ -81,9 +80,6 @@ struct exit_reasons_table { const char *reason; }; -#define EVENTS_BITS 12 -#define EVENTS_CACHE_SIZE (1UL << EVENTS_BITS) - struct perf_kvm_stat { struct perf_tool tool; struct record_opts opts; @@ -103,7 +99,6 @@ struct perf_kvm_stat { struct kvm_events_ops *events_ops; key_cmp_fun compare; - struct list_head kvm_events_cache[EVENTS_CACHE_SIZE]; u64 total_time; u64 total_count; @@ -112,8 +107,6 @@ struct perf_kvm_stat { struct intlist *pid_list; - struct rb_root result; - int timerfd; unsigned int display_time; bool live; From patchwork Wed Mar 15 14:51:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13176011 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 C1129C61DA4 for ; Wed, 15 Mar 2023 14:53:55 +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=FwaTcp3EsnYcNyH/mioeizBhVjaChY/9u2Drjc6PO4o=; b=zkar+bfFxZ/IVc 3D+xyHZFbKhFyWkZfPwPQ2h/LgFa8T0EeuFmbMqG87b1VUsYRBbI3fHVw1vG+/QwABIH8Qw4Kl4kA WwXDblkHgpECiYVDlJRqhSjFYyNgHrtnHTGON6r6XgJBrfrc1ZMVHHtZoATXxSx2N3UTXb4sANyRE EvcwrqK/+jM8g6bhm7oIS9ey8MXiiGBlFEitEa69mFn5ZDezuOeZa4r/FIuW1D50JVuITz60MOk53 8dkzt23xWKqHg0S19Mg3JFJEYUppxqIj7Jl7/4rp7iSrGsShXgQhlZAfapiqJ9C4AKmVMPzgwyX2E NFZf0zbsOgP3m+Qn+4FA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUp-00DfsG-1t; Wed, 15 Mar 2023 14:52:55 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUi-00DfmP-2r for linux-arm-kernel@bombadil.infradead.org; Wed, 15 Mar 2023 14:52:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=GXjE1lNyQ6Ulq2wrJYSF6aHLvPPQtJdwrD75rVojf8A=; b=kswYYHYiGvWeIu3RtEJDmrZWZw GN6oHMFJUOIZUOs4/wWAiCbyznwbuA8NP70rI6Du3L8bPGTMFFdswWjX90JG+zm2UrSBAUZ0Xvs4e NMXfCqNnTYQLhZWS+XRxamm3GqE5NGkDfeW+OkM69xeh9IjDly/Tw8S7rKeyyUdnTL636W1BK47EG b1j4KFtCtKTv7J5CmaLqGaDRVaSk1JJElUmcMUvwIoO661nZkoSnDqVvN+gKc8lTM3IIFbrbbkfwl MpM7oS0BUXEXOM/UuAPLCY5yNBz25CbokpfJU97Rb3X9tpFxB0EML7rlET3M1LiGl+hJ/lWDp1MVz W8DRKcnQ==; Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUd-00289g-0X for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:45 +0000 Received: by mail-pl1-x62f.google.com with SMTP id p20so20268316plw.13 for ; Wed, 15 Mar 2023 07:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891959; 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=GXjE1lNyQ6Ulq2wrJYSF6aHLvPPQtJdwrD75rVojf8A=; b=BCoP6UXH2x8VV6ZsOW13Ae9hQ4T2I9/6OiiOOf26BOC3ZUWn3FhlVxYrwF0uGT2820 Z89j0GTbYPZbd2m0FTGAmQ3aeVDmEJtZzF1e/zHOZHQEwvVoNGq/xuYbvVwuqdT9d1ZE SMzXSpKbDY/rFapSOecLZBq8+zwdrzi6TujVS4OhT+wrSE/zUcm1EjBldfw1Mq+JajgA BwHIdRwEWuAS/5nOs4hcd4JPjVlkula1o2YjLf8HFYGm+SX7NX03Ph2xIXtoPM/cMhIv H8Lrwb4ru/Wj3svRHVKnevbHu7BtAfzHGDj+o4Dms7Ia98uaFLE1ZLCxRbiXzLeDdOr0 sfeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891959; 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=GXjE1lNyQ6Ulq2wrJYSF6aHLvPPQtJdwrD75rVojf8A=; b=QPW8ZXtq17MC369h+H2jauZTBNuRK0aA9uIHLdEbvc5qYKnIEmDIONgwfxiaTio1sD 2Tl4SL3sVH0Hd1/gdK5T2OwTvdX2DlU+MMeDGGIcqY3mNDoyhl2ENhxSRvZcGeWqlkLH wJGWy/kXtkyi5CS5ZHmvsmysYY9HmNYrUJuzDY4Yyi+tby2UYbDm+I/vh0iANLvH6IY7 oGdblKu2fp6s6MJYEmzmRJb2ST7XPVycRbwW0IUCFhyseB35AE+nCBtPGbd5rIstqRzP n0DqO03SWI0awiwgBHJPwCRT4LtCVd8idrVUPYIx4mCCbcIWMxj9UKT12pJTli8/dsnT Unxw== X-Gm-Message-State: AO0yUKXYZLgNvYAMppz9a4IgFcdK+Ji0BE8GwVMIzlODXk3bqU1EUN3s Z3qtSOUeXFWGj2W9u353r6AxCw== X-Google-Smtp-Source: AK7set/x2sbhiI0KJMwBONL5ZF5YA0yPzV1seKM6HmyYEhYd4ut50lJhZLlgYJcc5Kcg6TFT3KxMtg== X-Received: by 2002:a17:902:f54e:b0:1a0:76d1:545c with SMTP id h14-20020a170902f54e00b001a076d1545cmr2950647plf.10.1678891958787; Wed, 15 Mar 2023 07:52:38 -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.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:38 -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 12/16] perf kvm: Polish sorting key Date: Wed, 15 Mar 2023 22:51:08 +0800 Message-Id: <20230315145112.186603-13-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_145243_543316_4B74DCDA X-CRM114-Status: GOOD ( 17.34 ) 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 Since histograms supports sorting, the tool doesn't need to maintain the mapping between the sorting keys and the corresponding comparison callbacks, therefore, this patch removes structure kvm_event_key. But we still need to validate the sorting key, this patch uses an array for sorting keys and renames function select_key() to is_valid_key() to validate the sorting key passed by user. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 29 ++++++++++------------------- tools/perf/util/kvm-stat.h | 8 -------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index ba3134613bcb..1e9338855239 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -76,15 +76,6 @@ COMPARE_EVENT_KEY(min, stats.min); COMPARE_EVENT_KEY(count, stats.n); COMPARE_EVENT_KEY(mean, stats.mean); -#define DEF_SORT_NAME_KEY(name, compare_key) \ - { #name, cmp_event_ ## compare_key } - -static struct kvm_event_key keys[] = { - DEF_SORT_NAME_KEY(sample, count), - DEF_SORT_NAME_KEY(time, mean), - { NULL, NULL } -}; - struct kvm_hists { struct hists hists; struct perf_hpp_list list; @@ -757,18 +748,18 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, return true; } -static bool select_key(struct perf_kvm_stat *kvm) +static bool is_valid_key(struct perf_kvm_stat *kvm) { - int i; + static const char *key_array[] = { + "ev_name", "sample", "time", "max_t", "min_t", "mean_t", + }; + unsigned int i; - for (i = 0; keys[i].name; i++) { - if (!strcmp(keys[i].name, kvm->sort_key)) { - kvm->compare = keys[i].key; + for (i = 0; i < ARRAY_SIZE(key_array); i++) + if (!strcmp(key_array[i], kvm->sort_key)) return true; - } - } - pr_err("Unknown compare key:%s\n", kvm->sort_key); + pr_err("Unsupported sort key: %s\n", kvm->sort_key); return false; } @@ -1198,7 +1189,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm) return ret; if (!verify_vcpu(kvm->trace_vcpu) || - !select_key(kvm) || + !is_valid_key(kvm) || !register_kvm_events_ops(kvm)) { goto out; } @@ -1393,7 +1384,7 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) if (!verify_vcpu(vcpu)) goto exit; - if (!select_key(kvm)) + if (!is_valid_key(kvm)) goto exit; if (!register_kvm_events_ops(kvm)) diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 3f0cbecb862c..35d03894fac3 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -49,13 +49,6 @@ struct kvm_event { struct hist_entry he; }; -typedef int64_t (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); - -struct kvm_event_key { - const char *name; - key_cmp_fun key; -}; - struct child_event_ops { void (*get_key)(struct evsel *evsel, struct perf_sample *sample, @@ -98,7 +91,6 @@ struct perf_kvm_stat { const char *exit_reasons_isa; struct kvm_events_ops *events_ops; - key_cmp_fun compare; u64 total_time; u64 total_count; From patchwork Wed Mar 15 14:51:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13176010 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 D416EC6FD1D for ; Wed, 15 Mar 2023 14:53:47 +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=psi9b+vMSSuDkbyORzUH7GBL2ctH0YKL1ZO07vR5Vqo=; b=dt/S9aGVE/hiqZ uobsgmysaMyWoTueGXBNKNIka8G3Mf7A9KayPNWVJ6hee2RajlUYbjE7XEuhHITmsSvkokA73Hm0s zqIwhCX8iP4mVewoiGEW138dHZnosB1stXqZy05mIOOqnXwDd7C6Oz8d4OfBc7vhbsZWi/dHaPnb/ KDw7YgX/zsRubSwPttyA7uhLjG7nAfsNxKU7lAs+v3tC1VD/cVrT+DXDWHVdwP/rKXiuHYpwq3Wsp i5FPBVljeODF8fIU5o4yZH4Ml2haHJEhjZpnFOlAWo1VbZdtxWHdYhQcDmOTALMQraXTiymq7mwp+ RYwxPvh950EJwnoSesrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUm-00DfqA-2I; Wed, 15 Mar 2023 14:52:52 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUe-00Dfbh-2w for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:46 +0000 Received: by mail-pj1-x1034.google.com with SMTP id l9-20020a17090a3f0900b0023d32684e7fso3602042pjc.1 for ; Wed, 15 Mar 2023 07:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891964; 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=lYZdsrHdzQhNgPnVDhJiRxXzSTwxol5Us4hF+GT6h6U=; b=Z/6R9liCK/YrFp9eYW9AUu6LjcM4VNWD0T+ur1ctZrYkL/CCX04ldFgRVAvsmKANMa MsBCR2iX9Z9KTNnc6Y2u4ilNwAy2qDvMnXvp1nHxGR+xafim2knMSamta8dG6pc5Tm1x PU0Bm8kEjchwO1RrLqoRcLJ3yf94PdOKIJNgS70HHS0x3bbwMhDCfo/ZIMwRc/xDUa1+ sSnTN4Y1WRhhMXf+4BwbtzgcBtfCG8YnXP8KAVnY8FbyteeKVJbFjUox/ebgs61Y1/bm oJj9Rg8UBr6GO30Zr/Cf0vnBkp3n5OrZ/cFwHWbPkpJdQbSMxkTN5I24WSpjmq5DkTcR DW4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891964; 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=lYZdsrHdzQhNgPnVDhJiRxXzSTwxol5Us4hF+GT6h6U=; b=Qv5MEJMDaz5IAxyEBnqgnu4XRm7Jaxz9NJa446GEEZunYLKLR2ft02ISXOvm6uc9sY 30Co+pl4J+sppiiFFrzA+trqhqy6AbehZS2pzX23bbqURRsW+kdtKCQKis0Wk2JzNNk5 Kho7Ll3oEbLFcIYqUMP7ZQLF1AOq8C2jne1zL+wlA2GY49ufE885uhfXrzmm41FPbNAO OOwpoj2rgpkdOujKJoPHfF2xuXVRNQlqPr4Gzc1S1Hna7DPM2Ymi48tCYFuYQfbQkbRa szOp0GrN3U9NshhNBYxkhS68+xJy/O0yGRc3wW5sOsoORYItUskssc1M58FSsWVMcj+4 VLBw== X-Gm-Message-State: AO0yUKXBUrBHeN4kBUoW+6KmwK+Sby8frHx5b35wcNy4yahHcbXuUxcQ +OguG4brVAWuSLI4aHSKqfuvEg== X-Google-Smtp-Source: AK7set9WYvSWjIWJgp0gOzWd6Dr90KziquqYDNhjoLU7G8Dq0TcdXxYH33jyfL2gx99UjaaeADGPiQ== X-Received: by 2002:a17:902:cecd:b0:19e:9f97:f427 with SMTP id d13-20020a170902cecd00b0019e9f97f427mr3556306plg.10.1678891964438; Wed, 15 Mar 2023 07:52:44 -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.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:44 -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 13/16] perf kvm: Support printing attributions for dimensions Date: Wed, 15 Mar 2023 22:51:09 +0800 Message-Id: <20230315145112.186603-14-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_075244_965511_1B71E005 X-CRM114-Status: GOOD ( 14.77 ) 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 This patch adds header, entry callback and width for every dimension, thus in TUI mode the tool can print items with the defined attributions. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 97 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 1e9338855239..0d857df826cf 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -83,8 +83,12 @@ struct kvm_hists { struct kvm_dimension { const char *name; + const char *header; + int width; int64_t (*cmp)(struct perf_hpp_fmt *fmt, struct hist_entry *left, struct hist_entry *right); + int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hist_entry *he); }; struct kvm_fmt { @@ -102,9 +106,24 @@ static int64_t ev_name_cmp(struct perf_hpp_fmt *fmt __maybe_unused, return -strcmp(left->kvm_info->name, right->kvm_info->name); } +static int fmt_width(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp __maybe_unused, + struct hists *hists __maybe_unused); + +static int ev_name_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width = fmt_width(fmt, hpp, he->hists); + + return scnprintf(hpp->buf, hpp->size, "%*s", width, he->kvm_info->name); +} + static struct kvm_dimension dim_event = { + .header = "Event name", .name = "ev_name", .cmp = ev_name_cmp, + .entry = ev_name_entry, + .width = 40, }; #define EV_METRIC_CMP(metric) \ @@ -130,29 +149,77 @@ EV_METRIC_CMP(max) EV_METRIC_CMP(min) EV_METRIC_CMP(mean) +#define EV_METRIC_ENTRY(metric) \ +static int ev_entry_##metric(struct perf_hpp_fmt *fmt, \ + struct perf_hpp *hpp, \ + struct hist_entry *he) \ +{ \ + struct kvm_event *event; \ + int width = fmt_width(fmt, hpp, he->hists); \ + struct perf_kvm_stat *perf_kvm; \ + \ + event = container_of(he, struct kvm_event, he); \ + perf_kvm = event->perf_kvm; \ + return scnprintf(hpp->buf, hpp->size, "%*lu", width, \ + get_event_##metric(event, perf_kvm->trace_vcpu)); \ +} + +EV_METRIC_ENTRY(time) +EV_METRIC_ENTRY(count) +EV_METRIC_ENTRY(max) +EV_METRIC_ENTRY(min) + static struct kvm_dimension dim_time = { + .header = "Time (ns)", .name = "time", .cmp = ev_cmp_time, + .entry = ev_entry_time, + .width = 12, }; static struct kvm_dimension dim_count = { + .header = "Samples", .name = "sample", .cmp = ev_cmp_count, + .entry = ev_entry_count, + .width = 12, }; static struct kvm_dimension dim_max_time = { + .header = "Max Time (ns)", .name = "max_t", .cmp = ev_cmp_max, + .entry = ev_entry_max, + .width = 14, }; static struct kvm_dimension dim_min_time = { + .header = "Min Time (ns)", .name = "min_t", .cmp = ev_cmp_min, + .entry = ev_entry_min, + .width = 14, }; +static int ev_entry_mean(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hist_entry *he) +{ + struct kvm_event *event; + int width = fmt_width(fmt, hpp, he->hists); + struct perf_kvm_stat *perf_kvm; + + event = container_of(he, struct kvm_event, he); + perf_kvm = event->perf_kvm; + return scnprintf(hpp->buf, hpp->size, "%*lu", width, + get_event_mean(event, perf_kvm->trace_vcpu)); +} + static struct kvm_dimension dim_mean_time = { + .header = "Mean Time (ns)", .name = "mean_t", .cmp = ev_cmp_mean, + .entry = ev_entry_mean, + .width = 14, }; static struct kvm_dimension *dimensions[] = { @@ -165,6 +232,30 @@ static struct kvm_dimension *dimensions[] = { NULL, }; +static int fmt_width(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp __maybe_unused, + struct hists *hists __maybe_unused) +{ + struct kvm_fmt *kvm_fmt; + + kvm_fmt = container_of(fmt, struct kvm_fmt, fmt); + return kvm_fmt->dim->width; +} + +static int fmt_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hists *hists, int line __maybe_unused, + int *span __maybe_unused) +{ + struct kvm_fmt *kvm_fmt; + struct kvm_dimension *dim; + int width = fmt_width(fmt, hpp, hists); + + kvm_fmt = container_of(fmt, struct kvm_fmt, fmt); + dim = kvm_fmt->dim; + + return scnprintf(hpp->buf, hpp->size, "%*s", width, dim->header); +} + static bool fmt_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b) { struct kvm_fmt *kvm_fmt_a = container_of(a, struct kvm_fmt, fmt); @@ -214,9 +305,9 @@ static struct kvm_fmt *get_format(const char *name) fmt->cmp = dim->cmp; fmt->sort = dim->cmp; fmt->color = NULL; - fmt->entry = NULL; - fmt->header = NULL; - fmt->width = NULL; + fmt->entry = dim->entry; + fmt->header = fmt_header; + fmt->width = fmt_width; fmt->collapse = dim->cmp; fmt->equal = fmt_equal; fmt->free = fmt_free; From patchwork Wed Mar 15 14:51:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13176012 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 6502DC7618D for ; Wed, 15 Mar 2023 14:53:56 +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=7wuHzcL1hkb5KXrH6UAB2PY7XtY0jT5NoYixMOaMCHw=; b=GGO75/ki8mOZup 5Z4TLdQWlifNLuv0VAxZYBBxYjlzdRu+GS9kv1bJbSM9iDIvYoftubNvvk2XEIKfIjuMqF2r2jTQc bxN8YqSUaH1iT9QbyIOtNhoaIT+wZEmUyXRwwtrIf9bPeY/QGtcxuZ/N1wXDWeaV+Iav2t2JKdTZb XDRltnHccldiHrBp6UHDQX/pvlW6/aOe9L+DXUzCLbIyY7ptEmUnzDsK3BHVluUh4cxmQhRFF5J4f pBL6gKhfF7pQZ2QU+r+TCDEGVbjBwMMuKcUl67mIr0AoeQTvpS6SMlsQqqiK9wsoQEOuuMXDib/2Q qLD1AGFnDPlPDfezmbNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUx-00Dfz0-0u; Wed, 15 Mar 2023 14:53:03 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUk-00DfoC-1U for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:53 +0000 Received: by mail-pl1-x629.google.com with SMTP id v21so10177808ple.9 for ; Wed, 15 Mar 2023 07:52:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891970; 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=lmJnfY2lbCc2C3dy6sxzWUeYnl8mSWLRJqM4XO3hbV8=; b=KypbBeFiiw071Rag2kqAVfUN+QVZTcqiKgxUGUU95LCFu9MmUtsYI+52dxV0Gv89Vy pvCdUgfGXRI6tPoC+r7RLW1BiF/XK9AmJdznQYzoS/HYtLWDcmCSSeflr+kVEeKLe4At SWjpbBLrLMBEltp6BVgmrJMqMhOjBu4+KbFYaw4+W+kuEtJe9qqUWwufhhMUJjwKMkXW UBSeVJ2/7gqCKip0CHurXPOnl1XVpTx+LrtS6vTTZQPVq77Pla+qZWnZATzQj7nDNFwc Jv1vNx+VfVH0Yahp0jDLw3tKhw+sbCtt5eRr+u60J23SyyNF0e5sas97TCOCDhbpSsfW KqCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891970; 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=lmJnfY2lbCc2C3dy6sxzWUeYnl8mSWLRJqM4XO3hbV8=; b=XbpNd81sJaqFgCg5ZGU/urCIFii1SSEWNWWSSClGqfw8pSsDZEhCBD22rtMMLK0f+m VvYS0CHLVm9AWifrSrPIptpM42CKGdFcv49Tz2wASOqHmDDw91GvBziW9SHg7LuuwFpF jMgfaSSY3+SbG4k0BR1plETHKKNlYBnHdibQ3Gp0Iib8Hoh1cr0hNEJL3ZBLJ5LEF3qx Eb35aqDh1agb48UDHl3NGpB55lM+hvedAjUzUZHZrdaJMRPzqV5Hd8hT9hjG0j7GTT9x IFSkWPGS92BShO5pAqi07Yvt2c8Pe6Iechy59TNmosTFfYcrTbdBWZPYi7KnQRJ657Oc kb2g== X-Gm-Message-State: AO0yUKU6SStfc9LCMxJDci6SuEg9X6flPQMm3kaIRUOPQZUvWksiVPhs 66f8azfYXpFZMdrLKfnp5iwbH0SYLsS3GC3FxcGdZsGs X-Google-Smtp-Source: AK7set8CJNZe2JhTNOxg0QgEtz1dzP7EuN9M3xiZmEechhTZHY0AG3PLkB8JSV85l+21tYStSl89xg== X-Received: by 2002:a17:902:e886:b0:19a:7f4b:3ef6 with SMTP id w6-20020a170902e88600b0019a7f4b3ef6mr3551199plg.3.1678891969844; Wed, 15 Mar 2023 07:52:49 -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.52.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:49 -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 14/16] perf kvm: Add dimensions for percentages Date: Wed, 15 Mar 2023 22:51:10 +0800 Message-Id: <20230315145112.186603-15-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_075250_532377_D4C9F095 X-CRM114-Status: GOOD ( 14.27 ) 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 Add dimensions for count and time percentages, it would be useful for user to review percentage statistics. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 98 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 0d857df826cf..ab1cd6b5e528 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -222,10 +222,105 @@ static struct kvm_dimension dim_mean_time = { .width = 14, }; +#define PERC_STR(__s, __v) \ +({ \ + scnprintf(__s, sizeof(__s), "%.2F%%", __v); \ + __s; \ +}) + +static double percent(u64 st, u64 tot) +{ + return tot ? 100. * (double) st / (double) tot : 0; +} + +#define EV_METRIC_PERCENT(metric) \ +static int ev_percent_##metric(struct hist_entry *he) \ +{ \ + struct kvm_event *event; \ + struct perf_kvm_stat *perf_kvm; \ + \ + event = container_of(he, struct kvm_event, he); \ + perf_kvm = event->perf_kvm; \ + \ + return percent(get_event_##metric(event, perf_kvm->trace_vcpu), \ + perf_kvm->total_##metric); \ +} + +EV_METRIC_PERCENT(time) +EV_METRIC_PERCENT(count) + +static int ev_entry_time_precent(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width = fmt_width(fmt, hpp, he->hists); + double per; + char buf[10]; + + per = ev_percent_time(he); + return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); +} + +static int64_t +ev_cmp_time_precent(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left, struct hist_entry *right) +{ + double per_left; + double per_right; + + per_left = ev_percent_time(left); + per_right = ev_percent_time(right); + + return per_left - per_right; +} + +static struct kvm_dimension dim_time_percent = { + .header = "Time%", + .name = "percent_time", + .cmp = ev_cmp_time_precent, + .entry = ev_entry_time_precent, + .width = 12, +}; + +static int ev_entry_count_precent(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width = fmt_width(fmt, hpp, he->hists); + double per; + char buf[10]; + + per = ev_percent_count(he); + return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); +} + +static int64_t +ev_cmp_count_precent(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left, struct hist_entry *right) +{ + double per_left; + double per_right; + + per_left = ev_percent_count(left); + per_right = ev_percent_count(right); + + return per_left - per_right; +} + +static struct kvm_dimension dim_count_percent = { + .header = "Sample%", + .name = "percent_sample", + .cmp = ev_cmp_count_precent, + .entry = ev_entry_count_precent, + .width = 12, +}; + static struct kvm_dimension *dimensions[] = { &dim_event, &dim_time, + &dim_time_percent, &dim_count, + &dim_count_percent, &dim_max_time, &dim_min_time, &dim_mean_time, @@ -875,7 +970,8 @@ static int filter_cb(struct hist_entry *he, void *arg __maybe_unused) static void sort_result(struct perf_kvm_stat *kvm) { - const char *output_columns = "ev_name,sample,time,max_t,min_t,mean_t"; + const char *output_columns = "ev_name,sample,percent_sample," + "time,percent_time,max_t,min_t,mean_t"; kvm_hists__reinit(output_columns, kvm->sort_key); hists__collapse_resort(&kvm_hists.hists, NULL); From patchwork Wed Mar 15 14:51:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13176013 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 79A22C7618B for ; Wed, 15 Mar 2023 14:54:02 +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=K7n5nUGqLmNV+T+oPdyVhMjSQd1O2d+duApgh2PNxOM=; b=HP5NNmMc0eyFDw kYpecXEfUfYz1Q7W1yT1ftC8X34sm1ZD/Mbpmc+5R4lIvFjt7W80fJO+vhvUrAj8dyGnaH7c5+6l4 YmKBaZ6T99IEggCsh/uZHJyfzk4QZE5icwxg45lwPspR9B5fdTHZV3Rc1Rl6rrtbugKpBZhXfu55u gvUafSx0opsQkaoQqPjwYxnHyCAIYVjLBsQOFPm+e8tNG9f4FpK/kZ53ejLpZKnJg/fNZC2pdP4GS DE7ZXJv6yRVvJTVWOV+AFImg98jVoXID1Iuk9Su0cUzQr7cewQoP2hl1m0NfieS7+fFlZArbr76qk XZg6hylyyftKHSAWb8tA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUz-00Dg0b-1e; Wed, 15 Mar 2023 14:53:05 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUq-00Dfsr-2t for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:59 +0000 Received: by mail-pj1-x1031.google.com with SMTP id d13so9045400pjh.0 for ; Wed, 15 Mar 2023 07:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891975; 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=4fUVJ64SEnuw/uEL+nd4TijpPo7wgQdrNlutXsuxFPw=; b=x9vKO8zrluYXjIO9bjuhov9DZqAYa+F8jPYdBlS5kHR0dQKGSslQ3g1RIFT/DY3dOi VVw7kKtu24W/1xfax5GHrCuIF38Xnp01YXTRGWvIJsSs4CS6X1z6szgrhaZNh8Py3f8n AGYREmFwR+i8ztqj+WLQj8ejBEfCI13ArCEUGW5dDcx4hi/nuHtan9lOjsnVHFf3qk/M ELsF+6QNzSAgNYgtQWu41OUMvJh1xo62qR5QUAvQ5/dF8MvHfNslaEzh6me8hCAHAWr4 6XWNYL5m4aGKIGg5APbsyJN58aq4yEHfL1cIqB2JEgmf0Zw2yF7ajrpoC6X5DKrlKAXE zTSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891975; 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=4fUVJ64SEnuw/uEL+nd4TijpPo7wgQdrNlutXsuxFPw=; b=qTZtil0KN3XIjhEsvqorRS+TXe4vQvnp8+ZeBoiChMf9KYJ83vf7sOQsQuGzRuEySm vq7rlzEoIobPCsMXuatVrBvGjKtxNbjtbTngDsphd/IpdfAHKeizAhGjLbhqS8f4VRcr qRBsS3uGg0mbOHu/opeWxF6JM0HLkNV+S4XpD0a5jSzmQ+ImRjzqaEPx2f9Rgc9S4b6/ LcpAYYAPV8d+tPMir15S0+cJJtC6luGdJhNStWv7Awf5hUg3P2UvgwRLqTGjX5+aow+5 xMwX7FNdxTGUj3Bd3nbwTB+ooaQzPd7BI1QL+19e0W72UHsmb8HoCkEu7et2gsR5GqLv PYHw== X-Gm-Message-State: AO0yUKWRMnpA01msKt2UfoJ/QiNkN7kvzxoXgfBUBfQsZqB32lv5BjxQ dePLpA6rCTt2lVL6+UwlrCdYmA== X-Google-Smtp-Source: AK7set9B+UVpE782e+TBDyWEej89u0xSElFONYLClqrCI95oD1FjuDxJopuGRtjHwWabgeFPczT3Ow== X-Received: by 2002:a17:902:e2ca:b0:19a:f9b5:2f2f with SMTP id l10-20020a170902e2ca00b0019af9b52f2fmr2311988plc.55.1678891975618; Wed, 15 Mar 2023 07:52:55 -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.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:55 -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 15/16] perf kvm: Add TUI mode for stat report Date: Wed, 15 Mar 2023 22:51:11 +0800 Message-Id: <20230315145112.186603-16-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_075257_008305_37D60D71 X-CRM114-Status: GOOD ( 20.91 ) 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 Since we have supported histograms list and prepared the dimensions in the tool, this patch adds TUI mode for stat report. It also adds UI progress for sorting for better user experience. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 109 ++++++++++++++++++++++++++++++++++++- tools/perf/util/kvm-stat.h | 1 + 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index ab1cd6b5e528..3dd44763d1fc 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -23,6 +23,8 @@ #include "util/data.h" #include "util/ordered-events.h" #include "util/kvm-stat.h" +#include "ui/browsers/hists.h" +#include "ui/progress.h" #include "ui/ui.h" #include "util/string2.h" @@ -495,6 +497,7 @@ static int kvm_hpp_list__parse(struct perf_hpp_list *hpp_list, static int kvm_hists__init(void) { + kvm_hists.list.nr_header_lines = 1; __hists__init(&kvm_hists.hists, &kvm_hists.list); perf_hpp_list__init(&kvm_hists.list); return kvm_hpp_list__parse(&kvm_hists.list, NULL, "ev_name"); @@ -506,6 +509,93 @@ static int kvm_hists__reinit(const char *output, const char *sort) return kvm_hpp_list__parse(&kvm_hists.list, output, sort); } +static void print_result(struct perf_kvm_stat *kvm); + +#ifdef HAVE_SLANG_SUPPORT +static void kvm_browser__update_nr_entries(struct hist_browser *hb) +{ + struct rb_node *nd = rb_first_cached(&hb->hists->entries); + u64 nr_entries = 0; + + for (; nd; nd = rb_next(nd)) { + struct hist_entry *he = rb_entry(nd, struct hist_entry, + rb_node); + + if (!he->filtered) + nr_entries++; + } + + hb->nr_non_filtered_entries = nr_entries; +} + +static int kvm_browser__title(struct hist_browser *browser, + char *buf, size_t size) +{ + scnprintf(buf, size, "KVM event statistics (%lu entries)", + browser->nr_non_filtered_entries); + return 0; +} + +static struct hist_browser* +perf_kvm_browser__new(struct hists *hists) +{ + struct hist_browser *browser = hist_browser__new(hists); + + if (browser) + browser->title = kvm_browser__title; + + return browser; +} + +static int kvm__hists_browse(struct hists *hists) +{ + struct hist_browser *browser; + int key = -1; + + browser = perf_kvm_browser__new(hists); + if (browser == NULL) + return -1; + + /* reset abort key so that it can get Ctrl-C as a key */ + SLang_reset_tty(); + SLang_init_tty(0, 0, 0); + + kvm_browser__update_nr_entries(browser); + + while (1) { + key = hist_browser__run(browser, "? - help", true, 0); + + switch (key) { + case 'q': + goto out; + default: + break; + } + } + +out: + hist_browser__delete(browser); + return 0; +} + +static void kvm_display(struct perf_kvm_stat *kvm) +{ + if (!use_browser) + print_result(kvm); + else + kvm__hists_browse(&kvm_hists.hists); +} + +#else + +static void kvm_display(struct perf_kvm_stat *kvm) +{ + use_browser = 0; + print_result(kvm); +} + +#endif /* HAVE_SLANG_SUPPORT */ + static const char *get_filename_for_perf_kvm(void) { const char *filename; @@ -970,12 +1060,15 @@ static int filter_cb(struct hist_entry *he, void *arg __maybe_unused) static void sort_result(struct perf_kvm_stat *kvm) { + struct ui_progress prog; const char *output_columns = "ev_name,sample,percent_sample," "time,percent_time,max_t,min_t,mean_t"; kvm_hists__reinit(output_columns, kvm->sort_key); + ui_progress__init(&prog, kvm_hists.hists.nr_entries, "Sorting..."); hists__collapse_resort(&kvm_hists.hists, NULL); hists__output_resort_cb(&kvm_hists.hists, NULL, filter_cb); + ui_progress__finish(); } static void print_vcpu_info(struct perf_kvm_stat *kvm) @@ -1577,7 +1670,14 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) if (!register_kvm_events_ops(kvm)) goto exit; - setup_pager(); + if (kvm->use_stdio) { + use_browser = 0; + setup_pager(); + } else { + use_browser = 1; + } + + setup_browser(false); kvm_hists__init(); @@ -1586,7 +1686,7 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) goto exit; sort_result(kvm); - print_result(kvm); + kvm_display(kvm); exit: return ret; @@ -1693,6 +1793,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) OPT_STRING('p', "pid", &kvm->opts.target.pid, "pid", "analyze events only for given process id(s)"), OPT_BOOLEAN('f', "force", &kvm->force, "don't complain, do it"), + OPT_BOOLEAN(0, "stdio", &kvm->use_stdio, "use the stdio interface"), OPT_END() }; @@ -1710,6 +1811,10 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) kvm_events_report_options); } +#ifndef HAVE_SLANG_SUPPORT + kvm->use_stdio = true; +#endif + if (!kvm->opts.target.pid) kvm->opts.target.system_wide = true; diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 35d03894fac3..bc6c8e38ef50 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -103,6 +103,7 @@ struct perf_kvm_stat { unsigned int display_time; bool live; bool force; + bool use_stdio; }; struct kvm_reg_events_ops { From patchwork Wed Mar 15 14:51:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13176014 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 81F29C6FD1D for ; Wed, 15 Mar 2023 14:54:17 +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=k3cCkjFFiO2r8pCOda+ofl72sy4+FDtaKf0LDa/P9pA=; b=FJGf7eGwV1ek3c t315TCLj5XG+tpwSpZtGeub5P1cBitq9Wieny4eziuCiahdwKHDnWx+7W5C4I4RdbtIj3s1ctSdST Ox/cnJMZ4BU8HJiJ/T5ue+LdnqAwdYMDReKGOQcFsGVNMkp9OHUkxrr/EZBbroLPfd5ihyLy4Lzch Dpab45jGcNkkX4tfbJ0k5Yzna15umdU12WF5zVFjANZBt6xnbAmKX4SEfWnZVHNSk200Jkm2rQxrD jlReSMwY51DM+WcGKFsmn0KEL871K26lKKDjfJ/61d9klCrCSsda6LxFEfXmVx+PfYdDqQF+DT1vt vmoAnrwsduh2KBasxAzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSVF-00DgCA-0Z; Wed, 15 Mar 2023 14:53:21 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUw-00Dfxi-01 for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:53:03 +0000 Received: by mail-pl1-x629.google.com with SMTP id c18so1715935ple.11 for ; Wed, 15 Mar 2023 07:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891981; 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=t1yEtOA/S7kgzfPudB0ZivwtY0/Ec+bbW+dtSNwunWQ=; b=fBRB+iqdB2lrxzxP/K6MLf4EVrdfE0pmldFOD/r94qjAPy1mKmIlnvNcBS3W/1QOdZ GB1Yr8uy1wE/+elFlEF+g8O3cQZMYKq46UlaeD4QOba7SeslEPUMYDWLAnQu5j1Is7Jp 3m9F0TNKHkF/Hcr0Cl6aGH6Xg29iw/A5KtZBAuA9e8D6Ds6tig1mOs/+KA0OYA7TMD0E Iiqn4iHdoz9bxm5gXl3XrAqZEHNiXBcPOFFu99NUAczAW7OQNB8Z0Zj+ysgGnRNbuWpW LO4an+DRY+3aj3Y69HgvpZRxVwLx0ikauopI6KAUHGYAEaezIggdyg6uJadwj4n6nBMs U6ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891981; 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=t1yEtOA/S7kgzfPudB0ZivwtY0/Ec+bbW+dtSNwunWQ=; b=fxPDqt680u0CGJmqrxvWQiBAN+CmG5clVlODNoL0G2Tuq8HNcxNkCVZ8NWZ7qPxjB+ SFSblw+3SF1uRc7EUlXTsDNlYcfGE3E4k1Y/pQjlKEWK7C3sRYhiFm8YDYs9Ejpmf0E9 bAwgebM+af4SZjGQ41lLZCcMrVHXLSFlKZ1KqrP/dmHkRPXSh2pDJAjH41pJfiCJ3WrM p3GB6IW/bzV3GtLBrSpxhdjCpxd0UQNWQ7lb8yyidT7TAltsDJNQTxDuohGhdGPVnoq6 CkEOj1YKIIQzXUK1ULm+rDfUEUecADUPMGeAcj14pS1C9ogkjAzgesrfdlUBii7BhMKw opSg== X-Gm-Message-State: AO0yUKUmuzeyi6IF+LXlOedWB7bLSOArDDxZJcOJfjjoVeIzD3LrVgok tIyhfwq16c1eVT7U/zD/a9+82Q== X-Google-Smtp-Source: AK7set+JCK/kO1YmQbSWHbUctvXH13LzI3Uf5TBpJAr0ALjblrtiTJbKCOgXTLT8x7A3gG/mulzd7Q== X-Received: by 2002:a17:903:430b:b0:19c:171a:d346 with SMTP id jz11-20020a170903430b00b0019c171ad346mr2373750plb.44.1678891981306; Wed, 15 Mar 2023 07:53:01 -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.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:53:01 -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 16/16] perf kvm: Update documentation to reflect new changes Date: Wed, 15 Mar 2023 22:51:12 +0800 Message-Id: <20230315145112.186603-17-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_075302_058006_5B63B471 X-CRM114-Status: GOOD ( 11.96 ) 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 Update documentation for new sorting and option '--stdio'. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/Documentation/perf-kvm.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt index 2ad3f5d9f72b..b66be66fe836 100644 --- a/tools/perf/Documentation/perf-kvm.txt +++ b/tools/perf/Documentation/perf-kvm.txt @@ -58,7 +58,7 @@ There are a couple of variants of perf kvm: events. 'perf kvm stat report' reports statistical data which includes events - handled time, samples, and so on. + handled sample, percent_sample, time, percent_time, max_t, min_t, mean_t. 'perf kvm stat live' reports statistical data in a live mode (similar to record + report but with statistical data updated live at a given display @@ -82,6 +82,8 @@ OPTIONS :GMEXAMPLESUBCMD: top include::guest-files.txt[] +--stdio:: Use the stdio interface. + -v:: --verbose:: Be more verbose (show counter open errors, etc). @@ -97,7 +99,10 @@ STAT REPORT OPTIONS -k:: --key=:: Sorting key. Possible values: sample (default, sort by samples - number), time (sort by average time). + number), percent_sample (sort by sample percentage), time + (sort by average time), precent_time (sort by time percentage), + max_t (sort by maximum time), min_t (sort by minimum time), mean_t + (sort by mean time). -p:: --pid=:: Analyze events only for given process ID(s) (comma separated list).