Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1086506lqp; Sun, 14 Apr 2024 13:47:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWRV2rrPiKYcRoinL64I1QncKDKPigUvh7aB15Xbhws979/To2Q2i+h+/1/kTBJOTYmuIfYrUJ9QjpSDDaRqJA4QFnvRveapuEqhDt17w== X-Google-Smtp-Source: AGHT+IGyaObzQ7sIQIsSIF5t0RlKHy7uVo8hORwxObZVCRF04vWls2IY3jJW6O9y0TZ8cQAr370d X-Received: by 2002:a54:4007:0:b0:3c6:974:f1f2 with SMTP id x7-20020a544007000000b003c60974f1f2mr10059561oie.38.1713127670246; Sun, 14 Apr 2024 13:47:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713127670; cv=pass; d=google.com; s=arc-20160816; b=KSvaTDwS9d8uRweQCzivh9JZzOHC2hcm+Zf/4/oNLypYrooL5rX0CaGVEeRxNIImsb Nwv5NRj4V4rcEmcBCStEtdaflMWWJTXKCts9LNV3bl8JC5HyT4fF21pFLZyB+8ZlVQ/k denkR7VMbB5/0gqmUFOLH1udqDOLERqLs3QFarmC0Dg1bKUYn3Bw+GhEQxXaMH1hpHBe kIGmPHR78cZIpDDK1/gspT6M0x656GbciYt1aBdP+lZ4dGIB+zuLoCta6KRF6+i32Axr tAeVvcvJa+Esw4IUXrmC6dENYKt/SE041DVkxRIIWlx4/vRvID7rIFR/ltMkORqbGdDc NqmQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=OtMr7UovHNpiBfohCCUTpX4vqrJn1Sp3nThSAOU8oXs=; fh=9y/kTBTAtyzQerNfP+d4gfB7uNRQC5za/MiFPn88JWI=; b=TMUEW98ILvzudU+7d3f6rc3hbuX2heUjiT+uWwrcmKUY7LVw39kDc+opyonzw8xM1d m5PvmzZ6mZbtoexWD4AJDcSV4YAUhYLdGb1Uk/K/bfLVvm5uom40OITCA1IxFCZ6CkU8 CsmQ1pX6MjZRWTXSU66OzeAp0tqd9TRLCiAGxCmvZAdaymfxgR4SFk1k1LyBY4YzS35v 8HMwqyx9NwyUlAY14EgkZxlzzk8KKDhhrLQaZSMASOW5qoODuFnKQXYREPzqdZ4MXWsP NVcnVS18o+hvAlm3jHQlA4aYJU6ICUfQaOLDYBLVjMbYFPWlR6wNLgzheeO6L8LpuqbB I3Gw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TqQ4puOy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-144399-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144399-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p6-20020a170902780600b001e6765cf0c9si460757pll.437.2024.04.14.13.47.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Apr 2024 13:47:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144399-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TqQ4puOy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-144399-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144399-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 12232B2137E for ; Sun, 14 Apr 2024 20:47:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 50C1A13775F; Sun, 14 Apr 2024 20:47:15 +0000 (UTC) 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" 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 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: 7bit The following commit has been merged into the perf/core branch of tip: Commit-ID: e224d1c1fb93f258030186b4878abe105c296ac1 Gitweb: https://git.kernel.org/tip/e224d1c1fb93f258030186b4878abe105c296ac1 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/selftests/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 += -Wl,-no-as-needed -Wall $(KHDR_INCLUDES) LDFLAGS += -lpthread -TEST_GEN_PROGS := sigtrap_threads remove_on_exec +TEST_GEN_PROGS := 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 = 0; i < 20; ++i) + sleep(1); + + raise(SIGSTOP); + + exit(0); +} + +TEST(watermark_signal) +{ + struct perf_event_attr attr; + struct perf_event_mmap_page *p = NULL; + struct sigaction previous_sigio, sigio = { 0 }; + pid_t child = -1; + int child_status; + int fd = -1; + long page_size = sysconf(_SC_PAGE_SIZE); + + sigio.sa_sigaction = handle_sigio; + EXPECT_EQ(sigaction(SIGIO, &sigio, &previous_sigio), 0); + + memset(&attr, 0, sizeof(attr)); + attr.size = sizeof(attr); + attr.type = PERF_TYPE_SOFTWARE; + attr.config = PERF_COUNT_SW_DUMMY; + attr.sample_period = 1; + attr.disabled = 1; + attr.watermark = 1; + attr.context_switch = 1; + attr.wakeup_watermark = 1; + + child = fork(); + EXPECT_GE(child, 0); + if (child == 0) + do_child(); + else if (child < 0) { + perror("fork()"); + goto cleanup; + } + + if (waitpid(child, &child_status, WSTOPPED) != child || + !(WIFSTOPPED(child_status) && WSTOPSIG(child_status) == SIGSTOP)) { + fprintf(stderr, + "failed to sycnhronize with child errno=%d status=%x\n", + errno, + child_status); + goto cleanup; + } + + fd = 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 = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (p == 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) != -1 || errno != EINTR) + fprintf(stderr, + "expected SIGIO to terminate wait errno=%d status=%x\n%d", + errno, + child_status, + sigio_count); + + EXPECT_GE(sigio_count, 1); + +cleanup: + if (p != NULL) + munmap(p, 2 * page_size); + + if (fd >= 0) + close(fd); + + if (child > 0) { + kill(child, SIGKILL); + waitpid(child, NULL, 0); + } + + sigaction(SIGIO, &previous_sigio, NULL); +} + +TEST_HARNESS_MAIN