From nobody Tue Nov 26 15:40:04 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 468471DE3D3 for ; Thu, 17 Oct 2024 14:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729174196; cv=none; b=QW/1jCzAr3E0KN5AxlXZoU+XnFpr8N9MU5Cm2mOLnwo7fr1H06BXn23ZRch+yOW122IArLE8xgg9snaMCIzA1eOOVrddGTs6xJX9whH3d5HXOMp/c1TFgMpIVw88TF01/cXE1jQmkf0xeLFdiOXdu1+7aojiOcpIFxXmRdb0ufw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729174196; c=relaxed/simple; bh=xeLkTEKTNAT9sGDnDK9o2ilMhsBVyA9UijtR9xfjMfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=doK3FkR3TCquXSjTlatsIwW58QppnuNKrMBGz3ozr1ZJdOnucP12ZY9cl9g+Duv2uDDiKwXNOSOM+3ZVCMxYBfNotN7kD7ARULFddm79a4z5oYdv+7dtJF2ItUmgNkj286v0dRZ6/k6rvSFSz+pH6Cf4WrrdYnm1GYk126SS2kY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=T/hsT7dK; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="T/hsT7dK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729174194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JwYhkpHghGKHLaekKCNgK0lS740JHddsBSXXuOkvWNI=; b=T/hsT7dKtE5pW2H5pq/brFY9PyjONCXdOZqD+5NcVOjNvc3y5T7ZofkZ4VhOhYrTa47aYw 7SsKUJCvas8HYR5cS8gR9rAnB9DvVackBrMGkiJhZ6pyBAt8b1zKBnKUpRjBQs6OpoFTtI ZEKDkmwO7pRaKzx7PQPetfpxJ3KoIWI= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-256-A0xs7SFyN8W5863nr0UWJw-1; Thu, 17 Oct 2024 10:09:51 -0400 X-MC-Unique: A0xs7SFyN8W5863nr0UWJw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EB1391955EE6; Thu, 17 Oct 2024 14:09:49 +0000 (UTC) Received: from fedora.brq.redhat.com (unknown [10.43.17.159]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2765E19560AD; Thu, 17 Oct 2024 14:09:47 +0000 (UTC) From: tglozar@redhat.com To: rostedt@goodmis.org Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, jkacur@redhat.com, jwyatt@redhat.com, Tomas Glozar Subject: [PATCH v5 4/6] rtla/timerlat: Add --deepest-idle-state for top Date: Thu, 17 Oct 2024 16:09:12 +0200 Message-ID: <20241017140914.3200454-5-tglozar@redhat.com> In-Reply-To: <20241017140914.3200454-1-tglozar@redhat.com> References: <20241017140914.3200454-1-tglozar@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Content-Type: text/plain; charset="utf-8" From: Tomas Glozar Add option to limit deepest idle state on CPUs where timerlat is running for the duration of the workload. Signed-off-by: Tomas Glozar --- tools/tracing/rtla/src/timerlat_top.c | 42 ++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index 7fb85c8ee3bc..fca0da3caa87 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -48,6 +48,7 @@ struct timerlat_top_params { int pretty_output; int warmup; int buffer_size; + int deepest_idle_state; cpu_set_t hk_cpu_set; struct sched_attr sched_param; struct trace_events *events; @@ -447,7 +448,7 @@ static void timerlat_top_usage(char *usage) "", " usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us]= [-i us] [-T us] [-s us] \\", " [[-t[file]] [-e sys[:event]] [--filter ] [--trigger ] [-c cpu-list] [-H cpu-list]\\", - " [-P priority] [--dma-latency us] [--aa-only us] [-C[=3Dcgroup_name]]= [-u|-k] [--warm-up s]", + " [-P priority] [--dma-latency us] [--aa-only us] [-C[=3Dcgroup_name]]= [-u|-k] [--warm-up s] [--deepest-idle-state n]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argumen= t in us latency is hit", @@ -481,6 +482,7 @@ static void timerlat_top_usage(char *usage) " -U/--user-load: enable timerlat for user-defined user-space workload= ", " --warm-up s: let the workload run for s seconds before collecting= data", " --trace-buffer-size kB: set the per-cpu trace buffer size in kB", + " --deepest-idle-state n: only go down to idle state n on cpus used= by timerlat to reduce exit from idle latency", NULL, }; =20 @@ -518,6 +520,9 @@ static struct timerlat_top_params /* disabled by default */ params->dma_latency =3D -1; =20 + /* disabled by default */ + params->deepest_idle_state =3D -2; + /* display data in microseconds */ params->output_divisor =3D 1000; =20 @@ -550,6 +555,7 @@ static struct timerlat_top_params {"aa-only", required_argument, 0, '5'}, {"warm-up", required_argument, 0, '6'}, {"trace-buffer-size", required_argument, 0, '7'}, + {"deepest-idle-state", required_argument, 0, '8'}, {0, 0, 0, 0} }; =20 @@ -726,6 +732,9 @@ static struct timerlat_top_params case '7': params->buffer_size =3D get_llong_from_str(optarg); break; + case '8': + params->deepest_idle_state =3D get_llong_from_str(optarg); + break; default: timerlat_top_usage("Invalid option"); } @@ -922,6 +931,7 @@ int timerlat_top_main(int argc, char *argv[]) int return_value =3D 1; char *max_lat; int retval; + int nr_cpus, i; =20 params =3D timerlat_top_parse_args(argc, argv); if (!params) @@ -971,6 +981,28 @@ int timerlat_top_main(int argc, char *argv[]) } } =20 + if (params->deepest_idle_state >=3D -1) { + if (!have_libcpupower_support()) { + err_msg("rtla built without libcpupower, --deepest-idle-state is not su= pported\n"); + goto out_free; + } + + nr_cpus =3D sysconf(_SC_NPROCESSORS_CONF); + + for (i =3D 0; i < nr_cpus; i++) { + if (params->cpus && !CPU_ISSET(i, ¶ms->monitored_cpus)) + continue; + if (save_cpu_idle_disable_state(i) < 0) { + err_msg("Could not save cpu idle state.\n"); + goto out_free; + } + if (set_deepest_cpu_idle_state(i, params->deepest_idle_state) < 0) { + err_msg("Could not set deepest cpu idle state.\n"); + goto out_free; + } + } + } + if (params->trace_output) { record =3D osnoise_init_trace_tool("timerlat"); if (!record) { @@ -1125,6 +1157,13 @@ int timerlat_top_main(int argc, char *argv[]) timerlat_aa_destroy(); if (dma_latency_fd >=3D 0) close(dma_latency_fd); + if (params->deepest_idle_state >=3D -1) { + for (i =3D 0; i < nr_cpus; i++) { + if (params->cpus && !CPU_ISSET(i, ¶ms->monitored_cpus)) + continue; + restore_cpu_idle_disable_state(i); + } + } trace_events_destroy(&record->trace, params->events); params->events =3D NULL; out_free: @@ -1134,6 +1173,7 @@ int timerlat_top_main(int argc, char *argv[]) osnoise_destroy_tool(record); osnoise_destroy_tool(top); free(params); + free_cpu_idle_disable_states(); out_exit: exit(return_value); } --=20 2.47.0