Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp279460pxb; Sat, 21 Aug 2021 02:23:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKNWrhvChr+GPtO4+BXAfnH/SOlDUW3/b3SL6xkIKs/yfvtnDcd9ISBE5wJrL9V4delfmN X-Received: by 2002:a05:6638:51b:: with SMTP id i27mr21503650jar.67.1629537838326; Sat, 21 Aug 2021 02:23:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629537838; cv=none; d=google.com; s=arc-20160816; b=CGEK2f2C3YP3Dj/Xfj6KXdr9WUzpnbK4TLVvBuAiVVT1VwJ0o4LGzIVOFo5oEANC5g Mas92VEnhb3jv8xi1zKyZwdtebZJfsKyweDhx+Pz5l/6xTMlBCia858XcnJJT/fFTI0o P3dC1YD6yfxizetEH81EyLikyjcL6iOr4jFic1ADJDQ0qv9LKjLtowuV/PGhlg9FqX5Y FQrDCnXVKUoT0qUSQBfLQjQ5rhfeB37L1u1/Ro2O/GiabN4LJ+4bGvSacYCv4ELZTBYC RBtV5D4jQzbRqBdSG7wlolBLB15Fp2URMQ9hkfoon5AsstkbnCHeD6W56nCJfQfVWhg7 FQNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Kt1ytqrFQ3gxDFuU2/KO3OHIat7YiLJUy+EkQoB0jDg=; b=nU7K06gtACiqc99KDAI+KqQBNl9YXmzjrSwl2/6n6Gp4FVZvgNmiduW77eQVfhxDJL 9cgikHl0FsipAaSlgvV69vJ6YC1i175MZSxl5zDRN9pmFqM7iuhu5p0wO6xz/J2KZTIp Ow2B9JEqH9f2OOyvJM53wyAGfQs6RoNhx2NNtrkEI5YLBJYCfx9wxtRY8ikAXBPSQcY8 R3hvy7QA+ck2bqQ4wUYt3+/zp1jYVs4DBCzQQ949dk9ur+fp5Stp9mmUuRlk/D9UpLxC qmgiGc/CUdmVpl3TEK7usnXl3NclJNVmnIH2uY8H4mKDS2VGWNyBjngzG3Z/r/qYBMXT 03EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VQUzkOsg; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f11si8928597iok.80.2021.08.21.02.23.47; Sat, 21 Aug 2021 02:23:58 -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=@gmail.com header.s=20161025 header.b=VQUzkOsg; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237879AbhHUJWM (ORCPT + 99 others); Sat, 21 Aug 2021 05:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233594AbhHUJVj (ORCPT ); Sat, 21 Aug 2021 05:21:39 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F08AC0611C1; Sat, 21 Aug 2021 02:20:16 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id n12so17621850edx.8; Sat, 21 Aug 2021 02:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Kt1ytqrFQ3gxDFuU2/KO3OHIat7YiLJUy+EkQoB0jDg=; b=VQUzkOsgyk04CQmPGLMYJKdX92MbEcNeSP7aW98PvA8QFuZP3rFpJykMWn30t1FYky byLp9t4MJOgoMxmlBmGRnlNhwoSxVQKPj1GCtHp3f2AjnJIL8vnofjYqngZIbMK/58Sv Oot81y+bSDY21kzySyVJcJnXkyYYhDOPGN8V/DHGtwHSidIJyaR/TT1TM/Wx8BK+ekAk R+XTlxe0JkL0yEt0HpGTS7zDALlMbNOOSA6BbhkJy5Mc1NmifjjJnpXTra9nZHiEve8e 6HeGnAE3cYjvb0bjoxsrriN4j01pOB9v+thg5srLjvPNsx43oh8MmpF9MxI4fOQcpPMH haXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kt1ytqrFQ3gxDFuU2/KO3OHIat7YiLJUy+EkQoB0jDg=; b=AEf5K1eTVFPWSiAD9jHR4w+NxCIll+Vztf/ZrR80Uzikbt+1k+OJI2UUQ5KgHlbMMJ 2phSrXTl+VjBC/dbwBAFN1A2x58pRoZBAAIqjmg6E8AA33HEgXiGOWx3+tvC5thsb1xo mCDg9/ayDR0AcouMOrFQ13xg6TVLh/L8qEWDHG2UCAQdhgNh4sfI/9mD3qzJDG2b249U KHyYeAer1hAruY3kTTR7PY/LNDm+FlTyyi6gBHf9YqVCTtAB03wOeo04PwQIx24pWCz8 15oxhf+AYOAAuGL4qWH3RYT2+F6Mil3drur7JNSfM4aVaDHfxiqa46SMnynxlCE6kb0l fJ+Q== X-Gm-Message-State: AOAM533Da09PY4DEe/zxMakau4OgOiaB9E76fAsOR87vkbhixMXPwV84 6HOjzfY1KpdFroLlvZYiT5U= X-Received: by 2002:aa7:c0c6:: with SMTP id j6mr15646714edp.146.1629537614656; Sat, 21 Aug 2021 02:20:14 -0700 (PDT) Received: from honeypot.. (mob-176-243-254-204.net.vodafone.it. [176.243.254.204]) by smtp.googlemail.com with ESMTPSA id a25sm4003878ejv.91.2021.08.21.02.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Aug 2021 02:20:14 -0700 (PDT) From: Riccardo Mancini To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Riccardo Mancini Subject: [RFC PATCH v1 21/37] perf evsel: move ignore_missing_thread to fallback code Date: Sat, 21 Aug 2021 11:19:27 +0200 Message-Id: <4eca51443c786baaf6811b7cd8e73aafd97f7606.1629490974.git.rickyman7@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch moves ignore_missing_thread outside the perf_event_open loop. Doing so, we need to move the retry_open flag a few places higher, with minimal impact. Furthermore, thread need not be decreased since it won't get increased by the for loop (since we're jumping back inside), but we need to check that the nthreads decrease didn't put thread out of range. The goal is to have fallbacks handled in one place only, since in the future parallel code, these would be handled separately. Signed-off-by: Riccardo Mancini --- tools/perf/util/evsel.c | 29 +++++++++++++---------------- tools/perf/util/evsel.h | 5 +++++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 916930ea31450265..a1a88607fd59efcb 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1656,7 +1656,7 @@ static int update_fds(struct evsel *evsel, return 0; } -static bool ignore_missing_thread(struct evsel *evsel, +bool evsel__ignore_missing_thread(struct evsel *evsel, int nr_cpus, int cpu, struct perf_thread_map *threads, int thread, int err) @@ -1993,12 +1993,15 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, for (thread = 0; thread < nthreads; thread++) { int fd, group_fd; +retry_open: + if (thread >= nthreads) + break; if (!evsel->cgrp && !evsel->core.system_wide) pid = perf_thread_map__pid(threads, thread); group_fd = get_group_fd(evsel, cpu, thread); -retry_open: + test_attr__ready(); fd = perf_event_open(evsel, pid, cpus->map[cpu], @@ -2016,20 +2019,6 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, if (fd < 0) { err = -errno; - if (ignore_missing_thread(evsel, cpus->nr, cpu, threads, thread, err)) { - /* - * We just removed 1 thread, so take a step - * back on thread index and lower the upper - * nthreads limit. - */ - nthreads--; - thread--; - - /* ... and pretend like nothing have happened. */ - err = 0; - continue; - } - pr_debug2_peo("\nsys_perf_event_open failed, error %d\n", err); goto try_fallback; @@ -2069,6 +2058,14 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, return 0; try_fallback: + if (evsel__ignore_missing_thread(evsel, cpus->nr, cpu, threads, thread, err)) { + /* We just removed 1 thread, so lower the upper nthreads limit. */ + nthreads--; + + /* ... and pretend like nothing have happened. */ + err = 0; + goto retry_open; + } /* * perf stat needs between 5 and 22 fds per CPU. When we run out * of them try to increase the limits. diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index bf9abd9a5cbf9852..661d2677a19b6248 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -293,6 +293,11 @@ bool evsel__detect_missing_features(struct evsel *evsel); enum rlimit_action { NO_CHANGE, SET_TO_MAX, INCREASED_MAX }; bool evsel__increase_rlimit(enum rlimit_action *set_rlimit); +bool evsel__ignore_missing_thread(struct evsel *evsel, + int nr_cpus, int cpu, + struct perf_thread_map *threads, + int thread, int err); + struct perf_sample; void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name); -- 2.31.1