From patchwork Wed Mar 15 14:51:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13175983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2EE73C6FD1D for ; Wed, 15 Mar 2023 14:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PJGapw9uA+hjxTx8SHSM/Lls3Hh8kio0/yVeV1a4LLE=; b=pl3Ok8q1IKAgbh f7GyMFDNVT44YIq5qLxdVc9CHik7rub662PMVbXlY2oUBA52CNnuD5jf517Nj2R2IZdPjO8FIeuzB 0zgpUYurv2XvQa+in3qnxejPi8VwTazVg1g55M2gHWaIFiE7oCedW7s/MO53hYFuT7kkoPnzq5Gk7 yQ+oXqy9u1R8whdIZn2N9Ocq/L9GM+C4r+lqTBYbXjfDWAqLES/iqsoHlrutF9lZADRb41QJoXFHX 0NKOCJDlMSBP/LhkUSxnZKCICP4/fFbHd5nrOkONbZCq8ouXyOQH47jLAfiCFJPrwb1hBOLYvEpyJ sfRzh7Azx+Hdcg047cJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTw-00DfG8-1J; Wed, 15 Mar 2023 14:52:00 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pcSTq-00DfDT-0H for linux-arm-kernel@lists.infradead.org; Wed, 15 Mar 2023 14:51:55 +0000 Received: by mail-pl1-x633.google.com with SMTP id x11so20265289pln.12 for ; Wed, 15 Mar 2023 07:51:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678891913; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cd+dkas2glmconcA3nZgOv1IgDvFJOrEFeQZRwvRr9Q=; b=YfMLFLfFXMW5NCpCaRGVHpsK7tI9UBEjIKHVIzaHfGrbedKISm9IE63szUmP0A5hXc R89hHVJJt+esMau2kph4nwZrNEcq8uYxo6x2zXz/r+d7/1Okwxl+v3WF2xwrIDLWcdbs rKjbrgvUGpiPsxhu3jCpASTHDCYRUxlQkQZL/UpPYcesmaXrfepoteyH7ey556AoKLcV kgVebWHBYJbNVH6hI0+VGA6MgvbltWc4xx+/j9J3eeyRFLH5gEKiC5Atg7pquz8y8K4h oQyFyszZGeEd0EK8lsiKu8mQFMxAZsbFmp/dtszSePeLqEOnyuglHR6oSJuvjfqXPNPr M3Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891913; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cd+dkas2glmconcA3nZgOv1IgDvFJOrEFeQZRwvRr9Q=; b=kh1jyRS4NTxV8jKIZ45l++L1gZj54Z57SEvFZ6eRR4+KYzzGLvnrgQUWIrMJeF5E0j ZLDW0pP5hwFHs5h1uKWD1xcVLjQRzObkn60jODb38KxC1FvpqX2gvUenzM1qvBcufyDV 0DPG5LTy4W4m64qJJPxAfGzfKZh0pBza1gJoCRzlb1qDhciKyc2BdLi8LfKnN4N/7yxF cNuJsZEMQ0XJzUw+G/WrRj8e9cKzfkDpyuAVKb5kSbgkaW4ZxnhzH4TT0f9+yjfhs6D7 ZimGfcAoZ+RIbt3chOaPbf4FY6TieUz/J2ZbV0QUVdPwUqQ94XULwt29TOIs3EaR/SjM CcBg== X-Gm-Message-State: AO0yUKV07ROMB7QNFFn/G6C0VS9xylsXNZwBSAw8C3IAccG8l1RARPVd QnV0bsEJvKKgOqr8tVtKpuF8lA== X-Google-Smtp-Source: AK7set+OD/ekdbUPyKgmlJavsWyrlHgkyNT+r7p946TYxjT0XL2xAzkm0EgeNF4uEnXoKDJhxpAPAQ== X-Received: by 2002:a17:903:234a:b0:19f:3797:d8de with SMTP id c10-20020a170903234a00b0019f3797d8demr3589747plh.9.1678891913436; Wed, 15 Mar 2023 07:51:53 -0700 (PDT) Received: from leoy-huanghe.lan ([107.151.177.133]) by smtp.gmail.com with ESMTPSA id kh3-20020a170903064300b0019926c77577sm3781587plb.90.2023.03.15.07.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:51:53 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , John Garry , James Clark , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v5 04/16] perf kvm: Use subtraction for comparison metrics Date: Wed, 15 Mar 2023 22:51:00 +0800 Message-Id: <20230315145112.186603-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230315145112.186603-1-leo.yan@linaro.org> References: <20230315145112.186603-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230315_075154_124504_4EBC71CF X-CRM114-Status: GOOD ( 15.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently the metrics comparison uses greater operator (>), it returns the boolean value (0 or 1). This patch changes to use subtraction as comparison result, which can be used by histograms sorting. Since the subtraction result is u64 type, we change key_cmp_fun's return type to int64_t to avoid overflow. Signed-off-by: Leo Yan --- tools/perf/builtin-kvm.c | 6 +++--- tools/perf/util/kvm-stat.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 62c097a37da9..4e9519390da6 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -63,10 +63,10 @@ static u64 get_event_ ##func(struct kvm_event *event, int vcpu) \ #define COMPARE_EVENT_KEY(func, field) \ GET_EVENT_KEY(func, field) \ -static int cmp_event_ ## func(struct kvm_event *one, \ +static int64_t cmp_event_ ## func(struct kvm_event *one, \ struct kvm_event *two, int vcpu) \ { \ - return get_event_ ##func(one, vcpu) > \ + return get_event_ ##func(one, vcpu) - \ get_event_ ##func(two, vcpu); \ } @@ -523,7 +523,7 @@ static void insert_to_result(struct rb_root *result, struct kvm_event *event, p = container_of(*rb, struct kvm_event, rb); parent = *rb; - if (bigger(event, p, vcpu)) + if (bigger(event, p, vcpu) > 0) rb = &(*rb)->rb_left; else rb = &(*rb)->rb_right; diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index 40a4b66cfee6..0c2400d9b227 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -40,7 +40,7 @@ struct kvm_event { struct kvm_event_stats *vcpu; }; -typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); +typedef int64_t (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); struct kvm_event_key { const char *name;