User Tools

Site Tools


mywiki:linux:linuxstack

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
mywiki:linux:linuxstack [2014/07/20 22:53] – external edit 127.0.0.1mywiki:linux:linuxstack [2022/04/02 17:29] (current) – external edit 127.0.0.1
Line 3: Line 3:
  
 ====== kernel Stack ====== ====== kernel Stack ======
 +The default stack size for a process running in kernel space is 8K (as of 2011). 
 +
 exception/hard IRQ/soft IRQ stack exception/hard IRQ/soft IRQ stack
  
Line 15: Line 17:
  
 ===== checkstack.pl ====== ===== checkstack.pl ======
 +checkstack.pl creates a listing of **the size of the stack frame used by every function in the kernel** (i.e. the total amount of local scratch space used by each function for local variables and whatnot).
  
 +The way it does this is by going through the disassembly of the kernel and looking for 2 things: function names and instructions which adjust the stack. It looks for function names by looking for lines that match $funcre (qr/^$x* <(.*)>:$/), and it looks for stack adjustment instructions that match $re or $dre; the latter two depend highly on what architecture the kernel was compiled for, which is what the first big block if if/else statements is checking for. $re searches for functions which adjust the stack by a fixed amount (the vast majority of functions), and $dre searches for functions which adjust the stack by a variable amount (rare).
 + 
 +$CROSS_COMPILE)objdump -d vmlinux | scripts/checkstack.pl [arch]
  
-$(CROSS_COMPILE)objdump -d vmlinux | scripts/checkstack.pl [arch]+Example:
  
-$ arm-eabi-objdummp -d vmlinux -o vmlinux-arm.S +  * mips-openwrt-linux-objdump -d vmlinux | scripts/checkstack.pl mips 
-$ cat vmlinux-arm.S | scripts/checkstack.pl arm+ 
 +Its output like below:
  
 <file> <file>
-0x0012c858 nlmclnt_reclaim [vmlinux-arm.o]:             720 +0x803feed4 match [vmlinux]: 3184 
-0x0025748c do_tcp_getsockopt.clone.11 [vmlinux-arm.o]:  552 +0x803fedc8 mangle_http_header.constprop.[vmlinux]: 2096 
-0x00258d04 do_tcp_setsockopt.clone.14 [vmlinux-arm.o]:  544 +0x80045da8 mtsched_proc_write [vmlinux]: 1088 
-0x000b2db4 do_sys_poll [vmlinux-arm.o]:                 532 +0x801119c0 do_sys_poll [vmlinux]: 952 
-0x00138744 semctl_main.clone.7 [vmlinux-arm.o]:         532 +0x802fa7ac pce_rule_write [vmlinux]: 848 
-0x00138ec4 sys_semtimedop [vmlinux-arm.o]:              484 +0x8033daec of_get_dma_window [vmlinux]: 832 
-0x000c5618 default_file_splice_read [vmlinux-arm.o]:    436 +0x80110c78 do_select [vmlinux]: 752 
-0x00251de4 do_ip_setsockopt.clone.22 [vmlinux-arm.o]:   416 +0x802ed918 GSW_MulticastRouterPortRemove [vmlinux]: 664 
-0x00191fd4 extract_buf [vmlinux-arm.o]:                 408 +0x802edd68 GSW_MulticastSnoopCfgSet [vmlinux]: 664 
-0x0019bc24 loop_get_status_old [vmlinux-arm.o]:         396 +... 
-0x000e6f88 do_task_stat [vmlinux-arm.o]:                380 +0x8023ade4 test_comp [vmlinux]: 584 
-0x0019b8f0 loop_set_status_old [vmlinux-arm.o]:         380 +0x8022b4e0 SyS_semtimedop [vmlinux]: 520 
-0x002078f0 snd_ctl_elem_add_user [vmlinux-arm.o]:       376 +0x80038ff8 dma_build_device_chan_tbl [vmlinux]: 504 
-0x0026267c tcp_make_synack [vmlinux-arm.o]:             372 +0x801298ac default_file_splice_read [vmlinux]: 496 
-0x00127be4 nfs_dns_parse [vmlinux-arm.o]:               368 +0x8023b690 __test_skcipher [vmlinux]: 496 
-0x000b2240 do_select [vmlinux-arm.o]:                   340 +0x80163cd0 elf_kcore_store_hdr [vmlinux]: 464 
-0x001f6f10 mmc_blk_issue_rw_rq [vmlinux-arm.o]:         340 +... 
-0x001726a0 fb_set_var [vmlinux-arm.o]:                  336 +0x80129c08 vmsplice_to_pipe [vmlinux]: 368 
-0x000c58d0 __generic_file_splice_read [vmlinux-arm.o]:  316 +0x801aabc8 autofs4_notify_daemon [vmlinux]: 368 
-0x0022a074 dev_seq_printf_stats [vmlinux-arm.o]:        316 +0x8034c8b8 skb_splice_bits [vmlinux]: 352 
-0x0006383c tracing_splice_read_pipe [vmlinux-arm.o]:    308 +0x800c2c3c show_free_areas [vmlinux]: 344 
-0x000c53c8 vmsplice_to_pipe [vmlinux-arm.o]:            308 +0x8037053c dev_seq_printf_stats [vmlinux]: 344 
-0x002512b4 do_ip_getsockopt [vmlinux-arm.o]:            304 +0x803b0e8c do_ip_setsockopt.isra.17 [vmlinux]: 344 
-0x00225f68 skb_splice_bits [vmlinux-arm.o]:             300+0x80592c94 init_posix_timers [vmlinux]: 344 
 +0x801111ac core_sys_select [vmlinux]: 336 
 +0x8030adb4 tmu_proc_tmu_cascade_write [vmlinux]: 336 
 +0x803b0214 do_ip_getsockopt.constprop.18 [vmlinux]: 328 
 +0x80122c88 setxattr [vmlinux]: 320 
 +0x80147660 elf_core_dump [vmlinux]: 320 
 +... 
 +0x80396de0 conntrack_pptp_help [vmlinux]: 304
 </file> </file>
 +
 +===== CONFIG_FRAME_WARN ===== 
 +This kernel configuration option passes an option to the compiler to cause it to emit a warning when a static stack size for a routine is detected that is larger than the specified threshold. It requires gcc version 4.4 or later in order to work.
 + 
 +The gcc option used is "-Wframe-larger-than=xxx"
 +
 +By default, CONFIG_FRAME_WARN has the value of **1024**, but you can set it to any value from 0 to 8192.
 + 
 +Here is a sample of build output with this option configured to 256: 
 +    ...
 +    CC      ipc/msg.o
 +    CC      ipc/sem.o
 +    .../linux-3.0.y/ipc/sem.c: In function 'semctl_main.clone.7':
 +    .../linux-3.0.y/ipc/sem.c:1021:1: warning: the frame size of 520 bytes is larger than 256 bytes
 +    .../linux-3.0.y/ipc/sem.c: In function 'sys_semtimedop':
 +    .../linux-3.0.y/ipc/sem.c:1514:1: warning: the frame size of 472 bytes is larger than 256 bytes
 +    CC      ipc/shm.o
 +    CC      ipc/ipcns_notifier.o
 +    ...
 +
  
 ===== stack_size =====  ===== stack_size ===== 
Line 76: Line 110:
  
  
-==== CONFIG_DEBUG_STACK_USAGE / CONFIG_DEBUG_STACKOVERFLOW ====+===== CONFIG_DEBUG_STACK_USAGE / CONFIG_DEBUG_STACKOVERFLOW ===== 
 # dmesg | grep greatest        # dmesg | grep greatest       
 <file>                                                 <file>                                                
mywiki/linux/linuxstack.1405868011.txt.gz · Last modified: (external edit)