Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4259574ybp; Mon, 7 Oct 2019 05:56:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLDgVyOHk+dBNjQVQ1JRaWwMYUnbkI4vFjxYH7mQTniJC1hGhzCA7qeeSusdMYSx4lFvxZ X-Received: by 2002:a05:6402:1681:: with SMTP id a1mr28692436edv.218.1570452966416; Mon, 07 Oct 2019 05:56:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570452966; cv=none; d=google.com; s=arc-20160816; b=0eEHHdC1zTSk/yrVea1Yid8zfLE356Lrt/1NHfOWXlCaZQxYpI9V2xYzK6fE7sVWX0 UQG49vAdAMlASWpEULqk4ToxD2P3HThuNogpb2CaVcWvnKpyrP2tJbm6vk45Smbg7MOy mRdTZpLcFk5TAXZe++HoSpz+qbZb6UwUO6Y+4Hk6t2gkiiP1bR7eopE9HS69Z3Fc538Q i8duOpOfwpL/TAK1NUJsdszzmM+ygtalQILQV9Mhbt6iIwb/gUz8gQgPXMf/jjwtI/Kl mJIYprXrZIWDVLKxRPa97Q/IS3N5z2zeC9oNn8zYF+0kq0k1MCDQHeDbb7x8UFOm6NqF 0s8g== 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=fsVCPgY6V8QMkOTKLrDHiBJPJpJ3OJVJXQ6dGGtU4GA=; b=SlQje8Q7rXwa0I3JLmUiaYCRn0yO8Rz3zrECVmuNM+Ayd1mf4s6/r1RJpJG3AfQQ1y iABoTDhzI8E5F0Ps8vfqLn6NcFlGZvygFzJGObnQebCidc0xj74lmK0COTdGx+3KP+Em GV7CDRGw+DKIF5d5uMTCnMvcS2mDpRsC5YM6Zd33S0L7IPYl67OXtCNdRdOPU6ndRHM5 gTiYvKA/ZuxINLr+LLiRFobcWcu644RwqbrIXFUjNOJFWELRErOVy85iOqx1tGS2zA8d vaRZQcS2eYLXyGRPsxmYtrk3iFUn7emMFYXHz1MNWvL9kBUGeFuxGLuTehnc6LPA7EIY EF6w== 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 k53si539052edb.303.2019.10.07.05.55.43; Mon, 07 Oct 2019 05:56:06 -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 S1728417AbfJGMyu (ORCPT + 99 others); Mon, 7 Oct 2019 08:54:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60950 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728372AbfJGMyt (ORCPT ); Mon, 7 Oct 2019 08:54:49 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E14DAA44AD4; Mon, 7 Oct 2019 12:54:48 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FBBD5DA8D; Mon, 7 Oct 2019 12:54:46 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan Subject: [PATCH 26/36] libperf: Add perf_evlist__filter_pollfd function Date: Mon, 7 Oct 2019 14:53:34 +0200 Message-Id: <20191007125344.14268-27-jolsa@kernel.org> In-Reply-To: <20191007125344.14268-1-jolsa@kernel.org> References: <20191007125344.14268-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Mon, 07 Oct 2019 12:54:49 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding perf_evlist__filter_pollfd function and exporting it in perf/evlist.h header, so libperf users can check if descriptor is still alive. Link: http://lkml.kernel.org/n/tip-7lmjzpk6k2wfhh1os8qw1dxz@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/lib/evlist.c | 15 +++++++++++++++ tools/perf/lib/include/perf/evlist.h | 2 ++ tools/perf/lib/libperf.map | 1 + tools/perf/util/evlist.c | 12 +----------- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c index 9534ad9a572f..65045614c938 100644 --- a/tools/perf/lib/evlist.c +++ b/tools/perf/lib/evlist.c @@ -313,6 +313,21 @@ int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, return pos; } +static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd, + void *arg __maybe_unused) +{ + struct perf_mmap *map = fda->priv[fd].ptr; + + if (map) + perf_mmap__put(map); +} + +int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask) +{ + return fdarray__filter(&evlist->pollfd, revents_and_mask, + perf_evlist__munmap_filtered, NULL); +} + int perf_evlist__poll(struct perf_evlist *evlist, int timeout) { return fdarray__poll(&evlist->pollfd, timeout); diff --git a/tools/perf/lib/include/perf/evlist.h b/tools/perf/lib/include/perf/evlist.h index 28b6a12a8a2b..16f526e74d13 100644 --- a/tools/perf/lib/include/perf/evlist.h +++ b/tools/perf/lib/include/perf/evlist.h @@ -32,6 +32,8 @@ LIBPERF_API void perf_evlist__set_maps(struct perf_evlist *evlist, struct perf_cpu_map *cpus, struct perf_thread_map *threads); LIBPERF_API int perf_evlist__poll(struct perf_evlist *evlist, int timeout); +LIBPERF_API int perf_evlist__filter_pollfd(struct perf_evlist *evlist, + short revents_and_mask); LIBPERF_API int perf_evlist__mmap(struct perf_evlist *evlist, int pages); LIBPERF_API void perf_evlist__munmap(struct perf_evlist *evlist); diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map index 5a18fd1aacf2..2184aba36c3f 100644 --- a/tools/perf/lib/libperf.map +++ b/tools/perf/lib/libperf.map @@ -42,6 +42,7 @@ LIBPERF_0.0.1 { perf_evlist__poll; perf_evlist__mmap; perf_evlist__munmap; + perf_evlist__filter_pollfd; perf_mmap__consume; perf_mmap__read_init; perf_mmap__read_done; diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 3669ca767340..4910ae711b13 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -399,19 +399,9 @@ int evlist__add_pollfd(struct evlist *evlist, int fd) return perf_evlist__add_pollfd(&evlist->core, fd, NULL, POLLIN); } -static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd, - void *arg __maybe_unused) -{ - struct perf_mmap *map = fda->priv[fd].ptr; - - if (map) - perf_mmap__put(map); -} - int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask) { - return fdarray__filter(&evlist->core.pollfd, revents_and_mask, - perf_evlist__munmap_filtered, NULL); + return perf_evlist__filter_pollfd(&evlist->core, revents_and_mask); } int evlist__poll(struct evlist *evlist, int timeout) -- 2.21.0