Subject: uvm_cnt replacement
To: None <tech-kern@netbsd.org>
From: Andrey Petrov <petrov@netbsd.org>
List: tech-kern
Date: 04/30/2004 14:29:03
Here is a replacement for uvm counters with evcnt. Please
review and let me know if you see drawbacks in approach or
anything.

Thanks,
	Andrey

Index: uvm/uvm_map.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_map.c,v
retrieving revision 1.168
diff -u -p -r1.168 uvm_map.c
--- uvm/uvm_map.c	27 Apr 2004 09:50:43 -0000	1.168
+++ uvm/uvm_map.c	30 Apr 2004 21:00:59 -0000
@@ -102,11 +102,28 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 
 
 extern struct vm_map *pager_map;
 
-struct uvm_cnt map_ubackmerge, map_uforwmerge;
-struct uvm_cnt map_ubimerge, map_unomerge;
-struct uvm_cnt map_kbackmerge, map_kforwmerge;
-struct uvm_cnt map_kbimerge, map_knomerge;
-struct uvm_cnt uvm_map_call, uvm_mlk_call, uvm_mlk_hint;
+#define UVMMAP_COUNTERS
+#ifdef UVMMAP_COUNTERS
+#include <sys/device.h>
+struct evcnt map_ubackmerge = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "ubackmerge");
+struct evcnt map_uforwmerge = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "uforwmerge");
+struct evcnt map_ubimerge = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "ubimerge");
+struct evcnt map_unomerge = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "unomerge");
+struct evcnt map_kbackmerge = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "kbackmerge");
+struct evcnt map_kforwmerge = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "kforwmerge");
+struct evcnt map_kbimerge = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "kbimerge");
+struct evcnt map_knomerge = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "knomerge");
+struct evcnt uvm_map_call = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "map_call");
+struct evcnt uvm_mlk_call = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "mlk_call");
+struct evcnt uvm_mlk_hint = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "uvmmap", "mlk_hint");
+
+#define UVMCNT_INCR(ev)		ev.ev_count++
+#define UVMCNT_DECR(ev)		ev.ev_count--
+#else
+#define UVMCNT_INCR(ev)
+#define UVMCNT_DECR(ev)
+#endif
+
 const char vmmapbsy[] = "vmmapbsy";
 
 /*
@@ -523,30 +540,20 @@ uvm_map_init(void)
 	UVMHIST_INIT_STATIC(pdhist, pdhistbuf);
 	UVMHIST_CALLED(maphist);
 	UVMHIST_LOG(maphist,"<starting uvm map system>", 0, 0, 0, 0);
-	UVMCNT_INIT(uvm_map_call, UVMCNT_CNT, 0,
-	    "# uvm_map() successful calls", 0);
-
-	UVMCNT_INIT(map_ubackmerge, UVMCNT_CNT, 0,
-	    "# uvm_map() back umerges", 0);
-	UVMCNT_INIT(map_uforwmerge, UVMCNT_CNT, 0,
-	    "# uvm_map() forward umerges", 0);
-	UVMCNT_INIT(map_ubimerge, UVMCNT_CNT, 0,
-	    "# uvm_map() dual umerge", 0);
-	UVMCNT_INIT(map_unomerge, UVMCNT_CNT, 0,
-	    "# uvm_map() no umerge", 0);
-
-	UVMCNT_INIT(map_kbackmerge, UVMCNT_CNT, 0,
-	    "# uvm_map() back kmerges", 0);
-	UVMCNT_INIT(map_kforwmerge, UVMCNT_CNT, 0,
-	    "# uvm_map() forward kmerges", 0);
-	UVMCNT_INIT(map_kbimerge, UVMCNT_CNT, 0,
-	    "# uvm_map() dual kmerge", 0);
-	UVMCNT_INIT(map_knomerge, UVMCNT_CNT, 0,
-	    "# uvm_map() no kmerge", 0);
-
-	UVMCNT_INIT(uvm_mlk_call, UVMCNT_CNT, 0, "# map lookup calls", 0);
-	UVMCNT_INIT(uvm_mlk_hint, UVMCNT_CNT, 0, "# map lookup hint hits", 0);
 
+#ifdef UVMMAP_COUNTERS
+	evcnt_attach_static(&map_ubackmerge);
+	evcnt_attach_static(&map_uforwmerge);
+	evcnt_attach_static(&map_ubimerge);
+	evcnt_attach_static(&map_unomerge);
+	evcnt_attach_static(&map_kbackmerge);
+	evcnt_attach_static(&map_kforwmerge);
+	evcnt_attach_static(&map_kbimerge);
+	evcnt_attach_static(&map_knomerge);
+	evcnt_attach_static(&uvm_map_call);
+	evcnt_attach_static(&uvm_mlk_call);
+	evcnt_attach_static(&uvm_mlk_hint);
+#endif
 	/*
 	 * now set up static pool of kernel map entrys ...
 	 */
Index: uvm/uvm_stat.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_stat.c,v
retrieving revision 1.23
diff -u -p -r1.23 uvm_stat.c
--- uvm/uvm_stat.c	24 Mar 2004 07:55:01 -0000	1.23
+++ uvm/uvm_stat.c	30 Apr 2004 21:00:59 -0000
@@ -54,8 +54,6 @@ __KERNEL_RCSID(0, "$NetBSD: uvm_stat.c,v
  * globals
  */
 
-struct uvm_cnt *uvm_cnt_head = NULL;
-
 #ifdef UVMHIST
 struct uvm_history_head uvm_histories;
 #endif
@@ -192,19 +190,6 @@ uvm_hist(bitmask)
 }
 #endif /* UVMHIST */
 
-void
-uvmcnt_dump()
-{
-	struct uvm_cnt *uvc = uvm_cnt_head;
-
-	while (uvc) {
-		if ((uvc->t & UVMCNT_MASK) != UVMCNT_CNT)
-			continue;
-		printf("%s = %d\n", uvc->name, uvc->c);
-		uvc = uvc->next;
-	}
-}
-
 /*
  * uvmexp_print: ddb hook to print interesting uvm counters
  */
Index: uvm/uvm_stat.h
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_stat.h,v
retrieving revision 1.31
diff -u -p -r1.31 uvm_stat.h
--- uvm/uvm_stat.h	29 Apr 2004 23:13:35 -0000	1.31
+++ uvm/uvm_stat.h	30 Apr 2004 21:00:59 -0000
@@ -48,55 +48,6 @@
  */
 
 /*
- * counters  [XXX: maybe replace event counters with this]
- */
-
-#define UVMCNT_MASK	0xf			/* rest are private */
-#define UVMCNT_CNT	0			/* normal counter */
-#define UVMCNT_DEV	1			/* device event counter */
-
-struct uvm_cnt {
-	int c;					/* the value */
-	int t;					/* type */
-	struct uvm_cnt *next;			/* global list of cnts */
-	char *name;				/* counter name */
-	void *p;				/* private data */
-};
-
-#ifdef _KERNEL
-
-extern struct uvm_cnt *uvm_cnt_head;
-
-/*
- * counter operations.  assume spl is set ok.
- */
-
-#define UVMCNT_INIT(CNT,TYP,VAL,NAM,PRIV) \
-do { \
-	CNT.c = VAL; \
-	CNT.t = TYP; \
-	CNT.next = uvm_cnt_head; \
-	uvm_cnt_head = &CNT; \
-	CNT.name = NAM; \
-	CNT.p = PRIV; \
-} while (/*CONSTCOND*/ 0)
-
-#define UVMCNT_SET(C,V) \
-do { \
-	(C).c = (V); \
-} while (/*CONSTCOND*/ 0)
-
-#define UVMCNT_ADD(C,V) \
-do { \
-	(C).c += (V); \
-} while (/*CONSTCOND*/ 0)
-
-#define UVMCNT_INCR(C) UVMCNT_ADD(C,1)
-#define UVMCNT_DECR(C) UVMCNT_ADD(C,-1)
-
-#endif /* _KERNEL */
-
-/*
  * history/tracing
  */