From 1dcc2689e70c9a1ef6ab3fdc4cd16d3ccaa83c7d Mon Sep 17 00:00:00 2001 From: dyson Date: Mon, 16 Jun 1997 00:29:36 +0000 Subject: [PATCH] Modifications to existing files to support the initial AIO/LIO and kernel based threading support. --- sys/conf/files | 2 ++ sys/kern/init_main.c | 8 +++++- sys/kern/init_sysent.c | 12 +++++++++ sys/kern/kern_exit.c | 33 +++++++++++++++++++++++- sys/kern/kern_fork.c | 16 +++++++++++- sys/kern/makesyscalls.sh | 3 ++- sys/kern/sys_generic.c | 6 ++++- sys/kern/syscalls.c | 12 +++++++++ sys/kern/syscalls.master | 14 +++++++++- sys/sys/proc.h | 11 +++++++- sys/sys/syscall-hide.h | 12 +++++++++ sys/sys/syscall.h | 14 +++++++++- sys/sys/sysproto.h | 55 ++++++++++++++++++++++++++++++++++++++++ sys/sys/unistd.h | 4 ++- 14 files changed, 193 insertions(+), 9 deletions(-) diff --git a/sys/conf/files b/sys/conf/files index 036176829aa0..415d340d6ac2 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -119,6 +119,8 @@ kern/vfs_lookup.c standard kern/vfs_subr.c standard kern/vfs_syscalls.c standard kern/vfs_vnops.c standard +kern/kern_threads.c standard +kern/vfs_aio.c standard miscfs/deadfs/dead_vnops.c standard miscfs/devfs/devfs_tree.c optional devfs miscfs/devfs/devfs_vfsops.c optional devfs diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index b4855536ff31..949dad8f57d7 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -39,7 +39,7 @@ * SUCH DAMAGE. * * @(#)init_main.c 8.9 (Berkeley) 1/21/94 - * $Id: init_main.c,v 1.62 1997/05/11 18:05:36 tegge Exp $ + * $Id: init_main.c,v 1.63 1997/05/29 04:52:03 peter Exp $ */ #include "opt_rlimit.h" @@ -339,6 +339,12 @@ proc0_init(dummy) p->p_rtprio.type = RTP_PRIO_NORMAL; p->p_rtprio.prio = 0; +/* + * Link for kernel based threads + */ + p->p_peers = 0; + p->p_leader = p; + bcopy("swapper", p->p_comm, sizeof ("swapper")); /* Create credentials. */ diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c index 2a92d9179265..29b435f3096b 100644 --- a/sys/kern/init_sysent.c +++ b/sys/kern/init_sysent.c @@ -346,4 +346,16 @@ struct sysent sysent[] = { { 0, (sy_call_t *)nosys }, /* 311 = setresuid */ { 0, (sy_call_t *)nosys }, /* 312 = setresgid */ { 3, (sy_call_t *)signanosleep }, /* 313 = signanosleep */ + { 1, (sy_call_t *)aio_return }, /* 314 = aio_return */ + { 3, (sy_call_t *)aio_suspend }, /* 315 = aio_suspend */ + { 2, (sy_call_t *)aio_cancel }, /* 316 = aio_cancel */ + { 1, (sy_call_t *)aio_error }, /* 317 = aio_error */ + { 1, (sy_call_t *)aio_read }, /* 318 = aio_read */ + { 1, (sy_call_t *)aio_write }, /* 319 = aio_write */ + { 4, (sy_call_t *)lio_listio }, /* 320 = lio_listio */ + { 0, (sy_call_t *)yield }, /* 321 = yield */ + { 1, (sy_call_t *)thr_sleep }, /* 322 = thr_sleep */ + { 1, (sy_call_t *)thr_wakeup }, /* 323 = thr_wakeup */ + { 1, (sy_call_t *)mlockall }, /* 324 = mlockall */ + { 0, (sy_call_t *)munlockall }, /* 325 = munlockall */ }; diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index efe1dc60d04c..e5be44ef05c4 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_exit.c 8.7 (Berkeley) 2/12/94 - * $Id: kern_exit.c,v 1.47 1997/04/07 07:16:00 peter Exp $ + * $Id: kern_exit.c,v 1.48 1997/05/22 07:25:20 phk Exp $ */ #include "opt_ktrace.h" @@ -125,6 +125,37 @@ exit1(p, rv) WTERMSIG(rv), WEXITSTATUS(rv)); panic("Going nowhere without my init!"); } + + /* are we a task leader? */ + if(p == p->p_leader) { + struct kill_args killArgs; + killArgs.signum = SIGKILL; + q = p->p_peers; + while(q) { + killArgs.pid = q->p_pid; + /* + * The interface for kill is better + * than the internal signal + */ + kill(p, &killArgs, &rv); + nq = q; + q = q->p_peers; + /* + * orphan the threads so we don't mess up + * when they call exit + */ + nq->p_peers = 0; + nq->p_leader = nq; + } + + /* otherwise are we a peer? */ + } else if(p->p_peers) { + q = p->p_leader; + while(q->p_peers != p) + q = q->p_peers; + q->p_peers = p->p_peers; + } + #ifdef PGINPROF vmsizmon(); #endif diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index ac82dffa6f3e..33e961fe48bb 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_fork.c 8.6 (Berkeley) 4/8/94 - * $Id: kern_fork.c,v 1.41 1997/04/26 15:59:50 peter Exp $ + * $Id: kern_fork.c,v 1.42 1997/05/29 04:52:04 peter Exp $ */ #include "opt_ktrace.h" @@ -218,6 +218,20 @@ fork1(p1, flags, retval) /* Allocate new proc. */ MALLOC(newproc, struct proc *, sizeof(struct proc), M_PROC, M_WAITOK); +/* + * Setup linkage for kernel based threading + */ + if((flags & RFTHREAD) != 0) { + newproc->p_peers = p1->p_peers; + p1->p_peers = newproc; + newproc->p_leader = p1->p_leader; + } else { + newproc->p_peers = 0; + newproc->p_leader = newproc; + } + + newproc->p_wakeup = 0; + /* * Find an unused process ID. We remember a range of unused IDs * ready to use (from nextpid+1 through pidchecked-1). diff --git a/sys/kern/makesyscalls.sh b/sys/kern/makesyscalls.sh index 9fb06a1a7bb3..2af3872e5e5b 100644 --- a/sys/kern/makesyscalls.sh +++ b/sys/kern/makesyscalls.sh @@ -1,6 +1,6 @@ #! /bin/sh - # @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93 -# $Id: makesyscalls.sh,v 1.21 1997/02/22 09:39:14 peter Exp $ +# $Id: makesyscalls.sh,v 1.22 1997/03/29 11:11:18 peter Exp $ set -e @@ -105,6 +105,7 @@ s/\$//g printf " * created from%s\n */\n\n", $0 > sysarg printf("#ifndef %s\n", sysproto_h) > sysarg printf("#define\t%s\n\n", sysproto_h) > sysarg + printf "#include \n" > sysarg printf "#include \n\n", $0 > sysarg printf " * created from%s\n */\n\n", $0 > sysnames diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 2bcfd681b3d7..4f0cc23c1af7 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94 - * $Id: sys_generic.c,v 1.25 1997/03/23 03:36:23 bde Exp $ + * $Id: sys_generic.c,v 1.26 1997/03/24 11:52:25 bde Exp $ */ #include "opt_ktrace.h" @@ -99,6 +99,7 @@ read(p, uap, retval) aiov.iov_len = uap->nbyte; auio.uio_iov = &aiov; auio.uio_iovcnt = 1; + auio.uio_offset = -1; auio.uio_resid = uap->nbyte; if (auio.uio_resid < 0) @@ -176,6 +177,7 @@ readv(p, uap, retval) auio.uio_rw = UIO_READ; auio.uio_segflg = UIO_USERSPACE; auio.uio_procp = p; + auio.uio_offset = -1; if ((error = copyin((caddr_t)uap->iovp, (caddr_t)iov, iovlen))) goto done; auio.uio_resid = 0; @@ -250,6 +252,7 @@ write(p, uap, retval) aiov.iov_len = uap->nbyte; auio.uio_iov = &aiov; auio.uio_iovcnt = 1; + auio.uio_offset = -1; auio.uio_resid = uap->nbyte; auio.uio_rw = UIO_WRITE; auio.uio_segflg = UIO_USERSPACE; @@ -327,6 +330,7 @@ writev(p, uap, retval) auio.uio_rw = UIO_WRITE; auio.uio_segflg = UIO_USERSPACE; auio.uio_procp = p; + auio.uio_offset = -1; if ((error = copyin((caddr_t)uap->iovp, (caddr_t)iov, iovlen))) goto done; auio.uio_resid = 0; diff --git a/sys/kern/syscalls.c b/sys/kern/syscalls.c index 4dda7cf41d8f..b824925f4813 100644 --- a/sys/kern/syscalls.c +++ b/sys/kern/syscalls.c @@ -335,4 +335,16 @@ char *syscallnames[] = { "#311", /* 311 = setresuid */ "#312", /* 312 = setresgid */ "signanosleep", /* 313 = signanosleep */ + "aio_return", /* 314 = aio_return */ + "aio_suspend", /* 315 = aio_suspend */ + "aio_cancel", /* 316 = aio_cancel */ + "aio_error", /* 317 = aio_error */ + "aio_read", /* 318 = aio_read */ + "aio_write", /* 319 = aio_write */ + "lio_listio", /* 320 = lio_listio */ + "yield", /* 321 = yield */ + "thr_sleep", /* 322 = thr_sleep */ + "thr_wakeup", /* 323 = thr_wakeup */ + "mlockall", /* 324 = mlockall */ + "munlockall", /* 325 = munlockall */ }; diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index 82ceb9dc4fb5..d944470f1ad2 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ - $Id: syscalls.master,v 1.38 1997/05/08 14:07:11 peter Exp $ + $Id: syscalls.master,v 1.39 1997/06/01 08:52:38 peter Exp $ ; from: @(#)syscalls.master 8.2 (Berkeley) 1/13/94 ; ; System call name/number master file. @@ -462,3 +462,15 @@ 312 UNIMPL NOHIDE setresgid 313 STD BSD { int signanosleep(const struct timespec *rqtp, \ struct timespec *rmtp, sigset_t *mask); } +314 STD BSD { int aio_return(struct aiocb *aiocbp); } +315 STD BSD { int aio_suspend(struct aiocb * const * aiocbp, int nent, const struct timespec *timeout); } +316 STD BSD { int aio_cancel(int fd, struct aiocb *aiocbp); } +317 STD BSD { int aio_error(struct aiocb *aiocbp); } +318 STD BSD { int aio_read(struct aiocb *aiocbp); } +319 STD BSD { int aio_write(struct aiocb *aiocbp); } +320 STD BSD { int lio_listio(int mode, struct aiocb * const *acb_list, int nent, struct sigevent *sig); } +321 STD BSD { int yield(void); } +322 STD BSD { int thr_sleep(const struct timespec *timeout); } +323 STD BSD { int thr_wakeup(pid_t pid); } +324 STD BSD { int mlockall(int how); } +325 STD BSD { int munlockall(void); } diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 54b320507fe6..2c18e4ed5336 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)proc.h 8.15 (Berkeley) 5/19/95 - * $Id: proc.h,v 1.38 1997/05/22 07:24:46 phk Exp $ + * $Id: proc.h,v 1.39 1997/06/01 08:49:49 peter Exp $ */ #ifndef _SYS_PROC_H_ @@ -178,6 +178,12 @@ struct proc { u_short p_xstat; /* Exit status for wait; also stop signal. */ u_short p_acflag; /* Accounting flags. */ struct rusage *p_ru; /* Exit information. XXX */ + + int p_nthreads; /* number of threads (only in leader) */ + int p_npeers; /* number of kernel threads (only in leader) */ + int p_wakeup; /* thread id */ + struct proc *p_peers; + struct proc *p_leader; }; #define p_session p_pgrp->pg_session @@ -218,6 +224,9 @@ struct proc { #define P_SWAPINREQ 0x80000 /* Swapin request due to wakeup */ #define P_IDLEPROC 0x100000 /* Process is an idle-eater, don't count */ +/* Marked a kernel thread */ +#define P_KTHREADP 0x200000 /* Process is really a kernel thread */ + /* * MOVE TO ucred.h? * diff --git a/sys/sys/syscall-hide.h b/sys/sys/syscall-hide.h index e1d8420af21d..97196189ac5e 100644 --- a/sys/sys/syscall-hide.h +++ b/sys/sys/syscall-hide.h @@ -229,3 +229,15 @@ HIDE_BSD(kldnext) HIDE_BSD(kldstat) HIDE_BSD(kldfirstmod) HIDE_BSD(signanosleep) +HIDE_BSD(aio_return) +HIDE_BSD(aio_suspend) +HIDE_BSD(aio_cancel) +HIDE_BSD(aio_error) +HIDE_BSD(aio_read) +HIDE_BSD(aio_write) +HIDE_BSD(lio_listio) +HIDE_BSD(yield) +HIDE_BSD(thr_sleep) +HIDE_BSD(thr_wakeup) +HIDE_BSD(mlockall) +HIDE_BSD(munlockall) diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h index 30493846aec0..bd7b41dd87b8 100644 --- a/sys/sys/syscall.h +++ b/sys/sys/syscall.h @@ -223,4 +223,16 @@ #define SYS_kldstat 308 #define SYS_kldfirstmod 309 #define SYS_signanosleep 313 -#define SYS_MAXSYSCALL 314 +#define SYS_aio_return 314 +#define SYS_aio_suspend 315 +#define SYS_aio_cancel 316 +#define SYS_aio_error 317 +#define SYS_aio_read 318 +#define SYS_aio_write 319 +#define SYS_lio_listio 320 +#define SYS_yield 321 +#define SYS_thr_sleep 322 +#define SYS_thr_wakeup 323 +#define SYS_mlockall 324 +#define SYS_munlockall 325 +#define SYS_MAXSYSCALL 326 diff --git a/sys/sys/sysproto.h b/sys/sys/sysproto.h index fb6a79e8e69f..cf0015bf0cfe 100644 --- a/sys/sys/sysproto.h +++ b/sys/sys/sysproto.h @@ -8,6 +8,7 @@ #ifndef _SYS_SYSPROTO_H_ #define _SYS_SYSPROTO_H_ +#include #include struct nosys_args { @@ -786,6 +787,48 @@ struct signanosleep_args { struct timespec * rmtp; sigset_t * mask; }; +struct aio_return_args { + struct aiocb * aiocbp; +}; +struct aio_suspend_args { + struct aiocb *const * aiocbp; + int nent; + const struct timespec * timeout; +}; +struct aio_cancel_args { + int fd; + struct aiocb * aiocbp; +}; +struct aio_error_args { + struct aiocb * aiocbp; +}; +struct aio_read_args { + struct aiocb * aiocbp; +}; +struct aio_write_args { + struct aiocb * aiocbp; +}; +struct lio_listio_args { + int mode; + struct aiocb *const * acb_list; + int nent; + struct sigevent * sig; +}; +struct yield_args { + int dummy; +}; +struct thr_sleep_args { + const struct timespec * timeout; +}; +struct thr_wakeup_args { + pid_t pid; +}; +struct mlockall_args { + int how; +}; +struct munlockall_args { + int dummy; +}; int nosys __P((struct proc *, struct nosys_args *, int [])); void exit __P((struct proc *, struct rexit_args *, int [])) __dead2; int fork __P((struct proc *, struct fork_args *, int [])); @@ -973,6 +1016,18 @@ int kldnext __P((struct proc *, struct kldnext_args *, int [])); int kldstat __P((struct proc *, struct kldstat_args *, int [])); int kldfirstmod __P((struct proc *, struct kldfirstmod_args *, int [])); int signanosleep __P((struct proc *, struct signanosleep_args *, int [])); +int aio_return __P((struct proc *, struct aio_return_args *, int [])); +int aio_suspend __P((struct proc *, struct aio_suspend_args *, int [])); +int aio_cancel __P((struct proc *, struct aio_cancel_args *, int [])); +int aio_error __P((struct proc *, struct aio_error_args *, int [])); +int aio_read __P((struct proc *, struct aio_read_args *, int [])); +int aio_write __P((struct proc *, struct aio_write_args *, int [])); +int lio_listio __P((struct proc *, struct lio_listio_args *, int [])); +int yield __P((struct proc *, struct yield_args *, int [])); +int thr_sleep __P((struct proc *, struct thr_sleep_args *, int [])); +int thr_wakeup __P((struct proc *, struct thr_wakeup_args *, int [])); +int mlockall __P((struct proc *, struct mlockall_args *, int [])); +int munlockall __P((struct proc *, struct munlockall_args *, int [])); #ifdef COMPAT_43 diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h index fc3413984c07..efe6785ae3e0 100644 --- a/sys/sys/unistd.h +++ b/sys/sys/unistd.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)unistd.h 8.2 (Berkeley) 1/7/94 - * $Id$ + * $Id: unistd.h,v 1.13 1997/02/22 09:46:21 peter Exp $ */ #ifndef _SYS_UNISTD_H_ @@ -138,7 +138,9 @@ #define RFCNAMEG (1<<10) /* UNIMPL zero plan9 `name space' */ #define RFCENVG (1<<11) /* UNIMPL zero plan9 `env space' */ #define RFCFDG (1<<12) /* zero fd table */ +#define RFTHREAD (1<<13) /* enable kernel thread support */ #define RFPPWAIT (1<<31) /* parent sleeps until child exits (vfork) */ + #endif /* !_POSIX_SOURCE */ #endif /* !_SYS_UNISTD_H_ */