Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1558987pxp; Sun, 20 Mar 2022 22:22:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw551jFYAodc6SBjtHc5UZyA2hqJwWzYsAjeeUxb6Htx8i+0JfbnNPTBo6PQqGKOhMAr/L4 X-Received: by 2002:a17:90a:ea92:b0:1c7:3961:8d3d with SMTP id h18-20020a17090aea9200b001c739618d3dmr166663pjz.88.1647840131159; Sun, 20 Mar 2022 22:22:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647840131; cv=none; d=google.com; s=arc-20160816; b=onBiW5uiEo7U0Z+JTMCAomqcrlK28wT2LNIr/HcNVLyY1i4kNqinY8Wij4kRl5TI5A w4SOg/KooprI85XuKGUHTjCLOR7xCa7oU1fSD+oMjSVZwkFB8+DfOnZPOW5IF5l2G92q L7NvbqkKdFGINxfmTRpt4xI4mHArALrixC7lhrSTUkv5kmvqsUzVYNsERixxWV396GIO Xe3GxPXJY0w91+eagvjq3p+BRSh+CSVbkK6U8UFKDJf1ptTaZyaWQzObnWlelmwwjyiC HYPkYUP9vYIjcBX56CyVb+Jt0BpvupyPej2umwJ48CzJ8AOt9cynQZ4DQn+10Xj7OC7n k+Bg== 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=pzFK/L8jrb4SpzZ3v4GeCIos+dZnAZe5Zkw5DCwe97I=; b=Tn0U4pmFrMRMRkMSoD9l0IjwCkGj7UF+cuIGbbUeQ8Q4/C19jePf2aIfZGKjSmRp21 7BxcCj+6R/72seUDPM+TlZTUeG9TCM3TE+hfFXMBFIG1xkl7y2jvN5fAkC68eTmZAKAt 0TIedEoOq6i0oPOsKuGGhx4P1rb2vhaPUXZO+Cix07WuVW+MCcWOdUJ4B4hETnRVUIcy X1BwDCXktEqLvyUR3EEhAC5rEkqE41K3VnNwdqEcMP8zQtabYH/bYjx4BQqiKP6G/s95 OOwPbLGVJfJlks0g1Ok3I9hHHU5gznXayeqJ41fUJJ27EZR4shL1d+JrsyjPAZT1qHMB b5FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mjpANjH7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g10-20020a170902868a00b00153c0334fd4si8982240plo.559.2022.03.20.22.21.47; Sun, 20 Mar 2022 22:22:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mjpANjH7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240727AbiCRUlc (ORCPT + 99 others); Fri, 18 Mar 2022 16:41:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240614AbiCRUl1 (ORCPT ); Fri, 18 Mar 2022 16:41:27 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19F472467C8 for ; Fri, 18 Mar 2022 13:40:08 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a8so19199202ejc.8 for ; Fri, 18 Mar 2022 13:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=pzFK/L8jrb4SpzZ3v4GeCIos+dZnAZe5Zkw5DCwe97I=; b=mjpANjH7f8JLct/KJ9f4LFEERuTp0htS9e48xmZcucHY2F80rDh1IK0jtzKzqY+1IF 4N7hHkHVUTYISboJRjmKklJjCBzwA/NA90tG2BRhBMDhdhjzX54FdL+Gpmh6v3/WBg+i tt0rHfybejtyYbm+YoKRv4kQUQ2hL9oZTrE6cxt4dvEEPfQx/JexbwUNdBie4++LG0iF 05sA1rN3mum8FJ2U8EesrYgCckal5QBuaUATRaMgI55Mrj3VmkP2BMvXQw+6hvUe2gYe 7wImWsYF9hYHMF4x+WP74VH0ttzHhmzi3SxYHpOv3uDp2mrfqw4J5htr7e1xtpejAGBV cHaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=pzFK/L8jrb4SpzZ3v4GeCIos+dZnAZe5Zkw5DCwe97I=; b=jcdYQipidddxEgoRhUllnlThtt6UZFWIYmEReiLTgD7BFPuxdF0Npa9tashouliwbi /ePPPuUf9mvpPj9V/2oVua36G7ydpO/Ih+4w3LyMcntCs8lhbhfIGWNf8IauUJEWFUwc KPDunUMfiPJj0vW19jR0HTnWA91yZvivqw4hgWxjOVnEmo+QxiAYu5889nH+VxpwD2KG oZMj647k8wV2GkGu29jwNm/ZF7vKG1AuJeBevKwr6sMRYrG+SngasZV8kLTxH9vn8Jki wfK2UFchq+MqEgJGfSJGdHRtKLEgowZm+D8lVrUCULUZ7W3V070kcT395mYTVvQc4ePt JpZw== X-Gm-Message-State: AOAM5331kj/Xu/bTbVR+MLx5PIpP9/igtvl0ITEvnjITJq2s36tlMnZN TXZdvNvMIEZK7BiMTjt281E= X-Received: by 2002:a17:906:743:b0:6d0:7f19:d737 with SMTP id z3-20020a170906074300b006d07f19d737mr10894755ejb.11.1647636006367; Fri, 18 Mar 2022 13:40:06 -0700 (PDT) Received: from krava ([83.240.61.119]) by smtp.gmail.com with ESMTPSA id o2-20020a50d802000000b00410d7f0c52csm4697707edj.8.2022.03.18.13.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Mar 2022 13:40:06 -0700 (PDT) Date: Fri, 18 Mar 2022 21:40:04 +0100 From: Jiri Olsa To: Ian Rogers Cc: Arnaldo Carvalho de Melo , Namhyung Kim , Jiri Olsa , Adrian Hunter , Linux Kernel Mailing List Subject: Re: [PATCH v2] perf evlist: Avoid iteration for empty evlist. Message-ID: References: <20220317231643.550902-1-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220317231643.550902-1-irogers@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 17, 2022 at 04:16:43PM -0700, Ian Rogers wrote: > As seen with 'perf stat --null ..' and reported in: > https://lore.kernel.org/lkml/YjCLcpcX2peeQVCH@kernel.org/ > > v2. Avoids setting evsel in the empty list case as suggested by Jiri > Olsa . > Fixes: 472832d2c000 ("perf evlist: Refactor evlist__for_each_cpu()") > Signed-off-by: Ian Rogers Acked-by: Jiri Olsa thanks, jirka > --- > tools/perf/util/evlist.c | 28 +++++++++++++++++----------- > 1 file changed, 17 insertions(+), 11 deletions(-) > > diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c > index 8134d45e2164..9bb79e049957 100644 > --- a/tools/perf/util/evlist.c > +++ b/tools/perf/util/evlist.c > @@ -346,7 +346,7 @@ struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affin > { > struct evlist_cpu_iterator itr = { > .container = evlist, > - .evsel = evlist__first(evlist), > + .evsel = NULL, > .cpu_map_idx = 0, > .evlist_cpu_map_idx = 0, > .evlist_cpu_map_nr = perf_cpu_map__nr(evlist->core.all_cpus), > @@ -354,16 +354,22 @@ struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affin > .affinity = affinity, > }; > > - if (itr.affinity) { > - itr.cpu = perf_cpu_map__cpu(evlist->core.all_cpus, 0); > - affinity__set(itr.affinity, itr.cpu.cpu); > - itr.cpu_map_idx = perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu); > - /* > - * If this CPU isn't in the evsel's cpu map then advance through > - * the list. > - */ > - if (itr.cpu_map_idx == -1) > - evlist_cpu_iterator__next(&itr); > + if (evlist__empty(evlist)) { > + /* Ensure the empty list doesn't iterate. */ > + itr.evlist_cpu_map_idx = itr.evlist_cpu_map_nr; > + } else { > + itr.evsel = evlist__first(evlist); > + if (itr.affinity) { > + itr.cpu = perf_cpu_map__cpu(evlist->core.all_cpus, 0); > + affinity__set(itr.affinity, itr.cpu.cpu); > + itr.cpu_map_idx = perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu); > + /* > + * If this CPU isn't in the evsel's cpu map then advance > + * through the list. > + */ > + if (itr.cpu_map_idx == -1) > + evlist_cpu_iterator__next(&itr); > + } > } > return itr; > } > -- > 2.35.1.894.gb6a874cedc-goog >