From nobody Tue Dec 16 04:40:13 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADEB853365; Sun, 14 Apr 2024 20:47:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713127634; cv=none; b=pTkeaYEGGEidqqPJUFUTN0Z543EzmSzp4PvkOLuKpKOfrnttsIQBk20wTmoUpNNanYnze14I7T2vkAySZxJEDmRQjN7RhgTm5zC8CGcOSg6xA+VCzkSli3dcexxbD0hjZsxxvknVJRlGadOepsPly4zzrW4hUrLGbLRKauu3EGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713127634; c=relaxed/simple; bh=SSq63jYCy0vXvN/OQllQvfRMkNdf48Ela2wdi5HCzfA=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=XbaSJHHTon8+XOlZdyM609mFdZEHb5RjT+e7ztz6z+u9LkbgjsL9H9YJcElimhBMMsTK+9zuUIakOmhkcvz547tfDAvKFq9RaXmyJoIdVBe2G15+nZlKlNsmB3tQLPXs4bNw2rdTwBPD0ug2SVlXgHauprBS6DGI2gDyw4I2MLw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=TqQ4puOy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WJxz2TuQ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TqQ4puOy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WJxz2TuQ" Date: Sun, 14 Apr 2024 20:47:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1713127631; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OtMr7UovHNpiBfohCCUTpX4vqrJn1Sp3nThSAOU8oXs=; b=TqQ4puOyuO3/jbdD64bvAKQQfz01ooB1ExB6SbDQfIqlM9vOqu3pEkH/7REjf9GzPaQ5Nq eEfJP4NvVXbvzrbZUJeIE52N+U8dc8I8LzOmVlZM2fAf87z8SVR/+Yb34LVRTqxXB31Mke UnieLMWcoeQC7BvthggiGAt2fhQ/flJIZupfiAchfpLIjUMgB5M5+c8C0cWazhCt2RI598 9tcfQC1Put+vcMCdj6235qEPFc/YWdnrH9K+D9g30ydcqY22HGPXV2LL4b3zYEhu+1UdrU 3ZdvCuDM+gbTDZkMUCdhijCfT9yOVXq+XUAY6KnC1vzWoyZJNtmtK9giJnTKzQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1713127631; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OtMr7UovHNpiBfohCCUTpX4vqrJn1Sp3nThSAOU8oXs=; b=WJxz2TuQB5+dIDPcySri/yZhvqYtHNbXQ1aY/Uk5hngWndaPQ2iY2ERkbDesXtW+CkLL6N Khx2Xz882HqDB4Ag== From: "tip-bot2 for Kyle Huey" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] selftests/perf_events: Test FASYNC with watermark wakeups Cc: Kyle Huey , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240413141618.4160-4-khuey@kylehuey.com> References: <20240413141618.4160-4-khuey@kylehuey.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171312763030.10875.17033743361320585734.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the perf/core branch of tip: Commit-ID: e224d1c1fb93f258030186b4878abe105c296ac1 Gitweb: https://git.kernel.org/tip/e224d1c1fb93f258030186b4878abe105= c296ac1 Author: Kyle Huey AuthorDate: Sat, 13 Apr 2024 07:16:20 -07:00 Committer: Ingo Molnar CommitterDate: Sun, 14 Apr 2024 22:26:33 +02:00 selftests/perf_events: Test FASYNC with watermark wakeups The test uses PERF_RECORD_SWITCH records to fill the ring buffer and trigger the watermark wakeup, which in turn should trigger an IO signal. Signed-off-by: Kyle Huey Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20240413141618.4160-4-khuey@kylehuey.com --- tools/testing/selftests/perf_events/.gitignore | 1 +- tools/testing/selftests/perf_events/Makefile | 2 +- tools/testing/selftests/perf_events/watermark_signal.c | 146 ++++++++- 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/perf_events/watermark_signal.c diff --git a/tools/testing/selftests/perf_events/.gitignore b/tools/testing= /selftests/perf_events/.gitignore index 790c470..ee93dc4 100644 --- a/tools/testing/selftests/perf_events/.gitignore +++ b/tools/testing/selftests/perf_events/.gitignore @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only sigtrap_threads remove_on_exec +watermark_signal diff --git a/tools/testing/selftests/perf_events/Makefile b/tools/testing/s= elftests/perf_events/Makefile index db93c4f..70e3ff2 100644 --- a/tools/testing/selftests/perf_events/Makefile +++ b/tools/testing/selftests/perf_events/Makefile @@ -2,5 +2,5 @@ CFLAGS +=3D -Wl,-no-as-needed -Wall $(KHDR_INCLUDES) LDFLAGS +=3D -lpthread =20 -TEST_GEN_PROGS :=3D sigtrap_threads remove_on_exec +TEST_GEN_PROGS :=3D sigtrap_threads remove_on_exec watermark_signal include ../lib.mk diff --git a/tools/testing/selftests/perf_events/watermark_signal.c b/tools= /testing/selftests/perf_events/watermark_signal.c new file mode 100644 index 0000000..49dc1e8 --- /dev/null +++ b/tools/testing/selftests/perf_events/watermark_signal.c @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../kselftest_harness.h" + +#define __maybe_unused __attribute__((__unused__)) + +static int sigio_count; + +static void handle_sigio(int signum __maybe_unused, + siginfo_t *oh __maybe_unused, + void *uc __maybe_unused) +{ + ++sigio_count; +} + +static void do_child(void) +{ + raise(SIGSTOP); + + for (int i =3D 0; i < 20; ++i) + sleep(1); + + raise(SIGSTOP); + + exit(0); +} + +TEST(watermark_signal) +{ + struct perf_event_attr attr; + struct perf_event_mmap_page *p =3D NULL; + struct sigaction previous_sigio, sigio =3D { 0 }; + pid_t child =3D -1; + int child_status; + int fd =3D -1; + long page_size =3D sysconf(_SC_PAGE_SIZE); + + sigio.sa_sigaction =3D handle_sigio; + EXPECT_EQ(sigaction(SIGIO, &sigio, &previous_sigio), 0); + + memset(&attr, 0, sizeof(attr)); + attr.size =3D sizeof(attr); + attr.type =3D PERF_TYPE_SOFTWARE; + attr.config =3D PERF_COUNT_SW_DUMMY; + attr.sample_period =3D 1; + attr.disabled =3D 1; + attr.watermark =3D 1; + attr.context_switch =3D 1; + attr.wakeup_watermark =3D 1; + + child =3D fork(); + EXPECT_GE(child, 0); + if (child =3D=3D 0) + do_child(); + else if (child < 0) { + perror("fork()"); + goto cleanup; + } + + if (waitpid(child, &child_status, WSTOPPED) !=3D child || + !(WIFSTOPPED(child_status) && WSTOPSIG(child_status) =3D=3D SIGSTOP))= { + fprintf(stderr, + "failed to sycnhronize with child errno=3D%d status=3D%x\n", + errno, + child_status); + goto cleanup; + } + + fd =3D syscall(__NR_perf_event_open, &attr, child, -1, -1, + PERF_FLAG_FD_CLOEXEC); + if (fd < 0) { + fprintf(stderr, "failed opening event %llx\n", attr.config); + goto cleanup; + } + + if (fcntl(fd, F_SETFL, FASYNC)) { + perror("F_SETFL FASYNC"); + goto cleanup; + } + + if (fcntl(fd, F_SETOWN, getpid())) { + perror("F_SETOWN getpid()"); + goto cleanup; + } + + if (fcntl(fd, F_SETSIG, SIGIO)) { + perror("F_SETSIG SIGIO"); + goto cleanup; + } + + p =3D mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0= ); + if (p =3D=3D NULL) { + perror("mmap"); + goto cleanup; + } + + if (ioctl(fd, PERF_EVENT_IOC_ENABLE, 0)) { + perror("PERF_EVENT_IOC_ENABLE"); + goto cleanup; + } + + if (kill(child, SIGCONT) < 0) { + perror("SIGCONT"); + goto cleanup; + } + + if (waitpid(child, &child_status, WSTOPPED) !=3D -1 || errno !=3D EINTR) + fprintf(stderr, + "expected SIGIO to terminate wait errno=3D%d status=3D%x\n%d", + errno, + child_status, + sigio_count); + + EXPECT_GE(sigio_count, 1); + +cleanup: + if (p !=3D NULL) + munmap(p, 2 * page_size); + + if (fd >=3D 0) + close(fd); + + if (child > 0) { + kill(child, SIGKILL); + waitpid(child, NULL, 0); + } + + sigaction(SIGIO, &previous_sigio, NULL); +} + +TEST_HARNESS_MAIN