Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp92321pxb; Tue, 31 Aug 2021 15:59:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7WJRk/I1pEz5z3PcohC6LlzWVsdJgOXABQ/Kp4/3Lc7FbkDeNs3AD2O098vaqkzY9b4uV X-Received: by 2002:a02:5442:: with SMTP id t63mr5145370jaa.7.1630450748343; Tue, 31 Aug 2021 15:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630450748; cv=none; d=google.com; s=arc-20160816; b=r9W89ckulb8a+hA7rvc9iqkTkduILytaRVP5Ivo/lZnavmKosCinLUUl0yStiLmJA+ 9GudTi39IlwqDm639Al1rwEX5bv8flcJA1W5TDw3riI1crgY9Xn+6EBfQB2gpU2JPlAV 8+Qz5ScNJYGnyBaeTJK8pu2+mfO0VN+GDue+JSkdTuAC4yPFv8aL58E/CscrQ9rhpaZW lI5HYvK1w9HvtjHcJRETbghT7u3KwqRHC9psMMV728+3xbvJSEadBcWRQy74jrBDoUpD /dSMnXf2gVM7tkJyxqiYqRxLLTPP6BXEUL5zZJPB4gRIpByfluKSEBRZfM5B7DSNp1Ej zM3Q== 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=62151uIU24ZxXuBeqYaV4xuSYQ9c7A9yATH0ICQvDCM=; b=g4TMEoETljZat+g0Du6nyq9z806ZZXoMmeNsjO1pZiEE510lLz5gQunTBtM0a86jGW jLDZ9+3QrEAsPpd8LnVl/lDdYLVzO6LO5W5ssiBmAw1rhySWTnb3tOslnAYSPOkrBRHZ UshNqcXiJhfwGbDJLa0KheHETf8AIKfMWvkAieKbF0hGDbMlTJ/wFV0P3yTC1kbKwpzK qoaoE1NJcYb+9mzo4/le7aVL1Rrp7umxM0kLsH5hg+ZJv5yrXmeykOMEJC978Q7JyHY0 ji3R8g+uwxIpjBUk96fJqHZ0a6zJMziBYvwQoZJJI9xM1AAGEni3ejRo/5vhFyePTaDn TBOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PSpUpSae; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m9si19872639iow.85.2021.08.31.15.58.55; Tue, 31 Aug 2021 15:59:08 -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=@kernel.org header.s=k20201202 header.b=PSpUpSae; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239407AbhHaTpv (ORCPT + 99 others); Tue, 31 Aug 2021 15:45:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:54042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232016AbhHaTpu (ORCPT ); Tue, 31 Aug 2021 15:45:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CAE2160F6C; Tue, 31 Aug 2021 19:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630439095; bh=lTUh2DVu0SDf71xXMtCahB5YXku0JQOpZqCnumJpauU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PSpUpSaeyStxnRc3bwUi/cP1kzByp2fzzq47ippka8ErdVWlgjFDVnGjGw3XKJp1U QU2044pyd9KDZUizfIKBMLrzVX7yAJiN2MfFDh1ltSyZWlINsQHaSuFnqfwpeDzNnk 6i7c7fesST/LydueI+UT6px2LLUgVRqrAqboPu1z+JRwvo/S0YisbFEAV2MBiVyJlz C6n8xY69p+k1YmrDGwnsUwod4Gp/D37TzvnHaDqtKfrLCYsJ7xuSKysb3zuq3wH0ib kjH9XfK80p3Laq4CAPK8PNYAxy/7SnQQ1WtC5hDzd1CzsbwthBYsHjlTyPWyjEawhg DBAvR+1pNsu+g== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 858CF4007E; Tue, 31 Aug 2021 16:44:52 -0300 (-03) Date: Tue, 31 Aug 2021 16:44:52 -0300 From: Arnaldo Carvalho de Melo To: Riccardo Mancini Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [RFC PATCH v1 21/37] perf evsel: move ignore_missing_thread to fallback code Message-ID: References: <4eca51443c786baaf6811b7cd8e73aafd97f7606.1629490974.git.rickyman7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4eca51443c786baaf6811b7cd8e73aafd97f7606.1629490974.git.rickyman7@gmail.com> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sat, Aug 21, 2021 at 11:19:27AM +0200, Riccardo Mancini escreveu: > 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. Thanks, looks ok, applied. - Arnaldo > 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 -- - Arnaldo