Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src adapt the cyclic module and profile dtrace provider to netbsd.
details: https://anonhg.NetBSD.org/src/rev/8743dfd9ddb1
branches: trunk
changeset: 783031:8743dfd9ddb1
user: chs <chs%NetBSD.org@localhost>
date: Sun Dec 02 01:05:16 2012 +0000
description:
adapt the cyclic module and profile dtrace provider to netbsd.
for now, just hook the cyclic callback into hardclock().
diffstat:
external/cddl/osnet/dev/cyclic/cyclic.c | 64 ++++++++++++++++++-
external/cddl/osnet/dev/cyclic/i386/cyclic_machdep.c | 33 ++++++++--
external/cddl/osnet/sys/sys/cyclic_impl.h | 4 +-
sys/kern/kern_clock.c | 19 +++++-
sys/modules/Makefile | 3 +-
sys/modules/cyclic/Makefile | 16 +++++
sys/modules/dtrace/Makefile | 4 +-
sys/modules/dtrace/profile/Makefile | 16 +++++
sys/sys/dtrace_bsd.h | 13 +---
9 files changed, 144 insertions(+), 28 deletions(-)
diffs (truncated from 391 to 300 lines):
diff -r 407265f699da -r 8743dfd9ddb1 external/cddl/osnet/dev/cyclic/cyclic.c
--- a/external/cddl/osnet/dev/cyclic/cyclic.c Sun Dec 02 00:47:37 2012 +0000
+++ b/external/cddl/osnet/dev/cyclic/cyclic.c Sun Dec 02 01:05:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cyclic.c,v 1.3 2012/12/02 00:05:38 chs Exp $ */
+/* $NetBSD: cyclic.c,v 1.4 2012/12/02 01:05:16 chs Exp $ */
/*
* CDDL HEADER START
@@ -326,8 +326,10 @@
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/kernel.h>
+#ifdef __FreeBSD___
#include <sys/lock.h>
#include <sys/sx.h>
+#endif
#include <sys/cyclic_impl.h>
#include <sys/module.h>
#include <sys/systm.h>
@@ -335,7 +337,32 @@
#include <sys/kmem.h>
#include <sys/cmn_err.h>
#include <sys/dtrace_bsd.h>
+#ifdef __FreeBSD__
#include <machine/cpu.h>
+#endif
+
+#ifdef __NetBSD__
+#include <sys/cpu.h>
+#include <sys/malloc.h>
+#include <sys/xcall.h>
+
+#undef mutex_init
+#define mtx_init(m, d, p, f) mutex_init(m, MUTEX_DEFAULT, IPL_CLOCK)
+#define mtx_lock_spin(x) mutex_spin_enter(x)
+#define mtx_unlock_spin(x) mutex_spin_exit(x)
+#define mtx_destroy(x) mutex_destroy(x)
+
+#define ASSERT(x) KASSERT(x)
+#define SYSINIT(a1, a2, a3, a4, a5)
+#define SYSUNINIT(a1, a2, a3, a4, a5)
+#define CPU_FOREACH(var) \
+ CPU_INFO_ITERATOR cii; \
+ struct cpu_info *ci; \
+ for (CPU_INFO_FOREACH(cii, ci))
+#define MAXCPU MAXCPUS
+#define TRAPF_USERMODE(x) CLKF_USERMODE(x)
+#define TRAPF_PC(x) CLKF_PC(x)
+#endif
static kmem_cache_t *cyclic_id_cache;
static cyc_id_t *cyclic_id_head;
@@ -873,7 +900,7 @@
ASSERT(MUTEX_HELD(&cpu_lock));
if (cyclic_id_cache == NULL)
- cyclic_id_cache = kmem_cache_create("cyclic_id_cache",
+ cyclic_id_cache = kmem_cache_create(__UNCONST("cyclic_id_cache"),
sizeof (cyc_id_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
cpu->cyp_cpu = c;
@@ -1110,7 +1137,7 @@
cyclic_add(cyc_handler_t *hdlr, cyc_time_t *when)
{
cyc_id_t *idp = cyclic_new_id();
- solaris_cpu_t *c = &solaris_cpu[curcpu];
+ solaris_cpu_t *c = &solaris_cpu[cpu_number()];
ASSERT(MUTEX_HELD(&cpu_lock));
ASSERT(when->cyt_when >= 0 && when->cyt_interval > 0);
@@ -1217,6 +1244,7 @@
idp->cyi_omni_hdlr = *omni;
CPU_FOREACH(i) {
+ i = cpu_index(ci);
c = &solaris_cpu[i];
if ((cpu = c->cpu_cyclic) == NULL)
continue;
@@ -1305,7 +1333,7 @@
*/
bcopy(be, &cyclic_backend, sizeof (cyc_backend_t));
- cyclic_configure(&solaris_cpu[curcpu]);
+ cyclic_configure(&solaris_cpu[cpu_number()]);
}
/*
@@ -1320,15 +1348,20 @@
cpu_t *c;
int i;
+#ifndef __NetBSD__
mutex_enter(&cpu_lock);
+#endif
CPU_FOREACH(i) {
+ i = cpu_index(ci);
c = &solaris_cpu[i];
if (c->cpu_cyclic == NULL)
cyclic_configure(c);
}
+#ifndef __NetBSD__
mutex_exit(&cpu_lock);
+#endif
}
static void
@@ -1338,6 +1371,7 @@
int id;
CPU_FOREACH(id) {
+ id = cpu_index(ci);
c = &solaris_cpu[id];
if (c->cpu_cyclic == NULL)
continue;
@@ -1379,6 +1413,7 @@
SYSUNINIT(cyclic_unregister, SI_SUB_CYCLIC, SI_ORDER_SECOND, cyclic_unload, NULL);
+#ifdef __FreeBSD__
/* ARGSUSED */
static int
cyclic_modevent(module_t mod __unused, int type, void *data __unused)
@@ -1406,3 +1441,24 @@
DEV_MODULE(cyclic, cyclic_modevent, NULL);
MODULE_VERSION(cyclic, 1);
MODULE_DEPEND(cyclic, opensolaris, 1, 1, 1);
+#endif
+
+#ifdef __NetBSD__
+static int
+cyclic_modcmd(modcmd_t cmd, void *data)
+{
+ switch (cmd) {
+ case MODULE_CMD_INIT:
+ cyclic_load(NULL);
+ return 0;
+
+ case MODULE_CMD_FINI:
+ cyclic_unload();
+ return 0;
+ default:
+ return ENOTTY;
+ }
+}
+
+MODULE(MODULE_CLASS_MISC, cyclic, "dtrace");
+#endif
diff -r 407265f699da -r 8743dfd9ddb1 external/cddl/osnet/dev/cyclic/i386/cyclic_machdep.c
--- a/external/cddl/osnet/dev/cyclic/i386/cyclic_machdep.c Sun Dec 02 00:47:37 2012 +0000
+++ b/external/cddl/osnet/dev/cyclic/i386/cyclic_machdep.c Sun Dec 02 01:05:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cyclic_machdep.c,v 1.3 2012/12/02 00:05:38 chs Exp $ */
+/* $NetBSD: cyclic_machdep.c,v 1.4 2012/12/02 01:05:16 chs Exp $ */
/*-
* Copyright 2006-2008 John Birrell <jb%FreeBSD.org@localhost>
@@ -60,6 +60,9 @@
{
/* Register the cyclic backend. */
cyclic_init(&be);
+#ifdef __NetBSD__
+ cyclic_ap_start(NULL);
+#endif
}
static void
@@ -82,11 +85,11 @@
* initialiser as the callback for high speed timer events.
*/
static void
-cyclic_clock(struct trapframe *frame)
+cyclic_clock(struct clockframe *frame)
{
- cpu_t *c = &solaris_cpu[curcpu];
+ cpu_t *c = &solaris_cpu[cpu_number()];
- if (c->cpu_cyclic != NULL && gethrtime() >= exp_due[curcpu]) {
+ if (c->cpu_cyclic != NULL && gethrtime() >= exp_due[cpu_number()]) {
if (TRAPF_USERMODE(frame)) {
c->cpu_profile_pc = 0;
c->cpu_profile_upc = TRAPF_PC(frame);
@@ -107,23 +110,39 @@
static void enable(cyb_arg_t arg)
{
/* Register the cyclic clock callback function. */
- cyclic_clock_func[curcpu] = cyclic_clock;
+ cyclic_clock_func[cpu_number()] = cyclic_clock;
}
static void disable(cyb_arg_t arg)
{
/* Reset the cyclic clock callback function. */
- cyclic_clock_func[curcpu] = NULL;
+ cyclic_clock_func[cpu_number()] = NULL;
}
static void reprogram(cyb_arg_t arg, hrtime_t exp)
{
- exp_due[curcpu] = exp;
+ exp_due[cpu_number()] = exp;
}
+#ifdef __NetBSD__
+static void xcall_func(void *arg0, void *arg1)
+{
+ cyc_func_t func;
+
+ func = arg0;
+ (*func)(arg1);
+}
+#endif
+
static void xcall(cyb_arg_t arg, cpu_t *c, cyc_func_t func, void *param)
{
+#ifdef __NetBSD__
+ uint64_t xc;
+ xc = xc_unicast(XC_HIGHPRI, xcall_func, func, param, cpu_lookup(c->cpuid));
+ xc_wait(xc);
+#else
smp_rendezvous_cpus((cpumask_t) (1 << c->cpuid),
smp_no_rendevous_barrier, func, smp_no_rendevous_barrier, param);
+#endif
}
diff -r 407265f699da -r 8743dfd9ddb1 external/cddl/osnet/sys/sys/cyclic_impl.h
--- a/external/cddl/osnet/sys/sys/cyclic_impl.h Sun Dec 02 00:47:37 2012 +0000
+++ b/external/cddl/osnet/sys/sys/cyclic_impl.h Sun Dec 02 01:05:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cyclic_impl.h,v 1.3 2012/12/02 00:05:39 chs Exp $ */
+/* $NetBSD: cyclic_impl.h,v 1.4 2012/12/02 01:05:16 chs Exp $ */
/*
* CDDL HEADER START
@@ -269,7 +269,7 @@
cyc_index_t cyp_nelems;
cyc_index_t cyp_size;
cyc_backend_t *cyp_backend;
- struct mtx cyp_mtx;
+ kmutex_t cyp_mtx;
} cyc_cpu_t;
typedef struct cyc_omni_cpu {
diff -r 407265f699da -r 8743dfd9ddb1 sys/kern/kern_clock.c
--- a/sys/kern/kern_clock.c Sun Dec 02 00:47:37 2012 +0000
+++ b/sys/kern/kern_clock.c Sun Dec 02 01:05:16 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_clock.c,v 1.130 2011/10/30 01:57:40 christos Exp $ */
+/* $NetBSD: kern_clock.c,v 1.131 2012/12/02 01:05:16 chs Exp $ */
/*-
* Copyright (c) 2000, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,8 +69,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_clock.c,v 1.130 2011/10/30 01:57:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_clock.c,v 1.131 2012/12/02 01:05:16 chs Exp $");
+#include "opt_dtrace.h"
#include "opt_ntp.h"
#include "opt_perfctrs.h"
@@ -93,6 +94,13 @@
#include <sys/gmon.h>
#endif
+#ifdef KDTRACE_HOOKS
+#include <sys/dtrace_bsd.h>
+#include <sys/cpu.h>
+
+cyclic_clock_func_t cyclic_clock_func[MAXCPUS];
+#endif
+
/*
* Clock handling routines.
*
@@ -225,6 +233,13 @@
* Update real-time timeout queue.
*/
callout_hardclock();
+
+#ifdef KDTRACE_HOOKS
+ cyclic_clock_func_t func = cyclic_clock_func[cpu_index(ci)];
+ if (func) {
+ (*func)((struct clockframe *)frame);
+ }
+#endif
}
/*
diff -r 407265f699da -r 8743dfd9ddb1 sys/modules/Makefile
--- a/sys/modules/Makefile Sun Dec 02 00:47:37 2012 +0000
+++ b/sys/modules/Makefile Sun Dec 02 01:05:16 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.115 2012/11/06 07:59:09 alnsn Exp $
+# $NetBSD: Makefile,v 1.116 2012/12/02 01:05:16 chs Exp $
Home |
Main Index |
Thread Index |
Old Index