Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4763639pxb; Tue, 31 Aug 2021 12:43:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwypV8dJd0CqgL79DKkII/XQ8gvEoJ9yj3FU+e5J1Iy1Nk2BtPvLdyf6YmLU+nxvBpRUtgW X-Received: by 2002:aa7:c7c2:: with SMTP id o2mr31293726eds.166.1630439025576; Tue, 31 Aug 2021 12:43:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630439025; cv=none; d=google.com; s=arc-20160816; b=l7uwaZ2nlr/Ly2PQl5nukuBayIFeoMGSRWMcZUEmf9WGQd/x8vMtjGvUYOFsiJ89ct zZeSU03eh1cB+QtEYn2n5Zi8SCHfp+5kcY0PAKTtHtUQYcZZzy3toCSxLOwDP4L8ziOK 4qn+Rbk5Sfnctpkai1dABcdQttuIheuqOfpdX9b8wGfQuNep1Vj50vNnPL1mjW3g5NPw gTbzG6dBvTyY1Q4UJ67vwjWt9UtzNi8evp3xibNMqZw5Q3+1UJIeRVbf4SEaZhnDQxTX Dbv8ejqwC1pBB7dlLuN0M2uL4BbvyWoialSNRKTJUrLbaoVE361cg9OcreqqheJi/2FE ydxw== 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=z9DMKnsyXAqcEeoOEaexnJGJSMvMeOafzlh7PCUGkkI=; b=hj24Vioz/M+90R4K+jlKX5tJIlsfHAJ6W8wRCD9F63kvwCq0dl4xI5waa1alQm9iOK cNyjXoQ0hN0zEn2GnuZGYYYokntaxL0n/CLQASYExW81BFqSxjeeP4INx+xo5E/XEDPm aHU+dlclRnuzsLPv3m4EXgRgtjFDRjgVMnnqmKakJZc3/563R9yHn1GGN7yYVfQ0FsJj CuEDLH5fIGE1LZBActMLZzsWlFXDp7A+Ww/bXcIXHtgF/vWUkeGygrg/RY2utIeX2cjV LqE/GopMCDNSzol72BHlRdTsvTXiOZ4zyl90KJjMo4UwQHmPSDgIUDuGP8Oh2qkx9G3r vyHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=acTIp6Jq; 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 m4si2730209edi.38.2021.08.31.12.43.22; Tue, 31 Aug 2021 12:43:45 -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=acTIp6Jq; 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 S240943AbhHaTmZ (ORCPT + 99 others); Tue, 31 Aug 2021 15:42:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:51112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234715AbhHaTmV (ORCPT ); Tue, 31 Aug 2021 15:42:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 09DD060F6C; Tue, 31 Aug 2021 19:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630438886; bh=Q/h/rcc7Azc7x48LlJctFK4Yk9KlVRAwRYtEyT2GKVU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=acTIp6JqMSQqh/gLADlqOjJVw/uAm/cbra626tqWnkrhMK8idIn9lu3jmD3MwAooP gfngHiPFc+20P0ilC0lYES1zQMOtofGInvEdsozcC+KeKggrUHepI0vSoTO8qsqxQl FjDckiSmDp3VMBtS6VAC38e2eN/qq/F+sblYLKmve5FRNkr6ygdNpx8vqFpRKMswZ3 wEt/qaT7YeJo6C0e2iCPR/9Es8Yx3FMa81nMSplYkAf8JYOobhuw8ibekPkSuwfXz+ E+n6wdmJYWNVEweyp+XLEav6EYiqnfFApTps4OwLGaexCdowz7vm6vh7uy2DlZK7Uv DAwmpWJTDv6+A== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 939CF4007E; Tue, 31 Aug 2021 16:41:23 -0300 (-03) Date: Tue, 31 Aug 2021 16:41:23 -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 20/37] perf evsel: separate rlimit increase from evsel__open_cpu Message-ID: References: <2f256de8ec37b9809a5cef73c2fa7bce416af5d3.1629490974.git.rickyman7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2f256de8ec37b9809a5cef73c2fa7bce416af5d3.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:26AM +0200, Riccardo Mancini escreveu: > This is a preparatory patch for the following patches with the goal to > separate from evlist__open_cpu the actual opening (which could be > performed in parallel), from the existing fallback mechanisms, which > should be handled sequentially. > > This patch separates the rlimit increase from evsel__open_cpu. > > Signed-off-by: Riccardo Mancini > --- > tools/perf/util/evsel.c | 50 ++++++++++++++++++++++++----------------- > tools/perf/util/evsel.h | 3 +++ > 2 files changed, 33 insertions(+), 20 deletions(-) > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index c393bd992322d925..916930ea31450265 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -1931,13 +1931,40 @@ bool evsel__detect_missing_features(struct evsel *evsel) > } > } > > +bool evsel__increase_rlimit(enum rlimit_action *set_rlimit) > +{ > + int old_errno; > + struct rlimit l; > + > + if (*set_rlimit < INCREASED_MAX) { > + The above blank line is not needed > + old_errno = errno; And here it should be used, I'm recycling it for you :-) > + if (getrlimit(RLIMIT_NOFILE, &l) == 0) { > + if (*set_rlimit == NO_CHANGE) > + l.rlim_cur = l.rlim_max; > + else { Also when the else clause has {}, the if should have it too, I'm fixing it. I see that you just moved things around, but then this is a good time to do these cosmetic changes. Applying. - Arnaldo > + l.rlim_cur = l.rlim_max + 1000; > + l.rlim_max = l.rlim_cur; > + } > + if (setrlimit(RLIMIT_NOFILE, &l) == 0) { > + (*set_rlimit) += 1; > + errno = old_errno; > + return true; > + } > + } > + errno = old_errno; > + } > + > + return false; > +} > + > static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, > struct perf_thread_map *threads, > int start_cpu, int end_cpu) > { > int cpu, thread, nthreads; > int pid = -1, err, old_errno; > - enum { NO_CHANGE, SET_TO_MAX, INCREASED_MAX } set_rlimit = NO_CHANGE; > + enum rlimit_action set_rlimit = NO_CHANGE; > > err = __evsel__prepare_open(evsel, cpus, threads); > if (err) > @@ -2046,25 +2073,8 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, > * perf stat needs between 5 and 22 fds per CPU. When we run out > * of them try to increase the limits. > */ > - if (err == -EMFILE && set_rlimit < INCREASED_MAX) { > - struct rlimit l; > - > - old_errno = errno; > - if (getrlimit(RLIMIT_NOFILE, &l) == 0) { > - if (set_rlimit == NO_CHANGE) > - l.rlim_cur = l.rlim_max; > - else { > - l.rlim_cur = l.rlim_max + 1000; > - l.rlim_max = l.rlim_cur; > - } > - if (setrlimit(RLIMIT_NOFILE, &l) == 0) { > - set_rlimit++; > - errno = old_errno; > - goto retry_open; > - } > - } > - errno = old_errno; > - } > + if (err == -EMFILE && evsel__increase_rlimit(&set_rlimit)) > + goto retry_open; > > if (err != -EINVAL || cpu > 0 || thread > 0) > goto out_close; > diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h > index a83fb7f69b1ead73..bf9abd9a5cbf9852 100644 > --- a/tools/perf/util/evsel.h > +++ b/tools/perf/util/evsel.h > @@ -290,6 +290,9 @@ int evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, > struct perf_thread_map *threads); > 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); > + > struct perf_sample; > > void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name); > -- > 2.31.1 -- - Arnaldo