Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Sep 2002 03:28:19 -0700 (PDT)
From:      Jonathan Mini <mini@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 17230 for review
Message-ID:  <200209081028.g88ASJGR097590@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=17230

Change 17230 by mini@mini_stylus on 2002/09/08 03:27:45

	Add logic to switch back into the UTS from a thread.

Affected files ...

.. //depot/projects/kse/tools/KSE/uts/context.S#2 edit
.. //depot/projects/kse/tools/KSE/uts/uts.c#8 edit

Differences ...

==== //depot/projects/kse/tools/KSE/uts/context.S#2 (text+ko) ====

@@ -33,23 +33,14 @@
 #define	MC_SIZE			640	/* sizeof mcontext_t */
 #define	UC_MC_OFFSET		16	/* offset to mcontext from ucontext */
 #define	UC_MC_LEN_OFFSET	96	/* offset to mc_len from mcontext */
-#define	UC_FLAGS_OFFSET		676	/* offset to uc_flags from ucontext */
-#define	MC_FLAGS_OFFSET		660	/* offset to uc_flags from ucontext */
-#define	MC_BUSY_OFFSET		656	/* offset to uc_busy from ucontext */
 #define	MC_LEN_OFFSET		80	/* offset to mc_len from mcontext */
 #define	MC_FP_REGS_OFFSET	96	/* offset to FP regs from mcontext */
 #define	MC_FP_CW_OFFSET		96	/* offset to FP control word */
 #define	MC_OWNEDFP_OFFSET	88	/* offset to mc_ownedfp from mcontext */
-#define	UCF_SKIPSIGMASK	0x00000001	/* Don't set/restore signal mask. */
-#define	UCF_OBEYBUSY	0x00000002	/* Respect uc_busy marker. */
-#define	UCF_SWAPPED	0x00000080	/* Used by swapcontext(3). */
-#define	UCF_CRITICAL	0x00000200	/* In a critical section. */
-#define	UCF_CLEARSTATE	0x00000400	/* Clear UCF_STATE in setcontext. */
-#define	UCF_STATE	0x0000ff00	/* State-related flags. */
-#define	UCF_OPTIONS	0x000000ff	/* Behaviour-related flags. */
- 
+#define	KM_STACK_SP_OFFSET	32	/* offset to km_stack.ss_sp */
+#define	KM_STACK_SIZE_OFFSET	36	/* offset to km_stack.ss_sp */
+#define	KM_FUNC_OFFSET		28	/* offset to km_func */
  
-
 /*
  * int uts_to_thread(thread_mailbox *tdp, thread_mailbox **curthreadp);
  *
@@ -99,39 +90,19 @@
 	popf				/* flags off stack */
 5:	ret				/* %eip off stack */
 
-#if 0
-	/*
-	 * We'll convert this into a enter_uts() call later.
-	 */
 /*
- * int getcontext(ucontext_t *ucp);
+ * int thread_to_uts(thread_mailbox *tm, kse_mailbox *km);
  *
- *   calls sigprocmask(int how, sigset_t *set, sigset_t *oset);
- *
- * Returns 0 if there are no errors; -1 otherwise
+ * Does not return on success, returns -1 otherwise.
  */
-	.weak CNAME(getcontext)
-	.set CNAME(getcontext),CNAME(__getcontext)
-ENTRY(__getcontext)
+ENTRY(thread_to_uts)
 	movl	4(%esp), %eax		/* get address of context */
 	cmpl	$0, %eax		/* check for null pointer */
 	jne	1f
 	movl	$-1, %eax
-	jmp	3f
-	movl	4(%esp), %eax		/* get address of context and sigset */
-1:	testl $UCF_SKIPSIGMASK, UC_FLAGS_OFFSET(%eax)	/* Save sigmask? */
-	jnz 2f
-	PIC_PROLOGUE
-	pushl	%eax			/* oset = &ucp->uc_sigmask */
-	pushl	$0			/* set = NULL */
-	pushl	$3			/* how = SIG_SETMASK */
-	call	PIC_PLT(CNAME(_sigprocmask))
-	addl	$12, %esp
-	PIC_EPILOGUE
-	testl	%eax, %eax		/* check for error */
-	jnz	3f
-2:	pushl	%edx			/* save value of edx */
-	movl	8(%esp), %edx		/* get address of context */
+	jmp	2f
+1:	pushl	%edx			/* save value of edx */
+	movl	%eax, %edx		/* get address of context */
 	addl	$UC_MC_OFFSET, %edx	/* add offset to mcontext */
 	movl	%gs, 4(%edx)
 	movl	%fs, 8(%edx)
@@ -164,7 +135,12 @@
 	addl	$4, %eax		/*   address onto the top of the */
 	movl	%eax, 72(%edx)		/*   stack; account for this     */
 	movl	$MC_SIZE, MC_LEN_OFFSET(%edx) /* context is now valid */
-	movl	40(%edx), %edx		/* restore edx -- is this needed? */
-	xorl	%eax, %eax		/* return 0 */
-3:	ret
-#endif
+	movl	8(%esp), %edx		/* get address of mailbox */
+	movl	KM_STACK_SP_OFFSET(%edx), %eax	/* get bottom of stack */
+	addl	KM_STACK_SIZE_OFFSET(%edx), %eax /* add length */
+	movl	%eax, %esp		/* switch to the uts's stack */
+	pushl	%edx			/* push the address of the mailbox */
+	pushl	KM_FUNC_OFFSET(%edx)	/* .. the uts can return to itself */
+	pushl	KM_FUNC_OFFSET(%edx)	/* push the address of the uts func */
+2:	ret
+

==== //depot/projects/kse/tools/KSE/uts/uts.c#8 (text+ko) ====

@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $P4: //depot/projects/kse/tools/KSE/uts/uts.c#7 $
+ * $P4: //depot/projects/kse/tools/KSE/uts/uts.c#8 $
  */
 
 #include <sys/types.h>
@@ -63,6 +63,7 @@
 static int progress = 0;
 
 static void	init_uts(void);
+static void	enter_uts(void);
 static void	pchar(char c);
 static void	pfmt(const char *fmt, ...);
 static void	pstr(const char *s);
@@ -80,29 +81,30 @@
 	struct timespec time_remaining;
 
 	time_to_sleep.tv_sec = 0;
-	time_to_sleep.tv_nsec = len * 1000;
+	time_to_sleep.tv_nsec = len * 10000;
 	nanosleep(&time_to_sleep, &time_remaining);
 }
 
-static void
-foof(int sig)
-{
-	pfmt("\n[%d]\n", sig);
-}
-
 void
 aaaa(int c)
 {
 	for (;;) {
-		// pchar(c);
+		pchar(c);
 		nano(1);
 	}
 }
 
+static void
+foof(int sig)
+{
+	pfmt("\n[%d]\n", sig);
+	thread_start(aaaa, '0' + progress++);
+}
+
 void
 spin(int arg)
 {
-	for (;;) sched_yield();
+	for (;;) enter_uts(); sched_yield();
 }
 
 /*
@@ -113,19 +115,35 @@
 {
 	int i;
 
-	thread_start(aaaa, '.');
+	thread_start(spin, '.');
 	// thread_start(spin);
 	init_uts();
 	for (i = 0;1;i++) {
 //		if (i < 1000)
 //			thread_start(aaaa, 'a' + (i % 26));
-		// pchar('A' + (i % 26));
-		nano(1);
+		pchar('A' + (i % 26));
+		nano(5);
 	}
 	pstr("\n** main() exiting **\n");
 	return (EX_OK);
 }
 
+
+/*
+ * Enter the UTS from a thread.
+ */
+static void
+enter_uts(void)
+{
+	struct thread_mailbox	*td;
+
+	/* XXX: We should atomically exchange these two. */
+	td = uts_mb.km_curthread;
+	uts_mb.km_curthread = NULL;
+
+	thread_to_uts(td, &uts_mb);
+}
+
 /*
  * Initialise threading.
  */

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




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