Add initial AIO/LIO kernel thread support files. This is preliminary, and
further features will be added.
This commit is contained in:
parent
91487cf4bf
commit
ee877a356c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=26670
168
sys/kern/kern_threads.c
Normal file
168
sys/kern/kern_threads.c
Normal file
@ -0,0 +1,168 @@
|
||||
/*
|
||||
*
|
||||
* Portions of this code was derived from the file kern_fork.c and as such
|
||||
* is subject to the copyrights below.
|
||||
*
|
||||
* Copyright (c) 1982, 1986, 1989, 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
* (c) UNIX System Laboratories, Inc.
|
||||
* All or some portions of this file are derived from material licensed
|
||||
* to the University of California by American Telephone and Telegraph
|
||||
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||
* the permission of UNIX System Laboratories, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Copyright (c) 1996 Douglas Santry
|
||||
*
|
||||
* This code is subject to the beer copyright. If I chance to meet you in a
|
||||
* bar and this code helped you in some way, you owe me a beer. Only
|
||||
* in Germany will I accept domestic beer. This code may or may not work
|
||||
* and I certainly make no claims as to its fitness for *any* purpose.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/resourcevar.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/acct.h>
|
||||
#include <sys/ktrace.h>
|
||||
#include <sys/sysproto.h>
|
||||
#include <sys/unistd.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
|
||||
#include <machine/cpu.h>
|
||||
|
||||
/*
|
||||
* Low level support for sleep/wakeup paradigm
|
||||
* If a timeout is specified:
|
||||
* returns 0 if wakeup
|
||||
* returns EAGAIN if timed out
|
||||
* returns EINVAL if error
|
||||
*
|
||||
* If a timeout is not specified:
|
||||
*
|
||||
* returns time waiting in ticks.
|
||||
*/
|
||||
int
|
||||
thr_sleep(struct proc *p, struct thr_sleep_args *uap, int *retval) {
|
||||
int sleepStart;
|
||||
long long sleeptime;
|
||||
int sleepclocks;
|
||||
struct timespec ts;
|
||||
int error;
|
||||
|
||||
sleepclocks = 0;
|
||||
if (uap->timeout != 0) {
|
||||
/*
|
||||
* Get timespec struct
|
||||
*/
|
||||
if (error = copyin((caddr_t) uap->timeout, (caddr_t) &ts, sizeof ts)) {
|
||||
p->p_wakeup = 0;
|
||||
return error;
|
||||
}
|
||||
sleeptime = (long long) (hz * ts.tv_nsec);
|
||||
sleeptime /= 1000000000LL;
|
||||
sleeptime += ts.tv_sec * hz;
|
||||
sleepclocks = sleeptime;
|
||||
if (sleepclocks != sleeptime) {
|
||||
p->p_wakeup = 0;
|
||||
retval[0] = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
if (sleepclocks == 0)
|
||||
sleepclocks = 1;
|
||||
}
|
||||
|
||||
retval[0] = 0;
|
||||
if (p->p_wakeup == 0) {
|
||||
sleepStart = ticks;
|
||||
p->p_flag |= P_SINTR;
|
||||
error = tsleep(p, PUSER, "thrslp", sleepclocks);
|
||||
p->p_flag &= ~P_SINTR;
|
||||
if (error == EWOULDBLOCK) {
|
||||
p->p_wakeup = 0;
|
||||
retval[0] = EAGAIN;
|
||||
return 0;
|
||||
}
|
||||
if (uap->timeout == 0)
|
||||
retval[0] = ticks - sleepStart;
|
||||
}
|
||||
p->p_wakeup = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
thr_wakeup(struct proc *p, struct thr_wakeup_args *uap, int *retval) {
|
||||
struct proc *pSlave = p->p_leader;
|
||||
|
||||
while(pSlave && (pSlave->p_pid != uap->pid))
|
||||
pSlave = pSlave->p_peers;
|
||||
|
||||
if(pSlave == 0) {
|
||||
retval[0] = ESRCH;
|
||||
return(0);
|
||||
}
|
||||
|
||||
pSlave->p_wakeup++;
|
||||
if((pSlave->p_stat == SSLEEP) && (pSlave->p_wchan == pSlave)) {
|
||||
wakeup(pSlave);
|
||||
return(0);
|
||||
}
|
||||
|
||||
retval[0] = EAGAIN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* General purpose yield system call
|
||||
*/
|
||||
int
|
||||
yield(struct proc *p, struct yield_args *uap, int *retval) {
|
||||
int s;
|
||||
|
||||
retval[0] = 0;
|
||||
|
||||
s = splhigh();
|
||||
p->p_priority = MAXPRI;
|
||||
setrunqueue(p);
|
||||
mi_switch();
|
||||
splx(s);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
264
sys/kern/vfs_aio.c
Normal file
264
sys/kern/vfs_aio.c
Normal file
@ -0,0 +1,264 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 John S. Dyson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. John S. Dyson's name may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: This code isn't warranted to do anything useful. Anything
|
||||
* bad that happens because of using this software isn't the responsibility
|
||||
* of the author. This software is distributed AS-IS.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains support for the POSIX.4 AIO facility.
|
||||
*
|
||||
* The initial version provides only the (bogus) synchronous semantics
|
||||
* but will support async in the future. Note that a bit
|
||||
* in a private field allows the user mode subroutine to adapt
|
||||
* the kernel operations to true POSIX.4 for future compatibility.
|
||||
*
|
||||
* This code is used to support true POSIX.4 AIO/LIO with the help
|
||||
* of a user mode subroutine package. Note that eventually more support
|
||||
* will be pushed into the kernel.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/sysent.h>
|
||||
#include <sys/sysproto.h>
|
||||
#include <sys/namei.h>
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/dirent.h>
|
||||
#include <sys/signalvar.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/vm_param.h>
|
||||
#include <vm/vm_object.h>
|
||||
#include <vm/vm_extern.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/aio.h>
|
||||
|
||||
|
||||
/*
|
||||
* aio_cancel at the kernel level is a NOOP right now. It
|
||||
* might be possible to support it partially in user mode, or
|
||||
* in kernel mode later on.
|
||||
*/
|
||||
int
|
||||
aio_cancel(struct proc *p, struct aio_cancel_args *uap, int *retval) {
|
||||
return AIO_NOTCANCELLED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* aio_error is implemented in the kernel level for compatibility
|
||||
* purposes only. For a user mode async implementation, it would be
|
||||
* best to do it in a userland subroutine.
|
||||
*/
|
||||
int
|
||||
aio_error(struct proc *p, struct aio_error_args *uap, int *retval) {
|
||||
int activeflag, errorcode;
|
||||
struct aiocb iocb;
|
||||
int error;
|
||||
|
||||
/*
|
||||
* Get control block
|
||||
*/
|
||||
if (error = copyin((caddr_t) uap->aiocbp, (caddr_t) &iocb, sizeof iocb))
|
||||
return error;
|
||||
if (iocb._aiocb_private.active == -1)
|
||||
return EFAULT;
|
||||
|
||||
if (iocb._aiocb_private.active != AIO_PMODE_ACTIVE) {
|
||||
retval[0] = EINVAL;
|
||||
return(0);
|
||||
}
|
||||
|
||||
retval[0] = iocb._aiocb_private.error;
|
||||
return(0);
|
||||
}
|
||||
|
||||
int
|
||||
aio_read(struct proc *p, struct aio_read_args *uap, int *retval) {
|
||||
struct filedesc *fdp;
|
||||
struct file *fp;
|
||||
struct uio auio;
|
||||
struct iovec aiov;
|
||||
unsigned int fd;
|
||||
int cnt;
|
||||
struct aiocb iocb;
|
||||
int error;
|
||||
|
||||
|
||||
/*
|
||||
* Get control block
|
||||
*/
|
||||
if (error = copyin((caddr_t) uap->aiocbp, (caddr_t) &iocb, sizeof iocb))
|
||||
return error;
|
||||
|
||||
/*
|
||||
* We support sync only for now.
|
||||
*/
|
||||
if ((iocb._aiocb_private.privatemodes & AIO_PMODE_SYNC) == 0)
|
||||
return ENOSYS;
|
||||
|
||||
/*
|
||||
* Get the fd info for process
|
||||
*/
|
||||
fdp = p->p_fd;
|
||||
|
||||
/*
|
||||
* Range check file descriptor
|
||||
*/
|
||||
fd = iocb.aio_fildes;
|
||||
if (fd >= fdp->fd_nfiles)
|
||||
return EBADF;
|
||||
fp = fdp->fd_ofiles[fd];
|
||||
if ((fp == NULL) || ((fp->f_flag & FREAD) == 0))
|
||||
return EBADF;
|
||||
if (((int) iocb.aio_offset) == -1)
|
||||
return EINVAL;
|
||||
|
||||
aiov.iov_base = iocb.aio_buf;
|
||||
aiov.iov_len = iocb.aio_nbytes;
|
||||
auio.uio_iov = &aiov;
|
||||
auio.uio_iovcnt = 1;
|
||||
auio.uio_offset = iocb.aio_offset;
|
||||
|
||||
auio.uio_resid = iocb.aio_nbytes;
|
||||
if (auio.uio_resid < 0)
|
||||
return (EINVAL);
|
||||
|
||||
auio.uio_rw = UIO_READ;
|
||||
auio.uio_segflg = UIO_USERSPACE;
|
||||
auio.uio_procp = p;
|
||||
|
||||
cnt = iocb.aio_nbytes;
|
||||
error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred);
|
||||
if (error &&
|
||||
(auio.uio_resid != cnt) &&
|
||||
(error == ERESTART || error == EINTR || error == EWOULDBLOCK))
|
||||
error = 0;
|
||||
cnt -= auio.uio_resid;
|
||||
*retval = cnt;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return and suspend aren't supported (yet).
|
||||
*/
|
||||
int
|
||||
aio_return(struct proc *p, struct aio_return_args *uap, int *retval) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
aio_suspend(struct proc *p, struct aio_suspend_args *uap, int *retval) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
aio_write(struct proc *p, struct aio_write_args *uap, int *retval) {
|
||||
struct filedesc *fdp;
|
||||
struct file *fp;
|
||||
struct uio auio;
|
||||
struct iovec aiov;
|
||||
unsigned int fd;
|
||||
int cnt;
|
||||
struct aiocb iocb;
|
||||
int error;
|
||||
|
||||
if (error = copyin((caddr_t) uap->aiocbp, (caddr_t) &iocb, sizeof iocb))
|
||||
return error;
|
||||
|
||||
/*
|
||||
* We support sync only for now.
|
||||
*/
|
||||
if ((iocb._aiocb_private.privatemodes & AIO_PMODE_SYNC) == 0)
|
||||
return ENOSYS;
|
||||
|
||||
/*
|
||||
* Get the fd info for process
|
||||
*/
|
||||
fdp = p->p_fd;
|
||||
|
||||
/*
|
||||
* Range check file descriptor
|
||||
*/
|
||||
fd = iocb.aio_fildes;
|
||||
if (fd >= fdp->fd_nfiles)
|
||||
return EBADF;
|
||||
fp = fdp->fd_ofiles[fd];
|
||||
if ((fp == NULL) || ((fp->f_flag & FWRITE) == 0))
|
||||
return EBADF;
|
||||
if (((int) iocb.aio_offset) == -1)
|
||||
return EINVAL;
|
||||
|
||||
aiov.iov_base = iocb.aio_buf;
|
||||
aiov.iov_len = iocb.aio_nbytes;
|
||||
auio.uio_iov = &aiov;
|
||||
auio.uio_iovcnt = 1;
|
||||
auio.uio_offset = iocb.aio_offset;
|
||||
|
||||
auio.uio_resid = iocb.aio_nbytes;
|
||||
if (auio.uio_resid < 0)
|
||||
return (EINVAL);
|
||||
|
||||
auio.uio_rw = UIO_WRITE;
|
||||
auio.uio_segflg = UIO_USERSPACE;
|
||||
auio.uio_procp = p;
|
||||
|
||||
cnt = iocb.aio_nbytes;
|
||||
error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred);
|
||||
if (error) {
|
||||
if (auio.uio_resid != cnt) {
|
||||
if (error == ERESTART || error == EINTR || error == EWOULDBLOCK)
|
||||
error = 0;
|
||||
if (error == EPIPE)
|
||||
psignal(p, SIGPIPE);
|
||||
}
|
||||
}
|
||||
cnt -= auio.uio_resid;
|
||||
*retval = cnt;
|
||||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
lio_listio(struct proc *p, struct lio_listio_args *uap, int *retval) {
|
||||
struct filedesc *fdp;
|
||||
struct file *fp;
|
||||
struct uio auio;
|
||||
struct iovec aiov;
|
||||
unsigned int fd;
|
||||
int cnt;
|
||||
unsigned int iocblen, iocbcnt;
|
||||
struct aiocb *iocb;
|
||||
int error;
|
||||
int i;
|
||||
|
||||
if (uap->mode == LIO_NOWAIT)
|
||||
return ENOSYS;
|
||||
iocbcnt = uap->nent;
|
||||
if (iocbcnt > AIO_LISTIO_MAX)
|
||||
return EINVAL;
|
||||
return ENOSYS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user