Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Aug 2002 13:34:57 -0700 (PDT)
From:      Jonathan Mini <mini@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 16866 for review
Message-ID:  <200208312034.g7VKYvZO011070@freefall.freebsd.org>

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

Change 16866 by mini@mini_stylus on 2002/08/31 13:33:58

	Add some extra debugging info, and move swapcontext() into
	here for now (while tweaking the context switch operation order).

Affected files ...

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

Differences ...

==== //depot/projects/kse/tools/KSE/uts/uts.c#2 (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#1 $
+ * $P4: //depot/projects/kse/tools/KSE/uts/uts.c#2 $
  */
 
 #include <sys/types.h>
@@ -33,6 +33,7 @@
 #include <sys/ucontext.h>
 
 #include <stdarg.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sysexits.h>
@@ -44,6 +45,8 @@
 static struct kse_mailbox	uts_mb;
 static struct thread_mailbox	*run_queue;
 
+static int progress = 0;
+
 static void	init_uts(void);
 static void	pchar(char c);
 static void	pfmt(const char *fmt, ...);
@@ -53,9 +56,13 @@
 static void	thread_start(const void *func);
 static void	uts(void);
 
+static int	myswapcontext(ucontext_t *oucp, const ucontext_t *ucp,
+		    struct thread_mailbox *p);
+
 void
 aaaa(void)
 {
+	progress++;
 	for (;;) {
 		pchar('.');
 		sleep(1);
@@ -70,7 +77,8 @@
 {
 	int i;
 
-	thread_start(aaaa);
+	pfmt("ofs: %d\n", offsetof(ucontext_t, uc_flags) - offsetof(ucontext_t, uc_mcontext));
+	//thread_start(aaaa);
 	init_uts();
 	for (i = 0;i < 5;i++) {
 		pfmt("main(): %d\n", i);
@@ -98,6 +106,7 @@
 
 	/* Throw us into its context. */
 	getcontext(&tm->tm_context);
+	tm->tm_context.uc_flags = UCF_SKIPSIGMASK | UCF_OBEYBUSY;
 
 	/* Find our stack. */
 	mib[0] = CTL_KERN;
@@ -276,11 +285,18 @@
 		p = runq_remove();
 		if (p != NULL) {
 			pfmt("-- uts() scheduling 0x%x--\n", p);
-			pfmt("eip -> 0x%x\n", p->tm_context.uc_mcontext.mc_eip);
-			uts_mb.km_curthread = p;
-			ret = swapcontext(&uts_mb.km_context, &p->tm_context);
+			pfmt("eip -> 0x%x progress -> %d\n",
+			    p->tm_context.uc_mcontext.mc_eip, progress);
+			pstr("curthread set\n");
+			ret = myswapcontext(&uts_mb.km_context, &p->tm_context,
+			    p);
 			pfmt("\n-- uts() back from swapcontext() [%d] --\n",
 			    ret);
+			if (ret)
+				/*
+				 * Invalid thread context. Exit.
+				 */
+				exit(ret);
 		} else
 			kse_yield();
 	}
@@ -307,3 +323,30 @@
 	tm->tm_context.uc_flags = UCF_SKIPSIGMASK | UCF_OBEYBUSY;
 	runq_insert(tm);
 }
+
+static int
+myswapcontext(ucontext_t *oucp, const ucontext_t *ucp, struct thread_mailbox *p)
+{
+	int ret;
+
+	pfmt("msctx(%x,%x,%x) - %d %d, %x %x, %x %x\n", oucp, ucp, p,
+	    oucp->uc_mcontext.mc_len, ucp->uc_mcontext.mc_len,
+	    oucp->uc_busy, ucp->uc_busy,
+	    oucp->uc_flags, ucp->uc_flags);
+	if ((oucp == NULL) ||
+	    (oucp->uc_mcontext.mc_len != sizeof(mcontext_t)) ||
+	    (ucp == NULL) ||
+	    (ucp->uc_mcontext.mc_len != sizeof(mcontext_t))) {
+		pstr("msctx: EINVAL\n");
+		return (-1);
+	}
+	oucp->uc_flags &= ~UCF_SWAPPED;
+	ret = getcontext(oucp);
+	if ((ret == 0) && !(oucp->uc_flags & UCF_SWAPPED)) {
+		oucp->uc_flags |= UCF_SWAPPED;
+		uts_mb.km_curthread = p;
+		oucp->uc_busy = 0;
+		ret = setcontext(ucp);
+	}
+	return (ret);
+}

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?200208312034.g7VKYvZO011070>