From nobody Mon Feb 9 14:32:01 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 7F1EF3093D7 for ; Fri, 6 Feb 2026 22:25:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770416726; cv=none; b=WzTSX1oEouFI1OVIuyxDtRwpbe5jGC+f3RPCJQYEx9CDh+sK8eBI8ek3nfak4uEy0EiMMRzLu114DR9lpACCg5rdsyvXl9zJT2x4TjngWv3ZQNZw3AG6M9FaEHU+GsVDUDeLIhoJ9/FC3EBwu6g8Xl1ELfxaYKNkcMHgpSSW1ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770416726; c=relaxed/simple; bh=4dzqlAY6Jwfn5UZRMxqibkJ/WzReutE/CulfgusKL0g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XqlQY/CVItPLLdP5eeALJV2cX6bQmvIQRUEW0BbR0QwHxp7Xizod1hPczhHj2g20+sYc+RwtIAOp5ym/yxYRAgOADVteiZPEGgCNR7kn3oWzkb6qv5uXsnoQOP5qIIhWI0IB+kXzz/nsfpEYY6GMqDg3uNQx7tp9icS4isNnCE8= 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=jKyI1YMZ; arc=none smtp.client-ip=74.125.82.73 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="jKyI1YMZ" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-124a95d580cso19959535c88.1 for ; Fri, 06 Feb 2026 14:25:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770416726; x=1771021526; 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=wNGV+9W9psENt274mz6PMhj6c8c5MewbEM3NGZmHhlM=; b=jKyI1YMZU8KbTKscOXZfdYZu4iM6Y+wucv0aNSVZL2q667YcK6+dF92c3RMhRV9W2m qOmtvaD0ur+uLDDJN7xT9sNbS6Lz305e8BrSOCGvIBsj0hjgI0kSnuiPD7ofOnyruFDL RDf6U+eX54DrEdc8Yiz10Ou80TQTSxNoN6q6z3DV5nxhELEGbe3HApZNgHIPO/eHWOnJ pmNXCv2DUqa00yeJWgecuN2uRHV6ThHRXOhzomMbNQGI2cYPVbQNhsgY3TQ2Kf/wQwXY wC7c9W5oGUIPFJCc/tcICBsyPJfrpZQaRUyhaBcpxTpth3LSKysbWip+4SWbBYW9W1BV xpEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770416726; x=1771021526; 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=wNGV+9W9psENt274mz6PMhj6c8c5MewbEM3NGZmHhlM=; b=BoX4xzhJWZU24mhipPBp8u2DHYjWmu6Cu03rR9FenFdXMudUVDJM6pYBb7+Kki5dnX g7qVUQ24RLDWdO2brMpUL7dcHPjP34hjcYO2XafzhrQeWIffXA1aoyClv7f9gX3xsL5H 3kLmzlVDaWMhztrvLD0lAWJTIcTE89i0THSf0WdRAs9JhZCutSwKaQ9iO+XU6CcGehj8 f/TbI4Pkcz+bC9643zpQPGvqI+YQ3NOcks7fQUGO1+P4WDfJwKVgvBLgC6JfwJzhZivl CbGGu6A+IzVu6HVfLncnlviSHuO37wRo60dGXP1JK6Ek9RCfzGopL7inc3VoxHDngG5d 6TMg== X-Forwarded-Encrypted: i=1; AJvYcCWhANnEuKXW9S1lEpQcoZkMWLU/IzI0XgOi8WJfyLZRsFWM1UpMJs2r8fBe6bCt5yRWQ2I2a4Q0KE5OnUk=@vger.kernel.org X-Gm-Message-State: AOJu0YwWdG9S5jPAYt0a053urv5iDbibP4sLW7FKsWMkMq9/LZjOASEY Jeu6k07SgKn3xuqNr9BcfWyv0sH7t5ZfDHlg6ETc4g4XVHrjTyLh5gtFSJd9t3Q9r/0incYCELy txzDq2NUi9Q== X-Received: from dlbur6-n2.prod.google.com ([2002:a05:7022:ea46:20b0:127:c76:21ec]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:618f:b0:11b:9386:a3cc with SMTP id a92af1059eb24-1270419f22amr1886234c88.45.1770416725561; Fri, 06 Feb 2026 14:25:25 -0800 (PST) Date: Fri, 6 Feb 2026 14:25:09 -0800 In-Reply-To: <20260206222509.982489-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: <20260206222509.982489-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260206222509.982489-7-irogers@google.com> Subject: [PATCH v8 6/6] perf stat: Add no-affinity flag From: Ian Rogers To: acme@kernel.org Cc: adrian.hunter@intel.com, ak@linux.intel.com, alexander.shishkin@linux.intel.com, andres@anarazel.de, dapeng1.mi@linux.intel.com, irogers@google.com, james.clark@linaro.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org, thomas.falcon@intel.com, tmricht@linux.ibm.com, yang.lee@linux.alibaba.com 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