Linux Trace Kernel
 help / color / mirror / Atom feed
From: Tomas Glozar <tglozar@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>, Tomas Glozar <tglozar@redhat.com>
Cc: John Kacur <jkacur@redhat.com>,
	Luis Goncalves <lgoncalv@redhat.com>,
	Crystal Wood <crwood@redhat.com>,
	Costa Shulyupin <costa.shul@redhat.com>,
	Wander Lairson Costa <wander@redhat.com>,
	linux-trace-kernel <linux-trace-kernel@vger.kernel.org>
Subject: [RFC PATCH 07/10] rtla/trace: Allow storing start clock value of tracefs instances
Date: Fri, 27 Nov 2026 16:32:03 +0100	[thread overview]
Message-ID: <20261127153206.134322-8-tglozar@redhat.com> (raw)
In-Reply-To: <20261127153206.134322-1-tglozar@redhat.com>

Add a per-CPU start_ts array to struct trace_instance, allocated and
freed with the instance, and helpers to save the current clock into it
and to copy it between instances.

Signed-off-by: Tomas Glozar <tglozar@redhat.com>
---
 tools/tracing/rtla/src/trace.c | 36 ++++++++++++++++++++++++++++++++++
 tools/tracing/rtla/src/trace.h |  4 ++++
 2 files changed, 40 insertions(+)

diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c
index a007479768f99..1885219cdb589 100644
--- a/tools/tracing/rtla/src/trace.c
+++ b/tools/tracing/rtla/src/trace.c
@@ -200,6 +200,11 @@ void trace_instance_destroy(struct trace_instance *trace)
 		tep_free(trace->tep);
 		trace->tep = NULL;
 	}
+
+	if (trace->start_ts) {
+		free(trace->start_ts);
+		trace->start_ts = NULL;
+	}
 }
 
 /*
@@ -219,6 +224,8 @@ int trace_instance_init(struct trace_instance *trace, char *tool_name)
 
 	trace_seq_init(trace->seq);
 
+	trace->start_ts = calloc_fatal(nr_cpus, sizeof(*trace->start_ts));
+
 	trace->inst = create_instance(tool_name);
 	if (!trace->inst)
 		goto out_err;
@@ -276,6 +283,35 @@ int trace_instance_clear(struct trace_instance *trace)
 	return tracefs_instance_file_write(trace->inst, "trace", "");
 }
 
+/*
+ * trace_instance_save_start - save the start timestamp of a given instance
+ * @trace: the trace instance
+ * @cpus: the set of CPUs to read
+ *
+ * Read the current timestamp of each CPU in @cpus and store it in the
+ * instance's start_ts array. Must be called before tracing is enabled.
+ *
+ * Returns 0 on success, -1 if any CPU could not be read.
+ */
+int trace_instance_save_start(struct trace_instance *trace, const cpu_set_t *cpus)
+{
+	return trace_get_now_ts_cpus(trace->inst, cpus, trace->start_ts);
+}
+
+/*
+ * trace_instance_copy_start - copy the start timestamps between instances
+ * @dst: the destination trace instance
+ * @src: the source trace instance
+ *
+ * The per-CPU clock is not tied to a trace instance, so the timestamps
+ * captured for one instance are valid for every other instance as well.
+ */
+void trace_instance_copy_start(struct trace_instance *dst,
+			       const struct trace_instance *src)
+{
+	memcpy(dst->start_ts, src->start_ts, nr_cpus * sizeof(*src->start_ts));
+}
+
 /*
  * trace_get_cpu_now_ts - get the current timestamp of a CPU
  * @inst: the trace instance, NULL for the top instance
diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h
index ad9eaaa61b77a..5a3cdb14f86a7 100644
--- a/tools/tracing/rtla/src/trace.h
+++ b/tools/tracing/rtla/src/trace.h
@@ -19,6 +19,7 @@ struct trace_instance {
 	struct tracefs_instance		*inst;
 	struct tep_handle		*tep;
 	struct trace_seq		*seq;
+	unsigned long long		*start_ts;
 	unsigned long long		missed_events;
 	unsigned long long		invalid_events;
 	unsigned long long		processed_events;
@@ -28,6 +29,9 @@ int trace_instance_init(struct trace_instance *trace, char *tool_name);
 int trace_instance_start(struct trace_instance *trace);
 int trace_instance_stop(struct trace_instance *trace);
 int trace_instance_clear(struct trace_instance *trace);
+int trace_instance_save_start(struct trace_instance *trace, const cpu_set_t *cpus);
+void trace_instance_copy_start(struct trace_instance *dst,
+			       const struct trace_instance *src);
 void trace_instance_destroy(struct trace_instance *trace);
 
 struct trace_seq *get_trace_seq(void);
-- 
2.56.1


  parent reply	other threads:[~2026-11-27 15:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 15:31 [RFC PATCH 00/10] rtla/timerlat: Add auto-analysis action and report spike timestamps Tomas Glozar
2026-11-27 15:31 ` [RFC PATCH 01/10] rtla: Support auto-analysis as an action Tomas Glozar
2026-11-27 15:31 ` [RFC PATCH 02/10] rtla/tests: Add unit tests for aa action Tomas Glozar
2026-11-27 15:31 ` [RFC PATCH 03/10] rtla/tests: Add runtime " Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 04/10] Documentation/rtla: Document " Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 05/10] rtla/trace: Add helper to read "now ts" stats field Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 06/10] rtla/trace: Add helper to gather "now ts" over a CPU set Tomas Glozar
2026-11-27 15:32 ` Tomas Glozar [this message]
2026-11-27 15:32 ` [RFC PATCH 08/10] rtla/timerlat: Save the trace clock at measurement start Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 09/10] rtla/timerlat_aa: Print time offset and seqnum of the spike Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 10/10] Documentation/rtla: Document auto-analysis timestamps Tomas Glozar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127153206.134322-8-tglozar@redhat.com \
    --to=tglozar@redhat.com \
    --cc=costa.shul@redhat.com \
    --cc=crwood@redhat.com \
    --cc=jkacur@redhat.com \
    --cc=lgoncalv@redhat.com \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=wander@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox