Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Feb 2008 05:19:03 GMT
From:      John Birrell <jb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 135366 for review
Message-ID:  <200802140519.m1E5J39C005170@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=135366

Change 135366 by jb@jb_freebsd1 on 2008/02/14 05:18:40

	Add probes for the dtmalloc DTrace provider.

Affected files ...

.. //depot/projects/dtrace/src/sys/kern/kern_malloc.c#7 edit

Differences ...

==== //depot/projects/dtrace/src/sys/kern/kern_malloc.c#7 (text+ko) ====

@@ -46,6 +46,7 @@
 __FBSDID("$FreeBSD: src/sys/kern/kern_malloc.c,v 1.162 2007/06/27 13:39:38 rwatson Exp $");
 
 #include "opt_ddb.h"
+#include "opt_kdtrace.h"
 #include "opt_vm.h"
 
 #include <sys/param.h>
@@ -86,6 +87,12 @@
 
 #include <ddb/ddb.h>
 
+#ifdef KDTRACE_HOOKS
+#include <sys/dtrace_bsd.h>
+
+dtrace_malloc_probe_func_t	dtrace_malloc_probe;
+#endif
+
 /*
  * When realloc() is called, if the new size is sufficiently smaller than
  * the old size, realloc() will allocate a new, smaller block to avoid
@@ -255,6 +262,15 @@
 	}
 	if (zindx != -1)
 		mtsp->mts_size |= 1 << zindx;
+
+#ifdef KDTRACE_HOOKS
+	if (dtrace_malloc_probe != NULL &&
+	    mtip->mti_probes[DTMALLOC_PROBE_MALLOC] != 0)
+		(dtrace_malloc_probe)(mtip->mti_probes[DTMALLOC_PROBE_MALLOC],
+		    (uintptr_t) mtp, (uintptr_t) mtip,
+		    (uintptr_t) mtsp, size, zindx);
+#endif
+
 	critical_exit();
 }
 
@@ -283,6 +299,15 @@
 	mtsp = &mtip->mti_stats[curcpu];
 	mtsp->mts_memfreed += size;
 	mtsp->mts_numfrees++;
+
+#ifdef KDTRACE_HOOKS
+	if (dtrace_malloc_probe != NULL &&
+	    mtip->mti_probes[DTMALLOC_PROBE_MALLOC] != 0)
+		(dtrace_malloc_probe)(mtip->mti_probes[DTMALLOC_PROBE_FREE],
+		    (uintptr_t) mtp, (uintptr_t) mtip,
+		    (uintptr_t) mtsp, size, 0);
+#endif
+
 	critical_exit();
 }
 
@@ -804,6 +829,40 @@
 SYSCTL_INT(_kern, OID_AUTO, malloc_count, CTLFLAG_RD, &kmemcount, 0,
     "Count of kernel malloc types");
 
+void
+malloc_type_list(malloc_type_list_func_t *func, void *arg)
+{
+	struct malloc_type *mtp, **bufmtp;
+	int count, i;
+	size_t buflen;
+
+	mtx_lock(&malloc_mtx);
+restart:
+	mtx_assert(&malloc_mtx, MA_OWNED);
+	count = kmemcount;
+	mtx_unlock(&malloc_mtx);
+
+	buflen = sizeof(struct malloc_type *) * count;
+	bufmtp = malloc(buflen, M_TEMP, M_WAITOK);
+
+	mtx_lock(&malloc_mtx);
+
+	if (count < kmemcount) {
+		free(bufmtp, M_TEMP);
+		goto restart;
+	}
+
+	for (mtp = kmemstatistics, i = 0; mtp != NULL; mtp = mtp->ks_next, i++)
+		bufmtp[i] = mtp;
+
+	mtx_unlock(&malloc_mtx);
+
+	for (i = 0; i < count; i++)
+		(func)(bufmtp[i], arg);
+
+	free(bufmtp, M_TEMP);
+}
+
 #ifdef DDB
 DB_SHOW_COMMAND(malloc, db_show_malloc)
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802140519.m1E5J39C005170>