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