Re: [PATCH] libtraceevent plugins: Add plugin_net to handle bswap during print
Steven Rostedt <[email protected]> Thu, 17 Apr 2025 10:58:38 -0400
| Newsgroups | org.kernel.vger.linux-trace-devel |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 17 Apr 2025 10:39:12 -0400 Petr Malat <[email protected]> wrote: > 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. Ah, I guess just swapping would always work. * If recorded on x86 and we have __builtin_bswap*() so that the number read into the buffer is not byte swapped, but should be when printed: If read: 0xaabbccdd, it would print: 0xddccbbaa But in the file, it is still how it was read (0xaabbccdd). Now if the trace.dat file is read on MIPS (BE), it would do the conversion when it reads the number: Reads 0xaabbccdd but then converts it to 0xddccbbaa, but since it's BE, that would be read as a number as: 0xaabbccdd. Then the print fmt would have __builtin_bswap32(), and then mips would convert the 0xddccbbaa into 0xaabbccdd, which being BE it would print: 0xddccbbaa By always swapping if the print_fmt says to swap, reading the x86 trace.dat on both x86 and BE MIPS, would produce the same: 0xddccbbaa. Then we would always need to swap. OK, forget my other suggestions, I think this should be fine. > > > > 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. Hmm, I didn't test it myself (just compiled it). -- Steve