From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F136CC6FA8E for ; Thu, 2 Mar 2023 04:12:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229817AbjCBEMw (ORCPT ); Wed, 1 Mar 2023 23:12:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbjCBEMq (ORCPT ); Wed, 1 Mar 2023 23:12:46 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23C574AFCD for ; Wed, 1 Mar 2023 20:12:44 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 204-20020a2514d5000000b00a3637aea9e1so2809613ybu.17 for ; Wed, 01 Mar 2023 20:12:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677730363; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+HlToJfehRhwifEwaYoS40OI/SsPSnYmXMj6fUkz2Ls=; b=qevYgswAKLTMJHEpZ1D1rEx/wavZ8kB2WNYP1lCXw7WBpA/nHbKIZmNSPWC5ob4DhT 7k0KxAShaTJ0mwzvG4+i02UJBYmj3XZd3TsitdcsrP90PomolW/s/Y83V0G+ZDuBh17F f78faMJJN1lWF4bzwdBtmeqxtDMrxn4iH3Mz26EZKZnYYyKHx5iaTdsBtRR2zABdiCAp qG+tHXcvei5IJNJBmGJlTkfoiQ9i8/DhuB0cSa9GRLJJOBDNHdBUvZ8sTyH5hMRQAsKR UKZLkeojPJAr/7Rv9h7xHt6ErpJHb60esoMn4Mcja/SYSXOxysgXYSC8ASWEXi1xzWU1 Ig9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677730363; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+HlToJfehRhwifEwaYoS40OI/SsPSnYmXMj6fUkz2Ls=; b=KkbZ4gMw3ZkPFwG91GoN1PpOrOCtncFFsEcCr34zm5RSoyzXcQ+JIngu2QuEgfq41S jC/16m7vEiOHRpa0mSJnHaqI6R1tZ/VPRVOR9O7VReYAJdD3ZOvLdQ6JTvBzkPS7R31e Z7aACCu++UXAiKp2zJIvh93A5wUJ3c5bxRaPdmLHfs5tQ4/eVZbTwVX01gyKluEkiXga FwZ96sBQ+eXkryM9EPIUiOuFvYX0C53+sQhVl44cKoWkxOKk6XRWIvkVBQrzOv8pIscC 4jjhAdLB+Ps1BtepXEfmgBwD2D+WzXIF9Rdu5ehStyH4WYlJr+Ozzcjs0hK/5Q8A73in v1Gw== X-Gm-Message-State: AO0yUKUOXDCHjgS3P/ZbZRMnqC3qGDIcRbVmqUVKMK0OJM+fpktzZ5cs XamLTV6FiFwdSO6TbkfIqf4IGIu/PfTY X-Google-Smtp-Source: AK7set++5gPppZpZoeoSdEk4o80WCpbyfqtkcyaNbCceeKcnZ863H2evX2BEcZlXwVMLNoOn7FpEduuP4Gea X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:bdf9:f5cb:d05:c4d5]) (user=irogers job=sendgmr) by 2002:a5b:98d:0:b0:a59:4709:c785 with SMTP id c13-20020a5b098d000000b00a594709c785mr13ybq.678.1677730362957; Wed, 01 Mar 2023 20:12:42 -0800 (PST) Date: Wed, 1 Mar 2023 20:12:02 -0800 In-Reply-To: <20230302041211.852330-1-irogers@google.com> Message-Id: <20230302041211.852330-2-irogers@google.com> Mime-Version: 1.0 References: <20230302041211.852330-1-irogers@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Subject: [PATCH v1 01/10] libperf evlist: Avoid a use of evsel idx From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Qi Liu , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Setting the leader iterates the list, so rather than use idx (which may be changed through list reordering) just count the elements and set afterwards. Signed-off-by: Ian Rogers --- tools/lib/perf/evlist.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 61b637f29b82..2d6121e89ccb 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -687,15 +687,14 @@ perf_evlist__next_mmap(struct perf_evlist *evlist, struct perf_mmap *map, void __perf_evlist__set_leader(struct list_head *list, struct perf_evsel *leader) { - struct perf_evsel *first, *last, *evsel; - - first = list_first_entry(list, struct perf_evsel, node); - last = list_last_entry(list, struct perf_evsel, node); - - leader->nr_members = last->idx - first->idx + 1; + struct perf_evsel *evsel; + int n = 0; - __perf_evlist__for_each_entry(list, evsel) + __perf_evlist__for_each_entry(list, evsel) { evsel->leader = leader; + n++; + } + leader->nr_members = n; } void perf_evlist__set_leader(struct perf_evlist *evlist) -- 2.39.2.722.g9855ee24e9-goog