Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2422728pxb; Fri, 8 Oct 2021 07:31:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzorZNGu4AwtP29nPi4yK1N128ncknrzMaPfVvY5uwS1QmIfpZ3yxFlfoco769mSyUzVKsK X-Received: by 2002:a17:90a:46c2:: with SMTP id x2mr12893210pjg.207.1633703482294; Fri, 08 Oct 2021 07:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633703482; cv=none; d=google.com; s=arc-20160816; b=VLRTeSM+RDh7B8Lt71sDaa+Ca6epn7nrZJBNbdd57mXX4Rt2jCLPNTtCMGWkOOtGGN aRbXQDve5W0vmBkU5P8lL6yBpkxXDUei3MMIT94wdKldAnefpe3IB4s4AFtLklEi+/2l wsbtlCmk+wOfITKvzduATDX8ymme8JJwpiububp3Yb+m25Hj9ySHX5elmBrV7lB/Qwf+ KU6+VvG6y3vKKGxp5XfOigv5Qp8bgOy7zD1E3g2FemJHNDgzy17wWplBg/tB8jUdDq8z nn6/QxcUMz4ejRibk+X1Cei/vVrmpYbf64G0S3pW0ZTnwukCBEhgJJb0B5pzCzCuM56a EYkw== 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=L3iAbXHXxVASnU3Y+KODqZ48FNhyNtE/2+plG2Ioy3Q=; b=UmzyICGorUpz/+GdGqKsThG9E2aC5i/9YxZdipIgq1WOVCOZfoJg/ktwkD8wThoKc7 Aq9T4XYHJZqegTw6UL1D8ud9E550TgD260rS1xja82xt6KxvclDTlK7gFX5l6GkmfqZu GbPaTzbduthDlqCUHKELlLVM+seJJyqx1PtZziaam51BcBnDxtVn97CkZZZ/vyKF8T4W 3DrY16X3frOCNe4pI3CyVr8rpAi2IP10LsHDqH1C6LHEG3TjaDlhuOBBL9fRef1BJFAS UzMir+rGQdrW43qC8bdv4oLFj/rkbvB6Z2hlY088wKLG40ev+1d1ZLx1Pm6sFpjThzed O/ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XelR3LJX; 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 ij6si3362203plb.350.2021.10.08.07.31.07; Fri, 08 Oct 2021 07:31:22 -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=XelR3LJX; 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 S238915AbhJHObO (ORCPT + 99 others); Fri, 8 Oct 2021 10:31:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:42936 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbhJHObJ (ORCPT ); Fri, 8 Oct 2021 10:31:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 143D460EB6; Fri, 8 Oct 2021 14:29:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633703354; bh=8okn7WP++OasUoqVVEB1PJg6oI3Q18MMY20pDXxku2M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XelR3LJXFLSXs7lgpCH8wyXJ/sZ7T24II38jHjkrAi3W37jkBXIK0VhPJ9BtWtRge bxBW3lHLheFQckuVxTfmnQYkoY9UFrZ51cXbofV7E5vEAXUOnaOzPeU5+1oOqvBLOU r82S7JJJ3JNSDoR/5zI9u+nPGk7Lvlh5P1tQCfqJCXGAgj6VtH4gDd8VrLVavFqT2W NjYuvC/eq4LpwX09kMHqjd/RSoGkogbetKJPd1DJbAHvwybn2CjxUd/2+higVD4xQ1 MBHKUnYKvpwnRv69AjzrSevsvU1aWUgeQ28Gp0ZsewP5dz/gOqOaFD77hllbFyLbnL /uXsDmbLr+9pA== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id D994A410A1; Fri, 8 Oct 2021 11:29:10 -0300 (-03) Date: Fri, 8 Oct 2021 11:29:10 -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. Thanks, applied. - 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