Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] oprofile: report anonymous region samples

The below patch passes samples from anonymous regions to userspace instead
of just dropping them. This provides the support needed for reporting
anonymous-region code samples (today: basic accumulated results; later:
Java and other dynamically compiled code).

As this changes the format, an upgrade to the just-released 0.9 release of
the userspace tools is required.

This patch is based upon an earlier one by Will Cohen <wcohen@redhat.com>

Signed-off-by: John Levon <levon@movementarian.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

John Levon and committed by
Linus Torvalds
0c0a400d 391cd727

+29 -15
+1 -1
Documentation/Changes
··· 63 63 o isdn4k-utils 3.1pre1 # isdnctrl 2>&1|grep version 64 64 o nfs-utils 1.0.5 # showmount --version 65 65 o procps 3.2.0 # ps --version 66 - o oprofile 0.5.3 # oprofiled --version 66 + o oprofile 0.9 # oprofiled --version 67 67 68 68 Kernel compilation 69 69 ==================
+7 -3
Documentation/basic_profiling.txt
··· 27 27 28 28 Oprofile 29 29 -------- 30 - Get the source (I use 0.8) from http://oprofile.sourceforge.net/ 31 - and add "idle=poll" to the kernel command line 30 + 31 + Get the source (see Changes for required version) from 32 + http://oprofile.sourceforge.net/ and add "idle=poll" to the kernel command 33 + line. 34 + 32 35 Configure with CONFIG_PROFILING=y and CONFIG_OPROFILE=y & reboot on new kernel 36 + 33 37 ./configure --with-kernel-support 34 38 make install 35 39 ··· 50 46 stop opcontrol --stop 51 47 dump output opreport > output_file 52 48 53 - To only report on the kernel, run opreport /boot/vmlinux > output_file 49 + To only report on the kernel, run opreport -l /boot/vmlinux > output_file 54 50 55 51 A reset is needed to clear old statistics, which survive a reboot. 56 52
+18 -11
drivers/oprofile/buffer_sync.c
··· 206 206 */ 207 207 static unsigned long get_exec_dcookie(struct mm_struct * mm) 208 208 { 209 - unsigned long cookie = 0; 209 + unsigned long cookie = NO_COOKIE; 210 210 struct vm_area_struct * vma; 211 211 212 212 if (!mm) ··· 234 234 */ 235 235 static unsigned long lookup_dcookie(struct mm_struct * mm, unsigned long addr, off_t * offset) 236 236 { 237 - unsigned long cookie = 0; 237 + unsigned long cookie = NO_COOKIE; 238 238 struct vm_area_struct * vma; 239 239 240 240 for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) { 241 241 242 - if (!vma->vm_file) 243 - continue; 244 - 245 242 if (addr < vma->vm_start || addr >= vma->vm_end) 246 243 continue; 247 244 248 - cookie = fast_get_dcookie(vma->vm_file->f_dentry, 249 - vma->vm_file->f_vfsmnt); 250 - *offset = (vma->vm_pgoff << PAGE_SHIFT) + addr - vma->vm_start; 245 + if (vma->vm_file) { 246 + cookie = fast_get_dcookie(vma->vm_file->f_dentry, 247 + vma->vm_file->f_vfsmnt); 248 + *offset = (vma->vm_pgoff << PAGE_SHIFT) + addr - 249 + vma->vm_start; 250 + } else { 251 + /* must be an anonymous map */ 252 + *offset = addr; 253 + } 254 + 251 255 break; 252 256 } 257 + 258 + if (!vma) 259 + cookie = INVALID_COOKIE; 253 260 254 261 return cookie; 255 262 } 256 263 257 264 258 - static unsigned long last_cookie = ~0UL; 265 + static unsigned long last_cookie = INVALID_COOKIE; 259 266 260 267 static void add_cpu_switch(int i) 261 268 { 262 269 add_event_entry(ESCAPE_CODE); 263 270 add_event_entry(CPU_SWITCH_CODE); 264 271 add_event_entry(i); 265 - last_cookie = ~0UL; 272 + last_cookie = INVALID_COOKIE; 266 273 } 267 274 268 275 static void add_kernel_ctx_switch(unsigned int in_kernel) ··· 324 317 325 318 cookie = lookup_dcookie(mm, s->eip, &offset); 326 319 327 - if (!cookie) { 320 + if (cookie == INVALID_COOKIE) { 328 321 atomic_inc(&oprofile_stats.sample_lost_no_mapping); 329 322 return 0; 330 323 }
+3
drivers/oprofile/event_buffer.h
··· 35 35 #define TRACE_BEGIN_CODE 8 36 36 #define TRACE_END_CODE 9 37 37 38 + #define INVALID_COOKIE ~0UL 39 + #define NO_COOKIE 0UL 40 + 38 41 /* add data to the event buffer */ 39 42 void add_event_entry(unsigned long data); 40 43