Re: [PATCH] libtraceevent plugins: Add plugin_net to handle bswap during print

Petr Malat <[email protected]> Thu, 17 Apr 2025 10:39:12 -0400
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <CANMuvJkUM7m7byL0bRfe2eBb5wB8vhaMV7qzGpTymQ75Rxn0Uw@mail.gmail.com>
On Thu, Apr 17, 2025 at 07:49:00AM -0400, Steven Rostedt wrote:
> On Thu, 17 Apr 2025 05:06:44 -0400
> Petr Malat <[email protected]> wrote:
>
> > Sorry for the late reply, I tested my patch on mips, arm, arm64 and x86 and
> > it works everywhere, but for arm64 I had to add extra functions, because
> > it doesn't use the GCC __builin for swapping bytes. I have extended the
> > plugin and will send a new version.
> >
> > On mips using network order ntohs (and similar) expands to a cast only, so
> > the call to swap is not present.
>
> So if you record on x86 and read it on mips (or other big endian machines)
> does it produce the correct output? What about recording on mips and then
> reading it on x86?
Yes, it works (mips is BE):
 - when trace is taken on mips, then ntohs expands to a cast and there is no
   __builin_bswap in the print format. When that trace is read, it's then
   handled as any other number. So on mips nothing is done and on x86 bytes
   are swapped to translate the number to native ordering.
 - when trace is taken on x86, then ntohs expands to byte swapping. When that
   trace is read on x86 it's swapped and correctly printed. When it's read
   on mips it's swapped twice - once when read due to different endianess and
   then again due to bswap in print format and again the correct value
is printed.


> That is, do a "trace-cmd record" on a bigendian or little endian machine,
> then copying the trace.dat file to a machine with the opposite endian, and
> seeing if it still produces the correct output?
>
> BTW, libtraceevent also provides its own swap functions so if the GCC
> builtin is not always available, then it should use that instead.
>
>   See the "tep_data2host*()" fuctions.
>
> But that may need to be updated as "tep_swapbytes*()" and have:
>
> 	if (!tep || tep->host_bigendian != tep->file_bigendian)
> 		return data;
>
For some reason I was not able to get your patch working, it always prints
zeroes instead actual value. I tried to fix it, but no luck, only found copy
and paste error where you swap 64-bit int as 16-bit. If you want I can share
some example trace.dat files.

I will send my updated patch as a separate mail.
BR,
  Petr