From owner-p4-projects Sat Aug 31 13:35:11 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id AE79C37B401; Sat, 31 Aug 2002 13:34:58 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 361D637B400 for ; Sat, 31 Aug 2002 13:34:58 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id E11B243E6A for ; Sat, 31 Aug 2002 13:34:57 -0700 (PDT) (envelope-from mini@freebsd.org) Received: from freefall.freebsd.org (perforce@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g7VKYvJU011073 for ; Sat, 31 Aug 2002 13:34:57 -0700 (PDT) (envelope-from mini@freebsd.org) Received: (from perforce@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g7VKYvZO011070 for perforce@freebsd.org; Sat, 31 Aug 2002 13:34:57 -0700 (PDT) Date: Sat, 31 Aug 2002 13:34:57 -0700 (PDT) Message-Id: <200208312034.g7VKYvZO011070@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: perforce set sender to mini@freebsd.org using -f From: Jonathan Mini Subject: PERFORCE change 16866 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -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