Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4749984pxb; Tue, 31 Aug 2021 12:20:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0k7uG7OOM5najO6tzSnUsjKcwFULJ+puJ1ljxFxD6UMOT3ZV2nbuEY3hnPQQ5bY+KxuHc X-Received: by 2002:a92:cc01:: with SMTP id s1mr22774821ilp.15.1630437608074; Tue, 31 Aug 2021 12:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630437608; cv=none; d=google.com; s=arc-20160816; b=HIP/P2ONOUObloJePVrxkeQt/UhcdbJYIRRpPj7btav1arGio9vA1tCVkJXFZp5lBa QoMe7jLIbt7vbuIa+VrQksVir/sE8y14HKG4Bd7lY6gLJv/ar9FoON4ZzT2zphN2hA7v c3h/j55dWd/uPWg641UOB4TwWM2q/v/NWnR6svI2nNFpNyS8S6RBmFpKP8IugrtosB7c 4OHBVsaCpQmkv1NecEx9NANGocfpwGlss2yPWs/R1x4uB0eoSyW5Xe6D8llOCFY/605N t6t0dU7gcp+UgBUwagSix577FIq/L1i4DM6A26wH48l8Yb7Dvv6B/UZHxrneVt1sfBno aBeA== 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=ZTNngZ2de6kLaDkmjy5uyJMqn4seUQqFp7Vc9nGKak0=; b=0y8TItsHb9jn38EOXQM5V/BW7L1I6KwNjCHGm55C/L2UkbYTqY9rAFfTGKdJ2fnwnj QD3zPNkb48iSRI65wB6fxS+fT0Eslz5ylue8mbc/F/pzMP444ilXIeyfnCLVgoLiw28w fYTb+cWeIAg9XLQ+ANjjzfToeHTzvAacOAYmfxBBXxMK5aNBMO7fi+p+FawhHEOclu3F FEhKCqwfnpVXlkqePf2REQTs5GM7UHuEY29DEqvlR7lBOWHmUOo3zh5HXUAjBGs6XrTU HiEayt7uwcYpKHLEyaM6j0TsEeGtx65I9kI+G4ZiMYG7V0UDvolL7JkCsBGNx6riH65o ITIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="eoGIT/5e"; 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 m9si18824441jap.72.2021.08.31.12.19.51; Tue, 31 Aug 2021 12:20:08 -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="eoGIT/5e"; 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 S240524AbhHaTR5 (ORCPT + 99 others); Tue, 31 Aug 2021 15:17:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:38524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231938AbhHaTR5 (ORCPT ); Tue, 31 Aug 2021 15:17:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7682161057; Tue, 31 Aug 2021 19:17:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630437421; bh=bTQUHDephO2BwXAw6npExcZWHUGXMCAV4h/ZXp453S0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eoGIT/5ecE7FeDZWcHzNQ7gI5GmMz1XF7CYKFfnRfVVOrS2wCBNW2sUdKh9LoLy2V 8nxfrCGlGpUZUYMwLFpKJyfmEiEoSxbfi25CFGA2n++CMyNT8va3Q37pmaDFIwbWIz +yfhL518zmwR7tyF1towo3fBL6sdXIVZYSJx+eb8E7LL4aR5zzQTCnJQvyQ4sOiRdQ w+VlSnS78/7NGBQteJpCbz7nzQGCFYFJ7BAr5FIIzAkZcZtIGPUjVxdpNGEyLKd4ia rPD9QI+6z+AhbiDrzU42I0TsS+mS5xrorRHZcsRjCQZbXjM54cUKd1nibOZqPww/uF clS2GhacneB+A== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id D664E4007E; Tue, 31 Aug 2021 16:16:57 -0300 (-03) Date: Tue, 31 Aug 2021 16:16:57 -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 02/37] libperf cpumap: improve max 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 Tue, Aug 31, 2021 at 03:47:10PM -0300, Arnaldo Carvalho de Melo escreveu: > Em Sat, Aug 21, 2021 at 11:19:08AM +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__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; > > Applying, but adding spaces around the '-', I ended up with this, ok? +++ b/tools/lib/perf/cpumap.c @@ -282,10 +282,8 @@ int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu) int perf_cpu_map__max(struct perf_cpu_map *map) { - if (map->nr > 0) - return map->map[map->nr-1]; - else - return -1; + // cpu_map__trim_new() qsort()s it, cpu_map__default_new() sorts it as well. + return map->nr > 0 ? map->map[map->nr - 1] : -1; }