1 /* 2 * Copyright (c) 2015-2018 François Tigeot <ftigeot@wolfpond.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef _LINUX_SCHED_H_ 28 #define _LINUX_SCHED_H_ 29 30 #include <linux/capability.h> 31 #include <linux/threads.h> 32 #include <linux/kernel.h> 33 #include <linux/types.h> 34 #include <linux/jiffies.h> 35 #include <linux/cpumask.h> 36 #include <linux/errno.h> 37 #include <linux/mm_types.h> 38 39 #include <asm/page.h> 40 41 #include <linux/compiler.h> 42 #include <linux/completion.h> 43 #include <linux/pid.h> 44 #include <linux/rcupdate.h> 45 #include <linux/rculist.h> 46 47 #include <linux/time.h> 48 #include <linux/timer.h> 49 #include <linux/hrtimer.h> 50 #include <linux/gfp.h> 51 52 #include <linux/spinlock.h> 53 54 #include <sys/param.h> 55 #include <sys/systm.h> 56 #include <sys/proc.h> 57 #include <sys/sched.h> 58 #include <sys/signal2.h> 59 60 #define TASK_RUNNING 0 61 #define TASK_INTERRUPTIBLE 1 62 #define TASK_UNINTERRUPTIBLE 2 63 64 /* 65 * schedule_timeout - sleep until timeout 66 * @timeout: timeout value in jiffies 67 */ 68 static inline long 69 schedule_timeout(signed long timeout) 70 { 71 static int dummy; 72 73 if (timeout < 0) { 74 kprintf("schedule_timeout(): timeout cannot be negative\n"); 75 return 0; 76 } 77 78 tsleep(&dummy, 0, "lstim", timeout); 79 80 return 0; 81 } 82 83 #define TASK_COMM_LEN MAXCOMLEN 84 85 #define signal_pending(lp) CURSIG(lp) 86 87 /* 88 * local_clock: fast time source, monotonic on the same cpu 89 */ 90 static inline uint64_t 91 local_clock(void) 92 { 93 struct timespec ts; 94 95 getnanouptime(&ts); 96 return (ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec; 97 } 98 99 #define MAX_SCHEDULE_TIMEOUT LONG_MAX 100 101 static inline void 102 yield(void) 103 { 104 lwkt_yield(); 105 } 106 107 static inline int 108 wake_up_process(struct proc *tsk) { 109 /* Among other things, this function is supposed to act as 110 * a barrier */ 111 smp_wmb(); 112 113 return 0; 114 } 115 116 static inline int 117 signal_pending_state(long state, struct lwp *lp) 118 { 119 sigset_t pending_set; 120 121 if (!(state & TASK_INTERRUPTIBLE)) 122 return 0; 123 124 pending_set = lwp_sigpend(lp); 125 126 return SIGISMEMBER(pending_set, SIGKILL); 127 } 128 129 /* Explicit rescheduling in order to reduce latency */ 130 static inline int 131 cond_resched(void) 132 { 133 lwkt_yield(); 134 return 0; 135 } 136 137 static inline int 138 send_sig(int sig, struct proc *p, int priv) 139 { 140 ksignal(p, sig); 141 return 0; 142 } 143 144 #endif /* _LINUX_SCHED_H_ */ 145