Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp792652ybe; Fri, 13 Sep 2019 06:28:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLhXus9S6Lw+0gzCpzbAzO4pxYKkZwNgSaQe5Ejp4Ewk5wUbTF+ItnjtXsbEtBXWQnLl4c X-Received: by 2002:a17:907:20eb:: with SMTP id rh11mr3061812ejb.25.1568381317773; Fri, 13 Sep 2019 06:28:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568381317; cv=none; d=google.com; s=arc-20160816; b=uE7c/6PCDu6vX+2Gl0q0LrQXMJoEYJObPv/WkWyllTxCmYjmOX+ekqrHywUvXGb6EC fTG1ju8TPJ0/zWeH0RmG+jFXzfHAf+OhibSMmiPMvZWNJckYa84ub8ddpl0c9mk2vEvz o3QSsxcIcPL0DlOvx18D3PvxJA+5RnNkDVXcAphTRluk+9AiSArYj+5FaDlilGUjrUkX oTEwKOBYiNEpL6rFiok+/hyMgzOAEvZqnw0jdmRQ+AQRfjZXYMpfX/czpimC8OKEyInb ZqVYBbilTe5lOsVsxYq/W9fuMWEFqeqlyMA/4oLuKZkEPKcWaKXCaoRlTWRBPtdBYOmT cUzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7gMIs0UXysUZJBiRd9yk74IKRHbA6LCM2RlKIEdOcgc=; b=oBdtHBtrk4zGYFZWH1oCCUVLxsrlmUMhcDQG6YDrK/OGpAzSL0OXtP8fJaHgGs6Ptz MMhhKLQql+AgYCGHNxTO0UDpZsIHW5YBoVN62fVcqdbg72DtakTDzLFMFB2IClpQOkoS W5xqihQ34Uu8dv4lyuLkWdxsMUre9VVph7pOqdMquMhkia4MWg7hjrvNTJUqVTTusLDh /UslXwWRRLPfUh1OvmH9l1dEBHJNtpKhqvFpNGJ5rNkN23ZGGROyrDRJxI6USnzs6Gf4 USJQUcQz2fMtT2G//jN08YQNhLYIyjzY0Kh2esAA79J/Rsm1FvAPOBTObyOdn6yI1iuF XLOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ba7si11933892edb.76.2019.09.13.06.28.14; Fri, 13 Sep 2019 06:28:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391384AbfIMNZd (ORCPT + 99 others); Fri, 13 Sep 2019 09:25:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55626 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391379AbfIMNZb (ORCPT ); Fri, 13 Sep 2019 09:25:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F41210DCC80; Fri, 13 Sep 2019 13:25:31 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10B495C1D4; Fri, 13 Sep 2019 13:25:28 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan Subject: [PATCH 36/73] libperf: Add perf_evlist__alloc_pollfd function Date: Fri, 13 Sep 2019 15:23:18 +0200 Message-Id: <20190913132355.21634-37-jolsa@kernel.org> In-Reply-To: <20190913132355.21634-1-jolsa@kernel.org> References: <20190913132355.21634-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Fri, 13 Sep 2019 13:25:31 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move perf_evlist__alloc_pollfd function under libperf, it will be used in following patches. Link: http://lkml.kernel.org/n/tip-ak1oqlj43qsbioo7q9m5fg9t@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/lib/evlist.c | 21 +++++++++++++++++++++ tools/perf/lib/include/internal/evlist.h | 2 ++ tools/perf/util/evlist.c | 23 +---------------------- tools/perf/util/evlist.h | 1 - 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c index 35467d99cea5..0f84f5dc519f 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c @@ -237,3 +237,24 @@ int perf_evlist__id_add_fd(struct perf_evlist *evlist, perf_evlist__id_add(evlist, evsel, cpu, thread, id); return 0; } + +int perf_evlist__alloc_pollfd(struct perf_evlist *evlist) +{ + int nr_cpus = perf_cpu_map__nr(evlist->cpus); + int nr_threads = perf_thread_map__nr(evlist->threads); + int nfds = 0; + struct perf_evsel *evsel; + + perf_evlist__for_each_entry(evlist, evsel) { + if (evsel->system_wide) + nfds += nr_cpus; + else + nfds += nr_cpus * nr_threads; + } + + if (fdarray__available_entries(&evlist->pollfd) < nfds && + fdarray__grow(&evlist->pollfd, nfds) < 0) + return -ENOMEM; + + return 0; +} diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h index 7d64185cfabd..88c0dfaf0ddc 100644 --- a/tools/perf/lib/include/internal/evlist.h +++ b/tools/perf/lib/include/internal/evlist.h @@ -24,6 +24,8 @@ struct perf_evlist { struct hlist_head heads[PERF_EVLIST__HLIST_SIZE]; }; +int perf_evlist__alloc_pollfd(struct perf_evlist *evlist); + /** * __perf_evlist__for_each_entry - iterate thru all the evsels * @list: list_head instance to iterate diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 433e9af6e063..664c8e87ec96 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -397,27 +397,6 @@ int perf_evlist__enable_event_idx(struct evlist *evlist, return perf_evlist__enable_event_thread(evlist, evsel, idx); } -int perf_evlist__alloc_pollfd(struct evlist *evlist) -{ - int nr_cpus = perf_cpu_map__nr(evlist->core.cpus); - int nr_threads = perf_thread_map__nr(evlist->core.threads); - int nfds = 0; - struct evsel *evsel; - - evlist__for_each_entry(evlist, evsel) { - if (evsel->core.system_wide) - nfds += nr_cpus; - else - nfds += nr_cpus * nr_threads; - } - - if (fdarray__available_entries(&evlist->core.pollfd) < nfds && - fdarray__grow(&evlist->core.pollfd, nfds) < 0) - return -ENOMEM; - - return 0; -} - static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd, struct mmap *map, short revent) { @@ -943,7 +922,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages, if (!evlist->mmap) return -ENOMEM; - if (evlist->core.pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0) + if (evlist->core.pollfd.entries == NULL && perf_evlist__alloc_pollfd(&evlist->core) < 0) return -ENOMEM; evlist->core.mmap_len = evlist__mmap_size(pages); diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 204315516c32..9c90df51ce08 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -114,7 +114,6 @@ perf_evlist__find_tracepoint_by_name(struct evlist *evlist, const char *name); int perf_evlist__add_pollfd(struct evlist *evlist, int fd); -int perf_evlist__alloc_pollfd(struct evlist *evlist); int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask); int perf_evlist__poll(struct evlist *evlist, int timeout); -- 2.21.0