Skip to contentSkip to conversation

ftace: remove struct list_head in struct dyn_ftrace

PATCH In review Lai Jiangshan 3 participants 6 messages Mar 13, 2009 – Mar 18, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ftace: remove struct list_head in struct dyn_ftrace

Impact: save memory

The struct dyn_ftrace table is very large, this patch will save about 50%

---

include/linux/ftrace.h +0 -1
index e1583f2..4dc32c8 100644
@@ -145,7 +145,6 @@ enum {
 };
 
 struct dyn_ftrace {
-	struct list_head	list;
 	unsigned long		ip; /* address of mcount call-site */
 	unsigned long		flags;
 	struct dyn_arch_ftrace	arch;
kernel/trace/ftrace.c +8 -6
index d33d306..40eaaae 100644
@@ -272,7 +272,7 @@ enum {
 
 static int ftrace_filtered;
 
-static LIST_HEAD(ftrace_new_addrs);
+static struct dyn_ftrace *ftrace_new_addrs;
 
 static DEFINE_MUTEX(ftrace_regex_lock);
 
@@ -408,8 +408,8 @@ ftrace_record_ip(unsigned long ip)
 		return NULL;
 
 	rec->ip = ip;
-
-	list_add(&rec->list, &ftrace_new_addrs);
+	rec->flags = (unsigned long)ftrace_new_addrs;
+	ftrace_new_addrs = rec;
 
 	return rec;
 }
@@ -714,19 +714,21 @@ unsigned long		ftrace_update_tot_cnt;
 
 static int ftrace_update_code(struct module *mod)
 {
-	struct dyn_ftrace *p, *t;
+	struct dyn_ftrace *p;
 	cycle_t start, stop;
 
 	start = ftrace_now(raw_smp_processor_id());
 	ftrace_update_cnt = 0;
 
-	list_for_each_entry_safe(p, t, &ftrace_new_addrs, list) {
+	while (ftrace_new_addrs) {
 
 		/* If something went wrong, bail without enabling anything */
 		if (unlikely(ftrace_disabled))
 			return -1;
 
-		list_del_init(&p->list);
+		p = ftrace_new_addrs;
+		ftrace_new_addrs = (struct dyn_ftrace *)p->flags;
+		p->flags = 0L;
 
 		/* convert record (i.e, patch mcount-call with NOP) */
 		if (ftrace_code_disable(mod, p)) {
#1 lore raw

[tip:tracing/ftrace] ftrace: remove struct list_head from struct dyn_ftrace

Commit-ID:  e94142a67f8bad494c593f0a07c9fc2fbec98c0e
Gitweb:     http://git.kernel.org/tip/e94142a67f8bad494c593f0a07c9fc2fbec98c0e
Author:     Lai Jiangshan <[email protected]>
AuthorDate: Fri, 13 Mar 2009 17:51:27 +0800
Commit:     Ingo Molnar <[email protected]>
CommitDate: Fri, 13 Mar 2009 11:36:20 +0100

ftrace: remove struct list_head from struct dyn_ftrace

Impact: save memory

The struct dyn_ftrace table is very large, this patch will save about 50%.

LKML-Reference: <[email protected]>

---
 include/linux/ftrace.h |    1 -
 kernel/trace/ftrace.c  |   14 ++++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
include/linux/ftrace.h +0 -1
index c146c10..9d598bb 100644
@@ -145,7 +145,6 @@ enum {
 };
 
 struct dyn_ftrace {
-	struct list_head	list;
 	unsigned long		ip; /* address of mcount call-site */
 	unsigned long		flags;
 	struct dyn_arch_ftrace	arch;
kernel/trace/ftrace.c +8 -6
index bf78a4c..90d5729 100644
@@ -272,7 +272,7 @@ enum {
 
 static int ftrace_filtered;
 
-static LIST_HEAD(ftrace_new_addrs);
+static struct dyn_ftrace *ftrace_new_addrs;
 
 static DEFINE_MUTEX(ftrace_regex_lock);
 
@@ -409,8 +409,8 @@ ftrace_record_ip(unsigned long ip)
 		return NULL;
 
 	rec->ip = ip;
-
-	list_add(&rec->list, &ftrace_new_addrs);
+	rec->flags = (unsigned long)ftrace_new_addrs;
+	ftrace_new_addrs = rec;
 
 	return rec;
 }
@@ -716,19 +716,21 @@ unsigned long		ftrace_update_tot_cnt;
 
 static int ftrace_update_code(struct module *mod)
 {
-	struct dyn_ftrace *p, *t;
+	struct dyn_ftrace *p;
 	cycle_t start, stop;
 
 	start = ftrace_now(raw_smp_processor_id());
 	ftrace_update_cnt = 0;
 
-	list_for_each_entry_safe(p, t, &ftrace_new_addrs, list) {
+	while (ftrace_new_addrs) {
 
 		/* If something went wrong, bail without enabling anything */
 		if (unlikely(ftrace_disabled))
 			return -1;
 
-		list_del_init(&p->list);
+		p = ftrace_new_addrs;
+		ftrace_new_addrs = (struct dyn_ftrace *)p->flags;
+		p->flags = 0L;
 
 		/* convert record (i.e, patch mcount-call with NOP) */
 		if (ftrace_code_disable(mod, p)) {
#2 lore raw

Re: [tip:tracing/ftrace] ftrace: remove struct list_head from struct dyn_ftrace

Quoted 50 lines · Lai Jiangshan
Commit-ID:  e94142a67f8bad494c593f0a07c9fc2fbec98c0e
Gitweb:     http://git.kernel.org/tip/e94142a67f8bad494c593f0a07c9fc2fbec98c0e
Author:     Lai Jiangshan <[email protected]>
AuthorDate: Fri, 13 Mar 2009 17:51:27 +0800
Commit:     Ingo Molnar <[email protected]>
CommitDate: Fri, 13 Mar 2009 11:36:20 +0100

ftrace: remove struct list_head from struct dyn_ftrace
Impact: save memory

The struct dyn_ftrace table is very large, this patch will save about 50%.

LKML-Reference: <[email protected]>

---
 include/linux/ftrace.h |    1 -
 kernel/trace/ftrace.c  |   14 ++++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
include/linux/ftrace.h +0 -1
index c146c10..9d598bb 100644
@@ -145,7 +145,6 @@ enum {
 };
 
 struct dyn_ftrace {
-	struct list_head	list;
 	unsigned long		ip; /* address of mcount call-site */
 	unsigned long		flags;
 	struct dyn_arch_ftrace	arch;
kernel/trace/ftrace.c +1 -1
index bf78a4c..90d5729 100644
@@ -272,7 +272,7 @@ enum {
 
 static int ftrace_filtered;
 
-static LIST_HEAD(ftrace_new_addrs);
+static struct dyn_ftrace *ftrace_new_addrs;
 
 static DEFINE_MUTEX(ftrace_regex_lock);
 

kernel/trace/ftrace.c ftrace_record_ip(unsigned long ip) · line 412

Quoted 6 lines
kernel/trace/ftrace.c +1 -2
@@ -409,8 +409,8 @@ ftrace_record_ip(unsigned long ip)
 		return NULL;
 
 	rec->ip = ip;
-
-	list_add(&rec->list, &ftrace_new_addrs);
+	rec->flags = (unsigned long)ftrace_new_addrs;

Lets not play games with pointers. If we are going to do this, make it into a union.

struct dyn_arch_ftrace {
	unsigned long ip;
	union {
		unsigned long flags;
		struct dyn_arch_ftrace *next;
	}
	struct dyn_arch_ftrace arch;
};

This way it is much clearer to what is going on.

Quoted 15 lines
kernel/trace/ftrace.c +2 -1
+	ftrace_new_addrs = rec;
 
 	return rec;
 }
@@ -716,19 +716,21 @@ unsigned long		ftrace_update_tot_cnt;
 
 static int ftrace_update_code(struct module *mod)
 {
-	struct dyn_ftrace *p, *t;
+	struct dyn_ftrace *p;
 	cycle_t start, stop;
 
 	start = ftrace_now(raw_smp_processor_id());
 	ftrace_update_cnt = 0;
 

kernel/trace/ftrace.c unsigned long ftrace_update_tot_cnt; · line 732

Quoted 10 lines
kernel/trace/ftrace.c +3 -2
-	list_for_each_entry_safe(p, t, &ftrace_new_addrs, list) {
+	while (ftrace_new_addrs) {
 
 		/* If something went wrong, bail without enabling anything */
 		if (unlikely(ftrace_disabled))
 			return -1;
 
-		list_del_init(&p->list);
+		p = ftrace_new_addrs;
+		ftrace_new_addrs = (struct dyn_ftrace *)p->flags;

This confused me (and scared me) for a bit. Having a union would not have.

Make the change to a union, and then you have my:

Thanks,

-- Steve

Quoted 4 lines
kernel/trace/ftrace.c +1 -0
+		p->flags = 0L;
 
 		/* convert record (i.e, patch mcount-call with NOP) */
 		if (ftrace_code_disable(mod, p)) {
#3 lore raw

Re: [tip:tracing/ftrace] ftrace: remove struct list_head from struct dyn_ftrace

In reply to Lai Jiangshan
Quoted 51 lines · Lai Jiangshan
Commit-ID:  e94142a67f8bad494c593f0a07c9fc2fbec98c0e
Gitweb:     http://git.kernel.org/tip/e94142a67f8bad494c593f0a07c9fc2fbec98c0e
Author:     Lai Jiangshan <[email protected]>
AuthorDate: Fri, 13 Mar 2009 17:51:27 +0800
Commit:     Ingo Molnar <[email protected]>
CommitDate: Fri, 13 Mar 2009 11:36:20 +0100

ftrace: remove struct list_head from struct dyn_ftrace

Impact: save memory

The struct dyn_ftrace table is very large, this patch will save about 50%.

LKML-Reference: <[email protected]>

---
 include/linux/ftrace.h |    1 -
 kernel/trace/ftrace.c  |   14 ++++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
include/linux/ftrace.h +0 -1
index c146c10..9d598bb 100644
@@ -145,7 +145,6 @@ enum {
 };
 
 struct dyn_ftrace {
-	struct list_head	list;
 	unsigned long		ip; /* address of mcount call-site */
 	unsigned long		flags;
 	struct dyn_arch_ftrace	arch;
kernel/trace/ftrace.c +1 -1
index bf78a4c..90d5729 100644
@@ -272,7 +272,7 @@ enum {
 
 static int ftrace_filtered;
 
-static LIST_HEAD(ftrace_new_addrs);
+static struct dyn_ftrace *ftrace_new_addrs;
 
 static DEFINE_MUTEX(ftrace_regex_lock);
 

kernel/trace/ftrace.c ftrace_record_ip(unsigned long ip) · line 413

Quoted 7 lines
kernel/trace/ftrace.c +2 -2
@@ -409,8 +409,8 @@ ftrace_record_ip(unsigned long ip)
 		return NULL;
 
 	rec->ip = ip;
-
-	list_add(&rec->list, &ftrace_new_addrs);
+	rec->flags = (unsigned long)ftrace_new_addrs;
+	ftrace_new_addrs = rec;

But... you are overwritting all the ftrace flags infrastructure by using it as a list pointer.

This is breaking dynamic tracing.

Quoted 32 lines
kernel/trace/ftrace.c +5 -4
 	return rec;
 }
@@ -716,19 +716,21 @@ unsigned long		ftrace_update_tot_cnt;
 
 static int ftrace_update_code(struct module *mod)
 {
-	struct dyn_ftrace *p, *t;
+	struct dyn_ftrace *p;
 	cycle_t start, stop;
 
 	start = ftrace_now(raw_smp_processor_id());
 	ftrace_update_cnt = 0;
 
-	list_for_each_entry_safe(p, t, &ftrace_new_addrs, list) {
+	while (ftrace_new_addrs) {
 
 		/* If something went wrong, bail without enabling anything */
 		if (unlikely(ftrace_disabled))
 			return -1;
 
-		list_del_init(&p->list);
+		p = ftrace_new_addrs;
+		ftrace_new_addrs = (struct dyn_ftrace *)p->flags;
+		p->flags = 0L;
 
 		/* convert record (i.e, patch mcount-call with NOP) */
 		if (ftrace_code_disable(mod, p)) {
--

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

#4 lore raw

Re: [tip:tracing/ftrace] ftrace: remove struct list_head from struct dyn_ftrace

Quoted 64 lines · Frederic Weisbecker
Quoted 51 lines · Lai Jiangshan
Commit-ID:  e94142a67f8bad494c593f0a07c9fc2fbec98c0e
Gitweb:     http://git.kernel.org/tip/e94142a67f8bad494c593f0a07c9fc2fbec98c0e
Author:     Lai Jiangshan <[email protected]>
AuthorDate: Fri, 13 Mar 2009 17:51:27 +0800
Commit:     Ingo Molnar <[email protected]>
CommitDate: Fri, 13 Mar 2009 11:36:20 +0100

ftrace: remove struct list_head from struct dyn_ftrace

Impact: save memory

The struct dyn_ftrace table is very large, this patch will save about 50%.

LKML-Reference: <[email protected]>

---
 include/linux/ftrace.h |    1 -
 kernel/trace/ftrace.c  |   14 ++++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
include/linux/ftrace.h +0 -1
index c146c10..9d598bb 100644
@@ -145,7 +145,6 @@ enum {
 };
 
 struct dyn_ftrace {
-	struct list_head	list;
 	unsigned long		ip; /* address of mcount call-site */
 	unsigned long		flags;
 	struct dyn_arch_ftrace	arch;
kernel/trace/ftrace.c +1 -1
index bf78a4c..90d5729 100644
@@ -272,7 +272,7 @@ enum {
 
 static int ftrace_filtered;
 
-static LIST_HEAD(ftrace_new_addrs);
+static struct dyn_ftrace *ftrace_new_addrs;
 
 static DEFINE_MUTEX(ftrace_regex_lock);
 

kernel/trace/ftrace.c ftrace_record_ip(unsigned long ip) · line 413

Quoted 7 lines
kernel/trace/ftrace.c +2 -2
@@ -409,8 +409,8 @@ ftrace_record_ip(unsigned long ip)
 		return NULL;
 
 	rec->ip = ip;
-
-	list_add(&rec->list, &ftrace_new_addrs);
+	rec->flags = (unsigned long)ftrace_new_addrs;
+	ftrace_new_addrs = rec;

But... you are overwritting all the ftrace flags infrastructure by using it as a list pointer.

Quoted 1 line

This is breaking dynamic tracing.

May be I'm wrong. May be I misunderstood this patch.
But I don't understand how flags can be used at the same time as a pointer and as a flag value.

Quoted 33 lines
Quoted 32 lines
kernel/trace/ftrace.c +5 -4
 	return rec;
 }
@@ -716,19 +716,21 @@ unsigned long		ftrace_update_tot_cnt;
 
 static int ftrace_update_code(struct module *mod)
 {
-	struct dyn_ftrace *p, *t;
+	struct dyn_ftrace *p;
 	cycle_t start, stop;
 
 	start = ftrace_now(raw_smp_processor_id());
 	ftrace_update_cnt = 0;
 
-	list_for_each_entry_safe(p, t, &ftrace_new_addrs, list) {
+	while (ftrace_new_addrs) {
 
 		/* If something went wrong, bail without enabling anything */
 		if (unlikely(ftrace_disabled))
 			return -1;
 
-		list_del_init(&p->list);
+		p = ftrace_new_addrs;
+		ftrace_new_addrs = (struct dyn_ftrace *)p->flags;
+		p->flags = 0L;
 
 		/* convert record (i.e, patch mcount-call with NOP) */
 		if (ftrace_code_disable(mod, p)) {
--

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

#5 lore raw

Re: [tip:tracing/ftrace] ftrace: remove struct list_head from struct dyn_ftrace

Quoted 6 lines · Frederic Weisbecker

May be I'm wrong. May be I misunderstood this patch.
But I don't understand how flags can be used at the same time as a pointer and as a flag value.

When a new dyn_ftrace is added to ftrace_new_addrs list, the flag is 0, it's always 0 until this dyn_ftrace is removed from the list, so we can reuse the flag field. As Steven's suggest, using an union is better.

ftrace_convert_nops()
ftrace_record_ip() // allocate dyn_ftrace, and add it

                     // to ftrace_new_addrs list

ftrace_update_code() // remove it from ftrace_new_addrs.

Lai.