Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp938584pxb; Fri, 22 Apr 2022 14:51:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqqMu/O5okmZUFZp3PjCBboiLae+sZMQTxF2TwlZCZt/QGTjj8Rfl2pEednHg3oorFi7kc X-Received: by 2002:a05:6a00:2402:b0:4e1:46ca:68bd with SMTP id z2-20020a056a00240200b004e146ca68bdmr6856350pfh.70.1650664301693; Fri, 22 Apr 2022 14:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650664301; cv=none; d=google.com; s=arc-20160816; b=wCkOh7qkohrUJ+SCkODc3gp1kNLlyIfgM6TbUbMFhwCQ6Ddhpuvv5x2hOo0FHbN9AS mlvwO2W+gUNVwVLTYB+11uyqwS+371gOUBUdOJT6n1hMkhPUYHjsqi4eUUvXN83ucwlQ 13andwAGw1bpn/9Cv8+yi854G6GynaDpYDuY+98JcpYHxMoGNhqHhbjobd1URR7uBfOI yrub7CbyrT3jLS/ptfRkrsKmaevHnNPvuGC4SjPctWZsTBpd89rVvXD/pKLa/wKA6DAC ej+ml+Ax/TaK0HEBKGvE8bDjVWy4G1y02uJlKZpTnL29/wYaCDGmHI80Xxa6OzWj6uDV LGbw== 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; bh=rf4NN+CzzZkBJzGoMNYqKTcFqtkmTEEcaJX8yFjs4rc=; b=VcWqfRfQMZkK6qGb1YT5i+EZlRXFHnc1zXO0OgDBm3rQ2r+xKWFwZ7Kn3eV7dv7u9N WwhfOwvLoxhY5q0QO2qUE6MEMlyGl+DVQNf2Bs33/RwioKwpGm0oT+y3S9+VEWx/EkMo U2R8nM2QAkll7ThHrWUifqV+BxRpD0ulcu9U9EvcGvOWNqknl5ECsdwccxyPj2/ucj8K 43UfM7JusnXradorrFOTe5IO8d+9IAroYmpdriFtI8cvKWmfOeCo0383+Nya9cAjifWH +JWVryYmNenqgJX+f4DNqx2XyM3ibEGB6mbIKCkGIsSydNyTf5xHOlPLSJVSYeGLakKe u/MA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h6-20020a63df46000000b003980ae22575si9340885pgj.438.2022.04.22.14.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 14:51:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 51A243492E9; Fri, 22 Apr 2022 12:59:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445979AbiDVJrH (ORCPT + 99 others); Fri, 22 Apr 2022 05:47:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1446166AbiDVJrC (ORCPT ); Fri, 22 Apr 2022 05:47:02 -0400 Received: from esa4.hc1455-7.c3s2.iphmx.com (esa4.hc1455-7.c3s2.iphmx.com [68.232.139.117]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EFA853B5D; Fri, 22 Apr 2022 02:44:09 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6400,9594,10324"; a="70646198" X-IronPort-AV: E=Sophos;i="5.90,281,1643641200"; d="scan'208";a="70646198" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa4.hc1455-7.c3s2.iphmx.com with ESMTP; 22 Apr 2022 18:44:07 +0900 Received: from yto-m2.gw.nic.fujitsu.com (yto-nat-yto-m2.gw.nic.fujitsu.com [192.168.83.65]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 06E2DC68B8; Fri, 22 Apr 2022 18:44:05 +0900 (JST) Received: from oym-om1.fujitsu.com (oym-om1.o.css.fujitsu.com [10.85.58.161]) by yto-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 1A32EE6747; Fri, 22 Apr 2022 18:44:04 +0900 (JST) Received: from localhost.localdomain (bakeccha.fct.css.fujitsu.com [10.126.195.136]) by oym-om1.fujitsu.com (Postfix) with ESMTP id C9C7F40483741; Fri, 22 Apr 2022 18:44:03 +0900 (JST) From: Shunsuke Nakamura To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH 4/7] libperf: Add perf_evsel__has_fd() functions Date: Fri, 22 Apr 2022 18:38:30 +0900 Message-Id: <20220422093833.340873-5-nakamura.shun@fujitsu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220422093833.340873-1-nakamura.shun@fujitsu.com> References: <20220422093833.340873-1-nakamura.shun@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the following functions: perf_evsel__has_fd to check for perf events with the file descriptor specified in the argument. This function can be used in signal handlers to check overflow. Signed-off-by: Shunsuke Nakamura --- tools/lib/perf/Documentation/libperf.txt | 1 + tools/lib/perf/evsel.c | 18 ++++++++++++++++++ tools/lib/perf/include/perf/evsel.h | 1 + tools/lib/perf/libperf.map | 1 + 4 files changed, 21 insertions(+) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt index ec93b1c75ebe..bc7881348c76 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -161,6 +161,7 @@ SYNOPSIS int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx); int perf_evsel__disable(struct perf_evsel *evsel); int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx); + bool perf_evsel__has_fd(struct perf_evsel *evsel, int fd); struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel); struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel); struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel); diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index a289f6c44d7c..446934c0e5e5 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -556,3 +556,21 @@ int perf_evsel__open_opts(struct perf_evsel *evsel, struct perf_cpu_map *cpus, return err; } + +bool perf_evsel__has_fd(struct perf_evsel *evsel, int fd) +{ + int cpu_map_idx; + int thread; + int *evsel_fd; + + for (cpu_map_idx = 0; cpu_map_idx < xyarray__max_x(evsel->fd); ++cpu_map_idx) { + for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) { + evsel_fd = FD(evsel, cpu_map_idx, thread); + + if (fd == *evsel_fd) + return true; + } + } + + return false; +} diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h index 50662babfe97..19a7993d9021 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -69,5 +69,6 @@ LIBPERF_API int perf_evsel__open_opts(struct perf_evsel *evsel, struct perf_cpu_map *cpus, struct perf_thread_map *threads, struct perf_evsel_open_opts *opts); +LIBPERF_API bool perf_evsel__has_fd(struct perf_evsel *evsel, int fd); #endif /* __LIBPERF_EVSEL_H */ diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index eeeb3075e092..b2ace16bbc32 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -34,6 +34,7 @@ LIBPERF_0.0.1 { perf_evsel__cpus; perf_evsel__threads; perf_evsel__attr; + perf_evsel__has_fd; perf_evlist__new; perf_evlist__delete; perf_evlist__open; -- 2.25.1