From owner-p4-projects Sat Sep 7 5:23:56 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3D03037B401; Sat, 7 Sep 2002 05:23:22 -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 C1F0C37B400 for ; Sat, 7 Sep 2002 05:23:21 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6A66143E6E for ; Sat, 7 Sep 2002 05:23:21 -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 g87CNLJU083950 for ; Sat, 7 Sep 2002 05:23:21 -0700 (PDT) (envelope-from mini@freebsd.org) Received: (from perforce@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g87CNLUT083947 for perforce@freebsd.org; Sat, 7 Sep 2002 05:23:21 -0700 (PDT) Date: Sat, 7 Sep 2002 05:23:21 -0700 (PDT) Message-Id: <200209071223.g87CNLUT083947@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: perforce set sender to mini@freebsd.org using -f From: Jonathan Mini Subject: PERFORCE change 17193 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=17193 Change 17193 by mini@mini_stylus on 2002/09/07 05:22:54 Deliver caught signals via an upcall to the UTS in KSE processes. Affected files ... .. //depot/projects/kse/lib/libc/i386/gen/signalcontext.c#2 edit .. //depot/projects/kse/sys/kern/kern_sig.c#65 edit .. //depot/projects/kse/sys/kern/kern_thread.c#105 edit .. //depot/projects/kse/sys/sys/proc.h#129 edit .. //depot/projects/kse/tools/KSE/uts/uts.c#7 edit Differences ... ==== //depot/projects/kse/lib/libc/i386/gen/signalcontext.c#2 (text+ko) ==== @@ -31,6 +31,7 @@ #include #include +#include #include #include #include ==== //depot/projects/kse/sys/kern/kern_sig.c#65 (text+ko) ==== @@ -1853,6 +1853,9 @@ p->p_code = 0; p->p_sig = 0; } + if (p->p_flag & P_KSES) + if (signal_upcall(p, sig)) + return; (*p->p_sysent->sv_sendsig)(action, sig, &returnmask, code); } } ==== //depot/projects/kse/sys/kern/kern_thread.c#105 (text+ko) ==== @@ -487,6 +487,40 @@ } /* + * Schedule an upcall to notify a KSE process recieved signals. + * + * XXX - Modifying a sigset_t like this is totally bogus. + */ +struct thread * +signal_upcall(struct proc *p, int sig) +{ + struct thread *td, *td2; + struct kse *ke; + sigset_t ss; + int error; + + PROC_LOCK_ASSERT(p, MA_OWNED); + + td = FIRST_THREAD_IN_PROC(p); + ke = td->td_kse; + PROC_UNLOCK(p); + error = copyin(&ke->ke_mailbox->km_sigscaught, &ss, sizeof(sigset_t)); + PROC_LOCK(p); + if (error) + return (NULL); + SIGADDSET(ss, sig); + PROC_UNLOCK(p); + error = copyout(&ss, &ke->ke_mailbox->km_sigscaught, sizeof(sigset_t)); + PROC_LOCK(p); + if (error) + return (NULL); + mtx_lock_spin(&sched_lock); + td2 = thread_schedule_upcall(td, ke); + mtx_unlock_spin(&sched_lock); + return (td2); +} + +/* * Consider whether or not an upcall should be made, and update the * TDF_UPCALLING flag appropriately. * ==== //depot/projects/kse/sys/sys/proc.h#129 (text+ko) ==== @@ -291,7 +291,7 @@ #define td_startcopy td_kse /* XXXKSE just copying td_md needs checking! */ struct kse *td_kse; /* Current KSE if running. */ - void *td_mailbox; /* the userland mailbox address */ + struct thread_mailbox *td_mailbox; /* the userland mailbox address */ struct mdthread td_md; /* (k) Any machine-dependent fields. */ u_char td_base_pri; /* (j) Thread base kernel priority. */ u_char td_priority; /* (j) Thread active priority. */ @@ -851,6 +851,7 @@ void ksegrp_link(struct ksegrp *kg, struct proc *p); int kserunnable(void); void make_kse_runnable(struct kse *ke); +struct thread *signal_upcall(struct proc *p, int sig); void thread_exit(void) __dead2; int thread_export_context(struct thread *td); void thread_link(struct thread *td, struct ksegrp *kg); ==== //depot/projects/kse/tools/KSE/uts/uts.c#7 (text+ko) ==== @@ -23,11 +23,12 @@ * 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#6 $ + * $P4: //depot/projects/kse/tools/KSE/uts/uts.c#7 $ */ #include #include +#include #include #include #include @@ -37,6 +38,7 @@ #include #include #include +#include #include #undef TRACE_UTS @@ -66,28 +68,39 @@ static void pstr(const char *s); static void runq_insert(struct thread_mailbox *tm); static struct thread_mailbox *runq_remove(void); -static void thread_start(const void *func); +static void thread_start(const void *func, int arg); static void uts(struct kse_mailbox *km); extern int uts_to_thread(struct thread_mailbox *tdp, struct thread_mailbox **curthreadp); static void +nano(int len) +{ + struct timespec time_to_sleep; + struct timespec time_remaining; + + time_to_sleep.tv_sec = 0; + time_to_sleep.tv_nsec = len * 1000; + nanosleep(&time_to_sleep, &time_remaining); +} + +static void foof(int sig) { - pfmt("%d", sig); + pfmt("\n[%d]\n", sig); } void -aaaa(void) +aaaa(int c) { for (;;) { - pchar('.'); - sleep(1); + // pchar(c); + nano(1); } } void -spin(void) +spin(int arg) { for (;;) sched_yield(); } @@ -100,13 +113,14 @@ { int i; - thread_start(aaaa); + thread_start(aaaa, '.'); // thread_start(spin); init_uts(); for (i = 0;1;i++) { - if (i) progress++; - pchar('a' + (i % 26)); - sleep(5); +// if (i < 1000) +// thread_start(aaaa, 'a' + (i % 26)); + // pchar('A' + (i % 26)); + nano(1); } pstr("\n** main() exiting **\n"); return (EX_OK); @@ -130,7 +144,6 @@ /* Throw us into its context. */ getcontext(&tm->tm_context); - tm->tm_context.uc_flags = UCF_SKIPSIGMASK; /* Find our stack. */ mib[0] = CTL_KERN; @@ -163,7 +176,7 @@ /* * Arrange to deliver signals via KSE. */ - /* XXX: Not yet. */ + signal(SIGURG, foof); } /* @@ -279,7 +292,7 @@ uts(struct kse_mailbox *km) { struct thread_mailbox *tm, *p; - int ret; + int ret, i; UPSTR("\n--uts() start--\n"); UPFMT("mailbox -> %x\n", km); @@ -299,9 +312,17 @@ UPCHAR('\n'); /* - * Process any signals we've recieved. + * Process any signals we've recieved (but only if we have + * somewhere to deliver them to). */ - /* XXX: Not yet. */ + if ((run_queue != NULL) && SIGNOTEMPTY(km->km_sigscaught)) { + for (i = 0;i < _SIG_MAXSIG;i++) + if (SIGISMEMBER(km->km_sigscaught, i)) { + signalcontext(&run_queue->tm_context, i, foof); + break; + } + bzero(&km->km_sigscaught, sizeof(sigset_t)); + } /* * Pull a thread off the run queue. @@ -321,10 +342,6 @@ UPFMT("\n-- uts() scheduling 0x%x--\n", p); UPFMT("eip -> 0x%x progress -> %d\n", p->tm_context.uc_mcontext.mc_eip, progress); - if ((p->tm_context.uc_flags & UCF_CRITICAL) == 0) - p->tm_context.uc_flags |= - UCF_CRITICAL | UCF_CLEARSTATE; - uts_mb.km_curthread = p; UPSTR("curthread set\n"); uts_to_thread(p, &km->km_curthread); UPSTR("\n-- uts_to_thread() failed --\n"); @@ -338,7 +355,7 @@ * Start a thread. */ static void -thread_start(const void *func) +thread_start(const void *func, int arg) { struct thread_mailbox *tm; char *p; @@ -349,8 +366,7 @@ p = (char *)malloc(THREAD_STACK_SIZE); tm->tm_context.uc_stack.ss_sp = p; tm->tm_context.uc_stack.ss_size = THREAD_STACK_SIZE; - makecontext(&tm->tm_context, func, 1); - tm->tm_context.uc_flags = UCF_SKIPSIGMASK; + makecontext(&tm->tm_context, func, 2, arg); // setcontext(&tm->tm_context); runq_insert(tm); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message