From patchwork Wed Mar 8 22:59:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 66506 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp635106wrd; Wed, 8 Mar 2023 15:26:02 -0800 (PST) X-Google-Smtp-Source: AK7set+4KOhGwzt+vrpGMrqK5VLV9E37vYJGBO+pUggW0Iv8bxR/VrUwO2vqWZ8leZkjVudGg65L X-Received: by 2002:a17:902:ea11:b0:194:cc66:66f7 with SMTP id s17-20020a170902ea1100b00194cc6666f7mr24364167plg.19.1678317961929; Wed, 08 Mar 2023 15:26:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678317961; cv=none; d=google.com; s=arc-20160816; b=pRNiRT0SEBpISSFKn+Av/MwdnKVrjQT+ikN1IUy39NgNC0kMsRzdxI4dAwj6/t59G0 hcldradSPHPELLIuDCYU4D0C0+gObUJBQHExaKDIPDBLlQg9UZ8diTuRWZT5UX5yZA9S ZAksrrm2EWgeUtH7YTtwMqA1fN1x5U1fAoM/BZnDFPXQwNGaFAK2KVUoPMzyqRNED08O v1k0wPYgw7dL7wN1SuF5FA3aTnA1yocKkoO47Ohejm32b6j645n6Cg7gVo3ggLJyr3ku H5epaulAm2JXCDuru19DxDSfiH52/aQRPd2MxU56kCGCdJ9lFz2PSCt+VXcbp9Ym/MXT XsGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=ywTh5n03SqFTSvl6jepwvheFrqPaSHAy7v4KxsLV2lY=; b=mx0egj484p+QouuTJgA6NgVpniBI5sR9VsmgRPGefIhHb4YIm2+DWN1gFy091D21Ao 4vsGhTi1LvjNyxvaubf1tbqQ2H4j5VEjPbSjTneX840uJ8FqqY5gtnwvmDiV6pwTyOac WrBMQ7JRrWftJ25hJtgxcUrtV93D+BvyRwXPMSnSbhpjGcN1sg/R9TNPpYArTmjSNQps 9z9JL8upqX0Gr8fXJ2Ey4XkXtvb8sb3Cefn3um0eAL8TLyB79mePvMwnhBtzpQgGebiG jHfGAj6QgUamzd0X79FLHcVEX7Jh/4Kp4ZcWOWj7HTxWFaR+tR6q6EGgKjZfhRlbBkRO dFuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="szI/v2kS"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kc7-20020a17090333c700b0019cd6d11f0fsi3451741plb.377.2023.03.08.15.25.46; Wed, 08 Mar 2023 15:26:01 -0800 (PST) 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=@google.com header.s=20210112 header.b="szI/v2kS"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbjCHW7h (ORCPT + 99 others); Wed, 8 Mar 2023 17:59:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbjCHW7c (ORCPT ); Wed, 8 Mar 2023 17:59:32 -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 E58DCD13DF for ; Wed, 8 Mar 2023 14:59:31 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id n203-20020a25dad4000000b0091231592671so266386ybf.1 for ; Wed, 08 Mar 2023 14:59:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678316371; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ywTh5n03SqFTSvl6jepwvheFrqPaSHAy7v4KxsLV2lY=; b=szI/v2kSJ1UzVtvNqdIiPV2xdcpUV7T27NeWsV2CESv02Nv1QVxVRzRb1BiSs1xFxz KRteNhiXld4XZkmdW+A0ojwllhTIWO8yc4PUenXBk+QEkqbDUMchTAb51E6ZATiuekAW iW8wSIMLkJG+K2ZAhk2ap8XAg50gkJ22oLDrW3EpWwdf4HCvQdaOgF8bE3ScP7Cxar8J CjZyAKRXQa65gEb9FYBc8PJX1NbQGDNVLYcjwtaOibGEr84RLAUO+ESsEMKxF1s1f1IV p9/oujXwZOtsZLhdakEZ+QUcZ4K3xeza1sWd1j+Jfc7ruxLu13N+ZfamtXvQMCBreKpx 1pYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678316371; 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=ywTh5n03SqFTSvl6jepwvheFrqPaSHAy7v4KxsLV2lY=; b=XQCNEBBS6XL09QRvVMeMBcON/PiwyvE7Ix2CGEz3/c0VqvFeWvgkb7zCOrNHGBZ5k5 s0bHcw1APePUJoDupm0lTYW18LuEKdru2uZcY1GO7bLK5VvyUceGYDJKXbKJ2o36BDb0 y0f7Q1XXgspb85nVcfjCJPVNa9EVIe218MpbWSjZWoAibbVkVHL6NE3RNVxKQwyXb1vf KJZQVRE/VoqHM6cpWzWyIP9wMoF+4V2zvpx9nCQ4IWMvYGo8MolbAe4Mv5r+KyUKWTb+ sJHr9E/ssGWOrJuF2HGUGLCCsZasuuv7oXAw7r+kMdah+5jUV3QRzpn14GfNQf7+txsW Lg7w== X-Gm-Message-State: AO0yUKWbT3IzugH2wRgxELlYraWjoDI/bSbxWx39X+zn+ruCTVXG7G8S 8SJmwyS03dIZofPOalpWw4AehETfIcTo X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5292:ba14:c261:246a]) (user=irogers job=sendgmr) by 2002:a05:6902:185:b0:acd:7374:f15b with SMTP id t5-20020a056902018500b00acd7374f15bmr12051059ybh.13.1678316371198; Wed, 08 Mar 2023 14:59:31 -0800 (PST) Date: Wed, 8 Mar 2023 14:59:02 -0800 In-Reply-To: <20230308225912.1960990-1-irogers@google.com> Message-Id: <20230308225912.1960990-2-irogers@google.com> Mime-Version: 1.0 References: <20230308225912.1960990-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v4 01/11] libperf evlist: Avoid a use of evsel idx From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Mark Rutland , Adrian Hunter , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , "Steinar H. Gunderson" , 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759843935433233311?= X-GMAIL-MSGID: =?utf-8?q?1759843935433233311?= 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)