From nobody Mon Feb 9 12:13:27 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 4DB682DE703 for ; Wed, 3 Dec 2025 21:47:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764798450; cv=none; b=EO8T0xRHxxBSaRPCb1eVZJG1COlQ08mo3wpYEo0wLQUah1m0kYGxFQF3eK0BGBu58E+QVFmHAuq27VItfnXV6J1QjNwiqWijVvaa3+4fe+uwbEs7GMaMEvt6R9uPfmT9pS1+YjpeWjKAP/kIfaUj3MORBLBeeymEOp2ZybE6XSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764798450; c=relaxed/simple; bh=NLjjJgqj44yOShiPvUtgrdHvboGVu5475ukXj0UL1WE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dBaRY82zVmOI9NBIDzlcPsUZXMH7BibXX/Y5V2Wr/XzWVsXMzFO7czwnHyKH0visVMhk02jVEk35E1TR7i3WxUANhdX1Mb7lGuTjWcW2AJpzamxJPUQl06JO9XggEm7rmzGS1r7HsCFUb/PPJyRxnSsz86zRj++afZDune7MytU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jgMJpgMz; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jgMJpgMz" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-bb27b422cf2so304068a12.1 for ; Wed, 03 Dec 2025 13:47:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764798447; x=1765403247; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4ROp2gD1qsi5HFemrZlvE5vnoydq6n4iQlRkymTuUuc=; b=jgMJpgMz41ZkXX6Q7M80cfV/fcFXXUgwdzB3e7KCtrj3lmGNiEktxPohCGNGFdpyrG /RuAoUTxM0g8L2M4DSVjRL+OWdm/Lz7sexng8ebb6ZzjzN5mtom6ctVKB/2NDPQvSA5M Lg2msT9Jd0xV42sHdlLdTILBBY4K3uSjGrzMFH3mOld7fMFBByxPvqk93JpTE+JdTh5U 8ln42cNUMb4m3MukkYAekF3aubgZ6xcuBD4FWSDrjCZByZTLXyONsgUgNkzDXHkWJthr 9U00Sizuf/yDCPNI9RRZQauKar4mNwcGUGovGHM1ZRY5Yna5rOfoxuF69+eJFR9h+XSz 18Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764798447; x=1765403247; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4ROp2gD1qsi5HFemrZlvE5vnoydq6n4iQlRkymTuUuc=; b=Epq2Glryj3nI10DxfTFoOvl3Ue0oC/n98a0IKzZCxyit5hLJTJO1DtIVKa3B4306F1 m1lh0LwXk/rPaCX3yjhtGMrtB6JQI4vrLrb/EG0bow86yh+pFstuaG0pt/Fpz1bVNNqu myINi3GaJGIUe0S3Pp7FohIP68STf/QrXWseAQrQfJX3VNa4FvGGtjHlXb4CXX9YAKRq jV6bquDcvwYh48kx3efcGaRXpcvCMRxl6E9dYNd4CjeNRzA7bLy8u5d62XRaRFKKwQVq jlSqAy2k3JJt24CT7BCcyvAWOAw3W1bKHG7MJImd7ee4jmlDW4QvtcN4NCOIJDWjkXYL RMoA== X-Forwarded-Encrypted: i=1; AJvYcCVDYZ5wpbRWp9Bb2cje2E4Tr3YbxFNkgzinUETiyJ4CBU7yC3P0c3+A1zMQtpxCwFWUCnfV9Lz8wxAMF8A=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9syGE4PNaA8USKLFRAB0Hr30t/82lpZKCQBhUEAfOYe5Nc+6K /5pyMUAdDSV00ORGVxf5xOFuInKYThxr1b5jzHfqg1Q7Zjr07Brqht6RjpsI2lALK5vtvsH9nFi aedbas5dS5g== X-Google-Smtp-Source: AGHT+IHOGolbfyVik9GfL8FV0R1q7aR/DF1pW7wJKBvhtMirbEukdNxXMJ1WtmyaSH2UeJq4wnhjMPuIrobw X-Received: from dyjh23.prod.google.com ([2002:a05:7300:5617:b0:2a4:7a56:1730]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:4007:b0:2a4:3593:96a6 with SMTP id 5a478bee46e88-2ab92e8105amr1977090eec.35.1764798447380; Wed, 03 Dec 2025 13:47:27 -0800 (PST) Date: Wed, 3 Dec 2025 13:47:06 -0800 In-Reply-To: <20251203214706.112174-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251203214706.112174-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.177.g9f829587af-goog Message-ID: <20251203214706.112174-8-irogers@google.com> Subject: [PATCH v2 7/7] perf stat: Improve handling of termination by signal From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Thomas Richter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ingo Molnar Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When interrupting perf stat in repeat mode with a signal the signal is passed to the child process but the repeat doesn't terminate: ``` $ perf stat -v --null --repeat 10 sleep 1 Control descriptor is not initialized [ perf stat: executing run #1 ... ] [ perf stat: executing run #2 ... ] ^Csleep: Interrupt [ perf stat: executing run #3 ... ] [ perf stat: executing run #4 ... ] [ perf stat: executing run #5 ... ] [ perf stat: executing run #6 ... ] [ perf stat: executing run #7 ... ] [ perf stat: executing run #8 ... ] [ perf stat: executing run #9 ... ] [ perf stat: executing run #10 ... ] Performance counter stats for 'sleep 1' (10 runs): 0.9500 +- 0.0512 seconds time elapsed ( +- 5.39% ) 0.01user 0.02system 0:09.53elapsed 0%CPU (0avgtext+0avgdata 18940maxresiden= t)k 29944inputs+0outputs (0major+2629minor)pagefaults 0swaps ``` Terminate the repeated run and give a reasonable exit value: ``` $ perf stat -v --null --repeat 10 sleep 1 Control descriptor is not initialized [ perf stat: executing run #1 ... ] [ perf stat: executing run #2 ... ] [ perf stat: executing run #3 ... ] ^Csleep: Interrupt Performance counter stats for 'sleep 1' (10 runs): 0.680 +- 0.321 seconds time elapsed ( +- 47.16% ) Command exited with non-zero status 130 0.00user 0.01system 0:02.05elapsed 0%CPU (0avgtext+0avgdata 70688maxresiden= t)k 0inputs+0outputs (0major+5002minor)pagefaults 0swaps ``` Note, this also changes the exit value for non-repeat runs when interrupted by a signal. Reported-by: Ingo Molnar Closes: https://lore.kernel.org/lkml/aS5wjmbAM9ka3M2g@gmail.com/ Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index bd3c3de8d200..ab40d85fb125 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1007,10 +1007,20 @@ static int __run_perf_stat(int argc, const char **a= rgv, int run_idx) goto err_out; } =20 - if (WIFSIGNALED(status)) + if (WIFSIGNALED(status)) { + /* + * We want to indicate failure to stop a repeat run, + * hence negative. We want the value to be the exit code + * of perf, which for termination by a signal is 128 + * plus the signal number. + */ + err =3D 0 - (128 + WTERMSIG(status)); psignal(WTERMSIG(status), argv[0]); + } else { + err =3D WEXITSTATUS(status); + } } else { - status =3D dispatch_events(forks, timeout, interval, ×); + err =3D dispatch_events(forks, timeout, interval, ×); } =20 disable_counters(); @@ -1050,7 +1060,7 @@ static int __run_perf_stat(int argc, const char **arg= v, int run_idx) if (!STAT_RECORD) evlist__close(evsel_list); =20 - return WEXITSTATUS(status); + return err; =20 err_out: if (forks) @@ -2969,7 +2979,7 @@ int cmd_stat(int argc, const char **argv) evlist__reset_prev_raw_counts(evsel_list); =20 status =3D run_perf_stat(argc, argv, run_idx); - if (status =3D=3D -1) + if (status < 0) break; =20 if (forever && !interval) { @@ -3039,5 +3049,6 @@ int cmd_stat(int argc, const char **argv) =20 evlist__close_control(stat_config.ctl_fd, stat_config.ctl_fd_ack, &stat_c= onfig.ctl_fd_close); =20 - return status; + /* Only the low byte of status becomes the exit code. */ + return abs(status); } --=20 2.52.0.177.g9f829587af-goog