1 /* 2 * Copyright (c) 2015-2019 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 #include <linux/preempt.h> 39 40 #include <asm/page.h> 41 42 #include <linux/compiler.h> 43 #include <linux/completion.h> 44 #include <linux/pid.h> 45 #include <linux/rcupdate.h> 46 #include <linux/rculist.h> 47 48 #include <linux/time.h> 49 #include <linux/timer.h> 50 #include <linux/hrtimer.h> 51 #include <linux/gfp.h> 52 53 #include <asm/processor.h> 54 55 #include <linux/spinlock.h> 56 57 #include <sys/param.h> 58 #include <sys/systm.h> 59 #include <sys/proc.h> 60 #include <sys/sched.h> 61 #include <sys/signal2.h> 62 63 #define TASK_RUNNING 0 64 #define TASK_INTERRUPTIBLE 1 65 #define TASK_UNINTERRUPTIBLE 2 66 67 /* 68 * schedule_timeout - sleep until timeout 69 * @timeout: timeout value in jiffies 70 */ 71 static inline long 72 schedule_timeout(signed long timeout) 73 { 74 static int dummy; 75 76 if (timeout < 0) { 77 kprintf("schedule_timeout(): timeout cannot be negative\n"); 78 return 0; 79 } 80 81 tsleep(&dummy, 0, "lstim", timeout); 82 83 return 0; 84 } 85 86 #define TASK_COMM_LEN MAXCOMLEN 87 88 #define signal_pending(lp) CURSIG(lp) 89 90 /* 91 * local_clock: fast time source, monotonic on the same cpu 92 */ 93 static inline uint64_t 94 local_clock(void) 95 { 96 struct timespec ts; 97 98 getnanouptime(&ts); 99 return (ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec; 100 } 101 102 #define MAX_SCHEDULE_TIMEOUT LONG_MAX 103 104 static inline void 105 yield(void) 106 { 107 lwkt_yield(); 108 } 109 110 static inline int 111 wake_up_process(struct proc *tsk) { 112 /* Among other things, this function is supposed to act as 113 * a barrier */ 114 smp_wmb(); 115 116 return 0; 117 } 118 119 static inline int 120 signal_pending_state(long state, struct lwp *lp) 121 { 122 sigset_t pending_set; 123 124 if (!(state & TASK_INTERRUPTIBLE)) 125 return 0; 126 127 pending_set = lwp_sigpend(lp); 128 129 return SIGISMEMBER(pending_set, SIGKILL); 130 } 131 132 /* Explicit rescheduling in order to reduce latency */ 133 static inline int 134 cond_resched(void) 135 { 136 lwkt_yield(); 137 return 0; 138 } 139 140 static inline int 141 send_sig(int sig, struct proc *p, int priv) 142 { 143 ksignal(p, sig); 144 return 0; 145 } 146 147 #endif /* _LINUX_SCHED_H_ */ 148