Skip to contentSkip to conversation

dwarves print: Cacheline accounting fixes

PATCH In review Jiri Olsa 3 participants 11 messages Dec 8, 2015 – Dec 17, 2015 7 messages not in the archive

lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

cover dwarves print: Cacheline accounting fixes

hi,
hit 2 issues when used pahole
- sometimes it did not account the hole between variables
- when using -E to extract inner struct, cacheline boundaries were wrong

with this patchset I was able to get it work on structs that I was investigating, but I'm not sure I covered all parts or fixed it in proper way.

thanks,
jirka

---
Jiri Olsa (3):
dwarves print: Fix holes accounting
dwarves print: Pass into struct conf_fprintf class__fprintf_cacheline_boundary dwarves print: Keep global cacheline in struct conf_fprintf

 dwarves.h         |  1 +
 dwarves_fprintf.c | 45 ++++++++++++++++++++++++++-------------------
 2 files changed, 27 insertions(+), 19 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1449614826-2278-1-git-send-email-jolsa-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

author
#2 lore raw

PATCH 1/3 dwarves print: Fix holes accounting

Sometimes the hole could be missing, try to bypass this issue by comparing last and current offsets.

---
 dwarves_fprintf.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
dwarves_fprintf.c +11 -0
index 71d8ce9f982b..df80af255c67 100644
@@ -1268,6 +1268,17 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 		}
 		pos = tag__class_member(tag_pos);
 
+		/*
+		 * Sometimes the hole could be missing, try to bypass
+		 * this issue by comparing last and current offsets.
+		 */
+		if (last) {
+			uint32_t tmp = last->byte_offset + last->byte_size + last->hole;
+
+			if (pos->byte_offset > tmp)
+				sum_holes += pos->byte_offset - tmp;
+		}
+
 		if (last != NULL &&
 		    pos->byte_offset != last->byte_offset &&
 		    !cconf.suppress_comments)
Signature · 6 lines
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1449614826-2278-2-git-send-email-jolsa-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#4 lore raw

Re: [PATCH 1/3] dwarves print: Fix holes accounting

Em Tue, Dec 08, 2015 at 11:47:04PM +0100, Jiri Olsa escreveu:

Quoted 2 lines

Sometimes the hole could be missing, try to bypass this issue by comparing last and current offsets.

Can you provide an example of before and after this change? What real case triggered this?

- Arnaldo

Quoted 34 lines
---
 dwarves_fprintf.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
dwarves_fprintf.c +11 -0
index 71d8ce9f982b..df80af255c67 100644
@@ -1268,6 +1268,17 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 		}
 		pos = tag__class_member(tag_pos);
 
+		/*
+		 * Sometimes the hole could be missing, try to bypass
+		 * this issue by comparing last and current offsets.
+		 */
+		if (last) {
+			uint32_t tmp = last->byte_offset + last->byte_size + last->hole;
+
+			if (pos->byte_offset > tmp)
+				sum_holes += pos->byte_offset - tmp;
+		}
+
 		if (last != NULL &&
 		    pos->byte_offset != last->byte_offset &&
 		    !cconf.suppress_comments)
Signature · 6 lines
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [PATCH 1/3] dwarves print: Fix holes accounting

Em Wed, Dec 16, 2015 at 02:58:39PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 22 lines

Em Tue, Dec 08, 2015 at 11:47:04PM +0100, Jiri Olsa escreveu:

Quoted 2 lines

Sometimes the hole could be missing, try to bypass this issue by comparing last and current offsets.

Can you provide an example of before and after this change? What real case triggered this?

- Arnaldo

Quoted 13 lines
---
 dwarves_fprintf.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
dwarves_fprintf.c +0 -0
index 71d8ce9f982b..df80af255c67 100644
@@ -1268,6 +1268,17 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 		}
 		pos = tag__class_member(tag_pos);
 
Quoted 11 lines

dwarves_fprintf.c size_t class__fprintf(struct class *class, const struct cu *cu, · line 1281

Quoted 11 lines
dwarves_fprintf.c +11 -0
+		/*
+		 * Sometimes the hole could be missing, try to bypass
+		 * this issue by comparing last and current offsets.
+		 */
+		if (last) {
+			uint32_t tmp = last->byte_offset + last->byte_size + last->hole;
+
+			if (pos->byte_offset > tmp)
+				sum_holes += pos->byte_offset - tmp;
+		}
+

I mean, how could this be? last->hole then would have been wrong, miscalculated, looking at where it is calculated now...

- arnaldo

Quoted 10 lines
Quoted 10 lines
dwarves_fprintf.c +0 -0
 		if (last != NULL &&
 		    pos->byte_offset != last->byte_offset &&
 		    !cconf.suppress_comments)
Signature · 6 lines
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [PATCH 1/3] dwarves print: Fix holes accounting

Em Wed, Dec 16, 2015 at 03:05:32PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 7 lines

Em Wed, Dec 16, 2015 at 02:58:39PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 6 lines

Em Tue, Dec 08, 2015 at 11:47:04PM +0100, Jiri Olsa escreveu:

Quoted 2 lines

Sometimes the hole could be missing, try to bypass this issue by comparing last and current offsets.

Can you provide an example of before and after this change? What real case triggered this?

<SNIP>

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+++ b/dwarves_fprintf.c

dwarves_fprintf.c +0 -0
@@ -1268,6 +1268,17 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 		}
 		pos = tag__class_member(tag_pos);
 
Quoted 13 lines
Quoted 10 lines

dwarves_fprintf.c size_t class__fprintf(struct class *class, const struct cu *cu, · line 1280

Quoted 10 lines
dwarves_fprintf.c +10 -0
+		/*
+		 * Sometimes the hole could be missing, try to bypass
+		 * this issue by comparing last and current offsets.
+		 */
+		if (last) {
+			uint32_t tmp = last->byte_offset + last->byte_size + last->hole;
+
+			if (pos->byte_offset > tmp)
+				sum_holes += pos->byte_offset - tmp;
+		}

I mean, how could this be? last->hole then would have been wrong, miscalculated, looking at where it is calculated now...

Yeah, class__find_holes() should have properly calculated last->hole so that (last->byte_offset + last->byte_size + last->hole) == pos->byte_offset.

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe dwarves" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#9 lore raw

PATCH 2/3 dwarves print: Pass into struct conf_fprintf class__fprintf_cacheline_boundary

In reply to a message not in the archive

Passing into struct conf_fprintf class__fprintf_cacheline_boundary, so the next patch is more easy to read.

---
 dwarves_fprintf.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
dwarves_fprintf.c +5 -4
index df80af255c67..2d114210831a 100644
@@ -1122,7 +1122,8 @@ static size_t class__fprintf_cacheline_boundary(uint32_t last_cacheline,
 						size_t sum, size_t sum_holes,
 						uint8_t *newline,
 						uint32_t *cacheline,
-						int indent, FILE *fp)
+						struct conf_fprintf *cconf,
+						FILE *fp)
 {
 	const size_t real_sum = sum + sum_holes;
 	size_t printed = 0;
@@ -1139,7 +1140,7 @@ static size_t class__fprintf_cacheline_boundary(uint32_t last_cacheline,
 			++printed;
 		}
 
-		printed += fprintf(fp, "%.*s", indent, tabs);
+		printed += fprintf(fp, "%.*s", cconf->indent, tabs);
 
 		if (cacheline_pos == 0)
 			printed += fprintf(fp, "/* --- cacheline %u boundary "
@@ -1287,7 +1288,7 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 							      sum, sum_holes,
 							      &newline,
 							      &last_cacheline,
-							      cconf.indent,
+							      &cconf,
 							      fp);
 		/*
 		 * These paranoid checks doesn't make much sense on
@@ -1477,7 +1478,7 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 							     sum, sum_holes,
 							     &newline,
 							     &last_cacheline,
-							     cconf.indent, fp);
+							     &cconf, fp);
 	if (!cconf.show_only_data_members)
 		class__vtable_fprintf(class, cu, &cconf, fp);
 
Signature · 6 lines
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1449614826-2278-3-git-send-email-jolsa-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#11 lore raw

Re: [PATCH 2/3] dwarves print: Pass into struct conf_fprintf class__fprintf_cacheline_boundary

Em Tue, Dec 08, 2015 at 11:47:05PM +0100, Jiri Olsa escreveu:

Quoted 2 lines

Passing into struct conf_fprintf class__fprintf_cacheline_boundary, so the next patch is more easy to read.

"Passing struct conf_fprintf to class__fprintf_cacheline_boundary(), so the next patch is more easy to read."

?

Quoted 53 lines
---
 dwarves_fprintf.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
dwarves_fprintf.c +5 -4
index df80af255c67..2d114210831a 100644
@@ -1122,7 +1122,8 @@ static size_t class__fprintf_cacheline_boundary(uint32_t last_cacheline,
 						size_t sum, size_t sum_holes,
 						uint8_t *newline,
 						uint32_t *cacheline,
-						int indent, FILE *fp)
+						struct conf_fprintf *cconf,
+						FILE *fp)
 {
 	const size_t real_sum = sum + sum_holes;
 	size_t printed = 0;
@@ -1139,7 +1140,7 @@ static size_t class__fprintf_cacheline_boundary(uint32_t last_cacheline,
 			++printed;
 		}
 
-		printed += fprintf(fp, "%.*s", indent, tabs);
+		printed += fprintf(fp, "%.*s", cconf->indent, tabs);
 
 		if (cacheline_pos == 0)
 			printed += fprintf(fp, "/* --- cacheline %u boundary "
@@ -1287,7 +1288,7 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 							      sum, sum_holes,
 							      &newline,
 							      &last_cacheline,
-							      cconf.indent,
+							      &cconf,
 							      fp);
 		/*
 		 * These paranoid checks doesn't make much sense on
@@ -1477,7 +1478,7 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 							     sum, sum_holes,
 							     &newline,
 							     &last_cacheline,
-							     cconf.indent, fp);
+							     &cconf, fp);
 	if (!cconf.show_only_data_members)
 		class__vtable_fprintf(class, cu, &cconf, fp);
 
Signature · 6 lines
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw

Re: [PATCH 2/3] dwarves print: Pass into struct conf_fprintf class__fprintf_cacheline_boundary

Quoted 8 lines · Arnaldo Carvalho de Melo

Em Tue, Dec 08, 2015 at 11:47:05PM +0100, Jiri Olsa escreveu:

Quoted 2 lines

Passing into struct conf_fprintf class__fprintf_cacheline_boundary, so the next patch is more easy to read.

"Passing struct conf_fprintf to class__fprintf_cacheline_boundary(), so the next patch is more easy to read."

?

exactly ;-)

jirka
--
To unsubscribe from this list: send the line "unsubscribe dwarves" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#14 lore raw

PATCH 3/3 dwarves print: Keep global cacheline in struct conf_fprintf

In reply to a message not in the archive

Together with adding cconf->base_offset to sums used for cacheline computation, this ensures proper cacheline number to be printed for nested struct. Note possitions of 'cacheline' lines in following outputs.

Before:

  $ pahole -C task_struct -E ~/kernel/linux-perf-local/vmlinux
  struct task_struct {
        volatile long int          state;                                                /*     0     8 */
        --- First cacheline is ok

        struct task_struct *       last_wakee;                                           /*    56     8 */
        /* --- cacheline 1 boundary (64 bytes) --- */
        int                        wake_cpu;                                             /*    64     4 */

        ...

        const struct sched_class  * sched_class;                                         /*    88     8 */
        struct sched_entity {
                struct load_weight {
                        long unsigned int weight;                                        /*    96     8 */
                        /* typedef u32 */ unsigned int inv_weight;                       /*   104     4 */
                } load; /*    96    16 */

                --- Second one is still in relative mode and gives wrong
                    alignment in wrt task_struct start

                unsigned int       on_rq;                                                /*   152     4 */
                /* --- cacheline 1 boundary (64 bytes) --- */
                /* typedef u64 */ long long unsigned int exec_start;                     /*   160     8 */
                /* typedef u64 */ long long unsigned int sum_exec_runtime;               /*   168     8 */
       ...

After:

  $ pahole -C task_struct -E ~/kernel/linux-perf-local/vmlinux
   struct task_struct {
        volatile long int          state;                                                /*     0     8 */
        --- First cacheline is ok

        struct task_struct *       last_wakee;                                           /*    56     8 */
        /* --- cacheline 1 boundary (64 bytes) --- */
        int                        wake_cpu;                                             /*    64     4 */

        ...

        const struct sched_class  * sched_class;                                         /*    88     8 */
        struct sched_entity {
                struct load_weight {
                        long unsigned int weight;                                        /*    96     8 */
                        /* typedef u32 */ unsigned int inv_weight;                       /*   104     4 */
                } load; /*    96    16 */
                struct rb_node {
                        long unsigned int __rb_parent_color;                             /*   112     8 */
                        struct rb_node * rb_right;                                       /*   120     8 */
                        /* --- cacheline 2 boundary (128 bytes) --- */
                        struct rb_node * rb_left;                                        /*   128     8 */
                } run_node; /*   112    24 */

                --- Second one is still in relative mode and gives wrong
                    alignment in wrt task_struct start

                /* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */
                struct list_head {
                        struct list_head * next;                                         /*   136     8 */
                        struct list_head * prev;                                         /*   144     8 */
                } group_node; /*   136    16 */
       ...
---
 dwarves.h         |  1 +
 dwarves_fprintf.c | 25 ++++++++++---------------
 2 files changed, 11 insertions(+), 15 deletions(-)
dwarves.h +1 -0
index 73fec8ac614a..44ebf8384b9c 100644
@@ -56,6 +56,7 @@ struct conf_fprintf {
 	int32_t	   type_spacing;
 	int32_t	   name_spacing;
 	uint32_t   base_offset;
+	uint32_t   base_cacheline;
 	uint8_t	   indent;
 	uint8_t	   expand_types:1;
 	uint8_t	   expand_pointers:1;
dwarves_fprintf.c +10 -15
index 2d114210831a..72d8b08bf235 100644
@@ -1118,22 +1118,21 @@ size_t function__fprintf_stats(const struct tag *tag, const struct cu *cu,
 	return printed + fprintf(fp, " */\n");
 }
 
-static size_t class__fprintf_cacheline_boundary(uint32_t last_cacheline,
-						size_t sum, size_t sum_holes,
+static size_t class__fprintf_cacheline_boundary(size_t sum, size_t sum_holes,
 						uint8_t *newline,
-						uint32_t *cacheline,
 						struct conf_fprintf *cconf,
 						FILE *fp)
 {
-	const size_t real_sum = sum + sum_holes;
+	const size_t real_sum = sum + sum_holes + cconf->base_offset;
 	size_t printed = 0;
+	uint32_t cacheline = real_sum / cacheline_size;
 
-	*cacheline = real_sum / cacheline_size;
-
-	if (*cacheline > last_cacheline) {
+	if (cacheline != cconf->base_cacheline) {
 		const uint32_t cacheline_pos = real_sum % cacheline_size;
 		const uint32_t cacheline_in_bytes = real_sum - cacheline_pos;
 
+		cconf->base_cacheline = cacheline;
+
 		if (*newline) {
 			fputc('\n', fp);
 			*newline = 0;
@@ -1144,12 +1143,12 @@ static size_t class__fprintf_cacheline_boundary(uint32_t last_cacheline,
 
 		if (cacheline_pos == 0)
 			printed += fprintf(fp, "/* --- cacheline %u boundary "
-					   "(%u bytes) --- */\n", *cacheline,
+					   "(%u bytes) --- */\n", cacheline,
 					   cacheline_in_bytes);
 		else
 			printed += fprintf(fp, "/* --- cacheline %u boundary "
 					   "(%u bytes) was %u bytes ago --- "
-					   "*/\n", *cacheline,
+					   "*/\n", cacheline,
 					   cacheline_in_bytes, cacheline_pos);
 	}
 	return printed;
@@ -1284,10 +1283,8 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 		    pos->byte_offset != last->byte_offset &&
 		    !cconf.suppress_comments)
 			printed +=
-			    class__fprintf_cacheline_boundary(last_cacheline,
-							      sum, sum_holes,
+			    class__fprintf_cacheline_boundary(sum, sum_holes,
 							      &newline,
-							      &last_cacheline,
 							      &cconf,
 							      fp);
 		/*
@@ -1474,10 +1471,8 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 	}
 
 	if (!cconf.suppress_comments)
-		printed += class__fprintf_cacheline_boundary(last_cacheline,
-							     sum, sum_holes,
+		printed += class__fprintf_cacheline_boundary(sum, sum_holes,
 							     &newline,
-							     &last_cacheline,
 							     &cconf, fp);
 	if (!cconf.show_only_data_members)
 		class__vtable_fprintf(class, cu, &cconf, fp);
Signature · 6 lines
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1449614826-2278-4-git-send-email-jolsa-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#16 lore raw

Re: [PATCH 3/3] dwarves print: Keep global cacheline in struct conf_fprintf

Em Tue, Dec 08, 2015 at 11:47:06PM +0100, Jiri Olsa escreveu:

Quoted 25 lines

Together with adding cconf->base_offset to sums used for cacheline computation, this ensures proper cacheline number to be printed for nested struct. Note possitions of 'cacheline' lines in following outputs.

Before:

  $ pahole -C task_struct -E ~/kernel/linux-perf-local/vmlinux
  struct task_struct {
        volatile long int          state;                                                /*     0     8 */

--- First cacheline is ok

struct task_struct * last_wakee; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
int wake_cpu; /* 64 4 */

...

const struct sched_class * sched_class; /* 88 8 */
struct sched_entity {
struct load_weight {
long unsigned int weight; /* 96 8 */
/* typedef u32 */ unsigned int inv_weight; /* 104 4 */
} load; /* 96 16 */

Quoted 5 lines

--- Second one is still in relative mode and gives wrong
alignment in wrt task_struct start

unsigned int on_rq; /* 152 4 */
/* --- cacheline 1 boundary (64 bytes) --- */

Ok, this is a bug...

Quoted 20 lines
                /* typedef u64 */ long long unsigned int exec_start;                     /*   160     8 */
                /* typedef u64 */ long long unsigned int sum_exec_runtime;               /*   168     8 */
       ...

After:

  $ pahole -C task_struct -E ~/kernel/linux-perf-local/vmlinux
   struct task_struct {
        volatile long int          state;                                                /*     0     8 */
        --- First cacheline is ok

        struct task_struct *       last_wakee;                                           /*    56     8 */
        /* --- cacheline 1 boundary (64 bytes) --- */
        int                        wake_cpu;                                             /*    64     4 */

        ...

        const struct sched_class  * sched_class;                                         /*    88     8 */
        struct sched_entity {
Quoted 8 lines
                struct load_weight {
                        long unsigned int weight;                                        /*    96     8 */
                        /* typedef u32 */ unsigned int inv_weight;                       /*   104     4 */
                } load; /*    96    16 */
                struct rb_node {
                        long unsigned int __rb_parent_color;                             /*   112     8 */
                        struct rb_node * rb_right;                                       /*   120     8 */
                        /* --- cacheline 2 boundary (128 bytes) --- */

Which seems fixed here, but...

Quoted 5 lines

struct rb_node * rb_left; /* 128 8 */
} run_node; /* 112 24 */

--- Second one is still in relative mode and gives wrong
alignment in wrt task_struct start

... why this one is buggy still? I.e. it should be fixed in such a way that when we go recursively expanding structs, we know what is the current cacheline we're on.

- Arnaldo

Quoted 105 lines
                /* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */
                struct list_head {
                        struct list_head * next;                                         /*   136     8 */
                        struct list_head * prev;                                         /*   144     8 */
                } group_node; /*   136    16 */
       ...
---
 dwarves.h         |  1 +
 dwarves_fprintf.c | 25 ++++++++++---------------
 2 files changed, 11 insertions(+), 15 deletions(-)
dwarves.h +1 -0
index 73fec8ac614a..44ebf8384b9c 100644
@@ -56,6 +56,7 @@ struct conf_fprintf {
 	int32_t	   type_spacing;
 	int32_t	   name_spacing;
 	uint32_t   base_offset;
+	uint32_t   base_cacheline;
 	uint8_t	   indent;
 	uint8_t	   expand_types:1;
 	uint8_t	   expand_pointers:1;
dwarves_fprintf.c +10 -15
index 2d114210831a..72d8b08bf235 100644
@@ -1118,22 +1118,21 @@ size_t function__fprintf_stats(const struct tag *tag, const struct cu *cu,
 	return printed + fprintf(fp, " */\n");
 }
 
-static size_t class__fprintf_cacheline_boundary(uint32_t last_cacheline,
-						size_t sum, size_t sum_holes,
+static size_t class__fprintf_cacheline_boundary(size_t sum, size_t sum_holes,
 						uint8_t *newline,
-						uint32_t *cacheline,
 						struct conf_fprintf *cconf,
 						FILE *fp)
 {
-	const size_t real_sum = sum + sum_holes;
+	const size_t real_sum = sum + sum_holes + cconf->base_offset;
 	size_t printed = 0;
+	uint32_t cacheline = real_sum / cacheline_size;
 
-	*cacheline = real_sum / cacheline_size;
-
-	if (*cacheline > last_cacheline) {
+	if (cacheline != cconf->base_cacheline) {
 		const uint32_t cacheline_pos = real_sum % cacheline_size;
 		const uint32_t cacheline_in_bytes = real_sum - cacheline_pos;
 
+		cconf->base_cacheline = cacheline;
+
 		if (*newline) {
 			fputc('\n', fp);
 			*newline = 0;
@@ -1144,12 +1143,12 @@ static size_t class__fprintf_cacheline_boundary(uint32_t last_cacheline,
 
 		if (cacheline_pos == 0)
 			printed += fprintf(fp, "/* --- cacheline %u boundary "
-					   "(%u bytes) --- */\n", *cacheline,
+					   "(%u bytes) --- */\n", cacheline,
 					   cacheline_in_bytes);
 		else
 			printed += fprintf(fp, "/* --- cacheline %u boundary "
 					   "(%u bytes) was %u bytes ago --- "
-					   "*/\n", *cacheline,
+					   "*/\n", cacheline,
 					   cacheline_in_bytes, cacheline_pos);
 	}
 	return printed;
@@ -1284,10 +1283,8 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 		    pos->byte_offset != last->byte_offset &&
 		    !cconf.suppress_comments)
 			printed +=
-			    class__fprintf_cacheline_boundary(last_cacheline,
-							      sum, sum_holes,
+			    class__fprintf_cacheline_boundary(sum, sum_holes,
 							      &newline,
-							      &last_cacheline,
 							      &cconf,
 							      fp);
 		/*
@@ -1474,10 +1471,8 @@ size_t class__fprintf(struct class *class, const struct cu *cu,
 	}
 
 	if (!cconf.suppress_comments)
-		printed += class__fprintf_cacheline_boundary(last_cacheline,
-							     sum, sum_holes,
+		printed += class__fprintf_cacheline_boundary(sum, sum_holes,
 							     &newline,
-							     &last_cacheline,
 							     &cconf, fp);
 	if (!cconf.show_only_data_members)
 		class__vtable_fprintf(class, cu, &cconf, fp);
Signature · 6 lines
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe dwarves" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#17 lore raw
In reply to a message not in the archive
Quoted 8 lines · Jiri Olsa

hi,
hit 2 issues when used pahole
- sometimes it did not account the hole between variables
- when using -E to extract inner struct, cacheline boundaries were wrong

with this patchset I was able to get it work on structs that I was investigating, but I'm not sure I covered all parts or fixed it in proper way.

any feedback?

thanks,
jirka
--
To unsubscribe from this list: send the line "unsubscribe dwarves" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html