Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4729153pxb; Tue, 31 Aug 2021 11:49:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8pbXJcTPq/zf6xCQ9WZZJa6hthal0Epws+YoTs//tJ+JP7HSLvCRkqi++hJRwyI2F1HUV X-Received: by 2002:a02:1cc5:: with SMTP id c188mr4247846jac.46.1630435791011; Tue, 31 Aug 2021 11:49:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630435791; cv=none; d=google.com; s=arc-20160816; b=OsOivO8ycmiC/iG48g6776ShUzFZOJhySMks8ZeccrGVFHt+UgUvB0nXDpQ+ECJ0sx YezoGA1CHbXdwqDZGP20wiw7G5IOGGWjM3atUmobfkgcrZvVV3/omU51l5Sw8b/Cd8gU nxZeDqCl8vbCjapVFVndlI27HS3wnbLlYjyK2af79gvN04SS35sUIATJEr9JQ60cLAOa pdWne7l2gRwrO3+Zra2jjrk7Wq/3ubZUNPaxYNHj2ryNiGfngB5ADIdwEg2UiFiBTKmK 3WB91JJR2IRf4U7RKZ5Q2W27fAu82mgkqrOFNXstx9KbkM70hZeHaFI7rw1gBjDOlT4g 9fPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=frP76FVAHDdKVds3PfTqJOn0r+5HF18ZKmbXB1xA7bk=; b=UrEmRFCKgmU5niFNyDgZS20hdOyME3FIGOO4CfJQwjz2FK/J8jX5W14WD8aggLDsd3 5XPEhCoc3n5J1iFFdwVJNFGBL+X4HfHtJRXg7W+D4sBSAYNIiFc7bVh/OHB+n9O9Nela FWqbYYr6B/G6E3jsobj5xEFchwQuYCpN3oxuZmvTYDNLXh8XuQPUDV2iV0FJNJAkhh+0 sE0sVWJPtKV6soEe9Eiy11nrUqAefFTZf5AeWIn7OlDr1356N7RVPa6zoB661msAAx1U YgqSuqiNqkP1YqR0EdH9YWzegnrhubkbLu7L2xPJ6HSk2e+2k8jxo5KS0TsqIJREFpNm GzEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G6qXQvPA; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a14si16688768iod.86.2021.08.31.11.49.39; Tue, 31 Aug 2021 11:49:50 -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=@kernel.org header.s=k20201202 header.b=G6qXQvPA; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239316AbhHaSrc (ORCPT + 99 others); Tue, 31 Aug 2021 14:47:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:56616 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239280AbhHaSrb (ORCPT ); Tue, 31 Aug 2021 14:47:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 825176056B; Tue, 31 Aug 2021 18:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630435595; bh=kTXrNmPAOjCCJ87XuzHaMszrCV1Jfzu38Ezem81EJ/E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=G6qXQvPARkrHm3Ca+RTu4DzO5nw5PbL2A+/CBzgbRuIPi8sW9f3Q/rXP3Ni6Wkbyp 7++7YQ7jipWuNR2QgTxgUqVLlaQ9Ugv2u19BH+MV8f+7KI8FAR+YJAjp3aPGUklydD NM6ZP2wkxs53iin29VnoLs1fa68pX1RfJ0QXwDxy44wPB55NPi4B26CvHQEVYkECP9 2wwt+4qkKBK465ZImQ4XcagvMzZGToTpyxLGY49xWfJQ4J1oOfdU5s7Ha+VygSmUEj 0hcfuczwqtrPJmF5BNwCv934yh1CiBNPfGVM17b1+FoYNwQBfN98Xc9hTwre9wO2eD NaqIsWJxYIllA== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id EF4384007E; Tue, 31 Aug 2021 15:46:32 -0300 (-03) Date: Tue, 31 Aug 2021 15:46:32 -0300 From: Arnaldo Carvalho de Melo To: Riccardo Mancini Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [RFC PATCH v1 01/37] libperf cpumap: improve idx function Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sat, Aug 21, 2021 at 11:19:07AM +0200, Riccardo Mancini escreveu: > >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. Why not use bsearch()? See 'man bsearch' and look at the example. - Arnaldo > 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 -- - Arnaldo