From nobody Mon Feb 9 21:18:51 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 A3B0037F75C for ; Tue, 3 Feb 2026 22:51:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770159115; cv=none; b=VI44ivggZ9D6Ibf+OgwthqZ+upJWwL5xzeAp3OGKgyY0tZ+ZIjEZD9P9eW8dusm1xT9aJe80dmdAJRrPjb8b9mA5Bave3qyhknx/1C25INZO/8eHIkfwaikDpwh0QhlzQqCiZdjrNnzjm09LeDZBYn8qDdDmK+g7SwgNNO+mT3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770159115; c=relaxed/simple; bh=4dzqlAY6Jwfn5UZRMxqibkJ/WzReutE/CulfgusKL0g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=nrl27Eiz3Hboq5j9Lt+iOsrWCR1EkqKR2IDXUbG+EOjwxifsXmnnYtOgx9XX4ranIgnv3HvC6QIxK7Ky/Ir5xNU6Hut/6A2o7eHqplCmp47jpldHuD08LpJdMksw/+7MUKk/8p27wi65BiBFONfMTNx5YotkVXlIwW9+JOI+mT4= 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=sj8H1v7R; arc=none smtp.client-ip=209.85.210.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="sj8H1v7R" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-81f53036ac9so118169b3a.3 for ; Tue, 03 Feb 2026 14:51:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770159113; x=1770763913; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=wNGV+9W9psENt274mz6PMhj6c8c5MewbEM3NGZmHhlM=; b=sj8H1v7RTkZ2CjP69ZBd+bKMeopp7+up9Fz+sQELAW4vZIjYMEB92bgCSfe9q3+HLW 2iis+PSQe3jhdpPkz09dm91gJW8PFEW/aa/o0va1vv9I/wiyr2HATuhtdH1P8Xe+EAHG nqn5p+PDmC1QNzidWeQjfjc6JBGkt6AXVRkVsMIUFyn8Gnv9JNhJCzSF9W2yErpOQYLk 3S8zgJSLPo2Q5TeHheg2mPAtn10D1Xm+vqFfnGqOm5qSIH+DvAh1tZWkkjJv2MUd1rTr yAcSvLA3KTE3CD3qUqaTdbfBtN4783iwcx4XSzlJ9pcXMhQubKN/2dnQC6nOZnCxQn51 5ZLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770159113; x=1770763913; h=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=wNGV+9W9psENt274mz6PMhj6c8c5MewbEM3NGZmHhlM=; b=dY1WU+AIfcxnV6H/Q2w4fcRZWXZkTmRWY0/ieR9+BcYK/j0sTHplDIhApr6EfRLigK R5/d+47UEzLy4+O4HX0rldS0qz4/xxOPrECbMkwPWWjVZ+6qQ4mS80WcS5axz0tvkDjG MkqYgf3WMaNeS7laDDVd/Jr4Jbcsy+jMhsqLAnxlYbGJGS1s30tBSKGWGzPn84NPe+0+ hm3UZh1ehUV9B6Op3RHDPTOCVY8WJ99/7PyB+KkHRBHDs1Ld/5IbiCnHE1Rxq6noDIMk pBubAd8HsH3UbqKoOzVrJfwbD6XUA2yullhUIU4UyPcL2B1zv7Uh0k1qDPT3Jxt+y3iG hjEA== X-Forwarded-Encrypted: i=1; AJvYcCVtILMqQGhcnbj7YbMr6zrG8at3+h68MpgRKP1zQeTjTUa41cLEQKRndkc505yVhk33IjnWdKBltrPHW1M=@vger.kernel.org X-Gm-Message-State: AOJu0YzvGAdVLAgKOcDtS5G+kvfye9S708Cv4fFE8NrAxpR/dlEu3Yl0 Q/LJp8DvinPCk4A4BkVnzHgsn4St2CEaxs70BLgfgGxqZXpZ8oR1YNCUt5BEpFm/+h8fSWEi8L8 Zt9lYmdJxnA== X-Received: from pfjg11.prod.google.com ([2002:a05:6a00:b8b:b0:81f:7db9:83d5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1709:b0:81c:5694:c544 with SMTP id d2e1a72fcca58-8241c637192mr908753b3a.56.1770159112816; Tue, 03 Feb 2026 14:51:52 -0800 (PST) Date: Tue, 3 Feb 2026 14:51:29 -0800 In-Reply-To: <20260203225129.4077140-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: <20260203225129.4077140-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260203225129.4077140-7-irogers@google.com> Subject: [PATCH v7 6/6] perf stat: Add no-affinity flag From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Dr. David Alan Gilbert" , Yang Li , James Clark , Thomas Falcon , Thomas Richter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Andi Kleen , Dapeng Mi , Andres Freund Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add flag that disables affinity behavior. Using sched_setaffinity to place a perf thread on a CPU can avoid certain interprocessor interrupts but may introduce a delay due to the scheduling, particularly on loaded machines. Add a command line option to disable the behavior. This behavior is less present in other tools like `perf record`, as it uses a ring buffer and doesn't make repeated system calls. Signed-off-by: Ian Rogers --- tools/perf/Documentation/perf-stat.txt | 4 ++++ tools/perf/builtin-stat.c | 6 ++++++ tools/perf/util/evlist.c | 6 +----- tools/perf/util/evlist.h | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentat= ion/perf-stat.txt index 1a766d4a2233..1ffb510606af 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -382,6 +382,10 @@ color the metric's computed value. Don't print output, warnings or messages. This is useful with perf stat record below to only write data to the perf.data file. =20 +--no-affinity:: +Don't change scheduler affinities when iterating over CPUs. Disables +an optimization aimed at minimizing interprocessor interrupts. + STAT RECORD ----------- Stores stat data into perf data file. diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index c1bb40b99176..8bbdea44c3ba 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2426,6 +2426,7 @@ static int parse_tpebs_mode(const struct option *opt,= const char *str, int cmd_stat(int argc, const char **argv) { struct opt_aggr_mode opt_mode =3D {}; + bool affinity =3D true, affinity_set =3D false; struct option stat_options[] =3D { OPT_BOOLEAN('T', "transaction", &transaction_run, "hardware transaction statistics"), @@ -2554,6 +2555,8 @@ int cmd_stat(int argc, const char **argv) "don't print 'summary' for CSV summary output"), OPT_BOOLEAN(0, "quiet", &quiet, "don't print any output, messages or warnings (useful with record)"), + OPT_BOOLEAN_SET(0, "affinity", &affinity, &affinity_set, + "don't allow affinity optimizations aimed at reducing IPIs"), OPT_CALLBACK(0, "cputype", &evsel_list, "hybrid cpu type", "Only enable events on applying cpu with this type " "for hybrid platform (e.g. core or atom)", @@ -2611,6 +2614,9 @@ int cmd_stat(int argc, const char **argv) } else stat_config.csv_sep =3D DEFAULT_SEPARATOR; =20 + if (affinity_set) + evsel_list->no_affinity =3D !affinity; + if (argc && strlen(argv[0]) > 2 && strstarts("record", argv[0])) { argc =3D __cmd_record(stat_options, &opt_mode, argc, argv); if (argc < 0) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 45833244daf3..591bdf0b3e2a 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -369,11 +369,7 @@ static bool evlist__use_affinity(struct evlist *evlist) struct perf_cpu_map *used_cpus =3D NULL; bool ret =3D false; =20 - /* - * With perf record core.user_requested_cpus is usually NULL. - * Use the old method to handle this for now. - */ - if (!evlist->core.user_requested_cpus || + if (evlist->no_affinity || !evlist->core.user_requested_cpus || cpu_map__is_dummy(evlist->core.user_requested_cpus)) return false; =20 diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 30dff7484d3c..d17c3b57a409 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -59,6 +59,7 @@ struct event_enable_timer; struct evlist { struct perf_evlist core; bool enabled; + bool no_affinity; int id_pos; int is_pos; int nr_br_cntr; --=20 2.53.0.rc2.204.g2597b5adb4-goog