From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12314 invoked by alias); 9 Nov 2009 07:10:18 -0000 Received: (qmail 12306 invoked by uid 22791); 9 Nov 2009 07:10:15 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from e28smtp08.in.ibm.com (HELO e28smtp08.in.ibm.com) (122.248.162.8) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 09 Nov 2009 07:10:09 +0000 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by e28smtp08.in.ibm.com (8.14.3/8.13.1) with ESMTP id nA96qW7W026248 for ; Mon, 9 Nov 2009 12:22:32 +0530 Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id nA97A57K1544232 for ; Mon, 9 Nov 2009 12:40:05 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id nA97A5C8024932 for ; Mon, 9 Nov 2009 18:10:05 +1100 Received: from localhost ([9.124.217.37]) by d28av02.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id nA97A4aS024922 for ; Mon, 9 Nov 2009 18:10:05 +1100 Date: Mon, 09 Nov 2009 07:10:00 -0000 From: Rajasekhar Duddu To: systemtap@sources.redhat.com Subject: [PATCH V3] Tracepoint Tapset for Memory Subsystem Message-ID: <20091109071004.GA8837@rajduddu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2009-q4/txt/msg00464.txt.bz2 Hi all, here I am sending the updated patch based on all the previous comments. Please review it and let me know if it needs any more improvemnts. Changelog 1: Removed the Hardcoded constants in converting GFPFLAGS. Added a kprobe based fallback probe to kfree. Changelog 2: Removed the unreliable code which was used in fetching the call_site in kprobe based probe for kfree.(__builtin_return_address(0)) Changelog 3: Defined two macros for converting the GFP_FLAGS into string formats. Added k(ret)probe based fallback probes for all the Functions. Sample O/P: stapio 0x0000000230168 0x0000000000230168 0x00000a1eed018 24 24 80 GFP_NOFS kmem_cache_alloc sendmail 0x0000000153ed8 0x0000000000153ed8 0x00000b28a8000 4096 4096 208 GFP_KERNEL kmem_cache_alloc sendmail 0x000000014740a 0x000000000014740a 0x00000b572ba00 256 256 32976 __GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_ZERO kmem_cache_alloc sendmail 0x0000000271de0 0x0000000000271de0 0x00000bca09af0 16 16 32976 __GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_ZERO kmalloc sendmail 0x0000000271d90 0x0000000000271d90 0x00000bca09af0 16 16 32976 __GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_ZERO kmem_cache_alloc sendmail 0x000000015ef38 0x000000000015ef38 0x00000ada220c0 192 192 208 GFP_KERNEL kmem_cache_alloc sendmail 0x00000001b35a6 0x00000000001b35a6 0x00000bbae6540 640 648 208 GFP_KERNEL kmem_cache_alloc sendmail 0x0000000277264 0x0000000000277264 0x00000b9c03e10 72 72 32848 __GFP_WAIT | __GFP_IO | __GFP_ZERO kmem_cache_alloc sendmail 0x00000001b368c 0x00000000001b368c 0x00000b7e69dc0 64 64 208 GFP_KERNEL kmalloc Patch: Signed-off-by: Rajasekhar Duddu diff -rupaN a/tapset/memory.stp b/tapset/memory.stp --- a/tapset/memory.stp 2009-09-30 06:14:29.000000000 -0400 +++ b/tapset/memory.stp 2009-10-16 07:06:54.000000000 -0400 @@ -195,3 +195,269 @@ probe vm.brk = kernel.function("do_brk") probe vm.oom_kill = kernel.function("__oom_kill_task") { task = $p } +/* Macro for GFP Bitmasks. */ +/* The resulted GFP_FLAGS may be either single or concatenation of the multiple bitmasks. */ + +%{ +#define __GFP_BITMASKS(FLAG) if(gfp_flag & FLAG) { if(THIS->__retvalue[0] != '\0') \ + strlcat(THIS->__retvalue, " | "#FLAG, MAXSTRINGLEN); \ + else strlcat(THIS->__retvalue, #FLAG, MAXSTRINGLEN); } +%} + + +/* Macro for Composite Flags. */ +/* Each Composite GFP_FLAG is the combination of multiple bitmasks. */ + +%{ +#define __GFP_COMPOSITE_FLAG(FLAG) if(gfp_flag == FLAG) { \ + strlcat(THIS->__retvalue, #FLAG, MAXSTRINGLEN); return; +%} + + +/* Function to convert the GFP_FLAGS into corresponding STRING formats. */ + +function __gfp_flag_str:string(gfp_flag:long) %{ + int gfp_flag = (int)THIS->gfp_flag; + THIS->__retvalue[0] = '\0'; + + +/* Composite GFP FLAGS of the BitMasks. */ + + __GFP_COMPOSITE_FLAG(GFP_ZONEMASK) + __GFP_COMPOSITE_FLAG(GFP_ATOMIC) + __GFP_COMPOSITE_FLAG(GFP_NOIO) + __GFP_COMPOSITE_FLAG(GFP_NOFS) + __GFP_COMPOSITE_FLAG(GFP_KERNEL) + __GFP_COMPOSITE_FLAG(GFP_TEMPORARY) + __GFP_COMPOSITE_FLAG(GFP_USER) + __GFP_COMPOSITE_FLAG(GFP_HIGHUSER) + __GFP_COMPOSITE_FLAG(GFP_HIGHUSER_MOVABLE) + __GFP_COMPOSITE_FLAG(GFP_THISNODE) + __GFP_COMPOSITE_FLAG(GFP_DMA) + __GFP_COMPOSITE_FLAG(GFP_DMA32) + +/* GFP BitMasks */ + + __GFP_BITMASKS(__GFP_DMA) + __GFP_BITMASKS(__GFP_HIGHMEM) + __GFP_BITMASKS(__GFP_MOVABLE) + __GFP_BITMASKS(__GFP_WAIT) + __GFP_BITMASKS(__GFP_HIGH) + __GFP_BITMASKS(__GFP_IO) + __GFP_BITMASKS(__GFP_FS) + __GFP_BITMASKS(__GFP_COLD) + __GFP_BITMASKS(__GFP_NOWARN) + __GFP_BITMASKS(__GFP_REPEAT) + __GFP_BITMASKS(__GFP_NOFAIL) + __GFP_BITMASKS(__GFP_COMP) + __GFP_BITMASKS(__GFP_ZERO) + __GFP_BITMASKS(__GFP_NOMEMALLOC) + __GFP_BITMASKS(__GFP_HARDWALL) + __GFP_BITMASKS(__GFP_THISNODE) + __GFP_BITMASKS(__GFP_RECLAIMABLE) + __GFP_BITMASKS(__GFP_NOTRACK) + +%} + +/* The Formal Parameters will be displayed if available, otherwise \ + "0" or "unknown" will be displayed */ + +probe __vm.kmalloc.tp = kernel.trace("kmalloc") { + name = "kmalloc" + call_site = $call_site + caller_function = symname(call_site) + bytes_req = $bytes_req + bytes_alloc = $bytes_alloc + gfp_flags = $gfp_flags + gfp_flag_name = __gfp_flag_str($gfp_flags) + ptr = $ptr +} + +/* It is unsafe to invoke __builtin_return_address() \ +presently(to get call_site for kporbe based probes) \ +and that it can be improved later when fix for bugs bz#6961 and bz#6580 is available. */ + +probe __vm.kmalloc.kp = kernel.function("kmalloc").return { + name = "kmalloc" + call_site = 0 + caller_function = "unknown" + bytes_req = $size + bytes_alloc = "unknown" + gfp_flags = $gfp_flags + gfp_flag_name = __gfp_flag_str($flags) + ptr = $return +} + +/** + * probe vm.kmalloc - Fires when kmalloc is requested. + * @call_site: Address of the kmemory function. + * @caller_function: Name of the caller function. + * @bytes_req: Requested Bytes + * @bytes_alloc: Allocated Bytes + * @gfp_flags: type of kmemory to allocate + * @gfp_flag_name: type of kmemory to allocate (in String format) + * @ptr: Pointer to the kmemory allocated + */ +probe vm.kmalloc = __vm.kmalloc.tp !, + __vm.kmalloc.kp +{} + + +probe __vm.kmem_cache_alloc.tp = kernel.trace("kmem_cache_alloc") { + name = "kmem_cache_alloc" + call_site = $call_site + caller_function = symname(call_site) + bytes_req = $bytes_req + bytes_alloc = $bytes_alloc + gfp_flags = $gfp_flags + gfp_flag_name = __gfp_flag_str($gfp_flags) + ptr = $ptr +} + +probe __vm.kmem_cache_alloc.kp = kernel.function("kmem_cache_alloc").return { + name = "kmem_cache_alloc" + call_site = 0 + caller_function = "unknown" + bytes_req = $size + bytes_alloc = "unknown" + gfp_flags = $gfp_flags + gfp_flag_name = __gfp_flag_str($flags) + ptr = $return +} + +/** + * probe vm.kmem_cache_alloc - Fires when \ + * kmem_cache_alloc is requested. + * @call_site: Address of the function calling this kmemory function. + * @caller_function: Name of the caller function. + * @bytes_req: Requested Bytes + * @bytes_alloc: Allocated Bytes + * @gfp_flags: type of kmemory to allocate + * @gfp_flag_name: Type of kmemory to allocate(in string format) + * @ptr: Pointer to the kmemory allocated + */ + +probe vm.kmem_cache_alloc = __vm.kmem_cache_alloc.tp !, + __vm.kmem_cache_alloc.kp +{} + +probe __vm.kmalloc_node.tp = kernel.trace("kmalloc_node")? { + name = "kmalloc_node" + call_site = $call_site + caller_function = symname(call_site) + bytes_req = $bytes_req + bytes_alloc = $bytes_alloc + gfp_flags = $gfp_flags + gfp_flag_name = __gfp_flag_str($gfp_flags) + ptr = $ptr +} + +probe __vm.kmalloc_node.kp = kernel.function("kmalloc_node").return? { + name = "kmalloc_node" + call_site = 0 + caller_function = "unknown" + bytes_req = $size + bytes_alloc = "unknown" + gfp_flags = $gfp_flags + gfp_flag_name = __gfp_flag_str($flags) + ptr = $return +} + +/** + * probe vm.kmalloc_node - Fires when kmalloc_node is requested. + * @call_site: Address of the function caling this kmemory function. + * @caller_function: Name of the caller function. + * @bytes_req: Requested Bytes + * @bytes_alloc: Allocated Bytes + * @gfp_flags: type of kmemory to allocate + * @gfp_flag_name: Type of kmemory to allocate(in string format) + * @ptr: Pointer to the kmemory allocated + */ +probe vm.kmalloc_node = __vm.kmalloc_node.tp !, + __vm.kmalloc_node.kp +{} + +probe __vm.kmem_cache_alloc_node.tp = kernel.trace("kmem_cache_alloc_node")? { + name = "kmem_cache_alloc_node" + call_site = $call_site + caller_function = symname(call_site) + bytes_req = $bytes_req + bytes_alloc = $bytes_alloc + gfp_flags = $gfp_flags + gfp_flag_name =__gfp_flag_str($gfp_flags) + ptr = $ptr +} + +probe __vm.kmem_cache_alloc_node.kp = kernel.function("kmem_cache_alloc_node").return? { + name = "kmem_cache_alloc_node" + call_site = 0 + caller_function = "unknown" + bytes_req = $size + bytes_alloc = "unknown" + gfp_flags = $gfp_flags + gfp_flag_name =__gfp_flag_str($flags) + ptr = $return +} + +/** + * probe vm.kmem_cache_alloc_node - Fires when \ + * kmem_cache_alloc_node is requested. + * @call_site: Address of the function calling this kmemory function. + * @caller_function: Name of the caller function. + * @bytes_req: Requested Bytes + * @bytes_alloc: Allocated Bytes + * @gfp_flags: type of kmemory to allocate + * @gfp_flag_name: Type of kmemory to allocate(in string format) + * @ptr: Pointer to the kmemory allocated + */ +probe vm.kmem_cache_alloc_node = __vm.kmem_cache_alloc_node.tp !, + __vm.kmem_cache_alloc_node.kp +{} + + +probe __vm.kfree.tp = kernel.trace("kfree") { + name = "kfree" + call_site = $call_site + caller_function = symname(call_site) + ptr = $ptr +} + +probe __vm.kfree.kp = kernel.function("kfree").return { + name = "kfree" + call_site = 0 + caller_function = "unknown" + ptr = $return +} + +/** + * probe vm.kfree - Fires when kfree is requested. + * @call_site: Address of the function calling this kmemory function. + * @caller_function: Name of the caller function. + * @ptr: Pointer to the kmemory allocated which is returned by kmalloc + */ +probe vm.kfree = __vm.kfree.tp !, + __vm.kfree.kp +{} + +probe __vm.kmem_cache_free.tp = kernel.trace("kmem_cache_free") { + name = "kmem_cache_free" + call_site = $call_site + caller_function = symname(call_site) + ptr = $ptr +} +probe __vm.kmem_cache_free.kp = kernel.function("kmem_cache_free").return { + name = "kmem_cache_free" + call_site = 0 + caller_function = "unknown" + ptr = $return +} +/** + * probe vm.kmem_cache_free - Fires when \ + * kmem_cache_free is requested. + * @call_site: Address of the function calling this kmemory function. + * @caller_function: Name of the caller function. + * @ptr: Pointer to the kmemory allocated which is returned by kmem_cache + */ +probe vm.kmem_cache_free = __vm.kmem_cache_free.tp !, + __vm.kmem_cache_free.kp +{} diff -rupaN a/testsuite/buildok/vm.tracepoints.stp b/testsuite/buildok/vm.tracepoints.stp --- a/testsuite/buildok/vm.tracepoints.stp 1969-12-31 19:00:00.000000000 -0500 +++ b/testsuite/buildok/vm.tracepoints.stp 2009-10-16 01:19:26.000000000 -0400 @@ -0,0 +1,31 @@ +#! stap -up4 + +probe vm.kfree { + println(name) + printf("%-15s %-15p %-15s %-15p \n", execname(), call_site, caller_function, ptr) +} + +probe vm.kmalloc { + println(name) + printf("%-15s %-15p %-15s %-15p %-15d %-15d %-15d %-15s \n", execname(), call_site, caller_function, ptr, bytes_req, bytes_alloc, gfp_flags, gfp_flag_name) +} + +probe vm.kmem_cache_alloc { + println(name) + printf("%-15s %-15p %-15s %-15p %-15d %-15d %-15d %-15s \n", execname(), call_site, caller_function, ptr, bytes_req, bytes_alloc, gfp_flags, gfp_flag_name) +} + +probe vm.kmalloc_node { + println(name) + printf("%-15s %-15p %-15s %-15p %-15d %-15d %-15d %-15s \n", execname(), call_site, caller_function, ptr, bytes_req, bytes_alloc, gfp_flags, gfp_flag_name) +} + +probe vm.kmem_cache_alloc_node { + println(name) + printf("%-15s %-15p %-15s %-15p %-15d %-15d %-15d %-15s \n", execname(), call_site, caller_function, ptr, bytes_req, bytes_alloc, gfp_flags, gfp_flag_name) +} + +probe vm.kmem_cache_free { + println(name) + printf("%-15s %-15p %-15s %-15p \n", execname(), call_site, caller_function, ptr) +} Thanks -- Rajasekhar Duddu (rajduddu@linux.vnet.ibm.com), Linux on System z - CSVT, IBM LTC, Bangalore.