linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtla: Set /dev/cpu_dma_latency to avoid exit from idle latencies
@ 2022-02-23 18:37 Daniel Bristot de Oliveira
  2022-03-01 20:59 ` Daniel Bristot de Oliveira
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Bristot de Oliveira @ 2022-02-23 18:37 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Daniel Bristot de Oliveira, linux-kernel, linux-trace-devel

Set /dev/cpu_dma_latency to 0 to avoid having exit from idle
states latencies influencing in the analysis.

Cc: Daniel Bristot de Oliveira <bristot@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
---
 tools/tracing/rtla/src/timerlat_hist.c | 10 ++++++++
 tools/tracing/rtla/src/timerlat_top.c  | 10 ++++++++
 tools/tracing/rtla/src/utils.c         | 33 ++++++++++++++++++++++++++
 tools/tracing/rtla/src/utils.h         |  1 +
 4 files changed, 54 insertions(+)

diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c
index 237e1735afa7..3c0108ff63ab 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -732,6 +732,7 @@ int timerlat_hist_main(int argc, char *argv[])
 	struct osnoise_tool *record = NULL;
 	struct osnoise_tool *tool = NULL;
 	struct trace_instance *trace;
+	int dma_latency_fd = -1;
 	int return_value = 1;
 	int retval;
 
@@ -767,6 +768,13 @@ int timerlat_hist_main(int argc, char *argv[])
 		}
 	}
 
+	/*
+	 * Avoid going into deep idle states.
+	 */
+	dma_latency_fd = set_cpu_dma_latency(0);
+	if (dma_latency_fd < 0)
+		err_msg("Could not set /dev/cpu_dma_latency to 0. Long IRQ latencies expected\n");
+
 	trace_instance_start(trace);
 
 	if (params->trace_output) {
@@ -812,6 +820,8 @@ int timerlat_hist_main(int argc, char *argv[])
 	}
 
 out_hist:
+	if (dma_latency_fd >= 0)
+		close(dma_latency_fd);
 	timerlat_free_histogram(tool->data);
 	osnoise_destroy_tool(record);
 	osnoise_destroy_tool(tool);
diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c
index d4187f6534ed..f4bca0ad5de3 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -524,6 +524,7 @@ int timerlat_top_main(int argc, char *argv[])
 	struct osnoise_tool *record = NULL;
 	struct osnoise_tool *top = NULL;
 	struct trace_instance *trace;
+	int dma_latency_fd = -1;
 	int return_value = 1;
 	int retval;
 
@@ -559,6 +560,13 @@ int timerlat_top_main(int argc, char *argv[])
 		}
 	}
 
+	/*
+	 * Avoid going into deep idle states.
+	 */
+	dma_latency_fd = set_cpu_dma_latency(0);
+	if (dma_latency_fd < 0)
+		err_msg("Could not set /dev/cpu_dma_latency. Long IRQ latencies expected.\n");
+
 	trace_instance_start(trace);
 
 	if (params->trace_output) {
@@ -608,6 +616,8 @@ int timerlat_top_main(int argc, char *argv[])
 	}
 
 out_top:
+	if (dma_latency_fd >= 0)
+		close(dma_latency_fd);
 	timerlat_free_top(top->data);
 	osnoise_destroy_tool(record);
 	osnoise_destroy_tool(top);
diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
index ffaf8ec84001..da2b590edaed 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <sched.h>
 #include <stdio.h>
 
@@ -431,3 +432,35 @@ int parse_prio(char *arg, struct sched_attr *sched_param)
 	}
 	return 0;
 }
+
+/*
+ * set_cpu_dma_latency - set the /dev/cpu_dma_latecy
+ *
+ * This is used to reduce the exit from idle latency. The value
+ * will be reset once the file descriptor of /dev/cpu_dma_latecy
+ * is closed.
+ *
+ * Return: the /dev/cpu_dma_latecy file descriptor
+ */
+int set_cpu_dma_latency(int32_t latency)
+{
+	int retval;
+	int fd;
+
+	fd = open("/dev/cpu_dma_latency", O_RDWR);
+	if (fd < 0) {
+		err_msg("Error opening /dev/cpu_dma_latency\n");
+		return -1;
+	}
+
+	retval = write(fd, &latency, 4);
+	if (retval < 1) {
+		err_msg("Error setting /dev/cpu_dma_latency\n");
+		close(fd);
+		return -1;
+	}
+
+	debug_msg("Set /dev/cpu_dma_latency to %d\n", latency);
+
+	return fd;
+}
diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h
index 9aa962319ca2..fa08e374870a 100644
--- a/tools/tracing/rtla/src/utils.h
+++ b/tools/tracing/rtla/src/utils.h
@@ -54,3 +54,4 @@ struct sched_attr {
 
 int parse_prio(char *arg, struct sched_attr *sched_param);
 int set_comm_sched_attr(const char *comm, struct sched_attr *attr);
+int set_cpu_dma_latency(int32_t latency);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] rtla: Set /dev/cpu_dma_latency to avoid exit from idle latencies
  2022-02-23 18:37 [PATCH] rtla: Set /dev/cpu_dma_latency to avoid exit from idle latencies Daniel Bristot de Oliveira
@ 2022-03-01 20:59 ` Daniel Bristot de Oliveira
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Bristot de Oliveira @ 2022-03-01 20:59 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-kernel, linux-trace-devel

On 2/23/22 19:37, Daniel Bristot de Oliveira wrote:
> Set /dev/cpu_dma_latency to 0 to avoid having exit from idle
> states latencies influencing in the analysis.
> 

Sending a v2 of this patch together with a new version of rtla features patch
series.

-- Daniel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-01 20:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23 18:37 [PATCH] rtla: Set /dev/cpu_dma_latency to avoid exit from idle latencies Daniel Bristot de Oliveira
2022-03-01 20:59 ` Daniel Bristot de Oliveira

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).