Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Dec 2007 02:46:08 GMT
From:      John Birrell <jb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 131403 for review
Message-ID:  <200712220246.lBM2k8qD096323@repoman.freebsd.org>

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

Change 131403 by jb@jb_freebsd1 on 2007/12/22 02:46:02

	Port the front end of the cyclic timer device. It needs the backend
	to be functional. Stay tuned.

Affected files ...

.. //depot/projects/dtrace/src/sys/contrib/opensolaris/uts/common/os/cyclic.c#5 edit
.. //depot/projects/dtrace/src/sys/contrib/opensolaris/uts/common/sys/cyclic.h#5 edit
.. //depot/projects/dtrace/src/sys/modules/cyclic/Makefile#4 edit

Differences ...

==== //depot/projects/dtrace/src/sys/contrib/opensolaris/uts/common/os/cyclic.c#5 (text) ====

@@ -561,6 +561,11 @@
 
 #if defined(sun)
 #include <sys/ddi.h>
+#else
+#include <sys/dtrace_bsd.h>
+#define gethrtime_unscaled	dtrace_gethrtime
+static cyclic_cpu_t	cyclic_cpu[MAXCPU];
+static kmutex_t		cpu_lock;
 #endif
 
 #ifdef CYCLIC_TRACE
@@ -1271,7 +1276,7 @@
 	/*
 	 * Assert that the new size is a power of 2.
 	 */
-	ASSERT((new_size & new_size - 1) == 0);
+	ASSERT((new_size & (new_size - 1)) == 0);
 	ASSERT(new_size == (size << 1));
 	ASSERT(cpu->cyp_heap != NULL && cpu->cyp_cyclics != NULL);
 
@@ -1369,7 +1374,7 @@
 	/*
 	 * Check that the new_size is a power of 2.
 	 */
-	ASSERT((new_size - 1 & new_size) == 0);
+	ASSERT(((new_size - 1) & new_size) == 0);
 
 	new_heap = kmem_alloc(sizeof (cyc_index_t) * new_size, KM_SLEEP);
 	new_cyclics = kmem_zalloc(sizeof (cyclic_t) * new_size, KM_SLEEP);
@@ -1457,6 +1462,7 @@
 static cyc_cpu_t *
 cyclic_pick_cpu(cpupart_t *part, cpu_t *bound, cpu_t *avoid, uint16_t flags)
 {
+#if defined(sun)
 	cpu_t *c, *start = (part != NULL) ? part->cp_cpulist : CPU;
 	cpu_t *online = NULL;
 	uintptr_t offset;
@@ -1548,6 +1554,13 @@
 	CYC_PTRACE("pick-cpu-found", c, avoid);
 	ASSERT(c != avoid);
 	ASSERT(c->cpu_cyclic != NULL);
+#else
+	/*
+	 * FreeBSD doesn't have cpu partitions, so just use the current
+	 * CPU for now.
+	 */
+	cyclic_cpu_t *c = &cyclic_cpu[curcpu];
+#endif
 
 	return (c->cpu_cyclic);
 }
@@ -1910,7 +1923,11 @@
 		/*
 		 * Before we begin this operation, disable kernel preemption.
 		 */
+#if defined(sun)
 		kpreempt_disable();
+#else
+		critical_enter();
+#endif
 		if (cyclic_remove_here(src, ndx, &when, CY_NOWAIT))
 			break;
 
@@ -1918,14 +1935,22 @@
 		 * The operation failed; enable kernel preemption while
 		 * spinning.
 		 */
+#if defined(sun)
 		kpreempt_enable();
+#else
+		critical_exit();
+#endif
 
 		CYC_PTRACE("remove-retry", idp, src);
 
 		if (delay > (cyclic->cy_interval >> 1))
 			delay = cyclic->cy_interval >> 1;
 
+#if defined(sun)
 		drv_usecwait((clock_t)(delay / (NANOSEC / MICROSEC)));
+#else
+		DELAY(delay);
+#endif
 	}
 
 	/*
@@ -1935,7 +1960,11 @@
 	 */
 	idp->cyi_ndx = cyclic_add_here(dest, &hdlr, &when, flags);
 	idp->cyi_cpu = dest;
+#if defined(sun)
 	kpreempt_enable();
+#else
+	critical_exit();
+#endif
 }
 
 static int
@@ -1945,7 +1974,11 @@
 	cyc_cpu_t *cpu = idp->cyi_cpu, *dest;
 	cyclic_t *cyclic = &cpu->cyp_cyclics[ndx];
 	cpu_t *c = cpu->cyp_cpu;
+#if defined(sun)
 	cpupart_t *part = c->cpu_part;
+#else
+	void *part = NULL;
+#endif
 
 	CYC_PTRACE("juggle-one", idp, cpu);
 	ASSERT(MUTEX_HELD(&cpu_lock));
@@ -1966,6 +1999,7 @@
 	return (1);
 }
 
+#if defined(sun)
 static void
 cyclic_unbind_cpu(cyclic_id_t id)
 {
@@ -1995,7 +2029,9 @@
 		    (!res && (cyclic->cy_flags & CYF_PART_BOUND)));
 	}
 }
+#endif
 
+#if defined(sun)
 static void
 cyclic_bind_cpu(cyclic_id_t id, cpu_t *d)
 {
@@ -2024,7 +2060,9 @@
 
 	cyclic->cy_flags |= CYF_CPU_BOUND;
 }
+#endif
 
+#if defined(sun)
 static void
 cyclic_unbind_cpupart(cyclic_id_t id)
 {
@@ -2077,6 +2115,7 @@
 
 	cyc->cy_flags |= CYF_PART_BOUND;
 }
+#endif
 
 static void
 cyclic_configure(cpu_t *c)
@@ -2094,7 +2133,11 @@
 
 	cpu->cyp_cpu = c;
 
+#if defined(sun)
 	sema_init(&cpu->cyp_modify_wait, 0, NULL, SEMA_DEFAULT, NULL);
+#else
+	sema_init(&cpu->cyp_modify_wait, 0, NULL);
+#endif
 
 	cpu->cyp_size = 1;
 	cpu->cyp_heap = kmem_zalloc(sizeof (cyc_index_t), KM_SLEEP);
@@ -2129,6 +2172,7 @@
 	c->cpu_cyclic = cpu;
 }
 
+#if defined(sun)
 static void
 cyclic_unconfigure(cpu_t *c)
 {
@@ -2181,7 +2225,9 @@
 
 	c->cpu_cyclic = NULL;
 }
+#endif
 
+#if defined(sun)
 static int
 cyclic_cpu_setup(cpu_setup_t what, int id)
 {
@@ -2211,6 +2257,7 @@
 
 	return (0);
 }
+#endif
 
 static void
 cyclic_suspend_xcall(cyc_xcallarg_t *arg)
@@ -2355,7 +2402,7 @@
 }
 
 static cyc_id_t *
-cyclic_new_id()
+cyclic_new_id(void)
 {
 	cyc_id_t *idp;
 
@@ -2577,24 +2624,42 @@
 	cyc_id_t *idp = cyclic_new_id();
 	cyc_cpu_t *cpu;
 	cpu_t *c;
+#if !defined(sun)
+	int i;
+#endif
 
 	ASSERT(MUTEX_HELD(&cpu_lock));
 	ASSERT(omni != NULL && omni->cyo_online != NULL);
 
 	idp->cyi_omni_hdlr = *omni;
 
+#if defined(sun)
 	c = cpu_list;
 	do {
+#else
+	for (i = 0; i < MAXCPU; i++) {
+		if (pcpu_find(i) == NULL)
+			continue;
+
+		c = &cyclic_cpu[i];
+#endif
+
 		if ((cpu = c->cpu_cyclic) == NULL)
 			continue;
 
+#if defined(sun)
 		if (cpu->cyp_state != CYS_ONLINE) {
 			ASSERT(cpu->cyp_state == CYS_OFFLINE);
 			continue;
 		}
+#endif
 
 		cyclic_omni_start(idp, cpu);
+#if defined(sun)
 	} while ((c = c->cpu_next) != cpu_list);
+#else
+	}
+#endif
 
 	/*
 	 * We must have found at least one online CPU on which to run
@@ -2668,6 +2733,7 @@
 	kmem_cache_free(cyclic_id_cache, idp);
 }
 
+#if defined(sun)
 /*
  *  void cyclic_bind(cyclic_id_t, cpu_t *, cpupart_t *)
  *
@@ -2788,6 +2854,7 @@
 	if (!(flags & CYF_PART_BOUND) && part != NULL)
 		cyclic_bind_cpupart(id, part);
 }
+#endif
 
 hrtime_t
 cyclic_getres()
@@ -2809,6 +2876,7 @@
 	 */
 	bcopy(be, &cyclic_backend, sizeof (cyc_backend_t));
 
+#if defined(sun)
 	/*
 	 * It's safe to look at the "CPU" pointer without disabling kernel
 	 * preemption; cyclic_init() is called only during startup by the
@@ -2816,6 +2884,10 @@
 	 */
 	cyclic_configure(CPU);
 	cyclic_online(CPU);
+#else
+	cyclic_configure(&cyclic_cpu[curcpu]);
+	cyclic_online(&cyclic_cpu[curcpu]);
+#endif
 }
 
 /*
@@ -2828,18 +2900,35 @@
 cyclic_mp_init()
 {
 	cpu_t *c;
+#if !defined(sun)
+	int i;
+#endif
 
 	mutex_enter(&cpu_lock);
 
+#if defined(sun)
 	c = cpu_list;
 	do {
+#else
+	for (i = 0; i < MAXCPU; i++) {
+		if (pcpu_find(i) == NULL)
+			continue;
+
+		c = &cyclic_cpu[i];
+#endif
 		if (c->cpu_cyclic == NULL) {
 			cyclic_configure(c);
 			cyclic_online(c);
 		}
+#if defined(sun)
 	} while ((c = c->cpu_next) != cpu_list);
+#else
+	}
+#endif
 
+#if defined(sun)
 	register_cpu_setup_func((cpu_setup_func_t *)cyclic_cpu_setup, NULL);
+#endif
 	mutex_exit(&cpu_lock);
 }
 
@@ -3020,6 +3109,7 @@
 	}
 }
 
+#if defined(sun)
 /*
  *  void cyclic_move_in(cpu_t *)
  *
@@ -3100,7 +3190,9 @@
 
 	CYC_PTRACE1("move-in-done", dest);
 }
+#endif
 
+#if defined(sun)
 /*
  *  int cyclic_move_out(cpu_t *)
  *
@@ -3183,6 +3275,7 @@
 	CYC_PTRACE1("move-out-done", cpu);
 	return (1);
 }
+#endif
 
 /*
  *  void cyclic_suspend()
@@ -3239,19 +3332,34 @@
 	cyc_cpu_t *cpu;
 	cyc_xcallarg_t arg;
 	cyc_backend_t *be;
+#if !defined(sun)
+	int i;
+#endif
 
 	CYC_PTRACE0("suspend");
 	ASSERT(MUTEX_HELD(&cpu_lock));
+#if defined(sun)
 	c = cpu_list;
 
 	do {
+#else
+	for (i = 0; i < MAXCPU; i++) {
+		if (pcpu_find(i) == NULL)
+			continue;
+
+		c = &cyclic_cpu[i];
+#endif
 		cpu = c->cpu_cyclic;
 		be = cpu->cyp_backend;
 		arg.cyx_cpu = cpu;
 
 		be->cyb_xcall(be->cyb_arg, c,
 		    (cyc_func_t)cyclic_suspend_xcall, &arg);
+#if defined(sun)
 	} while ((c = c->cpu_next) != cpu_list);
+#else
+	}
+#endif
 }
 
 /*
@@ -3291,18 +3399,34 @@
 	cyc_cpu_t *cpu;
 	cyc_xcallarg_t arg;
 	cyc_backend_t *be;
+#if !defined(sun)
+	int i;
+#endif
 
 	CYC_PTRACE0("resume");
 	ASSERT(MUTEX_HELD(&cpu_lock));
 
+#if defined(sun)
 	c = cpu_list;
 
 	do {
+#else
+	for (i = 0; i < MAXCPU; i++) {
+		if (pcpu_find(i) == NULL)
+			continue;
+
+		c = &cyclic_cpu[i];
+#endif
+
 		cpu = c->cpu_cyclic;
 		be = cpu->cyp_backend;
 		arg.cyx_cpu = cpu;
 
 		be->cyb_xcall(be->cyb_arg, c,
 		    (cyc_func_t)cyclic_resume_xcall, &arg);
+#if defined(sun)
 	} while ((c = c->cpu_next) != cpu_list);
+#else
+	}
+#endif
 }

==== //depot/projects/dtrace/src/sys/contrib/opensolaris/uts/common/sys/cyclic.h#5 (text) ====

@@ -36,7 +36,18 @@
 #ifndef _ASM
 #include <sys/time.h>
 #include <sys/cpuvar.h>
+#if defined(sun)
 #include <sys/cpupart.h>
+#else
+struct cyc_cpu;
+#define	cpupart_t	void
+#undef	cpu_t
+#define cpu_t   cyclic_cpu_t
+typedef struct {
+        struct cyc_cpu *cpu_cyclic;
+	uint32_t	cpu_flags;
+} cyclic_cpu_t; 
+#endif
 #endif /* !_ASM */
 
 #define	CY_LOW_LEVEL		0

==== //depot/projects/dtrace/src/sys/modules/cyclic/Makefile#4 (text+ko) ====

@@ -1,9 +1,13 @@
 # $FreeBSD#
 
 .PATH: ${.CURDIR}/../../contrib/opensolaris/uts/common/os
+.PATH: ${.CURDIR}/../../compat/opensolaris/kern
 
 KMOD=		cyclic
-SRCS=		cyclic.c
+SRCS=		cyclic.c		\
+		opensolaris_atomic.c	\
+		opensolaris_kmem.c
+		
 SRCS+=		bus_if.h device_if.h vnode_if.h
 
 CFLAGS+=	-I${.CURDIR}/../../compat/opensolaris \



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