From patchwork Mon Mar 13 11:40:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13172300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8F58BC6FD1C for ; Mon, 13 Mar 2023 11:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WxYHaArlSWQDNVWb0Q+HiD792dCrF+E0oMk/PcZfjaA=; b=bKArHGu9VgatQD L96x18SZy8JdMGvVJByQL/hgefkfyWtdxBUb+hA+MvFN1HXqXvHU1ExQxchiACDkVue6kkwTKeJJ6 ZF9NnO7GZBLsUwkkGN/UhhHdSBHxEhVvGrOX0ktWe+nav0DAdysYho0f5ruPlwOmL4Mlve96amGZ1 aowXjShYoqzVkheOODmNlGKjxqwc9sw1tnopVnG0g3363CzRBcOncCRnWpLc4/gnuiii8lC+3cVW8 qkHugCsuQ7NBK5JAxAbTsvrNV0JRVM5T07TFs4YeHJ1ngqsyXFMvMSnyrHnKpBwvg3Uy3oCmAspz4 chC0G9v408xTuexCfe/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgXr-005S1A-Rw; Mon, 13 Mar 2023 11:40:51 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgXj-005Ryk-Sm for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:40:45 +0000 Received: by mail-pj1-x1031.google.com with SMTP id u3-20020a17090a450300b00239db6d7d47so11348730pjg.4 for ; Mon, 13 Mar 2023 04:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707641; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EfFwm9/whD1jR/5n6DKKR8V6Fa945UAISwsDPx5HLJU=; b=UKMSaTwrX/iAEgtNVLYK1CXWlwTqjnwE629XOSX71tKhB6T3cAOlOXRTt3LvlrWi5X FqlTeRl98HKQVTHqKqa29/tAnEmIxP09oGP9/8q3Gu/uMR3E1dnVkTr0nDcF/SOpIkoP K1tgzxVrbtc398A2UEIShZ3XaBB3OyZkCx12EVsY2GMx99hts27vPZWdKGe1VXBA+1u6 DikXAAaaBuGfS5cSKOLPHhi/GvbKi1EyuN0dErkJI4ai+P/eewM/XyDHcbX41FIesMjC bUSF2i+E4x58EQP94dSS6NFDlKbrBcYM7VPl7vL5Hx53Uoj3uCKZWCJSVqDlOx0icC9N HmzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707641; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EfFwm9/whD1jR/5n6DKKR8V6Fa945UAISwsDPx5HLJU=; b=jWVg8ToflzKfPlZfFRsQsQBMgqim38TapRIxqEd/4tFzmBboPUt2gzYU5+/E5u4YH3 PnIvrKAGGxxWaeXzBTfcoeMfYALmhkuU8Fn7w144y+MvdhMdwSyicx5dUORuwN1kPE0z Q5P/wDz3BqjHYUfF8NnJPKhsVXSNH36YlqMX9kBW/eTjEZu+j1yHrg9CGjeAUbj+KH+D S4Fmc4KZ1s700k8Gfh1ehFxa9L17gM5/0UJirpGKQ706QuEccK7jzWIVb1ysm4D/xAQi RZhTSeJyoabAEJHfw5KHgGa7Zxsn+YXf3YDHflY0LA/d6vWQHHx5LaatWwwAPX/35GAz e8CQ== X-Gm-Message-State: AO0yUKUUk6q5lBzjnUUyfq1VZ7dR8zdNABdSqgtbAaHTj6k4rE1SCJo8 FqFAk2dCO/fABS9BOsVosvFwvw== X-Google-Smtp-Source: AK7set9Qn3N/Y7oeDr4/exTQKdkEWr0ZNpz0BljQKMTsO0FQUS1zMkn4oSsJkGhlLxsW10/KuXmQFQ== X-Received: by 2002:a17:902:a986:b0:19d:297:f30b with SMTP id bh6-20020a170902a98600b0019d0297f30bmr26907234plb.19.1678707641163; Mon, 13 Mar 2023 04:40:41 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:40:40 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 01/16] perf kvm: Refactor overall statistics Date: Mon, 13 Mar 2023 19:40:03 +0800 Message-Id: <20230313114018.543254-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044043_937462_1120FF4C X-CRM114-Status: GOOD ( 14.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently the tool computes overall statistics when sort the results. This patch refactors overall statistics during events processing, therefore, the function update_total_coun() is not needed anymore, an extra benefit is we can de-couple code between the statistics and the sorting. This patch is not expected any functionality changes. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 641e739c717c..0172e5b0d26e 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -278,9 +278,14 @@ static double kvm_event_rel_stddev(int vcpu_id, struct kvm_event *event) avg_stats(&kvm_stats->stats)); } -static bool update_kvm_event(struct kvm_event *event, int vcpu_id, +static bool update_kvm_event(struct perf_kvm_stat *kvm, + struct kvm_event *event, int vcpu_id, u64 time_diff) { + /* Update overall statistics */ + kvm->total_count++; + kvm->total_time += time_diff; + if (vcpu_id == -1) { kvm_update_event_stats(&event->total, time_diff); return true; @@ -399,7 +404,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, } } - return update_kvm_event(event, vcpu, time_diff); + return update_kvm_event(kvm, event, vcpu, time_diff); } static @@ -526,15 +531,6 @@ static void insert_to_result(struct rb_root *result, struct kvm_event *event, rb_insert_color(&event->rb, result); } -static void -update_total_count(struct perf_kvm_stat *kvm, struct kvm_event *event) -{ - int vcpu = kvm->trace_vcpu; - - kvm->total_count += get_event_count(event, vcpu); - kvm->total_time += get_event_time(event, vcpu); -} - static bool event_is_valid(struct kvm_event *event, int vcpu) { return !!get_event_count(event, vcpu); @@ -549,7 +545,6 @@ static void sort_result(struct perf_kvm_stat *kvm) for (i = 0; i < EVENTS_CACHE_SIZE; i++) { list_for_each_entry(event, &kvm->kvm_events_cache[i], hash_entry) { if (event_is_valid(event, vcpu)) { - update_total_count(kvm, event); insert_to_result(&kvm->result, event, kvm->compare, vcpu); } From patchwork Mon Mar 13 11:40: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: 13172302 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 E0334C61DA4 for ; Mon, 13 Mar 2023 11:42:14 +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=JJrR+J/Mg7s4eD kriAATDHvALBpsprlBJ2q6ADmZRhV+mv9X3Twn3c99sIcsELCms5On6KCoXjYAtnP588Z8Rb4zpV0 3E0xyvSfZeb4fTsK9Dm3yngku0oNBmB5O34wvaA556zAYjdHvYS29MUxZQNaX1BAsOsc78z8diBCw lStPRfphrLeD2tyL4z0LT+/jsV8V7RobYb9/xKLoH0mq0BzifPszVRJeADq/6ubrjDH/OLMW2y8Au GnWJe7LwteedfFYrCyVCB0mZ5sR2hvRiXplhdTmKW1JwfRn+I0d3+wuVV75HEaUt4NlA12LL7yXVQ 7PzONJeas4OevfmHrQHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgY0-005S4Q-50; Mon, 13 Mar 2023 11:41:00 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgXq-005S0N-7F for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:40:51 +0000 Received: by mail-pj1-x1035.google.com with SMTP id kb15so11708803pjb.1 for ; Mon, 13 Mar 2023 04:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707647; 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=ys+dsTy2vh5IRMXu/71+ZQS9QxgiwshRjarRfNFvlFiW60uTbW/yU0lWs+E37FB4qz VSPJHNbcO33USpFkL/q9Adz8H03Zhlk0Q3tIsXazE/d9+g8USW9+18mTPEORCn6mP9wx JF1xEietU5qPMMzExkFMe/Q1aL0hz7F5EL2rxl6sh3mclaE+XDHgej7K0aEcXF/fl2tQ k01DVC2W2dXjTDnptjKW/fRRstP2X41ql9tXQKTnmvbDl/QR3Of8lQuxNexFkTPbfVaN IERCN2JEGZC1Sp4Gw2tU8tbCM85A9E2bqYLC42pgd8r309b/27IP4+aWTujQPYJtuOE2 oWcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707647; 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=f9q5P41PoLyoU6awy/ufSkPSnZ3hhl8PR5cymw3ok2wJ6lBKUgf0GCwNDuSTpAVvJR nBo/eJj7lbIoP4hjAqJ3WK5xcGW0ST9AAogkCu56ajZCkc1eypS2Rv3JCV3S9mK0BgVk EOrVWzw0uSJZnVgAvkW313ZFfjY10EKxl1tf2gW0wpXltfuzYik1d43GkGcCD7g6Ywyn 6px8i19PNTrf0lMjUoGWOtQeCdAKfQK7yA+vqMdC7131qJwlL5niquiutRcyIstdYEPo fa5J0JDZ2SXyD58CP0xK782+rYbO5NJI4mICBtQzeXtc4baKhqKyRUVA3WTqRrc45xM6 9i8g== X-Gm-Message-State: AO0yUKWuQetFYaFrsorUDEe7xuY0Ez1djZ1xMyD4CsPk4i2zbjAHlczy kXLkGkq8yfuEeRaEU/q735Qz9Q== X-Google-Smtp-Source: AK7set9XabVkPC0XB7oQedZ03RgD/a3sbthW1LOnLfUx8dkqc7s8K45x5xD5S1HL2sqJ+GK0fRCdqQ== X-Received: by 2002:a17:90a:ec13:b0:23d:9ae:a49a with SMTP id l19-20020a17090aec1300b0023d09aea49amr2896119pjy.30.1678707647136; Mon, 13 Mar 2023 04:40:47 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:40:46 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 02/16] perf kvm: Add pointer to 'perf_kvm_stat' in kvm event Date: Mon, 13 Mar 2023 19:40:04 +0800 Message-Id: <20230313114018.543254-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044050_269999_EC441B7E X-CRM114-Status: GOOD ( 14.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 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 Mon Mar 13 11:40: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: 13172303 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 C06D7C76196 for ; Mon, 13 Mar 2023 11:42: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=4CmB8kIvjg1Us3HAKhr0mHDnjk0Icl+j7Ztkbwz8JU0=; b=lI6inRDUMzKUhP zZvwvenoCtZZFEW/dWQbL3Fl62EgUMAQJpS0eV3xi309OBDEgJcJlh4+G4xUst8oIHYbdJwwnnGkb Qs2R3i0fmY/5jH9ZEDMjxHcjb//5ID+zVb5fePSuSsiU9FJPEHQjZOxNEyGr+elezVcAwaQgAEnh9 DZ6mccia9t249M1DpV0gMB/0aukByWM9Hrda3ZXgqMM4TTtDWa0ryF//lnkn2Cf+f2QykQwHZoOtW IaFqQfxPr3NDthFiWjoIGTOmqQKR5GIHk/hE1qEGYObfpTBkSmlVyD/TGp1bXj0QDwkd9HcTLeIly Rji0IxKCclsgUCPgQj+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgY9-005S7J-Ft; Mon, 13 Mar 2023 11:41:09 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgXv-005S2d-E7 for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:40:56 +0000 Received: by mail-pj1-x102a.google.com with SMTP id y2so11677728pjg.3 for ; Mon, 13 Mar 2023 04:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707655; 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=lnyLElApv7NnUsgOvaifBSHgYeHAmg6da7c7jzAexRiFFgCaBVjIDqWsedH4pS3CQ2 Jw0+7ZrHOQBWZGR/XKq2dkLxLEMHw9AE9/58WvGpBwyGvQ3Ilrj0Kvhm04xfWfySExcD 5DETnEtSfjQIEf27I/QR4HS4fKDgHnT/aeCKKy0yZLaKzO229NgEPXyov+ObigOAonz7 bKX4em//1FqtEQVLJPTz+j5dg7zEIfAaUKv78qttuZnOp2Om45cIM4cLM1RFnGFaQEVR OoAG6i+q6Mg9TyDVwnMQFQNHCNp7OlDcOZq1aUkdLzU8yUP0OSLjyo9xKTLqAI+LI6jU EZxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707655; 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=jY5yiQ/n/KuphxbY0QLcFYldX9Yu4lZKJfCJfHAGnDpwydWHnAZ1nQidQCLqYnWzKE Tlt5coPONhTw+u30mIZvHKaU73cjQWDQU5ch3SndY9pvNKYTwlwwW1PHXPFes4LGdDdt y/Dn6yXT/iv7gA4stVjgqPbgklehrsHAujHkllkQ0NIVRgqxCyJIrweUgamWMeMb5Wxf kmx4DczVhuh53MmRleF+tuuQ5/gpChslWokQCKPtr0IJoNekDh7YNlkUEDk3863wmfcz 3DIyR11FHmxgVL+xwKDqojUwp7v+BYRW6RQZtGiQjIzAVTrplOj5MeNNMmbhrftslyRe jmqQ== X-Gm-Message-State: AO0yUKXa88Rj5fR7GbFfy7e4G/mJtxxutv7ohYDlHp9MdCLuxzvOprHx GhYKmOoAsJEV0K0zxb2+enUinw== X-Google-Smtp-Source: AK7set9NefgnF+3svVDo4B3o+1IDC59WD7sj8UM5nnDc9xjSkGgKmUAixlouEv38J+Ox6ns97dZuQg== X-Received: by 2002:a17:90b:38c3:b0:237:d44c:5861 with SMTP id nn3-20020a17090b38c300b00237d44c5861mr35810313pjb.12.1678707654867; Mon, 13 Mar 2023 04:40:54 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:40:54 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 03/16] perf kvm: Move up metrics helpers Date: Mon, 13 Mar 2023 19:40:05 +0800 Message-Id: <20230313114018.543254-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044055_497168_9F0FE7C3 X-CRM114-Status: GOOD ( 14.30 ) 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 Mon Mar 13 11:40: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: 13172304 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 6CA83C6FD19 for ; Mon, 13 Mar 2023 11:42:30 +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=2jLSopEKCVpZH4z2ctRIpoMt5FSzv7mLAxYBWN3JxwU=; b=1PpbqKIjCJiEav bUV2Kxcn9ZD8tj/1+rDoTlq38nLt6QfC1UscmEcl1UopBCIFVbCQjjKFdoNIiwxJS1BorWsu7wYnU ODz145g1tJT6jFJ/n8JyIekqreokKEZtdmQGqLwChRz5/qUagq5ewdz/ez09SrgEBpg5QSyDjdMJ8 TeUz3i5WAe+aIqpdxtuQeNBN144+Jz/yvVUfF+tlzfHzq/akQXLks35dX0mY1Oun1yp1yuOo7LY+w mEWfvFFEQqc6uSF1/NI3585LxdFNnWMnYRGjVedac9/w7cH6vX3bsonElIAQdNNEiXMjWXJafFL/I IEDuTwxGxBLb58666dNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYK-005SBa-Mu; Mon, 13 Mar 2023 11:41:20 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgXz-005S0N-3g for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:00 +0000 Received: by mail-pj1-x1035.google.com with SMTP id kb15so11709316pjb.1 for ; Mon, 13 Mar 2023 04:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707659; 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=Q/nbi3g1G7blTIc7EqTO9R+UAXnIBnoxcjmSOAZ7Xck=; b=evWDaAHRTVMrCXo8odtG+XiiUQi/tIoaxy/YK2dWKYAJKc1YsgTzVcGbRMwl/jK+A2 se7zCOxQLs0/AMm0R/Hhi+RHruUbuxn1oDGZPAGOfRrzGKFTMfkzP5AJ1vrEY24SqPj6 U8QlLyFEj/m6hPLsidBw0kiRmNFqGEVPs0lrJSV2ii0F/aNS05n+LoTzlWtrKf9cVICX nxxlfGv8wfAiU5rqfpRciQ3k/egPgubfloC8K9Pq+dvRgpUbfugeEwPme8sOHuBvXGuC D1LMKU1U44tgTYfVr/K7MSsq73F/9BaP+WfFwm0fORwzQ+LDfFh+u4/B+dSRQoGTJG1o /mWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707659; 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=Q/nbi3g1G7blTIc7EqTO9R+UAXnIBnoxcjmSOAZ7Xck=; b=VyAmEYqhN+8oeR9b4wyGn3oTOGKhIbLoe7rO9+aL4/rA+8YLbLqSxfHBgztVFa9q7N x4JACSqgIVYIWwst8bf3/wKNL4y08WZVSn/HGRMozu6r3rTdQz/LfN60EVQ3fabVgsy2 UDE4yVU64/xOePUa9hkmrawoWsN3BOGQqPpQQ/9vPZAOT92ediS9tmpa8W6SoLrZo9se qsamPb+m0h32MJwt0c9uUjr37DcIegRdggomS5WpwWG26FZ1owSgj0GOO2wWf/r7GpYE dTFibCQPkyPH0sxkdc3VTTMRXlbN7TfaCwmN5FDyzo8rpxFumQ4M2kDthXZ3r/rpifdd NOrQ== X-Gm-Message-State: AO0yUKUX3iQu44V4LTr+3sKJf9OnNfLBe5TnhPC2b1jEa7eQCo0VwDJL J6JBD7/tgM/EH17yAdrVvHKEZQ== X-Google-Smtp-Source: AK7set8teySbue549QBMEg2WXUd64gS+oeeOqp2p0guknoK0bwSJzOLunt6prvsrWSje1dQr+Go6YQ== X-Received: by 2002:a17:90a:94c7:b0:23d:2b11:b39b with SMTP id j7-20020a17090a94c700b0023d2b11b39bmr34239pjw.31.1678707658713; Mon, 13 Mar 2023 04:40:58 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:40: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 v4 04/16] perf kvm: Use subtraction for comparison metrics Date: Mon, 13 Mar 2023 19:40:06 +0800 Message-Id: <20230313114018.543254-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044059_220464_94B82CBF X-CRM114-Status: GOOD ( 14.73 ) 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 the function return type from int to int64_t to avoid overflow. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 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; From patchwork Mon Mar 13 11:40: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: 13172305 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 A297AC61DA4 for ; Mon, 13 Mar 2023 11:42: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=PAGd8YIDNQvBOcjE/m29gRuLgdvytAKJKFzT/H8mgow=; b=pRAU45vsPURf4w q5ETc2yin4Hvs4mextaDWGuoPhlYs99Wc1nfPvuU8gIvE3yj8KGbTUsdCI5u9MEfSRtpy7Z++g1QO HPTcVrE0APPVJiqMTish+7uqZt7GBNcFZ7akyh1AUUvtc74XNMTrUthisHlfHTYxeUC0BTQoK4e+y ewSQUf4RvhD/oCiHuT9qWuWEYIhaBYWirzzEHwxLqDyFbd8nzOldgPJwK9fFg8ek5he9wyDaVjuU0 ScEyLRckU4CKB7wcg04SH8zO7Zs9B007dOjR9is6wc/g9u9KGvxuOzarLXUwcKfDo4PTTS1u9LAXp 1J9aSEbC+X79+3X77SLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYg-005SJI-6v; Mon, 13 Mar 2023 11:41:43 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgY3-005S5Y-Ay for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:06 +0000 Received: by mail-pj1-x1031.google.com with SMTP id e15-20020a17090ac20f00b0023d1b009f52so1267259pjt.2 for ; Mon, 13 Mar 2023 04:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707663; 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=j6kBGPnEPjnrQRBTl/Gpvo8CV0NUMglCUWHrEzVJ/Sc=; b=jA43tTQ/5MyWe2o8ZUk5lS1lsoTHjUFAMFyBBCy7ZsblnFSv/JOleIk5ctj/QB1OoF bUJgmdWeSHg3TmOkIvEe8hfdhqre22AXIVUi0bpG9Zo6Vho45RFu4m9XMfHUt6x9yufN 6u4gu3/sTI0YjdiQgU3GD8+QE+eXfqp9epZWGILkk44SPPPvK+ssZC537q5x1ECMMMXc qIBE5u5z8/uqbkBI8oI9JFMntIJugM1uX4d3pwrefeflOn+yS8zRV2EeteaDfvByjcUk qF7Ifvh6XmOAHRgA4d0+syhrVskvlxJUlaZEuj7taVxDkcWyxIxPx+PGZpTN3H0Vlu9V RsCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707663; 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=j6kBGPnEPjnrQRBTl/Gpvo8CV0NUMglCUWHrEzVJ/Sc=; b=E4dizZHI4hihcHaMD5ALCxy5d+JtuCktCy3mi4lQV/dDrknwZLL/ewgcysqbAgnSeP u4D2INJLqjMEkEQLI8RgdGIiaptg7jD/lW7bZvw9KSIwT417slP+TQayFsTWN7TKnVnf FRA9URlOtmsCl2piQIUbn8ucj5/pfigumqNLjRFxRFZ7SIW+rT57tMk2c3pty4MpFK/K vLY2TOGJYRpswUI9XszXJOcJRtM2e6WDG3GNPHxqid0TLZJ/FN7lLL4zIQwmWWCHP/aV VuyHyV6SpFBpXkcSyBArZKr9/eNrPNuHl0OBCqFIWZTFkgQ3g0/TK+oa1Ug6TL9Qd8Ne OQWg== X-Gm-Message-State: AO0yUKUZErSc5Jf2tpVHb0S/eYTgoNfiCjMO/jpCeMpAIxWYURCw+wC+ tCXxTph6hZ7r/YiC7uqVoch1Wg== X-Google-Smtp-Source: AK7set9nVaagRcU9ZX8gAq7nQu+fXUOP5fXebaFHVDbGUNxbikBDE3zH/8mbwgUV6+rT+S7uO0KL+Q== X-Received: by 2002:a17:902:cf0e:b0:19e:2495:20e0 with SMTP id i14-20020a170902cf0e00b0019e249520e0mr9441697plg.21.1678707662693; Mon, 13 Mar 2023 04:41:02 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:02 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 05/16] perf kvm: Use macro to replace variable 'decode_str_len' Date: Mon, 13 Mar 2023 19:40:07 +0800 Message-Id: <20230313114018.543254-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044103_528141_F333286E X-CRM114-Status: GOOD ( 15.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 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 40a4b66cfee6..e84f1cdcfe05 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 Mon Mar 13 11:40: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: 13172306 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 50093C6FD1C for ; Mon, 13 Mar 2023 11:43:20 +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=ClTmUzslRhRb6wuuwabJV+32/MfIcT2lrbfmxUvZo4M=; b=ZSTz8DptVXG+AZ wLR0WXL17V6IcNSObhhTi9hHy8t3Mgp7rT2JoEpo5lZxMtJS/mnByN8h3LiJMmBKHX9M/KJbJf/Jw rOHbYttNxMtL3leiYmRsJiGcnPIIkfQskYcoVoL7DYgpdM4nitGMmXZPKg5K9/gESjWqZ/wVcf5jH 3FwYeIVxYw8t15Y9wFIQiS6cXVsgB6EyyYJOlmXqn97w0tJ6dJo2SyvG1RZkSpUEqHHvOXLuh7rKM 5keLg2Kk1kwc0o5retjFlul6IRisz+lk3dqgslyQ9VIg3zNl0IgoeJj7WtDvCA0vgKZHnU2ipZYOd LCX5Y73BhhbuTQGDwHow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgZ9-005SXs-Bu; Mon, 13 Mar 2023 11:42:11 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgY9-005S6j-78 for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:10 +0000 Received: by mail-pj1-x102d.google.com with SMTP id d13so1652631pjh.0 for ; Mon, 13 Mar 2023 04:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707667; 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=qSdUbtxY1+Pylww6c27L2gmYy3OoEmd30YUAl5uUuD4=; b=JdCN4DnjsIz8YM3uGExs6pbkHrIiWnJ/jCXj3wqhLn3yYf0rTHXThsN/8y65TcJYDH ORkO3CS9JgQi6TrHXBccQXUpAOoxrP3021V2614gp/rDRlP3XvIYGQMKNzOicBpd25ZY 1M/Ya7gznDe5xSpPhVONXi38ESzr9rkKoMeRnkyDrc62UjSY4LQ0l9U3SxEo3L4pOI5g wkbaVz0+wa8QCUqXc0INVPCGd9WXY/NqWEqahFhnCk4Uzp2aAasqU2mt8UZBzE4roxT6 j+THZ/H8Vb39Kj59OrEIRBUKLdFZ68n6gMWKI4H9zJaM5ShqvCeI4HPKnC0C/5Cp3PBL 7BZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707667; 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=qSdUbtxY1+Pylww6c27L2gmYy3OoEmd30YUAl5uUuD4=; b=Ru7Cdqqwl8o2DzOMQL8IChVIn2b1jPOFwhZHRBv3BvTO0Sk/irge+wx/ix3lb3zbfK /d4Bx2IOIwnNdJlchjR9vhQhAWfGRNNr8XBTUo1Jv0HNn569C7GV6o+GByDxw0bwLAzy car327dFxjdlF23lyT7Li8A84/oiaQrCWN6f0Oo1DRM4IeQYIImjJYBDDMAKTHTOWm0X l45H0ypfGUcBRPY31egjSr6Pw2E95ef5gX0FpprwYugS0eixwOHlEuHW6ArBZSIkNPaS 7wOBHEsKKMhR/SjcWCGkXRmW1vY3wCWOjg0QQWDLpj/qHo9PYVQw1DkcJ2bJmvilwL4w JsmA== X-Gm-Message-State: AO0yUKWacyAsPOBWo/S9UpBMJ7NnO1w6BRyqDr1+SZ2e5s7HgVhx++AQ DUVFF+dvltEwYVt6uUOBUIF9hg== X-Google-Smtp-Source: AK7set+I4pJRklsniO4bIb9F5JsmmXbJnyucsWHWv8Gcq4NOTrgG603vO5mGR2pP4FkasqnfbzhYpQ== X-Received: by 2002:a17:90b:4d04:b0:230:81e9:ebb4 with SMTP id mw4-20020a17090b4d0400b0023081e9ebb4mr33650785pjb.10.1678707667093; Mon, 13 Mar 2023 04:41:07 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:06 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 06/16] perf kvm: Introduce histograms data structures Date: Mon, 13 Mar 2023 19:40:08 +0800 Message-Id: <20230313114018.543254-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044109_276001_6392657F X-CRM114-Status: GOOD ( 13.21 ) 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 e84f1cdcfe05..a53cebe519b3 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 Mon Mar 13 11:40: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: 13172333 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 6FE97C6FD19 for ; Mon, 13 Mar 2023 11:43: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=5y5oEQVKFbLVTsye6xdv3mZgAfUbatPDH3ykig8+Xq4=; b=R9Zxect55c4imj SV0HJun1X2Gs8ERFEVU13LZShlrjqGCRdrmyY8OnzRYvLrAV319LTRTv1rGKmC7dnzpYD1/HRtd/7 a6XW4oJ7geQO9rXo8kPMayy8bpPlp9So6L7vInWx762NVSqGVPOKxpRxxr1pGMx00jRtQN/1UQiut G5nQDkor4akWtXuuV7qcaHZ/J7nSUV7znw9CPELDddOSe0bM5kO4cW4dipU+2SdC/4vFz+dxAYSft IOKGHXH1CcF/tx+IgRRb7fLK/TbwTtdhzy56YTa1F/XK5cVrvoqKYPsFq7cDvzXMLtEORpHDbjTbk f1QZZl4cudqJn27LbF+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgZU-005Sji-4f; Mon, 13 Mar 2023 11:42:32 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYE-005S8O-IO for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:16 +0000 Received: by mail-pl1-x635.google.com with SMTP id k2so4706888pll.8 for ; Mon, 13 Mar 2023 04:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707671; 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=S4r7hqotk6HS7rVbQXptLHHawPHLQynLpKGSY1VkolIE/P7FIMKBjLWIAuTMlYpreq OpQKBFi5ELO1PnYucscKkPnLEjMjjcEWnPEzYU7ytndE+WEUtal3s+Vuq+qmhfyhr7Hn w8q8zJL17SnHalrey6tGzfGbCBMsG1MI2S99ksy/jyXPRhaaJlb87m9yXuhMNT6GSMIT zh/2h+0qkJiMZcpqK//u3Zbg92xNu8jgOUWSZK78rUOkIYSv4hugoVxwXf2DON74U4A/ ge5qgcoBGN+29Sybdw5CrYfFGmz+88pNqkrDFDSr6nKTlZ2yWvkgO4IbbVQHK0strO+l LQyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707671; 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=7w9VRyt+nXm0qW1m3S2rZlDFJYsI5HI3QcJ0JmGhdx+zOMzA6M2DABYaM4z3HLUXTT TXl/RLiU9eWqTDCjSE+/DQBelt3sZrCBIKu/USV9wIICxrg+sGeQY1Aug/ui/QlHSm3o YeGwhxVwn//n6467fV/97vTpGP45fI8tLVbFEJ/Zu/W5EjkcPb1uVKbPI0wchbe/oaMV l/pkGWIg2QJ9gC+MNaHZ2JqQDVErFpAqhhlv4n9yCdaOLrQzWLHiLUh3lGpiybnmS31B vI+fZXhpI6AGCRfCoyvHFqrglKL9omD4XGG+g7EuNQ/4g9mPAQQubcuyujOnWMDCad3d JlhQ== X-Gm-Message-State: AO0yUKU5EnCiz8DlCiff1noeHe6zzFgDHZ7Sij5vxZGCX5GQrjqnPmwV VbpMdL3iywES+MfbF0620XoDed4vX5xb8xsYS7HSgJe4 X-Google-Smtp-Source: AK7set8RVASXZ6HtexSO7pgR6L/6ygL9d+NKSaVenQUGjJww7nIV0uWTsEiwzQuPe6liL3MbQoj4Tw== X-Received: by 2002:a17:90a:728d:b0:23b:4f2a:8026 with SMTP id e13-20020a17090a728d00b0023b4f2a8026mr4863481pjg.48.1678707671340; Mon, 13 Mar 2023 04:41:11 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:11 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 07/16] perf kvm: Pass argument 'sample' to kvm_alloc_init_event() Date: Mon, 13 Mar 2023 19:40:09 +0800 Message-Id: <20230313114018.543254-8-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044114_657808_A8E555CD X-CRM114-Status: GOOD ( 14.65 ) 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 Mon Mar 13 11:40: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: 13172334 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 B2A12C6FD1C for ; Mon, 13 Mar 2023 11:44: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=etpOCviRyBhr9hexN0aPR4/vjWs52hlEQu8kDLEAeYE=; b=ByzhY1DgK21Ctx 8C0cDG214ouhfLaeWpS4J0ludNY1t133xelUwZVCtnsI9bEz9qntntEF862HZENnXu7EuJbNJr+2N 4HHerezkOjab5SN9tApfQRm2KZKxKvbtofT5w3SgEm1vYTDCQkrhB42xUg4n65Zj6+uF8f+FhDz3P ob+sa0f569p7hqLfdIP4o5lnwLnBClgXkr4tdOZp/PRyY0ROkN2+WzSh8gXYpELfm3hLSxMkdjSDr uaQJhRduCazx6vcBPf6vdqn0yB7h6FduficZbdKwPR2tiXaP5dfimft7lK5G7VsucAxaVlp9zGrmf TKJnHeIdxls3N9wY64cg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgZv-005T1b-Uo; Mon, 13 Mar 2023 11:43:05 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYG-005SA6-4t for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:18 +0000 Received: by mail-pl1-x631.google.com with SMTP id i5so12603059pla.2 for ; Mon, 13 Mar 2023 04:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707675; 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=ygfxx0XS0Skh5yEpdT4mJzv/3MvrNT373bzz9DkGUB4=; b=Wx+waaKfMUU6sOzzAcpMsIz/5BgPy51Sblvw1oxRbHogJwZiGABhiwdqf6tgtxoeoz 5oLuApkLypxZxAgAxFFdYLgGGYrQ1oxxygX8eLckC+tNwe3Lvmr2hCowAnbpyb9GNbKm QvDKXioBA7ru6YXqZwqdYfvJiDCmS9SpsKYfkuO8tOfP25d8qeV3edxXdljXuEqXg6TQ O0Z2T6EvHYY/utz6arVSdDaDdJmg8/At3PxKKCDTA70ongM5sI/D4cLdE0498R74b4Ps jnATtrCs+a5HB49xL9Vwdt2CaQP0OnVDyXwEFu/AEMLqiLAqQirFqrhQ/TmV7E0M8OXx n+Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707675; 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=ygfxx0XS0Skh5yEpdT4mJzv/3MvrNT373bzz9DkGUB4=; b=GeDEqUL8Bu/5fic5mc7VaxuCC7vinLLpBRknxUh6GfHgzYQNdkDi0V6CsqOoToDH2y yGDPYGfTlZUKE5w80uvT6wGUApZmfJs9BBcPAICX52BLRemhV4BtirKXCYA+SlhxZIaa LlOts2G9BTixC6LIVMyz5WkVRl0AT0z81cj6UPzQca5lN7tt96QbDq+tjtZTDu/2m20o 2THQbURSGzqXnYxo3EK5vJ5xCN2kMhPvuDZW2JfQOxO4ga7Y/O7F8CJ50tHdIjHQu3Me aWUEQTaM6+wyJoHDOO9e7N440xbiShPUnTTOdiJnmgRLxv8Zmp8TPfTVUKbl298z4Q7r vLKQ== X-Gm-Message-State: AO0yUKXq7cyAo4PL6189r182pDNeR0Irs6w96+pwSEkzu56iWYnlMdZl JfYCvfOrmwdrkSAvw++BN2zOeg== X-Google-Smtp-Source: AK7set/Dozj1HoRO5RN3CbjTkCs7qKoMXvP2jNYP2m6mHopQoT7G2BMN6DBnf4OsRGhIq6GidEqVoA== X-Received: by 2002:a17:90a:3ea3:b0:23b:4614:6f84 with SMTP id k32-20020a17090a3ea300b0023b46146f84mr6304138pjc.28.1678707675655; Mon, 13 Mar 2023 04:41:15 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41: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 v4 08/16] perf kvm: Parse address location for samples Date: Mon, 13 Mar 2023 19:40:10 +0800 Message-Id: <20230313114018.543254-9-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044116_209088_B51860EA X-CRM114-Status: GOOD ( 14.89 ) 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 a53cebe519b3..2d791b04379a 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 Mon Mar 13 11:40: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: 13172335 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 EE68EC61DA4 for ; Mon, 13 Mar 2023 11:44:34 +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=ISpJLITCkkEQJSwBxvliw7GBn7rosgEzTIgiA9jHAtg=; b=2MgkEy1fIEvE6J v8LnALtZ0l0jiP98qy8ZwjnN27Mw/u4mnPmcdZFC7LMXxqFFpEdYJJuwA/1VDRZSWz5/oc7oMsb6y AZwMv/syquT95qL9xjkYmEyNb0EaGQBVMJgFKeGVDkAUYlHc7QHfLycIkEYXBFAX9pif+kfpGc0xy byqR+di26qCay0AfsmZ4nUbooljT2XYL9FwR5lTABQcFxjqzpvoMLxf3dQlW/+bt2KXeAn0W22EIQ 7/AONTOShyDaUyOFpc9iE68eaHalIYJwAXqcp/9m0pd451qELY/bM92eqi5G7AifoxQ8C6ovoG1CY ndRZN3jbFWkjotNEEgRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgaO-005TFj-V2; Mon, 13 Mar 2023 11:43:29 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYM-005SBn-By for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:24 +0000 Received: by mail-pj1-x1032.google.com with SMTP id rj10so1127231pjb.4 for ; Mon, 13 Mar 2023 04:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707680; 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=5MNnE3quOGvdDqG29dvywID+kT+Z2WHpLbe0kchj83s=; b=iHjA3HW8bxjICMYAwwBDMXriyMjyCoGNWZ/IveRUvJW4I6xPCm7LH5JpBJLKACCqtE 2oxp+1EWlDjdTKJ4/7d9ZN8D1toR6VnB+osaCLpwEqUe0DTvc3wYuVBYyEOQdZvtdiaC laxiGP4xy8G5J+LrjSJJrHZUUvj+MM7njQJQyNbHlbfC882XG6Lte6uXLiOoVK1QfVOT v/dOWRujYZN80ljZDW+MbMxBF6pj0uCLYwyh3TVCxnwaFkEB5r0+IYVIpxnYRWaep+4T cBAfNOMFs8o05/YvHuF8EICP5jVx55lYWeaCb0V/TlADMTa/ceQuk8iAGV5O9iFZuKFZ sumQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707680; 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=5MNnE3quOGvdDqG29dvywID+kT+Z2WHpLbe0kchj83s=; b=rIJcw6VWXsi3x9JI/uNshizth1dMF0e4KfJlTGarlSGNRTU6tB8gqfLpyVesNa7HP0 sw8fWx6jNvFy+cwf4AMz0tP+yq/NYu0i+n59qMgxhY4No3Kc17tA97hufQVaQ3Coe1eu Sq+EHNBQDaHIcAKnMCwRvc3FR03VwN3vUKxhoAttCMdDScxj8X7MdYjIwPsGORaQKgRZ feJiwX7hPevPEbgj8J2ARfD3/NDE5AM02d5ylKecDXmEbh2R4zSwxCq7CMyoP5JEZozQ HXg/OELItxIruyMhU6SluR9E13LS9fec06iboO7IkOONTKitJrKBhnUXJwl1m8X1+nNf heSQ== X-Gm-Message-State: AO0yUKVCyV6iZdwO8Ve7P4fYW4ymJxfCCBYFU1yr/HXxmmsN/zkepv8a XWTdcsr/kk0jTS2rJRY5IpyYXw== X-Google-Smtp-Source: AK7set9qrpXHCAgUfFwP2EzkBC5cR7tRC1nhrOapmqeyF1RayxLJTVQq/lkK4gReOoRBRAcZUst1tA== X-Received: by 2002:a17:90b:33ce:b0:234:5eb:2177 with SMTP id lk14-20020a17090b33ce00b0023405eb2177mr36787199pjb.9.1678707680030; Mon, 13 Mar 2023 04:41:20 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:19 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 09/16] perf hist: Add 'kvm_info' field in histograms entry Date: Mon, 13 Mar 2023 19:40:11 +0800 Message-Id: <20230313114018.543254-10-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044122_640321_83DE3592 X-CRM114-Status: GOOD ( 20.87 ) 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 2d791b04379a..43dd6472fa50 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 Mon Mar 13 11:40: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: 13172336 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 DF540C61DA4 for ; Mon, 13 Mar 2023 11:45:20 +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=QwuqE13rLl3l4mlQ8wmujPQejkXMZpYnK0qCQOjg1BI=; b=orG8rJ1pQ6arkI GjLBzMEdGzmWE8G8+ozRvBBQwv/u1Bs+oSlaCJYQJiaN2fLNCeqgT+JvPAfoODg+OUV72kUzqVA9C u02ht1pk0Blgxxi2yk8zFM3tlmQDSKsOOCtWTp5dwD8R38lHzpzhhVM8iIt300V709cgWOMku+zLD zml7segbvtsdI4SmoKx+f6YrlIkhzDqPCnTNVSL4WHqeijA5072jKHhDwucgaNqWWKet0PyH66ZU2 WtgrHiMZkpMji/yfl65g0nOEh4PjY75OIztZ9u/0qMfzluSsS5XUdGdfoltilU26XjQXCbEO2D15g Qv5CFkT1Q3W/gKojoePA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgb3-005Tae-KZ; Mon, 13 Mar 2023 11:44:09 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYR-005SDo-Nh for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:35 +0000 Received: by mail-pj1-x102e.google.com with SMTP id h12-20020a17090aea8c00b0023d1311fab3so1805937pjz.1 for ; Mon, 13 Mar 2023 04:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707684; 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=a36C9sWQdmAM0bfeAU4tZKbhIdnBMA6DO8wWZqH9jAY=; b=th6rpjZHiwhNM8zVk01MyOEseFNhcY5FryX2AZq3DGrEwlliqdvaWb1mec2Zm5ksVL 9uRDP/fujDSq3eD+YpSwOvSRP1rNnwlpDir00g2oOC5BJoBI6L6hiiOe2a/CNL7l+Q2A Q2SA97oYXx4OEBVz3AxsbUm/7zm/YJslEk3qGX04jMpc8FfRMTpo7kvTKHgsUlX68r7m /NmuTXCLFKSCdXfNYQz2VQtpm8azTBGhDRbArWQ1NKh0DJ9Z7YcEnV40Da3CdCCGIYBq QGcDmpZpInLt8EcZbveyBqFAA05UaAO4tVzobifseXX0alaiJiQIn2FfmEOglPb0xBZj 5y1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707684; 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=a36C9sWQdmAM0bfeAU4tZKbhIdnBMA6DO8wWZqH9jAY=; b=BrDiJPT7kYL+yNVgU+I0Uoq/HMAaDcDEBTrh/ejC0/zfz3RHgTYDimpCXXufEOTWwx 6tzzuRNnz+MKi/D0tLiveJaGuLnIu301Bql/MS8ZIR8UN7Vo1NEA0LradsOAtMStLulj ZT1P+1RStZiPBC+Nv3qqWWVrwfZ+15e6AnYP0Iuxa1RysPWLSjkl7vB6v5ZCEzm2p5M0 2F594O7qkl6m//yYrtvIQjhZqPMFfmKfWolr4GmtHNu6AiJkNrTP2hyCz2jrMJaJZ/oF UQvaU/XKmzwDyz34c2RyTbTa0dpdm8UIMRPUg7cHi25ZGGsXqR2EfQkcDyjryRcfsaPi 5p1Q== X-Gm-Message-State: AO0yUKUyQp85aVCYAtwhpFjbn0YFG57R7YiYaSsp2pRIsRMRr7N+JZWX E7X5D9uD5rkQI59dD17lFpVboA== X-Google-Smtp-Source: AK7set9xF+IXUey4HQTJ4NCVoXc/hwOZveLt76erFo4yaAmaGteB23Q0XeqUV3IpEWmrlpIbBkyPCg== X-Received: by 2002:a17:90a:de94:b0:234:881b:2e8b with SMTP id n20-20020a17090ade9400b00234881b2e8bmr34804987pjv.49.1678707684517; Mon, 13 Mar 2023 04:41:24 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:24 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 10/16] perf kvm: Add dimensions for KVM event statistics Date: Mon, 13 Mar 2023 19:40:12 +0800 Message-Id: <20230313114018.543254-11-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044133_639549_2BEF3D42 X-CRM114-Status: GOOD ( 21.40 ) 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 43dd6472fa50..92da2fb87380 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 int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); From patchwork Mon Mar 13 11:40:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13172340 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 51B6EC6FD19 for ; Mon, 13 Mar 2023 11:47:41 +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=5FWc4ExuI+VM6VV0D6/3ttBu2rfhtSJA4O4qGdctZ2k=; b=oXgWsAvxDNg80b Vvj+okgldMWypEy2XsZcC2qpfXhgZbNR8XBVSZdaX5GtFdv2Yqhr4DwLJJh3I7ab1VEH/DgWddv8f md9nkq/0FknUbYYBteleVZ7378Evmgwy8bXgbtBSuefV/hM8EhZm1sn4S4reNVsKuNxKY1aPsh2bo Cbfh0MH5c9fQe1uLTN9t8DLNA1HTCHDlTCougd74qYMuXQhyq/K/45XMU2Yt4mDdc+CRmAMHYEg1w bnARK5JSFjG0PibH9AW7BasKiIncPdJhmdWbntGRPNVsMSnmmGm4VeCONf1H6aV3HXCr2Zw9SfKM2 jfsiWq8LlbAZbzs9iypg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgd7-005Udj-Em; Mon, 13 Mar 2023 11:46:18 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYj-005SLe-N2 for linux-arm-kernel@bombadil.infradead.org; Mon, 13 Mar 2023 11:41:45 +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=LbWTiwsNLCzhmnfJIO7ZAOWJugOE9iyft/rP2uRGCC8=; b=gQbXV8c/CuFT7Je9U2npvAGgyF +AosIyat9blxoEY7FWxY5GcFjXaHTuFJzC7mLaqaJ1ytQ/+Sy2ILEQsf3f6TCWisl7mKQM/wCr5fA +haMD1CTObo/F98d9k+/UqS3MG1BTIoW1j/DYH+JTVVBzxFmIwb4AGFsFW3o556tcpsOyXZFcEhZG DTYQWlc386eXfG0SontKf7CfvVyd3rH2yEYlIqqnw3GMyyC4Fsfk0pOJrb1wo6iKTt2ublEsFg8y3 a219JsbO+tDBgYQuU04G7S397aBdrlN1d2rOenbP2vUMSXZR8WcxJi/aih+nEDH/2VGu890G47p42 lcJ58I+g==; Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pbgYb-001Kpk-1p for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:44 +0000 Received: by mail-pj1-x1033.google.com with SMTP id ce8-20020a17090aff0800b0023a61cff2c6so13054360pjb.0 for ; Mon, 13 Mar 2023 04:41:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707689; 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=LbWTiwsNLCzhmnfJIO7ZAOWJugOE9iyft/rP2uRGCC8=; b=nZ8i5WMS0zGdM96heslrKJUIiOb1D7ofUN3SjacWtXfTVuSHaMD9cIkbY/tUTbZfmh nrLHpWAfXQavr0jWc8kCwfpXwMFxJGdFcK2WBhjk3s3iN3EhOW0bjnL2lbkgAV/l3KYR AZ3DEM/B8cFHgDYR7SlLG+B+/R46eeqwiJ3rw89Zn63nX+bLW30xeJGgJYdHPC2G0Yxk usB13ToHqBp7Dmk9JoZETT7VjOuH/1TOA4isEi8PrNUy7QDgBrs9jOmAK8VHIGOG+Yzx ilf56Z++S3UpY997GBOfGN8CDRhWHlkuEAuJDmpX60BPmx+6Eur2+MRv2mIH6ntlrujG u/fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707689; 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=LbWTiwsNLCzhmnfJIO7ZAOWJugOE9iyft/rP2uRGCC8=; b=ntDpTBQaag0UdL0HN7iAyLDUUzcFHnm2qDq+jhnmFBndUoNovItQry6wN4lnVh3Blm 2ByGF/issqxFYNlqN6dOONPBogpS3FRExl4oJwbMQbYdOSCy5V7LH9K72PVxSU891TRz 79BtJFeg1tXjCasE+ifyTj2VtdGLJI2+cQLedGTRa6xIX4Qf/NRz1SGF2W9iGXOK9Zqh yRHHARA3c61eS3DaDIfm8cPTWX3tSHfOYMAth9XKechV14UeQd/WkP5tXsfA5lo5LhQ8 Kxdvm+QOI+NhxowUv/XeDHxbOePiyiOi6uHcBFQVotSDHp8qJpgktgRKQYM9emESdXUt 0c6w== X-Gm-Message-State: AO0yUKURd0iQACdTOXnjfBaz2pqZORe0OYSGLDig9PlWkta9dMqutqbQ pkWUjXbonHoEh373mLS5OYZF5A== X-Google-Smtp-Source: AK7set8WqNlf7dj/GMmV4Uw0lWZ5Rte24uCy7j8wI2Vo0/UwEBhQE3vjtSMKNpzD/MjfTmuR6vTWtg== X-Received: by 2002:a17:90a:dac3:b0:23b:446b:bbfe with SMTP id g3-20020a17090adac300b0023b446bbbfemr5713335pjx.10.1678707688565; Mon, 13 Mar 2023 04:41:28 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:28 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 11/16] perf kvm: Use histograms list to replace cached list Date: Mon, 13 Mar 2023 19:40:13 +0800 Message-Id: <20230313114018.543254-12-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_114138_356890_680F8542 X-CRM114-Status: GOOD ( 26.01 ) 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 92da2fb87380..4385be769eee 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 Mon Mar 13 11:40:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13172337 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 31498C6FD19 for ; Mon, 13 Mar 2023 11:45:43 +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=gENK9PfoK+KQmDDRZWwc9wUVkF8e8yv8bpNjRcEy/Do=; b=3L9slBwprIlQ5f pgXqfj95HShaVSIxxi0Hcq3Q8SktRJwTgSDj25XWf/qaHZfAtHu4xs5s47KBxYpRe5ACymDvGSNvq nMCHSSYMlVugiSP+4veTyV7ON6erhQR7ab+mylHztm9uCamjYOLcMOY8IqwkxXnsMr4DvCh5rCnNA y45vgwM/Bcp8mms0EmS5d6IKCBp+8wltx9C9GSW0Pek9tVlMJCKgoakq8fwJbKJOqt8rXI+Jit80A 60XtRElfo+OhsFyDE7A9bcrQKCBYmHxNFBIKqU4nlKa8M4uSMyfRyo14JgBQIIozt6t8NDSPl4RXR NT8NjYFgdeMDRJKuaAuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgbS-005ToG-S2; Mon, 13 Mar 2023 11:44:35 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYX-005SF4-NZ for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:37 +0000 Received: by mail-pl1-x62c.google.com with SMTP id x11so12562046pln.12 for ; Mon, 13 Mar 2023 04:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707693; 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=JgI7sIUXfEuJw5LLT6sg1Fr5x2zyVVOPMU2FeyfJj/s=; b=JSIqC98bHXd1HfroD6mo8qc6VuzWGpMiZiOthJxGbxLvgobrPsxvkG5EQWiZDRv19w 8a/xOu07TOj4EYGKthPFFnp2SbxDfE0fbj3bSEFRiSxL4P/fUXW9F+kDAMPDzWtT/bd2 SyjB158rjJK1DEIXNp+dd7yq+0P7jv0shgpYeDdvDZF9Nd8dGuuTZ6jkTa5/m6zh2Se0 uK2kxdbbp1G6x/0vfMELj8w9TzaykirdcTQ5RDv67S9/bX6Zu7e+MLWdq/txA1aLnFB0 r30Hwq9iMEbBMyK0a5eZwP+lTh0Vyr5MkZDlsVkuwX45BrDeM47pS5tdlHkWbtilq/v7 7BgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707693; 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=JgI7sIUXfEuJw5LLT6sg1Fr5x2zyVVOPMU2FeyfJj/s=; b=1wpRW73LVX+IW8vWnigTrZGGGkGYsOKHGhLY/3N1EF/njOMaFmpj61Y2YUcikfR7BQ QXGaW5/xj4s2jNTyM3IMi77iA78L0xOlt0m1GKlBDr/KoC7BRigXz6ADMmirWiybhf3G Qyd/NfdGU91LfvZCTVWHKCNixA9L9zLXj1FDQlGrC1lkWTH6bMlfkUZlMTiwW9GmIqmy EoX85qN/GdlTzbjYpluyuvkPdOiJaBOX5QIlTMVoZyVhk7tMH126qxf2abgQtOiIEr63 4tPeCraPEthVFoERcIpned2MVPese4Wl/xek88z1/WFMMXir9dRqfEgKDSJ9mvW5khIM 3Rgg== X-Gm-Message-State: AO0yUKXi8yZd1+sBAl0IvysCKAq1wVRS5fDXyFLXQtMQW3oraPcvPSfu SOylYADaNasOrujB8byGb9iELQ== X-Google-Smtp-Source: AK7set8lj7ygHJaxfEtsTufHlkoST0XAsShMw0uYRCqpWkwxzect/JSVGbVD3bocqyj/ONMhfjXT1Q== X-Received: by 2002:a17:90a:53:b0:234:d1c:f112 with SMTP id 19-20020a17090a005300b002340d1cf112mr35281110pjb.0.1678707692996; Mon, 13 Mar 2023 04:41:32 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41: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 v4 12/16] perf kvm: Polish sorting key Date: Mon, 13 Mar 2023 19:40:14 +0800 Message-Id: <20230313114018.543254-13-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044134_017174_49AD3029 X-CRM114-Status: GOOD ( 17.56 ) 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 4385be769eee..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 int (*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 Mon Mar 13 11:40:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13172338 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 76B0FC6FD19 for ; Mon, 13 Mar 2023 11:46:16 +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=C5u4XpDz0ADa+j 5VIbDrE4sUW7HmiXiC5usZWJr+5uuJ4IXq1miCshkR+olTcHjETzTuGXaTbxZNsuf8h+QzjtFBMK9 oy0o8nqFcJhxdQuTpumDP+FlGzwuebQ2Ra8+mIqwFloTBpCs9s3Cex/vK7QgoVxSKmSsa25m+F4p9 7re2Hu48OdGB/nvbYUYPjlwxKF72jI5WVDcnPQpvWPqpPH0SUQCGfUDwpZak8FQcduqdMfz4FdV++ ZNainfUicD0V90lFHlNiMW9Wkrh0dcCEX9K9YJGaE3pyKUHbcLZjWu0arCg+KJZJWAkRysjvpjXhL xihRTbaHlTU/C/vBD2Eg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgc4-005U5v-0i; Mon, 13 Mar 2023 11:45:13 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYc-005SI8-2Q for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:42 +0000 Received: by mail-pj1-x102b.google.com with SMTP id kb15so11711405pjb.1 for ; Mon, 13 Mar 2023 04:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707697; 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=HtcQ1Dsqji+5/51Jgddi4wmF19iXqpi5/q3y1S7vRBhkcO+9eiAHZNJgGKugNGFJe3 UkoD8p5470YfPpMcfbRLFm5bOStdn4VWkAeoMi+TZxn/D3t3pSicndN++cAPueo3Hvbz LKRjR1hcEmtJosnFX8Z4prmbcLX5cNAyfkDsR7ygVXxehulkCD7Izhd+0Ub0LgtdDHhJ tIsa7ldlKyyL/QRvQP9yDoAhy6IYqsHZVfLUCstKIRUlKliUeGbQ5JHl9ISaj+XJM3db rjZOjynBXF9AG20TqUhT3PFcYJ9T758CuiZQ5EC76W+4cbLkqpefNzrSaE8/0LOmdxJE hVbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707697; 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=6G2b8UKhriHnD5vkmkCrAedYADL0r8ohu4mRMWsiqfFmIrUaJHiEGq5JzmrCjTngST R9dIuaQ3LlVRXlAdUU0IprbuS7AQPzIrugoYpDqkaqddhN+oh2ZYWi5waXK2QzoesSmv QI1DRNuK5gZRl+7Eq/9273G8j5dSCr2r1Vydfcvp1C7nM7qHV7/ee6/u+6+Y+WtJxb3H CruGPluCtSnunWeIZeDtW9+g2d+/TrytTQhING2VtkyAkpiggpL85y3/+ejbmzZl5/S4 RgD32D2zfsuSKLPxJrKoDkYlT+QPulU+kCIh3F6s4sobHg/EDVbIyAeXLq6kEaiVIkEB kUng== X-Gm-Message-State: AO0yUKXdXl9aOd1ZWx5nAfV0g7e9yK8jcR/GA+msyTw0GmqY5LnWM27s D3YPy9Oyk4pl/a4ChAqE+9dBUg== X-Google-Smtp-Source: AK7set/BOeUqqeuViWC/Z5kQPNArKlQiD0EepwzcBVBkbMOYcfXI7afFPERJ2nJOxEjyUZWsVdxaSA== X-Received: by 2002:a17:90b:1d12:b0:234:e3f:f53b with SMTP id on18-20020a17090b1d1200b002340e3ff53bmr34768751pjb.21.1678707697421; Mon, 13 Mar 2023 04:41:37 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:37 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 13/16] perf kvm: Support printing attributions for dimensions Date: Mon, 13 Mar 2023 19:40:15 +0800 Message-Id: <20230313114018.543254-14-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044138_158071_79A1A45A X-CRM114-Status: GOOD ( 14.73 ) 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 Mon Mar 13 11:40:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13172339 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 E4C1CC6FD19 for ; Mon, 13 Mar 2023 11:46:44 +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=ifHuNMPoaGmSep vQtlCMnf57q8SAea+re/klV4fGpnIjmCWvlEUbiewzjblryHaHewKP1RJEWJRQXQoD0NJR8cF8TIe ITqoZ/ieQHy36JCM5wWgXv2BBItEeIGoDaanjVLyng1BUeo2VFk44Bd+fw5rd6VedO4pzic8ZFyD8 6jj964OfPeIvQEmdc9BesrY/7i6x5C+e+DD9+vDD71BGi8HjmuRQzVXgg70pTbVxS1l7DBHJ4fY8V dqXdyLLr13+XWsxjkZBWR9DyoeUbClWJ1P+WTlV8zixL6itSH/0vHn6iF/aQ7ArD8dpCR8yX36hYu 6x80+g8Wthy8fMBDuOXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgcW-005ULV-Af; Mon, 13 Mar 2023 11:45:41 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYg-005SK7-GM for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:44 +0000 Received: by mail-pl1-x630.google.com with SMTP id y11so12619028plg.1 for ; Mon, 13 Mar 2023 04:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707702; 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=pNiVNpQ25MN3oYBxt5/TM6uCwUc4SXP1Z4o4vh/+qLyntiFU4wcRaE6ohhV/RNqOW2 rHce4CMogEGfwLFpKWTQmXNWgcGLssUlmb0X/DKabDIagp5i2zz+Jdjidy5OC0XvprT2 PUnrmmSDm9cTgl7DCgzx/Me6o22O8ESkhhqpCoUaTz23F7oXPEujB7FZ7E5pfLPmMS8d pkohfPUjdUSS3Kb56DFZ8y/kaO8KXmAMWhKJW5tFCu+c9ws0jBh5YE8UuxjnkIgI9D8g egVm1EeGUu0qQ6ulKO5sksvYjDegOtWElEXfyuLiVgE5l33GDU59cQnj+z3mfo5QUqdu WhUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707702; 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=RzGPhULA/inbZqDZ2/DDUoApSLyBV9NxzNTMhTjhrYCiASLbstgJtShF2etVrqNN2+ T26uTByTj/BJPsSlx28m7c6wVfsW2dlKDRme+tXtKPvWSEek6cu3E7cn2SvrBgvFwIGf AOTNC1yVxk+duMaw2hmGomBhgfwvAdpjFHGZjoSzIXcGoL582RGzAD6qA5cCQyY7ICsb 3vJZAsfrxmq/q03Dw+b4Igm3cUBokFus5Jt8sKtf2vag37GJyX/+TG+NS0d1MdjASmLK FWtl2/uG2C/vjMasQfayNIiAGYtccx3p/8fqrYpGSypbSHQcK4edgB8BNz1Gvg7qmoX8 kbGQ== X-Gm-Message-State: AO0yUKUC3+z2WP6Yee5jMlL+BhEFrrbr0sGWwE4daeZaTBqbDh7Lz6xw rmNjN4o0mfVfXHVADiMBc1xsaw== X-Google-Smtp-Source: AK7set83wd4oHHArPR4ZCKuSZNrPw2lV7a4yfTBhkyt3/X3CHFU6GXj7CbeJUDTJqy3RCZTfnL321g== X-Received: by 2002:a17:90a:c7c3:b0:23b:4bf6:bbee with SMTP id gf3-20020a17090ac7c300b0023b4bf6bbeemr6415765pjb.21.1678707701711; Mon, 13 Mar 2023 04:41:41 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41: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 v4 14/16] perf kvm: Add dimensions for percentages Date: Mon, 13 Mar 2023 19:40:16 +0800 Message-Id: <20230313114018.543254-15-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044142_592649_0D0B6AA1 X-CRM114-Status: GOOD ( 14.13 ) 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 Mon Mar 13 11:40:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13172341 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 DF60EC61DA4 for ; Mon, 13 Mar 2023 11:48:28 +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=no7wFKyx11BFjB s5/5SbzISJ/RbTGppVL2gEU7fPaI+rRFsB1OsC1j33mLzzUeZdzX6S2hZc+6wCyPS5GZ3Wfh3QXpE 8J1W8R48sUF3BRWTyWfNJ+WhoFOo9CobG+4o/HdMI/ZJTADvkDuoNWc1FAgnzI6gJ+mlndahpOjfh XWXz1XieNZ1U0lUNetuXa2QowYn82vp+2JP/JAq6plrWo7D7MkOrsjxC+LoEJPfjzTEL9wOOmqLNV 7bTXtAoc7kB+VFTUGBy6NgFzlvDGrmjGjG7NHElD82zM+CssklO5dkKnuFaX3cj5yuuvi6cM0vquD fM3LdGrlS7UD1DEk+dqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbge5-005V6g-EW; Mon, 13 Mar 2023 11:47:18 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYm-005SMW-FJ for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:50 +0000 Received: by mail-pl1-x62a.google.com with SMTP id ix20so6081305plb.3 for ; Mon, 13 Mar 2023 04:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707706; 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=nx7x7sJa4vO1BZbZZBGq8aty9HkU1min3aeiiVvaQq9K/WZb1iYrPP6cZMgRoi0BSC MCGPxPk2OqlG0aD3oieBm6tQ4LTcebLcYiea0Po4kcBybtudYud3j0qvvTlGdw5QmFSt apXGeRgQ7OKmOWyAKKJXLQABCmttd50P8oiuxRfiFSOzkpa4SOIwdLLJQOwU8+jCah9R TYpzBYepRDAUb1oZiwRQN32eBjvXc/F2GvutMAJxJYBDceM1gGeHqm/3yGEQ6Jco8xHn 5aIW6RHLYCBJFhsJsqpZFSGDAZKMxsi/SqEMCVow3DEQpF2IYElj2xFYYFVY9/moWYUg sB7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707706; 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=3cxE3eMwvEhz3m0z4k7CYy1E1DzWk15lGIooWXsI5nWKGN7jVlYRZDIVgth43m39EK o3S8ZLppfBjcR5Og5p2VStQLnnEr/rdIo3Eoiz7HgyCZ5Qr3KZjBzC4IRIqIa0bR7gPe zM1kEvPZvOEmPxm9TDuPWECyR8OEDqlt4bJ9jx0260ACC3pFvgwgHZrzj85UREBQPrTE etZ8dymRKiFofqflY/6l+EgJ1KvgK7bHQ5WVDu+572NOPxMJ6EH/sRBOVEmtD+ZcbmJm RxSj3uDJx1fmeo3CbmUMdTjrsyOYYiIS/IouliR1Dy78kgnd5x4n8bXPmdZsjBQL33Zf dzQw== X-Gm-Message-State: AO0yUKVYowp+X2ucPScuD0fVG1V3olh4KdIQIumCZVIqEe+sXEBOBRnv 7NZDt6vjXYLimM5d0VzsP8jZww== X-Google-Smtp-Source: AK7set9/gbxblXwWYHW32OewJZrcp/QcEEM5ARA+uHA/hI74499fd6JnXCDnNkB8KpRvMOYYdJFQZg== X-Received: by 2002:a17:90a:3fce:b0:23b:33ef:7991 with SMTP id u14-20020a17090a3fce00b0023b33ef7991mr6439168pjm.49.1678707705816; Mon, 13 Mar 2023 04:41:45 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:45 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 15/16] perf kvm: Add TUI mode for stat report Date: Mon, 13 Mar 2023 19:40:17 +0800 Message-Id: <20230313114018.543254-16-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044148_558684_D8BED119 X-CRM114-Status: GOOD ( 21.20 ) 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 Mon Mar 13 11:40:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13172384 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 4D050C6FD19 for ; Mon, 13 Mar 2023 11:49:13 +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=LFAd4USsE/ryeS GfNnqPvMfiLtVeMevJVapGP8WHK+tmIDIxJrlVLY/Oc3mdtDJxQ5eM8bAvgpglzSYnwYufqG90TaP mwMi7dTS4W9uHH/oaFfV6jXzqb2P6ayVBHJKK5So4zHEIvyy9CaWxFrUEe6aJXn9V+TdO3t8OOENP gMRDDREAg7YcmLyADo6tTL+P5DWJZR45vN5xNoNMF75IIaiNnfXtNKnJnG8Fq/Qsz/rGbUCm4Qidc 4ofQxU1l5sweh3ZNaZrgtkKOEOUYqLhADhJF7028ObfTZqcM1NuT5UV25zVP9r3KJrJthnAq5WTv4 IOxWA0zCqh1X01O9eElA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgep-005VSy-Mw; Mon, 13 Mar 2023 11:48:05 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbgYq-005SOz-B0 for linux-arm-kernel@lists.infradead.org; Mon, 13 Mar 2023 11:41:54 +0000 Received: by mail-pj1-x1034.google.com with SMTP id y15-20020a17090aa40f00b00237ad8ee3a0so11374994pjp.2 for ; Mon, 13 Mar 2023 04:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707710; 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=PWzyhSH7DDp3iwYN3Te37MQ9JYhNVv0IyBMtCysoB+Q/lCmbMl9dUCChzy+LyzPolw JEtrqhXuoSgr4KHUHE7B1IiTCuDdGVmQubZtZPynd+U+gDWle9nRGhK+ZVYlkO1fDJTg aEKGg0F2n0NWcWtUdQhG1M2uUrb8BuempT554KwuimR0EdpziZhwy9RYCKcfxgDQORW1 D1DWKJ5r8vcJYeGGrz/RIPMmjMc0XDM/gas3njQjhj9cQQRREk5DevndMWvjgYJWLdA5 KeQsh13PJS7joZ+qEfa/baZHCx5ZBaL56qr5ATxHpKjDMUipZRf4tgQ0/+8KMReUtTvr BK7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707710; 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=5vxmeKyN6D2990hFYrzz7KH5GU5BWLEe6DKf79+7RZEAA744RDYsO7W4GzfeWS1hj7 VPVRGXoKHZQb4O3UNfLxBg/KSIdmk+uwiLHnE2TylFsLpAyf5zDL6ztnIHgORisC/e1f 4dV+n5EGUzOO5OQV3Wq8vUbslK1i9WWBIx6g5j0+VLdhO8aq7FL3V+bFnLYO8QmRy3JD 8wfi0T6sh5XiN5F7aIVHoDEXPX/CpWPiKHen5pwUw5afbQubnM6hbYrVPuqncS+ZqcCf hPMY9PyL7RnZfxjvAlnVib4wnFhICdoWm7CNtc8VmapE15Tj2FeAT7KNo4EGU2g+7hPd XWCA== X-Gm-Message-State: AO0yUKWvwzhRSwkGQJzFw9bc9iBUbvoVKihPkbNrZ2O8L+jel3CL+6Z3 FdapYT2PqalrTBdnvcRQmYS5Mg== X-Google-Smtp-Source: AK7set8ER/k+D4jtSDLuKMHuWPTPL48SSuXRYXmXmkyFS/46dYzVd9ITc/lT50214G26sg2nf9FORg== X-Received: by 2002:a17:90b:3c49:b0:233:e1e6:33d4 with SMTP id pm9-20020a17090b3c4900b00233e1e633d4mr35154950pjb.47.1678707710206; Mon, 13 Mar 2023 04:41:50 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41: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 v4 16/16] perf kvm: Update documentation to reflect new changes Date: Mon, 13 Mar 2023 19:40:18 +0800 Message-Id: <20230313114018.543254-17-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230313_044152_539840_2E1D8EDE X-CRM114-Status: GOOD ( 12.03 ) 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).