[PATCH 1/2] pahole: Add --padding_ge N to show only structs with at least N bytes of padding at its end

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

Example usage:

  $ pahole --padding_ge 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>

One can combine with -x/--exclude to remove from the output common
patterns such as 'struct trace_event_' structs:

  $ pahole --with_flexible_array --padding_ge 4 --exclude trace_event_ | grep ^struct
  struct rseq {
  struct mem_cgroup {
  struct netprio_map {
  struct qdisc_size_table {
  struct sysinfo {
  struct ethtool_rxnfc {
  struct ioam6_schema {
  struct poll_list {
  struct posix_acl {
  struct proc_dir_entry {
  struct scsi_vpd {
  struct xsk_buff_pool {
  struct ieee80211_regdomain {
  struct watch_filter {
  struct landlock_rule {
  struct ghes_vendor_record_entry {
  struct packet_fanout {
  struct name_cache_entry {
  struct workqueue_struct {
  struct svc_deferred_req {
  struct cis_cache_entry {
  struct sem_undo {
  struct sidtab_str_cache {
  struct pcpu_chunk {
  struct pericom8250 {
  struct dm_name_list {
  struct linux_dirent64 {
  struct old_linux_dirent {
  struct linux_dirent {
  $

Cc: "Gustavo A. R. Silva" <gustavoars@xxxxxxxxxx>
Cc: Willy Tarreau <w@xxxxxx>
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
 man-pages/pahole.1 |  4 ++++
 pahole.c           | 12 +++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/man-pages/pahole.1 b/man-pages/pahole.1
index 0a9d8ac49fbf94d5..840f8e13807ba1be 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_ge=SIZE_PADDING
+Show only structs with at least SIZE_PADDING bytes of padding at its end.
+
 .TP
 .B \-I, \-\-show_decl_info
 Show the file and line number where the tags were defined, if available in
diff --git a/pahole.c b/pahole.c
index a33490d698ead7d5..56b0ca0c55993100 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_ge;
 static uint16_t nr_bit_holes;
 static uint16_t hole_size_ge;
 static uint8_t show_packable;
@@ -824,12 +825,13 @@ 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) ? NULL : class;
+		return (just_structs || show_packable || nr_holes || nr_bit_holes || hole_size_ge || end_padding_ge) ? NULL : class;
 
 	if (tag->top_level)
 		class__find_holes(class);
 
 	if (class->nr_holes < nr_holes ||
+	    class->padding < end_padding_ge ||
 	    class->nr_bit_holes < nr_bit_holes ||
 	    (hole_size_ge != 0 && !class__has_hole_ge(class, hole_size_ge)))
 		return NULL;
@@ -1239,6 +1241,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_contains_enumerator 344
 #define ARGP_reproducible_build 345
 #define ARGP_running_kernel_vmlinux 346
+#define ARG_PADDING_GE		   347
 
 /* --btf_features=feature1[,feature2,..] allows us to specify
  * a list of requested BTF features or "default" to enable all default
@@ -1494,6 +1497,12 @@ static const struct argp_option pahole__options[] = {
 		.arg  = "NR_HOLES",
 		.doc  = "show only structs with at least NR_HOLES holes",
 	},
+	{
+		.name = "padding_ge",
+		.key  = ARG_PADDING_GE,
+		.arg  = "SIZE_PADDING",
+		.doc  = "show only structs with at least SIZE_PADDING bytes padding at its end",
+	},
 	{
 		.name = "hole_size_ge",
 		.key  = 'z',
@@ -1885,6 +1894,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_GE: end_padding_ge = atoi(arg); break;
 	case 'I': conf.show_decl_info = 1;
 		  conf_load.extra_dbg_info = 1;		break;
 	case 'i': find_containers = 1;
-- 
2.46.0





[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux