From patchwork Sat Jul 27 05:29:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13745461 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EFDF16F0E7 for ; Mon, 29 Jul 2024 16:46:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271570; cv=none; b=GmRLi3cSFKRDW+s2vO4MTno2K5ZROSm2W29a5DDFwLtn56Yq2ccZlcWNQ1leGqDWJlR1dPm6ZoTxRzrdW8IdpZeL7MqrHOI6e4HahDDdZqM68zwxRW0poimfc0FwfFdGxZYFzwm8waNL9oCoyweIj+27ZrmDZnfv3meuwTSNbwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271570; c=relaxed/simple; bh=tPwVwQ9afMUi2qsyAkI7jXUjgcctJpljCtDAaGNiM3w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mZqK92Q7Vfpp/DodJwIxDMIwA6yp7xcBle2zfmAsyNH9DEvkOi5/9Oul22jMdHvNfrdTZD/SGA811TTHy8YYJBstQ5fNdsB5K0aawVKtK/QJLR69ghYujuiXIWBowg4wO6o13QdRegA5PXrUfiIh98lmDJ4dRCUmKRmkJdagQqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=ekjWg2T5; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="ekjWg2T5" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1fc566ac769so18887155ad.1 for ; Mon, 29 Jul 2024 09:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722271568; x=1722876368; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2aScmstzHvx/v7UKZvzRNSOVMJdMn5iWDOIaOoUqNRU=; b=ekjWg2T5jNm1Mi5eKw2PnG2c7qdoRkeDWRyyl4sFWGls+/dFD8mna88jsJ1alFjekc SCPOmJl2Qc74r9VfQ2uHjni9pFzcs3g7WfGkdIED/W+W4X5aDH5sSfqWBBeznml+Um7Y PLm3boLWSwTL2yljrjT63jfiy8tCH9/BVhmSb97Xcq+mCQAJewAu6uP4XmAX1U4BxwXy KIlblP/xOMEfxoEUdZiISS1skreEV2ctDKIww0f9pCNp61yUR82UZkRQUY9Te7DVQ4PI ALYa4ALKPgXqvr2hxYQVwyDCkW9kJ+rk16235xsIYeADXamM0Jb36OJrhmFI4BqbGsFg XgKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722271568; x=1722876368; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2aScmstzHvx/v7UKZvzRNSOVMJdMn5iWDOIaOoUqNRU=; b=NUJBpnj+XzvoH5XixDCLN7HKKFQK6kDi2z+byN5YZpFyGDJKzLM+szCVa39MozAGwa 6m0z96EpovaZ52pGPQzB8dNX7NouVYFINjRwCSk1L+/FAUN9oP0xRGU1EYhhM/UPkKFX xJ7Zg/8j67Un54GT7QifmPmawabRSLoz9PqwvjddlXEQ1xj3Ag5GWKGS4sjf2XUmihcw 9TQKci+mA5mVNCjwhfeCm12LKg2UzHerLYkxbiNZkYDqCnDZsrXkyzubxY/YvUBO6J7u lJnq8Ge3+z5CzhwaTTg7Uq9UIB28Lyu3IJk0EN6U76ZG+thNdmJOZ/AUlJbtyddTdbO6 nqmg== X-Forwarded-Encrypted: i=1; AJvYcCVSt9HXnJZx8ingoTmeUsapUJmvWwkV0ctP1wDnrZPSY29CWQ8rhox02YXNLfE/kP6vM0OyosuXJZHUEe+qQ0U3T0v9 X-Gm-Message-State: AOJu0Yy861QSAxXbK6b4BclB2iK3ukMrS+7Rm/fA431UH0a3pZm06bPQ XF6LGIglCCxetf5QMXZwp3tbO8OmjZFlfD258LIcdQBsuhzZSbNjYhIulnQXBvs= X-Google-Smtp-Source: AGHT+IFw4yvYw/i8q9qY3Z4fCLdCFqDAF12yaV9mKyL9wxg0B2527KSAol4D6gP2nOhvSnXfhixfFQ== X-Received: by 2002:a17:902:f551:b0:1fb:fc96:757e with SMTP id d9443c01a7336-1ff047df750mr62572485ad.37.1722271567833; Mon, 29 Jul 2024 09:46:07 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7d401c6sm85480545ad.117.2024.07.29.09.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 09:46:07 -0700 (PDT) From: Charlie Jenkins Date: Fri, 26 Jul 2024 22:29:31 -0700 Subject: [PATCH v2 1/8] libperf: Move 'open_flags' from tools/perf to evsel::open_flags Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240726-overflow_check_libperf-v2-1-7d154dcf6bea@rivosinc.com> References: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> In-Reply-To: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Charlie Jenkins , Shunsuke Nakamura X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722271564; l=3858; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=EYj46EMmFuWQIBLme5IpvIZq5GbJ6nvJPdb/Sh/Sx+Q=; b=vLdlwLK8xuEDGs508wuLB7axsc0kxOK4nqPJyBnq14QfksSIFCuMQLC7FZKwlgaCswfBL1cHF L5JsaoW/jOSB90gGhDupKAl23sFBBAfqB6IwClC3TT0xddOQE+FNgn2 X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= From: Shunsuke Nakamura Move evsel::open_flags to perf_evsel::open_flags, so we can move the open_flags interface to libperf. Signed-off-by: Shunsuke Nakamura Signed-off-by: Charlie Jenkins --- tools/lib/perf/include/internal/evsel.h | 2 ++ tools/perf/util/evsel.c | 16 +++++++++------- tools/perf/util/evsel.h | 1 - 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/include/internal/evsel.h index 5cd220a61962..1d0d0406793a 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -75,6 +75,8 @@ struct perf_evsel { /** Is the PMU for the event a core one? Effects the handling of own_cpus. */ bool is_pmu_core; int idx; + + unsigned long open_flags; }; void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr, diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 4f818ab6b662..65f0f83ada6d 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1829,9 +1829,9 @@ static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, perf_evsel__alloc_fd(&evsel->core, perf_cpu_map__nr(cpus), nthreads) < 0) return -ENOMEM; - evsel->open_flags = PERF_FLAG_FD_CLOEXEC; + evsel->core.open_flags = PERF_FLAG_FD_CLOEXEC; if (evsel->cgrp) - evsel->open_flags |= PERF_FLAG_PID_CGROUP; + evsel->core.open_flags |= PERF_FLAG_PID_CGROUP; return 0; } @@ -1853,7 +1853,7 @@ static void evsel__disable_missing_features(struct evsel *evsel) evsel->core.attr.clockid = 0; } if (perf_missing_features.cloexec) - evsel->open_flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC; + evsel->core.open_flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC; if (perf_missing_features.mmap2) evsel->core.attr.mmap2 = 0; if (evsel->pmu && evsel->pmu->missing_features.exclude_guest) @@ -1951,7 +1951,8 @@ bool evsel__detect_missing_features(struct evsel *evsel) perf_missing_features.clockid = true; pr_debug2_peo("switching off use_clockid\n"); return true; - } else if (!perf_missing_features.cloexec && (evsel->open_flags & PERF_FLAG_FD_CLOEXEC)) { + } else if (!perf_missing_features.cloexec && + (evsel->core.open_flags & PERF_FLAG_FD_CLOEXEC)) { perf_missing_features.cloexec = true; pr_debug2_peo("switching off cloexec flag\n"); return true; @@ -2055,11 +2056,12 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, /* Debug message used by test scripts */ pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx", - pid, perf_cpu_map__cpu(cpus, idx).cpu, group_fd, evsel->open_flags); + pid, perf_cpu_map__cpu(cpus, idx).cpu, group_fd, + evsel->core.open_flags); fd = sys_perf_event_open(&evsel->core.attr, pid, perf_cpu_map__cpu(cpus, idx).cpu, - group_fd, evsel->open_flags); + group_fd, evsel->core.open_flags); FD(evsel, idx, thread) = fd; @@ -2076,7 +2078,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, if (unlikely(test_attr__enabled)) { test_attr__open(&evsel->core.attr, pid, perf_cpu_map__cpu(cpus, idx), - fd, group_fd, evsel->open_flags); + fd, group_fd, evsel->core.open_flags); } /* Debug message used by test scripts */ diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 375a38e15cd9..2efda7ad8f96 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -165,7 +165,6 @@ struct evsel { struct bperf_follower_bpf *follower_skel; void *bpf_skel; }; - unsigned long open_flags; int precise_ip_original; /* for missing_features */ From patchwork Sat Jul 27 05:29:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13745462 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 348B616F0D0 for ; Mon, 29 Jul 2024 16:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271571; cv=none; b=VFhav5kOvbh3qRSFb/hW+7V16Z0XUO4qDwcDIWoSwqsSTpTvs3P2rOtFaRg0rxp2l6+mXtqXX2sqxcuuYwsfWxyOS0ugIY62uGWKx8D2jS3++qhOcCK+++Sg3wIkyx7Yv+80WC5+aRyis1ppZ8Viy2JTDFZOPpYWkGmWLeTEsPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271571; c=relaxed/simple; bh=54U0GOikZ5RAzxgP6rcXIBTwH6OjsP6nIPiaMnC28qs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X7dple6PqM8OUGqqsIX1SoOZ88LdeC64rxo+61qFN1F8+1AUKOdV1VsWFdLkQV7R9BWCbQ1ljjw6IBDVDkk2scvZFL/NFRNHzMGv/c0ctb0CyxZHPK/djJXrKvaMU3OmiGwjAL0DitD7vE8Z1hSSmZ/d7L8/cLyIQIfD2P8T8+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=XYBFcoMG; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="XYBFcoMG" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1fd90c2fc68so23171955ad.1 for ; Mon, 29 Jul 2024 09:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722271569; x=1722876369; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=C7lNL7a7RnaEeEHqOAz4LqfV1YVzFzzZbPZA8bd7aYY=; b=XYBFcoMGO9GWA/bT4XFl/gAjnmAifflAAROJlrn1HoH7o0fC3h0G+9FJx/9TkQL4hL PQPTSjolFCo4GcTP2e7rj5ZKMyGuQ+/6ApUozIwtfYT76MNYAP8CrXnrcJdLva1+QjpZ x70CXXNvfFQ3ZUsT5qLgYrFT1fgAsKkPO+AizIC9iiBUz5GSk8cOSd3sMIMUHzjRBXlK 07xxgZRFXO7OxmnsNta6Txfzm9QUvxRJmnbv/DhTPbC6hWX7FPmzt12y8qxCsQmYX9nF lJX1wd/Tt2nf53/ibZGKpO8tsagH6sH+kjKJiCfeKC4VwHMVByCC3wYeD1+UU02lAnsF 2EdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722271569; x=1722876369; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C7lNL7a7RnaEeEHqOAz4LqfV1YVzFzzZbPZA8bd7aYY=; b=gIlclcUkejYWsrsrqXMQJY/PKcs9Z0DstpdJNgZDSG0gQSNnaZGevX5P7Tctm+iRjM EA/Gf+1fLegwFjKm7o80lQvW0woA6YOsAmkICQJ+XUR7Ub65njuUIOsjniEQHypdOish hYlSKrRTEz/wk7s2WcRBJ0ur6WXV89bZ4KxiOSScmBwoAz6tw+2o3AtHidIwfqf8I2Vq E6yv48BwvYFCIZDhqAbHzd2AypjHdKjgNohu8ELR+uCEVDzuf2REbbsoOOTYMt9A5/zq DCWVpZXqYwgSFk2hlGXB/nnQQwvF2g6lRkTFwWLULJMT++OWmQxwT3GvdjUyR9jk75f7 9h9Q== X-Forwarded-Encrypted: i=1; AJvYcCUqocBOMmZ+P8pMgwMDGQ7VsaOmUZ5c2DZIbKcw5SoIioircErCbRR017zU1c+Pz9ybkt3NZFHGH0ujyAF7ojJzi4ig X-Gm-Message-State: AOJu0YwQzOIlpNcmu6WltIZaFjmtdUeMNi/A90uu4iq21xlhdDHd2JjE Idz9kbxdmNTb93dnGfvkpb9AVtRosk69acNKx8F6g2QFk5pT7L3b7NHk9uKBSG8= X-Google-Smtp-Source: AGHT+IEDDXZa+6QWvwQqyxT5UERM3Q6JtNvwNq68P+XR9aZlgl//Sn9tiEuQaD04eysjXHhWZGRLcQ== X-Received: by 2002:a17:902:dad0:b0:1fb:389b:1054 with SMTP id d9443c01a7336-1ff048f402cmr68217195ad.52.1722271569445; Mon, 29 Jul 2024 09:46:09 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7d401c6sm85480545ad.117.2024.07.29.09.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 09:46:09 -0700 (PDT) From: Charlie Jenkins Date: Fri, 26 Jul 2024 22:29:32 -0700 Subject: [PATCH v2 2/8] libbpf: Move opts code into dedicated header Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240726-overflow_check_libperf-v2-2-7d154dcf6bea@rivosinc.com> References: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> In-Reply-To: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722271564; l=7398; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=54U0GOikZ5RAzxgP6rcXIBTwH6OjsP6nIPiaMnC28qs=; b=nRT6hIItDIVb3k4l/iTG0y78l/VSvtYH5Aq77UEkGeYTziNKgW7O3jJ03EqkBdAB64R0OOHKd l9oHIi4ae1NBYo/uXJckSHs1YGOa5dwGH17LuqtAABhpgbrJdAnPD63 X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-Patchwork-Delegate: bpf@iogearbox.net Signed-off-by: Charlie Jenkins --- tools/include/tools/opts.h | 68 +++++++++++++++++++++++++++++++++++++++++ tools/lib/bpf/bpf.c | 1 + tools/lib/bpf/btf.c | 1 + tools/lib/bpf/btf_dump.c | 1 + tools/lib/bpf/libbpf.c | 3 +- tools/lib/bpf/libbpf_internal.h | 48 ----------------------------- tools/lib/bpf/linker.c | 1 + tools/lib/bpf/netlink.c | 1 + tools/lib/bpf/ringbuf.c | 1 + 9 files changed, 76 insertions(+), 49 deletions(-) diff --git a/tools/include/tools/opts.h b/tools/include/tools/opts.h new file mode 100644 index 000000000000..42b4c1a66cad --- /dev/null +++ b/tools/include/tools/opts.h @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ + +/* + * Options helpers. + * + * Originally in tools/lib/bpf/libbpf_internal.h + */ + +#ifndef __TOOLS_OPTS_H +#define __TOOLS_OPTS_H + +#include +#include + +#ifndef offsetofend +#define offsetofend(TYPE, MEMBER) \ + (offsetof(TYPE, MEMBER) + sizeof((((TYPE *)0)->MEMBER))) +#endif + +static inline bool lib_is_mem_zeroed(const char *p, ssize_t len) +{ + while (len > 0) { + if (*p) + return false; + p++; + len--; + } + return true; +} + +static inline bool lib_validate_opts(const char *opts, + size_t opts_sz, size_t user_sz, + const char *type_name) +{ + if (user_sz < sizeof(size_t)) { + fprintf(stderr, "%s size (%zu) is too small\n", type_name, user_sz); + return false; + } + if (!lib_is_mem_zeroed(opts + opts_sz, (ssize_t)user_sz - opts_sz)) { + fprintf(stderr, "%s has non-zero extra bytes\n", type_name); + return false; + } + return true; +} + +#define OPTS_VALID(opts, type) \ + (!(opts) || lib_validate_opts((const char *)opts, \ + offsetofend(struct type, \ + type##__last_field), \ + (opts)->sz, #type)) +#define OPTS_HAS(opts, field) \ + ((opts) && opts->sz >= offsetofend(typeof(*(opts)), field)) +#define OPTS_GET(opts, field, fallback_value) \ + (OPTS_HAS(opts, field) ? (opts)->field : fallback_value) +#define OPTS_SET(opts, field, value) \ + do { \ + if (OPTS_HAS(opts, field)) \ + (opts)->field = value; \ + } while (0) + +#define OPTS_ZEROED(opts, last_nonzero_field) \ +({ \ + ssize_t __off = offsetofend(typeof(*(opts)), last_nonzero_field); \ + !(opts) || lib_is_mem_zeroed((const void *)opts + __off, \ + (opts)->sz - __off); \ +}) + +#endif /* __TOOLS_OPTS_H */ diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 2a4c71501a17..089f0e0be3a2 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "bpf.h" #include "libbpf.h" #include "libbpf_internal.h" diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 2d0840ef599a..e03974de2f02 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "btf.h" #include "bpf.h" #include "libbpf.h" diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c index 5dbca76b953f..877479228954 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "btf.h" #include "hashmap.h" #include "libbpf.h" diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 5401f2df463d..97a47a3d4e51 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -1146,7 +1147,7 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map) kern_member = find_member_by_name(kern_btf, kern_type, mname); if (!kern_member) { - if (!libbpf_is_mem_zeroed(mdata, msize)) { + if (!lib_is_mem_zeroed(mdata, msize)) { pr_warn("struct_ops init_kern %s: Cannot find member %s in kernel BTF\n", map->name, mname); return -ENOTSUP; diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h index a0dcfb82e455..033b852ed9a7 100644 --- a/tools/lib/bpf/libbpf_internal.h +++ b/tools/lib/bpf/libbpf_internal.h @@ -283,54 +283,6 @@ void *libbpf_add_mem(void **data, size_t *cap_cnt, size_t elem_sz, size_t cur_cnt, size_t max_cnt, size_t add_cnt); int libbpf_ensure_mem(void **data, size_t *cap_cnt, size_t elem_sz, size_t need_cnt); -static inline bool libbpf_is_mem_zeroed(const char *p, ssize_t len) -{ - while (len > 0) { - if (*p) - return false; - p++; - len--; - } - return true; -} - -static inline bool libbpf_validate_opts(const char *opts, - size_t opts_sz, size_t user_sz, - const char *type_name) -{ - if (user_sz < sizeof(size_t)) { - pr_warn("%s size (%zu) is too small\n", type_name, user_sz); - return false; - } - if (!libbpf_is_mem_zeroed(opts + opts_sz, (ssize_t)user_sz - opts_sz)) { - pr_warn("%s has non-zero extra bytes\n", type_name); - return false; - } - return true; -} - -#define OPTS_VALID(opts, type) \ - (!(opts) || libbpf_validate_opts((const char *)opts, \ - offsetofend(struct type, \ - type##__last_field), \ - (opts)->sz, #type)) -#define OPTS_HAS(opts, field) \ - ((opts) && opts->sz >= offsetofend(typeof(*(opts)), field)) -#define OPTS_GET(opts, field, fallback_value) \ - (OPTS_HAS(opts, field) ? (opts)->field : fallback_value) -#define OPTS_SET(opts, field, value) \ - do { \ - if (OPTS_HAS(opts, field)) \ - (opts)->field = value; \ - } while (0) - -#define OPTS_ZEROED(opts, last_nonzero_field) \ -({ \ - ssize_t __off = offsetofend(typeof(*(opts)), last_nonzero_field); \ - !(opts) || libbpf_is_mem_zeroed((const void *)opts + __off, \ - (opts)->sz - __off); \ -}) - enum kern_feature_id { /* v4.14: kernel support for program & map names. */ FEAT_PROG_NAME, diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c index 0d4be829551b..e6fb12ba396c 100644 --- a/tools/lib/bpf/linker.c +++ b/tools/lib/bpf/linker.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "libbpf.h" #include "btf.h" #include "libbpf_internal.h" diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c index 68a2def17175..786a4f6dc3ab 100644 --- a/tools/lib/bpf/netlink.c +++ b/tools/lib/bpf/netlink.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index bfd8dac4c0cc..547781cde26d 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include "libbpf.h" From patchwork Sat Jul 27 05:29:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13745463 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D150C18734F for ; Mon, 29 Jul 2024 16:46:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271573; cv=none; b=e/JlD+tJ04Fxgy000DrRsNLYJB+pTITPhil1HIulqd1bUMvPDssJeLwwaTO61xLydM5atdN1bHgJQOkS4d522b6gWJXZ9n7Ca4RyRkomyWza7Hc4Q5CjUFvfcn4jXO5t53LBGpCM7rm0YMXCqdqAOusiYvlXt/TlRRYDZMOF7RY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271573; c=relaxed/simple; bh=Ngg3rd0M9C6xmXKqdyh5Swv8+ulPNZzaCEcRVN+uVoE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZmaELzZPBAMwqjidvg72ynKycRVL2pC8kbndoDxbzBzj6RpJpecDrsBgeUDySmlnbbTSZ25aCohM5RH95IpOM4TIVWA8B1G5jaMY8ZAMVvvEryA9YO08Wp6529FS05/rg6/B9KHFz4+XFYOUb0N1t7J5321JX9BVrzM9R4xlNtI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=aHDxMYgR; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="aHDxMYgR" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1fd78c165eeso28319115ad.2 for ; Mon, 29 Jul 2024 09:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722271571; x=1722876371; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uo0PY2WTM6EhFKrs58+9HaWpsdI63v4tb+UT2YjwAqc=; b=aHDxMYgRJqmIcNcMqfj0aJ7fwsosMWNjNnKDzmuPaUd3w+hefwyllWdBb2tkWcttxG HOEMouQRhU+KLLkuuxO7ydQgFenCovmgGEOcXu79kkArkoqvpndyvxTFFAuyVO3aEJ7Q i0CpMsTq7PfeTQFgXtZI4oyjEQgctzUeCwvLdfPPKy7yFMPUzLevDdvbomes6zCTfbOd QHv2W/lUGK1lf6WKDJ5G16/IAesl0ZUOQKE1lQZtkLJ8ua8G1fYOdHfq/DHnMobYL0Np 7ty1SWyhH0ptCyueNahUYk15Kw35RXGZEU4X/7lsQEc0Bpvwocrw5FaGruX4ssLaUEE3 2tSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722271571; x=1722876371; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uo0PY2WTM6EhFKrs58+9HaWpsdI63v4tb+UT2YjwAqc=; b=Ae9RQ4IU7r7mjFlItzHCjdMb88yddJ8dEGsRGR6ngmIVrEdnEr7foAgNhLCH0bWZSV BJeOegBKRj032q9Eo9CN8Zxj1sykklbtiMTtRd/ITKVp37ElGgWfIsffJP0znB0Dm+Ej anIeATug+5Pp/JI50UG9tzbVbhbH46culLy2+gv44fNgxRk2EvpdjA+ykGckRaxMdLVd LB6+9KmfUjFwWvaJjm6Pdr6qRHfv+8UkXBYSkeZsDIzbl+KuhIVXQeLfKie3atyduul4 ZF8bfQhWGHj/e8pu2/6wOgyCflJ6awWQWdA7DjMOHUg0OimqDanzieDXxDeT1OSskkgh p8vg== X-Forwarded-Encrypted: i=1; AJvYcCULSNE1W5q9T3oBR0AO56YEeuH2DW3qqKdfHoKxR8semPb8sRVKxDACLbNUYl42FQjOpQb5w3x0xivYXhFJGUm/bfVZ X-Gm-Message-State: AOJu0Yw6OJGEjadCA/q+755cAS5wzjl7qZ+9cJEjY/KW0eJUw0SP9RBd llE95DGeYaeiUXwkiWdeu82Ykp+CsJlCxpFR6QsETLvyNx6xHFw2j4+40RpDrDg= X-Google-Smtp-Source: AGHT+IHLgMPdjmt0sDFCR6yF11VZsrAEjljxhSUWErrndmlusWxFwhB4XqPZLawRIvpO/YA7zmUOuQ== X-Received: by 2002:a17:902:f542:b0:1fb:779e:4fd0 with SMTP id d9443c01a7336-1ff04824612mr103219635ad.24.1722271571147; Mon, 29 Jul 2024 09:46:11 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7d401c6sm85480545ad.117.2024.07.29.09.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 09:46:10 -0700 (PDT) From: Charlie Jenkins Date: Fri, 26 Jul 2024 22:29:33 -0700 Subject: [PATCH v2 3/8] libperf: Introduce perf_{evsel, evlist}__open_opt with extensible struct opts Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240726-overflow_check_libperf-v2-3-7d154dcf6bea@rivosinc.com> References: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> In-Reply-To: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Charlie Jenkins , Shunsuke Nakamura X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722271564; l=7074; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=+5d9mj+wHf0VzhQfYQKCxev5dn5+38ZS8YUUwro/Nzs=; b=4PBFwV6Nyh9X5DwMJ8/GEDy/ecDevgP9/dGJd4n4JTycAjE7K//b7Dbg213JCH5ss5kjqMWkL MfL/jvDn1RkDy5EvdHb4DEd1g9XHj0Z4wrpg4+lHQWiHaPCPH6VQsSK X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= From: Shunsuke Nakamura Introduce perf_{evsel, evlist}__open_opt with extensible structure opts. The mechanism of the extensible structure opts imitates tools/lib/bpf/libbpf.h. Currently, only open_flags is supported for the opts structure. Signed-off-by: Shunsuke Nakamura Signed-off-by: Charlie Jenkins --- tools/lib/perf/Documentation/libperf.txt | 10 ++++++++++ tools/lib/perf/evlist.c | 20 ++++++++++++++++++++ tools/lib/perf/evsel.c | 26 +++++++++++++++++++++++++- tools/lib/perf/include/perf/evlist.h | 3 +++ tools/lib/perf/include/perf/evsel.h | 23 +++++++++++++++++++++++ tools/lib/perf/libperf.map | 2 ++ 6 files changed, 83 insertions(+), 1 deletion(-) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt index fcfb9499ef9c..83827b94617a 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -132,6 +132,16 @@ SYNOPSIS }; }; + struct perf_evsel_open_opts { + /* size of this struct, for forward/backward compatibility */ + size_t sz; + + unsigned long open_flags; /* perf_event_open flags */ + }; + #define perf_evsel_open_opts__last_field open_flags + + #define LIBPERF_OPTS(TYPE, NAME, ...) + struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr); void perf_evsel__delete(struct perf_evsel *evsel); int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index c6d67fc9e57e..7aa62f90f13b 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -753,3 +753,23 @@ void perf_evlist__go_system_wide(struct perf_evlist *evlist, struct perf_evsel * __perf_evlist__propagate_maps(evlist, evsel); } } + +int perf_evlist__open_opts(struct perf_evlist *evlist, + struct perf_evsel_open_opts *opts) +{ + struct perf_evsel *evsel; + int err; + + perf_evlist__for_each_entry(evlist, evsel) { + err = perf_evsel__open_opts(evsel, evsel->cpus, + evsel->threads, opts); + if (err < 0) + goto out_err; + } + + return 0; + +out_err: + perf_evlist__close(evlist); + return err; +} diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index c07160953224..96ecf3e5c8b4 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -16,8 +16,13 @@ #include #include #include +#include +#include +#include #include #include +#include +#include "internal.h" void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr, int idx) @@ -26,6 +31,7 @@ void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr, evsel->attr = *attr; evsel->idx = idx; evsel->leader = evsel; + evsel->open_flags = 0; } struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr) @@ -160,7 +166,7 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, fd = sys_perf_event_open(&evsel->attr, threads->map[thread].pid, - cpu, group_fd, 0); + cpu, group_fd, evsel->open_flags); if (fd < 0) { err = -errno; @@ -555,3 +561,21 @@ void perf_counts_values__scale(struct perf_counts_values *count, if (pscaled) *pscaled = scaled; } + +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) +{ + int err = 0; + + if (!OPTS_VALID(opts, perf_evsel_open_opts)) { + err = -EINVAL; + return err; + } + + evsel->open_flags = OPTS_GET(opts, open_flags, 0); + + err = perf_evsel__open(evsel, cpus, threads); + + return err; +} diff --git a/tools/lib/perf/include/perf/evlist.h b/tools/lib/perf/include/perf/evlist.h index e894b770779e..37ac44364d22 100644 --- a/tools/lib/perf/include/perf/evlist.h +++ b/tools/lib/perf/include/perf/evlist.h @@ -9,6 +9,7 @@ struct perf_evlist; struct perf_evsel; struct perf_cpu_map; struct perf_thread_map; +struct perf_evsel_open_opts; LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *evsel); @@ -48,4 +49,6 @@ LIBPERF_API struct perf_mmap *perf_evlist__next_mmap(struct perf_evlist *evlist, LIBPERF_API void perf_evlist__set_leader(struct perf_evlist *evlist); LIBPERF_API int perf_evlist__nr_groups(struct perf_evlist *evlist); +LIBPERF_API int perf_evlist__open_opts(struct perf_evlist *evlist, + struct perf_evsel_open_opts *opts); #endif /* __LIBPERF_EVLIST_H */ diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h index 6f92204075c2..8eb3927f3cd0 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -5,6 +5,7 @@ #include #include #include +#include #include struct perf_evsel; @@ -25,6 +26,24 @@ struct perf_counts_values { }; }; +struct perf_evsel_open_opts { + /* size of this struct, for forward/backward compatibility */ + size_t sz; + + unsigned long open_flags; /* perf_event_open flags */ +}; + +#define perf_evsel_open_opts__last_field open_flags + +#define LIBPERF_OPTS(TYPE, NAME, ...) \ + struct TYPE NAME = ({ \ + memset(&NAME, 0, sizeof(struct TYPE)); \ + (struct TYPE) { \ + .sz = sizeof(struct TYPE), \ + __VA_ARGS__ \ + }; \ + }) + LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr); LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel); LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, @@ -46,5 +65,9 @@ LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel); LIBPERF_API void perf_counts_values__scale(struct perf_counts_values *count, bool scale, __s8 *pscaled); +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); #endif /* __LIBPERF_EVSEL_H */ diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 2aa79b696032..84fed76621cb 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -29,6 +29,7 @@ LIBPERF_0.0.1 { perf_evsel__enable; perf_evsel__disable; perf_evsel__open; + perf_evsel__open_opts; perf_evsel__close; perf_evsel__mmap; perf_evsel__munmap; @@ -40,6 +41,7 @@ LIBPERF_0.0.1 { perf_evlist__new; perf_evlist__delete; perf_evlist__open; + perf_evlist__open_opts; perf_evlist__close; perf_evlist__enable; perf_evlist__disable; From patchwork Sat Jul 27 05:29:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13745464 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BE95187858 for ; Mon, 29 Jul 2024 16:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271575; cv=none; b=Jyewuhqe+wcstcpYZM+c/z39BksLz/IVaXXeqFYKB7olrGKVWTgyJhNgI20lRK+0CJROvlMPTUlYkCrWpGpY3Ya4F/8BOJFRYj0hHygOwnB/DDn1URkw7jqa+pnjU3cDQAr+ti2e9PIP2XGfioWd1SAI0WIrnnXjoSj3yx/sGcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271575; c=relaxed/simple; bh=NpgF1/kK1yOkWx7OSvhib/FvJeG2/8hZAiow4pKggL4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aFEzM9CE5enhMvnqXeQv2/5CkJpdOR4IF7GllTFRlC/epzbFycR3mI+5crd8X2m61U/+CV+219Mx8H77No9mEfNqbYO8ovXjh29Lu394P7rf2nP7rVNuFl43Zx98ku0Vv1nw4LRtmyKUn9htcndq+NqrA2Aecmy6D46ZSDkefI8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=TMwZha5V; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="TMwZha5V" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1fc49c0aaffso20222055ad.3 for ; Mon, 29 Jul 2024 09:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722271573; x=1722876373; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6sq/wgKkNEoeBfHdwGP5Fnla8E6KMSluE3DaT/hx6/0=; b=TMwZha5Vj0sKoxExJ1Z/M1IWi7zVxSwT2M+iy1OacbKhTpillhnuKWWwgvUKozSrvM 9A8xODtYCaadYioRhXt8gWNmvVDPi8dvIqHmVJbkxSvld8oZBXTsyKtYjDEgxV8PZJmd vLkOgH5R/a+xjjH/o5QVXZKEfgOLPbSoE95e+2UgpJmLUD39i6VdmKPw8UGsc9upjw5o VC4gPLGC8MNk+Tv2GA48RoY2kh2tfFDKrylifX/f5BBsTREzK7yGSwRisei/noVdTmTL qkwBgxLOhLcQ9uAUUJzK4uI5gYZM/1pLqT4PSCLquh17Hiq0iiTC9d3LZnzm35n0LJzS VZ3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722271573; x=1722876373; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6sq/wgKkNEoeBfHdwGP5Fnla8E6KMSluE3DaT/hx6/0=; b=EwigaZqwtYWgDH0FVNCafpBGWqIRjT83UMbvKwLwV3z8xLBXtTDbk9hjrpaWLGgSva cvRHLw6Rtxymdn+YT6dF1I85L5QfQlNdZl56pPJiJrnlxusnUHd+puctuYhWOgjKLhBt enrsu9ClnrLyIpE64Z6u1Ka/Vc8q9eVv255SLYA81GTjfBqNPGPryv5LBbUFsuykp5h4 WubHEYnBBvhF7uHhykR+M8UF93ctKq8BjD/8VtIneBPAmmYZyS77RK6Mf/yF9u5Zr9Tk /uuKR9+09cPjoCvj6Pw94kezb14C+jQmOjhZnP0/VjbgCASvv1K8v/880FQL430Qv4y3 bRzQ== X-Forwarded-Encrypted: i=1; AJvYcCVucYlHxirA9Zms/3HkfGTOZCITU8qC+9dLFsJQAd/rNnRNoBwTq7woBV4tgY0EmxsqpyxCIPboEd+tURqjiEt3XeIA X-Gm-Message-State: AOJu0YwM66gUlHaeVQ3OKgudi6bGpBm9E1tG8he8tmvoW5jDI0gp8F/4 Uky+QneFTcK2Dh1I6lJxktBwEkziOnRnvjJKFXtCxJpIBtuDh8C+cxc0iC21XAc= X-Google-Smtp-Source: AGHT+IHIU4ZqwMOi+9pCWVyiNYiqbMYPUL7gmvjWFUUZYuciqgVS+40fRq++sBF6vHIYSXwLkZudiw== X-Received: by 2002:a17:902:d491:b0:1fd:709a:2978 with SMTP id d9443c01a7336-1ff0485ba87mr59797395ad.38.1722271572808; Mon, 29 Jul 2024 09:46:12 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7d401c6sm85480545ad.117.2024.07.29.09.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 09:46:12 -0700 (PDT) From: Charlie Jenkins Date: Fri, 26 Jul 2024 22:29:34 -0700 Subject: [PATCH v2 4/8] libperf: Add support for overflow handling of sampling events Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240726-overflow_check_libperf-v2-4-7d154dcf6bea@rivosinc.com> References: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> In-Reply-To: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Charlie Jenkins , Shunsuke Nakamura X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722271564; l=5292; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=8zwxFTYoYw8Wodjo527mV6UDvzQ+n1PNG6cEAoqFF1c=; b=kuo9VfbWPQ1nC8bXfn/ATV7gFoalcR9fMmHKAB0r+H6d1E/DkyARWRHZKCQpUjWnGHSDTpwTS qtCb21rRC7iBHI35lGaYorH25PUiulnNYyi3xrmSbD4e9VOHkUtdCLZ X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= From: Shunsuke Nakamura Extend the fields of the opts structure to set up overflow handling for sampling events. Also, add processing to set signal handlers in perf_evsel__open_opts. Signed-off-by: Shunsuke Nakamura Signed-off-by: Charlie Jenkins --- tools/lib/perf/Documentation/libperf.txt | 6 ++- tools/lib/perf/Makefile | 1 + tools/lib/perf/evsel.c | 79 ++++++++++++++++++++++++++++++++ tools/lib/perf/include/perf/evsel.h | 6 ++- tools/lib/perf/tests/test-evlist.c | 1 - 5 files changed, 90 insertions(+), 3 deletions(-) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt index 83827b94617a..bb99534d5855 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -137,8 +137,12 @@ SYNOPSIS size_t sz; unsigned long open_flags; /* perf_event_open flags */ + int fcntl_flags; + unsigned int signal; + int owner_type; /* value for F_SETOWN_EX */ + struct sigaction *sigact; }; - #define perf_evsel_open_opts__last_field open_flags + #define perf_evsel_open_opts__last_field sigact #define LIBPERF_OPTS(TYPE, NAME, ...) diff --git a/tools/lib/perf/Makefile b/tools/lib/perf/Makefile index 3a9b2140aa04..9dade2ad91bd 100644 --- a/tools/lib/perf/Makefile +++ b/tools/lib/perf/Makefile @@ -75,6 +75,7 @@ override CFLAGS += -Werror -Wall override CFLAGS += -fPIC override CFLAGS += $(INCLUDES) override CFLAGS += -fvisibility=hidden +override CFLAGS += -D_GNU_SOURCE all: diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 96ecf3e5c8b4..17d3d9a88c23 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -562,6 +562,79 @@ void perf_counts_values__scale(struct perf_counts_values *count, *pscaled = scaled; } +static int perf_evsel__run_fcntl(struct perf_evsel *evsel, + unsigned int cmd, unsigned long arg, + int cpu_map_idx) +{ + int thread; + + for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) { + int err; + int *fd = FD(evsel, cpu_map_idx, thread); + + if (!fd || *fd < 0) + return -1; + + err = fcntl(*fd, cmd, arg); + if (err) + return err; + } + + return 0; +} + +static int perf_evsel__set_signal_handler(struct perf_evsel *evsel, + struct perf_evsel_open_opts *opts) +{ + unsigned int fcntl_flags; + unsigned int signal; + struct f_owner_ex owner; + struct sigaction *sigact; + int cpu_map_idx; + int err = 0; + + fcntl_flags = OPTS_GET(opts, fcntl_flags, (O_RDWR | O_NONBLOCK | O_ASYNC)); + signal = OPTS_GET(opts, signal, SIGIO); + owner.type = OPTS_GET(opts, owner_type, F_OWNER_PID); + sigact = OPTS_GET(opts, sigact, NULL); + + if (fcntl_flags == 0 && signal == 0 && !owner.type == 0 && sigact == 0) + return err; + + err = sigaction(signal, sigact, NULL); + if (err) + return err; + + switch (owner.type) { + case F_OWNER_PID: + owner.pid = getpid(); + break; + case F_OWNER_TID: + owner.pid = syscall(SYS_gettid); + break; + case F_OWNER_PGRP: + default: + return -1; + } + + for (cpu_map_idx = 0; cpu_map_idx < xyarray__max_x(evsel->fd); cpu_map_idx++) { + err = perf_evsel__run_fcntl(evsel, F_SETFL, fcntl_flags, cpu_map_idx); + if (err) + return err; + + err = perf_evsel__run_fcntl(evsel, F_SETSIG, signal, cpu_map_idx); + if (err) + return err; + + err = perf_evsel__run_fcntl(evsel, F_SETOWN_EX, + (unsigned long)&owner, cpu_map_idx); + if (err) + return err; + } + + return err; +} + 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) @@ -576,6 +649,12 @@ int perf_evsel__open_opts(struct perf_evsel *evsel, struct perf_cpu_map *cpus, evsel->open_flags = OPTS_GET(opts, open_flags, 0); err = perf_evsel__open(evsel, cpus, threads); + if (err) + return err; + + err = perf_evsel__set_signal_handler(evsel, opts); + if (err) + return err; return err; } diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h index 8eb3927f3cd0..344808f23371 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -31,9 +31,13 @@ struct perf_evsel_open_opts { size_t sz; unsigned long open_flags; /* perf_event_open flags */ + int fcntl_flags; + int signal; + int owner_type; /* value for F_SETOWN_EX */ + struct sigaction *sigact; }; -#define perf_evsel_open_opts__last_field open_flags +#define perf_evsel_open_opts__last_field sigact #define LIBPERF_OPTS(TYPE, NAME, ...) \ struct TYPE NAME = ({ \ diff --git a/tools/lib/perf/tests/test-evlist.c b/tools/lib/perf/tests/test-evlist.c index 10f70cb41ff1..3a833f0349d3 100644 --- a/tools/lib/perf/tests/test-evlist.c +++ b/tools/lib/perf/tests/test-evlist.c @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE // needed for sched.h to get sched_[gs]etaffinity and CPU_(ZERO,SET) #include #include #include From patchwork Sat Jul 27 05:29:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13745465 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09CAE188CA7 for ; Mon, 29 Jul 2024 16:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271576; cv=none; b=a1g4+EW8taCx6n0L1viOv8qYHS33H5KyEE+PKZVfidi8E1+iezX3C+WSUgkDHuluzZ0fCU8rL94//372or9o6URcvJLpX70GLBqXRXyBPXpFqnocDF+w6G0npzDTLZVVf3HdbCFQrlVI8ouSscDAWyTrymShCCXX/tqypm0cYxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271576; c=relaxed/simple; bh=r/jk1bPDMru1N5AoMkuunoH2pb49M7nOjU+z9/MKibs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DQOLEq/42AU/LnjjHEPIriCv6GGi590pHedxEHcjIwz+x/MhI6T0IgjhrOrCHYD8ZVRi03mJQZu1MDpvMZYNvfwxSvixXGrJMr6QR8B4SfGmeoLKjyyCb1rYnvknQGEmgJeLNs2qiIWzCV/qfmyW/tMmyl0HP1DZFIur4U70ISo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=1oIw8pz4; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="1oIw8pz4" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fee6435a34so19700585ad.0 for ; Mon, 29 Jul 2024 09:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722271574; x=1722876374; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hggTn66JrbOD+sBIjW9DCUZjKZdbaIlQ6N1BF/br8RA=; b=1oIw8pz4xw91U1lrSFWpH2e8AatUcCm+BOQmYAcl77qG6e+K0VIGBaC817vD4ocYTu ADb4hUs9AcZ660dCqipoX7LTdcMnbFHqRqrg7LfdqzwYJvLCK00rqToDpUij9nVvWFzk WZ0j2lqkmpqih7CVB3ZIQ/HrqvOaNnEJm8+5LMouIKsiOglMvHYxqlSxCzf9EFfJYWFK hi797EZs/3Lu01f6jAQCuPnj4UmixOG2VGy0x+CPJ5lRd1T4XESJvIM2jqe0O66jP4zK w2dgn1dpxlntwsMad9puw4KIkqagKgdXnZjgfHq/o4HmYn/fF2gofZ24RK+5ES8VkgrE 952g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722271574; x=1722876374; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hggTn66JrbOD+sBIjW9DCUZjKZdbaIlQ6N1BF/br8RA=; b=eyaOxMh/nlpmGioAgfaWENpw5kDwXILsTOi5GByuZx+ncW8am/w7KYUUYpyHDRtvPL X1X1aecy4dUi6H6oJwVJ3wKLmWCXvSk9k+iAOcIdSqHYzgXQGSWTEP+S9QsuwmB8Xv+C tHCoj/iZ46Am90Hz7MHlxJaxZXkQ3uSn++N2bp1Q23xvHiwG2xs2WEXsqLRTfvlNJP5y HhzNIn6VaXqRR9KW3kzloxJDPynhKkV/duZ+/Izo+uaRW697KdZuszWrWcTaysT+uIc2 LtL2mzb9UYuTUqucRT5sa7u1OYzqo6Yc1//kTIV5u9+j/SWzdfUCT7Gvn2DTsy3sqwh/ 1rHA== X-Forwarded-Encrypted: i=1; AJvYcCVNy2eG2hqGOipgNujFZi4ZEoGuJvPkecL+s9CO6GOPEPeQ6DCnG2cM4Bng+On5Y7jxNpIV8PrBg220FfW76H2KUjwq X-Gm-Message-State: AOJu0Yx9WDjXU7vJ78p9H/soIfe5P6zgYJ8oJO0RRVwKH40sxAoiQinq ltz9SQzlxqri6dEJkaIu8uDKKeo61riVDxZqr+nW9szI1eEsPrGQ35wHF6n2GjQ= X-Google-Smtp-Source: AGHT+IHwput5h4gdG/FQNNx/hl3tLZc38qQQiY4RziyanWxKoKdtV+dUnUDnm99B90DEvM0zWr8vPg== X-Received: by 2002:a17:902:f68d:b0:1fd:9d0c:99a2 with SMTP id d9443c01a7336-1ff0492e124mr76115145ad.54.1722271574501; Mon, 29 Jul 2024 09:46:14 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7d401c6sm85480545ad.117.2024.07.29.09.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 09:46:14 -0700 (PDT) From: Charlie Jenkins Date: Fri, 26 Jul 2024 22:29:35 -0700 Subject: [PATCH v2 5/8] libperf: Add perf_evsel__has_fd() functions Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240726-overflow_check_libperf-v2-5-7d154dcf6bea@rivosinc.com> References: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> In-Reply-To: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Charlie Jenkins , Shunsuke Nakamura X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722271564; l=2952; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=5bOJ2b703722JpraMU92aYFsGhC7VVqbjBOBXBX1n9w=; b=qvpfqD8c3mf+ibeI5OmudMFTmZt9WlbIgEglZdGnFxeEODawAp89wEr+czBg6PIJlpPnwuHka VyXXS8w7cRKCzleuS1aTn0nSnupQnm74zOk1NTd0Isx8R8RG65UAKN1 X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= From: Shunsuke Nakamura 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 Signed-off-by: Charlie Jenkins --- 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 bb99534d5855..f1bfe6b6e78a 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 17d3d9a88c23..6b98cba6eb4f 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -658,3 +658,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 344808f23371..77816a35c383 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -73,5 +73,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 84fed76621cb..f68519e17885 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -38,6 +38,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; From patchwork Sat Jul 27 05:29:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13745466 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10577188CDF for ; Mon, 29 Jul 2024 16:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271578; cv=none; b=l7NCb8WfCA4MFretpdRKSKFT2BcY6pIagmbCNqmjxS//gAX6FxkjZ81obR7igDXsXytAsqVsRQbotFFnjnpavAVvcdfOUwKjOYaS8Nr6nl/X0eavEnxaFUSjGYXAJ0io53c3it8GP1N/THNJy0lhtg1UsiuRVi8W3Pc9pLkcdL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271578; c=relaxed/simple; bh=etOVA7exvPfFTzoKY8Fso7Jdm7CkckVi5SBT4zKGBQQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rXF9vSl1O392BLPPllfABiKE2LnjCtPyLGhy3zQNUSZTzZG6qsH1xAbhPbjvC7+fcPc5SmScwU+ebZyjuFDM8lmEkJVL9J2pOwxWHlVYevv5CHI79U+gimvdoGofeVzpXvzU8rAicCw6vmC5/iRHRfUmHfSIOLfP6amJ76peSyk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=si/D5Nw5; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="si/D5Nw5" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1fd66cddd07so21148295ad.2 for ; Mon, 29 Jul 2024 09:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722271576; x=1722876376; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=TiJ7fM85IMGMjgBBVYYw2ZNteCJKvpwjrHE2P481mUM=; b=si/D5Nw5bXzZWCnofDgsL7pgSb1ARcMF2ZLz8CGawwrDXFSeujISVWosTh1pWrwwgi Y5SLPzHYOEIbdm8DA56jrh2iGxIy6gr3J2fi0DQDhUy6/pugFDg4pRZa/QTstt2prcE5 1LELcbFNQy+dBWO1/Os5CFWfOjRP5TKdzcpZ529TX7PxotrQhoMTnew07+/LzswPEdPp R2woQPlsInLrY1WJEbLfM1a8zBltJ8OLvwN2QFP5q+Mi7BJJOoLNN1qI/2M7EPs6a7hj +frRa4BkHh1Ngzw7N+CKCdEpoSyoKMDbavgj9LT9b8+vWUj/YuQE1DQrlZYpua2wSmrF TwQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722271576; x=1722876376; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TiJ7fM85IMGMjgBBVYYw2ZNteCJKvpwjrHE2P481mUM=; b=cN5mbeK9kbUwsUnQuQpzVDkWrVS9a0eYOcifikl/K/ihTp5wN9ZHIHElaCJH7Wx/mH j3Hv1WlNlFZ4zGill+JDt7w5CiQl4lH5RVsjMWxSBJobG+daBpVvvpvgmyeXu/yoU+NC vFbK6OFm39abWjUHiKQuZBn+3FcaHRd7eCWOsXdUYzB/zCdak7fq7VM00KgReVJGJtOx nECErDgcidcy/na+Cg1eWg/Thj9FNPqNYBlSn2gZfRasbpCIm0Sus1mZ1ZAgCbrAUdMy loeuAM+Kg0HBtqy3XaGz6RA1cMyyA9Ex7PEUJ3Z8xO2HkIXf5ub/CXG5IK12TGJyEJd2 K0lw== X-Forwarded-Encrypted: i=1; AJvYcCUH95V8w3Dd8ezFsnr+aP4DsjXFG6NYEA1KrfV/ZezWIy7aBJO6ic00hOHT5AUil+jnpJk0zEANvebkFDpQzFoZIPFx X-Gm-Message-State: AOJu0YzxC4a3+BZY/1jlZ9Gwt+3yjmwkPgKMJUKZ52tvXowzu99/yFC6 VT0857L498wYukOdnq9/2AtHbmu2U6IXuyNyAjPlaBzMVukbsoNt0JrBREtmYy0= X-Google-Smtp-Source: AGHT+IFhuipRzGKQii+jATiqJQQJZtOk5vz10sHKaqUAKhBj4Dqb4RoBXjOU9eIeu9ns2+sh073puA== X-Received: by 2002:a17:903:1245:b0:1fb:3e8c:95a6 with SMTP id d9443c01a7336-1ff048e59c8mr60825725ad.40.1722271576219; Mon, 29 Jul 2024 09:46:16 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7d401c6sm85480545ad.117.2024.07.29.09.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 09:46:15 -0700 (PDT) From: Charlie Jenkins Date: Fri, 26 Jul 2024 22:29:36 -0700 Subject: [PATCH v2 6/8] libperf: Add perf_evsel__{refresh, period}() functions Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240726-overflow_check_libperf-v2-6-7d154dcf6bea@rivosinc.com> References: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> In-Reply-To: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Charlie Jenkins , Shunsuke Nakamura X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722271564; l=6171; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=aVBjIsxJT8LS4fAGhXq/xpQCeYcYwi9ufo4Vs2pLLv0=; b=4ordREpvBQFF9nRLjzkG5AYtTDom9kp+2J+geJhO9Yp6HMv/+UWcHQtAxs9+iatyKJaqco8NC SpRNHVe7k69ClWIp01TemQTm7dk2bf/Zfb5bcN84iq/MmtiCHsCmzla X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= From: Shunsuke Nakamura Add the following functions: perf_evsel__refresh() perf_evsel__period() to set the over flow limit and period. Signed-off-by: Shunsuke Nakamura Signed-off-by: Charlie Jenkins --- tools/lib/perf/Documentation/libperf.txt | 2 ++ tools/lib/perf/evsel.c | 46 ++++++++++++++++++++++++++------ tools/lib/perf/include/perf/evsel.h | 2 ++ tools/lib/perf/libperf.map | 2 ++ 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt index f1bfe6b6e78a..aac764e63db6 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -162,6 +162,8 @@ SYNOPSIS 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); + int perf_evsel__refresh(struct perf_evsel *evsel, int refresh); + int perf_evsel__period(struct perf_evsel *evsel, int period); 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 6b98cba6eb4f..063498fc52f2 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -418,7 +418,7 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu_map_idx, int thread, return 0; } -static int perf_evsel__ioctl(struct perf_evsel *evsel, int ioc, void *arg, +static int perf_evsel__ioctl(struct perf_evsel *evsel, int ioc, unsigned long arg, int cpu_map_idx, int thread) { int *fd = FD(evsel, cpu_map_idx, thread); @@ -430,7 +430,7 @@ static int perf_evsel__ioctl(struct perf_evsel *evsel, int ioc, void *arg, } static int perf_evsel__run_ioctl(struct perf_evsel *evsel, - int ioc, void *arg, + int ioc, unsigned long arg, int cpu_map_idx) { int thread; @@ -447,7 +447,7 @@ static int perf_evsel__run_ioctl(struct perf_evsel *evsel, int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx) { - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, cpu_map_idx); + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, cpu_map_idx); } int perf_evsel__enable_thread(struct perf_evsel *evsel, int thread) @@ -457,7 +457,7 @@ int perf_evsel__enable_thread(struct perf_evsel *evsel, int thread) int err; perf_cpu_map__for_each_cpu(cpu, idx, evsel->cpus) { - err = perf_evsel__ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, idx, thread); + err = perf_evsel__ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, idx, thread); if (err) return err; } @@ -471,13 +471,13 @@ int perf_evsel__enable(struct perf_evsel *evsel) int err = 0; for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++) - err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, i); + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, i); return err; } int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx) { - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, cpu_map_idx); + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0, cpu_map_idx); } int perf_evsel__disable(struct perf_evsel *evsel) @@ -486,7 +486,37 @@ int perf_evsel__disable(struct perf_evsel *evsel) int err = 0; for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++) - err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, i); + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0, i); + return err; +} + +int perf_evsel__refresh(struct perf_evsel *evsel, int refresh) +{ + int i; + int err = 0; + + for (i = 0; i < xyarray__max_x(evsel->fd) && !err; i++) + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_REFRESH, refresh, i); + return err; +} + +int perf_evsel__period(struct perf_evsel *evsel, __u64 period) +{ + struct perf_event_attr *attr; + int i; + int err = 0; + + attr = perf_evsel__attr(evsel); + + for (i = 0; i < xyarray__max_x(evsel->fd); i++) { + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_PERIOD, + (unsigned long)&period, i); + if (err) + return err; + } + + attr->sample_period = period; + return err; } @@ -497,7 +527,7 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter) for (i = 0; i < perf_cpu_map__nr(evsel->cpus) && !err; i++) err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_SET_FILTER, - (void *)filter, i); + (unsigned long)filter, i); return err; } diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/evsel.h index 77816a35c383..613a63790346 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -63,6 +63,8 @@ LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel); LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx); LIBPERF_API int perf_evsel__enable_thread(struct perf_evsel *evsel, int thread); LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel); +LIBPERF_API int perf_evsel__refresh(struct perf_evsel *evsel, int refresh); +LIBPERF_API int perf_evsel__period(struct perf_evsel *evsel, __u64 period); LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx); LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel); LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel); diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index f68519e17885..12bdf2f43993 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -35,6 +35,8 @@ LIBPERF_0.0.1 { perf_evsel__munmap; perf_evsel__mmap_base; perf_evsel__read; + perf_evsel__refresh; + perf_evsel__period; perf_evsel__cpus; perf_evsel__threads; perf_evsel__attr; From patchwork Sat Jul 27 05:29:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13745467 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD200189F30 for ; Mon, 29 Jul 2024 16:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271580; cv=none; b=Yt++IE7MGsMgtJhQzpCWeebBetM5MeA8BJACixo+0TLw9XJJD6VrQCtEOQmuiA5qKRzGv1NPhdT0IjN3ZCCH1YBsdh2kDeNm6vpDRcSGsawGLM6MVj3y4Ud/x8/sumvGUwZFf/GczAOS5LuVWvmtKHixU4/cGrO59jzfirHbuT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271580; c=relaxed/simple; bh=DcCALxIHVCUK+9WrmJFTXpoeJxfw9pHG1sO9q8SD+00=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YlwoY3HkJc5NbsXlu3jHF7r/NIKdEBGLgO0SdLsFKF1ms0jlN96l17RtJsEdnBdfIDFHne3+sMpcuDRnBIMmeMRYe9PmqDWitWjF1BCRnLya1XQEqgaa1Hu+BME0nCxPBntWA8Cn9DaODxoAfJd6Ugfq4wrImfGNPWV4OUAO8DU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=mJyZycx+; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="mJyZycx+" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1fed72d23a7so22058745ad.1 for ; Mon, 29 Jul 2024 09:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722271578; x=1722876378; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=esv+2bQw0aEMT9KM4UokUyH6FGgrDkyBUaVhFoJhC+U=; b=mJyZycx+hMEodAzZe9rbUdYqULnRVrcPJN0Y0oBMluGhX7EROrWyv/Rj7aqLnRorml tRmoyulT9QlLciumW9EVqeQYxBg3Um/woe6WrkyZ4iEUL54YvinHk0wN+WwCriZGELGI y2x4Xvi4Dee0ICkK6yDO6GB9/RTItdpsLn6jVhn410NJEhfkw7HpFLFqYckGaMBN7uLl 7ILn1M5v0bgPftZD3RkuEV4G9R5Hck6JLLnSDcq22USvZ5Gg4adW40pVXpTFi/3L/xuW XtNzQNrqHI1EU3YrocfJLmOkGjjvi0vOY09xEAkzjh/bIJf9lZL9w8U7EhHVBH0WpaG+ 8iBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722271578; x=1722876378; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=esv+2bQw0aEMT9KM4UokUyH6FGgrDkyBUaVhFoJhC+U=; b=HCOpt/lqLNeXUV1cNh41ohiet74Y8sG0qOs8e5fHp2/MXCoK/sM5jFK/CeWlOmfLyX CQyp0KaHtUJRLNvHCw/76yLIfpgJZfylPWcijK1e7JxthrhvmhcNX6k7tp1cWhy5TF6R KbCMSLCdnK9Q4w7wwwnZdN+oAkViHBZp47VUAi062TneEQlPIrtrzbwGO7/wV2ASJz7K 8UIl2niwC7mfrMMw05qksBHQigKuW+FVGHGszE5jK1Bl6VJh9gUVKS37Q6dXXWRXF9af i0OfPoYNqp6ZlfbhkyG1pBylm+WB4moMB22XBa+eUs8sUDAHEwR3Jr8SAXXdgQA4D1tB 08yg== X-Forwarded-Encrypted: i=1; AJvYcCUZvnGfHX+HDWwi7BgAjBRV1CmfRo1c70P/Fmmivs0wi5Wtt4B6Bl9ZM6YeiX3UXNAh2VqzeWjpZ2TryEUbLXzcCXrq X-Gm-Message-State: AOJu0YxgeBJ/tdCXfMV+fFjwvdR02DP27HcH6pkPANUBrBo8oDSvbBsI 4nHixJAu+EkPFdo4n3u8uCxkYEkCXIK34V9MGsY2B/JA9FW4o8JomqzspxEbeo8= X-Google-Smtp-Source: AGHT+IFSQceV8kL40vzasoKkWICuL+b5k2ukcYwrsTHg9WGugoQ3cfB1FuG9VUzxm2y6klGdQ4UbgQ== X-Received: by 2002:a17:902:ecd1:b0:1fd:a412:5ded with SMTP id d9443c01a7336-1ff0482c4b4mr61845635ad.26.1722271578209; Mon, 29 Jul 2024 09:46:18 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7d401c6sm85480545ad.117.2024.07.29.09.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 09:46:17 -0700 (PDT) From: Charlie Jenkins Date: Fri, 26 Jul 2024 22:29:37 -0700 Subject: [PATCH v2 7/8] libperf test: Add test_stat_overflow() Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240726-overflow_check_libperf-v2-7-7d154dcf6bea@rivosinc.com> References: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> In-Reply-To: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Charlie Jenkins , Shunsuke Nakamura X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722271564; l=6608; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=A//Q40WQ+t6MAB7Qrx+4soh8s9dOFzIWFwFxUkcU1xQ=; b=+cUdR4bb9FAKj9f/4IUP2R/tUuPZM+LqB0IMO5aNFMPM4mX7d13LQVKXc6rmVNnaFYgiGulWk PlzGGTIQ9umDJIit7xHV/tS7FtHPUUN0OsO1VqzI/T/ntOXJ8jerbFS X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= From: Shunsuke Nakamura Added overflow test using refresh and period. Confirmation - That the overflow occurs the number of times specified by perf_evse__refresh() - That the period can be updated by perf_evsel__period() Committer testing: $ sudo make tests -C ./tools/lib/perf V=1 make: Entering directory '/home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/perf' make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=. obj=libperf make -C /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/api/ O= libapi.a make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./fd obj=libapi make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./fs obj=libapi make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=. obj=tests make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./tests obj=tests running static: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c... OK - running tests/test-evsel.c... period = 1000000 overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_HUP = 1, other signal event = 0 period = 2000000 overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_HUP = 1, other signal event = 0 period = 1000000 overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_HUP = 1, other signal event = 0 period = 2000000 overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_HUP = 1, other signal event = 0 OK running dynamic: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c... OK - running tests/test-evsel.c... period = 1000000 overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_HUP = 1, other signal event = 0 period = 2000000 overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_HUP = 1, other signal event = 0 period = 1000000 overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_HUP = 1, other signal event = 0 period = 2000000 overflow limit = 3, overflow count = 3, POLL_IN = 2, POLL_HUP = 1, other signal event = 0 OK make: Leaving directory '/home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/perf' Signed-off-by: Shunsuke Nakamura Signed-off-by: Charlie Jenkins --- tools/lib/perf/tests/test-evsel.c | 107 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/tools/lib/perf/tests/test-evsel.c b/tools/lib/perf/tests/test-evsel.c index 545ec3150546..b27dd65f2ec9 100644 --- a/tools/lib/perf/tests/test-evsel.c +++ b/tools/lib/perf/tests/test-evsel.c @@ -1,7 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include +#include +#include +#include #include #include #include @@ -11,6 +15,15 @@ #include #include "tests.h" +#define WAIT_COUNT 10000000UL +static struct signal_counts { + int in; + int hup; + int others; + int overflow; +} sig_count; +static struct perf_evsel *s_evsel; + static int libperf_print(enum libperf_print_level level, const char *fmt, va_list ap) { @@ -349,6 +362,98 @@ static int test_stat_read_format(void) return 0; } +static void sig_handler(int signo, siginfo_t *info, void *uc) +{ + switch (info->si_code) { + case POLL_IN: + sig_count.in++; + break; + case POLL_HUP: + sig_count.hup++; + break; + default: + sig_count.others++; + } + + sig_count.overflow++; +} + +static int test_stat_overflow(int owner) +{ + static struct sigaction sig; + u64 period = 1000000; + int overflow_limit = 3; + + struct perf_thread_map *threads; + struct perf_event_attr attr = { + .type = PERF_TYPE_SOFTWARE, + .config = PERF_COUNT_SW_TASK_CLOCK, + .sample_type = PERF_SAMPLE_PERIOD, + .sample_period = period, + .disabled = 1, + }; + struct perf_event_attr *tmp_attr; + int err = 0, i; + + LIBPERF_OPTS(perf_evsel_open_opts, opts, + .open_flags = PERF_FLAG_FD_CLOEXEC, + .flags = (O_RDWR | O_NONBLOCK | O_ASYNC), + .signal = SIGRTMIN + 1, + .owner_type = owner, + .sig = &sig); + + /* setup signal handler */ + memset(&sig, 0, sizeof(struct sigaction)); + sig.sa_sigaction = (void *)sig_handler; + sig.sa_flags = SA_SIGINFO; + + threads = perf_thread_map__new_dummy(); + __T("failed to create threads", threads); + + perf_thread_map__set_pid(threads, 0, 0); + + s_evsel = perf_evsel__new(&attr); + __T("failed to create evsel", s_evsel); + + err = perf_evsel__open_opts(s_evsel, NULL, threads, &opts); + __T("failed to open evsel", err == 0); + + for (i = 0; i < 2; i++) { + volatile unsigned int wait_count = WAIT_COUNT; + + sig_count.in = 0; + sig_count.hup = 0; + sig_count.others = 0; + sig_count.overflow = 0; + + period = period << i; + err = perf_evsel__period(s_evsel, period); + __T("failed to period evsel", err == 0); + + tmp_attr = perf_evsel__attr(s_evsel); + __T_VERBOSE("\tperiod = %llu\n", tmp_attr->sample_period); + + err = perf_evsel__refresh(s_evsel, overflow_limit); + __T("failed to refresh evsel", err == 0); + + while (wait_count--) + ; + + __T_VERBOSE("\toverflow limit = %d, overflow count = %d, ", + overflow_limit, sig_count.overflow); + __T_VERBOSE("POLL_IN = %d, POLL_HUP = %d, other signal event = %d\n", + sig_count.in, sig_count.hup, sig_count.others); + + __T("failed to overflow count", overflow_limit == sig_count.overflow); + } + + perf_evsel__close(s_evsel); + perf_evsel__delete(s_evsel); + perf_thread_map__put(threads); + + return 0; +} + int test_evsel(int argc, char **argv) { __T_START; @@ -361,6 +466,8 @@ int test_evsel(int argc, char **argv) test_stat_user_read(PERF_COUNT_HW_INSTRUCTIONS); test_stat_user_read(PERF_COUNT_HW_CPU_CYCLES); test_stat_read_format(); + test_stat_overflow(F_OWNER_PID); + test_stat_overflow(F_OWNER_TID); __T_END; return tests_failed == 0 ? 0 : -1; From patchwork Sat Jul 27 05:29:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 13745468 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A011F18A930 for ; Mon, 29 Jul 2024 16:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271582; cv=none; b=epuZSV2Upg3rBsdMOS6Ad6469NflnhTN5gG+8SWHRcn2F4sGmpe1kQ8+NolJFAtx/w98RhfrDTNzH3iNX/ZXILCR07MuWwSAekBPFADkR6GOX3nQh0EpaupuhgJNRBfIE12xniwkjep1L/LbNBUjfJAkgEJcyZoe8Vi/GsSLk+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722271582; c=relaxed/simple; bh=vcEzXouSW5qhs+WKWJ6j7BThr5Umszy0VJSt4R3KWXE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d8CgqCxq9B05FsjLtYhrF+UlROltMTiaSL3wn7BxxQqufcIT2chlT1BwOpgujOzfpftKkcfMlMprE4MZzJszZv+URatu3yP39Vf5aIkizoFhXz3wfsRrcxeOEBhf5UDJVhD+83QGCBM5hMKDLEGuJDNZlYCUJc1HmfeHJ14QHas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=P6zz1nS1; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="P6zz1nS1" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1fc4fccdd78so20572735ad.2 for ; Mon, 29 Jul 2024 09:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722271580; x=1722876380; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BW7CGRA85beDZYynJOG3K+o2YMpxrF+HMxsvS/Z8BLI=; b=P6zz1nS1Qk6Oh+bA2gtESUKV0MFqo0sGW6ESrThezO3r8j2MjGd+lofOCCGbUF/dwa ETo0w5q6T8iRFn1kZjwph9A9dd4ODJ377xXiXrNxF6j5A1Y0xhUMbmtk+SQpHIqRxy/0 CUQPgYPdFIV4biOdmMyPOHS9GkVyWCH6C7nF52tuLAr/PmD05i8MCg1HBxXb0+67xmBL HcGtAMzRYcDVmPkJ76hwO+EEWH4vSJrr1fcvQOZ6PXkzBu0v10ZEtNikGmpks0h9b49H HfQjfDzuBOZlXUaPkR716dz/Y/KrQeVj0M+052DE/a3E9YWmxoaSpGBUbSghCmnYXVsY U9cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722271580; x=1722876380; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BW7CGRA85beDZYynJOG3K+o2YMpxrF+HMxsvS/Z8BLI=; b=PU3se96+xdbpxMkLW08i28gtyYI6RI6QPTjyUgE8/DBpGMIXbhDDeLqWlvKPfbt0ZV hoENzYzMUxEduNajqPKu0LBgIuJ+GxN8kzv+2jZeKLEYNAzJO90sKfkTZaV9dCfnYqYs lK78OWKbUjhO355cH0JwZIACRnCENOF3mfpvDvXGS+Pmd0ZpC8PQsvZ9aEwMohuBwPqF ++o5vvq1cPSaXOM0q2zMzYtgMVLQEkZeq70QCp7nj2bnIo5K3DbkHCbVGqFFG7xhLY/J wdFrcU7twJzsXAi6vPos84tgX0r+sgm8KS0/wIu9Z7PRIpByNU7lHoGe2nlkJ0rD53wl ejdw== X-Forwarded-Encrypted: i=1; AJvYcCX0f72ssDG35X8FShoM/Wp9tFuIa4PxqkkVmOFKa5dLLuiFxR9RhRg7mfw7Cn8ZHZ+uqO2La0XwiXEQ4WEnq8nVcvZE X-Gm-Message-State: AOJu0YyYXKKu5vKls1U9vPi14ch2BiZBhfvE/dU5GvPJO7Xi+7FJhesr LGMAuMWtpnA/6Y9bhgxgWR6gM4Eo3rGj+gS5N3zPaNQvf4t/p8/H6+Fuz4d0/Bo= X-Google-Smtp-Source: AGHT+IGT68p/2k5fQAsQJYVblnXyBTkymlHklXNAKKlhKSCjLI+wrBNoURLMQpu2s75WaRqmrTJs/A== X-Received: by 2002:a17:903:4298:b0:1fd:3cf9:c7d1 with SMTP id d9443c01a7336-1ff0482be69mr57426615ad.19.1722271579966; Mon, 29 Jul 2024 09:46:19 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7d401c6sm85480545ad.117.2024.07.29.09.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 09:46:19 -0700 (PDT) From: Charlie Jenkins Date: Fri, 26 Jul 2024 22:29:38 -0700 Subject: [PATCH v2 8/8] libperf test: Add test_stat_overflow_event() Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240726-overflow_check_libperf-v2-8-7d154dcf6bea@rivosinc.com> References: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> In-Reply-To: <20240726-overflow_check_libperf-v2-0-7d154dcf6bea@rivosinc.com> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Charlie Jenkins , Shunsuke Nakamura X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722271564; l=7556; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=NX8BD2CX09iOEogiAZJc+2h9Y+GaCDx2QBL9DE7jL6c=; b=vj4XrZPx2rKNLrg7qQ9zQkLdR+6nTeAcc3FVWqgcDvl00wCiU8f0eW84vn9pbovF0dF0LBn7o BXCM/LpaJu1DMdDywG4WOfEvQVKgPjHU1FyIEX12mh4eKyAnU8EZExi X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= From: Shunsuke Nakamura Add a test to check overflowed events. Committer testing: $ sudo make tests -C ./tools/lib/perf V=1 make: Entering directory '/home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/perf' make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=. obj=libperf make -C /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/api/ O= libapi.a make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./fd obj=libapi make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./fs obj=libapi make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=. obj=tests make -f /home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/build/Makefile.build dir=./tests obj=tests running static: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c... Event 0 -- overflow flag = 0x1, POLL_HUP = 1, other signal event = 0 Event 1 -- overflow flag = 0x2, POLL_HUP = 1, other signal event = 0 Event 2 -- overflow flag = 0x4, POLL_HUP = 1, other signal event = 0 Event 3 -- overflow flag = 0x8, POLL_HUP = 1, other signal event = 0 OK - running tests/test-evsel.c... OK running dynamic: - running tests/test-cpumap.c...OK - running tests/test-threadmap.c...OK - running tests/test-evlist.c... Event 0 -- overflow flag = 0x1, POLL_HUP = 1, other signal event = 0 Event 1 -- overflow flag = 0x2, POLL_HUP = 1, other signal event = 0 Event 2 -- overflow flag = 0x4, POLL_HUP = 1, other signal event = 0 Event 3 -- overflow flag = 0x8, POLL_HUP = 1, other signal event = 0 OK - running tests/test-evsel.c... OK make: Leaving directory '/home/nakamura/build_work/build_kernel/linux-kernel/linux/tools/lib/perf' Signed-off-by: Shunsuke Nakamura Signed-off-by: Charlie Jenkins --- tools/lib/perf/tests/test-evlist.c | 111 +++++++++++++++++++++++++++++++++++++ tools/lib/perf/tests/test-evsel.c | 20 +++---- 2 files changed, 121 insertions(+), 10 deletions(-) diff --git a/tools/lib/perf/tests/test-evlist.c b/tools/lib/perf/tests/test-evlist.c index 3a833f0349d3..7bfceb8e0c66 100644 --- a/tools/lib/perf/tests/test-evlist.c +++ b/tools/lib/perf/tests/test-evlist.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include #include @@ -24,6 +26,13 @@ #define EVENT_NUM 15 #define WAIT_COUNT 100000000UL +static unsigned int overflow_flag; +static struct signal_counts { + int hup; + int others; +} sig_count; +static struct perf_evlist *s_evlist; + static int libperf_print(enum libperf_print_level level, const char *fmt, va_list ap) { @@ -570,6 +579,107 @@ static int test_stat_multiplexing(void) return 0; } +static void sig_handler(int signo, siginfo_t *info, void *uc) +{ + struct perf_evsel *evsel; + int i = 0; + + perf_evlist__for_each_evsel(s_evlist, evsel) { + if (perf_evsel__has_fd(evsel, info->si_fd)) { + if (info->si_code == POLL_HUP) + sig_count.hup++; + else + sig_count.others++; + + overflow_flag = (1U << i); + return; + } + i++; + } + + __T_VERBOSE("Failed to get fd of overflowed event"); +} + +static int test_stat_overflow_event(void) +{ + static struct sigaction sigact; + + struct perf_thread_map *threads; + struct perf_evsel *evsel; + struct perf_event_attr attr = { + .type = PERF_TYPE_SOFTWARE, + .config = PERF_COUNT_SW_CPU_CLOCK, + .sample_type = PERF_SAMPLE_PERIOD, + .sample_period = 100000, + .disabled = 1, + }; + int err, i, event_num = 4; + + LIBPERF_OPTS(perf_evsel_open_opts, opts, + .open_flags = PERF_FLAG_FD_CLOEXEC, + .fcntl_flags = (O_RDWR | O_NONBLOCK | O_ASYNC), + .signal = SIGRTMIN + 1, + .owner_type = F_OWNER_PID, + .sigact = &sigact); + + /* setup signal handler */ + memset(&sigact, 0, sizeof(struct sigaction)); + sigact.sa_sigaction = (void *)sig_handler; + sigact.sa_flags = SA_SIGINFO; + + threads = perf_thread_map__new_dummy(); + __T("failed to create threads", threads); + + perf_thread_map__set_pid(threads, 0, 0); + + s_evlist = perf_evlist__new(); + __T("failed to create evlist", s_evlist); + + for (i = 0; i < event_num; i++) { + evsel = perf_evsel__new(&attr); + __T("failed to create evsel", evsel); + + perf_evlist__add(s_evlist, evsel); + } + + perf_evlist__set_maps(s_evlist, NULL, threads); + + err = perf_evlist__open_opts(s_evlist, &opts); + __T("failed to open evlist", err == 0); + + i = 0; + perf_evlist__for_each_evsel(s_evlist, evsel) { + volatile unsigned int wait_count = WAIT_COUNT; + + overflow_flag = 0; + sig_count.hup = 0; + sig_count.others = 0; + + err = perf_evsel__refresh(evsel, 1); + __T("failed to refresh evsel", err == 0); + + while (wait_count--) + ; + + __T_VERBOSE("Event %2d -- overflow flag = %#x, ", + i, overflow_flag); + __T_VERBOSE("POLL_HUP = %d, other signal event = %d\n", + sig_count.hup, sig_count.others); + + __T("unexpected event overflow detected", overflow_flag && (1U << i)); + __T("unexpected signal event detected", + sig_count.hup == 1 && sig_count.others == 0); + + i++; + } + + perf_evlist__close(s_evlist); + perf_evlist__delete(s_evlist); + perf_thread_map__put(threads); + + return 0; +} + int test_evlist(int argc, char **argv) { __T_START; @@ -582,6 +692,7 @@ int test_evlist(int argc, char **argv) test_mmap_thread(); test_mmap_cpus(); test_stat_multiplexing(); + test_stat_overflow_event(); __T_END; return tests_failed == 0 ? 0 : -1; diff --git a/tools/lib/perf/tests/test-evsel.c b/tools/lib/perf/tests/test-evsel.c index b27dd65f2ec9..56f4ae20e922 100644 --- a/tools/lib/perf/tests/test-evsel.c +++ b/tools/lib/perf/tests/test-evsel.c @@ -15,7 +15,7 @@ #include #include "tests.h" -#define WAIT_COUNT 10000000UL +#define WAIT_COUNT 100000000UL static struct signal_counts { int in; int hup; @@ -380,7 +380,7 @@ static void sig_handler(int signo, siginfo_t *info, void *uc) static int test_stat_overflow(int owner) { - static struct sigaction sig; + static struct sigaction sigact; u64 period = 1000000; int overflow_limit = 3; @@ -396,16 +396,16 @@ static int test_stat_overflow(int owner) int err = 0, i; LIBPERF_OPTS(perf_evsel_open_opts, opts, - .open_flags = PERF_FLAG_FD_CLOEXEC, - .flags = (O_RDWR | O_NONBLOCK | O_ASYNC), - .signal = SIGRTMIN + 1, - .owner_type = owner, - .sig = &sig); + .open_flags = PERF_FLAG_FD_CLOEXEC, + .fcntl_flags = (O_RDWR | O_NONBLOCK | O_ASYNC), + .signal = SIGRTMIN + 1, + .owner_type = owner, + .sigact = &sigact); /* setup signal handler */ - memset(&sig, 0, sizeof(struct sigaction)); - sig.sa_sigaction = (void *)sig_handler; - sig.sa_flags = SA_SIGINFO; + memset(&sigact, 0, sizeof(struct sigaction)); + sigact.sa_sigaction = (void *)sig_handler; + sigact.sa_flags = SA_SIGINFO; threads = perf_thread_map__new_dummy(); __T("failed to create threads", threads);