This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] Tracepoint Tapset for Memory Subsystem


Hi, I have modified the patch according to the comments passed
by Frank and David.

Many thanks to Frank And David.

Changelog:
	Removed the Hardcoded constants in converting GFPFLAGS.
	Added a kprobe based fallback probe to kfree.


Signed-off-by: Rajasekhar Duddu <rajduddu@linux.vnet.ibm.com>
diff -rupaN a/tapset/memory.stp b/tapset/memory.stp
--- a/tapset/memory.stp	2009-09-24 19:01:10.000000000 +0200
+++ b/tapset/memory.stp	2009-09-24 19:13:30.000000000 +0200
@@ -195,3 +195,205 @@ probe vm.brk = kernel.function("do_brk")
 probe vm.oom_kill = kernel.function("__oom_kill_task") {
     task = $p
 }
+#Function to get the call_site for kprobe based kfree probe.
+
+function call_site:long ()
+%{
+        int *ptr ;
+        ptr = __builtin_return_address(0);
+        THIS->__retvalue = *ptr;
+%}
+
+
+/*Function to convert the GFP_FLAGS .*/
+function gfp_f:string (gfp_flag:long)
+%{
+int flags = (int)THIS->gfp_flag;
+
+
+#ifdef __GFP_HIGH
+        if (flags & __GFP_HIGH)
+                strlcat (THIS->__retvalue, "GFP_HIGH",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_WAIT
+        if (flags & __GFP_WAIT)
+                strlcat (THIS->__retvalue, "GFP_WAIT",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_IO
+        if (flags & __GFP_IO)
+                strlcat (THIS->__retvalue, "|GFP_IO",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_FS
+        if (flags & __GFP_FS)
+                strlcat (THIS->__retvalue, "|GFP_FS",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_COLD
+        if (flags & __GFP_COLD)
+                strlcat (THIS->__retvalue, "|GFP_COLD",MAXSTRINGLEN);
+#endif
+#ifdef __GFP_NOWARN
+        if (flags & __GFP_NOWARN)
+                strlcat (THIS->__retvalue, "|GFP_NOWARN",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_REPEAT
+        if (flags & __GFP_REPEAT)
+                strlcat (THIS->__retvalue, "|GFP_REPEAT",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_NOFAIL
+        if (flags & __GFP_NOFAIL)
+                strlcat (THIS->__retvalue, "|GFP_NOFAIL",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_NORETRY
+        if (flags & __GFP_NORETRY)
+                strlcat (THIS->__retvalue, "|GFP_NORETRY",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_COMP
+        if (flags & __GFP_COMP)
+                strlcat (THIS->__retvalue, "|GFP_COMP",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_ZERO
+        if (flags & __GFP_ZERO)
+                strlcat (THIS->__retvalue, "|GFP_ZERO",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_NOMEMALLOC
+        if (flags & __GFP_NOMEMALLOC)
+                strlcat (THIS->__retvalue, "|GFP_NOMEMALLOC",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_HARDWALL
+        if (flags & __GFP_HARDWALL)
+                strlcat (THIS->__retvalue, "|GFP_HARDWALL",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_THISNODE
+        if (flags & __GFP_THISNODE)
+                strlcat (THIS->__retvalue, "|GFP_THISNODE",MAXSTRINGLEN);
+#endif
+
+#ifdef __GFP_RECLAIMABLE
+        if (flags & __GFP_RECLAIMABLE)
+                strlcat (THIS->__retvalue, "|GFP_RECLAIMABLE",MAXSTRINGLEN);
+#endif
+
+
+#ifdef __GFP_NOTRACK
+        if (flags & __GFP_NOTRACK)
+                strlcat (THIS->__retvalue, "|GFP_NOTRACK",MAXSTRINGLEN);
+#endif
+%}
+
+
+/**
+ * probe kmem.kmalloc - Fires when <command>kmalloc</command> is requested.
+ * @call_site: Address of the kmemory function.
+ * @bytes_req: Requested Bytes
+ * @bytes_alloc: Allocated Bytes
+ * @gfp_flags: type of kmemory to allocate
+ * @ptr: Pointer to the kmemory allocated
+ */
+
+probe kmem.kmalloc = kernel.trace("kmalloc") {
+	name = "kmalloc"
+	call_site = symname($call_site)
+	bytes_req = $bytes_req
+	bytes_alloc = $bytes_alloc
+	gfp_flags = gfp_f($gfp_flags)
+	ptr = $ptr
+}
+
+/**
+ * probe kmem.kmem_cache_alloc - Fires when \
+ *		<command>kmem_cache_alloc</command> is requested.
+ * @call_site: Address of the function calling this kmemory function.
+ * @bytes_req: Requested Bytes
+ * @bytes_alloc: Allocated Bytes
+ * @gfp_flags: Type of kmemory to allocate
+ * @ptr: Pointer to the kmemory allocated
+ */
+probe kmem.kmem_cache_alloc = kernel.trace("kmem_cache_alloc") {
+	name = "kmem_cache_alloc"
+	call_site = symname($call_site)
+        bytes_req = $bytes_req
+        bytes_alloc = $bytes_alloc
+	gfp_flags = gfp_f($gfp_flags)
+        ptr = $ptr
+}
+
+
+/**
+ * probe kmem.kmalloc_node - Fires when <command>kmalloc_node</command> is requested.
+ * @call_site: Address of the function caling this  kmemory function.
+ * @bytes_req: Requested Bytes
+ * @bytes_alloc: Allocated Bytes
+ * @gfp_flags: Type of kmemory to allocate
+ * @ptr: Pointer to the kmemory allocated
+ */
+probe kmem.kmalloc_node = kernel.trace("kmalloc_node")? {
+	name = "kmalloc_node"
+	call_site = symname($call_site)
+	bytes_req = $bytes_req
+        bytes_alloc = $bytes_alloc
+        gfp_flags = gfp_f($gfp_flags)
+        ptr = $ptr
+}
+
+/**
+ * probe kmem.kmem_cache_alloc_node - Fires when \
+ *		<command>kmem_cache_alloc_node</command> is requested.
+ * @call_site: Address of the function calling this kmemory function.
+ * @bytes_req: Requested Bytes
+ * @bytes_alloc: Allocated Bytes
+ * @gfp_flags: Type of kmemory to allocate
+ * @ptr: Pointer to the kmemory allocated
+ */
+probe kmem.kmem_cache_alloc_node = kernel.trace("kmem_cache_alloc_node")? {
+	name = "kmem_cache_alloc_node"
+	call_site = symname($call_site)
+        bytes_req = $bytes_req
+	bytes_alloc = $bytes_alloc
+        gfp_flags =gfp_f($gfp_flags)
+        ptr = $ptr
+}
+
+/**
+ * probe kmem.kfree - Fires when <command>kfree</comand> is requested.
+ * @call_site: Address of the function calling this kmemory function.
+ * @ptr: Pointer to the kmemory allocated which is returned by kmalloc
+ */
+probe kmem.kfree.kp = kernel.function("kfree") {
+	name = "kfree"
+	call_site = symname(call_site())
+	ptr = $x
+}
+
+probe kmem.kfree.tp = kernel.trace("kfree") {
+	name = "kfree"
+	call_site = symname($call_site)
+	ptr = $ptr
+}
+
+probe kmem.kfree = kmem.kfree.tp !,
+		   kmem.kfree.kp
+{}
+
+/**
+ * probe kmem.kmem_cache_free - Fires when \
+ *		<command>kmem_cache_free</command> is requested.
+ * @call_site: Address of the function calling this kmemory function.
+ * @ptr: Pointer to the kmemory allocated which is returned by kmem_cache
+ */
+probe kmem.kmem_cache_free = kernel.trace("kmem_cache_free") {
+	name = "kmem_cache_free"
+	call_site = symname($call_site)
+	ptr = $ptr
+}
diff -rupaN a/testsuite/buildok/kmem_tracepoints.stp b/testsuite/buildok/kmem_tracepoints.stp
--- a/testsuite/buildok/kmem_tracepoints.stp	1970-01-01 01:00:00.000000000 +0100
+++ b/testsuite/buildok/kmem_tracepoints.stp	2009-09-24 19:13:40.000000000 +0200
@@ -0,0 +1,34 @@
+#!/usr/bin/stp -up4
+
+probe kmem.kfree {
+	println (name)
+		printf("%-15s %-15s %-15p \n", execname(),call_site,ptr)
+}
+
+probe kmem.kmalloc {
+	        println (name)
+		printf("%-15s %-15s %-15p %-15d %-15d %-15s \n", execname(),call_site,ptr,bytes_req,bytes_alloc,gfp_flags)
+}
+
+probe kmem.kmem_cache_alloc {
+	        println (name)
+		printf("%-15s %-15s %-15p %-15d %-15d %-15s \n", execname(),call_site,ptr,bytes_req,bytes_alloc,gfp_flags)
+}
+probe kmem.kmalloc_node {
+	        println (name)
+		printf("%-15s %-15s %-15p %-15d %-15d %-15s \n", execname(),call_site,ptr,bytes_req,bytes_alloc,gfp_flags)
+}
+
+probe kmem.kmem_cache_alloc_node {
+	        println (name)
+		printf("%-15s %-15s %-15p %-15d %-15d %-15s \n", execname(),call_site,ptr,bytes_req,bytes_alloc,gfp_flags)
+}
+
+probe kmem.kmem_cache_free {
+	        println (name)
+                printf("%-15s %-15s %-15p \n", execname(),call_site,ptr)
+}
+
+probe timer.s(1) {
+                exit()
+}


-- 
Rajasekhar Duddu (rajduddu@linux.vnet.ibm.com),
Linux on System z - CSVT, IBM LTC, Bangalore.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]