All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Willy Tarreau <w@1wt.eu>
Cc: dwarves@vger.kernel.org, Alan Maguire <alan.maguire@oracle.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Clark Williams <williams@redhat.com>,
	Kate Carcia <kcarcia@redhat.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>
Subject: [PATCH 2/2] pahole: Add --padding N to show only structs with N bytes of padding at its end
Date: Fri, 27 Sep 2024 15:59:58 -0300	[thread overview]
Message-ID: <20240927185958.37310-3-acme@kernel.org> (raw)
In-Reply-To: <20240927185958.37310-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Example usage:

  $ pahole --padding 4 --with_flexible_array
  <SNIP>
  struct netprio_map {
          struct callback_head       rcu;                  /*     0    16 */
          u32                        priomap_len;          /*    16     4 */
          u32                        priomap[];            /*    20     0 */

          /* size: 24, cachelines: 1, members: 3 */
          /* padding: 4 */
          /* last cacheline: 24 bytes */
  };
  <SNIP>

Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Willy Tarreau <w@1wt.eu>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 man-pages/pahole.1 | 4 ++++
 pahole.c           | 7 ++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/man-pages/pahole.1 b/man-pages/pahole.1
index 840f8e13807ba1be..b3e6632bdbf6b561 100644
--- a/man-pages/pahole.1
+++ b/man-pages/pahole.1
@@ -223,6 +223,10 @@ Find pointers to CLASS_NAME.
 .B \-H, \-\-holes=NR_HOLES
 Show only structs with at least NR_HOLES holes.
 
+.TP
+.B \-\-padding=SIZE_PADDING
+Show only structs with SIZE_PADDING bytes of padding at its end.
+
 .TP
 .B \-\-padding_ge=SIZE_PADDING
 Show only structs with at least SIZE_PADDING bytes of padding at its end.
diff --git a/pahole.c b/pahole.c
index 56b0ca0c55993100..780f0c4eacfe2ee8 100644
--- a/pahole.c
+++ b/pahole.c
@@ -60,6 +60,7 @@ static char *decl_exclude_prefix;
 static size_t decl_exclude_prefix_len;
 
 static uint16_t nr_holes;
+static uint16_t end_padding;
 static uint16_t end_padding_ge;
 static uint16_t nr_bit_holes;
 static uint16_t hole_size_ge;
@@ -825,7 +826,8 @@ static struct class *class__filter(struct class *class, struct cu *cu,
 	 * that need finding holes, like --packable, --nr_holes, etc
 	 */
 	if (!tag__is_struct(tag))
-		return (just_structs || show_packable || nr_holes || nr_bit_holes || hole_size_ge || end_padding_ge) ? NULL : class;
+		return (just_structs || show_packable || nr_holes || nr_bit_holes || hole_size_ge ||
+			end_padding_ge || end_padding) ? NULL : class;
 
 	if (tag->top_level)
 		class__find_holes(class);
@@ -833,6 +835,7 @@ static struct class *class__filter(struct class *class, struct cu *cu,
 	if (class->nr_holes < nr_holes ||
 	    class->padding < end_padding_ge ||
 	    class->nr_bit_holes < nr_bit_holes ||
+	    (end_padding != 0 && class->padding != end_padding) ||
 	    (hole_size_ge != 0 && !class__has_hole_ge(class, hole_size_ge)))
 		return NULL;
 
@@ -1242,6 +1245,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_reproducible_build 345
 #define ARGP_running_kernel_vmlinux 346
 #define ARG_PADDING_GE		   347
+#define ARG_PADDING		   348
 
 /* --btf_features=feature1[,feature2,..] allows us to specify
  * a list of requested BTF features or "default" to enable all default
@@ -1894,6 +1898,7 @@ static error_t pahole__options_parser(int key, char *arg,
 		  class_name = arg;			break;
 	case 'F': conf_load.format_path = arg;		break;
 	case 'H': nr_holes = atoi(arg);			break;
+	case ARG_PADDING: end_padding = atoi(arg);	break;
 	case ARG_PADDING_GE: end_padding_ge = atoi(arg); break;
 	case 'I': conf.show_decl_info = 1;
 		  conf_load.extra_dbg_info = 1;		break;
-- 
2.46.0


  parent reply	other threads:[~2024-09-27 19:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-27 18:59 [PATCH 0/2] --padding option to combine with --with_flexible_array Arnaldo Carvalho de Melo
2024-09-27 18:59 ` [PATCH 1/2] pahole: Add --padding_ge N to show only structs with at least N bytes of padding at its end Arnaldo Carvalho de Melo
2024-09-27 18:59 ` Arnaldo Carvalho de Melo [this message]
2024-09-27 19:22 ` [PATCH 0/2] --padding option to combine with --with_flexible_array Gustavo A. R. Silva
2024-09-27 19:39   ` Arnaldo Carvalho de Melo
2024-09-27 20:08     ` Gustavo A. R. Silva
2024-09-27 21:15 ` Willy Tarreau
2024-09-28  4:36   ` Willy Tarreau
2024-09-30 14:32     ` Arnaldo Carvalho de Melo

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=20240927185958.37310-3-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=alan.maguire@oracle.com \
    --cc=dwarves@vger.kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=kcarcia@redhat.com \
    --cc=w@1wt.eu \
    --cc=williams@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.