From patchwork Sun Feb 26 04:20:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1789529wrd; Sat, 25 Feb 2023 20:25:13 -0800 (PST) X-Google-Smtp-Source: AK7set/1m/3S9OOROV13t0T3MINQThYq0Bttv6HwK+wzjXXaRJ+Y6vSTBiAsgoosFroI2lChVdFi X-Received: by 2002:a17:902:dacf:b0:19c:13d2:44c1 with SMTP id q15-20020a170902dacf00b0019c13d244c1mr25813103plx.15.1677385513134; Sat, 25 Feb 2023 20:25:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385513; cv=none; d=google.com; s=arc-20160816; b=XXn9m58H319qkXz4dOxWUvfStwVRBqOc62bh/+FkAiJqejlU6KHD07jeeX/0wcInp9 bNL4FjpVE+tZhPN9wzqUiWaNQivVdIYn9ftOHVPyYcjqRZSU+HNeh9xkLhWCsC7BBsF/ z26sfqq23DB1BuiEDcs2enIUGDqZxRMWPziPHoUNOOeaAXjKf0ajGjdW/dwiE9t17e67 eQumDsUD4OME3VCfndLdGArxh9+eXZ0FHGNGkya8Wyty4YI2gQn4oxRI+hu3LO2uVOoF b0wTlKRP4Wc/4nUBnfSchkn1eNWzczxSWwJOggUgotChH4J98ddaaGgEXmPt6M4bk7eN 9DwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/6XdpHkz8A8bOxvOk1eGAORWD0fU8Q/VwNFknF3nlZE=; b=ljT7JPY3P+83cUwsIe8W4tadiEWideztXP72zD06UD9Dpt/2f7XPo6aPTc4VJapVb4 ttYBtXO/i8gwytY6MzEYjm3A8uFQpxjkGSTyvuJ9u6pilTfowEfWIIDGBAwSBp/SmjHc eDs2StIp+TMXcUCXjoj0I7aWjLvM+98T/R/4ZehbJHakvJ9+snl/txgLdu4mAHrICiYs Ejh3BD4cDhNF6XKn6GXbqs5CNa/glpKgL7eZiJdyIexpisQfsH92LFWwysk7ScH+l5o/ DURZVISnNKEmugJk8fKmA4L3kSVXqLJVPWZXcCcl24SiIwiDLiXJ2UptCvGgubXxQyHV dQiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oFoLR3Fi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020a170902d50a00b0019c9999f4dcsi3803474plg.230.2023.02.25.20.25.01; Sat, 25 Feb 2023 20:25:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oFoLR3Fi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229657AbjBZEVO (ORCPT + 99 others); Sat, 25 Feb 2023 23:21:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbjBZEVL (ORCPT ); Sat, 25 Feb 2023 23:21:11 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89155BDFD for ; Sat, 25 Feb 2023 20:21:10 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id i5so1843504pla.2 for ; Sat, 25 Feb 2023 20:21:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=/6XdpHkz8A8bOxvOk1eGAORWD0fU8Q/VwNFknF3nlZE=; b=oFoLR3FiLT+h5TvDFl1GMv2yCpurUwpbMglbpeM+aHbUkBo57SGlAj4ysITb90pRAD RJ3V9S1eBxSMEfVi/I8ve+chS48IInvz4zhBCxbkjhk8ePeevlcGnhvHL7H2qkgvfGn6 QOp+r2aLbM3gavUNPxXcV0yFWFpzC7632yZ5mcjdf4XgPapjcE/kFIO/pAFNYVQ/q+Fo qO6r1ooid1B+V8U0sm33s/nYeARnc+J2yWtxGa/ydAXudiqdHBjSN8Juwj5OohtDRMOU l47QGgZktZHueXcz4NmSS7ZJCan5UhNlTweSj1pBbKPuMRG9sYhGQlRL8ULigehujOwK sUXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=/6XdpHkz8A8bOxvOk1eGAORWD0fU8Q/VwNFknF3nlZE=; b=ugFOOF2zHq86tAw7q6jYfF6hFMZNiyyoYA8klBKMOs9jwG38Jp6lSPsAuu1Gaz9UgC 6L/cN9L3GWLeM3GSrd5fGglxbishniRJgbz9NOvhOHPteMKmMgG3urRVDVT4JYMUYDYx Ur4wJgxwCUfO5hquULmnCsmHYnr9e/MR37aEiGbhHzi+91aOIy5/fP055fJLdULXRZnl RKSSoIO8JZzYge+n6TXhJ/QxjCsxP8rJTKqqe/UCfjDesOcwgnuFgS/z0cSW6yv4Uzir hJ1dIaykc1Fdx2hvfnlB93ktbGwYJyp1NKi8W9HFdYQc6Il5kx3/3cdUZqRaLhK16lWO YqLQ== X-Gm-Message-State: AO0yUKU8T1tuxtnkfkaGWchHivjZ5dhZWhX5u2JRJ52NIONtbO44ujTV zoo2rVbKXUOr0y8DK1jC6HP91Q== X-Received: by 2002:a17:902:f903:b0:19d:7a4:4073 with SMTP id kw3-20020a170902f90300b0019d07a44073mr259328plb.59.1677385269877; Sat, 25 Feb 2023 20:21:09 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:09 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 01/14] perf kvm: Refactor overall statistics Date: Sun, 26 Feb 2023 12:20:40 +0800 Message-Id: <20230226042053.1492409-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866192081683540?= X-GMAIL-MSGID: =?utf-8?q?1758866192081683540?= 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 --- 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 Sun Feb 26 04:20:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61552 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1789721wrd; Sat, 25 Feb 2023 20:25:58 -0800 (PST) X-Google-Smtp-Source: AK7set+uSZ46kirKY7Atd0OgQXAKoyOIF8XYCs7QiXHa9gsswW6QZIpsM61J7WVMoZSjYSdFWvnF X-Received: by 2002:a05:6a21:32a9:b0:cc:70df:ae20 with SMTP id yt41-20020a056a2132a900b000cc70dfae20mr4558438pzb.0.1677385558014; Sat, 25 Feb 2023 20:25:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385557; cv=none; d=google.com; s=arc-20160816; b=P+iVIT4v1po5Z74ygj2jQVVoQIKiIV5xvQc/9UTCqxlVlU6AZ0cVVv+qR/1u54MVmu nByE6OcHAGJUqEcf3Gr1TY6M8lSdeibB0zwjYFUU4GGKKnMINBkEKo+fFQxx4sMxfVJ1 PKj0gV0UrHY6SfQVjz+ua3IErLgREuM6tVAJL0U9672lDnGqcJIevJzf5+PbmKf5766m KJjoDNADVUXNBPmnVeKShJd7zx8Xve310/R+Mu1bpK7IMZ5eb0EgX4BUFOh0WwGXW/vr 0k9cFnhS32UyQJ2iDJl8AG9h3MnvZwjc9LRzOyIR21KWHJkIyNmHFRrU637nXzksXr3g y36A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JpZ5nkw8exH6pwfmixa8Q7/xf5HABCQppgg+JZ7ONP0=; b=MB+YhWmNW2npTDnzNqnc33NCebgSppxw+Dx2Ze4vwqoctikbGFKTZYSyTQHYs5dh2e M9zH3LJMYE1P8OF+66bTqVdqf/CKv8aH++RKAh52LSfaVvnMsWbXtjaD/tNupI3C7k+j GaLdMNPm3gOBWWX5hO2RbMtOQBtiuj2cSspdK7YGUbz6rIkhbOj6bxJh5Oq2l3byLijs kw5f/5NnfAAWp0lQUGWPiT28Cd9+YX2J/MRiAn/HSG3uAaraHNaU0pC0zzwq8mfNQ3Pc FzSYxWREHHxuY1QLjECJasOHXdpbsxHk1W9LoI0q3J8iuChv3L3pYNuzkfBxlP39MN3D yEDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hK6xtK0P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k6-20020a63ff06000000b004fbb6560066si3380734pgi.57.2023.02.25.20.25.45; Sat, 25 Feb 2023 20:25:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hK6xtK0P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229745AbjBZEVT (ORCPT + 99 others); Sat, 25 Feb 2023 23:21:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbjBZEVP (ORCPT ); Sat, 25 Feb 2023 23:21:15 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36AAEC643 for ; Sat, 25 Feb 2023 20:21:14 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id kb15so2954300pjb.1 for ; Sat, 25 Feb 2023 20:21:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=JpZ5nkw8exH6pwfmixa8Q7/xf5HABCQppgg+JZ7ONP0=; b=hK6xtK0P+jdDy+P5lKMWHE4668MH19RL3AO3pqibo0WUV5zMY4MaoRrYR2uxTjfVjG Pha2OP+A0X8Q5sqoQZj0EpFZS9fKVPCzOJwI/6JUIebAngQCEd14aJ1u3yDpqzFO3CpG e1CoMW6O7S/jJrpkvCSxFbWz1Uyo8KBclfAVgSpD86+lOpoSVlFnXJF72E2UPwy5QVIm MCbqV/JrqyPCNZhGZkGcb77JK0UQ+JsgJfNPZex+AuUQgdnjY5sICBtSBsa7Av6vSZUn IfiT1+GVe79nfFRDw50GGsJGluI/FFYPUvvgEEv8/mVYpgd+/Jhm0AgNXJ2nzWJJjFSR /jDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=JpZ5nkw8exH6pwfmixa8Q7/xf5HABCQppgg+JZ7ONP0=; b=YVumJ8XTfNO5ElSzJ8vYHBev5DxpCnoz6HBM3ZbVcTjXc+ytCkXnWnIZVhkO4JwVuU tiShOv4alNSRSaLWR+LmPs0LasnSWHioVUgMPunckCFbIW5F8PwFGWh+JYPDSPEDCThB wiGUGTOKQIEqQmCLonfBK1D20Fu07oAHV2GjqiDd0QyvB0/RluYPIWHBkDVWOWn0RrZc 8aAtwqBF2bm1BLrNXXCPz0nxdAFMOEgrEc7czpOrJavq0q8aDkdCuXjaC+oo2673Dklw q0ynTLoaWyplrQYZfJG1vKpCTjLG8M87o+n5ctfDpYNOt/SOnB0zxpKvYIgVAedeJqU0 Ce2Q== X-Gm-Message-State: AO0yUKWaS95jRGvLgKWy2rRkXWkGk171h0PmNc7Wtb++gIxmJo3nvbjs Tww2nRAENvCxub+0Q1JSwns+OQ== X-Received: by 2002:a17:903:2347:b0:19b:64bb:d546 with SMTP id c7-20020a170903234700b0019b64bbd546mr4820182plh.18.1677385273638; Sat, 25 Feb 2023 20:21:13 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:13 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 02/14] perf kvm: Add pointer to 'perf_kvm_stat' in kvm event Date: Sun, 26 Feb 2023 12:20:41 +0800 Message-Id: <20230226042053.1492409-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866238347267106?= X-GMAIL-MSGID: =?utf-8?q?1758866238347267106?= 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 --- 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 Sun Feb 26 04:20:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1789579wrd; Sat, 25 Feb 2023 20:25:32 -0800 (PST) X-Google-Smtp-Source: AK7set+kzXAt0kfbaW82E5vT72xuIwQDcEK15jWNKgDmhRB3N3Dxz3PHDIDqTBkFpaSH4eZEv3CS X-Received: by 2002:a17:90a:194:b0:237:aab0:a539 with SMTP id 20-20020a17090a019400b00237aab0a539mr6370211pjc.41.1677385531693; Sat, 25 Feb 2023 20:25:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385531; cv=none; d=google.com; s=arc-20160816; b=YSfGoFj0pij5FtxfPN2Gzbp4XhV4BtoanCWiZJUI3vk9+jaHdYYO9Atjre30VZYZi5 a62wVaZbQpZOeYPdwDUU5XjFyVSF9+57byuyIsWZvgzjbt4LnQDWJszfgLgTp71Rwm4o nS/5wjwnLwGjvNQiL7njFQiRR8ufIC3g9FkjjpRI9nfINSJKvrvN8JDaH8pTeZcSTVCB UwxOyDj9fW1Aqr0tSFcuOQnCKRK3JE8kCdVCFKpMX+1eGeGYwgUyaf3lSJurA3L4Co+p 76CztrqtX35yLtBqyWwdB9ubujpUF0nAlWDL8lXnQ4q6B4Aia2n4nq/XhtlYxwQKo5Ok 3IUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fdGtU8CdVJ5aQaJfBI2DSk5cEkPEgW68Xd4/KtBW9/E=; b=SXvfCcpYSBf7MBaq7DzFf67t3OMrARlnNo4rx/JeIkYSVNM4ltVVy04e5d7W3n2ncm wDfFkQ9uqqXvs7QYgAqN5E5FYI4L3LpbXmHlVwa3YDNzusYrtNblu2INsby0xLgPRJ8E ibzHyKsftIXPcbe1kcHeBGwqpeFjBcqZFf1Nbah/63nlxbEfJ6zwN4oeYak9Vo+lVqzw SPKQOFpHeJiIEUFGlfps7A+QvluLqy9c5WehLjVbQ3T37IlLM6Izx4HRpPHZyyl1l59z 0mJwqNnn2+TwihfdGXm+TBvLqfKeS4d61HYzN3G+BYoMdRigccvu41+RvlBX125VVIpa y+cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VjxdWvAI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 1-20020a17090a018100b00233fe385e25si3812054pjc.6.2023.02.25.20.25.19; Sat, 25 Feb 2023 20:25:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VjxdWvAI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229783AbjBZEVr (ORCPT + 99 others); Sat, 25 Feb 2023 23:21:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229749AbjBZEVU (ORCPT ); Sat, 25 Feb 2023 23:21:20 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A271D506 for ; Sat, 25 Feb 2023 20:21:18 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id l1so2948340pjt.2 for ; Sat, 25 Feb 2023 20:21:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=fdGtU8CdVJ5aQaJfBI2DSk5cEkPEgW68Xd4/KtBW9/E=; b=VjxdWvAIfc1gAme/swteXdbpUmEZxEL6e7VSNv9Znpl+9QVpRe25OZxU3211okGiUW LG1A2ET4g/nr5TshBejSK1ExgS+BNGh1zHczpvQyYWZ07A9+n/8xRb2G084kmAU8OM9X OwKvNNwVhO5Nx+buk9mrduSPetSxVw0ZkaFWDECybAp+CXI0wSc13AyznTJXOkMCacyI 97Bycukn1Nexk7j7GOW1fKkC2XFfC8nRBXa1InSOya1MIQB1wbQdcTfcdn9aikk7tCBF WGgaGt+i/bwSY5YxdMZ11hPHRILFYLvBZXS/R6GDMAUvzQhdRTuo46iMHdovDnwh5APs 4FSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=fdGtU8CdVJ5aQaJfBI2DSk5cEkPEgW68Xd4/KtBW9/E=; b=sBmY7RJuu+hGbUm4tPXY2tvuj78AbHcKms0swpBMIanMHRjrOBHTLrQf7ENcnvccy1 lduPhy4OHn9EiXSPhx7LJFntMbzwx86cnQAf8lbEWxOrAQeV8aHGSXsCja8LKXAZ2SsK RKIaMNm9Hyor86036WZ52SQtwYOekLCH7bKyMUYdmtH/lZ16Lt/8GF+dygtzIc0ULHmn 26Qn2pWzwvk+qpaQklV6EahYZ2//oMOftVVYlc18bc+mTF2fauu+LqchGO0sEzxJLXNI kY0MDoOV36L46MLneLW5NgZpvn8xPBHztaMm2H6THqtWZnJ0lwqcIoma3D8qMxEVcPsZ jOHw== X-Gm-Message-State: AO0yUKX/JrJzNmlGEgzqdlVknWSwJUNrkh7jbaCOMc1tQ8/Yd/v11JJL mxvHebf7JtKgen3OIFtFKMT916drtkh5C7IhAZjNpw== X-Received: by 2002:a17:903:32cf:b0:19a:9686:ea8b with SMTP id i15-20020a17090332cf00b0019a9686ea8bmr23988286plr.28.1677385277500; Sat, 25 Feb 2023 20:21:17 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:17 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 03/14] perf kvm: Move up metrics helpers Date: Sun, 26 Feb 2023 12:20:42 +0800 Message-Id: <20230226042053.1492409-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866211087185862?= X-GMAIL-MSGID: =?utf-8?q?1758866211087185862?= 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 --- 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 Sun Feb 26 04:20:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1789660wrd; Sat, 25 Feb 2023 20:25:43 -0800 (PST) X-Google-Smtp-Source: AK7set9HR9Z0XBAFP9xidAm71tsP17Yf1/6OntteODntSUQTtS/cRPGrbhQcCEZws+o3JwDxzAgT X-Received: by 2002:a05:6a20:8f25:b0:be:b04d:1c29 with SMTP id b37-20020a056a208f2500b000beb04d1c29mr25377034pzk.5.1677385543037; Sat, 25 Feb 2023 20:25:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385543; cv=none; d=google.com; s=arc-20160816; b=kAkowbSkaJ5Ybf8sV0nF0HIVdhJu3/jUwTbJmVVF+E0c8xGWdIgSVsOazSRK92WRpg y4PNiRZYJJzyHoT17slGK2ugWvRATOcL5K83jycCEF437r9NfsstKAurYZFdqfQ4fwTW e0Qtk9rwBHO5WZONSI98YGqzfE8tq6UXh7pvR+MIoWu9EBVWOIV6aMm7n6H38hrtCZFx xS9lxiG7uqW1/VwBsN+m85TSwdeSftRusXnd405auhCvDVfoprLPu88VSqYI0xqay6Py ywKHq6WQCS5tXEHqo/DdvEfYht0VQnioTUf8ZlHs6y28TNR6zb2lCadi/OVSsYbYxnJD axPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aIt7hyoJVmNy/7vg+PJWYd0GZkeRWV7lG6iYd+8Wqps=; b=govrxS7r1MzE1Q5calnyPHi6brgvkYR4k7pP3kJLflnAcxgt3eIYLic5s291YiKfOT orsH9TL8XNGcQJPWTH733ehi9S7XbruUVgQZz+qFCbbLXtVSQHzAsBJLwopsnCKrVsB/ M9g25DQ5wan0ca5XQ8Lx+Wa8KAUD8d7QJ5/53ho0gjiyAZ0lkxRLmHk+QKShR5p+Di90 bEo03olSNA5luJ4pKDbWSkGvA2fmE0qBUeJcoGW7RkuMVXyTQHPIG0t4QalaQBNDO+0x w56xPP2i9nFvt69vR+N3iYJAkgOPk//qcpV4eO7HsCMD5XiooXSUmjcFbz2oX0TBgBD9 /V3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QLCZOXZA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w7-20020a63c107000000b00502e7d84884si3688424pgf.282.2023.02.25.20.25.30; Sat, 25 Feb 2023 20:25:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QLCZOXZA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbjBZEVw (ORCPT + 99 others); Sat, 25 Feb 2023 23:21:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229801AbjBZEVY (ORCPT ); Sat, 25 Feb 2023 23:21:24 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBDEACA04 for ; Sat, 25 Feb 2023 20:21:21 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id ky4so3555044plb.3 for ; Sat, 25 Feb 2023 20:21:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=aIt7hyoJVmNy/7vg+PJWYd0GZkeRWV7lG6iYd+8Wqps=; b=QLCZOXZA8bJOvg/e431jWcUuatC2M0BATcQlATzrxK/OSsLRVFfdDyj1Eeien+oMt9 6/+coTMUrO1gUQZbBlgoa1XDp/TxsSqW1AMGKb1+24q8M7IC43f8GITQ1D0PeK4ZGkTm vBjiMeFkdDt0DSZOzhHfzpehFxRRM+3xlsXQcS4n1gmM0YHTbu7geqhO20FWcfuzt6ed b1RjfsSpBz4ZerZq5To3SCcuJCDyuz87hWAedKW2Y0/HX7w7aLhz+/72RXBOWSVpP272 EYem2JG8n4ZCGTHUgNyZ1x/Eo93Ty9tepoF5PP47tIE4cdiE2x5cJ3dY36Pmeg5nmSIn 4+8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=aIt7hyoJVmNy/7vg+PJWYd0GZkeRWV7lG6iYd+8Wqps=; b=kqo4wydjqp+FutuaTSEzJHmH63yQJjrSqoeyuLHK6RzeF/nlybuSdw+09LQuTU5Ug3 u5oQRiLKHJ+SZ2DhaizTxju9/Ffn13uNWadgC4r0nsdyGUe8W5rNQ1UaVjvAzhL5ZLw4 0EnOIWAIE6d+VFgz8s1e9t94VmzSf1nwDveAdE3yXHY4oWCOYyHsHCfMhDtsjIm6Q0/w uevNEQEJZHgqAenTtISXcKX3R/5VcFLltKTz7xPMjK5KzZ19MkW/hbNTm5UmvnxA24ti KTIqldHrem3sA03ferkKPBjTFrn7MA6fgHUWv0l0WcXwAHb1daJEajBc9hXThJyAG7Nl KrXQ== X-Gm-Message-State: AO0yUKVEe5nUhM1qrDOaeZ9cckIKnHF6x3OQSrM2a0VXKxAcOep068UX ITUZNfGNxkxcWJ3+8hN6Vc0OmA== X-Received: by 2002:a17:902:db10:b0:19c:dbce:dce8 with SMTP id m16-20020a170902db1000b0019cdbcedce8mr6942908plx.15.1677385281289; Sat, 25 Feb 2023 20:21:21 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:20 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 04/14] perf kvm: Use subtraction for comparison metrics Date: Sun, 26 Feb 2023 12:20:43 +0800 Message-Id: <20230226042053.1492409-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866223130864719?= X-GMAIL-MSGID: =?utf-8?q?1758866223130864719?= 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. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 62c097a37da9..6eec0db2dda6 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -66,7 +66,7 @@ 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) > \ + 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 Sun Feb 26 04:20:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1789795wrd; Sat, 25 Feb 2023 20:26:15 -0800 (PST) X-Google-Smtp-Source: AK7set+vjNftLOVBtTL6lDHG5iEHOUIvzIcKDgjnLTjIqzXPEu27majZozxyAmHrB91GeV/kGF5m X-Received: by 2002:a17:902:e745:b0:19c:eaab:653d with SMTP id p5-20020a170902e74500b0019ceaab653dmr4637234plf.15.1677385574832; Sat, 25 Feb 2023 20:26:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385574; cv=none; d=google.com; s=arc-20160816; b=T7BYmhUCg2x/1igqLHjTKhxxq+vUjmgjRwyh4VMJdiJI9ZxOeQxr6A7xsE0nskvRiz 9Z01ycLF8+BAvSFF0UHr/PzCpuHjfCAH8YpkoXHezUQfX1oC7NsnRHGo4RK+4U7joT1J /W72PKCj8U3sDmB7Zw9hz1bEci/BCzKl9PCXu4x+AqFr6i6coAcHEBVsmzMl3gbBg5BK 6llov9Lj4alOtcEEniy+lgSnnVQs47Wlxb58cjqREzvYmOoQTgNrzewZECHdH4ReoTYD ZqGxeLK0gYGuJgtdE/kOXj5Xi2YSEI4lqTTPB7Pj6SWOsGhgcJZzBjYqXYwfI8GLy+AY iruQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JA7VJN/YcBA7IE+nNQeWn+LVdWT4KUb0IqvxyHZoo8o=; b=XcVcb5RuOPxZKXb/9xHWBcYyRICG7nNC/mRFNgfxsZU8yRg9iHPT/Z08R8l8R1kCIK dWdT8o4+bTJRV5Xpko1TBNMJN0iNfz4obVfdmNHcy6JSxdP6FJbKqvCobPxvIe3iUGIi mT7EguyDxnbwIl4yf/c1V1FSN2SENcqMBYWvgScPWzIp9K+tcLjygQkno+4OBzbHXjP0 efj4dE+yD8OXmwtH+LikdCBFZtmSakusX5S1u+ex/Jgcg3NCe7fH9irIgtDp0TeEDdgO hWbEQNc9FM6BB4oOCzNlycZisdEAuAOLxSP2JLVDiPebE2lLKljuslaqE0hMTj/lJwY7 YjqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yphIfzPv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kl11-20020a170903074b00b0019b64bbd53esi3457481plb.150.2023.02.25.20.26.02; Sat, 25 Feb 2023 20:26:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yphIfzPv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229796AbjBZEWS (ORCPT + 99 others); Sat, 25 Feb 2023 23:22:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229931AbjBZEVg (ORCPT ); Sat, 25 Feb 2023 23:21:36 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1835EB4A for ; Sat, 25 Feb 2023 20:21:25 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id z2so3504060plf.12 for ; Sat, 25 Feb 2023 20:21:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=JA7VJN/YcBA7IE+nNQeWn+LVdWT4KUb0IqvxyHZoo8o=; b=yphIfzPv05IfIc6/1JjUPJ2e4gRqh66jjIcuDpczDTonK4ArNDx4y+So9iG0FMtm+/ fwWtRRUmcMe1HVG0qrTS8NjNGGMnRU9KhkbxYie5RvfCuq7/FgRvvmaJzxwydmMkjVzu UnbD24ww//iKoNLFEDWeX4KsWPKo4L3T05BneHWWd5BqF+AWwutZPpmnBmKMHojrRPmB 3VFlySGh9zIo3/PNDaXbHTEjGeb1AlwlxtwACkBH6vGUKuLwkSlxdpN1B6TP/nsPqkyW qoWK9BoM5ZaMZggeuyCqYR+kDHIyZn/Z6sfAlqzH/yJfPDC6k7RYPGElCxaxc3g+dVXk GRhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=JA7VJN/YcBA7IE+nNQeWn+LVdWT4KUb0IqvxyHZoo8o=; b=PGfF+GIPCNwjw4e0RUZrlJUQsje5LYEAimE44YE2dfNpp5UttBf1ckYs3yr21VqQlI Ddyl6rXiNSIClmB+mBGlHSgbYfhkuGi+P7PJ3sD1A4gQrSoHaFNz7t4YLRv32v4LHT4j su+JeB/c8OmWD0DLtFEqmyPEJmD2Ev6TmHG4pHgbvlSmwrvkYKj/uJnjFFC8I62lzPg5 8WMxVLQzVVQY7jcK+M0s0k7E+OzDt7Hvf/csLwLztdUJkFfFK0U5GaAlpFiAnlYrq0TI 6SrZqTn/ln4xqzWO5FuyNBFR8B8W+GO98sk5QvjWJFKgE/W7OvvrpUGQm5sFMnmcbZKs 6YxQ== X-Gm-Message-State: AO0yUKXGIL1tNu6CnQl5ocuRPDT9FyyiJtj+1t2SsCBDhHYnl7vldmO3 SX83/ZLdupVC0MXTb1WGXdZTHA== X-Received: by 2002:a17:903:2283:b0:19a:ae30:3a42 with SMTP id b3-20020a170903228300b0019aae303a42mr5383543plh.21.1677385285179; Sat, 25 Feb 2023 20:21:25 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:24 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 05/14] perf kvm: Introduce histograms data structures Date: Sun, 26 Feb 2023 12:20:44 +0800 Message-Id: <20230226042053.1492409-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866256438790739?= X-GMAIL-MSGID: =?utf-8?q?1758866256438790739?= 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 --- 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 6eec0db2dda6..4ae54ba4fdaf 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 40a4b66cfee6..a3219829c448 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 Sun Feb 26 04:20:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1789926wrd; Sat, 25 Feb 2023 20:26:54 -0800 (PST) X-Google-Smtp-Source: AK7set9RIvepgkYWWFCpG/H3YsVu1JcP3FgD7/FxJRuQfoxUpWOCGEe+JOVNYr8yqydYe88ZtG8E X-Received: by 2002:a17:902:d2cc:b0:19a:8316:6b51 with SMTP id n12-20020a170902d2cc00b0019a83166b51mr24302903plc.4.1677385614020; Sat, 25 Feb 2023 20:26:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385614; cv=none; d=google.com; s=arc-20160816; b=VsqMixgeBpa65+C6agPdJOkoIFfdOEqwOXQMOKha05/lupp+//aQ40W8FNhA9MEb2N krFjMVOz7L6d28/kCNed/pAFAf4r4iH2JpKM8MFEZS/W9D8QZtFHbxS+snjNW/I58h1g 4kx47qLvfVZlBVR2fmIrYEKbxmOxZV8QvbSsc3v2OXDWuaom/EyLWy8H2Mu/u0IPI//q R60SrpNf+MpHaTvHYeQWP/99LT9lfdYoHWCR5bKju7/4l3b06KGuuJ6FCZ4EOdtjHKB7 MU2nKk25CG47i70J9iKlycOAV9eJyPHxvLTUKykjzh3wyGsyqNzg1V5cr/hcXe84xGNl BSLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=b0Hu2w1HCV6BLAJH+BUXhSI8OHGX3HrQUpTuSp+vt2M=; b=wIL7iO81R7jFii+ctgA2S7Hl+3/A6YNz7THJV8h9ebdmpSFTKeqL5qREYQj4VhAU8x Um0kxhkXOL3jQeLpaRBckYCwy3k4d/5Ep/mA2RMgVJWucX4kFqrRwh0ztwF0XBk9yHCa ecYRWT4UfZjdmQaEEI2KOQkZt2hXvDJPwdRcbhTl2oiJSBcr4zL+Pc48dHsXulHkrV+i 2+iTqXDqkemmEjYwmmaOxOxBZlSaY1vPFY7upFobmPlBqGtpdKSg9bwieg7wRYtBWtbO lJuj+7MD9bMvfIw4KVNs69w3RNwyW/sHVxEfCKMxca/RhHZgEnGuPn/L03aojTkyewS3 EZDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=du6tVr4c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kl11-20020a170903074b00b0019b64bbd53esi3457481plb.150.2023.02.25.20.26.41; Sat, 25 Feb 2023 20:26:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=du6tVr4c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbjBZEWV (ORCPT + 99 others); Sat, 25 Feb 2023 23:22:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbjBZEVm (ORCPT ); Sat, 25 Feb 2023 23:21:42 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABAD9E04C for ; Sat, 25 Feb 2023 20:21:29 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id p20so2316562plw.13 for ; Sat, 25 Feb 2023 20:21:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=b0Hu2w1HCV6BLAJH+BUXhSI8OHGX3HrQUpTuSp+vt2M=; b=du6tVr4cyHV9cIUuzZPA2mgvK3Yj70mmmSOE0beA5v6GpWHF6NBKXa19txUG3uYjcJ 3T6S0RTvBKqN3MDtZO/7rIekMG6UVd7VB3Usc4Po8lLhpX6c/apvcVfXKByrbjUBszaN GxFKZqElik0a9SnwiYGmbz+pHRrfeUidxxWp13LQJDxcda45mr22lCMMBoT8RMFvDBjV EDM50sA31l9H8keZyN3jRUNWMbN+Uxg/tlbq07lpYPvphyOG/g0RwFpvDSGK/8ydMSbC 7iVnPsOj6L7lGsqWvGEgJE2N7/8qD4bZ/Qny/CiI6+W9KcXtaVsz5akUq+lLSwSQ5p+v kJfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=b0Hu2w1HCV6BLAJH+BUXhSI8OHGX3HrQUpTuSp+vt2M=; b=MV7RB1VZAFISr53a4UxoYutB8OMidfTFdGQ4zBmwcAJRYFZxRV+crojYnraV5AuZlq BaUxwcW7ZVzPn5H2Mk40XnfLXUAzpxLWrBk+d1yicC9+i+b8pKx+4k60eNG+Z+RGdwYf UY0xkeXmLLdFHfOHxgIpdIpGxRmI16l6KJHkrJRCLDOgq/K238Ef6ybzth9g0wK9RBVS dBCcIqDoWQ4S/vI9eLBfFyCdo6dTtT7UArXt9qu4Tdozmo87T8xERAwv2hy2qwsPDdzp zob4MXz+1y3SF253o0g+LeFBjdojn1MVEs8ls9OJc+pGQq1fm6o6alDrBEvtIv3ikBBV EHGg== X-Gm-Message-State: AO0yUKUc3yuht4VCsZNpBqOnv4uMf7KqkepW4p6R32VF3oyBZT4TnAuV Uwj942nx0G3NZGzDZEMFQehigg== X-Received: by 2002:a17:902:d4c3:b0:19c:17d1:28a4 with SMTP id o3-20020a170902d4c300b0019c17d128a4mr25077299plg.67.1677385288941; Sat, 25 Feb 2023 20:21:28 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:28 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 06/14] perf kvm: Pass argument 'sample' to kvm_alloc_init_event() Date: Sun, 26 Feb 2023 12:20:45 +0800 Message-Id: <20230226042053.1492409-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866297566466233?= X-GMAIL-MSGID: =?utf-8?q?1758866297566466233?= 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 --- 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 4ae54ba4fdaf..779881901a05 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 Sun Feb 26 04:20:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1790179wrd; Sat, 25 Feb 2023 20:27:49 -0800 (PST) X-Google-Smtp-Source: AK7set/CmkC4RlbtVeNVQFBcmr4lUW+DhYi9kmG5jVQP9XwpiRyTV9KlfI8u+Z2NOjT7ootWVBJv X-Received: by 2002:a17:902:d4c4:b0:19c:d4c0:ce78 with SMTP id o4-20020a170902d4c400b0019cd4c0ce78mr5006608plg.29.1677385668891; Sat, 25 Feb 2023 20:27:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385668; cv=none; d=google.com; s=arc-20160816; b=wk9RlkkZE9c9ihUYU+vhhRZBcVbT1o3SQWpBbGMhNLDsx6OcaP7SmiOAfFljV3zHjp f1uSRhpmeClZ56w76R7PUvBlXDk7iGFNqmwtscLHf+IP261nmw55CkuVgvRugJMfzxRu sWwHFCnO6tmbxZjL+/8PyhtXnsr12HjWMie9yb2hFg237aBnticyaFeFtBEKK9TK1iSq DMzx35mdhVIeXouxyMJGmwsVEHpEUZqNoWskpxIbPq4CwCbk+tI9LsRysUpNyQn7u8zW MbproQeoTwjbYTWhMyFUy7A2tURyekQzCa5Y18AoVl1fx629qwaC8k6HssIwZmzkGmSz 22YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JCXvY3VOyromxWZSsh4iONVhiGPWxZ3OU8P5j9wqMDM=; b=oJjFLhRVuF+YZLZ96+uBlEpufN4L1N58hJ6EYRCO5NYJCXsfgipScuTVhVMtEP8AMY owP4AKVMp6gpDjQOlpfoqlyOqWqI+sMbsjsIUVdOURKZPtZb8GBhskPQF/CCy25fCQiF yzz+1bB/TUaV2ccbs2OS8xcDcQDQmhbEBDZqnDaWhPvBYJQkwlVkZ9xLXrj57Lp1096W np4FzP3A91wP2ZwViUm9GX8/jT+yMRCziWnnay0xIEdehkJJKlPOe9xXqjqVWuVYxRje k9FodaF+A1IonuS2iajAX0tyfuI4nRbz78k6FjXozVZpjW9OABrXRXEMWW29fqKbmsEu pl1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DaNxzuvh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kl11-20020a170903074b00b0019b64bbd53esi3457481plb.150.2023.02.25.20.27.36; Sat, 25 Feb 2023 20:27:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DaNxzuvh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbjBZEW2 (ORCPT + 99 others); Sat, 25 Feb 2023 23:22:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbjBZEVu (ORCPT ); Sat, 25 Feb 2023 23:21:50 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70C75D33C for ; Sat, 25 Feb 2023 20:21:33 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id h8so232803plf.10 for ; Sat, 25 Feb 2023 20:21:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=JCXvY3VOyromxWZSsh4iONVhiGPWxZ3OU8P5j9wqMDM=; b=DaNxzuvhNXQ4wLJCYxYJ+wm5GTMCmnmX7mKLaXKDpQ/55+I+7Uan/JFCiCyRt25vc9 wN0dRrC09xps5a0nKV6Yxww+EuFZuq178G7Eh/kj7U2GBoZTCFQ4U9iuyb/hWEq0VizP 5CFx+8zCFmcfZhizaPIS5ChS8G2rbUatvmxq2er3inqcRB6kb18KJKz6+2ISDgouLrZD SjNrXh2mP0TXtK15gpllKaDJaTfA3CNou4LYFtAmygJODh8aA9QTsY1GlW7+43DOQhr9 6b3B08uFMqKIMnVa4VUL4blCAutgcB8gqWd23/bLXyLGSAlyABo0wNOFcgHpRsq8j+o3 blPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=JCXvY3VOyromxWZSsh4iONVhiGPWxZ3OU8P5j9wqMDM=; b=DpDk6x79jq6PXEmsY1Ojj5pLwYYJuEQytFW7C7Emj/pc+GdybXKqLM4uRD0aXIFMhD nEem6uASAo6eEAOPpILePwTtXz4+HCtwcBM+WRsfGqVKWaQhsuJhPIjPpqy1DSeRXosl cgtXvJAAoMtEUpKazo+aDfmwWZgb9Z85+HieWkMDm8KxWuFgF5wMOyl2cj9m/7S08JEQ 6PiGOdwxm9nj5XAUllIoDH7QGDggvV9rDExd1xDLdhHiGXjUhZhK+59u6PkHQBcANBp4 NWtmvL6cq24KLtjG3v9CpOZUrIJ7QePnnQVFV1sMTWBhAh5OR2PtfIkZUdc6aQjtPsaR boTg== X-Gm-Message-State: AO0yUKWzyD7xB2IMHSY7O4gbhGzZLtmoQVYcBuHcRt9iqFuy56v7lwuQ EBekI7weVajn7GRfmuCm1td4lw== X-Received: by 2002:a17:903:2347:b0:19a:9859:be26 with SMTP id c7-20020a170903234700b0019a9859be26mr4289506plh.22.1677385292839; Sat, 25 Feb 2023 20:21:32 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:32 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 07/14] perf kvm: Parse address location for samples Date: Sun, 26 Feb 2023 12:20:46 +0800 Message-Id: <20230226042053.1492409-8-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866355375481451?= X-GMAIL-MSGID: =?utf-8?q?1758866355375481451?= 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 --- 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 779881901a05..a9f467926bdd 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 a3219829c448..80d5c5a9ae31 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" struct evsel; @@ -86,6 +87,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 Sun Feb 26 04:20:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61556 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1790312wrd; Sat, 25 Feb 2023 20:28:17 -0800 (PST) X-Google-Smtp-Source: AK7set/10ImaGzKQapiVLTMia2A/SZ3puzsVOWIuYJB/kE7d1/B/FEIKQHmh3xs/dN0s7Lf7hkmE X-Received: by 2002:a17:906:f14e:b0:8f0:143d:fa4b with SMTP id gw14-20020a170906f14e00b008f0143dfa4bmr10416300ejb.7.1677385697373; Sat, 25 Feb 2023 20:28:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385697; cv=none; d=google.com; s=arc-20160816; b=JIo3comDdktoAXzw0Ljg3AQGSpkql/Nd8yB74SmVSYleHYtQnIcN9+VHTxI8PXV0+K M1UKZdphDXfPntQOSld9KrRv6uLrgCQzZP2r7b3bcooW4ubol/syYaEPQRBNBebBEfG3 3l9o40oeyFRLwJyo7MJ6G+9nA6uXp80dZ1k/1FFdJmpejohYCFsjYqtWTWTTOP0MvLoq aT1SINwHi6EOeMscfhcF9hXyD7WeaRw/E57Vjr/k5fqjCek5Ao8sUljCbaogYT1YWPxA zikmaxobNRXfV7OKMbD6BLe3sPis8Zdb4th4k7xFTmRCN66g9/vX4Xd2LFhKzKxY1y44 IRYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dkGLzxiRgSOZTh04Z+2xATChlICYHMpA+J8qmtvpz8Q=; b=a+MxkhQIalBLSTR04b0DnD0AOPBMiRzW/OPAHIjcxrvFafpolFQMJ/PY9rJln2PMqG g4E53tsI0Lb8GvyUF5DFJPw0S2vZjesf72X5osQNjlZcbaluj4t9FZ+O8SJhC1xeuh91 fLWohmZQZPDUlVxfX+kzV2JWD762psnM0c2W0VHLJ/l507jhKMvzS0K0O8eTCzwfW6qt qBnSh0MaY3zUbxz3GqstLdbYkZruCf87sW5LxAoC84uJonx2rnxx1jzwpDTkudOqfriN 2D1r9ugPhejgiq2nVkej2VWT5IsK8FB5jreIIvyfvKflGtWPxku027sTtiwoY2ST4AAc odjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gx+ufAE8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020a056402064300b004acc3c0cff8si4516493edx.398.2023.02.25.20.27.54; Sat, 25 Feb 2023 20:28:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gx+ufAE8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229777AbjBZEWc (ORCPT + 99 others); Sat, 25 Feb 2023 23:22:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbjBZEVz (ORCPT ); Sat, 25 Feb 2023 23:21:55 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A869F746 for ; Sat, 25 Feb 2023 20:21:37 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id kb15so2954651pjb.1 for ; Sat, 25 Feb 2023 20:21:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=dkGLzxiRgSOZTh04Z+2xATChlICYHMpA+J8qmtvpz8Q=; b=Gx+ufAE8jtAIOrUrcwqcWqNzeaceHXeJlSzjgx87+Bne7Il2nH/9IukXpJKr1GGC8M sSfXXu93Tun7DMhxRDh+M67NQnJK1QOf7jI2OZ1ZgeSO+CURNv/nUGhkoOLsfotB8syl kajZawm/ayOyRSkagX7Dm1S56bBUVGA43NhHTpWkWAy7K0x+l4WLDkrYDl2U8EKIBevT 3bS5uIBnpqmm3bKmvSma19iMULRzixS2Z4ClfHuNBkY2rw5bLYyAsunMLPYZUfYjqqr1 IXf29fJh3O+7bpzUA6ah1Zpxwk/1GErFRcMUSCW1KVInRxbGRolSukXn/qA5ypq35j6Q Mkfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=dkGLzxiRgSOZTh04Z+2xATChlICYHMpA+J8qmtvpz8Q=; b=eq8lTZm8BDinJZGS+jWJWBOojJft8xgItjIMg7GrZOzxjqfiW8DpKDttDbLMCYnXW6 K0TrpL9baduXTffwN7oVDUHqAOcsex/NatR1p77PIWtqckOMY26KY2fQTD7ZCiASRnTu v5DOtOS62kKPcnpJZz739nbg3Ni1zFHi228U8+mG9AVkvqF3AMVAP85CygcxBiRiWLYe XWnnQvG6sBMHVVk9b4N5sysYJi81SKkVojX+OoEA5SkP4bnWE7JXbqS37eHqsXKpJy/E pEcWODFp33PVZhh911oUJQiy5w0Znzrbb2AhlE5UUappPMYkXav4hLEo+jV3iFKxjKlr 463Q== X-Gm-Message-State: AO0yUKWI0A5oiPWD86TzRSNeaa1AoDiRFmixwIucEcrsdjQu3SfVV3g/ xIUGHFDG9dvw/Q4MIhX9WAYONYTLIjHOJHdmuIeuVA== X-Received: by 2002:a17:902:c40b:b0:19c:e3dd:db3c with SMTP id k11-20020a170902c40b00b0019ce3dddb3cmr5358292plk.20.1677385296665; Sat, 25 Feb 2023 20:21:36 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:36 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 08/14] perf kvm: Add dimensions for KVM event statistics Date: Sun, 26 Feb 2023 12:20:47 +0800 Message-Id: <20230226042053.1492409-9-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866384971613714?= X-GMAIL-MSGID: =?utf-8?q?1758866384971613714?= 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 | 239 +++++++++++++++++++++++++++++++++++-- tools/perf/util/kvm-stat.h | 2 + 2 files changed, 234 insertions(+), 7 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index a9f467926bdd..da84f5063d4d 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -70,9 +70,9 @@ static int 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,238 @@ 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 int kvm_hists__init(void) +static int64_t +empty_cmp(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left __maybe_unused, + struct hist_entry *right __maybe_unused) +{ + return 0; +} + +static struct kvm_dimension dim_event = { + .name = "name", + .cmp = empty_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) { + reset_dimensions(); + return output_field_add(hpp_list, name); + } + + 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) { + reset_dimensions(); + return sort_dimension__add(hpp_list, name, NULL, 0); + } + + 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); + +out: + free(output); + free(sort); + return ret; +} + +static int kvm_hists__init(struct perf_kvm_stat *kvm) +{ + const char *output_columns = "name,sample,time,max_t,min_t,mean_t"; + __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, output_columns, + kvm->sort_key); } static const char *get_filename_for_perf_kvm(void) @@ -979,7 +1204,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm) set_term_quiet_input(&save); init_kvm_event_record(kvm); - kvm_hists__init(); + kvm_hists__init(kvm); signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); @@ -1176,7 +1401,7 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) init_kvm_event_record(kvm); setup_pager(); - kvm_hists__init(); + kvm_hists__init(kvm); ret = read_events(kvm); if (ret) diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 80d5c5a9ae31..ca5796959f66 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -40,6 +40,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 Sun Feb 26 04:20:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61558 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1790956wrd; Sat, 25 Feb 2023 20:30:29 -0800 (PST) X-Google-Smtp-Source: AK7set9UG2pcG6SQlGpMrAx30Ix9QV2ndUpaqz1teXKDrjmzeUpVHy4xtvBcneOTPLK/V/flEtBv X-Received: by 2002:a17:902:ec86:b0:19a:a9dd:ed3f with SMTP id x6-20020a170902ec8600b0019aa9dded3fmr24809453plg.49.1677385829620; Sat, 25 Feb 2023 20:30:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385829; cv=none; d=google.com; s=arc-20160816; b=kN55pey12uRtWEbFJbYLxcS6r2FnJ3DVDVSS397VTIXLkKZzfOoUfnLNKSHc/dpUXE 4ucXaFJ0XVVrF+Hg4WFBNIJNpO3PJHftwmIgzvRKsuHmNJb4B89igUhMvbU/Zmh+q2Ea BnkbQqJnYOHF980pJ+olabviJTmn1IVvDNTlUHq2nooP/EREZCxSXb7uXNfeuJA1vZ2u c/RKTh1LxGHjRnbwidUFwMnWd+RAH/34mp8QY/V8dkVUDOt8C/kWTA3EZTdl79YkyS9x Kc5F07mK1iZtOpZYxmC+f3bJXMRALaIbk3k79r/1WYxoFtt0uC8gttsBZUVqIJhhQjJp 7n0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FKs+rsPj1hm0j71DGE8gonxUEIM8JV3GuGWVFR89M0w=; b=iNR6ZCMG/UKXKcBt5IBffS5PShXQghBg7IhSEQ6cxtCnN2z+WHB/4gTd2rcAjLXzz1 32Ji1jo8BBAbW3kIkmYhhk6ZcxmUH41KuyRdImu5ksYxaBldQrvaGO1UreCF7XE7yEkS ai8BZ1UiX+K0t+a7RV/iFYbPvsfNAtfsb4ryMSr9EV4CByAzRwooxznzIyqTohMRfz6q X3TmC7ej5KBB31/ywL1UZ16FkoYaw2ZqT24yX/oVKZosD5HdPmruKoNn2NfL125X/7mo pfMV6Zn6PGjNgc90HqdVTy/82daixxSGvw78Yk+IF/l9RwDCsmf0u+GZGbddSUdC+U6N 2PEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gkBmxZMd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kl11-20020a170903074b00b0019b64bbd53esi3457481plb.150.2023.02.25.20.30.17; Sat, 25 Feb 2023 20:30:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gkBmxZMd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229874AbjBZEWh (ORCPT + 99 others); Sat, 25 Feb 2023 23:22:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229786AbjBZEV7 (ORCPT ); Sat, 25 Feb 2023 23:21:59 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6396BEF83 for ; Sat, 25 Feb 2023 20:21:41 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id h17-20020a17090aea9100b0023739b10792so3114132pjz.1 for ; Sat, 25 Feb 2023 20:21:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=FKs+rsPj1hm0j71DGE8gonxUEIM8JV3GuGWVFR89M0w=; b=gkBmxZMdgES2pWq4PK7G0Xut5H3TEo8CPuhuOcv9GItaB8VA1sr0Iem9snET2rkqK/ cU+5/NhRtqG98TXt306wm4HCT2MldnpVrMM/+KWT+wINUhmutTs6vt3LgK/XoOC3mSMi yhHD5ffFfQtByp2ChfZWaADO3hMnZIp6ZpCpM2O3qCu5+Q3xze5lnSR9yq4y2FVt4Z8L OpCtTaLBUDmRtjG5tmIhPmABTOwQiGhzNdyQ4vAX/L8N9H4/izsZJH0xFvSWRpFQVdck T2MEfodj2R2KT0MHMKFpBhbttj5bUIPzxGmEzY7AJ1spTi4tjoXE6DlAOCyuCZFzoudQ zOsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=FKs+rsPj1hm0j71DGE8gonxUEIM8JV3GuGWVFR89M0w=; b=4V1ODq32rAt3rfuEDYN5gunoqx+0ZqGJCO4jGzG82r4pWal/sAxBD1mk3EX3/7fOMR xR80D9mGXJGVjwu6hnaL19THIp2phlZxqatEWut5frWNNeEMoCTG8cgiPpxjvWeZxC+t bL5Y3gIPuVDdQ5TS7jWfNFsXYHPTbQkNR/IDhNEuoidedxXVd1fLFVvUBaZwjv2be+h4 L78kGIzeaMiAzIWW68zgZIOSrHS12csXsCdH5XI8ZC0Gvv8kVPvgADDdMkIU3T6XQngh +XXrJXdl2fbSbo+4E7BqinaBK52QV6ySCrbuJUIpBF85sGjl7JnKyvtjS9/kV7kTnTPo qbZA== X-Gm-Message-State: AO0yUKXUQhM88DKZhOpvADKMai+K5Y8LIJs/9I8/1NdnHWA+Jz0f/Uil yhp8MF71uw/RQRkJU+eM3qemZA== X-Received: by 2002:a17:902:e5ce:b0:19d:14c:e590 with SMTP id u14-20020a170902e5ce00b0019d014ce590mr2353262plf.9.1677385300638; Sat, 25 Feb 2023 20:21:40 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:40 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 09/14] perf kvm: Use histograms list to replace cached list Date: Sun, 26 Feb 2023 12:20:48 +0800 Message-Id: <20230226042053.1492409-10-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866523917459398?= X-GMAIL-MSGID: =?utf-8?q?1758866523917459398?= 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 | 186 +++++++++++++++++++------------------ tools/perf/util/kvm-stat.h | 7 -- 2 files changed, 94 insertions(+), 99 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index da84f5063d4d..32dc697ff707 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -421,44 +421,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; @@ -484,21 +477,51 @@ static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) return true; } +static void *kvm_he_zalloc(size_t size) +{ + struct kvm_event *kvm_ev; + + kvm_ev = zalloc(size + sizeof(*kvm_ev)); + if (!kvm_ev) + return NULL; + + return &kvm_ev->he; +} + +static void kvm_he_free(void *he) +{ + struct kvm_event *kvm_ev; + + 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 *kvm_alloc_init_event(struct perf_kvm_stat *kvm, struct event_key *key, - struct perf_sample *sample __maybe_unused) + struct perf_sample *sample) { struct kvm_event *event; + struct hist_entry *he; - event = zalloc(sizeof(*event)); - if (!event) { - pr_err("Not enough memory\n"); + he = hists__add_entry_ops(&kvm_hists.hists, &kvm_ev_entry_ops, + &kvm->al, NULL, NULL, NULL, sample, true); + if (he == NULL) { + pr_err("Failed to allocate hist entry\n"); return NULL; } + hists__inc_nr_samples(&kvm_hists.hists, 0); + + event = container_of(he, struct kvm_event, he); event->perf_kvm = kvm; event->key = *key; init_stats(&event->total.stats); + return event; } @@ -507,22 +530,26 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, struct perf_sample *sample) { struct kvm_event *event; - struct list_head *head; + struct rb_root_cached *root; + struct rb_node *nd; 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 (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 = rb_entry(nd, struct hist_entry, + rb_node_in); + + event = container_of(he, struct kvm_event, he); if (event->key.key == key->key && event->key.info == key->info) return event; } - event = kvm_alloc_init_event(kvm, key, sample); - if (!event) - return NULL; - - list_add(&event->hash_entry, head); - return event; + return kvm_alloc_init_event(kvm, key, sample); } static bool handle_begin_event(struct perf_kvm_stat *kvm, @@ -754,58 +781,29 @@ 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(void) { - struct rb_node *node = rb_first(result); - - if (!node) - return NULL; - - rb_erase(node, result); - return container_of(node, struct kvm_event, rb); + 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) @@ -848,6 +846,7 @@ static void print_result(struct perf_kvm_stat *kvm) char decode[decode_str_len]; struct kvm_event *event; int vcpu = kvm->trace_vcpu; + struct rb_node *nd; if (kvm->live) { puts(CONSOLE_CLEAR); @@ -866,9 +865,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); @@ -1142,11 +1147,11 @@ static int perf_kvm__handle_timerfd(struct perf_kvm_stat *kvm) pr_debug("Missed timer beats: %" PRIu64 "\n", c-1); /* update display */ - sort_result(kvm); + sort_result(); print_result(kvm); /* 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; @@ -1202,8 +1207,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(kvm); signal(SIGINT, sig_handler); @@ -1250,7 +1253,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm) evlist__disable(kvm->evlist); if (err == 0) { - sort_result(kvm); + sort_result(); print_result(kvm); } @@ -1398,7 +1401,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(kvm); @@ -1407,7 +1409,7 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) if (ret) goto exit; - sort_result(kvm); + sort_result(); print_result(kvm); exit: diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index ca5796959f66..c38d320c7cbe 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -30,7 +30,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; @@ -75,9 +74,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; @@ -97,7 +93,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; @@ -106,8 +101,6 @@ struct perf_kvm_stat { struct intlist *pid_list; - struct rb_root result; - int timerfd; unsigned int display_time; bool live; From patchwork Sun Feb 26 04:20:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61557 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1790756wrd; Sat, 25 Feb 2023 20:29:45 -0800 (PST) X-Google-Smtp-Source: AK7set9cOiwmGoGO/u4mWYM1GM+6I0pQs9gsPr0vbWqO6YCkh9w+wfTQxx4YnnQB7WVG1Q6Yu2ct X-Received: by 2002:a05:6402:2742:b0:4a3:43c1:842f with SMTP id z2-20020a056402274200b004a343c1842fmr5914014edd.3.1677385785587; Sat, 25 Feb 2023 20:29:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385785; cv=none; d=google.com; s=arc-20160816; b=aIWNSVexTY0ZMYsBSCUO5QilPXZwPePaHxNLQ6rejeSd+NeKOIip80YRvZvz1akMV5 NYsrZQPLCVbc4jU1uJLv52kmJ/1MtgogD9UAyJ/NCMEVKuN/dKSOQK2vCpdHVN0x+juF +mB8c5K6sWKpJ2+V1sZrjUzAW6PqoE3m2uwLGO62Z/bXljf51VGm7BS6NbRTvc5CS+Q4 ZuPI3AAuJjla6yUiM7scqN5bwbo4QsVvAidbxrGxPQu/Gc4jiB0iHoofcdBX0qsGsdDl onYmV3XR0eWh0O5zP2kt/5atJNQ9hAzmeJXc/B81WQenzkZytxxlNQItV/FpbE6fr/CD O67w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hjL18aIBPgYfHqrjofZNutkN8+DYauLGt6A7ZGJ8B24=; b=lUBCJW7H8NQLKKTMUUzhL4+e5OoZ14PS03NFc9DrPhB1wuZxo3adWaqZDCpwtvttI7 lKr3ZribLUTfINZJ4f8849OS3ApytTFNR/BrzuSXejOjvwnRUkAFhS5C+cvyYpnY77mf T4GQbO0asLKNyd7qJkoDMr7RfBhLSFtqgyhS/ES7qbCcw3v+Ci34E8FlftOVq9TsPWYL ho+ezJn/448TzUaabD5oS01s0SFBLEfdGSvaxZldve/lLozFerdioLrGDndo9xHIHW0a K6ZbxgjYcn/r6K9XiwecMp/S1nGwpPXzPB24oQJLCCQwxCK7DhlbvALPDZaQstuTK0T0 OF2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iAaSKRQm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020aa7dd06000000b004acc83a78aasi4691291edv.474.2023.02.25.20.29.22; Sat, 25 Feb 2023 20:29:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iAaSKRQm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbjBZEWk (ORCPT + 99 others); Sat, 25 Feb 2023 23:22:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbjBZEWC (ORCPT ); Sat, 25 Feb 2023 23:22:02 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D54C15C for ; Sat, 25 Feb 2023 20:21:45 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id nw10-20020a17090b254a00b00233d7314c1cso6822608pjb.5 for ; Sat, 25 Feb 2023 20:21:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=hjL18aIBPgYfHqrjofZNutkN8+DYauLGt6A7ZGJ8B24=; b=iAaSKRQm+FOLvfH3xW+UZRCqNcZ9ZcCC8SZ8qSTMKlHcTHAaMlDYLbjYMQI4Dyye3X G9cxLmKM1zzFzw051kf7KT3cbqPkYAW39t5Bb/f7RPOkTK/yftpgxGJO7tq6x/dUiDM3 5R5iKeqB1r2qOmmRBeGqRkI7hqDrAUDBLyMouI9ej3wvbtCIWcVCGSbzNigTtvia0Veb Hq80ibcu4nd7uYc87D7L1JNs8iLnu2HGojw2ntSiYl6G6TjWPE8HCigkivvT1+FHcZGi pPi5sttWl7Ly0A6bv3y09aAHyqcwMdKJAM7PYIjgATI/fbeDL8jmffXEIcUylSFpGHxg /V/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=hjL18aIBPgYfHqrjofZNutkN8+DYauLGt6A7ZGJ8B24=; b=XaB+Iwd4nXQpLqJiJLDK8BegYS5yYposqemhMgmGS18olWC25K7NkQTFrdY5Dhr902 z1Mm+yIzENtzRH75kAVzzeWFOT1ED77AinYC/S9/8+TQPOiE8hDh2hVMpcZHTcq/sqqr y8MawMiY4Uirfmw/Dhg9HU/9UvT2Z9OexMtaAQeSRkVxnnSMFUMVv4NGzjDwX6cM2XDw vimJh2t9+SUocScotAZE/bdT+9DMqtCqaXrUKMUxAJC//LrjX/TU4asVcVlppzRbrO1m jQTpynOQjXD7wB2w/2uSvH2HWd1WWxcV/eHwt1N05/K+labTWhTxV3J4WxWI8ReUiBbo zGug== X-Gm-Message-State: AO0yUKUFoCY6/hiSTqA4VKCJHGwHmzA03RJktIED7V5qbt5bgGARm1gj lBlUB4TrXuiFuEedxXqG1FJ1lg== X-Received: by 2002:a17:902:dac6:b0:19b:c491:21be with SMTP id q6-20020a170902dac600b0019bc49121bemr24672072plx.64.1677385304682; Sat, 25 Feb 2023 20:21:44 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:44 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 10/14] perf kvm: Polish sorting key Date: Sun, 26 Feb 2023 12:20:49 +0800 Message-Id: <20230226042053.1492409-11-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866477754744262?= X-GMAIL-MSGID: =?utf-8?q?1758866477754744262?= 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 | 27 +++++++++------------------ tools/perf/util/kvm-stat.h | 8 -------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 32dc697ff707..741ba65bf092 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; @@ -766,18 +757,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) { + const char *key_array[] = { + "sample", "time", "max_t", "min_t", "mean_t", + }; 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; 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 key: %s\n", kvm->sort_key); return false; } @@ -1201,7 +1192,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; } @@ -1395,7 +1386,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 c38d320c7cbe..a8e919ca59f4 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -43,13 +43,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, @@ -92,7 +85,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 Sun Feb 26 04:20:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61559 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1791195wrd; Sat, 25 Feb 2023 20:31:25 -0800 (PST) X-Google-Smtp-Source: AK7set/sNgrDmESit8Ks7NSJQU09VPA4ZiTGryAzmK5WG2PM6HURk830aVlI/YjcZ0ZTXqGKnce9 X-Received: by 2002:a17:906:9f14:b0:8b1:3a8d:6fc5 with SMTP id fy20-20020a1709069f1400b008b13a8d6fc5mr31617440ejc.25.1677385885148; Sat, 25 Feb 2023 20:31:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385885; cv=none; d=google.com; s=arc-20160816; b=LzmTh1+q+XTtZyX1m6RBNbYFg7RDRJCk6KpzdhC+PGuidkNmJNM7AXaKjtGUBqMJbE r2bht85Sr184GIUB3qq0WhaCC4cURK/lxd3gp8BG6lzgZrcjIOc9llkyNunbIe3tXi9f 1vSph/lDVBmwLzbUb9XIdSqcDldChNuwdb7FTv+XCqEYxF+Ck/tekaLufiwMtIPgSpMj aiM+1TjN81fqOV+tAYiiFKttgqruwPTbCSb7AFD2jeOfKmKgVChn7+vkTn22tXG/yhal 93WRX6AkOzLdcF7k7wTJZx7UZ4ZrY+mQ5PAz3wlDaiK7piy80ujFi/OwncNPtr7hLby/ flrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OfT+QNOxQJmHazP6lqFky4KrZI/iD3/8HshJqJUPAo0=; b=U7t907kRsuKjFJTUCH9vDKksHkWgWGiZKr/Ngi9lA8W5+umEyt6aVM0lJXNOM5Cz4C P/4QilGlAmRx/cxclhM0QoRv12+UDAI3NtCJM/5U7II7HjBu0959m74gIZiBkvkhwE3k V+q95P40+pfeLIol75SEoeWQ7kQUOlzJXiggYWuLWLq5+KMQj2MGk6vkOqqoSAA3paQS rw2BsMboiB6hOWO1qlzGQa9iSKtOb3YI3So+gv9+7jY8cK13hmhNJD/FaTHo5Qq6uE8f SG4e7CN8sCwoYDQta4K15TWaxb/0+uRrpI86HGJRkXxxocEep9uOiv4sd7Q+XLdX8BlB x3pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qptnsxVe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n16-20020a170906b31000b008b19eb42527si3617760ejz.267.2023.02.25.20.31.02; Sat, 25 Feb 2023 20:31:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qptnsxVe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229627AbjBZEWx (ORCPT + 99 others); Sat, 25 Feb 2023 23:22:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229925AbjBZEWG (ORCPT ); Sat, 25 Feb 2023 23:22:06 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77C2DE39F for ; Sat, 25 Feb 2023 20:21:49 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id gi3-20020a17090b110300b0023762f642dcso3070803pjb.4 for ; Sat, 25 Feb 2023 20:21:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=OfT+QNOxQJmHazP6lqFky4KrZI/iD3/8HshJqJUPAo0=; b=qptnsxVeddCZzP54pGIw/EKkorQ3BUbeevNbGhdcaMLpijxTPMJi50KWHZftsfuYK6 Gv8h/QGhDjIqG6Fg97YhgGVaoVaFpVCf3TC++qJYSiOHUkZyrT/t8xy0V1ibvLZTg1WS RlkEdeeHGxp9QgwI/5hMjkP0D1ZMbdmNlzgV/+Oro/B54uu37MSZ7m2iiOQdD9KI2XRS 2OrxxEIkBlTWtTk/GK4beifpBISUsQlDDuwOMyMNjYKqx2qDaLfQusp8FsY3LX78iZr+ ba5D4di5hlfNNXMB6aHRP5OWUgzUIcOkCGecJ/2CzPWaNTiYzQaIZvWmKjh59hEStboC Jd5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=OfT+QNOxQJmHazP6lqFky4KrZI/iD3/8HshJqJUPAo0=; b=ExoOncLZ4QHycAJ/pYXaC7bpneUFSHRbb/oYG2b5QJBsNWVdFNwQZCTVdMESh0eNK+ Y+ilXkShEww7aMghUrIKyKFiI7lwHPp6j3kpnJFljzJg7sRN6peEa1CB8pbJzq4JMHvy y/pB94BJki7OE0z44tmhPDxngo2E10GzYBCSGSeAVD8hRN3AXgTXu0MAwMg2HfR6B/SM 51vGZIc26pyGQib1hNDu9vrMgg5vMhHWmui/9O3r/7O6EmT0NkDJ2r1XofgibMl0JeRZ VrcphtXXzU4KV+JkRafjg1l2+2HGNtQDmmmhAWXk78lInfkGzrIcCRdoBDFQu9XEom3O p6vQ== X-Gm-Message-State: AO0yUKXAyWRbgfNHflW+UGzKvuX3EEAS1OrBNAXJAX6sVfb0L9mdcGy0 7GUZn2MqEKO1krpYAbd0OGqVmw== X-Received: by 2002:a17:903:22cc:b0:19a:a6ec:6721 with SMTP id y12-20020a17090322cc00b0019aa6ec6721mr25044023plg.16.1677385308551; Sat, 25 Feb 2023 20:21:48 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:48 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 11/14] perf kvm: Support printing attributions for dimensions Date: Sun, 26 Feb 2023 12:20:50 +0800 Message-Id: <20230226042053.1492409-12-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866581582142143?= X-GMAIL-MSGID: =?utf-8?q?1758866581582142143?= 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 --- tools/perf/builtin-kvm.c | 105 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 741ba65bf092..a56d0983c585 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,32 @@ empty_cmp(struct perf_hpp_fmt *fmt __maybe_unused, return 0; } +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) +{ + struct kvm_event *event; + int width = fmt_width(fmt, hpp, he->hists); + char decode[decode_str_len]; + struct perf_kvm_stat *perf_kvm; + + event = container_of(he, struct kvm_event, he); + + perf_kvm = event->perf_kvm; + perf_kvm->events_ops->decode_key(perf_kvm, &event->key, decode); + + return scnprintf(hpp->buf, hpp->size, "%*s", width, decode); +} + static struct kvm_dimension dim_event = { + .header = "Event name", .name = "name", .cmp = empty_cmp, + .entry = ev_name_entry, + .width = 40, }; #define EV_METRIC_CMP(metric) \ @@ -130,29 +157,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 +240,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 +313,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 Sun Feb 26 04:20:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61560 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1791818wrd; Sat, 25 Feb 2023 20:33:17 -0800 (PST) X-Google-Smtp-Source: AK7set+9qnHzkIn7wU32eybfMeyH74NoSMau8tGhBuGkG9/yUtXyQrEH6wo8VM3OLTRPA0qesqfj X-Received: by 2002:a05:6a20:8f05:b0:cd:b1f:1b86 with SMTP id b5-20020a056a208f0500b000cd0b1f1b86mr1633111pzk.61.1677385997333; Sat, 25 Feb 2023 20:33:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677385997; cv=none; d=google.com; s=arc-20160816; b=wRDGpCuei5SSMXrnBiOeOmiKbtYHMY/taO5hBzbuhWFT8mfnoS9YU5K6Z8oQ4dgHVE JdIdRZsvfzsKyQHvO9p6zComr4nLXOhktG5lJxMgJF4A+VHiWgo8GoWNGR22reAwnHmN ZsBPwlOkYH0FB2Xoly8mxYzwr9K6Es4/73HO+SRZJCJrvnCZ+B3jWhOrgtltmFY3O7DM GSWszzZv66cOxzZq2jF1TQ8U/QRu3sWOL90p5/Kti0moEknuJZYZfCA9oQEQB0JKHD73 XTmN1VnkdH/nl2E3QxOYZP1a3kGX1IHYcx1BDaLnsAO/FG9kBo9/m35/IyVHFwjJ4pon 8oMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7NEkdhqDMouB1zUi5eCnhcHJNUH+bFnGQLi//L7nojk=; b=eKMykM2SyVmoZVhRVAiOSkp4gxrnqUpnvpOpEv5EAerg+s0ANwnFVn91WMYlAa3d9I 0QCk32WOW7dzSP83193Nqx+BrzcEP1LTqfmiF8e28FaswoRyz5PB8VyZQorWko66/Ulg trIkfbwm7BvWRiT7FTpC9TjGsfN8egP6JjUyHA50CON0JEDQnzesfebnkB3y2sFJj0O5 76vQKK4zmF+SVZhV7N0wSMIEvJMzw20wWN9fAp/yJZ58t5W9W+v7HGgWGcVXnKyxZgwy Jt2zFWogXtacn0RuXR1SpFStJ9RATYJ4H+xgzSkPnzU6CLskYJUKQ59mQ+o/OPzzi1Kn inNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rutgprXk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020a656806000000b00502d774baefsi3214387pgt.241.2023.02.25.20.33.04; Sat, 25 Feb 2023 20:33:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rutgprXk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229722AbjBZEXY (ORCPT + 99 others); Sat, 25 Feb 2023 23:23:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230028AbjBZEWL (ORCPT ); Sat, 25 Feb 2023 23:22:11 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A18713D5D for ; Sat, 25 Feb 2023 20:21:56 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id l15so3564156pls.1 for ; Sat, 25 Feb 2023 20:21:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=7NEkdhqDMouB1zUi5eCnhcHJNUH+bFnGQLi//L7nojk=; b=rutgprXkcCVQHOHCa7qujzCTs/ZmwgPeBYglbDY1OzBhRd7fX0ULgHQ+m4xp/gJYBv Jhta71b2jIcoP8N4zkn8Enn6l7iI56wdtUQ5v/FGE56afGr9+uI6pSqOkqSDfhOjRFoQ kWcpjvZD5ljh/d7nwh5YdNN267zs3knak0z59rW2R1RqCedbTLIn8el6vS5HKPWjbU2j CGTQaBj8wYOSKN5qxIj1XUqb09I0oseoiToRG8LLN4D9rvh7uCRnb+MrNIEozkLVDjla 8P8hyex7pt1WeKBa9ZOpgH5tMBRSvAfOYNDQjE975DjStVCL8fTCfElvaRx/b4X0Bta4 4O9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=7NEkdhqDMouB1zUi5eCnhcHJNUH+bFnGQLi//L7nojk=; b=RfFal+wXV+8Jf2ogii91xCHTkmtJSPYcM125+KwVPs73GrqU+a62DVhxJ9uY1zx0dN gtNfAybBArDd6fSLBPtUzFcJ6UzLg+mRZRI2DG+Inpw8lQhCwUivyhi1RgIn+AmHywe/ LiRKyqfVRqvgHeiXEFwvQO8ZbDKjLewPXjNVbG+LK+GlYQ4mfBibZchQrYS4qYU2PV+X LNf5W/Hkmmvhj5cR/we4EBPLAbaxFPUUhC35tM72Ech/9oDj/bmyRCr1QHo09OMq/mv8 EZGtN0wiUV0ulKVl/1n6jIxvIk0kH5zk3uhoR4MYzw0WmQUuBrvPSVqBz/A8xvz8/mcs ptYg== X-Gm-Message-State: AO0yUKUGthSsVUmUhkdc/+xkd2XJNnn1F6RyCLAYkDTaenO8BIYd7JWk 6x66Lc78ablIhGCgmWId9ptyAA== X-Received: by 2002:a17:902:e883:b0:19a:d7d8:a080 with SMTP id w3-20020a170902e88300b0019ad7d8a080mr25758344plg.22.1677385312286; Sat, 25 Feb 2023 20:21:52 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:51 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 12/14] perf kvm: Add dimensions for percentages Date: Sun, 26 Feb 2023 12:20:51 +0800 Message-Id: <20230226042053.1492409-13-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758866699825954818?= X-GMAIL-MSGID: =?utf-8?q?1758866699825954818?= Add dimensions for count and time percentages, it would useful for user to review percentage statistics. Signed-off-by: Leo Yan --- 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 a56d0983c585..5b1b2042dfed 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -230,10 +230,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, @@ -406,7 +501,8 @@ static int kvm_hpp_list__parse(struct perf_hpp_list *hpp_list, static int kvm_hists__init(struct perf_kvm_stat *kvm) { - const char *output_columns = "name,sample,time,max_t,min_t,mean_t"; + const char *output_columns = "name,sample,percent_sample," + "time,percent_time,max_t,min_t,mean_t"; __hists__init(&kvm_hists.hists, &kvm_hists.list); perf_hpp_list__init(&kvm_hists.list); From patchwork Sun Feb 26 04:20:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1797548wrd; Sat, 25 Feb 2023 20:55:30 -0800 (PST) X-Google-Smtp-Source: AK7set9RgML1XPQ+3ck9eGLTWPZDF7lPPFOkdBAox/jermh4fklt34LTzA71k7hXrzQX9hMLItWT X-Received: by 2002:a17:907:10d4:b0:8b2:abc7:1ef9 with SMTP id rv20-20020a17090710d400b008b2abc71ef9mr32758503ejb.68.1677387329908; Sat, 25 Feb 2023 20:55:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677387329; cv=none; d=google.com; s=arc-20160816; b=XNQtHg6J7TJjhWe4ZGUb21DgaRDQTUr++xOMrLNIh+PMPaYaTMyS9ca56Y4PThiLaJ w611/TyWlwJddesMnzki5952mpQDVc16cnxKkde26v5dzULF90xkmuxlPbCeGN+XeOqZ GIUamLccSf09foDUXgpGDFjh0dI4u4RHApU8DByFYhW8vQgHL+2S2gLbIg/kboIPGrFw LkWEPIDBOz81PUmXWhuMIdNn/k7oRvX6WTTbZECTL9Wc7YD7SoidmVW0bGw59aMIxZce gLCpdSAVhYjk8MEcEXSidECk3FgOWLSOx+235pTfy9btZcpy2ChADp+tHuGi2b2QWzVV Gk6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CkztQHJFG8E1HY0jnPOj65OXed/JJ8e8RRCYx562Gss=; b=oTH4ibNKM86+/ziMDiJp+E8sdzM4Zb/6IJGOMggVeK+pOi2GfLB4IjtLDbPmnJCz4+ W17crJu/bNHmFzXR1lG5bwwHrS392Rm0+WCqSkRG8IQ665YaZOAhUf3mVN6EGvVrIJ/k uzf+gTblga+xEMBE/bRkx0DCHUT2wS/DVZwHcRnyXLOaHSdNIiRHD7vmLE1+Wc36ZnHD 0AI1os90LDjqAAEPiH+WZ0R/KDeVjO2ex5/LHn5F79oAZ2qdy46zWsApV7lK6aLKL4cz 86PszEZ4OwoNoBO7uX87BLo24aRPAWtJ/rTmBReYOFsZugbj0q1Hb3QPM5g7uB9v3U8Q KQsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rdGn+rf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb21-20020a170906b89500b008b2c034ca3dsi4069977ejb.744.2023.02.25.20.55.06; Sat, 25 Feb 2023 20:55:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rdGn+rf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229873AbjBZEXj (ORCPT + 99 others); Sat, 25 Feb 2023 23:23:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229775AbjBZEWS (ORCPT ); Sat, 25 Feb 2023 23:22:18 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38BC113DCA for ; Sat, 25 Feb 2023 20:22:04 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id h11-20020a17090a2ecb00b00237c740335cso2039550pjs.3 for ; Sat, 25 Feb 2023 20:22:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=CkztQHJFG8E1HY0jnPOj65OXed/JJ8e8RRCYx562Gss=; b=rdGn+rf3EDX9CoYEE1C9HkAkC13CzlzzeZwDTwdu2uovrBiZCP7QAv8NiebbDMvT8T JHhdIv62FpvSbHs1zot1bC8VmC71l4Km4a5aQlLtRIQjU+xrViz0kF9urSHjWDwjFYT3 qzmK4ItBVCMfBq+7/H6PYN8ooO2M9cYKvbXdJVBndfNafw/oFKBMpUc6XdqYCnD7Y6VG kQa5Nuc+xsPLcsvGCttpBLXLc3rc8AP024x+i9Aj1CjQQ4S9/Htt1sOYR8aM5xJBD+ND FXnk2AQB26lvVQ5mlDFeg5DBXfdox0OT3Yweyr/lbczjd9MOhmo+i9ZdWn7k9p2lpygf hSbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=CkztQHJFG8E1HY0jnPOj65OXed/JJ8e8RRCYx562Gss=; b=fUzOAcN1KbTEMSjb8//gY8/vIasL7gdNxfBRv3HD86t74+DS3cA6httTFsw5Q5Pgbx zzl4vmHRkYhGCRPGhpt5U4ygfxNu3xQWeFS0dPKGliLP08rCYyNm/TGKN8RnY1IN1YHp tblCIo8MbrGIPEGEj9DUt4qnWRdWaEvjvUvDng3Sgp3qRk9IQOrUe0aGgaItnCZPujNv 5Sy/s17umB9as8gTejg7kqz9ATRdICBnzmM57TArCeucb6aQxFwPQRVhL7MBpHS5KHOJ cxsM8UjxKqP62nrKXEOmOGftvvEXTeFjdvHnpxiju0p/ZZdO7MXfTiYNjw04o2zVmBpW Y4mQ== X-Gm-Message-State: AO0yUKWXbFbn9OIh+m1BZPGRsEtW1jQYn5Xl2HCp+TwGHKcBBIN86mvl vex65Mo9J5a89nuzvyLyDI8jFQ== X-Received: by 2002:a17:902:fb90:b0:19c:d97f:5d20 with SMTP id lg16-20020a170902fb9000b0019cd97f5d20mr5995110plb.38.1677385316213; Sat, 25 Feb 2023 20:21:56 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:55 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 13/14] perf kvm: Add TUI mode for stat report Date: Sun, 26 Feb 2023 12:20:52 +0800 Message-Id: <20230226042053.1492409-14-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758868096522580805?= X-GMAIL-MSGID: =?utf-8?q?1758868096522580805?= 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 | 101 ++++++++++++++++++++++++++++++++++++- tools/perf/util/kvm-stat.h | 1 + 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 5b1b2042dfed..3851e5798d75 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" @@ -506,10 +508,89 @@ static int kvm_hists__init(struct perf_kvm_stat *kvm) __hists__init(&kvm_hists.hists, &kvm_hists.list); perf_hpp_list__init(&kvm_hists.list); + kvm_hists.list.nr_header_lines = 1; return kvm_hpp_list__parse(&kvm_hists.list, output_columns, kvm->sort_key); } +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; +} + +#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__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 print_result(struct perf_kvm_stat *kvm); + +static void kvm_display(struct perf_kvm_stat *kvm) +{ + if (!use_browser) + print_result(kvm); + else + kvm__hists_browse(&kvm_hists.hists); +} +#endif + static const char *get_filename_for_perf_kvm(void) { const char *filename; @@ -988,8 +1069,12 @@ static int filter_cb(struct hist_entry *he, void *arg __maybe_unused) static void sort_result(void) { + struct ui_progress prog; + + 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) @@ -1587,7 +1672,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(kvm); @@ -1596,7 +1688,7 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) goto exit; sort_result(); - print_result(kvm); + kvm_display(kvm); exit: return ret; @@ -1703,6 +1795,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() }; @@ -1720,6 +1813,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 a8e919ca59f4..b66eb4e8c547 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -97,6 +97,7 @@ struct perf_kvm_stat { unsigned int display_time; bool live; bool force; + bool use_stdio; }; struct kvm_reg_events_ops { From patchwork Sun Feb 26 04:20:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 61561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1794255wrd; Sat, 25 Feb 2023 20:41:30 -0800 (PST) X-Google-Smtp-Source: AK7set8HMX0kA1erLyOI+wWXlwNig3J1A18JbD+mqjArPrpTr6JdLumixRPRXmCUWBo/SC+AWAh9 X-Received: by 2002:a05:6402:3551:b0:4ae:e4ec:cf9d with SMTP id f17-20020a056402355100b004aee4eccf9dmr5927848edd.9.1677386490678; Sat, 25 Feb 2023 20:41:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677386490; cv=none; d=google.com; s=arc-20160816; b=YxQVwLS6secqBJxZjPNXimTOkLYSyHRl09TjYBXKcwDg1SCoNzWZjGuGDZUkOUhRL0 eRZzpxRBFUht3H6GAYeOtUFNg3VW2x5YNAHLt26sAKE8KfcQkCPdQuX5APFEQbzQEKqD TCGl9FWS8PUypU7WXQhlUBSue0OlzrSK8Cj7isbrVd/7Yaz2f1XAG5mHEH9Yim4uWR3Q fniEukSqfv0vnGwVX4X0AUmw7MCejQO/i/ymDs9zW9pr9j2K2sVz2PMlLoOLqeZRnOmD azl8DohUrprQDeQ0NlJrTaATpD3hIF6impjpFEugimwiKysBHPrTfN5SfJgQywFJFprv 0wQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QcYnfVUhbZn9a7DJQxPts8NFnTbESI3ZdIxOG6ZSYi4=; b=VK3aFmK73/z5Dd2BbGMEPB1ldxzYmyguRVgFMMr4LGLZ6XQCtOM39/sMGkSmAuvnBT +520S9ivQmhwFFaoei0o2irPWkXswRZJN7yB/ZLSHh4CoGjPGOkB48r6DCB4/Xwxndek OZYE+ibdONzRP9uepMD7KKWQRC7nOTv+R59GKtmgYj4GI5X8wgIr80CDIr8SmNL3gKkp 4cc9o2B0fguz19dsFFrpLbnSHEWG+D/Nt4l02WYahoHhmDifcCz9+mLAXIS+jSoHk24Q dOBKaIM2ZTIz4wAobbAaZVESYk5uuHPgNqEjSrgK8RT1JB0eSshUMmr4S+mCVL2+nss/ Ohyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fceagpis; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v15-20020aa7d64f000000b004ada4ddbbf6si3763526edr.426.2023.02.25.20.41.05; Sat, 25 Feb 2023 20:41:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fceagpis; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229950AbjBZEXc (ORCPT + 99 others); Sat, 25 Feb 2023 23:23:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbjBZEWR (ORCPT ); Sat, 25 Feb 2023 23:22:17 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 372BE13D44 for ; Sat, 25 Feb 2023 20:22:04 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id 6-20020a17090a190600b00237c5b6ecd7so2347174pjg.4 for ; Sat, 25 Feb 2023 20:22:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=QcYnfVUhbZn9a7DJQxPts8NFnTbESI3ZdIxOG6ZSYi4=; b=fceagpisfJ+wn/x77XGmDDqUVFSi3OWTNsoYpFBrTZjqv2xkLCv1w5L27riERthRf8 FIEY8T7qN+Pe7NBaP8MHQ/Y8FDJajeeSzl+LaqP1neHfuMc1a0pyiikI0DIKUMqWcPkY f1KpBGfri+w/ZdDYg/IDgUIpnMDUx7FfFtGip+MYx573MaGUVMhTODQ6B6rCf16A0mbQ uB9HpdKTdhBmUx4WD9kvKpCMuy9yVDLgg/l3LPjgd+7buFaOqE2pnSjB7ia4Dv4PqsEf ldvtLxiCPXLZVhkSy6+AbsNx+8QqnA4KVYu43bLYTqqWEBQd3dfbKyo5w7PCTXjjo+wF cJWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=QcYnfVUhbZn9a7DJQxPts8NFnTbESI3ZdIxOG6ZSYi4=; b=2Uky59KA7vAtkmAO3HHyjcVC/lIhSfjcVo2/+pmUrFaGfDNZ6+GNQMSDpaOUTGYavI 0U+LGyxEpUVSe4OgGsDGZuQGY0xVHGW1HS33HBxkhSC0YsQ/Q/KWL7aFkIem/1hFqBMJ eILok8rMYrqmvt+8L20C5MMLCMJANykwyrOHTWv4Layhh6+dRdTzFramHbdfF88R7ogb tkLcseZzzaS4BkKS84PF2rUlFg2vLf96WxbZ2i5SxrJlFT3ev4vL2DU35hGDMlUzpCBm xEq/YAHQE2hcnCR7bjQ6pzxVXSLbtDWULta0E324ILUmVIa16O1syUPM04KAGen295ZO UFMw== X-Gm-Message-State: AO0yUKVDhiobFIl5v7oK5i99HDKCRJIM0CCgIPkj8LlO3K4kqUgrXGTt VIwSGlEU20IqQN3DpUYg51nLOQ== X-Received: by 2002:a17:903:6c5:b0:19c:c184:d211 with SMTP id kj5-20020a17090306c500b0019cc184d211mr7175760plb.37.1677385319973; Sat, 25 Feb 2023 20:21:59 -0800 (PST) Received: from leoy-huanghe.lan (n058152048225.netvigator.com. [58.152.48.225]) by smtp.gmail.com with ESMTPSA id jj2-20020a170903048200b0019aaab3f9d7sm1976036plb.113.2023.02.25.20.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 20:21:59 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 14/14] perf kvm: Update documentation to reflect new changes Date: Sun, 26 Feb 2023 12:20:53 +0800 Message-Id: <20230226042053.1492409-15-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230226042053.1492409-1-leo.yan@linaro.org> References: <20230226042053.1492409-1-leo.yan@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758867216949226943?= X-GMAIL-MSGID: =?utf-8?q?1758867216949226943?= Update documentation for new sorting and option '--stdio'. Signed-off-by: Leo Yan --- 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).