Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys introduce a new function that returns a unique string fo...



details:   https://anonhg.NetBSD.org/src/rev/dfba7f4a44de
branches:  trunk
changeset: 750755:dfba7f4a44de
user:      mrg <mrg%NetBSD.org@localhost>
date:      Wed Jan 13 01:57:17 2010 +0000

description:
introduce a new function that returns a unique string for each cpu:

        char *cpu_name(struct cpu_info *);

and use it when setting up the runq event counters, avoiding an 8 byte
kmem(4) allocation for each cpu.  there are more places the cpuname is
used that can be converted to using this new interface, but that can
and will be done as future work.

as discussed with rmind.

diffstat:

 sys/kern/kern_cpu.c  |   8 ++++++--
 sys/kern/kern_runq.c |  16 ++++++----------
 sys/sys/cpu.h        |   8 +++++++-
 sys/sys/cpu_data.h   |   3 ++-
 4 files changed, 21 insertions(+), 14 deletions(-)

diffs (116 lines):

diff -r d7afdff9e514 -r dfba7f4a44de sys/kern/kern_cpu.c
--- a/sys/kern/kern_cpu.c       Wed Jan 13 01:53:38 2010 +0000
+++ b/sys/kern/kern_cpu.c       Wed Jan 13 01:57:17 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_cpu.c,v 1.42 2009/04/19 14:11:37 ad Exp $ */
+/*     $NetBSD: kern_cpu.c,v 1.43 2010/01/13 01:57:17 mrg Exp $        */
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.42 2009/04/19 14:11:37 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.43 2010/01/13 01:57:17 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -111,6 +111,10 @@
        TAILQ_INIT(&ci->ci_data.cpu_ld_locks);
        __cpu_simple_lock_init(&ci->ci_data.cpu_ld_lock);
 
+       /* This is useful for eg, per-cpu evcnt */
+       snprintf(ci->ci_data.cpu_name, sizeof(ci->ci_data.cpu_name), "cpu%d",
+                cpu_index(ci));
+
        sched_cpuattach(ci);
 
        error = create_idle_lwp(ci);
diff -r d7afdff9e514 -r dfba7f4a44de sys/kern/kern_runq.c
--- a/sys/kern/kern_runq.c      Wed Jan 13 01:53:38 2010 +0000
+++ b/sys/kern/kern_runq.c      Wed Jan 13 01:57:17 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_runq.c,v 1.28 2009/12/30 23:49:59 rmind Exp $     */
+/*     $NetBSD: kern_runq.c,v 1.29 2010/01/13 01:57:17 mrg Exp $       */
 
 /*
  * Copyright (c) 2007, 2008 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.28 2009/12/30 23:49:59 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.29 2010/01/13 01:57:17 mrg Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -147,7 +147,6 @@
        runqueue_t *ci_rq;
        void *rq_ptr;
        u_int i, size;
-       char *cpuname;
 
        if (ci->ci_schedstate.spc_lwplock == NULL) {
                ci->ci_schedstate.spc_lwplock =
@@ -180,17 +179,14 @@
 
        ci->ci_schedstate.spc_sched_info = ci_rq;
 
-       cpuname = kmem_alloc(8, KM_SLEEP);
-       snprintf(cpuname, 8, "cpu%d", cpu_index(ci));
-
        evcnt_attach_dynamic(&ci_rq->r_ev_pull, EVCNT_TYPE_MISC, NULL,
-          cpuname, "runqueue pull");
+          cpu_name(ci), "runqueue pull");
        evcnt_attach_dynamic(&ci_rq->r_ev_push, EVCNT_TYPE_MISC, NULL,
-          cpuname, "runqueue push");
+          cpu_name(ci), "runqueue push");
        evcnt_attach_dynamic(&ci_rq->r_ev_stay, EVCNT_TYPE_MISC, NULL,
-          cpuname, "runqueue stay");
+          cpu_name(ci), "runqueue stay");
        evcnt_attach_dynamic(&ci_rq->r_ev_localize, EVCNT_TYPE_MISC, NULL,
-          cpuname, "runqueue localize");
+          cpu_name(ci), "runqueue localize");
 }
 
 /*
diff -r d7afdff9e514 -r dfba7f4a44de sys/sys/cpu.h
--- a/sys/sys/cpu.h     Wed Jan 13 01:53:38 2010 +0000
+++ b/sys/sys/cpu.h     Wed Jan 13 01:57:17 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.30 2009/04/19 14:11:37 ad Exp $      */
+/*     $NetBSD: cpu.h,v 1.31 2010/01/13 01:57:17 mrg Exp $     */
 
 /*-
  * Copyright (c) 2007 YAMAMOTO Takashi,
@@ -93,6 +93,12 @@
        return ci->ci_index;
 }
 
+static inline char *
+cpu_name(struct cpu_info *ci)
+{
+       return ci->ci_data.cpu_name;
+}
+
 #endif /* !_LOCORE */
 
 /* flags for cpu_need_resched */
diff -r d7afdff9e514 -r dfba7f4a44de sys/sys/cpu_data.h
--- a/sys/sys/cpu_data.h        Wed Jan 13 01:53:38 2010 +0000
+++ b/sys/sys/cpu_data.h        Wed Jan 13 01:57:17 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu_data.h,v 1.27 2008/06/03 15:50:22 ad Exp $ */
+/*     $NetBSD: cpu_data.h,v 1.28 2010/01/13 01:57:17 mrg Exp $        */
 
 /*-
  * Copyright (c) 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -96,6 +96,7 @@
        __cpu_simple_lock_t cpu_ld_lock;        /* lockdebug */
        uint64_t        cpu_cc_freq;            /* cycle counter frequency */
        int64_t         cpu_cc_skew;            /* counter skew vs cpu0 */
+       char            cpu_name[8];            /* eg, "cpu4" */
 };
 
 /* compat definitions */



Home | Main Index | Thread Index | Old Index