From patchwork Mon Mar 13 11:40:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68788 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1136636wrd; Mon, 13 Mar 2023 04:55:09 -0700 (PDT) X-Google-Smtp-Source: AK7set8XtVl9uVH2eOSJgOYCCugNByrM/b8Rt1lRyZuyx1D6Be5NCRyRbgvnS5xMZ8TaoCBToe1W X-Received: by 2002:a17:90a:50:b0:233:be7b:e71c with SMTP id 16-20020a17090a005000b00233be7be71cmr34639617pjb.5.1678708508945; Mon, 13 Mar 2023 04:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678708508; cv=none; d=google.com; s=arc-20160816; b=GytN4LlWOtrwtOpQTcTGKNvpxeoUiy+lePmV534BvJWwmpLAAV4s+/daSg7KwWp/CO Q2roxonrhZXiSg6lpz6EE74/lTT6TLg7VZbuapjnaewawiPrysHxNpuIipRIq4haDMaf nsJZ+gMreY9TLFzSyu6X4+BNnQr7LN9KEKFms2WcTkQSQUilH6aN9ZSve2zkotP193T8 O4mJ7JKjHEkXLPBdaiU6u8M7p2/H9B7nO0q8odkmldqDtxR9EyIqNNX2smHEmUlFAEnT PM8RtpLbUoEPvzCr7DgEf5PXWg0mNTzZgaOcS71uIpNIGXVars2nBIv2gWxiEs4S2RMa HudQ== 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=EfFwm9/whD1jR/5n6DKKR8V6Fa945UAISwsDPx5HLJU=; b=J87EBlMYqbVS2WH7/4o1lcOlUpjWWSYhDpsuJaBJmXb9AOfs4ZmkwDcSYwtMIBXhJB dgtDKiS9RKFhjXXZfiFD+IG1GA7+kEE7yPMZCHjkrpXqK6mojiFD1Tv2iC2KH66BSJga ZOU23wGcCWCpP73ugTOGCp7+fQNlJza+gYkkOzTjQBK/auejxWIdQ1e3eew8pYuR8Nx5 J2nPOhVp4IVUwJjHIlG/ncBenm4lyBoq2DGRIeI2A0QpEZx7BgmllNrC3SlSj9phK6mj jUS1RWQdpw4zkup49o06Kr0UUD4cyE+m0YD1TALd4QDO4I0x41m4UdyWb3Le7Lcs4BuS AmHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UKMSaTwr; 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 hg17-20020a17090b301100b002377ed22060si6097933pjb.178.2023.03.13.04.54.54; Mon, 13 Mar 2023 04:55:08 -0700 (PDT) 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=UKMSaTwr; 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 S230356AbjCMLkt (ORCPT + 99 others); Mon, 13 Mar 2023 07:40:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230374AbjCMLkn (ORCPT ); Mon, 13 Mar 2023 07:40:43 -0400 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 D96536485B for ; Mon, 13 Mar 2023 04:40:41 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id d13so1651399pjh.0 for ; Mon, 13 Mar 2023 04:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707641; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EfFwm9/whD1jR/5n6DKKR8V6Fa945UAISwsDPx5HLJU=; b=UKMSaTwrX/iAEgtNVLYK1CXWlwTqjnwE629XOSX71tKhB6T3cAOlOXRTt3LvlrWi5X FqlTeRl98HKQVTHqKqa29/tAnEmIxP09oGP9/8q3Gu/uMR3E1dnVkTr0nDcF/SOpIkoP K1tgzxVrbtc398A2UEIShZ3XaBB3OyZkCx12EVsY2GMx99hts27vPZWdKGe1VXBA+1u6 DikXAAaaBuGfS5cSKOLPHhi/GvbKi1EyuN0dErkJI4ai+P/eewM/XyDHcbX41FIesMjC bUSF2i+E4x58EQP94dSS6NFDlKbrBcYM7VPl7vL5Hx53Uoj3uCKZWCJSVqDlOx0icC9N HmzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707641; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EfFwm9/whD1jR/5n6DKKR8V6Fa945UAISwsDPx5HLJU=; b=YhzE2cetVu1MkUIa6cn7to0lEen1XWn2ShnUGUhvSCNDTn2R3IkH3ZIob/q7/uuYVA SR0HDUIomi/st/EGt3auAAWtFYOvRty/CK+TTu1T9cs1lTt2G7PNgunm5GFKuoleHMCS AZWR4qIiMFPG7mxcSJvQ7im3caxzcXAG+7Zli0BXP2gQQ0CuePRHncfdyrn/6n04Q5Hw Swc7iz/ngjYLKfgKby3HM/YcnmDkxmHZMGJvu72xE2L12JCnz6WDpJgEhSHdY7DfuJeK Rek6TtNYHE7EHKoFrEAkof6lRmFGS63t5uU1ZXAIj0LyqzZcNwSOCQpe47qulNHtC1e2 qOVQ== X-Gm-Message-State: AO0yUKWIlUm0GmLSE+DM7L4xvG4j1TgwVSAudGJwwFQbqmJ3fmDqhBb8 QP87E1KLXv0siEB/r1teqe99pQ== X-Received: by 2002:a17:902:a986:b0:19d:297:f30b with SMTP id bh6-20020a170902a98600b0019d0297f30bmr26907234plb.19.1678707641163; Mon, 13 Mar 2023 04:40:41 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:40:40 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 01/16] perf kvm: Refactor overall statistics Date: Mon, 13 Mar 2023 19:40:03 +0800 Message-Id: <20230313114018.543254-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760253453420280866?= X-GMAIL-MSGID: =?utf-8?q?1760253453420280866?= Currently the tool computes overall statistics when sort the results. This patch refactors overall statistics during events processing, therefore, the function update_total_coun() is not needed anymore, an extra benefit is we can de-couple code between the statistics and the sorting. This patch is not expected any functionality changes. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 641e739c717c..0172e5b0d26e 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -278,9 +278,14 @@ static double kvm_event_rel_stddev(int vcpu_id, struct kvm_event *event) avg_stats(&kvm_stats->stats)); } -static bool update_kvm_event(struct kvm_event *event, int vcpu_id, +static bool update_kvm_event(struct perf_kvm_stat *kvm, + struct kvm_event *event, int vcpu_id, u64 time_diff) { + /* Update overall statistics */ + kvm->total_count++; + kvm->total_time += time_diff; + if (vcpu_id == -1) { kvm_update_event_stats(&event->total, time_diff); return true; @@ -399,7 +404,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, } } - return update_kvm_event(event, vcpu, time_diff); + return update_kvm_event(kvm, event, vcpu, time_diff); } static @@ -526,15 +531,6 @@ static void insert_to_result(struct rb_root *result, struct kvm_event *event, rb_insert_color(&event->rb, result); } -static void -update_total_count(struct perf_kvm_stat *kvm, struct kvm_event *event) -{ - int vcpu = kvm->trace_vcpu; - - kvm->total_count += get_event_count(event, vcpu); - kvm->total_time += get_event_time(event, vcpu); -} - static bool event_is_valid(struct kvm_event *event, int vcpu) { return !!get_event_count(event, vcpu); @@ -549,7 +545,6 @@ static void sort_result(struct perf_kvm_stat *kvm) for (i = 0; i < EVENTS_CACHE_SIZE; i++) { list_for_each_entry(event, &kvm->kvm_events_cache[i], hash_entry) { if (event_is_valid(event, vcpu)) { - update_total_count(kvm, event); insert_to_result(&kvm->result, event, kvm->compare, vcpu); } From patchwork Mon Mar 13 11:40:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68760 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1131867wrd; Mon, 13 Mar 2023 04:43:08 -0700 (PDT) X-Google-Smtp-Source: AK7set8rog5eVEBmakMJ2XrymkqTvw7vsrZq5BeTfjKHSdhv+1ky5fR1lIfl6c2NBfpZnJDNfBa7 X-Received: by 2002:aa7:9713:0:b0:5a8:b2bf:26ac with SMTP id a19-20020aa79713000000b005a8b2bf26acmr30673943pfg.20.1678707788558; Mon, 13 Mar 2023 04:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678707788; cv=none; d=google.com; s=arc-20160816; b=r8bhbUKkZm1IeMmaCwjeX3Ph7DIU52ekLrUApui7rxKK/XM8MofNKvHzZLP1mD5Sqw o4uJCNiH6wCH1PXxBOLwZ32uNhINi2pmhHcWBW/eKJzLKIUsKG5JzqZ7xzh7txsGm8U4 kPZpHLQOaUSi87+bjr5N6Ba5NKuVWZ4qUsi0ScoohO9WVAkA7nJ7OaCvC0J78oCfqrJz vuEoj3htUEOvFGczv2ArPs3/1xs4dQl66fCUcGUDWOnzYJX5G2g2AMnvDMUK+h6n4pAY INztDjXWcmS0FZRLWLiWgeESEzj1w/NRiMm4lxd1uaaIIICxlYto+Uhodt4SC8sJUg2q t7IQ== 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=uN7zwUTTarFdEEyI4xavpEstkRipyyWqLXdanEnFXps=; b=lAzzbViHcO4j7fJKcGSz0jxQoOGNBs6bXf9U46pqb75A63lxvUOv8y7qLCCKHwt38M GReKRV5pkly/Vti2+HcVIO/o5ZqaYQkZ70T9Uj5heI5puocbi6E+PBGzFyVqLOilSnmE hzIHjPTF1HTWu4ucOi/JlReIjGcygi36gUAVOcBfNdH8nDNyNKwQesQl17BJV2enWnFi 5xB8bqAYS5/mxyfGt37rTeAI8Eidt3PKyMZJSSj7jTeOozDWnNpaOBYy52jFbF6YlsT5 UNCIq+/b0uds3NXpp2LPSm2uFcAMuH+bM5yuqPUGBY5mdb8YwOEo0K7XkPgz3ty55hAG SoAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ys+dsTy2; 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 z21-20020aa79495000000b005a8adf87826si6313398pfk.174.2023.03.13.04.42.49; Mon, 13 Mar 2023 04:43:08 -0700 (PDT) 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=ys+dsTy2; 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 S230455AbjCMLk7 (ORCPT + 99 others); Mon, 13 Mar 2023 07:40:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbjCMLks (ORCPT ); Mon, 13 Mar 2023 07:40:48 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D5C064273 for ; Mon, 13 Mar 2023 04:40:47 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id v21so2461078ple.9 for ; Mon, 13 Mar 2023 04:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uN7zwUTTarFdEEyI4xavpEstkRipyyWqLXdanEnFXps=; b=ys+dsTy2vh5IRMXu/71+ZQS9QxgiwshRjarRfNFvlFiW60uTbW/yU0lWs+E37FB4qz VSPJHNbcO33USpFkL/q9Adz8H03Zhlk0Q3tIsXazE/d9+g8USW9+18mTPEORCn6mP9wx JF1xEietU5qPMMzExkFMe/Q1aL0hz7F5EL2rxl6sh3mclaE+XDHgej7K0aEcXF/fl2tQ k01DVC2W2dXjTDnptjKW/fRRstP2X41ql9tXQKTnmvbDl/QR3Of8lQuxNexFkTPbfVaN IERCN2JEGZC1Sp4Gw2tU8tbCM85A9E2bqYLC42pgd8r309b/27IP4+aWTujQPYJtuOE2 oWcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uN7zwUTTarFdEEyI4xavpEstkRipyyWqLXdanEnFXps=; b=Qzaj6IHe9q7WuSVoQyhjdWnoJQbGA76QEuPyLn3F+vXsoGk8KEJuUxhGzzhfQghGBI q4b60sExNl8H1JR2sJWa1Yms/dSaX/0KMgiKfE5NLY/omrk4M0YN/RXECSCAmsgHEUj0 VtdZ2nNOFqqOmmPndv5IY9cFpeevSDZYNlBQom28r+oXwDiXVV7Cn26CuCYT4KRCKB9b sY6Si2nQVylNY9UfgD3EjrK55XRjd96+IRUcOrwoPPDuksozjHr2hwn+LQXhUguz5iqn QQCwcA08ZUkEP1LC7y8bKLvqXnk2rVCQdujPv6uNwfPbleZeBVv91LCTBJ1SOI+yELRG wMWg== X-Gm-Message-State: AO0yUKXalomdfTV3QO50htzoH9hj6PqZsl0AY70Fry+vrUigT1r+SmE/ hv9Da4ZVPL5bu+kKBWcp1fq72Q== X-Received: by 2002:a17:90a:ec13:b0:23d:9ae:a49a with SMTP id l19-20020a17090aec1300b0023d09aea49amr2896119pjy.30.1678707647136; Mon, 13 Mar 2023 04:40:47 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:40:46 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 02/16] perf kvm: Add pointer to 'perf_kvm_stat' in kvm event Date: Mon, 13 Mar 2023 19:40:04 +0800 Message-Id: <20230313114018.543254-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760252698198716605?= X-GMAIL-MSGID: =?utf-8?q?1760252698198716605?= Sometimes, handling kvm events needs to base on global variables, e.g. when read event counts we need to know the target vcpu ID; the global variables are stored in structure perf_kvm_stat. This patch adds add a 'perf_kvm_stat' pointer in kvm event structure, it is to be used by later refactoring. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 6 ++++-- tools/perf/util/kvm-stat.h | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 0172e5b0d26e..3d2560ec6b37 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -209,7 +209,8 @@ static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) return true; } -static struct kvm_event *kvm_alloc_init_event(struct event_key *key) +static struct kvm_event *kvm_alloc_init_event(struct perf_kvm_stat *kvm, + struct event_key *key) { struct kvm_event *event; @@ -219,6 +220,7 @@ static struct kvm_event *kvm_alloc_init_event(struct event_key *key) return NULL; } + event->perf_kvm = kvm; event->key = *key; init_stats(&event->total.stats); return event; @@ -238,7 +240,7 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, return event; } - event = kvm_alloc_init_event(key); + event = kvm_alloc_init_event(kvm, key); if (!event) return NULL; diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 6f0fa05b62b6..40a4b66cfee6 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -24,10 +24,13 @@ struct kvm_event_stats { struct stats stats; }; +struct perf_kvm_stat; + struct kvm_event { struct list_head hash_entry; struct rb_node rb; + struct perf_kvm_stat *perf_kvm; struct event_key key; struct kvm_event_stats total; @@ -44,8 +47,6 @@ struct kvm_event_key { key_cmp_fun key; }; -struct perf_kvm_stat; - struct child_event_ops { void (*get_key)(struct evsel *evsel, struct perf_sample *sample, From patchwork Mon Mar 13 11:40:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68771 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1133894wrd; Mon, 13 Mar 2023 04:47:56 -0700 (PDT) X-Google-Smtp-Source: AK7set9Al3zg5pjMrww65hdu/0/Va88fkdY0S413VpqDqcvr7BhmpAuRMVhcS36Kfx3EG59AHAFg X-Received: by 2002:a17:90b:3b4b:b0:234:19a1:8690 with SMTP id ot11-20020a17090b3b4b00b0023419a18690mr34849199pjb.26.1678708075971; Mon, 13 Mar 2023 04:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678708075; cv=none; d=google.com; s=arc-20160816; b=NytW732iR/WTYwBXZnwbr7DiGA2OUecMS7nPkIELibDwKJZNXJshu82BpP8xqykd5Y NLDqqDV9Qc0FwSxL+thFxsOWC0KjkeFmHzdect1E4orCKj4RcTqmqNGTfmK7Ds9NGYbW qQE3hVo29Rr+1w0r6fq0HJEb0ki+U56lYfHgASHFyrBVjjZ5lxkTPsf31II7FnsuZMnT MoLQrLv8YRokOxEloNRCj0Jrcs1dN7l2MEDlJSjHqMR2O1yM67d5hKRKdHO2Zmr+WUvs tVvihLqIrgNHAQs3Dp48dXZA6b2EeM8tCAxmuRlkMsrVIkTgZaH4AFEqE5mpwrBZ+z/E UaFQ== 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=F9P/WNNNsLKtkXIlBizDtRA5HEUxXu0PrB/8N0zALdo=; b=DcJdnVTWNBSZWBmtn4TAt6+dtn9zowB5maxlm9b5I84oPyToJs4loBVgb39MEtQbdL eMpUF4cZijrSjHPGFN5P0/h67O96NqYmqzBMD/krD32VTa74kdLNF/QK9xe+tFmeGvTM k/QYust1VkjvmqMQ+MMPaEruvBJhzVdDWVBjhfnDSLhSn/gC3Ey/zHXgvaaIE0xNmdfk 8eOUjyop4P/KTutoZf4hdlhJB6H5gi5RWWyKxaH0uOVSBYNC4v9nms4DG2abkGpAeDq0 7n+x8Am+ssxiV6yDV+Q5ykvvv8001uTQ5k6ZVa5WRXQzV+pT4pm4XVsjUCj04m747Wz4 K35A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lnyLElAp; 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 v11-20020a63d54b000000b004df0d68adf2si6440041pgi.629.2023.03.13.04.47.41; Mon, 13 Mar 2023 04:47:55 -0700 (PDT) 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=lnyLElAp; 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 S231143AbjCMLl2 (ORCPT + 99 others); Mon, 13 Mar 2023 07:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbjCMLlL (ORCPT ); Mon, 13 Mar 2023 07:41:11 -0400 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 8AB2C6507C for ; Mon, 13 Mar 2023 04:40:55 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id y15-20020a17090aa40f00b00237ad8ee3a0so11372665pjp.2 for ; Mon, 13 Mar 2023 04:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F9P/WNNNsLKtkXIlBizDtRA5HEUxXu0PrB/8N0zALdo=; b=lnyLElApv7NnUsgOvaifBSHgYeHAmg6da7c7jzAexRiFFgCaBVjIDqWsedH4pS3CQ2 Jw0+7ZrHOQBWZGR/XKq2dkLxLEMHw9AE9/58WvGpBwyGvQ3Ilrj0Kvhm04xfWfySExcD 5DETnEtSfjQIEf27I/QR4HS4fKDgHnT/aeCKKy0yZLaKzO229NgEPXyov+ObigOAonz7 bKX4em//1FqtEQVLJPTz+j5dg7zEIfAaUKv78qttuZnOp2Om45cIM4cLM1RFnGFaQEVR OoAG6i+q6Mg9TyDVwnMQFQNHCNp7OlDcOZq1aUkdLzU8yUP0OSLjyo9xKTLqAI+LI6jU EZxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F9P/WNNNsLKtkXIlBizDtRA5HEUxXu0PrB/8N0zALdo=; b=MhiXXHTwaGeTcB8I3mlZiqSgz2ujTVq4sIarthtstcQHXSwfyXKyf/aJsRW43XZLo7 6OpMcuygiAE4eh4jkXoS2Qytil04UnrnNQVBbax70JHUg+4XqtUmMDG+eGJvhTqdIm1F aqu+GGcXx9qtbLGS75nvQwyka0f0v3C1Cj4XOzbMtp51GUNq1ZGcWXlZn/o5LkCroCOk iSNhOjIXnaBVhXAPNXZ6EGQWqqa80XAhfMiEY7ysxR6HSRGbnfd1h3xcxVWCFs/ERyqG pNI1yEvoFH8BEAEIHvzkehl5yyKZ16LJk8Ljuei1lLnU/um3BkXa9cFDZLLeVUd3dMGu Zibg== X-Gm-Message-State: AO0yUKVxtZnYNoToumQ3yU2zGfp8t78ME/HiizfRRgHGKNvTTgguAI86 ok8SAeCygYZNUY/orXLDoYN33g== X-Received: by 2002:a17:90b:38c3:b0:237:d44c:5861 with SMTP id nn3-20020a17090b38c300b00237d44c5861mr35810313pjb.12.1678707654867; Mon, 13 Mar 2023 04:40:54 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:40:54 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 03/16] perf kvm: Move up metrics helpers Date: Mon, 13 Mar 2023 19:40:05 +0800 Message-Id: <20230313114018.543254-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760252999000259557?= X-GMAIL-MSGID: =?utf-8?q?1760252999000259557?= This patch moves up the helper functions of event's metrics for later adding code to call them. No any functionality changes, but has a function renaming from compare_kvm_event_{metric}() to cmp_event_{metric}(). Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 72 ++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 3d2560ec6b37..62c097a37da9 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -49,6 +49,42 @@ #include #include +#define GET_EVENT_KEY(func, field) \ +static u64 get_event_ ##func(struct kvm_event *event, int vcpu) \ +{ \ + if (vcpu == -1) \ + return event->total.field; \ + \ + if (vcpu >= event->max_vcpu) \ + return 0; \ + \ + return event->vcpu[vcpu].field; \ +} + +#define COMPARE_EVENT_KEY(func, field) \ +GET_EVENT_KEY(func, field) \ +static int cmp_event_ ## func(struct kvm_event *one, \ + struct kvm_event *two, int vcpu) \ +{ \ + return get_event_ ##func(one, vcpu) > \ + get_event_ ##func(two, vcpu); \ +} + +GET_EVENT_KEY(time, time); +GET_EVENT_KEY(max, stats.max); +GET_EVENT_KEY(min, stats.min); +COMPARE_EVENT_KEY(count, stats.n); +COMPARE_EVENT_KEY(mean, stats.mean); + +#define DEF_SORT_NAME_KEY(name, compare_key) \ + { #name, cmp_event_ ## compare_key } + +static struct kvm_event_key keys[] = { + DEF_SORT_NAME_KEY(sample, count), + DEF_SORT_NAME_KEY(time, mean), + { NULL, NULL } +}; + static const char *get_filename_for_perf_kvm(void) { const char *filename; @@ -461,42 +497,6 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, return true; } -#define GET_EVENT_KEY(func, field) \ -static u64 get_event_ ##func(struct kvm_event *event, int vcpu) \ -{ \ - if (vcpu == -1) \ - return event->total.field; \ - \ - if (vcpu >= event->max_vcpu) \ - return 0; \ - \ - return event->vcpu[vcpu].field; \ -} - -#define COMPARE_EVENT_KEY(func, field) \ -GET_EVENT_KEY(func, field) \ -static int compare_kvm_event_ ## func(struct kvm_event *one, \ - struct kvm_event *two, int vcpu)\ -{ \ - return get_event_ ##func(one, vcpu) > \ - get_event_ ##func(two, vcpu); \ -} - -GET_EVENT_KEY(time, time); -COMPARE_EVENT_KEY(count, stats.n); -COMPARE_EVENT_KEY(mean, stats.mean); -GET_EVENT_KEY(max, stats.max); -GET_EVENT_KEY(min, stats.min); - -#define DEF_SORT_NAME_KEY(name, compare_key) \ - { #name, compare_kvm_event_ ## compare_key } - -static struct kvm_event_key keys[] = { - DEF_SORT_NAME_KEY(sample, count), - DEF_SORT_NAME_KEY(time, mean), - { NULL, NULL } -}; - static bool select_key(struct perf_kvm_stat *kvm) { int i; From patchwork Mon Mar 13 11:40:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68774 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1135703wrd; Mon, 13 Mar 2023 04:52:38 -0700 (PDT) X-Google-Smtp-Source: AK7set+s3SGMJQ+aQMEVH96irNfBW7nx4yQgTBmJunDJVoDCrrY2MN12pHsSWPyOVw+uE8thR2Ae X-Received: by 2002:a05:6a20:1bdd:b0:cd:87ef:3f21 with SMTP id cv29-20020a056a201bdd00b000cd87ef3f21mr33595693pzb.8.1678708357876; Mon, 13 Mar 2023 04:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678708357; cv=none; d=google.com; s=arc-20160816; b=d7JuujDPgT+4NYRWuIzVVugBDEUGukf89qqG+pLvSor87aWCNIeDvwGp2wbX//s+0q M/f0GOURMWjeI2xqjoOVtiQVZFP+Chr3NKVyBWscGuMWlUCMYRO+5eGpz7ccE2qO8Jno qI3ITN2WmeT/SpyDXOWi9sPqJMRr58/FrF4qWF9qiGz96wvrsuUH9l3cA+jnJM7y8z+A uMt5AZjAqFwFMohBEpIK4okSgx8PzI2T8tTKKQQfCN14DFQQqiTGNfhPQzIxZPGWV5fc yY+8pF97hsuwRYN6YyPaqpm+blj8f6UvheW7SlGQ7vluU0hRUPHqx0dM71DUy71lixvn KIcw== 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=Q/nbi3g1G7blTIc7EqTO9R+UAXnIBnoxcjmSOAZ7Xck=; b=k9t+6z/UeBq0jqU6JVgyeXL5Szb2SKumtDaz9Sl5/xZCEulofBnjtJecp7KugOJi1E 26E+DCAFAT1p6e/wxNNCBmgoZGNpOsR89dL3AgzdNqnsvhA3nD7ZHibSVHnZ4FqCNs5c jgK0yLeLZXh8KzqoEbCX4X0Y4xVGuLVixFxJrgdwxEzp27MwkM00pu54dkzw/m5HrZ4i HIzeZIurrzborV2v9PuuwL3R4yJXXPkMQ/YYVkzPDKURMjU6W0P0RDJDNxVQZM/5QUh0 kp1id0pmpse/TwVaqyvqAfdGl8rQhkx7MFiEw3GunyGaa2ITHl0jzcGquOLBF4xg9fHo Qc7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=evWDaAHR; 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 w69-20020a638248000000b005074d06d833si6281751pgd.427.2023.03.13.04.52.22; Mon, 13 Mar 2023 04:52:37 -0700 (PDT) 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=evWDaAHR; 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 S230308AbjCMLlc (ORCPT + 99 others); Mon, 13 Mar 2023 07:41:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230461AbjCMLlU (ORCPT ); Mon, 13 Mar 2023 07:41:20 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 573096510A for ; Mon, 13 Mar 2023 04:40:59 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id l1so11704856pjt.2 for ; Mon, 13 Mar 2023 04:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q/nbi3g1G7blTIc7EqTO9R+UAXnIBnoxcjmSOAZ7Xck=; b=evWDaAHRTVMrCXo8odtG+XiiUQi/tIoaxy/YK2dWKYAJKc1YsgTzVcGbRMwl/jK+A2 se7zCOxQLs0/AMm0R/Hhi+RHruUbuxn1oDGZPAGOfRrzGKFTMfkzP5AJ1vrEY24SqPj6 U8QlLyFEj/m6hPLsidBw0kiRmNFqGEVPs0lrJSV2ii0F/aNS05n+LoTzlWtrKf9cVICX nxxlfGv8wfAiU5rqfpRciQ3k/egPgubfloC8K9Pq+dvRgpUbfugeEwPme8sOHuBvXGuC D1LMKU1U44tgTYfVr/K7MSsq73F/9BaP+WfFwm0fORwzQ+LDfFh+u4/B+dSRQoGTJG1o /mWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q/nbi3g1G7blTIc7EqTO9R+UAXnIBnoxcjmSOAZ7Xck=; b=YKfvWqUhu+tFZLyVKM5F1amV+Y1jOdrA33dw0TZn4PPGPs0wqJtgnx8+I0kKSZ8Y94 lm2eFSQsr2uR/SSusxRV6XQRJ8lqE41JnaAigFhAXrYglIL0WJr+4njjlc9d8zpJMZce WUiJATAJ6+JmQkOzeZhqLTaHfTMk27R7IcK37rLARKAWGc9/iZBNZw/j184W1/dkNcMI fWmYAx/wHJ+2xShfEEVLU3ZEfKDUP2WCDy2687PvPOtVPJfYQ+GtBTms2h/TWB5p761B 8+74NpM3jWUiA90ntLDrC/YnOVsrVtvZZhNh7e9MyfamKiiEn3N9H9TKqhIQSfpm32yB PGHw== X-Gm-Message-State: AO0yUKUXiROfUob2LxAqf/CdAsMALULWHWmbDwiA8JxaBtTuu0BR3G5+ +Ejr5M460/3TDooaPU7UAjx+EA== X-Received: by 2002:a17:90a:94c7:b0:23d:2b11:b39b with SMTP id j7-20020a17090a94c700b0023d2b11b39bmr34239pjw.31.1678707658713; Mon, 13 Mar 2023 04:40:58 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:40:58 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 04/16] perf kvm: Use subtraction for comparison metrics Date: Mon, 13 Mar 2023 19:40:06 +0800 Message-Id: <20230313114018.543254-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760253294881390854?= X-GMAIL-MSGID: =?utf-8?q?1760253294881390854?= Currently the metrics comparison uses greater operator (>), it returns the boolean value (0 or 1). This patch changes to use subtraction as comparison result, which can be used by histograms sorting. Since the subtraction result is u64 type, we change the function return type from int to int64_t to avoid overflow. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 62c097a37da9..4e9519390da6 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -63,10 +63,10 @@ static u64 get_event_ ##func(struct kvm_event *event, int vcpu) \ #define COMPARE_EVENT_KEY(func, field) \ GET_EVENT_KEY(func, field) \ -static int cmp_event_ ## func(struct kvm_event *one, \ +static int64_t cmp_event_ ## func(struct kvm_event *one, \ struct kvm_event *two, int vcpu) \ { \ - return get_event_ ##func(one, vcpu) > \ + return get_event_ ##func(one, vcpu) - \ get_event_ ##func(two, vcpu); \ } @@ -523,7 +523,7 @@ static void insert_to_result(struct rb_root *result, struct kvm_event *event, p = container_of(*rb, struct kvm_event, rb); parent = *rb; - if (bigger(event, p, vcpu)) + if (bigger(event, p, vcpu) > 0) rb = &(*rb)->rb_left; else rb = &(*rb)->rb_right; From patchwork Mon Mar 13 11:40:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1131931wrd; Mon, 13 Mar 2023 04:43:16 -0700 (PDT) X-Google-Smtp-Source: AK7set9mQcz5NoZTWHODGTVqfDQvxiZfmq833ff0r7gpk3BamcQaMWKp8l/60EXVnRakKozKMJ3N X-Received: by 2002:a62:64d4:0:b0:623:81d7:f65f with SMTP id y203-20020a6264d4000000b0062381d7f65fmr4498714pfb.17.1678707796436; Mon, 13 Mar 2023 04:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678707796; cv=none; d=google.com; s=arc-20160816; b=su/pyE+7A6Bq/aOSpaRVoV1kRShaWE8zUSlng7oscFcookoeA4RmX5+AQTa2goFKiM feqXh3EXCZG99XljditMXg5Pw3t7Q1oE7/1H+9KQmG2FxbxvPsWDnfEL4IxUFbt+L9Tr 9yV8Pxr2VWfCBPDT9ojXwCYIf66oKTdp/NZJ0mQwjPhdSBrlJA1yQ9m7A7rVZoOG1Lhl agKL9S/Zh/qrDxJV9nR6PXbfzgbxxFQDoKGd+hGeh82necrHTJpi6ksJqnhK9mlVRbOe BIqiEvJJoCyZN7dI4mU+5QCisstaKiu542ArD7ymhg/dSvopQo0RU5VO9efWp9VrJL96 6PyQ== 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=j6kBGPnEPjnrQRBTl/Gpvo8CV0NUMglCUWHrEzVJ/Sc=; b=dbjUMu8z7QRDQ9JGPty9RjQWhpXqpO9vBcSKe8cOrOx+5pCNGA1sDFiOEP+/1TamW2 3xn9yD/IKVjRoJ30ESzq/ALqcyyO1X5gFZSEQCf7noB9XuITqHJ71TQooY1i4zgz/V3/ 4DPnyocQI1RJPOaGnUgzHJQ8T/tGwwT/gm2N5otQZ5zEBKVeL88RhP0Q9kVVssOtO9sh we8VBAq1b5aIiJvQ/SuXenYgBOsCCsUCY2yxI3/1C4iRmacPJfHh2t8cFk9CA8zEi2+T 30DSvUd8v5Mm4Nyw8cwMnHeeV6kM/5vrOfQnVOXgPiUbOqj+7/XNyauu4o1MzQFYFpH2 tzSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jA43tTQ/"; 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 w21-20020aa79555000000b00597c2ecd86dsi6535640pfq.251.2023.03.13.04.42.57; Mon, 13 Mar 2023 04:43:16 -0700 (PDT) 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="jA43tTQ/"; 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 S231128AbjCMLlo (ORCPT + 99 others); Mon, 13 Mar 2023 07:41:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230449AbjCMLl1 (ORCPT ); Mon, 13 Mar 2023 07:41:27 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 758E065127 for ; Mon, 13 Mar 2023 04:41:03 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id d13so1652396pjh.0 for ; Mon, 13 Mar 2023 04:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707663; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j6kBGPnEPjnrQRBTl/Gpvo8CV0NUMglCUWHrEzVJ/Sc=; b=jA43tTQ/5MyWe2o8ZUk5lS1lsoTHjUFAMFyBBCy7ZsblnFSv/JOleIk5ctj/QB1OoF bUJgmdWeSHg3TmOkIvEe8hfdhqre22AXIVUi0bpG9Zo6Vho45RFu4m9XMfHUt6x9yufN 6u4gu3/sTI0YjdiQgU3GD8+QE+eXfqp9epZWGILkk44SPPPvK+ssZC537q5x1ECMMMXc qIBE5u5z8/uqbkBI8oI9JFMntIJugM1uX4d3pwrefeflOn+yS8zRV2EeteaDfvByjcUk qF7Ifvh6XmOAHRgA4d0+syhrVskvlxJUlaZEuj7taVxDkcWyxIxPx+PGZpTN3H0Vlu9V RsCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707663; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j6kBGPnEPjnrQRBTl/Gpvo8CV0NUMglCUWHrEzVJ/Sc=; b=G+Ba2yBskBG+RosEOMGRrbHBuPHQrk8fwuKFSmDJaxMgkAKdZnVq3+1pqgUhuhMNzC 3xvLev6cwj0xoAA9cxDUa+2znY7uPC6wGZNuU/rgMsOI9Mj62SAoxaE/3kFX4dnkTZYI 8Pynm3eMsl8X7Gs46S4M1iVkZOqhQTXf3lmSjZtVyLt18+q997mC+t4fQD27Bs9+GV8T q5JO0mxA9alDvAKo/Utz2YKluFKjkl5cBx6TGOFVunyzRQUgj3wg1AhUAfwd1SFNPZXr nv+uzPrNo+JJvXl2mwU0gM80gJmiQ4ZmZK8Sbmr5Lnh0b0ulaMHGoXh9sO5mB92vdEIC 5Mqw== X-Gm-Message-State: AO0yUKWpTmUNcjwl/7Yq/ycc/K53GNSj/6YBVbPqxGc/OLmvk0VLQMMQ 26IRsi2Nw+vddgQGrBQVoR6JVg== X-Received: by 2002:a17:902:cf0e:b0:19e:2495:20e0 with SMTP id i14-20020a170902cf0e00b0019e249520e0mr9441697plg.21.1678707662693; Mon, 13 Mar 2023 04:41:02 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:02 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 05/16] perf kvm: Use macro to replace variable 'decode_str_len' Date: Mon, 13 Mar 2023 19:40:07 +0800 Message-Id: <20230313114018.543254-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760252705925058185?= X-GMAIL-MSGID: =?utf-8?q?1760252705925058185?= The variable 'decode_str_len' defines the string length for KVM event name and every arch defines its own values. This introduces complexity that the variable definition are spreading in multiple source files under arch folder. This patch refactors code to use a macro KVM_EVENT_NAME_LEN to define event name length and thus remove the definitions in arch files. Signed-off-by: Leo Yan --- tools/perf/arch/arm64/util/kvm-stat.c | 1 - tools/perf/arch/powerpc/util/kvm-stat.c | 3 +-- tools/perf/arch/s390/util/kvm-stat.c | 1 - tools/perf/arch/x86/util/kvm-stat.c | 7 +++---- tools/perf/builtin-kvm.c | 10 +++++----- tools/perf/util/kvm-stat.h | 3 ++- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/tools/perf/arch/arm64/util/kvm-stat.c b/tools/perf/arch/arm64/util/kvm-stat.c index 73d18e0ed6f6..72ca9bb45804 100644 --- a/tools/perf/arch/arm64/util/kvm-stat.c +++ b/tools/perf/arch/arm64/util/kvm-stat.c @@ -11,7 +11,6 @@ define_exit_reasons_table(arm64_trap_exit_reasons, kvm_arm_exception_class); const char *kvm_trap_exit_reason = "esr_ec"; const char *vcpu_id_str = "id"; -const int decode_str_len = 20; const char *kvm_exit_reason = "ret"; const char *kvm_entry_trace = "kvm:kvm_entry"; const char *kvm_exit_trace = "kvm:kvm_exit"; diff --git a/tools/perf/arch/powerpc/util/kvm-stat.c b/tools/perf/arch/powerpc/util/kvm-stat.c index 1a9b40ea92a5..d04a08c9fd19 100644 --- a/tools/perf/arch/powerpc/util/kvm-stat.c +++ b/tools/perf/arch/powerpc/util/kvm-stat.c @@ -14,7 +14,6 @@ #define NR_TPS 4 const char *vcpu_id_str = "vcpu_id"; -const int decode_str_len = 40; const char *kvm_entry_trace = "kvm_hv:kvm_guest_enter"; const char *kvm_exit_trace = "kvm_hv:kvm_guest_exit"; @@ -80,7 +79,7 @@ static void hcall_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, { const char *hcall_reason = get_hcall_exit_reason(key->key); - scnprintf(decode, decode_str_len, "%s", hcall_reason); + scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", hcall_reason); } static struct kvm_events_ops hcall_events = { diff --git a/tools/perf/arch/s390/util/kvm-stat.c b/tools/perf/arch/s390/util/kvm-stat.c index 34da89ced29a..0aed92df51ba 100644 --- a/tools/perf/arch/s390/util/kvm-stat.c +++ b/tools/perf/arch/s390/util/kvm-stat.c @@ -19,7 +19,6 @@ define_exit_reasons_table(sie_diagnose_codes, diagnose_codes); define_exit_reasons_table(sie_icpt_prog_codes, icpt_prog_codes); const char *vcpu_id_str = "id"; -const int decode_str_len = 40; const char *kvm_exit_reason = "icptcode"; const char *kvm_entry_trace = "kvm:kvm_s390_sie_enter"; const char *kvm_exit_trace = "kvm:kvm_s390_sie_exit"; diff --git a/tools/perf/arch/x86/util/kvm-stat.c b/tools/perf/arch/x86/util/kvm-stat.c index c5dd54f6ef5e..ef513def03ba 100644 --- a/tools/perf/arch/x86/util/kvm-stat.c +++ b/tools/perf/arch/x86/util/kvm-stat.c @@ -18,7 +18,6 @@ static struct kvm_events_ops exit_events = { }; const char *vcpu_id_str = "vcpu_id"; -const int decode_str_len = 20; const char *kvm_exit_reason = "exit_reason"; const char *kvm_entry_trace = "kvm:kvm_entry"; const char *kvm_exit_trace = "kvm:kvm_exit"; @@ -77,7 +76,7 @@ static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, struct event_key *key, char *decode) { - scnprintf(decode, decode_str_len, "%#lx:%s", + scnprintf(decode, KVM_EVENT_NAME_LEN, "%#lx:%s", (unsigned long)key->key, key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R"); } @@ -121,7 +120,7 @@ static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, struct event_key *key, char *decode) { - scnprintf(decode, decode_str_len, "%#llx:%s", + scnprintf(decode, KVM_EVENT_NAME_LEN, "%#llx:%s", (unsigned long long)key->key, key->info ? "POUT" : "PIN"); } @@ -165,7 +164,7 @@ static void msr_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, struct event_key *key, char *decode) { - scnprintf(decode, decode_str_len, "%#llx:%s", + scnprintf(decode, KVM_EVENT_NAME_LEN, "%#llx:%s", (unsigned long long)key->key, key->info ? "W" : "R"); } diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 4e9519390da6..d400434aa137 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -159,7 +159,7 @@ void exit_event_decode_key(struct perf_kvm_stat *kvm, const char *exit_reason = get_exit_reason(kvm, key->exit_reasons, key->key); - scnprintf(decode, decode_str_len, "%s", exit_reason); + scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason); } static bool register_kvm_events_ops(struct perf_kvm_stat *kvm) @@ -432,7 +432,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, time_diff = sample->time - time_begin; if (kvm->duration && time_diff > kvm->duration) { - char decode[decode_str_len]; + char decode[KVM_EVENT_NAME_LEN]; kvm->events_ops->decode_key(kvm, &event->key, decode); if (!skip_event(decode)) { @@ -603,7 +603,7 @@ static void show_timeofday(void) static void print_result(struct perf_kvm_stat *kvm) { - char decode[decode_str_len]; + char decode[KVM_EVENT_NAME_LEN]; struct kvm_event *event; int vcpu = kvm->trace_vcpu; @@ -614,7 +614,7 @@ static void print_result(struct perf_kvm_stat *kvm) pr_info("\n\n"); print_vcpu_info(kvm); - pr_info("%*s ", decode_str_len, kvm->events_ops->name); + pr_info("%*s ", KVM_EVENT_NAME_LEN, kvm->events_ops->name); pr_info("%10s ", "Samples"); pr_info("%9s ", "Samples%"); @@ -633,7 +633,7 @@ static void print_result(struct perf_kvm_stat *kvm) min = get_event_min(event, vcpu); kvm->events_ops->decode_key(kvm, &event->key, decode); - pr_info("%*s ", decode_str_len, decode); + pr_info("%*s ", KVM_EVENT_NAME_LEN, decode); pr_info("%10llu ", (unsigned long long)ecount); pr_info("%8.2f%% ", (double)ecount / kvm->total_count * 100); pr_info("%8.2f%% ", (double)etime / kvm->total_time * 100); diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 40a4b66cfee6..e84f1cdcfe05 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -8,6 +8,8 @@ #include "stat.h" #include "record.h" +#define KVM_EVENT_NAME_LEN 40 + struct evsel; struct evlist; struct perf_session; @@ -143,7 +145,6 @@ extern const char *kvm_events_tp[]; extern struct kvm_reg_events_ops kvm_reg_events_ops[]; extern const char * const kvm_skip_events[]; extern const char *vcpu_id_str; -extern const int decode_str_len; extern const char *kvm_exit_reason; extern const char *kvm_entry_trace; extern const char *kvm_exit_trace; From patchwork Mon Mar 13 11:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68785 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1136427wrd; Mon, 13 Mar 2023 04:54:32 -0700 (PDT) X-Google-Smtp-Source: AK7set/hO9qCznnIdv/oAUevKRiDIfsdn+EIr9TX8QOyP46r/NT4ZeihW9r575miwz5c8VG9yzae X-Received: by 2002:a17:902:d512:b0:196:704e:2c9a with SMTP id b18-20020a170902d51200b00196704e2c9amr40326993plg.22.1678708472215; Mon, 13 Mar 2023 04:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678708472; cv=none; d=google.com; s=arc-20160816; b=qQ16WAVkHdIrtMBogXX80ONKKswU+ZXD1hjhD7NE27ixA/bpq2sC9Bp0h8c4V8k1el ODEJuD8kYA4WWEWW1b+wSsikiQV6Uzj4R5Y+F4WXCNmo6fC2nhwOFAAW9w0kQAuW3DDl 4c/KSV2++lRMd1ta5yKclDYKtI4JtBhzmQP3UDUq/soi2m+OXhhmRWEOKhyWZcuyPeO5 2DbzrSyDfXtw/+hn7vKvI2xfMHi9B5DDiSv9ePzZmdTWhUsFoCz+NUDDDB3g4h3ovoZ6 sx1dd2288YUfHIRuklDDq2UoxKvEZPzNzHNEAjTBKW5SoAL5P6TRZqhFgiw8f/yYhAGV IJqg== 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=qSdUbtxY1+Pylww6c27L2gmYy3OoEmd30YUAl5uUuD4=; b=yn/RD406W3rwvoBUWCl2PumaOJKqE15Mjt+lO6M/J8j/CG1bCkB93+0zNajNh7z1zE IiHhCZtMAeWiwq86/AKe/ay6RA7qfWHrHQhk6hJ0yORTKuDgOPPj02ZotKMHMxujefPY OHzOmCajEmk9/IcO5r7zpcXDlBMBLx4w8HxqpxaFhUxzmaQXWT6y/xK0gkeJntAhbzOJ 0qJIT5rk0oP6CXqxy7sAJDIKdwwToIRFA+KnZQsTADKimIbLOdH/f5iv22eHrHVM9OJT rtVr8GC8VejGwo96l96tW39WaOkx9DTFfuUv8KX+h6ZNteC+9JyNKmAI9BciFrFletaX R/vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JdCN4Dnj; 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 z3-20020a170902d54300b0019cafd4c385si4480742plf.408.2023.03.13.04.54.17; Mon, 13 Mar 2023 04:54:32 -0700 (PDT) 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=JdCN4Dnj; 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 S231209AbjCMLmA (ORCPT + 99 others); Mon, 13 Mar 2023 07:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231158AbjCMLlb (ORCPT ); Mon, 13 Mar 2023 07:41:31 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98FDA64AB8 for ; Mon, 13 Mar 2023 04:41:07 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id h11-20020a17090a2ecb00b00237c740335cso11358056pjs.3 for ; Mon, 13 Mar 2023 04:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707667; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qSdUbtxY1+Pylww6c27L2gmYy3OoEmd30YUAl5uUuD4=; b=JdCN4DnjsIz8YM3uGExs6pbkHrIiWnJ/jCXj3wqhLn3yYf0rTHXThsN/8y65TcJYDH ORkO3CS9JgQi6TrHXBccQXUpAOoxrP3021V2614gp/rDRlP3XvIYGQMKNzOicBpd25ZY 1M/Ya7gznDe5xSpPhVONXi38ESzr9rkKoMeRnkyDrc62UjSY4LQ0l9U3SxEo3L4pOI5g wkbaVz0+wa8QCUqXc0INVPCGd9WXY/NqWEqahFhnCk4Uzp2aAasqU2mt8UZBzE4roxT6 j+THZ/H8Vb39Kj59OrEIRBUKLdFZ68n6gMWKI4H9zJaM5ShqvCeI4HPKnC0C/5Cp3PBL 7BZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707667; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qSdUbtxY1+Pylww6c27L2gmYy3OoEmd30YUAl5uUuD4=; b=OIqMjo+YQEFfzuNBsZgzTAd5bIUskRwf3JbCgk2cVwhSnHAaALQoKhvNI+G9DOnMOC 5Gt+DpnHpKJBkj+ugGnjz3fqQX6CFCCRkG5VMSYehjkc6hMTRwT5WSGyZMsJQLvoZPac gzr5bVZHBFyScT4zoekun6J1rXZhwltUFkjslwNLuwf7XozH9E3Rl0yP8H9zCdNaWwBZ DdJAOtHCIk5/GyHncCKZYVfCn0keiw+BqYrt09z6j6KablYYb6XyQwszgali4V1ochBa 1JqRb/LY0608cKhlHwpWOHs28/p3qIXj0wMX1PmfbjlKqLUsoMJl5MLtaIw1gh0soA/k +glg== X-Gm-Message-State: AO0yUKW/TWJ0ZzjB8r9lar+BqZk0Q4MVSGPGI/ZKGNbU9TWnvahhyVYm AuVK7DlGzBlyh20OCVn9rNgp4A== X-Received: by 2002:a17:90b:4d04:b0:230:81e9:ebb4 with SMTP id mw4-20020a17090b4d0400b0023081e9ebb4mr33650785pjb.10.1678707667093; Mon, 13 Mar 2023 04:41:07 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:06 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 06/16] perf kvm: Introduce histograms data structures Date: Mon, 13 Mar 2023 19:40:08 +0800 Message-Id: <20230313114018.543254-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760253414734314421?= X-GMAIL-MSGID: =?utf-8?q?1760253414734314421?= This is a preparation to support histograms in perf kvm tool. As first step, this patch defines histograms data structures and initialize them. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 18 ++++++++++++++++++ tools/perf/util/kvm-stat.h | 1 + 2 files changed, 19 insertions(+) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index d400434aa137..384992c8a01a 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -85,6 +85,20 @@ static struct kvm_event_key keys[] = { { NULL, NULL } }; +struct kvm_hists { + struct hists hists; + struct perf_hpp_list list; +}; + +static struct kvm_hists kvm_hists; + +static int kvm_hists__init(void) +{ + __hists__init(&kvm_hists.hists, &kvm_hists.list); + perf_hpp_list__init(&kvm_hists.list); + return 0; +} + static const char *get_filename_for_perf_kvm(void) { const char *filename; @@ -957,6 +971,8 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm) set_term_quiet_input(&save); init_kvm_event_record(kvm); + kvm_hists__init(); + signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); @@ -1152,6 +1168,8 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) init_kvm_event_record(kvm); setup_pager(); + kvm_hists__init(); + ret = read_events(kvm); if (ret) goto exit; diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index e84f1cdcfe05..a53cebe519b3 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -5,6 +5,7 @@ #ifdef HAVE_KVM_STAT_SUPPORT #include "tool.h" +#include "sort.h" #include "stat.h" #include "record.h" From patchwork Mon Mar 13 11:40:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1136073wrd; Mon, 13 Mar 2023 04:53:35 -0700 (PDT) X-Google-Smtp-Source: AK7set+Eu1pXmVLNkivLaO6lFN365HPopA7ndwKH1CJMoX7u5LpaVQnW2BHiyeUnQ3+LKfJ874bL X-Received: by 2002:a17:902:da8d:b0:19b:33c0:409e with SMTP id j13-20020a170902da8d00b0019b33c0409emr40677400plx.50.1678708415071; Mon, 13 Mar 2023 04:53:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678708415; cv=none; d=google.com; s=arc-20160816; b=UpL5N9k8xhPV4r6IyXXabMc0Ok403fgaFFS6VpkrDVPjPTASSt8TxofLeOywrn6iux nQGrjWz+BWTq3qDANqvW64kjqMEzhYrLaQ+337pCKsmiEeWD4YwhWJOi8e2PXNeN0Yf4 AXqQ1SaHxc9lddL5SpmznEvWUDDUYu+h85joU7c4ffUDvYG7Jg5TygR++ibom/V34lxn SJm/FNj1rnnhVv4Rd+O/TxMEHAUOXGXCkIu7INVVaHb+bZhuyyx00KmmM5/Gd5dqPhuX 7aTZajyXllX0HvBbIxGPslLYkSG/UZNc/Dqrq/SevnF/7RWx7g9IKRcECnNhyzsdOuTt d2ag== 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=5IYKqlpTPvf4B9W/g9ZH0t1bS6GpjcqsifmwRVPlTPE=; b=A4w89z2GIfSIug/dAZQKa9hEZ7m7m9yURarVJG3920HuKVJCbF0ao99dXXCbgUB7n9 afnNBYo/Zc/gkKGLivaSkxcuRyNa7b0xuuWeKaetNbkV5A41NQLuIsRa40a+J62ObuQ1 lr8byFyQhUzF1CuazA4Df8qaVfcXsmv7WHSqQ0/Nwnv3woP0u4E2+goL10ujCmOfoGX5 eNDVZVacT+kh2pgHBtlbLhE2WCbgZrtGZnkazy7PoVBgw4R8q3G3bt03gTnaUluNe+B1 A/K7DYucGYBbwlH2z7E/MNT7rJiCW6c9ghbC4bHRFyuzXgp5XrqxjUw6lWniAtsAFk5H moJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S4r7hqot; 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 io23-20020a17090312d700b0019e3ffa255asi6696349plb.184.2023.03.13.04.53.20; Mon, 13 Mar 2023 04:53:35 -0700 (PDT) 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=S4r7hqot; 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 S230514AbjCMLmD (ORCPT + 99 others); Mon, 13 Mar 2023 07:42:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230448AbjCMLli (ORCPT ); Mon, 13 Mar 2023 07:41:38 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C23F130192 for ; Mon, 13 Mar 2023 04:41:11 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id l1so11705581pjt.2 for ; Mon, 13 Mar 2023 04:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5IYKqlpTPvf4B9W/g9ZH0t1bS6GpjcqsifmwRVPlTPE=; b=S4r7hqotk6HS7rVbQXptLHHawPHLQynLpKGSY1VkolIE/P7FIMKBjLWIAuTMlYpreq OpQKBFi5ELO1PnYucscKkPnLEjMjjcEWnPEzYU7ytndE+WEUtal3s+Vuq+qmhfyhr7Hn w8q8zJL17SnHalrey6tGzfGbCBMsG1MI2S99ksy/jyXPRhaaJlb87m9yXuhMNT6GSMIT zh/2h+0qkJiMZcpqK//u3Zbg92xNu8jgOUWSZK78rUOkIYSv4hugoVxwXf2DON74U4A/ ge5qgcoBGN+29Sybdw5CrYfFGmz+88pNqkrDFDSr6nKTlZ2yWvkgO4IbbVQHK0strO+l LQyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5IYKqlpTPvf4B9W/g9ZH0t1bS6GpjcqsifmwRVPlTPE=; b=Ulm4kFzD5Nk1Pz68qWJbBKYF36/8x0NdEsqR3I4HufNwz78T6CGv6sjl8qiBTX/Apn KPgbXHAvWRfriaDcUH1Jg/7g8r8kb9+q8G/HbZJ3EBUjaXLTuhGjs69ETi1RQFr7/ikR 0CSYXzaxrJfQJKSWR0rsmwsGqBVpcMTgmUbssCXncRwpIoDdzj6ZtDxJCFyTp304b4Pe IrbMAyrrbluZrwpMUBM4umjy+Gu/kE2I/fgYMe53Ap52uRnxncf9JNn2x7UQUKpizEN3 W83Ut7qzqqoM2kwCngt+LdM+SgQMLzQyGW8cYT5OFurinvsCR6GQ14N9WRErTZNP3EO1 PbSQ== X-Gm-Message-State: AO0yUKWAEMLYPAmp7T4YYzi5K4LB8kSR+p3cM/sw9Am1ktx9+vQGb1yi trZAHMi4kn0us+vyQlrTSHCI0g== X-Received: by 2002:a17:90a:728d:b0:23b:4f2a:8026 with SMTP id e13-20020a17090a728d00b0023b4f2a8026mr4863481pjg.48.1678707671340; Mon, 13 Mar 2023 04:41:11 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:11 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 07/16] perf kvm: Pass argument 'sample' to kvm_alloc_init_event() Date: Mon, 13 Mar 2023 19:40:09 +0800 Message-Id: <20230313114018.543254-8-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760253355382707771?= X-GMAIL-MSGID: =?utf-8?q?1760253355382707771?= This patch adds an argument 'sample' for kvm_alloc_init_event(), and its caller functions are updated as well for passing down the 'sample' pointer. This is a preparation change to allow later patch to create histograms entries for kvm event, no any functionality changes. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 384992c8a01a..5ea723fd45a4 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -260,7 +260,8 @@ static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) } static struct kvm_event *kvm_alloc_init_event(struct perf_kvm_stat *kvm, - struct event_key *key) + struct event_key *key, + struct perf_sample *sample __maybe_unused) { struct kvm_event *event; @@ -277,7 +278,8 @@ static struct kvm_event *kvm_alloc_init_event(struct perf_kvm_stat *kvm, } static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, - struct event_key *key) + struct event_key *key, + struct perf_sample *sample) { struct kvm_event *event; struct list_head *head; @@ -290,7 +292,7 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, return event; } - event = kvm_alloc_init_event(kvm, key); + event = kvm_alloc_init_event(kvm, key, sample); if (!event) return NULL; @@ -300,15 +302,16 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, static bool handle_begin_event(struct perf_kvm_stat *kvm, struct vcpu_event_record *vcpu_record, - struct event_key *key, u64 timestamp) + struct event_key *key, + struct perf_sample *sample) { struct kvm_event *event = NULL; if (key->key != INVALID_KEY) - event = find_create_kvm_event(kvm, key); + event = find_create_kvm_event(kvm, key, sample); vcpu_record->last_event = event; - vcpu_record->start_time = timestamp; + vcpu_record->start_time = sample->time; return true; } @@ -375,12 +378,12 @@ static bool is_child_event(struct perf_kvm_stat *kvm, static bool handle_child_event(struct perf_kvm_stat *kvm, struct vcpu_event_record *vcpu_record, struct event_key *key, - struct perf_sample *sample __maybe_unused) + struct perf_sample *sample) { struct kvm_event *event = NULL; if (key->key != INVALID_KEY) - event = find_create_kvm_event(kvm, key); + event = find_create_kvm_event(kvm, key, sample); vcpu_record->last_event = event; @@ -429,7 +432,7 @@ static bool handle_end_event(struct perf_kvm_stat *kvm, return true; if (!event) - event = find_create_kvm_event(kvm, key); + event = find_create_kvm_event(kvm, key, sample); if (!event) return false; @@ -500,7 +503,7 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, return true; if (kvm->events_ops->is_begin_event(evsel, sample, &key)) - return handle_begin_event(kvm, vcpu_record, &key, sample->time); + return handle_begin_event(kvm, vcpu_record, &key, sample); if (is_child_event(kvm, evsel, sample, &key)) return handle_child_event(kvm, vcpu_record, &key, sample); From patchwork Mon Mar 13 11:40:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68762 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1131954wrd; Mon, 13 Mar 2023 04:43:21 -0700 (PDT) X-Google-Smtp-Source: AK7set+2wuVDzkr0fArM+gz/vMYU/ZZIMSRJsFX9HL0nPu04BbkeynnVBgmqDOJ2qr0ODPMj9Lh+ X-Received: by 2002:a05:6a20:8ec6:b0:d3:7ac3:bc9e with SMTP id m6-20020a056a208ec600b000d37ac3bc9emr6224512pzk.49.1678707800961; Mon, 13 Mar 2023 04:43:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678707800; cv=none; d=google.com; s=arc-20160816; b=xmdUtQ2rbJ/5VFyjeLFxIrJIOuYBygeWUyY3ca7/S60l+8jx9J37p0i2W+8aEHHNsY +zkUGHdywXtIH110nRd88yDycFt1eCUylWaLT9Q0b1YmsCeNLcsvs2+cGPu5v99aNqhP ogmvGD/rV2IqlwACPdjh1hPTnoKt5GAwYsCD0J/q08rA6j45oJ8e5Qs/V6IimvN8EHx8 kRlIbpZnV9jEnrqxe+F1dM+EQ9NSU8TuT75K+vt/G9v62d3iYX+oH5PA2c1Ca141udVl UoaK6Is9wb3dMRVfou83ydmi3g0WPxaTBkfa0dh5jQ8qLo78VOPZ8O0U595T3D52RwOD c6bg== 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=ygfxx0XS0Skh5yEpdT4mJzv/3MvrNT373bzz9DkGUB4=; b=QXuGxzIikzUsmnOe8UCv+19sJ6bnokOB3NLWQxAahS04f5oOXRrWwVK4O5thsu2Srq dweKa4FxIDAJAAHbS2hfSx9BgJY1YfJC8Th9EFlGLQ2no7Ab196vqSX0F8vCQMb/LG1x N2GXMZd0eDqpCuirFxFYOM/LpL+HQMiQMspsS4UM7KsiFRJOndJD71n8dKPqmfLz3E+v pwQjDtgG5k4JZaIvZCWRS13GjjKOjBgUN5Edy8idLqcpszPk6e7R5kuBXFUxtzjkex8D BBUZEFVo85T6EyqksLmKicKjLGwQuqvqww15K/5uCcdAbzEs6wJcmOoYX44JpL7UhKWh 8cqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wx+waaKf; 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 69-20020a630048000000b004fb1ed5239csi6434779pga.364.2023.03.13.04.43.02; Mon, 13 Mar 2023 04:43:20 -0700 (PDT) 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=Wx+waaKf; 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 S231239AbjCMLmO (ORCPT + 99 others); Mon, 13 Mar 2023 07:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231133AbjCMLlt (ORCPT ); Mon, 13 Mar 2023 07:41:49 -0400 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 4A9E664B1F for ; Mon, 13 Mar 2023 04:41:16 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id u3-20020a17090a450300b00239db6d7d47so11350129pjg.4 for ; Mon, 13 Mar 2023 04:41:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ygfxx0XS0Skh5yEpdT4mJzv/3MvrNT373bzz9DkGUB4=; b=Wx+waaKfMUU6sOzzAcpMsIz/5BgPy51Sblvw1oxRbHogJwZiGABhiwdqf6tgtxoeoz 5oLuApkLypxZxAgAxFFdYLgGGYrQ1oxxygX8eLckC+tNwe3Lvmr2hCowAnbpyb9GNbKm QvDKXioBA7ru6YXqZwqdYfvJiDCmS9SpsKYfkuO8tOfP25d8qeV3edxXdljXuEqXg6TQ O0Z2T6EvHYY/utz6arVSdDaDdJmg8/At3PxKKCDTA70ongM5sI/D4cLdE0498R74b4Ps jnATtrCs+a5HB49xL9Vwdt2CaQP0OnVDyXwEFu/AEMLqiLAqQirFqrhQ/TmV7E0M8OXx n+Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ygfxx0XS0Skh5yEpdT4mJzv/3MvrNT373bzz9DkGUB4=; b=JvCDFU5L0FtkHsWaENyftonN+Z0EYWaNBl6Te1anj2FQHEoDoCD+Hf+1s7Uag/PET0 IF3sMRPshYDpnYlCTCnwP7C+QIXrCtpY7nqBr0aLMM+xN9jsCxssQdGb5gMmvijK89rF 5xe/BxtJUE1CAAonMzcko4CW3vsLArBId3XwevQ6KfS2/Rr2LIX1HfG0btJWa9kCzP06 SLmoZ0VG4UJ0aHuAf2PeD8GU1nwiwQH3mG+d+GkJh9+z/mxMDiyB61KmTRqTqZmcPmXN onUmO8vtyzN2dpqiSKKkEZ8VkosZW5I4aM/3hb64xKCHuhn9zS1JBxuROWzi9M9MaBsX uC2Q== X-Gm-Message-State: AO0yUKWtGfyErP85T0zFTyxnIyYPPbyrj4RSptN3me4zF3T/8XLn9x3X 5wVzgb6fOQW1HmQXsTLKzlLAlw== X-Received: by 2002:a17:90a:3ea3:b0:23b:4614:6f84 with SMTP id k32-20020a17090a3ea300b0023b46146f84mr6304138pjc.28.1678707675655; Mon, 13 Mar 2023 04:41:15 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:15 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 08/16] perf kvm: Parse address location for samples Date: Mon, 13 Mar 2023 19:40:10 +0800 Message-Id: <20230313114018.543254-9-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760252711200319551?= X-GMAIL-MSGID: =?utf-8?q?1760252711200319551?= Parse address location for samples and save it into the structure 'perf_kvm_stat', it is to be used by histograms entry. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 5 +++++ tools/perf/util/kvm-stat.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 5ea723fd45a4..fa91c8deb628 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -704,6 +704,11 @@ static int process_sample_event(struct perf_tool *tool, if (skip_sample(kvm, sample)) return 0; + if (machine__resolve(machine, &kvm->al, sample) < 0) { + pr_warning("Fail to resolve address location, skip sample.\n"); + return 0; + } + thread = machine__findnew_thread(machine, sample->pid, sample->tid); if (thread == NULL) { pr_debug("problem processing %d event, skipping it.\n", diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index a53cebe519b3..2d791b04379a 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -7,6 +7,7 @@ #include "tool.h" #include "sort.h" #include "stat.h" +#include "symbol.h" #include "record.h" #define KVM_EVENT_NAME_LEN 40 @@ -88,6 +89,9 @@ struct perf_kvm_stat { const char *sort_key; int trace_vcpu; + /* Used when process events */ + struct addr_location al; + struct exit_reasons_table *exit_reasons; const char *exit_reasons_isa; From patchwork Mon Mar 13 11:40:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1132499wrd; Mon, 13 Mar 2023 04:44:47 -0700 (PDT) X-Google-Smtp-Source: AK7set/tPYgg3BTqbC+ivLsJ8GLOQR4kX/QfU4pQxv3pWRPCaCQRrepWKdQWwnfv8b/qwp4VaRtE X-Received: by 2002:a17:903:32c3:b0:1a0:4423:b1bd with SMTP id i3-20020a17090332c300b001a04423b1bdmr5368262plr.7.1678707887423; Mon, 13 Mar 2023 04:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678707887; cv=none; d=google.com; s=arc-20160816; b=wjy//fPvzqZQ1OD+SEwUpLzrY5qQ3PQuNlIo6BPdFjoJ07k9/lnGUv5vvoxV1wuREE 7LCJCPmQ4EvIYt43/6b8baN1KPngAkfzJt5Gu1SzJaDVWix9IcRCGnRyzrtPnOj5szwV f8N7cgBq45dgWLhuG4sO4OzzAkTOIIfhGc/tUKIK5i6hKSNV5TRr+EGVnFN6bT9np9K4 u8wuTKHfx/YMB7ElMtFSkMHSsRO4QOn1utYv7/m9+tcfleJ7Ji2X2Ps8j2t/WPRRd942 hLc34h6QJhwWWqwhct/4Hj5Zu+hiM2l6KnqzZ2XNkJX8P5nIYDIu6RAVdpFyPwInJmQJ HK/A== 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=5MNnE3quOGvdDqG29dvywID+kT+Z2WHpLbe0kchj83s=; b=NdXMS11/mbWPDaLUWwA+88p3pInJYpO9qI3UkOpGCX7H3R16jY6LWWfDAs3jSEbcM5 Bg1pOyz5shGJ8TgGj8OTn+c6/hI9kaLb6REy2Km74r1vFuVGzdLgOrjuKV8HhAYnbzE+ wFCG+QToKVlh2B+QoZmtLWdvO1GxRcmVJUFdRLGstUBaDIA/tXzoSWGjgH/06b0DHaqN l1CtEQjn2xXMMdo6nO1rlN3O0TPaWd9BhZfU73Is7Gh72jg7iVej84vAQdIzAZV/Egtp p+BPiDoV8s7NGsDCJl4Mft2nN+ChD8JJYOPhSDqSoNiApd2b33wo00lIbYb5RxOIQw6o SbhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iHjA3HW8; 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 142-20020a630094000000b00508aefbec7asi5677696pga.300.2023.03.13.04.44.32; Mon, 13 Mar 2023 04:44:47 -0700 (PDT) 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=iHjA3HW8; 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 S231279AbjCMLm0 (ORCPT + 99 others); Mon, 13 Mar 2023 07:42:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231201AbjCMLl6 (ORCPT ); Mon, 13 Mar 2023 07:41:58 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4E3D65C79 for ; Mon, 13 Mar 2023 04:41:23 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id cp7-20020a17090afb8700b0023756229427so16615193pjb.1 for ; Mon, 13 Mar 2023 04:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5MNnE3quOGvdDqG29dvywID+kT+Z2WHpLbe0kchj83s=; b=iHjA3HW8bxjICMYAwwBDMXriyMjyCoGNWZ/IveRUvJW4I6xPCm7LH5JpBJLKACCqtE 2oxp+1EWlDjdTKJ4/7d9ZN8D1toR6VnB+osaCLpwEqUe0DTvc3wYuVBYyEOQdZvtdiaC laxiGP4xy8G5J+LrjSJJrHZUUvj+MM7njQJQyNbHlbfC882XG6Lte6uXLiOoVK1QfVOT v/dOWRujYZN80ljZDW+MbMxBF6pj0uCLYwyh3TVCxnwaFkEB5r0+IYVIpxnYRWaep+4T cBAfNOMFs8o05/YvHuF8EICP5jVx55lYWeaCb0V/TlADMTa/ceQuk8iAGV5O9iFZuKFZ sumQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5MNnE3quOGvdDqG29dvywID+kT+Z2WHpLbe0kchj83s=; b=bsy7i57ZyOMu4iN8LtPzTTtkB9UbHXY7RIbo9xoHVi5ZKEvVnGI9zYA0K6gDkySYuO Znve4kNZF/WajuBBBNzquBQpzJQeEpJlluNTeAQS2bhvfka5BvabzWSyERflNu21hXmR fk8KT7NyuQRK0Fs26DC0lY/SGRLJjNBoFPE0/XKDT7o19Q3HIiPjetBvO3jRFFV2EADo JqN+0Dy7Tu35JY30MiqxAAhehQgucVOQ6KeFThbo4jLNhZxuRfEMrjLKCPFbP5/FcdTA 9ssHCQUcAuKZpyAlSIRiIIPk/ap134fucx7Wvyj5JCou5WIihaZEUwC+bjl5f2WIjf1n BDGA== X-Gm-Message-State: AO0yUKUpMl2d0hQnpbXggvLx0LEF8UHOsO4Z1e3LGjX11zj8L64h1KQF aeJLtiLnqE57LTXG8avhoedsQw== X-Received: by 2002:a17:90b:33ce:b0:234:5eb:2177 with SMTP id lk14-20020a17090b33ce00b0023405eb2177mr36787199pjb.9.1678707680030; Mon, 13 Mar 2023 04:41:20 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:19 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 09/16] perf hist: Add 'kvm_info' field in histograms entry Date: Mon, 13 Mar 2023 19:40:11 +0800 Message-Id: <20230313114018.543254-10-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760252801529378018?= X-GMAIL-MSGID: =?utf-8?q?1760252801529378018?= __hists__add_entry() creates a temporary entry and compare it with existed histograms entries, if any existed entry equals to the temporary entry it skips to allocation to avoid duplication. The problem for support KVM event in histograms is it doesn't contain any info to identify KVM event and can be used for comparison entries. This patch adds 'kvm_info' field in the histograms entry which contains the KVM event's key, this identifier will be used for comparison histograms entries in later change. Signed-off-by: Leo Yan --- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-c2c.c | 4 ++-- tools/perf/builtin-diff.c | 4 ++-- tools/perf/tests/hists_link.c | 4 ++-- tools/perf/util/hist.c | 19 ++++++++++++------- tools/perf/util/hist.h | 3 +++ tools/perf/util/kvm-stat.h | 4 ++++ tools/perf/util/sort.h | 1 + 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 90458ca6933f..4750fac7bf93 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -252,7 +252,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample, if (ann->has_br_stack && has_annotation(ann)) return process_branch_callback(evsel, sample, al, ann, machine); - he = hists__add_entry(hists, al, NULL, NULL, NULL, sample, true); + he = hists__add_entry(hists, al, NULL, NULL, NULL, NULL, sample, true); if (he == NULL) return -ENOMEM; diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 56974eae0638..d3181fee4d3d 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -315,7 +315,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, c2c_decode_stats(&stats, mi); he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, - &al, NULL, NULL, mi, + &al, NULL, NULL, mi, NULL, sample, true); if (he == NULL) goto free_mi; @@ -349,7 +349,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, goto free_mi; he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, - &al, NULL, NULL, mi, + &al, NULL, NULL, mi, NULL, sample, true); if (he == NULL) goto free_mi; diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index ed07cc6cca56..22b526766e14 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -423,7 +423,7 @@ static int diff__process_sample_event(struct perf_tool *tool, switch (compute) { case COMPUTE_CYCLES: if (!hists__add_entry_ops(hists, &block_hist_ops, &al, NULL, - NULL, NULL, sample, true)) { + NULL, NULL, NULL, sample, true)) { pr_warning("problem incrementing symbol period, " "skipping event\n"); goto out_put; @@ -442,7 +442,7 @@ static int diff__process_sample_event(struct perf_tool *tool, break; default: - if (!hists__add_entry(hists, &al, NULL, NULL, NULL, sample, + if (!hists__add_entry(hists, &al, NULL, NULL, NULL, NULL, sample, true)) { pr_warning("problem incrementing symbol period, " "skipping event\n"); diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c index 14b2ff808b5e..e7e4ee57ce04 100644 --- a/tools/perf/tests/hists_link.c +++ b/tools/perf/tests/hists_link.c @@ -87,7 +87,7 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine) goto out; he = hists__add_entry(hists, &al, NULL, - NULL, NULL, &sample, true); + NULL, NULL, NULL, &sample, true); if (he == NULL) { addr_location__put(&al); goto out; @@ -106,7 +106,7 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine) goto out; he = hists__add_entry(hists, &al, NULL, - NULL, NULL, &sample, true); + NULL, NULL, NULL, &sample, true); if (he == NULL) { addr_location__put(&al); goto out; diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index b6e4b4edde43..3670136a0074 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -4,6 +4,7 @@ #include "dso.h" #include "build-id.h" #include "hist.h" +#include "kvm-stat.h" #include "map.h" #include "map_symbol.h" #include "branch.h" @@ -698,6 +699,7 @@ __hists__add_entry(struct hists *hists, struct symbol *sym_parent, struct branch_info *bi, struct mem_info *mi, + struct kvm_info *ki, struct block_info *block_info, struct perf_sample *sample, bool sample_self, @@ -733,6 +735,7 @@ __hists__add_entry(struct hists *hists, .hists = hists, .branch_info = bi, .mem_info = mi, + .kvm_info = ki, .block_info = block_info, .transaction = sample->transaction, .raw_data = sample->raw_data, @@ -756,10 +759,11 @@ struct hist_entry *hists__add_entry(struct hists *hists, struct symbol *sym_parent, struct branch_info *bi, struct mem_info *mi, + struct kvm_info *ki, struct perf_sample *sample, bool sample_self) { - return __hists__add_entry(hists, al, sym_parent, bi, mi, NULL, + return __hists__add_entry(hists, al, sym_parent, bi, mi, ki, NULL, sample, sample_self, NULL); } @@ -769,10 +773,11 @@ struct hist_entry *hists__add_entry_ops(struct hists *hists, struct symbol *sym_parent, struct branch_info *bi, struct mem_info *mi, + struct kvm_info *ki, struct perf_sample *sample, bool sample_self) { - return __hists__add_entry(hists, al, sym_parent, bi, mi, NULL, + return __hists__add_entry(hists, al, sym_parent, bi, mi, ki, NULL, sample, sample_self, ops); } @@ -846,7 +851,7 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al */ sample->period = cost; - he = hists__add_entry(hists, al, iter->parent, NULL, mi, + he = hists__add_entry(hists, al, iter->parent, NULL, mi, NULL, sample, true); if (!he) return -ENOMEM; @@ -949,7 +954,7 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a sample->period = 1; sample->weight = bi->flags.cycles ? bi->flags.cycles : 1; - he = hists__add_entry(hists, al, iter->parent, &bi[i], NULL, + he = hists__add_entry(hists, al, iter->parent, &bi[i], NULL, NULL, sample, true); if (he == NULL) return -ENOMEM; @@ -987,7 +992,7 @@ iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location struct hist_entry *he; he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, - sample, true); + NULL, sample, true); if (he == NULL) return -ENOMEM; @@ -1047,7 +1052,7 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter, struct hist_entry *he; int err = 0; - he = hists__add_entry(hists, al, iter->parent, NULL, NULL, + he = hists__add_entry(hists, al, iter->parent, NULL, NULL, NULL, sample, true); if (he == NULL) return -ENOMEM; @@ -1148,7 +1153,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, } he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, - sample, false); + NULL, sample, false); if (he == NULL) return -ENOMEM; diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index d93a4e510dc7..86a677954279 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -14,6 +14,7 @@ struct hist_entry_ops; struct addr_location; struct map_symbol; struct mem_info; +struct kvm_info; struct branch_info; struct branch_stack; struct block_info; @@ -150,6 +151,7 @@ struct hist_entry *hists__add_entry(struct hists *hists, struct symbol *parent, struct branch_info *bi, struct mem_info *mi, + struct kvm_info *ki, struct perf_sample *sample, bool sample_self); @@ -159,6 +161,7 @@ struct hist_entry *hists__add_entry_ops(struct hists *hists, struct symbol *sym_parent, struct branch_info *bi, struct mem_info *mi, + struct kvm_info *ki, struct perf_sample *sample, bool sample_self); diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 2d791b04379a..43dd6472fa50 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -23,6 +23,10 @@ struct event_key { struct exit_reasons_table *exit_reasons; }; +struct kvm_info { + char name[KVM_EVENT_NAME_LEN]; +}; + struct kvm_event_stats { u64 time; struct stats stats; diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index d79a100e5999..22f437c3476f 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -144,6 +144,7 @@ struct hist_entry { struct hists *hists; struct mem_info *mem_info; struct block_info *block_info; + struct kvm_info *kvm_info; void *raw_data; u32 raw_size; int num_res; From patchwork Mon Mar 13 11:40:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1135873wrd; Mon, 13 Mar 2023 04:53:02 -0700 (PDT) X-Google-Smtp-Source: AK7set/5VHoajcHDzrt6TpHLCtdKzshhP68DnLb1DhyLLWSx9mGWKdK0EudqLQHfszU2VCqijudU X-Received: by 2002:a17:903:2446:b0:19c:d78b:cdc with SMTP id l6-20020a170903244600b0019cd78b0cdcmr44400965pls.5.1678708381872; Mon, 13 Mar 2023 04:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678708381; cv=none; d=google.com; s=arc-20160816; b=ZegxHUNFkvibnyj6wbidqIOY74TvBwPxD22GZKluaVjx8LXCVDLz6uwO1FeQNYhCwI I/PhEgay8GEKd6YiqwiRr10lgK4PhjU6rz5Rrp3kO+kCrMXuqBUZpxit1yizxQi5B0rt XOpwDma8o3wbEtQLJglnb8vp9EauHwvMOLXSXBv7gNux7KT+xaYH+5twHYueYShLk6Ik CGMSsDYT6CLoflrnj78BN0oxfeHk3YafZWxOHR4YHKBmzygYQV2JWcRssiF6+19Wa2I5 4j51UTmM3I23EOqNn9zOOQW/O5h4enVAKJvxmIBj0rWxk/Zxh3oetdPepBkn2isTlsBo u0qw== 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=a36C9sWQdmAM0bfeAU4tZKbhIdnBMA6DO8wWZqH9jAY=; b=Ce2WEA+5Zeq1/1CDB1QFfhZ/VA5nqb/SjJIuDXkr2oX40JR2CzFpAqzLfPgweCoBRR 4qKDIRh7blV1gXYWqVbCnY8iSeo8yUuJlCRF4DSo/CtGtMW3fhztWk2aAtdNKxuRNEZ3 qPp0wn+Ya8HGlVG0eqlCXxMZHx1ED+Ul016SuOBN1UR/zW2vrI3KV0QeXhJ3aWPLWjo8 zfeaESgKuwgQvFRQ7JiEKlFyFtRPLFpI8Wob3yufWX0OA/Ha6x3Wzn80pXAqbaqIdkGE Kk39iZ9EJ/72YbpgCClk+rFisdzeHO3FqF02QOAR+XiWB315IT7knLMyes/y6NPbfSIN va0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=th6rpjZH; 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 h1-20020a170902704100b00198a715d260si6647890plt.565.2023.03.13.04.52.46; Mon, 13 Mar 2023 04:53:01 -0700 (PDT) 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=th6rpjZH; 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 S230265AbjCMLms (ORCPT + 99 others); Mon, 13 Mar 2023 07:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbjCMLmC (ORCPT ); Mon, 13 Mar 2023 07:42:02 -0400 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 AAEDD65058 for ; Mon, 13 Mar 2023 04:41:29 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id y2so11679204pjg.3 for ; Mon, 13 Mar 2023 04:41:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707684; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a36C9sWQdmAM0bfeAU4tZKbhIdnBMA6DO8wWZqH9jAY=; b=th6rpjZHiwhNM8zVk01MyOEseFNhcY5FryX2AZq3DGrEwlliqdvaWb1mec2Zm5ksVL 9uRDP/fujDSq3eD+YpSwOvSRP1rNnwlpDir00g2oOC5BJoBI6L6hiiOe2a/CNL7l+Q2A Q2SA97oYXx4OEBVz3AxsbUm/7zm/YJslEk3qGX04jMpc8FfRMTpo7kvTKHgsUlX68r7m /NmuTXCLFKSCdXfNYQz2VQtpm8azTBGhDRbArWQ1NKh0DJ9Z7YcEnV40Da3CdCCGIYBq QGcDmpZpInLt8EcZbveyBqFAA05UaAO4tVzobifseXX0alaiJiQIn2FfmEOglPb0xBZj 5y1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707684; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a36C9sWQdmAM0bfeAU4tZKbhIdnBMA6DO8wWZqH9jAY=; b=5nehoD0GLIDNs7jzl06Y8Ijcq+Q54dEss2Wt+2ToV4BAeyHhW+JwGTdZGM5QANsT+R vcWP21sdI8kvBHy3N2QN8CalDmQC6aXG4j5uW4vxUY7c6tFJbllj2N52EgsUt8JQSXye gFGNJEvpoY4mMEoOrThqAqeWN95cg5ZS+u+khU8HSEMqETE/5h5KJYbudJ3gSx0CIGk1 dmMDbjmzVWEnuEPe0tJ9S6oiHemfsPb8IX93TIw5ZY6u/9Pv8eRnpmAMaQVv/D7T5Wdu SHZS76cvusTT6444AaGPKxuTUb/CAu6/Kqo9zjDxAwaSCf8SvpiUu0f42M5mHymJOKIw zBEw== X-Gm-Message-State: AO0yUKUEOcTJ+WV74VGQFAt1Y5NDVVytHCuobEOuxAEIyvFDYLyISiLd hmUXrcMfic3resI7otRN4gBFwA== X-Received: by 2002:a17:90a:de94:b0:234:881b:2e8b with SMTP id n20-20020a17090ade9400b00234881b2e8bmr34804987pjv.49.1678707684517; Mon, 13 Mar 2023 04:41:24 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:24 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 10/16] perf kvm: Add dimensions for KVM event statistics Date: Mon, 13 Mar 2023 19:40:12 +0800 Message-Id: <20230313114018.543254-11-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760253320430340724?= X-GMAIL-MSGID: =?utf-8?q?1760253320430340724?= To support KVM event statistics, this patch firstly registers histograms columns and sorting fields; every column or field has its own format structure, the format structure is dereferenced to access the dimension, finally the dimension provides the comparison callback for sorting result. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 232 ++++++++++++++++++++++++++++++++++++- tools/perf/util/kvm-stat.h | 2 + 2 files changed, 230 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index fa91c8deb628..3f601ccb7aab 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -70,9 +70,9 @@ static int64_t cmp_event_ ## func(struct kvm_event *one, \ get_event_ ##func(two, vcpu); \ } -GET_EVENT_KEY(time, time); -GET_EVENT_KEY(max, stats.max); -GET_EVENT_KEY(min, stats.min); +COMPARE_EVENT_KEY(time, time); +COMPARE_EVENT_KEY(max, stats.max); +COMPARE_EVENT_KEY(min, stats.min); COMPARE_EVENT_KEY(count, stats.n); COMPARE_EVENT_KEY(mean, stats.mean); @@ -90,13 +90,237 @@ struct kvm_hists { struct perf_hpp_list list; }; +struct kvm_dimension { + const char *name; + int64_t (*cmp)(struct perf_hpp_fmt *fmt, struct hist_entry *left, + struct hist_entry *right); +}; + +struct kvm_fmt { + struct perf_hpp_fmt fmt; + struct kvm_dimension *dim; +}; + static struct kvm_hists kvm_hists; +static int64_t ev_name_cmp(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left, + struct hist_entry *right) +{ + /* Return opposite number for sorting in alphabetical order */ + return -strcmp(left->kvm_info->name, right->kvm_info->name); +} + +static struct kvm_dimension dim_event = { + .name = "ev_name", + .cmp = ev_name_cmp, +}; + +#define EV_METRIC_CMP(metric) \ +static int64_t ev_cmp_##metric(struct perf_hpp_fmt *fmt __maybe_unused, \ + struct hist_entry *left, \ + struct hist_entry *right) \ +{ \ + struct kvm_event *event_left; \ + struct kvm_event *event_right; \ + struct perf_kvm_stat *perf_kvm; \ + \ + event_left = container_of(left, struct kvm_event, he); \ + event_right = container_of(right, struct kvm_event, he); \ + \ + perf_kvm = event_left->perf_kvm; \ + return cmp_event_##metric(event_left, event_right, \ + perf_kvm->trace_vcpu); \ +} + +EV_METRIC_CMP(time) +EV_METRIC_CMP(count) +EV_METRIC_CMP(max) +EV_METRIC_CMP(min) +EV_METRIC_CMP(mean) + +static struct kvm_dimension dim_time = { + .name = "time", + .cmp = ev_cmp_time, +}; + +static struct kvm_dimension dim_count = { + .name = "sample", + .cmp = ev_cmp_count, +}; + +static struct kvm_dimension dim_max_time = { + .name = "max_t", + .cmp = ev_cmp_max, +}; + +static struct kvm_dimension dim_min_time = { + .name = "min_t", + .cmp = ev_cmp_min, +}; + +static struct kvm_dimension dim_mean_time = { + .name = "mean_t", + .cmp = ev_cmp_mean, +}; + +static struct kvm_dimension *dimensions[] = { + &dim_event, + &dim_time, + &dim_count, + &dim_max_time, + &dim_min_time, + &dim_mean_time, + NULL, +}; + +static bool fmt_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b) +{ + struct kvm_fmt *kvm_fmt_a = container_of(a, struct kvm_fmt, fmt); + struct kvm_fmt *kvm_fmt_b = container_of(b, struct kvm_fmt, fmt); + + return kvm_fmt_a->dim == kvm_fmt_b->dim; +} + +static void fmt_free(struct perf_hpp_fmt *fmt) +{ + struct kvm_fmt *kvm_fmt; + + kvm_fmt = container_of(fmt, struct kvm_fmt, fmt); + free(kvm_fmt); +} + +static struct kvm_dimension *get_dimension(const char *name) +{ + unsigned int i; + + for (i = 0; dimensions[i] != NULL; i++) { + if (!strcmp(dimensions[i]->name, name)) + return dimensions[i]; + } + + return NULL; +} + +static struct kvm_fmt *get_format(const char *name) +{ + struct kvm_dimension *dim = get_dimension(name); + struct kvm_fmt *kvm_fmt; + struct perf_hpp_fmt *fmt; + + if (!dim) + return NULL; + + kvm_fmt = zalloc(sizeof(*kvm_fmt)); + if (!kvm_fmt) + return NULL; + + kvm_fmt->dim = dim; + + fmt = &kvm_fmt->fmt; + INIT_LIST_HEAD(&fmt->list); + INIT_LIST_HEAD(&fmt->sort_list); + fmt->cmp = dim->cmp; + fmt->sort = dim->cmp; + fmt->color = NULL; + fmt->entry = NULL; + fmt->header = NULL; + fmt->width = NULL; + fmt->collapse = dim->cmp; + fmt->equal = fmt_equal; + fmt->free = fmt_free; + + return kvm_fmt; +} + +static int kvm_hists__init_output(struct perf_hpp_list *hpp_list, char *name) +{ + struct kvm_fmt *kvm_fmt = get_format(name); + + if (!kvm_fmt) { + pr_warning("Fail to find format for output field %s.\n", name); + return -EINVAL; + } + + perf_hpp_list__column_register(hpp_list, &kvm_fmt->fmt); + return 0; +} + +static int kvm_hists__init_sort(struct perf_hpp_list *hpp_list, char *name) +{ + struct kvm_fmt *kvm_fmt = get_format(name); + + if (!kvm_fmt) { + pr_warning("Fail to find format for sorting %s.\n", name); + return -EINVAL; + } + + perf_hpp_list__register_sort_field(hpp_list, &kvm_fmt->fmt); + return 0; +} + +static int kvm_hpp_list__init(char *list, + struct perf_hpp_list *hpp_list, + int (*fn)(struct perf_hpp_list *hpp_list, + char *name)) +{ + char *tmp, *tok; + int ret; + + if (!list || !fn) + return 0; + + for (tok = strtok_r(list, ", ", &tmp); tok; + tok = strtok_r(NULL, ", ", &tmp)) { + ret = fn(hpp_list, tok); + if (!ret) + continue; + + /* Handle errors */ + if (ret == -EINVAL) + pr_err("Invalid field key: '%s'", tok); + else if (ret == -ESRCH) + pr_err("Unknown field key: '%s'", tok); + else + pr_err("Fail to initialize for field key: '%s'", tok); + + break; + } + + return ret; +} + +static int kvm_hpp_list__parse(struct perf_hpp_list *hpp_list, + const char *output_, const char *sort_) +{ + char *output = output_ ? strdup(output_) : NULL; + char *sort = sort_ ? strdup(sort_) : NULL; + int ret; + + ret = kvm_hpp_list__init(output, hpp_list, kvm_hists__init_output); + if (ret) + goto out; + + ret = kvm_hpp_list__init(sort, hpp_list, kvm_hists__init_sort); + if (ret) + goto out; + + /* Copy sort keys to output fields */ + perf_hpp__setup_output_field(hpp_list); + + /* and then copy output fields to sort keys */ + perf_hpp__append_sort_keys(hpp_list); +out: + free(output); + free(sort); + return ret; +} + static int kvm_hists__init(void) { __hists__init(&kvm_hists.hists, &kvm_hists.list); perf_hpp_list__init(&kvm_hists.list); - return 0; + return kvm_hpp_list__parse(&kvm_hists.list, NULL, "ev_name"); } static const char *get_filename_for_perf_kvm(void) diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 43dd6472fa50..92da2fb87380 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -46,6 +46,8 @@ struct kvm_event { #define DEFAULT_VCPU_NUM 8 int max_vcpu; struct kvm_event_stats *vcpu; + + struct hist_entry he; }; typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); From patchwork Mon Mar 13 11:40:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1136204wrd; Mon, 13 Mar 2023 04:53:59 -0700 (PDT) X-Google-Smtp-Source: AK7set/Oo1tmpe4B5896S11eEtkKYhwlloAHsRv5EPdMUPcEEfQ9b6BXktwAS1rqv46MB5uWUUVp X-Received: by 2002:a17:903:2cb:b0:19c:d452:b282 with SMTP id s11-20020a17090302cb00b0019cd452b282mr36753755plk.12.1678708438955; Mon, 13 Mar 2023 04:53:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678708438; cv=none; d=google.com; s=arc-20160816; b=k+90Pqiz3kTEwJcg+mRoi+luegcVJoR/1ZPc7lJLOqLep64wW3JY1kAAwvy6hI0f8f 1qPzWQd9gAK8AosZ0ZnxsiKJMuGLX+4/L5wEK1bn8b3C6LAK2WEBI/9Uix8YW+dRqRk9 ap2sztI8XtDeRLHi78jDMAwfnUiK7+Sf/dIfS1383d8gigFRYadWdazcuX6QxNxH2pZf +737dsSlDEbzKTk8BViAs5OY/yysY04RxxqMoz7G/BeYL0Stq1kYIlQ9W0ix6DXuUwkZ YrZ+QMpZrM2DAzr8OadhBzGAAcKz0C/ILm4ImQ/BZaLcV4DbyY/D31jJK1dUOkwWnWDh Fwqw== 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=LbWTiwsNLCzhmnfJIO7ZAOWJugOE9iyft/rP2uRGCC8=; b=Ox3LV+doPihcEA5LRpr9I14s2GMcqTV5YOgXvoM5qhNPzg38QKToXxjefPrxzkHgvD WqIyEC69SALZdWwJHlNiw2pK4IrVHhywnIEVaW1ACVV77mXpkXQ4n5KrtzHM8X+K4/uA xkLTh/IgSx77sFWyzJRpT2TOML+j8yV5FtoNgnhcxLwW1lTkXgNjA+TU533szANKJS2f IqEDTRd4ZU/fJ0oOmRljT2MQTrj9EGlHoXqKfLYFWaBIMunieUAMGLMZsR3bCaVYrHdB sbjTfZ8J+UG/h2kxejcPeADJK6q2ebL2HK5jyFnmErhBPh5r8q+6rZCgsrA3YZPNOnSD vHKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nZ8i5WMS; 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 r131-20020a632b89000000b0050938c8b46csi4675195pgr.33.2023.03.13.04.53.34; Mon, 13 Mar 2023 04:53:58 -0700 (PDT) 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=nZ8i5WMS; 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 S231364AbjCMLm6 (ORCPT + 99 others); Mon, 13 Mar 2023 07:42:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231226AbjCMLmG (ORCPT ); Mon, 13 Mar 2023 07:42:06 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2959565448 for ; Mon, 13 Mar 2023 04:41:34 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id a2so12596937plm.4 for ; Mon, 13 Mar 2023 04:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707689; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LbWTiwsNLCzhmnfJIO7ZAOWJugOE9iyft/rP2uRGCC8=; b=nZ8i5WMS0zGdM96heslrKJUIiOb1D7ofUN3SjacWtXfTVuSHaMD9cIkbY/tUTbZfmh nrLHpWAfXQavr0jWc8kCwfpXwMFxJGdFcK2WBhjk3s3iN3EhOW0bjnL2lbkgAV/l3KYR AZ3DEM/B8cFHgDYR7SlLG+B+/R46eeqwiJ3rw89Zn63nX+bLW30xeJGgJYdHPC2G0Yxk usB13ToHqBp7Dmk9JoZETT7VjOuH/1TOA4isEi8PrNUy7QDgBrs9jOmAK8VHIGOG+Yzx ilf56Z++S3UpY997GBOfGN8CDRhWHlkuEAuJDmpX60BPmx+6Eur2+MRv2mIH6ntlrujG u/fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707689; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LbWTiwsNLCzhmnfJIO7ZAOWJugOE9iyft/rP2uRGCC8=; b=kLxIe6AaNU0C3tFyu3Ags3K4RGNOlxX7UMOqqn0re4jRKmqGosh6beqFM+O+mjHCyS BnuIpIJuWqwcM/HfqNmfCzqV248vjVXZ8sCCM+8gkk8dFct+WJWQ3pQB50cVYj4NmaiE 1hGs/2qRvMtVjm4sinOcRohZymtNxYYX4pTgXDLrseisoujLvpoyuB0jZPty3TTsxmFh Eio96d2mGUq2aVvF77o87wMvTKRC88KzDs5biL1VF5f2A2Qvl7+YjHq+YLVKixynMNp6 YdceeKdHUcaQ2U7EBkiKggxwa7l2mMvxljFwsT8AKGRUTHtXNf6lMux4grmqIdaBJJTy rBxA== X-Gm-Message-State: AO0yUKX1QBbJFeFOe0W0wO7LqoD8qWKwxa/unLjeklkmO3M/6uplhWZi h1HR7GvIDhJVKpUPOtzsvuPDbw== X-Received: by 2002:a17:90a:dac3:b0:23b:446b:bbfe with SMTP id g3-20020a17090adac300b0023b446bbbfemr5713335pjx.10.1678707688565; Mon, 13 Mar 2023 04:41:28 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:28 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 11/16] perf kvm: Use histograms list to replace cached list Date: Mon, 13 Mar 2023 19:40:13 +0800 Message-Id: <20230313114018.543254-12-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760253379679774642?= X-GMAIL-MSGID: =?utf-8?q?1760253379679774642?= perf kvm tool defines its own cached list which is managed with RB tree, histograms also provide RB tree to manage data entries. Since now we have introduced histograms in the tool, it's not necessary to use the self defined list and we can directly use histograms list to manage KVM events. This patch changes to use histograms list to track KVM events, and it invokes the common function hists__output_resort_cb() to sort result, this also give us flexibility to extend more sorting key words easily. After histograms list supported, the cached list is redundant so remove the relevant code for it. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 189 +++++++++++++++++++------------------ tools/perf/util/kvm-stat.h | 7 -- 2 files changed, 95 insertions(+), 101 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 3f601ccb7aab..ba3134613bcb 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -323,6 +323,12 @@ static int kvm_hists__init(void) return kvm_hpp_list__parse(&kvm_hists.list, NULL, "ev_name"); } +static int kvm_hists__reinit(const char *output, const char *sort) +{ + perf_hpp__reset_output_field(&kvm_hists.list); + return kvm_hpp_list__parse(&kvm_hists.list, output, sort); +} + static const char *get_filename_for_perf_kvm(void) { const char *filename; @@ -420,44 +426,37 @@ struct vcpu_event_record { struct kvm_event *last_event; }; - -static void init_kvm_event_record(struct perf_kvm_stat *kvm) -{ - unsigned int i; - - for (i = 0; i < EVENTS_CACHE_SIZE; i++) - INIT_LIST_HEAD(&kvm->kvm_events_cache[i]); -} - #ifdef HAVE_TIMERFD_SUPPORT -static void clear_events_cache_stats(struct list_head *kvm_events_cache) +static void clear_events_cache_stats(void) { - struct list_head *head; + struct rb_root_cached *root; + struct rb_node *nd; struct kvm_event *event; - unsigned int i; - int j; - - for (i = 0; i < EVENTS_CACHE_SIZE; i++) { - head = &kvm_events_cache[i]; - list_for_each_entry(event, head, hash_entry) { - /* reset stats for event */ - event->total.time = 0; - init_stats(&event->total.stats); - - for (j = 0; j < event->max_vcpu; ++j) { - event->vcpu[j].time = 0; - init_stats(&event->vcpu[j].stats); - } + int i; + + if (hists__has(&kvm_hists.hists, need_collapse)) + root = &kvm_hists.hists.entries_collapsed; + else + root = kvm_hists.hists.entries_in; + + for (nd = rb_first_cached(root); nd; nd = rb_next(nd)) { + struct hist_entry *he; + + he = rb_entry(nd, struct hist_entry, rb_node_in); + event = container_of(he, struct kvm_event, he); + + /* reset stats for event */ + event->total.time = 0; + init_stats(&event->total.stats); + + for (i = 0; i < event->max_vcpu; ++i) { + event->vcpu[i].time = 0; + init_stats(&event->vcpu[i].stats); } } } #endif -static int kvm_events_hash_fn(u64 key) -{ - return key & (EVENTS_CACHE_SIZE - 1); -} - static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) { int old_max_vcpu = event->max_vcpu; @@ -483,44 +482,64 @@ static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) return true; } -static struct kvm_event *kvm_alloc_init_event(struct perf_kvm_stat *kvm, - struct event_key *key, - struct perf_sample *sample __maybe_unused) +static void *kvm_he_zalloc(size_t size) { - struct kvm_event *event; + struct kvm_event *kvm_ev; - event = zalloc(sizeof(*event)); - if (!event) { - pr_err("Not enough memory\n"); + kvm_ev = zalloc(size + sizeof(*kvm_ev)); + if (!kvm_ev) return NULL; - } - event->perf_kvm = kvm; - event->key = *key; - init_stats(&event->total.stats); - return event; + init_stats(&kvm_ev->total.stats); + hists__inc_nr_samples(&kvm_hists.hists, 0); + return &kvm_ev->he; +} + +static void kvm_he_free(void *he) +{ + struct kvm_event *kvm_ev; + + free(((struct hist_entry *)he)->kvm_info); + kvm_ev = container_of(he, struct kvm_event, he); + free(kvm_ev); } +static struct hist_entry_ops kvm_ev_entry_ops = { + .new = kvm_he_zalloc, + .free = kvm_he_free, +}; + static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, struct event_key *key, struct perf_sample *sample) { struct kvm_event *event; - struct list_head *head; + struct hist_entry *he; + struct kvm_info *ki; BUG_ON(key->key == INVALID_KEY); - head = &kvm->kvm_events_cache[kvm_events_hash_fn(key->key)]; - list_for_each_entry(event, head, hash_entry) { - if (event->key.key == key->key && event->key.info == key->info) - return event; + ki = zalloc(sizeof(*ki)); + if (!ki) { + pr_err("Failed to allocate kvm info\n"); + return NULL; } - event = kvm_alloc_init_event(kvm, key, sample); - if (!event) + kvm->events_ops->decode_key(kvm, key, ki->name); + he = hists__add_entry_ops(&kvm_hists.hists, &kvm_ev_entry_ops, + &kvm->al, NULL, NULL, NULL, ki, sample, true); + if (he == NULL) { + pr_err("Failed to allocate hist entry\n"); + free(ki); return NULL; + } + + event = container_of(he, struct kvm_event, he); + if (!event->perf_kvm) { + event->perf_kvm = kvm; + event->key = *key; + } - list_add(&event->hash_entry, head); return event; } @@ -753,58 +772,32 @@ static bool select_key(struct perf_kvm_stat *kvm) return false; } -static void insert_to_result(struct rb_root *result, struct kvm_event *event, - key_cmp_fun bigger, int vcpu) -{ - struct rb_node **rb = &result->rb_node; - struct rb_node *parent = NULL; - struct kvm_event *p; - - while (*rb) { - p = container_of(*rb, struct kvm_event, rb); - parent = *rb; - - if (bigger(event, p, vcpu) > 0) - rb = &(*rb)->rb_left; - else - rb = &(*rb)->rb_right; - } - - rb_link_node(&event->rb, parent, rb); - rb_insert_color(&event->rb, result); -} - static bool event_is_valid(struct kvm_event *event, int vcpu) { return !!get_event_count(event, vcpu); } -static void sort_result(struct perf_kvm_stat *kvm) +static int filter_cb(struct hist_entry *he, void *arg __maybe_unused) { - unsigned int i; - int vcpu = kvm->trace_vcpu; struct kvm_event *event; + struct perf_kvm_stat *perf_kvm; - for (i = 0; i < EVENTS_CACHE_SIZE; i++) { - list_for_each_entry(event, &kvm->kvm_events_cache[i], hash_entry) { - if (event_is_valid(event, vcpu)) { - insert_to_result(&kvm->result, event, - kvm->compare, vcpu); - } - } - } + event = container_of(he, struct kvm_event, he); + perf_kvm = event->perf_kvm; + if (!event_is_valid(event, perf_kvm->trace_vcpu)) + he->filtered = 1; + else + he->filtered = 0; + return 0; } -/* returns left most element of result, and erase it */ -static struct kvm_event *pop_from_result(struct rb_root *result) +static void sort_result(struct perf_kvm_stat *kvm) { - struct rb_node *node = rb_first(result); - - if (!node) - return NULL; + const char *output_columns = "ev_name,sample,time,max_t,min_t,mean_t"; - rb_erase(node, result); - return container_of(node, struct kvm_event, rb); + kvm_hists__reinit(output_columns, kvm->sort_key); + hists__collapse_resort(&kvm_hists.hists, NULL); + hists__output_resort_cb(&kvm_hists.hists, NULL, filter_cb); } static void print_vcpu_info(struct perf_kvm_stat *kvm) @@ -847,6 +840,7 @@ static void print_result(struct perf_kvm_stat *kvm) char decode[KVM_EVENT_NAME_LEN]; struct kvm_event *event; int vcpu = kvm->trace_vcpu; + struct rb_node *nd; if (kvm->live) { puts(CONSOLE_CLEAR); @@ -865,9 +859,15 @@ static void print_result(struct perf_kvm_stat *kvm) pr_info("%16s ", "Avg time"); pr_info("\n\n"); - while ((event = pop_from_result(&kvm->result))) { + for (nd = rb_first_cached(&kvm_hists.hists.entries); nd; nd = rb_next(nd)) { + struct hist_entry *he; u64 ecount, etime, max, min; + he = rb_entry(nd, struct hist_entry, rb_node); + if (he->filtered) + continue; + + event = container_of(he, struct kvm_event, he); ecount = get_event_count(event, vcpu); etime = get_event_time(event, vcpu); max = get_event_max(event, vcpu); @@ -1144,8 +1144,11 @@ static int perf_kvm__handle_timerfd(struct perf_kvm_stat *kvm) sort_result(kvm); print_result(kvm); + /* Reset sort list to "ev_name" */ + kvm_hists__reinit(NULL, "ev_name"); + /* reset counts */ - clear_events_cache_stats(kvm->kvm_events_cache); + clear_events_cache_stats(); kvm->total_count = 0; kvm->total_time = 0; kvm->lost_events = 0; @@ -1201,7 +1204,6 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm) } set_term_quiet_input(&save); - init_kvm_event_record(kvm); kvm_hists__init(); @@ -1397,7 +1399,6 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) if (!register_kvm_events_ops(kvm)) goto exit; - init_kvm_event_record(kvm); setup_pager(); kvm_hists__init(); diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 92da2fb87380..4385be769eee 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -36,7 +36,6 @@ struct perf_kvm_stat; struct kvm_event { struct list_head hash_entry; - struct rb_node rb; struct perf_kvm_stat *perf_kvm; struct event_key key; @@ -81,9 +80,6 @@ struct exit_reasons_table { const char *reason; }; -#define EVENTS_BITS 12 -#define EVENTS_CACHE_SIZE (1UL << EVENTS_BITS) - struct perf_kvm_stat { struct perf_tool tool; struct record_opts opts; @@ -103,7 +99,6 @@ struct perf_kvm_stat { struct kvm_events_ops *events_ops; key_cmp_fun compare; - struct list_head kvm_events_cache[EVENTS_CACHE_SIZE]; u64 total_time; u64 total_count; @@ -112,8 +107,6 @@ struct perf_kvm_stat { struct intlist *pid_list; - struct rb_root result; - int timerfd; unsigned int display_time; bool live; From patchwork Mon Mar 13 11:40:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1132552wrd; Mon, 13 Mar 2023 04:44:56 -0700 (PDT) X-Google-Smtp-Source: AK7set+bqYg0VKGg1tRLADCqJ/I/4rRcBeKlpy3ej1B8vG5H5rNOmghfxzK4pcnZe+SaSKmUa1lJ X-Received: by 2002:a05:6a20:7349:b0:cc:9b29:f5ff with SMTP id v9-20020a056a20734900b000cc9b29f5ffmr34822388pzc.35.1678707895984; Mon, 13 Mar 2023 04:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678707895; cv=none; d=google.com; s=arc-20160816; b=u7OQX+FGmVOX3VAo16VMLXMFb/PV5G2WaoCAaH4msSE17R1vEwQJlY3ODpwIQT8B5M Gx1eF24B128hSKl4vP/AZCKPzaC+JgOAZ/BH3CE2Kl+eQahoJi9s17Rr0ofMQEq1sxha vapnEkZmgdMrA1oAWJCUZnzbtQQdtyxuprSfl41fn/8PXOrDlSzUZBx+DsYYBhWUkAO3 I1f3mkMUWcjBe9P4aEvv4ONoiecGrQK8sgp4OH0E6vC7XcO53Yhz/45z3PEiPscH7l5S snJ+OTIR68DjUqTlX+84Xa1ge1WLC+Xk3tdCX1s/RN5IFaPaqYP2ynLlVZm73lfYRiFG u1qA== 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=JgI7sIUXfEuJw5LLT6sg1Fr5x2zyVVOPMU2FeyfJj/s=; b=X2ZZmPL1JT3T6TDcwa7nJUHcMA5eLmjdl8Xfd0p8B6zwrY4qBimBr8J0MUDFy0FTQS Q2lYjFABo6nldTakQAYLFqrIEdHg5cVVNyrm4D8sR7rCQZypGTin+Fe7QB65rD5x/Vrx Cx8YmUtiEeLPVOCcc/IsBXaUNwatzJInHo0dKyc+0C0JWR1cxY0NOYLOzuLgg0XG0Sk9 o/j4xOJAk6oAXR41230Bw5AB086XF4UpnGjfJnsbGWU+T8BWjmU4Kad29RKJPrZVNAaM SRwrzRNbVFojmYjjnPpz4t+xbGuhm5vm91txntxS/G4h8vpg8t5Y1IUTQPzRlOyLfIBF GO1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JSIqC98b; 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 w1-20020aa79a01000000b00623114a7324si833620pfj.363.2023.03.13.04.44.41; Mon, 13 Mar 2023 04:44:55 -0700 (PDT) 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=JSIqC98b; 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 S231379AbjCMLnK (ORCPT + 99 others); Mon, 13 Mar 2023 07:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230452AbjCMLmK (ORCPT ); Mon, 13 Mar 2023 07:42:10 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ADDE64B2D for ; Mon, 13 Mar 2023 04:41:37 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id e15-20020a17090ac20f00b0023d1b009f52so1268634pjt.2 for ; Mon, 13 Mar 2023 04:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707693; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JgI7sIUXfEuJw5LLT6sg1Fr5x2zyVVOPMU2FeyfJj/s=; b=JSIqC98bHXd1HfroD6mo8qc6VuzWGpMiZiOthJxGbxLvgobrPsxvkG5EQWiZDRv19w 8a/xOu07TOj4EYGKthPFFnp2SbxDfE0fbj3bSEFRiSxL4P/fUXW9F+kDAMPDzWtT/bd2 SyjB158rjJK1DEIXNp+dd7yq+0P7jv0shgpYeDdvDZF9Nd8dGuuTZ6jkTa5/m6zh2Se0 uK2kxdbbp1G6x/0vfMELj8w9TzaykirdcTQ5RDv67S9/bX6Zu7e+MLWdq/txA1aLnFB0 r30Hwq9iMEbBMyK0a5eZwP+lTh0Vyr5MkZDlsVkuwX45BrDeM47pS5tdlHkWbtilq/v7 7BgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707693; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JgI7sIUXfEuJw5LLT6sg1Fr5x2zyVVOPMU2FeyfJj/s=; b=0Ut9hhVVukEIoXH4HSJjv2SA6nvpMrs98uZXzoUyABEn/Dln2c/5Os7quG164WbGGj 5c60XYyYQqn89sB+ZNNfa7nhM6wMUbsOUexSNHbvPRzD5SoFBBGOOFOfFc1NgproVAzq qze3K/AObWyetiXrVK31QeRxmd/E0GcMQw5xZPW4rUC3kznSmUnWjhlNJDASKU1HhjF6 aP+zrFoUUNCSnWkQXREtFCZGImqcBKoWWXrv1ymaoDtnzNiGrpYkXnmqqgx3cykY3psq /lBpYUCqtobCcaP+AyT3QNBNJx4rJYQuGeATyEdAhg6ssCw2T3FkP1NCg/mMezSiZRIM 5+jQ== X-Gm-Message-State: AO0yUKW02vAIMQy7YPVWg0kznoSTFT5FiPYiOTrHQfC5pUO9axMR7AEe S0Kf9jQwwuxrMUdRbQylq+D7mQ== X-Received: by 2002:a17:90a:53:b0:234:d1c:f112 with SMTP id 19-20020a17090a005300b002340d1cf112mr35281110pjb.0.1678707692996; Mon, 13 Mar 2023 04:41:32 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:32 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 12/16] perf kvm: Polish sorting key Date: Mon, 13 Mar 2023 19:40:14 +0800 Message-Id: <20230313114018.543254-13-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760252811024815635?= X-GMAIL-MSGID: =?utf-8?q?1760252811024815635?= Since histograms supports sorting, the tool doesn't need to maintain the mapping between the sorting keys and the corresponding comparison callbacks, therefore, this patch removes structure kvm_event_key. But we still need to validate the sorting key, this patch uses an array for sorting keys and renames function select_key() to is_valid_key() to validate the sorting key passed by user. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 29 ++++++++++------------------- tools/perf/util/kvm-stat.h | 8 -------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index ba3134613bcb..1e9338855239 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -76,15 +76,6 @@ COMPARE_EVENT_KEY(min, stats.min); COMPARE_EVENT_KEY(count, stats.n); COMPARE_EVENT_KEY(mean, stats.mean); -#define DEF_SORT_NAME_KEY(name, compare_key) \ - { #name, cmp_event_ ## compare_key } - -static struct kvm_event_key keys[] = { - DEF_SORT_NAME_KEY(sample, count), - DEF_SORT_NAME_KEY(time, mean), - { NULL, NULL } -}; - struct kvm_hists { struct hists hists; struct perf_hpp_list list; @@ -757,18 +748,18 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, return true; } -static bool select_key(struct perf_kvm_stat *kvm) +static bool is_valid_key(struct perf_kvm_stat *kvm) { - int i; + static const char *key_array[] = { + "ev_name", "sample", "time", "max_t", "min_t", "mean_t", + }; + unsigned int i; - for (i = 0; keys[i].name; i++) { - if (!strcmp(keys[i].name, kvm->sort_key)) { - kvm->compare = keys[i].key; + for (i = 0; i < ARRAY_SIZE(key_array); i++) + if (!strcmp(key_array[i], kvm->sort_key)) return true; - } - } - pr_err("Unknown compare key:%s\n", kvm->sort_key); + pr_err("Unsupported sort key: %s\n", kvm->sort_key); return false; } @@ -1198,7 +1189,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm) return ret; if (!verify_vcpu(kvm->trace_vcpu) || - !select_key(kvm) || + !is_valid_key(kvm) || !register_kvm_events_ops(kvm)) { goto out; } @@ -1393,7 +1384,7 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) if (!verify_vcpu(vcpu)) goto exit; - if (!select_key(kvm)) + if (!is_valid_key(kvm)) goto exit; if (!register_kvm_events_ops(kvm)) diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 4385be769eee..35d03894fac3 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -49,13 +49,6 @@ struct kvm_event { struct hist_entry he; }; -typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); - -struct kvm_event_key { - const char *name; - key_cmp_fun key; -}; - struct child_event_ops { void (*get_key)(struct evsel *evsel, struct perf_sample *sample, @@ -98,7 +91,6 @@ struct perf_kvm_stat { const char *exit_reasons_isa; struct kvm_events_ops *events_ops; - key_cmp_fun compare; u64 total_time; u64 total_count; From patchwork Mon Mar 13 11:40:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68799 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1143199wrd; Mon, 13 Mar 2023 05:07:30 -0700 (PDT) X-Google-Smtp-Source: AK7set/hztVJwn/45bIrOK/0uGntSR9v5kDscy+23PRTf/d4q74QzEpliqH4DzqX2fg1XGrsgyIy X-Received: by 2002:a17:90a:dac3:b0:23b:446b:bbfe with SMTP id g3-20020a17090adac300b0023b446bbbfemr5784499pjx.10.1678709250014; Mon, 13 Mar 2023 05:07:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678709249; cv=none; d=google.com; s=arc-20160816; b=ebHR9atyWflPfyg/fl+kyl2nPfhvrJZmpyfAl9+UcN9J1R/veTCQODrAh2WcBuJGrw tOiVuxcGfK3f9KiAHJnFxpbaXyteyiwEUg1EwRFWKn8278CDAAyMnQIGzeb4y5NDFOm8 HERPd/ZCyccQ9EiehNFKVMfbDQrhzbvWkefLGiUJ9/PH8t9Vk/66uPvBOJ/2Uk5DGtrx 44pO70wA/h85qtzmA2rnFPSPUqM1/QQbsY4zU6T2UwGyGLFMMpEMNK9J5GANaQUxGTBr aeN2/jBQuSpjqDSmpE9jOh9WEHwN71OhunJA1wqWd4UzqO6NtIfbW99Pz0kD28Kb2oP9 cxsQ== 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=lYZdsrHdzQhNgPnVDhJiRxXzSTwxol5Us4hF+GT6h6U=; b=SEVCb5CTJZ2IwLqYwQvYq0YWAuQImTrbaWD+t8lBy0D9u6KqyhWQNrCpRUMaKdVO8Q azv1I/uSsPWn+Iqg5/OZx0BGUrpb4pMHBV02HiQBvoXrax8Kx9Q720xbx6HK36LKXnk5 ++i7JRTORvDNtQurjC1tkvcQhHp3HFwPCnV2E/ivQaR5b0IEYYJgWkQSZCL6MC4gi1Q0 k7WKbPEUPEb2JC2E+qEvoX4Y6Qt4pleM+pQFVlb4gEU/XwyvKcUdaJt2M6Fy6ctlV6ob O4IPI97xy07xvueScoyElnwOBZyttBSv3t9LvGDL3N/K+VA0g5XsND0ZQ+Uwrym1smlt 4hjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HtcQ1Dsq; 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 c23-20020a17090abf1700b0023d269ed307si352635pjs.32.2023.03.13.05.07.12; Mon, 13 Mar 2023 05:07:29 -0700 (PDT) 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=HtcQ1Dsq; 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 S231387AbjCMLnO (ORCPT + 99 others); Mon, 13 Mar 2023 07:43:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230480AbjCMLmK (ORCPT ); Mon, 13 Mar 2023 07:42:10 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CABCD6423B for ; Mon, 13 Mar 2023 04:41:37 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id nn12so11678101pjb.5 for ; Mon, 13 Mar 2023 04:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707697; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lYZdsrHdzQhNgPnVDhJiRxXzSTwxol5Us4hF+GT6h6U=; b=HtcQ1Dsqji+5/51Jgddi4wmF19iXqpi5/q3y1S7vRBhkcO+9eiAHZNJgGKugNGFJe3 UkoD8p5470YfPpMcfbRLFm5bOStdn4VWkAeoMi+TZxn/D3t3pSicndN++cAPueo3Hvbz LKRjR1hcEmtJosnFX8Z4prmbcLX5cNAyfkDsR7ygVXxehulkCD7Izhd+0Ub0LgtdDHhJ tIsa7ldlKyyL/QRvQP9yDoAhy6IYqsHZVfLUCstKIRUlKliUeGbQ5JHl9ISaj+XJM3db rjZOjynBXF9AG20TqUhT3PFcYJ9T758CuiZQ5EC76W+4cbLkqpefNzrSaE8/0LOmdxJE hVbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707697; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lYZdsrHdzQhNgPnVDhJiRxXzSTwxol5Us4hF+GT6h6U=; b=IbuwBBEGmVaMifzGsmiBRo2kjQytV7no07N0c6SWURR6OY/CT+mnGPmoHjD0IzpYtU UJ2cLaSRureFjBx18UkqlsKlAriNXDHBXx+NvEHjMgzWLXVH5cgntJPuPFAgCvicF/cz Uiln9p2wk54J4kF8J545omHUzF9wt1JI0KQfjg8RzDPNR7tg5M0Bus5dF0SUvbSd/HGZ qsyYq5u0JAwEAwehH50sQoqIwPRYCsneUQhcr0U7WovZgH/KwR6E15fPWLdjzzBYNyQj sG7QHFPJ67xnOlisom8v+GuUiQ+1+I+w4w1BjpPumpPq1h1ODVicb/M79mbHEO+QYd5W /IIg== X-Gm-Message-State: AO0yUKXBWayeFJpT1lf9kDV38mtjNQJjYIxwuyzvHAT3zRj86r2P/glA 9dqrbtiTrO1VKU0KzlqGPKGs6w== X-Received: by 2002:a17:90b:1d12:b0:234:e3f:f53b with SMTP id on18-20020a17090b1d1200b002340e3ff53bmr34768751pjb.21.1678707697421; Mon, 13 Mar 2023 04:41:37 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:37 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 13/16] perf kvm: Support printing attributions for dimensions Date: Mon, 13 Mar 2023 19:40:15 +0800 Message-Id: <20230313114018.543254-14-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760254230049234114?= X-GMAIL-MSGID: =?utf-8?q?1760254230049234114?= This patch adds header, entry callback and width for every dimension, thus in TUI mode the tool can print items with the defined attributions. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 97 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 1e9338855239..0d857df826cf 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -83,8 +83,12 @@ struct kvm_hists { struct kvm_dimension { const char *name; + const char *header; + int width; int64_t (*cmp)(struct perf_hpp_fmt *fmt, struct hist_entry *left, struct hist_entry *right); + int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hist_entry *he); }; struct kvm_fmt { @@ -102,9 +106,24 @@ static int64_t ev_name_cmp(struct perf_hpp_fmt *fmt __maybe_unused, return -strcmp(left->kvm_info->name, right->kvm_info->name); } +static int fmt_width(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp __maybe_unused, + struct hists *hists __maybe_unused); + +static int ev_name_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width = fmt_width(fmt, hpp, he->hists); + + return scnprintf(hpp->buf, hpp->size, "%*s", width, he->kvm_info->name); +} + static struct kvm_dimension dim_event = { + .header = "Event name", .name = "ev_name", .cmp = ev_name_cmp, + .entry = ev_name_entry, + .width = 40, }; #define EV_METRIC_CMP(metric) \ @@ -130,29 +149,77 @@ EV_METRIC_CMP(max) EV_METRIC_CMP(min) EV_METRIC_CMP(mean) +#define EV_METRIC_ENTRY(metric) \ +static int ev_entry_##metric(struct perf_hpp_fmt *fmt, \ + struct perf_hpp *hpp, \ + struct hist_entry *he) \ +{ \ + struct kvm_event *event; \ + int width = fmt_width(fmt, hpp, he->hists); \ + struct perf_kvm_stat *perf_kvm; \ + \ + event = container_of(he, struct kvm_event, he); \ + perf_kvm = event->perf_kvm; \ + return scnprintf(hpp->buf, hpp->size, "%*lu", width, \ + get_event_##metric(event, perf_kvm->trace_vcpu)); \ +} + +EV_METRIC_ENTRY(time) +EV_METRIC_ENTRY(count) +EV_METRIC_ENTRY(max) +EV_METRIC_ENTRY(min) + static struct kvm_dimension dim_time = { + .header = "Time (ns)", .name = "time", .cmp = ev_cmp_time, + .entry = ev_entry_time, + .width = 12, }; static struct kvm_dimension dim_count = { + .header = "Samples", .name = "sample", .cmp = ev_cmp_count, + .entry = ev_entry_count, + .width = 12, }; static struct kvm_dimension dim_max_time = { + .header = "Max Time (ns)", .name = "max_t", .cmp = ev_cmp_max, + .entry = ev_entry_max, + .width = 14, }; static struct kvm_dimension dim_min_time = { + .header = "Min Time (ns)", .name = "min_t", .cmp = ev_cmp_min, + .entry = ev_entry_min, + .width = 14, }; +static int ev_entry_mean(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hist_entry *he) +{ + struct kvm_event *event; + int width = fmt_width(fmt, hpp, he->hists); + struct perf_kvm_stat *perf_kvm; + + event = container_of(he, struct kvm_event, he); + perf_kvm = event->perf_kvm; + return scnprintf(hpp->buf, hpp->size, "%*lu", width, + get_event_mean(event, perf_kvm->trace_vcpu)); +} + static struct kvm_dimension dim_mean_time = { + .header = "Mean Time (ns)", .name = "mean_t", .cmp = ev_cmp_mean, + .entry = ev_entry_mean, + .width = 14, }; static struct kvm_dimension *dimensions[] = { @@ -165,6 +232,30 @@ static struct kvm_dimension *dimensions[] = { NULL, }; +static int fmt_width(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp __maybe_unused, + struct hists *hists __maybe_unused) +{ + struct kvm_fmt *kvm_fmt; + + kvm_fmt = container_of(fmt, struct kvm_fmt, fmt); + return kvm_fmt->dim->width; +} + +static int fmt_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, + struct hists *hists, int line __maybe_unused, + int *span __maybe_unused) +{ + struct kvm_fmt *kvm_fmt; + struct kvm_dimension *dim; + int width = fmt_width(fmt, hpp, hists); + + kvm_fmt = container_of(fmt, struct kvm_fmt, fmt); + dim = kvm_fmt->dim; + + return scnprintf(hpp->buf, hpp->size, "%*s", width, dim->header); +} + static bool fmt_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b) { struct kvm_fmt *kvm_fmt_a = container_of(a, struct kvm_fmt, fmt); @@ -214,9 +305,9 @@ static struct kvm_fmt *get_format(const char *name) fmt->cmp = dim->cmp; fmt->sort = dim->cmp; fmt->color = NULL; - fmt->entry = NULL; - fmt->header = NULL; - fmt->width = NULL; + fmt->entry = dim->entry; + fmt->header = fmt_header; + fmt->width = fmt_width; fmt->collapse = dim->cmp; fmt->equal = fmt_equal; fmt->free = fmt_free; From patchwork Mon Mar 13 11:40:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68791 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1136752wrd; Mon, 13 Mar 2023 04:55:28 -0700 (PDT) X-Google-Smtp-Source: AK7set8D5L3oSKni5+/97HdcMpVLzWbWJXFRciy9hZ9LQV67DXQGYkbCJ+tXXd4AAC9ajOFK8YiU X-Received: by 2002:a05:6a20:69a3:b0:ca:4fde:4aec with SMTP id t35-20020a056a2069a300b000ca4fde4aecmr55345835pzk.49.1678708527978; Mon, 13 Mar 2023 04:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678708527; cv=none; d=google.com; s=arc-20160816; b=KaFGc/nKplZ4L1SZsup2Y+eucbx4M1GqGj3lxJ2aX7k9RKGX0+rAh2A+GHBxK4g3Ai PgLsaxA0+/+NKOIOkrZwfHJTPXcJU6vq2f+LH+OUbn7tgSjrxQbSyAifRrjHiKTGUXu9 T/o+79fhhjIdXqlsKCPnTcjolBp+X+gin7xcUhhuVaN/qQZg1pxKkvrnX+J8rgV2Ku+b xub7C1TmzhSlWrLaOu0owkM/kKPJMkNEfLnvzrw1F8UhZBBvATl8ujrgY432ophKGjHJ JVpxKSsX031nZuVOJYh78tiX5ce385eMV+OMj5nusfshIyRKlMSYmOXsK4FSdxh3B55c l6hA== 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=lmJnfY2lbCc2C3dy6sxzWUeYnl8mSWLRJqM4XO3hbV8=; b=n4Cg6VgGQPOSoKiyhlcQ7RI1hZ3RdqUCaT9NK6BypE3VoqosKauHOWb4p1O8PVAx7v GloZqV+rsHdvKJlmd23vcXExIt19q0qNAxOcOJTjn0Hw+IkXIa+v+FDaTKH4owpJ4Kca 3ne6RdVyauWf1Ld/gdt4Qb/w+3TJjNt4DOtwXs9dSqe+0suNiwd+BLVd3dHzkA1QQVnB PUZS9PrpRpcZnMB/xUqJorYUhk3Y0S79rQL7uZTMZlYSoj7Qh1WB+qS6lLqIUjZ7jQGQ cR3mePxHGk7HEBlIm15TFE+UhPrGH+J1f57yXccGKySnLxwg1p9UbIpHZC0RtqLRwGyf rxqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pNiVNpQ2; 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 n9-20020a635c49000000b004fb9c2c58cfsi6561074pgm.418.2023.03.13.04.55.12; Mon, 13 Mar 2023 04:55:27 -0700 (PDT) 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=pNiVNpQ2; 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 S231395AbjCMLnS (ORCPT + 99 others); Mon, 13 Mar 2023 07:43:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231131AbjCMLmM (ORCPT ); Mon, 13 Mar 2023 07:42:12 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC91E65047 for ; Mon, 13 Mar 2023 04:41:44 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id u5so12584008plq.7 for ; Mon, 13 Mar 2023 04:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707702; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lmJnfY2lbCc2C3dy6sxzWUeYnl8mSWLRJqM4XO3hbV8=; b=pNiVNpQ25MN3oYBxt5/TM6uCwUc4SXP1Z4o4vh/+qLyntiFU4wcRaE6ohhV/RNqOW2 rHce4CMogEGfwLFpKWTQmXNWgcGLssUlmb0X/DKabDIagp5i2zz+Jdjidy5OC0XvprT2 PUnrmmSDm9cTgl7DCgzx/Me6o22O8ESkhhqpCoUaTz23F7oXPEujB7FZ7E5pfLPmMS8d pkohfPUjdUSS3Kb56DFZ8y/kaO8KXmAMWhKJW5tFCu+c9ws0jBh5YE8UuxjnkIgI9D8g egVm1EeGUu0qQ6ulKO5sksvYjDegOtWElEXfyuLiVgE5l33GDU59cQnj+z3mfo5QUqdu WhUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707702; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lmJnfY2lbCc2C3dy6sxzWUeYnl8mSWLRJqM4XO3hbV8=; b=x3KcX6tRBUKR42gXIqgCjbvRcHm2UPGVVJJnVBaaPa1UcAaRvng8J54CPDkKNLcld1 B7s4XfxSzxdUjzaYX3HjwASOtn/q/U9i/e9B4QN07LIggA8eJxI1xFuciv2eZmZbL8Y9 iEQhEQ/QuQPN2sL8Br4209t5q2cmW1qsuzmbQx63imALfVhNrbzoGNPYMKdFpR61FYOt fld7PZ+yz12t3Xi863zOL51bxisZl7xBAdkxX1aPTO4VFZIFPjWjeeCcgpurgLsOz+1B H5gsYlcQ5nGyiV6zRa9WKhvHHnCCcJDYb5Ycogl7RYbRnspNPO/+WKmV+0aYycMVJmvY FW5A== X-Gm-Message-State: AO0yUKXmL4gIG6R4OUX9uUe/fO62jqUa40+Y7j8gt8DBwnSvjHU1Lb13 6oUYgBZYPMjCJMDHPmXBFafiTg== X-Received: by 2002:a17:90a:c7c3:b0:23b:4bf6:bbee with SMTP id gf3-20020a17090ac7c300b0023b4bf6bbeemr6415765pjb.21.1678707701711; Mon, 13 Mar 2023 04:41:41 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:41 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 14/16] perf kvm: Add dimensions for percentages Date: Mon, 13 Mar 2023 19:40:16 +0800 Message-Id: <20230313114018.543254-15-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760253473109306846?= X-GMAIL-MSGID: =?utf-8?q?1760253473109306846?= Add dimensions for count and time percentages, it would be useful for user to review percentage statistics. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/builtin-kvm.c | 98 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 0d857df826cf..ab1cd6b5e528 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -222,10 +222,105 @@ static struct kvm_dimension dim_mean_time = { .width = 14, }; +#define PERC_STR(__s, __v) \ +({ \ + scnprintf(__s, sizeof(__s), "%.2F%%", __v); \ + __s; \ +}) + +static double percent(u64 st, u64 tot) +{ + return tot ? 100. * (double) st / (double) tot : 0; +} + +#define EV_METRIC_PERCENT(metric) \ +static int ev_percent_##metric(struct hist_entry *he) \ +{ \ + struct kvm_event *event; \ + struct perf_kvm_stat *perf_kvm; \ + \ + event = container_of(he, struct kvm_event, he); \ + perf_kvm = event->perf_kvm; \ + \ + return percent(get_event_##metric(event, perf_kvm->trace_vcpu), \ + perf_kvm->total_##metric); \ +} + +EV_METRIC_PERCENT(time) +EV_METRIC_PERCENT(count) + +static int ev_entry_time_precent(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width = fmt_width(fmt, hpp, he->hists); + double per; + char buf[10]; + + per = ev_percent_time(he); + return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); +} + +static int64_t +ev_cmp_time_precent(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left, struct hist_entry *right) +{ + double per_left; + double per_right; + + per_left = ev_percent_time(left); + per_right = ev_percent_time(right); + + return per_left - per_right; +} + +static struct kvm_dimension dim_time_percent = { + .header = "Time%", + .name = "percent_time", + .cmp = ev_cmp_time_precent, + .entry = ev_entry_time_precent, + .width = 12, +}; + +static int ev_entry_count_precent(struct perf_hpp_fmt *fmt, + struct perf_hpp *hpp, + struct hist_entry *he) +{ + int width = fmt_width(fmt, hpp, he->hists); + double per; + char buf[10]; + + per = ev_percent_count(he); + return scnprintf(hpp->buf, hpp->size, "%*s", width, PERC_STR(buf, per)); +} + +static int64_t +ev_cmp_count_precent(struct perf_hpp_fmt *fmt __maybe_unused, + struct hist_entry *left, struct hist_entry *right) +{ + double per_left; + double per_right; + + per_left = ev_percent_count(left); + per_right = ev_percent_count(right); + + return per_left - per_right; +} + +static struct kvm_dimension dim_count_percent = { + .header = "Sample%", + .name = "percent_sample", + .cmp = ev_cmp_count_precent, + .entry = ev_entry_count_precent, + .width = 12, +}; + static struct kvm_dimension *dimensions[] = { &dim_event, &dim_time, + &dim_time_percent, &dim_count, + &dim_count_percent, &dim_max_time, &dim_min_time, &dim_mean_time, @@ -875,7 +970,8 @@ static int filter_cb(struct hist_entry *he, void *arg __maybe_unused) static void sort_result(struct perf_kvm_stat *kvm) { - const char *output_columns = "ev_name,sample,time,max_t,min_t,mean_t"; + const char *output_columns = "ev_name,sample,percent_sample," + "time,percent_time,max_t,min_t,mean_t"; kvm_hists__reinit(output_columns, kvm->sort_key); hists__collapse_resort(&kvm_hists.hists, NULL); From patchwork Mon Mar 13 11:40:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68779 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1135999wrd; Mon, 13 Mar 2023 04:53:22 -0700 (PDT) X-Google-Smtp-Source: AK7set8nEW8d0tlY6R33SgUOiLPSfYp4oVHK8+uj1Wf8zxWHGnLIJSAhrLcjaIxSXoRe4PORqxtd X-Received: by 2002:a17:902:c407:b0:19e:7490:c93e with SMTP id k7-20020a170902c40700b0019e7490c93emr46301899plk.63.1678708402237; Mon, 13 Mar 2023 04:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678708402; cv=none; d=google.com; s=arc-20160816; b=OZS63+nc05Dk77DCmbgjtPUEJa3WZGGYvwCxp4iGJnb7oM5fsp7rXMH0bAq0yu9+3W NkPg6jax3Dxk0JF6UR7BDy2xgydYX3TI28xN0jGWZnBwgT44+H5ZtZRbY7TKyhWStJqr yCsC3kEeNUO3grmq+5xzdRc/86DkaLzkUZsMMHt6ye4Wo07V6EXDrelNVA+FDi/mt8Lm L/5vbhiuVoaRg6QdbVQAX+QL3q70dZXovfSQyNh0cWvYZ8OLfbGM0DYW7p3vs6eYfb+d 6KZsWU17wHjExPoVyxfG79hHSGGjfIbQNLKo0gCkSXzPvgVRt2pXdfrFrKXATgYwS5Cx 4cwg== 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=4fUVJ64SEnuw/uEL+nd4TijpPo7wgQdrNlutXsuxFPw=; b=u1QV79JO4IWTS9LHHbO/+CNhEvtOQ2S2BX08WbzdyLwMpSeeuvx/X6sZ5ChxxNjNCx pRgnP/Vju8KZ+x4pk2th5o7fhZEoBjwBm5tcbqykocQatpmSZuBWN7GiPamMZ3SFGWjw wHFqWJ5VGzU+WAH4WRFd3Ggv7EkzqxkNTQnJ/PY4pK8tCZ01NW8FJ1zL39ZlqvHmRFPC 3MUtm50k0w+/7Go7KRKvd48LMBkVDbLU+6XaSYCs57b/SwJWNOI187VsH38w2n9j9jNc c7wf2Ua0cXEJhvazT6n3XUBHO1AMc4Uol5gJLqkqzGJ56hYkMwxy6m8HdH0p5QyQCdcA UP6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nx7x7sJa; 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 q22-20020a170902789600b0019cac5266b1si6607220pll.604.2023.03.13.04.53.07; Mon, 13 Mar 2023 04:53:22 -0700 (PDT) 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=nx7x7sJa; 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 S231247AbjCMLnZ (ORCPT + 99 others); Mon, 13 Mar 2023 07:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231244AbjCMLmO (ORCPT ); Mon, 13 Mar 2023 07:42:14 -0400 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 D760B664EF for ; Mon, 13 Mar 2023 04:41:47 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id v21so2463947ple.9 for ; Mon, 13 Mar 2023 04:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4fUVJ64SEnuw/uEL+nd4TijpPo7wgQdrNlutXsuxFPw=; b=nx7x7sJa4vO1BZbZZBGq8aty9HkU1min3aeiiVvaQq9K/WZb1iYrPP6cZMgRoi0BSC MCGPxPk2OqlG0aD3oieBm6tQ4LTcebLcYiea0Po4kcBybtudYud3j0qvvTlGdw5QmFSt apXGeRgQ7OKmOWyAKKJXLQABCmttd50P8oiuxRfiFSOzkpa4SOIwdLLJQOwU8+jCah9R TYpzBYepRDAUb1oZiwRQN32eBjvXc/F2GvutMAJxJYBDceM1gGeHqm/3yGEQ6Jco8xHn 5aIW6RHLYCBJFhsJsqpZFSGDAZKMxsi/SqEMCVow3DEQpF2IYElj2xFYYFVY9/moWYUg sB7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4fUVJ64SEnuw/uEL+nd4TijpPo7wgQdrNlutXsuxFPw=; b=VVTYcdJ8/07i/tSHs2rhz1bbrnBb4BKMN/+wG6RFHnO0/NPm73dVbpPD+Cv2L3iAnR AF9eYOz0bLel548/rIDXdF2Ia7ZHYmZV5P9BYS6bO3b7gAqyfl4cnmXC3T9nb8erbM9b CQJ2aEwABVFqUGIqnkj6iMMEQKdoXce6LK5vvqLxMBxHE0kB4ArZCrYOZ4ZV5c/Ub7i2 JryQfB+aTAzIwYXc51pBmaAWhIrYhYTBhZeqIMN3fqD3Rej5uvsEGumBGQ0SpRzwRSh0 zyJLWCYIFi+br49wAvWOlG7g+QWB4Ris/3lwBc5zVaz3zYFVfnd33JZnYbHyBUBX1VEb wLTA== X-Gm-Message-State: AO0yUKVGLDDn+O5oMGMMZzYB01dEHYb4SGKPU+BU+7BPUHyxh8H6uM0B DXSbGh8avRtjbeZRkFJrBglZkw== X-Received: by 2002:a17:90a:3fce:b0:23b:33ef:7991 with SMTP id u14-20020a17090a3fce00b0023b33ef7991mr6439168pjm.49.1678707705816; Mon, 13 Mar 2023 04:41:45 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:45 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 15/16] perf kvm: Add TUI mode for stat report Date: Mon, 13 Mar 2023 19:40:17 +0800 Message-Id: <20230313114018.543254-16-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760253342012943595?= X-GMAIL-MSGID: =?utf-8?q?1760253342012943595?= Since we have supported histograms list and prepared the dimensions in the tool, this patch adds TUI mode for stat report. It also adds UI progress for sorting for better user experience. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 109 ++++++++++++++++++++++++++++++++++++- tools/perf/util/kvm-stat.h | 1 + 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index ab1cd6b5e528..3dd44763d1fc 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -23,6 +23,8 @@ #include "util/data.h" #include "util/ordered-events.h" #include "util/kvm-stat.h" +#include "ui/browsers/hists.h" +#include "ui/progress.h" #include "ui/ui.h" #include "util/string2.h" @@ -495,6 +497,7 @@ static int kvm_hpp_list__parse(struct perf_hpp_list *hpp_list, static int kvm_hists__init(void) { + kvm_hists.list.nr_header_lines = 1; __hists__init(&kvm_hists.hists, &kvm_hists.list); perf_hpp_list__init(&kvm_hists.list); return kvm_hpp_list__parse(&kvm_hists.list, NULL, "ev_name"); @@ -506,6 +509,93 @@ static int kvm_hists__reinit(const char *output, const char *sort) return kvm_hpp_list__parse(&kvm_hists.list, output, sort); } +static void print_result(struct perf_kvm_stat *kvm); + +#ifdef HAVE_SLANG_SUPPORT +static void kvm_browser__update_nr_entries(struct hist_browser *hb) +{ + struct rb_node *nd = rb_first_cached(&hb->hists->entries); + u64 nr_entries = 0; + + for (; nd; nd = rb_next(nd)) { + struct hist_entry *he = rb_entry(nd, struct hist_entry, + rb_node); + + if (!he->filtered) + nr_entries++; + } + + hb->nr_non_filtered_entries = nr_entries; +} + +static int kvm_browser__title(struct hist_browser *browser, + char *buf, size_t size) +{ + scnprintf(buf, size, "KVM event statistics (%lu entries)", + browser->nr_non_filtered_entries); + return 0; +} + +static struct hist_browser* +perf_kvm_browser__new(struct hists *hists) +{ + struct hist_browser *browser = hist_browser__new(hists); + + if (browser) + browser->title = kvm_browser__title; + + return browser; +} + +static int kvm__hists_browse(struct hists *hists) +{ + struct hist_browser *browser; + int key = -1; + + browser = perf_kvm_browser__new(hists); + if (browser == NULL) + return -1; + + /* reset abort key so that it can get Ctrl-C as a key */ + SLang_reset_tty(); + SLang_init_tty(0, 0, 0); + + kvm_browser__update_nr_entries(browser); + + while (1) { + key = hist_browser__run(browser, "? - help", true, 0); + + switch (key) { + case 'q': + goto out; + default: + break; + } + } + +out: + hist_browser__delete(browser); + return 0; +} + +static void kvm_display(struct perf_kvm_stat *kvm) +{ + if (!use_browser) + print_result(kvm); + else + kvm__hists_browse(&kvm_hists.hists); +} + +#else + +static void kvm_display(struct perf_kvm_stat *kvm) +{ + use_browser = 0; + print_result(kvm); +} + +#endif /* HAVE_SLANG_SUPPORT */ + static const char *get_filename_for_perf_kvm(void) { const char *filename; @@ -970,12 +1060,15 @@ static int filter_cb(struct hist_entry *he, void *arg __maybe_unused) static void sort_result(struct perf_kvm_stat *kvm) { + struct ui_progress prog; const char *output_columns = "ev_name,sample,percent_sample," "time,percent_time,max_t,min_t,mean_t"; kvm_hists__reinit(output_columns, kvm->sort_key); + ui_progress__init(&prog, kvm_hists.hists.nr_entries, "Sorting..."); hists__collapse_resort(&kvm_hists.hists, NULL); hists__output_resort_cb(&kvm_hists.hists, NULL, filter_cb); + ui_progress__finish(); } static void print_vcpu_info(struct perf_kvm_stat *kvm) @@ -1577,7 +1670,14 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) if (!register_kvm_events_ops(kvm)) goto exit; - setup_pager(); + if (kvm->use_stdio) { + use_browser = 0; + setup_pager(); + } else { + use_browser = 1; + } + + setup_browser(false); kvm_hists__init(); @@ -1586,7 +1686,7 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) goto exit; sort_result(kvm); - print_result(kvm); + kvm_display(kvm); exit: return ret; @@ -1693,6 +1793,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) OPT_STRING('p', "pid", &kvm->opts.target.pid, "pid", "analyze events only for given process id(s)"), OPT_BOOLEAN('f', "force", &kvm->force, "don't complain, do it"), + OPT_BOOLEAN(0, "stdio", &kvm->use_stdio, "use the stdio interface"), OPT_END() }; @@ -1710,6 +1811,10 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) kvm_events_report_options); } +#ifndef HAVE_SLANG_SUPPORT + kvm->use_stdio = true; +#endif + if (!kvm->opts.target.pid) kvm->opts.target.system_wide = true; diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 35d03894fac3..bc6c8e38ef50 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -103,6 +103,7 @@ struct perf_kvm_stat { unsigned int display_time; bool live; bool force; + bool use_stdio; }; struct kvm_reg_events_ops { From patchwork Mon Mar 13 11:40:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 68804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1145397wrd; Mon, 13 Mar 2023 05:11:15 -0700 (PDT) X-Google-Smtp-Source: AK7set93/H7Lq4WN0/CnjKPcrE2ZjMQavytQ11n99dAAH+nA4KsemwOAwC76mPC1xcI2oRZG2P6z X-Received: by 2002:a17:90a:f018:b0:23b:4388:7d8a with SMTP id bt24-20020a17090af01800b0023b43887d8amr6554166pjb.21.1678709475516; Mon, 13 Mar 2023 05:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678709475; cv=none; d=google.com; s=arc-20160816; b=gfzmiRNPEaFi/6mZEoOZGtgjb/clAzL6Cuk8STUATg36HQMTI9jFA6zCxzt2jKv/04 YmZUB0TRBgVSvB+EfBVF+xSP/eueh7mvrtpO4VQ2VToDFze0SUwJNPXFHNBnAA3JI4Xb wvU2MU8OK0geIdRzhZlOeBrWQq6wxWt9RQdL+tvFL05XAtK/iZgi78iqZKbJjw9TJPgN +fWoUzj5LI/Ypa6//7raNnmBOTn8TkAkoygmYEeA7fpLLWxPhCQjydPrfkjUYWSo9gG1 TjYlKWWdgA0Xmbs7see2PRx39l5zDjl+IDZjOLqNpBcO6UPpZGNQfvpeNEi0AvLWb4Mx G0zg== 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=t1yEtOA/S7kgzfPudB0ZivwtY0/Ec+bbW+dtSNwunWQ=; b=Kb3wgWhqilfpDoudnfIaS5IRzDrV/IcRVtFX6IcVCUcS6uYwdMhXJOMhwkRpuSCnXP +OSDMhgV1vEP61KdEV+aQZOJ7ZzENzYHRBuKClS3lc2eKtNXJvh5MfaVQX7Hf1PgVdrN Jg//OK/CVQyUnihpeS/HFUr4N4Ywi+yq2o/96Whnv4uqKg1cuXgTNFh6q0hH0f3zr1Uz lLrJqGHlJq/icL1q5Rc8yueFyeo5zH3Lj4uGoleqQoGQzOnkE0R5GG7BUArjS1ugoUMk G+tEOC/K4v83kZW4weQmu8X2v1LRRSoZ6mzKAV3dc4mvzTfM9VLttc3eJe5m/Jv2jL51 0YUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PWzyhSH7; 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 z3-20020a170902d54300b0019cafd4c385si4515082plf.408.2023.03.13.05.11.02; Mon, 13 Mar 2023 05:11:15 -0700 (PDT) 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=PWzyhSH7; 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 S231415AbjCMLnl (ORCPT + 99 others); Mon, 13 Mar 2023 07:43:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231261AbjCMLmQ (ORCPT ); Mon, 13 Mar 2023 07:42:16 -0400 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 99ABF64844 for ; Mon, 13 Mar 2023 04:41:50 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id u3-20020a17090a450300b00239db6d7d47so11351630pjg.4 for ; Mon, 13 Mar 2023 04:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678707710; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t1yEtOA/S7kgzfPudB0ZivwtY0/Ec+bbW+dtSNwunWQ=; b=PWzyhSH7DDp3iwYN3Te37MQ9JYhNVv0IyBMtCysoB+Q/lCmbMl9dUCChzy+LyzPolw JEtrqhXuoSgr4KHUHE7B1IiTCuDdGVmQubZtZPynd+U+gDWle9nRGhK+ZVYlkO1fDJTg aEKGg0F2n0NWcWtUdQhG1M2uUrb8BuempT554KwuimR0EdpziZhwy9RYCKcfxgDQORW1 D1DWKJ5r8vcJYeGGrz/RIPMmjMc0XDM/gas3njQjhj9cQQRREk5DevndMWvjgYJWLdA5 KeQsh13PJS7joZ+qEfa/baZHCx5ZBaL56qr5ATxHpKjDMUipZRf4tgQ0/+8KMReUtTvr BK7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678707710; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t1yEtOA/S7kgzfPudB0ZivwtY0/Ec+bbW+dtSNwunWQ=; b=AbbbHUz1S1VqzgWBBQi1KnIK9r/v1U6Bvi2IyAUPzIGAuAe5AcWiTbLCh1KHQs6zK0 9VDoyzrfgFcDBSGAfbgP7g0TM2iBkDrxpG7gy47SXlYzewuVCowGVE9vVGC7Z4GqdIq1 nSZOEqiIsTzaxAUNunynkWPjHL3z8RVu9P6OSeV85R0AfWidFLmLVPYoN5C4afL/OwFZ fnYizkWdKtpFxFvzQm8OPG16NqeEMnXv1ZH3EbCx2pG5eujYlAzqRJIpC8KYDW2Bhtl1 fYAKA/1yhYS1XU1Y1yoeQorIw8jx/a48dclGCiQ3gBfIhPeP5hBL0x9uUWLdiKYmvLRr QNHQ== X-Gm-Message-State: AO0yUKV0xAfQpcWmGCohkEukEnDMbmLn5FKVSdlQsoOqxqjER4sGmL3j /9dN+GKv5A2mhTpWkugpiOs4Eg== X-Received: by 2002:a17:90b:3c49:b0:233:e1e6:33d4 with SMTP id pm9-20020a17090b3c4900b00233e1e633d4mr35154950pjb.47.1678707710206; Mon, 13 Mar 2023 04:41:50 -0700 (PDT) Received: from leoy-huanghe.lan ([156.59.236.112]) by smtp.gmail.com with ESMTPSA id q21-20020a17090a2e1500b0022335f1dae2sm4281625pjd.22.2023.03.13.04.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 04:41:49 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 16/16] perf kvm: Update documentation to reflect new changes Date: Mon, 13 Mar 2023 19:40:18 +0800 Message-Id: <20230313114018.543254-17-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230313114018.543254-1-leo.yan@linaro.org> References: <20230313114018.543254-1-leo.yan@linaro.org> MIME-Version: 1.0 X-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?1760254467137126795?= X-GMAIL-MSGID: =?utf-8?q?1760254467137126795?= Update documentation for new sorting and option '--stdio'. Signed-off-by: Leo Yan Reviewed-by: James Clark --- tools/perf/Documentation/perf-kvm.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt index 2ad3f5d9f72b..b66be66fe836 100644 --- a/tools/perf/Documentation/perf-kvm.txt +++ b/tools/perf/Documentation/perf-kvm.txt @@ -58,7 +58,7 @@ There are a couple of variants of perf kvm: events. 'perf kvm stat report' reports statistical data which includes events - handled time, samples, and so on. + handled sample, percent_sample, time, percent_time, max_t, min_t, mean_t. 'perf kvm stat live' reports statistical data in a live mode (similar to record + report but with statistical data updated live at a given display @@ -82,6 +82,8 @@ OPTIONS :GMEXAMPLESUBCMD: top include::guest-files.txt[] +--stdio:: Use the stdio interface. + -v:: --verbose:: Be more verbose (show counter open errors, etc). @@ -97,7 +99,10 @@ STAT REPORT OPTIONS -k:: --key=:: Sorting key. Possible values: sample (default, sort by samples - number), time (sort by average time). + number), percent_sample (sort by sample percentage), time + (sort by average time), precent_time (sort by time percentage), + max_t (sort by maximum time), min_t (sort by minimum time), mean_t + (sort by mean time). -p:: --pid=:: Analyze events only for given process ID(s) (comma separated list).