Skip to contentSkip to conversation

Enable kernel profiling with stepping of 1

PATCH In review Ravikiran G Thirumalai 1 participant 2 messages Sep 2, 2002 – Sep 3, 2002 1 message not in the archive

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

PATCH 1/1 Enable kernel profiling with stepping of 1

Right now the builtin profiler doesn't work with profile=0. The following patch fixes it.

Details:
The "profile" kernel parameter is used to determine the profile step of the builtin profiler. Value passed denotes the 'prof_shift' that is used to allocate the profiling buffer. If param profile=1, prof_shift=1 and the profiling buffer is half the size of kernel text; 2 insns hash on to the same bucket and the profiling step is 2.
(bufsize = kernel_text_size >> prof_shift; step = 1 << prof_shift) The foll patch enables profiling even when prof_shift=0. If profile parameter is missing at boot time, profiling is turned off.

Patch applies on 2.5.33, tested on PIII 8way. Works fine and doesn't break userspace readprofile. Should work for all archs.

Profiling with step=1 will help us do insn level profiling with better granularity using readprofile hacks (like the one by tridge). Pls apply.

-Kiran

fs/proc/proc_misc.c +1 -1
diff -ruN -X /home/kiran/dontdiff linux-2.5.33/fs/proc/proc_misc.c readprofile-2.5.33/fs/proc/proc_misc.c
@@ -634,7 +634,7 @@
 		proc_root_kcore->size =
 				(size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
 	}
-	if (prof_shift) {
+	if (prof_on) {
 		entry = create_proc_entry("profile", S_IWUSR | S_IRUGO, NULL);
 		if (entry) {
 			entry->proc_fops = &proc_profile_operations;
include/linux/sched.h +1 -0
diff -ruN -X /home/kiran/dontdiff linux-2.5.33/include/linux/sched.h readprofile-2.5.33/include/linux/sched.h
@@ -500,6 +500,7 @@
 extern unsigned int * prof_buffer;
 extern unsigned long prof_len;
 extern unsigned long prof_shift;
+extern int prof_on;
 
 extern void FASTCALL(__wake_up(wait_queue_head_t *q, unsigned int mode, int nr));
 extern void FASTCALL(__wake_up_locked(wait_queue_head_t *q, unsigned int mode));
init/main.c +6 -3
diff -ruN -X /home/kiran/dontdiff linux-2.5.33/init/main.c readprofile-2.5.33/init/main.c
@@ -135,8 +135,11 @@
 
 static int __init profile_setup(char *str)
 {
-    int par;
-    if (get_option(&str,&par)) prof_shift = par;
+	int par;
+	if (get_option(&str,&par)) {
+		prof_shift = par;
+		prof_on = 1;
+	}
 	return 1;
 }
 
@@ -413,7 +416,7 @@
 #ifdef CONFIG_MODULES
 	init_modules();
 #endif
-	if (prof_shift) {
+	if (prof_on) {
 		unsigned int size;
 		/* only text is profiled */
 		prof_len = (unsigned long) &_etext - (unsigned long) &_stext;
kernel/timer.c +1 -0
diff -ruN -X /home/kiran/dontdiff linux-2.5.33/kernel/timer.c readprofile-2.5.33/kernel/timer.c
@@ -79,6 +79,7 @@
 unsigned int * prof_buffer;
 unsigned long prof_len;
 unsigned long prof_shift;
+int prof_on;
 
 /*
  * Event timer code

A message that is not in the archive (sent off-list or not yet received): Pine.LNX.4.33.0209022031240.912-100000@coffee.psychology.mcmaster.ca

#2 lore raw
Quoted 3 lines · Mark Hahn
Quoted 1 line

and the profiling buffer is half the size of kernel text; 2 insns hash on to

s/insns/bytes of code/

Yep.. I was speaking in terms of the smallest possible size for a insn.

Quoted 6 lines
Quoted 3 lines

Profiling with step=1 will help us do insn level profiling with better granularity

I guess this means you want to do insn- or line-wise profiling, rather than the original point of this feature (function-wise).

Exactly.

Thanks,
Kiran