linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maximilian Luz <luzmaximilian@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rob Herring" <robh@kernel.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Blaž Hrastnik" <blaz@mxxn.io>,
	"Dorian Stoll" <dorian.stoll@tmsp.io>
Subject: Re: [RFC PATCH 4/9] surface_aggregator: Add trace points
Date: Thu, 24 Sep 2020 01:43:08 +0200	[thread overview]
Message-ID: <dad57e7f-7f3c-7fea-0fbf-a32006da52b6@gmail.com> (raw)
In-Reply-To: <20200923160757.51e773a0@oasis.local.home>

On 9/23/20 10:07 PM, Steven Rostedt wrote:
> On Wed, 23 Sep 2020 17:15:06 +0200
> Maximilian Luz <luzmaximilian@gmail.com> wrote:
> 
>> Add trace points to the Surface Aggregator subsystem core. These trace
>> points can be used to track packets, requests, and allocations. They are
>> further intended for debugging and testing/validation, specifically in
>> combination with the error injection capabilities introduced in the
>> subsequent commit.
> 
> I'm impressed! This uses some of the advanced features of the tracing
> infrastructure. But I still have some comments to make about the layout
> of the TP_STRUCT__entry() fields.

Thanks!

[...]

>> +DECLARE_EVENT_CLASS(ssam_packet_class,
>> +	TP_PROTO(const struct ssh_packet *packet),
>> +
>> +	TP_ARGS(packet),
>> +
>> +	TP_STRUCT__entry(
>> +		__array(char, uid, SSAM_PTR_UID_LEN)
>> +		__field(u8, priority)
>> +		__field(u16, length)
>> +		__field(unsigned long, state)
>> +		__field(u16, seq)
> 
> 
> Order matters above to keep the events as compact as possible. The more
> compact they are, the more events you can store without loss.
> 
> Now with SSAM_PTR_UID_LEN = 9, the above is (on a 64 bit system);
> 
> 	9 bytes;
> 	1 byte;
> 	2 bytes;
> 	8 bytes;
> 	2 bytes;
> 
> The ftrace ring buffer is 4 byte aligned. As words and long words are
> also 4 byte aligned, there's not much different to change. But it is
> possible that the compiler might add 4 byte padding between the long
> word "length" and "priority". Note, these are not packed structures.
> 
> Testing this out with the following code:
> 
>   $ cat << EOF > test.c
> struct test {
> 	unsigned char array[9];
> 	unsigned char priority;
> 	unsigned short length;
> 	unsigned long state;
> 	unsigned short seq;
> };
> 
> static struct test x;
> 
> void receive_x(struct test *p)
> {
> 	p = &x;
> }
> EOF
> 
>   $ gcc -g -c -o test.o test.c
>   $ pahole test.o
> struct test {
> 	unsigned char              array[9];             /*     0     9 */
> 	unsigned char              priority;             /*     9     1 */
> 	short unsigned int         length;               /*    10     2 */
> 
> 	/* XXX 4 bytes hole, try to pack */
> 
> 	long unsigned int          state;                /*    16     8 */
> 	short unsigned int         seq;                  /*    24     2 */
> 
> 	/* size: 32, cachelines: 1, members: 5 */
> 	/* sum members: 22, holes: 1, sum holes: 4 */
> 	/* padding: 6 */
> 	/* last cacheline: 32 bytes */
> };
> 
> You do see a hole between length and state. Now if we were to move this
> around a little.
> 
>   $ cat <<EOF > test2.c
> struct test {
> 	unsigned long state;
> 	unsigned char array[9];
> 	unsigned char priority;
> 	unsigned short length;
> 	unsigned short seq;
> };
> 
> static struct test x;
> 
> void receive_x(struct test *p)
> {
> 	p = &x;
> }
> EOF
> 
>   $ gcc -g -c -o test2 test2.c
>   $ pahole test2.o
> struct test {
> 	long unsigned int          state;                /*     0     8 */
> 	unsigned char              array[9];             /*     8     9 */
> 	unsigned char              priority;             /*    17     1 */
> 	short unsigned int         length;               /*    18     2 */
> 	short unsigned int         seq;                  /*    20     2 */
> 
> 	/* size: 24, cachelines: 1, members: 5 */
> 	/* padding: 2 */
> 	/* last cacheline: 24 bytes */
> };
> 
> 
> We get a more compact structure with:
> 
> 	TP_STRUCT__entry(
> 		__field(unsigned long, state)
> 		__array(char, uid, SSAM_PTR_UID_LEN)
> 		__field(u8, priority)
> 		__field(u16, length)
> 		__field(u16, seq)
> 	),
> 
> 
> Note, you can find pahole here:
> 
>     https://git.kernel.org/pub/scm/devel/pahole/pahole.git
> 
> 
>> +	),

Thank you for that detailed write-up! As you have clearly noticed, I
have not really looked at the struct layouts. I will fix this for v2,
include your changes, and have a look at pahole.

[...]

Thanks,
Max

  reply	other threads:[~2020-09-23 23:43 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23 15:15 [RFC PATCH 0/9] Add support for Microsoft Surface System Aggregator Module Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 2/9] surface_aggregator: Add control packet allocation chaching Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 3/9] surface_aggregator: Add event item " Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 4/9] surface_aggregator: Add trace points Maximilian Luz
2020-09-23 20:07   ` Steven Rostedt
2020-09-23 23:43     ` Maximilian Luz [this message]
2020-09-23 15:15 ` [RFC PATCH 5/9] surface_aggregator: Add error injection capabilities Maximilian Luz
2020-09-23 17:45   ` Greg Kroah-Hartman
2020-09-23 21:28     ` Maximilian Luz
2020-09-23 15:15 ` [RFC PATCH 7/9] docs: driver-api: Add Surface Aggregator subsystem documentation Maximilian Luz
2020-09-23 15:30 ` [RFC PATCH 0/9] Add support for Microsoft Surface System Aggregator Module Arnd Bergmann
2020-09-23 15:43   ` Maximilian Luz
2020-09-23 19:43     ` Arnd Bergmann
2020-09-23 23:28       ` Maximilian Luz
2020-09-24  8:26         ` Arnd Bergmann
2020-09-24 18:59           ` Maximilian Luz
2020-09-24 19:38             ` Arnd Bergmann
2020-09-24 21:07               ` Maximilian Luz
2020-09-25 14:53               ` Andy Shevchenko
2020-09-24  8:30   ` Andy Shevchenko
2020-09-24 19:17     ` Maximilian Luz
2020-09-25 14:58       ` Andy Shevchenko
2020-09-25 15:41         ` Maximilian Luz
     [not found] ` <20200923151511.3842150-2-luzmaximilian@gmail.com>
2020-09-23 16:57   ` [RFC PATCH 1/9] misc: Add Surface Aggregator subsystem Greg Kroah-Hartman
2020-09-23 20:34     ` Maximilian Luz
2020-09-24  6:48       ` Greg Kroah-Hartman
2020-09-24 18:16         ` Maximilian Luz

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=dad57e7f-7f3c-7fea-0fbf-a32006da52b6@gmail.com \
    --to=luzmaximilian@gmail.com \
    --cc=arnd@arndb.de \
    --cc=blaz@mxxn.io \
    --cc=dorian.stoll@tmsp.io \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=rostedt@goodmis.org \
    /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;
as well as URLs for NNTP newsgroup(s).