xref: /f-stack/lib/ff_kern_synch.c (revision 9bd490e8)
1 /*
2  * Copyright (c) 2010 Kip Macy. All rights reserved.
3  * Copyright (C) 2017 THL A29 Limited, a Tencent company.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  *   list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *   this list of conditions and the following disclaimer in the documentation
13  *   and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * Derived in part from libplebnet's pn_kern_synch.c.
27  */
28 
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 
32 #include <sys/param.h>
33 
34 #include <sys/systm.h>
35 #include <sys/condvar.h>
36 #include <sys/kdb.h>
37 #include <sys/kernel.h>
38 #include <sys/ktr.h>
39 #include <sys/lock.h>
40 #include <sys/malloc.h>
41 #include <sys/mutex.h>
42 #include <sys/proc.h>
43 #include <sys/resourcevar.h>
44 #include <sys/sched.h>
45 #include <sys/signalvar.h>
46 #include <sys/sleepqueue.h>
47 #include <sys/smp.h>
48 #include <sys/sx.h>
49 #include <sys/sysctl.h>
50 #include <sys/vmmeter.h>
51 #ifdef KTRACE
52 #include <sys/uio.h>
53 #include <sys/ktrace.h>
54 #endif
55 
56 #include "ff_host_interface.h"
57 
58 int hogticks;
59 static uint8_t pause_wchan[MAXCPU];
60 
61 typedef struct sleep_entry {
62     LIST_ENTRY(sleep_entry) list_entry;
63     void *chan;
64     const char *wmesg;
65     struct cv cond;
66     int waiters;
67 } *sleep_entry_t;
68 
69 static void synch_setup(void *dummy);
70 SYSINIT(synch_setup, SI_SUB_INTR, SI_ORDER_FIRST, synch_setup,
71     NULL);
72 
73 static struct se_head *se_active;
74 static u_long se_hashmask;
75 static struct mtx synch_lock;
76 #define SE_HASH(chan) (((uintptr_t)chan) & se_hashmask)
77 LIST_HEAD(se_head, sleep_entry);
78 
79 static void
80 synch_setup(void *arg)
81 {
82     mtx_init(&synch_lock, "synch_lock", NULL, MTX_DEF);
83     se_active = hashinit(64, M_TEMP, &se_hashmask);
84 }
85 
86 int
87 _sleep(void *ident, struct lock_object *lock, int priority,
88     const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags)
89 {
90     //FIXME:we couldn't really sleep.
91     return (EPERM);
92 }
93 
94 
95 //FIXME.
96 int
97 msleep_spin_sbt(void *ident, struct mtx *mtx, const char *wmesg,
98     sbintime_t sbt, sbintime_t pr, int flags)
99 {
100     return (0);
101 }
102 
103 int
104 pause_sbt(const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags)
105 {
106     return (_sleep(&pause_wchan[curcpu], NULL, 0, wmesg, sbt, pr, flags));
107 }
108 
109 void
110 wakeup(void *chan)
111 {
112 
113 }
114 
115 
116 void
117 wakeup_one(void *chan)
118 {
119 
120 }
121 
122 void
123 kern_yield(int prio)
124 {
125 
126 }
127