From patchwork Wed Mar 15 14:51:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13176011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C1129C61DA4 for ; Wed, 15 Mar 2023 14:53:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FwaTcp3EsnYcNyH/mioeizBhVjaChY/9u2Drjc6PO4o=; b=zkar+bfFxZ/IVc 3D+xyHZFbKhFyWkZfPwPQ2h/LgFa8T0EeuFmbMqG87b1VUsYRBbI3fHVw1vG+/QwABIH8Qw4Kl4kA WwXDblkHgpECiYVDlJRqhSjFYyNgHrtnHTGON6r6XgJBrfrc1ZMVHHtZoATXxSx2N3UTXb4sANyRE EvcwrqK/+jM8g6bhm7oIS9ey8MXiiGBlFEitEa69mFn5ZDezuOeZa4r/FIuW1D50JVuITz60MOk53 8dkzt23xWKqHg0S19Mg3JFJEYUppxqIj7Jl7/4rp7iSrGsShXgQhlZAfapiqJ9C4AKmVMPzgwyX2E NFZf0zbsOgP3m+Qn+4FA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUp-00DfsG-1t; Wed, 15 Mar 2023 14:52:55 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUi-00DfmP-2r for linux-arm-kernel@bombadil.infradead.org; Wed, 15 Mar 2023 14:52:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=GXjE1lNyQ6Ulq2wrJYSF6aHLvPPQtJdwrD75rVojf8A=; b=kswYYHYiGvWeIu3RtEJDmrZWZw GN6oHMFJUOIZUOs4/wWAiCbyznwbuA8NP70rI6Du3L8bPGTMFFdswWjX90JG+zm2UrSBAUZ0Xvs4e NMXfCqNnTYQLhZWS+XRxamm3GqE5NGkDfeW+OkM69xeh9IjDly/Tw8S7rKeyyUdnTL636W1BK47EG b1j4KFtCtKTv7J5CmaLqGaDRVaSk1JJElUmcMUvwIoO661nZkoSnDqVvN+gKc8lTM3IIFbrbbkfwl MpM7oS0BUXEXOM/UuAPLCY5yNBz25CbokpfJU97Rb3X9tpFxB0EML7rlET3M1LiGl+hJ/lWDp1MVz W8DRKcnQ==; Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSUd-00289g-0X for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:52:45 +0000 Received: by mail-pl1-x62f.google.com with SMTP id p20so20268316plw.13 for ; Wed, 15 Mar 2023 07:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891959; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GXjE1lNyQ6Ulq2wrJYSF6aHLvPPQtJdwrD75rVojf8A=; b=BCoP6UXH2x8VV6ZsOW13Ae9hQ4T2I9/6OiiOOf26BOC3ZUWn3FhlVxYrwF0uGT2820 Z89j0GTbYPZbd2m0FTGAmQ3aeVDmEJtZzF1e/zHOZHQEwvVoNGq/xuYbvVwuqdT9d1ZE SMzXSpKbDY/rFapSOecLZBq8+zwdrzi6TujVS4OhT+wrSE/zUcm1EjBldfw1Mq+JajgA BwHIdRwEWuAS/5nOs4hcd4JPjVlkula1o2YjLf8HFYGm+SX7NX03Ph2xIXtoPM/cMhIv H8Lrwb4ru/Wj3svRHVKnevbHu7BtAfzHGDj+o4Dms7Ia98uaFLE1ZLCxRbiXzLeDdOr0 sfeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891959; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GXjE1lNyQ6Ulq2wrJYSF6aHLvPPQtJdwrD75rVojf8A=; b=QPW8ZXtq17MC369h+H2jauZTBNuRK0aA9uIHLdEbvc5qYKnIEmDIONgwfxiaTio1sD 2Tl4SL3sVH0Hd1/gdK5T2OwTvdX2DlU+MMeDGGIcqY3mNDoyhl2ENhxSRvZcGeWqlkLH wJGWy/kXtkyi5CS5ZHmvsmysYY9HmNYrUJuzDY4Yyi+tby2UYbDm+I/vh0iANLvH6IY7 oGdblKu2fp6s6MJYEmzmRJb2ST7XPVycRbwW0IUCFhyseB35AE+nCBtPGbd5rIstqRzP n0DqO03SWI0awiwgBHJPwCRT4LtCVd8idrVUPYIx4mCCbcIWMxj9UKT12pJTli8/dsnT Unxw== X-Gm-Message-State: AO0yUKXYZLgNvYAMppz9a4IgFcdK+Ji0BE8GwVMIzlODXk3bqU1EUN3s Z3qtSOUeXFWGj2W9u353r6AxCw== X-Google-Smtp-Source: AK7set/x2sbhiI0KJMwBONL5ZF5YA0yPzV1seKM6HmyYEhYd4ut50lJhZLlgYJcc5Kcg6TFT3KxMtg== X-Received: by 2002:a17:902:f54e:b0:1a0:76d1:545c with SMTP id h14-20020a170902f54e00b001a076d1545cmr2950647plf.10.1678891958787; Wed, 15 Mar 2023 07:52:38 -0700 (PDT) Received: from leoy-huanghe.lan ([107.151.177.133]) by smtp.gmail.com with ESMTPSA id kh3-20020a170903064300b0019926c77577sm3781587plb.90.2023.03.15.07.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:52:38 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v5 12/16] perf kvm: Polish sorting key Date: Wed, 15 Mar 2023 22:51:08 +0800 Message-Id: <20230315145112.186603-13-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315145112.186603-1-leo.yan@linaro.org> References: <20230315145112.186603-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230315_145243_543316_4B74DCDA X-CRM114-Status: GOOD ( 17.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since histograms supports sorting, the tool doesn't need to maintain the mapping between the sorting keys and the corresponding comparison callbacks, therefore, this patch removes structure kvm_event_key. But we still need to validate the sorting key, this patch uses an array for sorting keys and renames function select_key() to is_valid_key() to validate the sorting key passed by user. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 29 ++++++++++------------------- tools/perf/util/kvm-stat.h | 8 -------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index ba3134613bcb..1e9338855239 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -76,15 +76,6 @@ COMPARE_EVENT_KEY(min, stats.min); COMPARE_EVENT_KEY(count, stats.n); COMPARE_EVENT_KEY(mean, stats.mean); -#define DEF_SORT_NAME_KEY(name, compare_key) \ - { #name, cmp_event_ ## compare_key } - -static struct kvm_event_key keys[] = { - DEF_SORT_NAME_KEY(sample, count), - DEF_SORT_NAME_KEY(time, mean), - { NULL, NULL } -}; - struct kvm_hists { struct hists hists; struct perf_hpp_list list; @@ -757,18 +748,18 @@ static bool handle_kvm_event(struct perf_kvm_stat *kvm, return true; } -static bool select_key(struct perf_kvm_stat *kvm) +static bool is_valid_key(struct perf_kvm_stat *kvm) { - int i; + static const char *key_array[] = { + "ev_name", "sample", "time", "max_t", "min_t", "mean_t", + }; + unsigned int i; - for (i = 0; keys[i].name; i++) { - if (!strcmp(keys[i].name, kvm->sort_key)) { - kvm->compare = keys[i].key; + for (i = 0; i < ARRAY_SIZE(key_array); i++) + if (!strcmp(key_array[i], kvm->sort_key)) return true; - } - } - pr_err("Unknown compare key:%s\n", kvm->sort_key); + pr_err("Unsupported sort key: %s\n", kvm->sort_key); return false; } @@ -1198,7 +1189,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm) return ret; if (!verify_vcpu(kvm->trace_vcpu) || - !select_key(kvm) || + !is_valid_key(kvm) || !register_kvm_events_ops(kvm)) { goto out; } @@ -1393,7 +1384,7 @@ static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) if (!verify_vcpu(vcpu)) goto exit; - if (!select_key(kvm)) + if (!is_valid_key(kvm)) goto exit; if (!register_kvm_events_ops(kvm)) diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 3f0cbecb862c..35d03894fac3 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -49,13 +49,6 @@ struct kvm_event { struct hist_entry he; }; -typedef int64_t (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); - -struct kvm_event_key { - const char *name; - key_cmp_fun key; -}; - struct child_event_ops { void (*get_key)(struct evsel *evsel, struct perf_sample *sample, @@ -98,7 +91,6 @@ struct perf_kvm_stat { const char *exit_reasons_isa; struct kvm_events_ops *events_ops; - key_cmp_fun compare; u64 total_time; u64 total_count;