From nobody Fri Jan 31 00:00:14 2025 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) (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 00FD41FCFC0 for ; Mon, 27 Jan 2025 09:59:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737971959; cv=none; b=Mss3I7+1S5aYT1Pmu6t0Sbo6dOWxJJ8cmrfrppf2XR9W4tzj3S6XgQ4P2RHJWEaCU7vVhjNdv4BSOrXAzWK+FPY8vLCnJHWn0q6mdagSEYlAysN9IJpwf7gkkP0tFjKr04Fe/t5BknOJwjW4ET/BzTB9nJOj/7tv0e0k4EglQXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737971959; c=relaxed/simple; bh=7Lwmz2qowc+FL2S348X3fs0ddxo5HZNQI1A8WhNfwmM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=B7Ig0KmhplWAWTU1y8GM26OAaNl6FaZpyPu17UZS4CuHGsL16mSgRDLVqFqnPp0dCVTzmfbVZkXoK1pPdAlszuWJxs5nfe0msNZjiPfOeBWE8w79x3bKbyQ/ssj728mg3o7xHztSmQ3CNLUmGc9FE8dtKS+yOqLM0klDKt7ghs0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dvyukov.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=23D0DEL1; arc=none smtp.client-ip=209.85.208.74 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--dvyukov.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="23D0DEL1" Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-5da0b47115aso4080816a12.1 for ; Mon, 27 Jan 2025 01:59:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737971956; x=1738576756; 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=wY6YjR33QYUTFA2QpzMQp9zL626GKLB+VcfcqXYl4og=; b=23D0DEL18KYt5Yqv75lVQiJyWNLsTiuhFGSinubLbFBwh4SiMTzHVAmAPRJp1FJKCD 946xU1laTwVZwJAXPdo8qTOugy2JCgRmcWcJUH5oX9pZNKmY1wV1Nq93plpNDCPzTQBW GJby9XqUhIVL9jqK28P8IgtkpsIPoerdoTxZz2/p2RWcm4yCeC43fAXfeodqsWOvLOMt eg5KK+O9owY4hpl2SYlIvd4W6SmP5KPlBgJJSRJXtdRXLFvngxiZI9qJIt9reBkq200H s4/oRAY4is4jkKkx/GbnSCo9/w4/rFNHmIvsB888S9vtUqs6FyvLumIxB2oBbrlar17H A28A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737971956; x=1738576756; 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=wY6YjR33QYUTFA2QpzMQp9zL626GKLB+VcfcqXYl4og=; b=ZctJcs+Jlt1SYNUAZ5vrPFb1/kKVL3kX5aCFIjrCl1to0AYpsRz+8D2f8jcpawRAsT bBHSUXvvYyc+FuSL8RHQR6dzAJHbXVjmjoVvOI6kErbugatW6o/7H01Onjwjf8i1rd4p VC22C83Zj9qNOhBee4cwl59hjO2JMCynUBgv73yfvJc+yATrrjVMO00y5+SwNKjAaxt8 5FrgnJlfCnMOjRZA6GF6RLABbN3Vz8jF4RMDPWqPAhXy1mbKrSfDHyslh/DxM5XucgQY AcJHm+RH4klRtvS2sRgDGCorYM/2QEgaFIdBMfBMuoSwvXakEvAZHQ0RsoetK3p31S1D NwiA== X-Forwarded-Encrypted: i=1; AJvYcCVMy9RJAR1Hu3Hjlo1IPDLd3r/Qic0nup/qH6ZBbGdHBTEDjkaJypeEAqXvqpteiEwc02sTPPXu8HYGhG0=@vger.kernel.org X-Gm-Message-State: AOJu0YwamWxarlYqGo5U0qpgiwGCfNMFCWThbfIRh50gHmPiN2OeG76J 2NQzXVAnWlcFSSj5yG5fJEcgk7ni1rWGzTf65ul/tuSg4FqjbnGecZPKFBzn022O4mIEVKuNfgy 8UAqAEw== X-Google-Smtp-Source: AGHT+IHWR5KT444/HwyTkeF8oEknrLW504GPADqAKXMZXiZu/CWtg9MudjXP4L1rx2P21ydNd5cATZPXKLPB X-Received: from edap3.prod.google.com ([2002:a05:6402:5003:b0:5dc:37ed:79fc]) (user=dvyukov job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:26c6:b0:5dc:545:40a7 with SMTP id 4fb4d7f45d1cf-5dc05454350mr17309711a12.12.1737971956452; Mon, 27 Jan 2025 01:59:16 -0800 (PST) Date: Mon, 27 Jan 2025 10:58:48 +0100 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <35860043ef3c4a25d36211853c3f2a6f83cd74b7.1737971364.git.dvyukov@google.com> Subject: [PATCH v3 1/7] perf report: Add machine parallelism From: Dmitry Vyukov To: namhyung@kernel.org, irogers@google.com Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Vyukov , Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add calculation of the current parallelism level (number of threads actively running on CPUs). The parallelism level can be shown in reports on its own, and to calculate latency overheads. Signed-off-by: Dmitry Vyukov Cc: Namhyung Kim Cc: Arnaldo Carvalho de Melo Cc: Ian Rogers Cc: linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- tools/perf/builtin-report.c | 1 + tools/perf/util/addr_location.c | 1 + tools/perf/util/addr_location.h | 2 ++ tools/perf/util/event.c | 3 +++ tools/perf/util/machine.c | 7 +++++++ tools/perf/util/machine.h | 6 ++++++ 6 files changed, 20 insertions(+) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index f5fbd670d619a..0d9bd090eda71 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -1568,6 +1568,7 @@ int cmd_report(int argc, const char **argv) report.tool.cgroup =3D perf_event__process_cgroup; report.tool.exit =3D perf_event__process_exit; report.tool.fork =3D perf_event__process_fork; + report.tool.context_switch =3D perf_event__process_switch; report.tool.lost =3D perf_event__process_lost; report.tool.read =3D process_read_event; report.tool.attr =3D process_attr; diff --git a/tools/perf/util/addr_location.c b/tools/perf/util/addr_locatio= n.c index 51825ef8c0ab7..007a2f5df9a6a 100644 --- a/tools/perf/util/addr_location.c +++ b/tools/perf/util/addr_location.c @@ -17,6 +17,7 @@ void addr_location__init(struct addr_location *al) al->cpumode =3D 0; al->cpu =3D 0; al->socket =3D 0; + al->parallelism =3D 1; } =20 /* diff --git a/tools/perf/util/addr_location.h b/tools/perf/util/addr_locatio= n.h index d8ac0428dff23..36aaa45445f24 100644 --- a/tools/perf/util/addr_location.h +++ b/tools/perf/util/addr_location.h @@ -21,6 +21,8 @@ struct addr_location { u8 cpumode; s32 cpu; s32 socket; + /* Same as machine.parallelism but within [1, nr_cpus]. */ + int parallelism; }; =20 void addr_location__init(struct addr_location *al); diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index aac96d5d19170..3d3ac58e1c660 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -767,6 +767,9 @@ int machine__resolve(struct machine *machine, struct ad= dr_location *al, al->socket =3D env->cpu[al->cpu].socket_id; } =20 + /* Account for possible out-of-order switch events. */ + al->parallelism =3D min(max(machine->parallelism, 1), machine__nr_cpus_av= ail(machine)); + if (al->map) { if (symbol_conf.dso_list && (!dso || !(strlist__has_entry(symbol_conf.dso_list, diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 2d51badfbf2e2..0e65c5377f983 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -94,6 +94,8 @@ int machine__init(struct machine *machine, const char *ro= ot_dir, pid_t pid) machine->comm_exec =3D false; machine->kernel_start =3D 0; machine->vmlinux_map =3D NULL; + /* There is no initial context switch in, so we start at 1. */ + machine->parallelism =3D 1; =20 machine->root_dir =3D strdup(root_dir); if (machine->root_dir =3D=3D NULL) @@ -677,8 +679,11 @@ int machine__process_aux_output_hw_id_event(struct mac= hine *machine __maybe_unus int machine__process_switch_event(struct machine *machine __maybe_unused, union perf_event *event) { + bool out =3D event->header.misc & PERF_RECORD_MISC_SWITCH_OUT; + if (dump_trace) perf_event__fprintf_switch(event, stdout); + machine->parallelism +=3D out ? -1 : 1; return 0; } =20 @@ -1900,6 +1905,8 @@ int machine__process_exit_event(struct machine *machi= ne, union perf_event *event if (dump_trace) perf_event__fprintf_task(event, stdout); =20 + /* There is no context switch out before exit, so we decrement here. */ + machine->parallelism--; if (thread !=3D NULL) { if (symbol_conf.keep_exited_threads) thread__set_exited(thread, /*exited=3D*/true); diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 2e5a4cb342d82..a5f28652873ce 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -50,6 +50,12 @@ struct machine { u64 text_start; u64 text_end; } sched, lock, traceiter, trace; + /* + * The current parallelism level (number of threads that run on CPUs). + * This value can be less than 1, or larger than the total number + * of CPUs, if events are poorly ordered. + */ + int parallelism; pid_t *current_tid; size_t current_tid_sz; union { /* Tool specific area */ --=20 2.48.1.262.g85cc9f2d1e-goog