150276Speter/* 2166124Srafan * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org> 350276Speter * All rights reserved. 450276Speter * 550276Speter * Redistribution and use in source and binary forms, with or without 650276Speter * modification, are permitted provided that the following conditions 750276Speter * are met: 850276Speter * 1. Redistributions of source code must retain the above copyright 950276Speter * notice, this list of conditions and the following disclaimer. 1050276Speter * 2. Redistributions in binary form must reproduce the above copyright 1150276Speter * notice, this list of conditions and the following disclaimer in the 1250276Speter * documentation and/or other materials provided with the distribution. 1350276Speter * 1450276Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 1550276Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1650276Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1750276Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 1850276Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1950276Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2050276Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2150276Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2250276Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2350276Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2450276Speter * SUCH DAMAGE. 2550276Speter * 2650276Speter * $FreeBSD$ 2750276Speter */ 2850276Speter 29174993Srafan#ifndef _OPENSOLARIS_SYS_PROC_H_ 3050276Speter#define _OPENSOLARIS_SYS_PROC_H_ 31166124Srafan 32166124Srafan#include <sys/param.h> 3350276Speter#include <sys/kthread.h> 3462449Speter#include_next <sys/proc.h> 3562449Speter#include <sys/stdint.h> 3662449Speter#include <sys/smp.h> 3762449Speter#include <sys/sched.h> 38166124Srafan#include <sys/lock.h> 39166124Srafan#include <sys/mutex.h> 4050276Speter#include <sys/unistd.h> 4150276Speter#include <sys/kmem.h> 42166124Srafan#include <sys/malloc.h> 4350276Speter 4450276Speter#ifdef _KERNEL 4550276Speter#define CPU curcpu 4650276Speter#define minclsyspri PRIBIO 4750276Speter#define defclsyspri minclsyspri 4850276Speter#define maxclsyspri PVM 4950276Speter#define max_ncpus (mp_maxid + 1) 5050276Speter#define boot_max_ncpus (mp_maxid + 1) 5150276Speter 5250276Speter#define TS_RUN 0 5350276Speter 54166124Srafan#define p0 proc0 5550276Speter 5650276Speter#define t_tid td_tid 5750276Speter 5850276Spetertypedef short pri_t; 59166124Srafantypedef struct thread _kthread; 6050276Spetertypedef struct thread kthread_t; 6150276Spetertypedef struct thread *kthread_id_t; 6250276Spetertypedef struct proc proc_t; 6350276Speter 6450276Speterextern proc_t *system_proc; 65166124Srafan 6650276Speterstatic __inline kthread_t * 6750276Speterdo_thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg, 6850276Speter size_t len, proc_t *pp, int state, pri_t pri, const char *name) 6950276Speter{ 70166124Srafan kthread_t *td = NULL; 7150276Speter proc_t **ppp; 7250276Speter int error; 7350276Speter 7450276Speter /* 75166124Srafan * Be sure there are no surprises. 7650276Speter */ 7750276Speter ASSERT(stk == NULL); 7850276Speter ASSERT(len == 0); 7950276Speter ASSERT(state == TS_RUN); 8050276Speter 81166124Srafan if (pp == &p0) 82166124Srafan ppp = &system_proc; 83166124Srafan else 84166124Srafan ppp = &pp; 8550276Speter error = kproc_kthread_add(proc, arg, ppp, &td, RFSTOPPED, 8650276Speter stksize / PAGE_SIZE, "zfskern", "%s", name); 8750276Speter if (error == 0) { 8850276Speter thread_lock(td); 8950276Speter sched_prio(td, pri); 90166124Srafan sched_add(td, SRQ_BORING); 9150276Speter#if __FreeBSD_version < 1300068 92166124Srafan thread_unlock(td); 9350276Speter#endif 9450276Speter } 9550276Speter return (td); 96174993Srafan} 9750276Speter 9850276Speter#define thread_create_named(name, stk, stksize, proc, arg, len, \ 9950276Speter pp, state, pri) \ 10050276Speter do_thread_create(stk, stksize, proc, arg, len, pp, state, pri, name) 10150276Speter#define thread_create(stk, stksize, proc, arg, len, pp, state, pri) \ 10250276Speter do_thread_create(stk, stksize, proc, arg, len, pp, state, pri, #proc) 103#define thread_exit() kthread_exit() 104 105int uread(proc_t *, void *, size_t, uintptr_t); 106int uwrite(proc_t *, void *, size_t, uintptr_t); 107 108static inline boolean_t 109zfs_proc_is_caller(proc_t *p) 110{ 111 return (p == curproc); 112} 113 114#endif /* _KERNEL */ 115#endif /* _OPENSOLARIS_SYS_PROC_H_ */ 116