Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp278349pxb; Sat, 21 Aug 2021 02:21:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWeN8WwN7lMqpJnN9+RwjMWA1Tn0M35V+qnX+QCbMWE5gf8Gm8DMwk4MlcFHzQCGQpZyK+ X-Received: by 2002:a05:6e02:174c:: with SMTP id y12mr15639046ill.35.1629537709496; Sat, 21 Aug 2021 02:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629537709; cv=none; d=google.com; s=arc-20160816; b=T+AKl6TX6lWskY7xYSwGZMAzw6Zmi7I417Y/qUsopKbASpeMCOjUvi6JhBT517s8VQ +BWItYPpECx9fNwSz4upb5FF0OrT/fSk/qqR9vZBAcqoz6zXL6oAi0GZXXT+pnR/Mjxg yGCfWhUVuZ2zX02+hLrqAxqiuOoY7qHs/6YHgfNeK/Gm5FLoWIPHyMzp4xe+vBzRY128 zEgKUn7qMqSZeXuwdFw7yd3N+WBbnuMe2WKeoVyOz9oIjJMWeK8Ghiwbu7PJAQJ/Bm1q cm87k4S063aabnW+cBJGO4kRUlYp0vfDjERE4Alz4sqmAKGfTTk2Um1Hr+amXLUTbbke jHNA== 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=mbPZDp/xkJGnPgN5FrjhXWQn3CwvReLDj7zmHU7fpVM=; b=ByBok08j9yrIxYxKIOwwe55r5ukjWOeL2d4Et6GADmDlqHTpaglENVTJ3VOnZ8OeJJ vYduBtL1AoNeac1aXRsbUvZOwnv6wlEk4SqJP6+cyvl5dVq3i3979djtidH6NH+mFQTu C5p0lex6dB75bLDh3Eqy773ZXabY3PJNAygAY1GHZrCIaewSkw/YRT5bon7Ia90h6tAz gHRTLhO6GfzF93pfP/UfPqazC9RrprXxFWBAzFdmXjuiyyWC7NFgRzc9tHEE5VRTlOWh xIbAmCSl+qngkyu3mDR8HL5zctkMWkUofVUVEuWianWzD0go7GVh9h4uX/HCRW7S4hnN rlhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q4cdAiRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y12si9326605jai.84.2021.08.21.02.21.19; Sat, 21 Aug 2021 02:21:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q4cdAiRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233695AbhHUJUc (ORCPT + 99 others); Sat, 21 Aug 2021 05:20:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233524AbhHUJUa (ORCPT ); Sat, 21 Aug 2021 05:20:30 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A63EEC061575; Sat, 21 Aug 2021 02:19:50 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id mf2so6671166ejb.9; Sat, 21 Aug 2021 02:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mbPZDp/xkJGnPgN5FrjhXWQn3CwvReLDj7zmHU7fpVM=; b=Q4cdAiRLpALsYo/BGM1e4/Df3zq8rBBfAO6wg/DJ7kxr5ekEoVLYHJHMt4ye1YZzw9 50RWVjwqc86ZX2sWywYTM4z8YL8egBA5ZkfA0u88cittsY0xVyrdlcEwDMxmV49JEuJR Qnb17XXmligG5zNmGsEf/Kn7bhTnhASE7QnRiWgBW+3G06cI6p7Tpyb9SwZ4DCQOjuk/ cxdtXV/gsgBQnc3fOGty4aP8QPmL7fBR2daZ3OzX5JITg1eOROUBgPy6L8wlQ98Ys5uD xjas/+qU8KloLKPJhGacXcVQVzG9U5YyuegS+005sigqFUGEB73OdcoenbSAW3jHtbe9 2N5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mbPZDp/xkJGnPgN5FrjhXWQn3CwvReLDj7zmHU7fpVM=; b=OebV9gypuPZsUfJfBvLWa6GZqZRTHKosPnT3Z1nTDg1hzZ4Uh9JIVpfQutBZwb3KLJ FQR2bypNLS2Ed/yodBLJz9LopZDXokRBlEva0KRCpkibO9UZi2P83lRAClIYOrfWWqw9 c6rqMUa+AQPRQx1w8TlnteVHTFSZCZftpH4UZH6jvqVOZbO9roExV9Lh9nMD3jO53Eh1 TMBkZmgxMtMM4oQ4GdRYu9OqvqnKu6F8uDgr7EpoGb2SjpdkuxG5GOQ7QsLYs2JLCdER /FupAVB9RUFap3IYginjBrf9RJU6HJOfnI0ZtKizXKlJM3VgoJHuvSzKeAoxKIVx96pK GKog== X-Gm-Message-State: AOAM530xwLsxhiaEU5wNJmeu6G/IH60nSL00LTqvNw8jQw8zZfEt7UkW kchy86JeHGTM4hYfV+7C79U= X-Received: by 2002:a17:906:3b54:: with SMTP id h20mr22119315ejf.436.1629537589196; Sat, 21 Aug 2021 02:19:49 -0700 (PDT) Received: from honeypot.. (mob-176-243-254-204.net.vodafone.it. [176.243.254.204]) by smtp.googlemail.com with ESMTPSA id a25sm4003878ejv.91.2021.08.21.02.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Aug 2021 02:19:48 -0700 (PDT) From: Riccardo Mancini To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Riccardo Mancini Subject: [RFC PATCH v1 02/37] libperf cpumap: improve max function Date: Sat, 21 Aug 2021 11:19:08 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From commit 7074674e7338863e ("perf cpumap: Maintain cpumaps ordered and without dups"), perf_cpu_map elements are sorted in ascending order. This patch improves the perf_cpu_map__max function by returning the last element. Signed-off-by: Riccardo Mancini --- tools/lib/perf/cpumap.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index fb633272be3aaed9..80e03b2f0c60cce7 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -284,14 +284,10 @@ int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu) int perf_cpu_map__max(struct perf_cpu_map *map) { - int i, max = -1; - - for (i = 0; i < map->nr; i++) { - if (map->map[i] > max) - max = map->map[i]; - } - - return max; + if (map->nr > 0) + return map->map[map->nr-1]; + else + return -1; } /* -- 2.31.1