From nobody Tue Dec 2 02:42:56 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 93C9631ED65 for ; Tue, 18 Nov 2025 21:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763500440; cv=none; b=K8TgXpsCgR4wyJAnIXMOY+TdhSKUXjxVJa5iIKBZQTK0cMdjhekiM4iv3YFgzk1jRB9SRLAA9C0b5vWRuie2y/qYAmgD2NN0BHS+gbAK0Ga+P05vldU1DjGmwQP3iqvd1cVItm49VluS77CoPTzs2labJqNzHu0ll2yE3Mib7Mk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763500440; c=relaxed/simple; bh=VEpT3v6RLJRFkj8ymYX48s+IRBrIsnUY0acR3wn+Eso=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=QyvFWoN4N2FHjUdmAQMbK5WQSX0BLgmuyhBK1hSbE6bxxDZ4nBHce4+sEaFVqKHEciuD9GOMxxBKTkh1paV95RHeJOc0uMlBS2ZdxmCDIQew097xK2B2UWNNXEuY/ok2of13LlUzgVkaUGH80QgiwfKtfNhXE3QdbZHBlh5nSOI= 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=xZhwNc1r; arc=none smtp.client-ip=209.85.215.202 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="xZhwNc1r" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b993eb2701bso5856122a12.0 for ; Tue, 18 Nov 2025 13:13:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763500438; x=1764105238; 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=/H5xzxd1i+W7d1YbcZd00dgpIJmb7baAkr21TY30fQQ=; b=xZhwNc1rAqfYNnZ2fJul0pyGNgU+ENI5ORWxiIe7Xdu0UT1pmKIFVMZdn9fYBl3ALj ghKh5A+yQuPhSAxiJq4uQq/p8GNZ3r+InGyJDQkahu8ca2RCOXkuS44Nn8jyxS3WPyN+ M2hpFQ5Zm68Q1uaZQnImlDr+Rd26CNooLOWuUefrmKujkrDPlPDycb4zp7ci1G0UQx6o M7u54xulYmSYxT/zgfVdJBOtz3ROPXz/YhGKaf7WFbZpnmAV/hPlguboKp4teN6h/F0I RJKsD8h033wbyK1+fj7q6iBvhBEMnaeBWTvtM+dyaYn+CAh6+3ddUURslCxE8A226kf8 gVSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763500438; x=1764105238; 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=/H5xzxd1i+W7d1YbcZd00dgpIJmb7baAkr21TY30fQQ=; b=YS+Ug91i7Gdm1BUjX3kKQBMyDtnnLOIbixlaW5+VhKH5CrT3fSPNhABK2wNwmaAHHV 3PXeNUGl63SN1+qu83Cm8UyAI0zsgLX+z7M0GO5QVJaklvTJ03e+k96jhKMYl5md2urr rNcGiI0b3NQUKhW7C+BW1h1sTRCPmWJIUgchMht+/L3SpwBySM4rAIhHmmZR1yDFzpeA GZziXTVEEUIpA+u/J9C7H4iF1WWEzrhQMP/UAV3rPSE+z+/1nc1E6vnsW1px2228TlaL UKfb/5fl7/+tUBAriY9kwZZBHH+viw/FbS4wkHA3KIeGFSYL91rzmY9jb6nCltg2RZYg jydg== X-Forwarded-Encrypted: i=1; AJvYcCVp48qMh5X57+BI/qGNH3OiIXF9cjWPqiLYvJdQooU/oQ7MiMzIYlkMLwj0pTL6PpnnLUCN+lro9c39Jto=@vger.kernel.org X-Gm-Message-State: AOJu0YwuxpHdnoX3tQNvPDm1a8pxtP758SPaOXa/htNuDD53O2ZEyD9S p8YPFZkb80Tw+c7IwuFQ2I71VrzpyO/xe/J4/YPoHmaCM54y2S+/671JDe+UjGFz/a7K84vBcGA znDUd/Modug== X-Google-Smtp-Source: AGHT+IGbvg38YhDssyfKkYHn/snXNT9UvFEofmzb4xmuUEiykWtfWmAMNadvzY7zVR7Qj4GyH+waQLA+HD0Y X-Received: from dycns6.prod.google.com ([2002:a05:7300:f786:b0:2a6:a0f0:d7bd]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:f292:b0:2a4:6df3:b95b with SMTP id 5a478bee46e88-2a4abb2612emr5957465eec.19.1763500437789; Tue, 18 Nov 2025 13:13:57 -0800 (PST) Date: Tue, 18 Nov 2025 13:13:26 -0800 In-Reply-To: <20251118211326.1840989-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: <20251118211326.1840989-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251118211326.1840989-4-irogers@google.com> Subject: [PATCH v5 3/3] 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 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 aec93b91fd11..709e4bcea398 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2415,6 +2415,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"), @@ -2543,6 +2544,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)", @@ -2600,6 +2603,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 b6df81b8a236..53c8e974de8b 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -368,11 +368,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 b4604c3f03d6..c7ba0e0b2219 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.52.0.rc1.455.g30608eb744-goog