Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp11867lfv; Tue, 12 Apr 2022 15:13:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdDvvq1nl4Le1gzfRApqQj+CBO4CB3rOwl+JsHwwEcXoyhctBKkmGMJdARVdu4IXSudQjU X-Received: by 2002:a63:da44:0:b0:39d:4f85:51b9 with SMTP id l4-20020a63da44000000b0039d4f8551b9mr10410216pgj.557.1649801609733; Tue, 12 Apr 2022 15:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649801609; cv=none; d=google.com; s=arc-20160816; b=FK3b//tm4X4h1/9vBhQCLKZApmnsVP1tPz4FLXMRVqhK7Oiv5uB2adfP7oG3fQakDF MxXH07C5qYQpJAks4FmNy/YNZq5u2e0FEILg9ketSFm5+HRvbX5VLtYaAYyaThrUz6Ce dTmCtqsx4imBK1LXpGCSYEzEijOuSU1nlutbO706V/KfrLspCUm3gSu1LAPpPZGxH4tU SOGNB6rZROJSpkfwD3FU8EDIscPxjTW2UuJZiFNouR2Lq0dcIGqLdzW9DcZJLqWgBWa3 EAx85kZfu7OD0JfqRzrXWcK/oLSoHTeHYsdDr4wY/NvlkYSdFxcEf11qFyZNbXiD207+ C97A== 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=wfRPDDLqzPUCOkuSnhqNwDomZ7gQgHK/WkZWhxyfSpI=; b=uMEXYIzFqUtBAjoRZyn5s6vfGrVDdA65pHwUvEjnumUlNHx/lDk1wBwHzae4aUlMRH XMQsao1wYsKJ2NfHVdA8KFxHfmBrJ5FEfRckJAty0cClpQcaHSraG1VhjOgG5iwzaCxo cO7m/6SGI/1cx4/w4Yz6z4LA/lBzHUIHMIhs5wnjhNRmj6az3KKLrF+zVnW1ghU2mJar EItuYRMvT4S4zNvYBsYfmhQvfPPmEGgVsJec4UNZn7O4W8mwmMKblG409X/F1QdsjZve S6fyxfU7BjBnwgbLVQcSwL5iO5saY06Yl4qCja9Xmpvf42JOQClzuSWBwl27XmMZmZvy gY1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Gm774vIk; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m127-20020a633f85000000b003816043f10csi4548082pga.769.2022.04.12.15.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 15:13:29 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Gm774vIk; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F179818B7AA; Tue, 12 Apr 2022 14:07:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348830AbiDLGYQ (ORCPT + 99 others); Tue, 12 Apr 2022 02:24:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348756AbiDLGYI (ORCPT ); Tue, 12 Apr 2022 02:24:08 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA6313527D for ; Mon, 11 Apr 2022 23:21:51 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2e642be1a51so149733387b3.21 for ; Mon, 11 Apr 2022 23:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=wfRPDDLqzPUCOkuSnhqNwDomZ7gQgHK/WkZWhxyfSpI=; b=Gm774vIkvSewmHfi4pheFtAkt/KHS01zJ0qDB/NJ3HRte+KdZcCaSbtvcghIvWn0Vi wAqsiWt0VEnAiIPPunjulYtp0G5S+Zz33XqsBif7bdVQeqWpPRQzKF8MtyiuCc8dhrl2 PTEc8MPev5UHpD5zxU8BRNckIIcZFCdl6AQQ6tAHJDxHn1Dj6818tgxegwD1flGwd2eO 3Q1iarRBeM54vA9zwVpnXJq4GdBtPjY33X1hDJzq7yJaqVWlbkjqUbavmELZdkEoq+nK 1toT0+vUirvSvHGNuHHz3EjOeApYLKsdkEa6QX5W1s0z7OvmfFQ6+s4Ej4J2xm2Q0ppW utmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=wfRPDDLqzPUCOkuSnhqNwDomZ7gQgHK/WkZWhxyfSpI=; b=AW3pj55sDjB5LVdCINPL4IDGldgRexA10MAdFPWRmUGrUQSb5+rnWuaq0/QmM2z4oq lHQr8W5BjsuMpKxQpKum2VZCirG/2fo4vzReQrOJzIRQ9RFKkphofY6ccAv53P40YsZi awzlsBgUnWN+IjUqQEBm/ZaMp4f07Ro0155z5h77lrgDF3bmQdo8mJPdBQnmA1v0Ugd4 L5RElBMFoMNFxepMgl786dRyt1fyeSXPQGoV8EYvITTQytykiUmPfLVMnpulLxISjLMK KJS1dimameoCMBMXGf0IOTT00qvLFhx4DVkA//qucEerP2680xQvRpqDNxpysBrM+2zq mLCg== X-Gm-Message-State: AOAM533O+tAbH2pmwOHNRDP54sTehcivg9MjhXjZjDQtGFE4P8U7qMtg UoZf9r+7IcJvtG+7j8pyR/vGGAQHTzn+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:5f6f:a698:92a:5d45]) (user=irogers job=sendgmr) by 2002:a81:ec5:0:b0:2ec:4a58:4bf1 with SMTP id 188-20020a810ec5000000b002ec4a584bf1mr4262223ywo.262.1649744511035; Mon, 11 Apr 2022 23:21:51 -0700 (PDT) Date: Mon, 11 Apr 2022 23:21:32 -0700 In-Reply-To: <20220412062133.2546080-1-irogers@google.com> Message-Id: <20220412062133.2546080-2-irogers@google.com> Mime-Version: 1.0 References: <20220412062133.2546080-1-irogers@google.com> X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH 2/3] perf cpumap: Switch to using perf_cpu_map API From: Ian Rogers To: Alexey Bayduraev , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Alexey Bayduraev , Andi Kleen , Riccardo Mancini , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Switch some raw accesses to the cpu map to using the library API. This can help with reference count checking. Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 13 ++++++------ tools/perf/util/bpf_counter_cgroup.c | 31 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 069825c48d40..a5cf6a99d67f 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1011,7 +1011,7 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru for (m = 0, tm = 0; m < nr_mmaps && tm < thread_data->nr_mmaps; m++) { if (cpu_map__is_dummy(cpus) || - test_bit(cpus->map[m].cpu, thread_data->mask->maps.bits)) { + test_bit(perf_cpu_map__cpu(cpus, m).cpu, thread_data->mask->maps.bits)) { if (thread_data->maps) { thread_data->maps[tm] = &mmap[m]; pr_debug2("thread_data[%p]: cpu%d: maps[%d] -> mmap[%d]\n", @@ -3331,13 +3331,14 @@ struct option *record_options = __record_options; static void record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cpu_map *cpus) { - int c; + struct perf_cpu cpu; + int idx; if (cpu_map__is_dummy(cpus)) return; - for (c = 0; c < cpus->nr; c++) - set_bit(cpus->map[c].cpu, mask->bits); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) + set_bit(cpu.cpu, mask->bits); } static int record__mmap_cpu_mask_init_spec(struct mmap_cpu_mask *mask, const char *mask_spec) @@ -3404,8 +3405,8 @@ static int record__init_thread_cpu_masks(struct record *rec, struct perf_cpu_map pr_debug("nr_threads: %d\n", rec->nr_threads); for (t = 0; t < rec->nr_threads; t++) { - set_bit(cpus->map[t].cpu, rec->thread_masks[t].maps.bits); - set_bit(cpus->map[t].cpu, rec->thread_masks[t].affinity.bits); + set_bit(perf_cpu_map__cpu(cpus, t).cpu, rec->thread_masks[t].maps.bits); + set_bit(perf_cpu_map__cpu(cpus, t).cpu, rec->thread_masks[t].affinity.bits); if (verbose) { pr_debug("thread_masks[%d]: ", t); mmap_cpu_mask__scnprintf(&rec->thread_masks[t].maps, "maps"); diff --git a/tools/perf/util/bpf_counter_cgroup.c b/tools/perf/util/bpf_counter_cgroup.c index ac60c08e8e2a..a4b676920da0 100644 --- a/tools/perf/util/bpf_counter_cgroup.c +++ b/tools/perf/util/bpf_counter_cgroup.c @@ -47,7 +47,7 @@ static int bperf_load_program(struct evlist *evlist) struct evsel *evsel; struct cgroup *cgrp, *leader_cgrp; __u32 i, cpu; - __u32 nr_cpus = evlist->core.all_cpus->nr; + __u32 nr_cpus = perf_cpu_map__nr(evlist->core.all_cpus); int total_cpus = cpu__max_cpu().cpu; int map_size, map_fd; int prog_fd, err; @@ -125,7 +125,7 @@ static int bperf_load_program(struct evlist *evlist) for (cpu = 0; cpu < nr_cpus; cpu++) { int fd = FD(evsel, cpu); __u32 idx = evsel->core.idx * total_cpus + - evlist->core.all_cpus->map[cpu].cpu; + perf_cpu_map__cpu(evlist->core.all_cpus, cpu).cpu; err = bpf_map_update_elem(map_fd, &idx, &fd, BPF_ANY); @@ -207,13 +207,13 @@ static int bperf_cgrp__install_pe(struct evsel *evsel __maybe_unused, */ static int bperf_cgrp__sync_counters(struct evlist *evlist) { - int i, cpu; - int nr_cpus = evlist->core.all_cpus->nr; + struct perf_cpu cpu; + int idx; int prog_fd = bpf_program__fd(skel->progs.trigger_read); - for (i = 0; i < nr_cpus; i++) { - cpu = evlist->core.all_cpus->map[i].cpu; - bperf_trigger_reading(prog_fd, cpu); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + cpu = perf_cpu_map__cpu(evlist->core.all_cpus, i); + bperf_trigger_reading(prog_fd, cpu.cpu); } return 0; @@ -244,12 +244,10 @@ static int bperf_cgrp__disable(struct evsel *evsel) static int bperf_cgrp__read(struct evsel *evsel) { struct evlist *evlist = evsel->evlist; - int i, cpu, nr_cpus = evlist->core.all_cpus->nr; int total_cpus = cpu__max_cpu().cpu; struct perf_counts_values *counts; struct bpf_perf_event_value *values; int reading_map_fd, err = 0; - __u32 idx; if (evsel->core.idx) return 0; @@ -263,7 +261,10 @@ static int bperf_cgrp__read(struct evsel *evsel) reading_map_fd = bpf_map__fd(skel->maps.cgrp_readings); evlist__for_each_entry(evlist, evsel) { - idx = evsel->core.idx; + __u32 idx = evsel->core.idx; + int i; + struct perf_cpu_map cpu; + err = bpf_map_lookup_elem(reading_map_fd, &idx, values); if (err) { pr_err("bpf map lookup failed: idx=%u, event=%s, cgrp=%s\n", @@ -271,13 +272,11 @@ static int bperf_cgrp__read(struct evsel *evsel) goto out; } - for (i = 0; i < nr_cpus; i++) { - cpu = evlist->core.all_cpus->map[i].cpu; - + perf_cpu_map__for_each_cpu(cpu, i, evlist->core.all_cpu) { counts = perf_counts(evsel->counts, i, 0); - counts->val = values[cpu].counter; - counts->ena = values[cpu].enabled; - counts->run = values[cpu].running; + counts->val = values[cpu.cpu].counter; + counts->ena = values[cpu.cpu].enabled; + counts->run = values[cpu.cpu].running; } } -- 2.35.1.1178.g4f1659d476-goog