Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp278348pxb; Sat, 21 Aug 2021 02:21:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwo1PqnxOcvclNL23Myz4/ysO2e4gIchb6NvLSD3Z/Hb5Xp9xKxG0413KUaExzkYmdd4qsF X-Received: by 2002:a6b:7a03:: with SMTP id h3mr11110381iom.39.1629537709502; 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=GijgVZb4Vr9QrkRvc+HbhDsC1p09J77SOgCLfDjL2ggPJWKsRWXwSOzyqnLcSPTZfd M411NOeButNSjTnff54a2dZBpG2d9sl/Wc9wJANoXQaH24NliCrY9EYUH+OboXzoEXJr hNzXGaO2oUCk6hSyFhSvlXTtWdhZ9w66iW8qRwwQJ/71uugL0RY4Tma9EvZPWW42CPJY 53VAykAsx+JFUcQauvlNp47oqT9QY/V9uUp8FCtBO9gSUWwBllDXBFbE4Wxgh0Kkd+3c lJTsYrJ+nFg+L15x7coSr7U+g4S3D3rh5dNAh1xhTXNPQeJnlrj653mL/jKAPRrIWQPF a9OA== 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=GDP1MLL1Qg0dnIIFehlblVPtQewpoe7l+lrwKCe2/Qk=; b=HfuJ89yja17VYXbVQ/3AxBzhjVYFJZuJ9QAUWqncVldXaA7bQK2TYZWwzWb2caHwkG 0ursG+4t/0xlXWEcA96X5ErbQR1ws3cIIoRMh1tkz67DitFkxaVEuvPsPsdjTl3L0d1t Vb/OtzidWToCoC4YcbDbZ1My+howwg3PpIg3FkGEAszncfRWMiFqKVRmZPyti9y9s/K9 wZ1LI/OPRkkcARhaWgoPgyEAjYMaYPRi402VIB6naLO/C5Ak9n8m29/CeJpP09TVl3Jk UBNL0gvZRZDgTXMDXLJ7RPtNN7QAmhwFcIt3rPh3/fIcJ0IMGxJRbdp1VzCKwHMmfJ1K lHdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gvuvUP4K; 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 o14si11078855ilj.89.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=gvuvUP4K; 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 S233551AbhHUJUa (ORCPT + 99 others); Sat, 21 Aug 2021 05:20:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233478AbhHUJU2 (ORCPT ); Sat, 21 Aug 2021 05:20:28 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B071C061575; Sat, 21 Aug 2021 02:19:49 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id q3so17660657edt.5; Sat, 21 Aug 2021 02:19:49 -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=GDP1MLL1Qg0dnIIFehlblVPtQewpoe7l+lrwKCe2/Qk=; b=gvuvUP4K8VAsRQXs8iaxCIOLZ2hgDYsfWfsFAsaNSwAEYkWQ/cbp6CmgbOKpmL2ba0 qfXF3SdKmYWLx0LYICMPcwDD7p1QXq+WqYJnKFZmnj3p/sj2Deb9OsDClZsi1Gr+isrj VFkDg0lJowsuvRFG6vFfTJcAOd23umQ2YDWQ1rMDIplTmMigt0ldWgftZYKQJ5fdZKp8 na5uCnJtZ/OAkJxRHJpkWEz+2xKafbrqsFpI3unVYP3VKVQAj0pH2rJ94XpCYIeieFdI 75YM0lqXc0FW9zOA5OWHRzuk6es8IIShY/jqjWi6/qs3Vmk12c5tJAPk4g5h/LTlc9HJ 09lA== 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=GDP1MLL1Qg0dnIIFehlblVPtQewpoe7l+lrwKCe2/Qk=; b=QuNv9qp/gPwKUrDn7gI+ms0ryFsPEqq5mbVWoOiXAm9MY4g3a7XR1RhccmY0tLszQT 5j3wMUCflyIGaReVoTHTYZnYPel9VY7j+4nDShxXVeM/M7+rN8D2R0bCLSFLe+khqpf7 lagQa1c4Kjyqp8SXHIcYndWlncFwC3vDXF+h5ho1dfSaiVQ2Ww1ypfcrBr/X/U1Rks8b 0s1wlYtRKmVcweNh+AqTsn2n6YOzAs6Mi8CdtyFhh8AgjsHU/FVJBUJ26lBpNkSGUjUz UH4/xIBZLmMEqDy8FoYaCV+qGb56+OoBzr28o5eqg7BOk1X+WcaBADai+9bnBt9MepK8 Kocg== X-Gm-Message-State: AOAM530TzPWXfDPlXzrsM8dqYJIhhV3WcTJPob+iH9nfIcciufuaoUoY q+UOprtaYJHh4jnR9L46lZ8= X-Received: by 2002:a05:6402:1694:: with SMTP id a20mr26812801edv.99.1629537587766; Sat, 21 Aug 2021 02:19:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Aug 2021 02:19:47 -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 01/37] libperf cpumap: improve idx function Date: Sat, 21 Aug 2021 11:19:07 +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__idx function by using a binary search. Signed-off-by: Riccardo Mancini --- tools/lib/perf/cpumap.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index ca0215047c326af4..fb633272be3aaed9 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -265,11 +265,18 @@ bool perf_cpu_map__empty(const struct perf_cpu_map *map) int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu) { - int i; + int low = 0, high = cpus->nr, idx, cpu_at_idx; - for (i = 0; i < cpus->nr; ++i) { - if (cpus->map[i] == cpu) - return i; + while (low < high) { + idx = (low + high) / 2; + cpu_at_idx = cpus->map[idx]; + + if (cpu_at_idx == cpu) + return idx; + else if (cpu_at_idx > cpu) + high = idx; + else + low = idx+1; } return -1; -- 2.31.1