public inbox for linux-trace-devel@vger.kernel.org
 help / color / mirror / Atom feed
* trace-cmd: question about explicit host endianness setting
@ 2025-12-23 14:42 Wenjun Huo
  2025-12-23 20:49 ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Wenjun Huo @ 2025-12-23 14:42 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Wenjun Huo

Dear Tracers,

While reading the trace-cmd code, I noticed a detail in
tracecmd_alloc_fd() regarding endianness handling and wanted to
double-check my understanding.

In tracecmd_alloc_fd(), after tep_alloc() and plugin loading,
trace-cmd explicitly sets both file and local endianness:

tep_set_file_bigendian(handle->pevent, buf[0]);
tep_set_local_bigendian(handle->pevent, tracecmd_host_bigendian());

I understand that setting the file endianness here is required,
since it is read from the trace file header.

For the local/host endianness, tep_alloc() already initializes
host_bigendian via tep_is_bigendian(), and in the common case
tracecmd_host_bigendian() resolves to the same value. So in practice
this explicit call usually does not change the value.

My understanding is that this is intentional, and that the call to
tep_set_local_bigendian() serves as an explicit binding step, making
it clear that trace-cmd confirms the local execution endianness
after parsing the trace header and loading plugins, rather than
relying on tep_alloc() defaults.

Could you please confirm if this interpretation is correct, and
whether this explicit setting is mainly for clarity / defensive API
usage rather than functional necessity?

If maintainers think there is a better way to clarify or improve
this behavior (for example via comments, documentation, or code
adjustments), I would be very happy to help by preparing and sending
a patch based on your guidance.

Thanks for your time.

Best regards,
Wenjun Huo


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

* Re: trace-cmd: question about explicit host endianness setting
  2025-12-23 14:42 trace-cmd: question about explicit host endianness setting Wenjun Huo
@ 2025-12-23 20:49 ` Steven Rostedt
  2025-12-25  4:52   ` Wenjun Huo
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2025-12-23 20:49 UTC (permalink / raw)
  To: Wenjun Huo; +Cc: linux-trace-devel

On Tue, 23 Dec 2025 22:42:21 +0800
Wenjun Huo <huowenjun.dev@gmail.com> wrote:

> Dear Tracers,
> 
> While reading the trace-cmd code, I noticed a detail in
> tracecmd_alloc_fd() regarding endianness handling and wanted to
> double-check my understanding.
> 
> In tracecmd_alloc_fd(), after tep_alloc() and plugin loading,
> trace-cmd explicitly sets both file and local endianness:
> 
> tep_set_file_bigendian(handle->pevent, buf[0]);
> tep_set_local_bigendian(handle->pevent, tracecmd_host_bigendian());
> 
> I understand that setting the file endianness here is required,
> since it is read from the trace file header.
> 
> For the local/host endianness, tep_alloc() already initializes
> host_bigendian via tep_is_bigendian(), and in the common case
> tracecmd_host_bigendian() resolves to the same value. So in practice
> this explicit call usually does not change the value.
> 
> My understanding is that this is intentional, and that the call to
> tep_set_local_bigendian() serves as an explicit binding step, making
> it clear that trace-cmd confirms the local execution endianness
> after parsing the trace header and loading plugins, rather than
> relying on tep_alloc() defaults.
> 
> Could you please confirm if this interpretation is correct, and
> whether this explicit setting is mainly for clarity / defensive API
> usage rather than functional necessity?

Nope, it's simply due to legacy and the evolution of software. Sort of why
we still have an appendix ;-)

If you look at trace-cmd commit cd001f7b40f9d ("Add handler to pevent
functions") [ from 2009! ] it has:

+       handle->pevent = pevent_alloc();
+       if (!handle->pevent)
+               goto failed_read;
+
+       handle->pevent->file_bigendian = buf[0];
+       handle->pevent->host_bigendian = bigendian();
 
Where at that time, pevent_alloc() was simply:

struct tep_handle *pevent_alloc(void)
{
        struct tep_handle *pevent = calloc(1, sizeof(*pevent));

        if (pevent)
                pevent->ref_count = 1;

        return pevent;
}

and trace-cmd had to set the file and host endianess.

But since then, libtraceevent renamed pevent_alloc() to tep_alloc() and
initialized the host_bigendian.

trace-cmd was updated to simply keep the original code but modified to have
the new APIs.

> 
> If maintainers think there is a better way to clarify or improve
> this behavior (for example via comments, documentation, or code
> adjustments), I would be very happy to help by preparing and sending
> a patch based on your guidance.

In reality, the line:

	tep_set_local_bigendian(handle->pevent, tracecmd_host_bigendian());

is obsolete, and probably could just be deleted.

If you want to send that patch feel free, or I can simply remove it.

Thanks for your curiosity of looking at this code ;-)

-- Steve

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

* Re: trace-cmd: question about explicit host endianness setting
  2025-12-23 20:49 ` Steven Rostedt
@ 2025-12-25  4:52   ` Wenjun Huo
  0 siblings, 0 replies; 3+ messages in thread
From: Wenjun Huo @ 2025-12-25  4:52 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-trace-devel, Wenjun Huo

Hi Steven,

Thanks for the detailed explanation and historical context!

I'll prepare a patch to remove the obsolete tep_set_local_bigendian() call
from tracecmd_alloc_fd() and submit it to the list.

Best regards,
Wenjun Huo

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

end of thread, other threads:[~2025-12-25  4:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-23 14:42 trace-cmd: question about explicit host endianness setting Wenjun Huo
2025-12-23 20:49 ` Steven Rostedt
2025-12-25  4:52   ` Wenjun Huo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox