Skip to contentSkip to conversation

ftrace does not work on cpus > 999.

DISCUSSION Robin Holt 5 participants 6 messages Oct 16, 2010 Tracing

lore
Share & tools
lore

Robin Holt

author
#0 lore raw

Just started looking into using ftrace to identify a difficult to diagnose userland set of processes when I noticed that the .../trace/per_cpu directory only contains entries for cpus 0-999. I have not looked at what else may not work. For the cpus that are listed, I am able to grep trace buffer information so it is mostly working.

I will be away from email for most of today, but may get back to this tonight. If there are any suggestions, I will happily give them a try.

Thanks,
Robin

maintainer
#2 lore raw
In reply to Frederic Weisbecker

kernel/trace/trace.c static void tracing_init_debugfs_percpu(long cpu) · line 4005

Quoted 13 lines · Frederic Weisbecker
kernel/trace/trace.c +1 -1
index 9ec59f5..3565f9e 100644
@@ -3999,7 +3999,7 @@ static void tracing_init_debugfs_percpu(long cpu)
 	/* strlen(cpu) + MAX(log10(cpu)) + '\0' */
 	char cpu_dir[7];
 
-	if (cpu > 999 || cpu < 0)
+	if (cpu < 0)
 		return;
 
 	sprintf(cpu_dir, "cpu%ld", cpu);

You need to change the size of cpu_dir, otherwise this will overflow.

The other case is to dynamically allocate cpu_dir.

	char *cpu_dir;
	int count = cpu;
	int size;

	if (cpu < 0)
		return;

	/* log10 sizeof cpu */
	for (size = 0; count > 0; count /= 10, size++)
		;

	cpu_dir = kmalloc(size + 4, GFP_KERNEL);

	if (!cpu_dir)
		return;

	snprintf(cpu_dir, size + 4, "cpu%ld", cpu);

	[...]

	kfree(cpu_dir);

-- Steve

#1 lore raw
In reply to Robin Holt
Quoted 11 lines · Robin Holt

Just started looking into using ftrace to identify a difficult to diagnose userland set of processes when I noticed that the .../trace/per_cpu directory only contains entries for cpus 0-999. I have not looked at what else may not work. For the cpus that are listed, I am able to grep trace buffer information so it is mostly working.

I will be away from email for most of today, but may get back to this tonight. If there are any suggestions, I will happily give them a try.

Thanks,
Robin

Oh!

Can you please try that?

Thanks.

kernel/trace/trace.c +1 -1
index 9ec59f5..3565f9e 100644
@@ -3999,7 +3999,7 @@ static void tracing_init_debugfs_percpu(long cpu)
 	/* strlen(cpu) + MAX(log10(cpu)) + '\0' */
 	char cpu_dir[7];
 
-	if (cpu > 999 || cpu < 0)
+	if (cpu < 0)
 		return;
 
 	sprintf(cpu_dir, "cpu%ld", cpu);
#3 lore raw
In reply to Steven Rostedt
Quoted 10 lines · Steven Rostedt
Quoted 8 lines · Frederic Weisbecker
kernel/trace/trace.c +0 -0
index 9ec59f5..3565f9e 100644
@@ -3999,7 +3999,7 @@ static void tracing_init_debugfs_percpu(long cpu)
 	/* strlen(cpu) + MAX(log10(cpu)) + '\0' */
 	char cpu_dir[7];
 
Quoted 7 lines

kernel/trace/trace.c static void tracing_init_debugfs_percpu(long cpu) · line 4005

Quoted 5 lines
kernel/trace/trace.c +1 -1
-	if (cpu > 999 || cpu < 0)
+	if (cpu < 0)
 		return;
 
 	sprintf(cpu_dir, "cpu%ld", cpu);

You need to change the size of cpu_dir, otherwise this will overflow.

If you change it to 30 that ought to be enough, as long as cpu_id's fit into u64. (I think we wont overflow that in my lifetime.)

Quoted 1 line

The other case is to dynamically allocate cpu_dir.

Please tell me that is a joke ...

Ingo

maintainer
#4 lore raw
Quoted 16 lines · Ingo Molnar
Quoted 14 lines · Steven Rostedt
Quoted 12 lines · Frederic Weisbecker
kernel/trace/trace.c +1 -1
index 9ec59f5..3565f9e 100644
@@ -3999,7 +3999,7 @@ static void tracing_init_debugfs_percpu(long cpu)
 	/* strlen(cpu) + MAX(log10(cpu)) + '\0' */
 	char cpu_dir[7];
 
-	if (cpu > 999 || cpu < 0)
+	if (cpu < 0)
 		return;
 
Quoted 6 lines
Quoted 3 lines

kernel/trace/trace.c static void tracing_init_debugfs_percpu(long cpu) · line 4005

Quoted 1 line
kernel/trace/trace.c +0 -0
 	sprintf(cpu_dir, "cpu%ld", cpu);

You need to change the size of cpu_dir, otherwise this will overflow.

If you change it to 30 that ought to be enough, as long as cpu_id's fit into u64. (I think we wont overflow that in my lifetime.)

And might as well make it static then, as we seem to be doing with sched_param.

Quoted 4 lines
Quoted 2 lines

The other case is to dynamically allocate cpu_dir.

Please tell me that is a joke ...

Why? It handles all cases and is only executed once at boot up. I'll admit it was a little over engineered, and setting a new max of 30 chars should be fine too. But no reason for it to be a joke.

-- Steve

#5 lore raw
In reply to Ingo Molnar
Quoted 16 lines · Ingo Molnar
Quoted 14 lines · Steven Rostedt
Quoted 12 lines · Frederic Weisbecker
kernel/trace/trace.c +1 -1
index 9ec59f5..3565f9e 100644
@@ -3999,7 +3999,7 @@ static void tracing_init_debugfs_percpu(long cpu)
     /* strlen(cpu) + MAX(log10(cpu)) + '\0' */
     char cpu_dir[7];
 
-   if (cpu > 999 || cpu < 0)
+   if (cpu < 0)
             return;
 
Quoted 5 lines
Quoted 3 lines

kernel/trace/trace.c static void tracing_init_debugfs_percpu(long cpu) · line 4005

Quoted 1 line
kernel/trace/trace.c +0 -0
     sprintf(cpu_dir, "cpu%ld", cpu);

You need to change the size of cpu_dir, otherwise this will overflow.

If you change it to 30 that ought to be enough, as long as cpu_id's fit

Yep.

Quoted 5 lines

into u64. (I think we wont overflow that in my lifetime.)

Quoted 1 line

The other case is to dynamically allocate cpu_dir.

Please tell me that is a joke ...

And if it isn't, use kasprintf() ;-)

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds