Home | History | Annotate | Line # | Download | only in rumpkern
intr.c revision 1.36.14.3
      1  1.36.14.1       tls /*	$NetBSD: intr.c,v 1.36.14.3 2017/12/03 11:39:16 jdolecek Exp $	*/
      2        1.2        ad 
      3        1.5     pooka /*
      4  1.36.14.3  jdolecek  * Copyright (c) 2008-2010, 2015 Antti Kantee.  All Rights Reserved.
      5        1.2        ad  *
      6        1.2        ad  * Redistribution and use in source and binary forms, with or without
      7        1.2        ad  * modification, are permitted provided that the following conditions
      8        1.2        ad  * are met:
      9        1.2        ad  * 1. Redistributions of source code must retain the above copyright
     10        1.2        ad  *    notice, this list of conditions and the following disclaimer.
     11        1.2        ad  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.2        ad  *    notice, this list of conditions and the following disclaimer in the
     13        1.2        ad  *    documentation and/or other materials provided with the distribution.
     14        1.2        ad  *
     15        1.5     pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16        1.5     pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17        1.5     pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18        1.5     pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19        1.5     pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20        1.5     pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21        1.5     pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22        1.5     pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23        1.5     pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24        1.5     pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25        1.5     pooka  * SUCH DAMAGE.
     26        1.2        ad  */
     27        1.2        ad 
     28       1.11     pooka #include <sys/cdefs.h>
     29  1.36.14.1       tls __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.36.14.3 2017/12/03 11:39:16 jdolecek Exp $");
     30       1.11     pooka 
     31        1.2        ad #include <sys/param.h>
     32       1.29    martin #include <sys/atomic.h>
     33        1.5     pooka #include <sys/cpu.h>
     34       1.24     pooka #include <sys/kernel.h>
     35       1.12     pooka #include <sys/kmem.h>
     36        1.5     pooka #include <sys/kthread.h>
     37       1.28     pooka #include <sys/malloc.h>
     38        1.2        ad #include <sys/intr.h>
     39       1.24     pooka #include <sys/timetc.h>
     40        1.2        ad 
     41  1.36.14.3  jdolecek #include <rump-sys/kern.h>
     42        1.5     pooka 
     43  1.36.14.3  jdolecek #include <rump/rumpuser.h>
     44        1.5     pooka 
     45        1.5     pooka /*
     46        1.5     pooka  * Interrupt simulator.  It executes hardclock() and softintrs.
     47        1.5     pooka  */
     48        1.5     pooka 
     49       1.18     pooka #define SI_MPSAFE 0x01
     50       1.32     pooka #define SI_KILLME 0x02
     51       1.20     pooka 
     52       1.32     pooka struct softint_percpu;
     53        1.5     pooka struct softint {
     54        1.5     pooka 	void (*si_func)(void *);
     55        1.5     pooka 	void *si_arg;
     56       1.18     pooka 	int si_flags;
     57       1.20     pooka 	int si_level;
     58        1.5     pooka 
     59       1.32     pooka 	struct softint_percpu *si_entry; /* [0,ncpu-1] */
     60       1.32     pooka };
     61       1.32     pooka 
     62       1.32     pooka struct softint_percpu {
     63       1.32     pooka 	struct softint *sip_parent;
     64       1.32     pooka 	bool sip_onlist;
     65  1.36.14.3  jdolecek 	bool sip_onlist_cpu;
     66       1.32     pooka 
     67  1.36.14.3  jdolecek 	TAILQ_ENTRY(softint_percpu) sip_entries;	/* scheduled */
     68  1.36.14.3  jdolecek 	TAILQ_ENTRY(softint_percpu) sip_entries_cpu;	/* to be scheduled */
     69        1.2        ad };
     70       1.10     pooka 
     71       1.22     pooka struct softint_lev {
     72       1.20     pooka 	struct rumpuser_cv *si_cv;
     73  1.36.14.3  jdolecek 	TAILQ_HEAD(, softint_percpu) si_pending;
     74       1.22     pooka };
     75       1.10     pooka 
     76  1.36.14.3  jdolecek static TAILQ_HEAD(, softint_percpu) sicpupending \
     77  1.36.14.3  jdolecek     = TAILQ_HEAD_INITIALIZER(sicpupending);
     78  1.36.14.3  jdolecek static struct rumpuser_mtx *sicpumtx;
     79  1.36.14.3  jdolecek static struct rumpuser_cv *sicpucv;
     80  1.36.14.3  jdolecek 
     81       1.23     pooka kcondvar_t lbolt; /* Oh Kath Ra */
     82       1.23     pooka 
     83       1.34     pooka static int ncpu_final;
     84       1.24     pooka 
     85  1.36.14.3  jdolecek void noclock(void); void noclock(void) {return;}
     86  1.36.14.3  jdolecek __strong_alias(sched_schedclock,noclock);
     87  1.36.14.3  jdolecek __strong_alias(cpu_initclocks,noclock);
     88  1.36.14.3  jdolecek __strong_alias(addupc_intr,noclock);
     89  1.36.14.3  jdolecek __strong_alias(sched_tick,noclock);
     90  1.36.14.3  jdolecek __strong_alias(setstatclockrate,noclock);
     91       1.14     pooka 
     92       1.10     pooka /*
     93       1.10     pooka  * clock "interrupt"
     94       1.10     pooka  */
     95       1.10     pooka static void
     96       1.10     pooka doclock(void *noarg)
     97       1.10     pooka {
     98  1.36.14.1       tls 	struct timespec thetick, curclock;
     99  1.36.14.3  jdolecek 	struct clockframe *clkframe;
    100  1.36.14.1       tls 	int64_t sec;
    101  1.36.14.1       tls 	long nsec;
    102       1.24     pooka 	int error;
    103  1.36.14.3  jdolecek 	struct cpu_info *ci = curcpu();
    104       1.14     pooka 
    105  1.36.14.1       tls 	error = rumpuser_clock_gettime(RUMPUSER_CLOCK_ABSMONO, &sec, &nsec);
    106  1.36.14.1       tls 	if (error)
    107  1.36.14.1       tls 		panic("clock: cannot get monotonic time");
    108  1.36.14.1       tls 
    109  1.36.14.1       tls 	curclock.tv_sec = sec;
    110  1.36.14.1       tls 	curclock.tv_nsec = nsec;
    111       1.24     pooka 	thetick.tv_sec = 0;
    112       1.24     pooka 	thetick.tv_nsec = 1000000000/hz;
    113       1.14     pooka 
    114  1.36.14.3  jdolecek 	/* generate dummy clockframe for hardclock to consume */
    115  1.36.14.3  jdolecek 	clkframe = rump_cpu_makeclockframe();
    116  1.36.14.3  jdolecek 
    117       1.10     pooka 	for (;;) {
    118  1.36.14.3  jdolecek 		int lbolt_ticks = 0;
    119  1.36.14.3  jdolecek 
    120  1.36.14.3  jdolecek 		hardclock(clkframe);
    121  1.36.14.3  jdolecek 		if (CPU_IS_PRIMARY(ci)) {
    122  1.36.14.3  jdolecek 			if (++lbolt_ticks >= hz) {
    123  1.36.14.3  jdolecek 				lbolt_ticks = 0;
    124  1.36.14.3  jdolecek 				cv_broadcast(&lbolt);
    125  1.36.14.3  jdolecek 			}
    126  1.36.14.3  jdolecek 		}
    127        1.5     pooka 
    128  1.36.14.1       tls 		error = rumpuser_clock_sleep(RUMPUSER_CLOCK_ABSMONO,
    129  1.36.14.1       tls 		    curclock.tv_sec, curclock.tv_nsec);
    130  1.36.14.3  jdolecek 		if (error) {
    131  1.36.14.3  jdolecek 			panic("rumpuser_clock_sleep failed with error %d",
    132  1.36.14.3  jdolecek 			    error);
    133        1.8     pooka 		}
    134  1.36.14.3  jdolecek 		timespecadd(&curclock, &thetick, &curclock);
    135       1.10     pooka 	}
    136       1.10     pooka }
    137        1.8     pooka 
    138       1.10     pooka /*
    139       1.28     pooka  * Soft interrupt execution thread.  This thread is pinned to the
    140       1.28     pooka  * same CPU that scheduled the interrupt, so we don't need to do
    141       1.28     pooka  * lock against si_lvl.
    142       1.10     pooka  */
    143       1.10     pooka static void
    144       1.10     pooka sithread(void *arg)
    145       1.10     pooka {
    146       1.32     pooka 	struct softint_percpu *sip;
    147       1.10     pooka 	struct softint *si;
    148       1.10     pooka 	void (*func)(void *) = NULL;
    149       1.10     pooka 	void *funarg;
    150       1.10     pooka 	bool mpsafe;
    151       1.20     pooka 	int mylevel = (uintptr_t)arg;
    152       1.22     pooka 	struct softint_lev *si_lvlp, *si_lvl;
    153       1.22     pooka 	struct cpu_data *cd = &curcpu()->ci_data;
    154       1.20     pooka 
    155       1.22     pooka 	si_lvlp = cd->cpu_softcpu;
    156       1.22     pooka 	si_lvl = &si_lvlp[mylevel];
    157       1.22     pooka 
    158       1.10     pooka 	for (;;) {
    159  1.36.14.3  jdolecek 		if (!TAILQ_EMPTY(&si_lvl->si_pending)) {
    160  1.36.14.3  jdolecek 			sip = TAILQ_FIRST(&si_lvl->si_pending);
    161       1.32     pooka 			si = sip->sip_parent;
    162       1.32     pooka 
    163        1.5     pooka 			func = si->si_func;
    164        1.5     pooka 			funarg = si->si_arg;
    165       1.18     pooka 			mpsafe = si->si_flags & SI_MPSAFE;
    166        1.5     pooka 
    167       1.32     pooka 			sip->sip_onlist = false;
    168  1.36.14.3  jdolecek 			TAILQ_REMOVE(&si_lvl->si_pending, sip, sip_entries);
    169       1.20     pooka 			if (si->si_flags & SI_KILLME) {
    170       1.18     pooka 				softint_disestablish(si);
    171       1.20     pooka 				continue;
    172       1.20     pooka 			}
    173       1.10     pooka 		} else {
    174       1.28     pooka 			rump_schedlock_cv_wait(si_lvl->si_cv);
    175       1.10     pooka 			continue;
    176        1.5     pooka 		}
    177        1.5     pooka 
    178       1.10     pooka 		if (!mpsafe)
    179       1.10     pooka 			KERNEL_LOCK(1, curlwp);
    180       1.10     pooka 		func(funarg);
    181       1.10     pooka 		if (!mpsafe)
    182       1.10     pooka 			KERNEL_UNLOCK_ONE(curlwp);
    183        1.5     pooka 	}
    184       1.20     pooka 
    185       1.20     pooka 	panic("sithread unreachable");
    186        1.5     pooka }
    187        1.2        ad 
    188  1.36.14.3  jdolecek /*
    189  1.36.14.3  jdolecek  * Helper for softint_schedule_cpu()
    190  1.36.14.3  jdolecek  */
    191  1.36.14.3  jdolecek static void
    192  1.36.14.3  jdolecek sithread_cpu_bouncer(void *arg)
    193  1.36.14.3  jdolecek {
    194  1.36.14.3  jdolecek 	struct lwp *me;
    195  1.36.14.3  jdolecek 
    196  1.36.14.3  jdolecek 	me = curlwp;
    197  1.36.14.3  jdolecek 	me->l_pflag |= LP_BOUND;
    198  1.36.14.3  jdolecek 
    199  1.36.14.3  jdolecek 	rump_unschedule();
    200  1.36.14.3  jdolecek 	for (;;) {
    201  1.36.14.3  jdolecek 		struct softint_percpu *sip;
    202  1.36.14.3  jdolecek 		struct softint *si;
    203  1.36.14.3  jdolecek 		struct cpu_info *ci;
    204  1.36.14.3  jdolecek 		unsigned int cidx;
    205  1.36.14.3  jdolecek 
    206  1.36.14.3  jdolecek 		rumpuser_mutex_enter_nowrap(sicpumtx);
    207  1.36.14.3  jdolecek 		while (TAILQ_EMPTY(&sicpupending)) {
    208  1.36.14.3  jdolecek 			rumpuser_cv_wait_nowrap(sicpucv, sicpumtx);
    209  1.36.14.3  jdolecek 		}
    210  1.36.14.3  jdolecek 		sip = TAILQ_FIRST(&sicpupending);
    211  1.36.14.3  jdolecek 		TAILQ_REMOVE(&sicpupending, sip, sip_entries_cpu);
    212  1.36.14.3  jdolecek 		sip->sip_onlist_cpu = false;
    213  1.36.14.3  jdolecek 		rumpuser_mutex_exit(sicpumtx);
    214  1.36.14.3  jdolecek 
    215  1.36.14.3  jdolecek 		/*
    216  1.36.14.3  jdolecek 		 * ok, now figure out which cpu we need the softint to
    217  1.36.14.3  jdolecek 		 * be handled on
    218  1.36.14.3  jdolecek 		 */
    219  1.36.14.3  jdolecek 		si = sip->sip_parent;
    220  1.36.14.3  jdolecek 		cidx = sip - si->si_entry;
    221  1.36.14.3  jdolecek 		ci = cpu_lookup(cidx);
    222  1.36.14.3  jdolecek 		me->l_target_cpu = ci;
    223  1.36.14.3  jdolecek 
    224  1.36.14.3  jdolecek 		/* schedule ourselves there, and then schedule the softint */
    225  1.36.14.3  jdolecek 		rump_schedule();
    226  1.36.14.3  jdolecek 		KASSERT(curcpu() == ci);
    227  1.36.14.3  jdolecek 		softint_schedule(si);
    228  1.36.14.3  jdolecek 		rump_unschedule();
    229  1.36.14.3  jdolecek 	}
    230  1.36.14.3  jdolecek 	panic("sithread_cpu_bouncer unreasonable");
    231  1.36.14.3  jdolecek }
    232  1.36.14.3  jdolecek 
    233  1.36.14.2       tls static kmutex_t sithr_emtx;
    234  1.36.14.2       tls static unsigned int sithr_est;
    235  1.36.14.2       tls static int sithr_canest;
    236  1.36.14.2       tls 
    237  1.36.14.2       tls /*
    238  1.36.14.2       tls  * Create softint handler threads when the softint for each respective
    239  1.36.14.2       tls  * level is established for the first time.  Most rump kernels don't
    240  1.36.14.2       tls  * need at least half of the softint levels, so on-demand saves bootstrap
    241  1.36.14.2       tls  * time and memory resources.  Note, though, that this routine may be
    242  1.36.14.2       tls  * called before it's possible to call kthread_create().  Creation of
    243  1.36.14.2       tls  * those softints (SOFTINT_CLOCK, as of writing this) will be deferred
    244  1.36.14.2       tls  * to until softint_init() is called for the main CPU.
    245  1.36.14.2       tls  */
    246  1.36.14.2       tls static void
    247  1.36.14.2       tls sithread_establish(int level)
    248  1.36.14.2       tls {
    249  1.36.14.2       tls 	int docreate, rv;
    250  1.36.14.2       tls 	int lvlbit = 1<<level;
    251  1.36.14.2       tls 	int i;
    252  1.36.14.2       tls 
    253  1.36.14.2       tls 	KASSERT((level & ~SOFTINT_LVLMASK) == 0);
    254  1.36.14.2       tls 	if (__predict_true(sithr_est & lvlbit))
    255  1.36.14.2       tls 		return;
    256  1.36.14.2       tls 
    257  1.36.14.2       tls 	mutex_enter(&sithr_emtx);
    258  1.36.14.2       tls 	docreate = (sithr_est & lvlbit) == 0 && sithr_canest;
    259  1.36.14.2       tls 	sithr_est |= lvlbit;
    260  1.36.14.2       tls 	mutex_exit(&sithr_emtx);
    261  1.36.14.2       tls 
    262  1.36.14.2       tls 	if (docreate) {
    263  1.36.14.2       tls 		for (i = 0; i < ncpu_final; i++) {
    264  1.36.14.2       tls 			if ((rv = kthread_create(PRI_NONE,
    265  1.36.14.2       tls 			    KTHREAD_MPSAFE | KTHREAD_INTR,
    266  1.36.14.2       tls 			    cpu_lookup(i), sithread, (void *)(uintptr_t)level,
    267  1.36.14.2       tls 			    NULL, "rsi%d/%d", i, level)) != 0)
    268  1.36.14.2       tls 				panic("softint thread create failed: %d", rv);
    269  1.36.14.2       tls 		}
    270  1.36.14.2       tls 	}
    271  1.36.14.2       tls }
    272  1.36.14.2       tls 
    273        1.5     pooka void
    274       1.34     pooka rump_intr_init(int numcpu)
    275       1.22     pooka {
    276       1.22     pooka 
    277       1.23     pooka 	cv_init(&lbolt, "oh kath ra");
    278  1.36.14.2       tls 	mutex_init(&sithr_emtx, MUTEX_DEFAULT, IPL_NONE);
    279       1.34     pooka 	ncpu_final = numcpu;
    280       1.22     pooka }
    281       1.22     pooka 
    282       1.22     pooka void
    283        1.5     pooka softint_init(struct cpu_info *ci)
    284        1.2        ad {
    285       1.22     pooka 	struct cpu_data *cd = &ci->ci_data;
    286       1.22     pooka 	struct softint_lev *slev;
    287       1.20     pooka 	int rv, i;
    288        1.5     pooka 
    289       1.22     pooka 	if (!rump_threads)
    290       1.22     pooka 		return;
    291       1.22     pooka 
    292       1.22     pooka 	slev = kmem_alloc(sizeof(struct softint_lev) * SOFTINT_COUNT, KM_SLEEP);
    293       1.20     pooka 	for (i = 0; i < SOFTINT_COUNT; i++) {
    294       1.22     pooka 		rumpuser_cv_init(&slev[i].si_cv);
    295  1.36.14.3  jdolecek 		TAILQ_INIT(&slev[i].si_pending);
    296       1.20     pooka 	}
    297       1.22     pooka 	cd->cpu_softcpu = slev;
    298        1.2        ad 
    299  1.36.14.2       tls 	/* overloaded global init ... */
    300  1.36.14.2       tls 	/* XXX: should be done the last time we are called */
    301  1.36.14.2       tls 	if (ci->ci_index == 0) {
    302  1.36.14.2       tls 		int sithr_swap;
    303  1.36.14.2       tls 
    304  1.36.14.3  jdolecek 		/* pretend that we have our own for these */
    305  1.36.14.3  jdolecek 		stathz = 1;
    306  1.36.14.3  jdolecek 		schedhz = 1;
    307  1.36.14.3  jdolecek 		profhz = 1;
    308  1.36.14.3  jdolecek 
    309  1.36.14.3  jdolecek 		initclocks();
    310       1.28     pooka 
    311  1.36.14.2       tls 		/* create deferred softint threads */
    312  1.36.14.2       tls 		mutex_enter(&sithr_emtx);
    313  1.36.14.2       tls 		sithr_swap = sithr_est;
    314  1.36.14.2       tls 		sithr_est = 0;
    315  1.36.14.2       tls 		sithr_canest = 1;
    316  1.36.14.2       tls 		mutex_exit(&sithr_emtx);
    317  1.36.14.2       tls 		for (i = 0; i < SOFTINT_COUNT; i++) {
    318  1.36.14.2       tls 			if (sithr_swap & (1<<i))
    319  1.36.14.2       tls 				sithread_establish(i);
    320  1.36.14.2       tls 		}
    321       1.22     pooka 	}
    322       1.14     pooka 
    323  1.36.14.2       tls 	/* well, not really a "soft" interrupt ... */
    324  1.36.14.2       tls 	if ((rv = kthread_create(PRI_NONE, KTHREAD_MPSAFE,
    325  1.36.14.2       tls 	    ci, doclock, NULL, NULL, "rumpclk%d", ci->ci_index)) != 0)
    326       1.25     pooka 		panic("clock thread creation failed: %d", rv);
    327  1.36.14.3  jdolecek 
    328  1.36.14.3  jdolecek 	/* not one either, but at least a softint helper */
    329  1.36.14.3  jdolecek 	rumpuser_mutex_init(&sicpumtx, RUMPUSER_MTX_SPIN);
    330  1.36.14.3  jdolecek 	rumpuser_cv_init(&sicpucv);
    331  1.36.14.3  jdolecek 	if ((rv = kthread_create(PRI_NONE, KTHREAD_MPSAFE,
    332  1.36.14.3  jdolecek 	    NULL, sithread_cpu_bouncer, NULL, NULL, "sipbnc")) != 0)
    333  1.36.14.3  jdolecek 		panic("softint cpu bouncer creation failed: %d", rv);
    334        1.2        ad }
    335        1.2        ad 
    336        1.5     pooka void *
    337        1.5     pooka softint_establish(u_int flags, void (*func)(void *), void *arg)
    338        1.2        ad {
    339        1.5     pooka 	struct softint *si;
    340       1.32     pooka 	struct softint_percpu *sip;
    341  1.36.14.2       tls 	int level = flags & SOFTINT_LVLMASK;
    342       1.32     pooka 	int i;
    343        1.2        ad 
    344       1.28     pooka 	si = malloc(sizeof(*si), M_TEMP, M_WAITOK);
    345        1.5     pooka 	si->si_func = func;
    346        1.5     pooka 	si->si_arg = arg;
    347       1.18     pooka 	si->si_flags = flags & SOFTINT_MPSAFE ? SI_MPSAFE : 0;
    348  1.36.14.2       tls 	si->si_level = level;
    349       1.20     pooka 	KASSERT(si->si_level < SOFTINT_COUNT);
    350       1.34     pooka 	si->si_entry = malloc(sizeof(*si->si_entry) * ncpu_final,
    351       1.32     pooka 	    M_TEMP, M_WAITOK | M_ZERO);
    352       1.34     pooka 	for (i = 0; i < ncpu_final; i++) {
    353       1.32     pooka 		sip = &si->si_entry[i];
    354       1.32     pooka 		sip->sip_parent = si;
    355       1.32     pooka 	}
    356  1.36.14.2       tls 	sithread_establish(level);
    357        1.5     pooka 
    358        1.5     pooka 	return si;
    359        1.2        ad }
    360        1.2        ad 
    361  1.36.14.3  jdolecek static struct softint_percpu *
    362  1.36.14.3  jdolecek sitosip(struct softint *si, struct cpu_info *ci)
    363  1.36.14.3  jdolecek {
    364  1.36.14.3  jdolecek 
    365  1.36.14.3  jdolecek 	return &si->si_entry[ci->ci_index];
    366  1.36.14.3  jdolecek }
    367  1.36.14.3  jdolecek 
    368       1.33     pooka /*
    369       1.33     pooka  * Soft interrupts bring two choices.  If we are running with thread
    370       1.33     pooka  * support enabled, defer execution, otherwise execute in place.
    371       1.33     pooka  */
    372       1.33     pooka 
    373        1.2        ad void
    374        1.2        ad softint_schedule(void *arg)
    375        1.2        ad {
    376        1.5     pooka 	struct softint *si = arg;
    377  1.36.14.2       tls 	struct cpu_info *ci = curcpu();
    378  1.36.14.3  jdolecek 	struct softint_percpu *sip = sitosip(si, ci);
    379  1.36.14.2       tls 	struct cpu_data *cd = &ci->ci_data;
    380       1.22     pooka 	struct softint_lev *si_lvl = cd->cpu_softcpu;
    381        1.2        ad 
    382        1.5     pooka 	if (!rump_threads) {
    383        1.5     pooka 		si->si_func(si->si_arg);
    384        1.5     pooka 	} else {
    385       1.32     pooka 		if (!sip->sip_onlist) {
    386  1.36.14.3  jdolecek 			TAILQ_INSERT_TAIL(&si_lvl[si->si_level].si_pending,
    387       1.32     pooka 			    sip, sip_entries);
    388       1.32     pooka 			sip->sip_onlist = true;
    389        1.5     pooka 		}
    390        1.5     pooka 	}
    391        1.2        ad }
    392        1.2        ad 
    393  1.36.14.3  jdolecek /*
    394  1.36.14.3  jdolecek  * Like softint_schedule(), except schedule softint to be handled on
    395  1.36.14.3  jdolecek  * the core designated by ci_tgt instead of the core the call is made on.
    396  1.36.14.3  jdolecek  *
    397  1.36.14.3  jdolecek  * Unlike softint_schedule(), the performance is not important
    398  1.36.14.3  jdolecek  * (unless ci_tgt == curcpu): high-performance rump kernel I/O stacks
    399  1.36.14.3  jdolecek  * should arrange data to already be on the right core at the driver
    400  1.36.14.3  jdolecek  * layer.
    401  1.36.14.3  jdolecek  */
    402  1.36.14.2       tls void
    403  1.36.14.3  jdolecek softint_schedule_cpu(void *arg, struct cpu_info *ci_tgt)
    404  1.36.14.2       tls {
    405  1.36.14.3  jdolecek 	struct softint *si = arg;
    406  1.36.14.3  jdolecek 	struct cpu_info *ci_cur = curcpu();
    407  1.36.14.3  jdolecek 	struct softint_percpu *sip;
    408  1.36.14.3  jdolecek 
    409  1.36.14.3  jdolecek 	KASSERT(rump_threads);
    410  1.36.14.3  jdolecek 
    411  1.36.14.3  jdolecek 	/* preferred case (which can be optimized some day) */
    412  1.36.14.3  jdolecek 	if (ci_cur == ci_tgt) {
    413  1.36.14.3  jdolecek 		softint_schedule(si);
    414  1.36.14.3  jdolecek 		return;
    415  1.36.14.3  jdolecek 	}
    416  1.36.14.3  jdolecek 
    417  1.36.14.2       tls 	/*
    418  1.36.14.3  jdolecek 	 * no?  then it's softint turtles all the way down
    419  1.36.14.2       tls 	 */
    420  1.36.14.3  jdolecek 
    421  1.36.14.3  jdolecek 	sip = sitosip(si, ci_tgt);
    422  1.36.14.3  jdolecek 	rumpuser_mutex_enter_nowrap(sicpumtx);
    423  1.36.14.3  jdolecek 	if (sip->sip_onlist_cpu) {
    424  1.36.14.3  jdolecek 		rumpuser_mutex_exit(sicpumtx);
    425  1.36.14.3  jdolecek 		return;
    426  1.36.14.3  jdolecek 	}
    427  1.36.14.3  jdolecek 	TAILQ_INSERT_TAIL(&sicpupending, sip, sip_entries_cpu);
    428  1.36.14.3  jdolecek 	sip->sip_onlist_cpu = true;
    429  1.36.14.3  jdolecek 	rumpuser_cv_signal(sicpucv);
    430  1.36.14.3  jdolecek 	rumpuser_mutex_exit(sicpumtx);
    431  1.36.14.2       tls }
    432  1.36.14.2       tls 
    433       1.32     pooka /*
    434       1.32     pooka  * flimsy disestablish: should wait for softints to finish.
    435       1.32     pooka  */
    436       1.18     pooka void
    437       1.18     pooka softint_disestablish(void *cook)
    438       1.18     pooka {
    439       1.18     pooka 	struct softint *si = cook;
    440       1.32     pooka 	int i;
    441       1.18     pooka 
    442       1.34     pooka 	for (i = 0; i < ncpu_final; i++) {
    443       1.32     pooka 		struct softint_percpu *sip;
    444       1.32     pooka 
    445       1.32     pooka 		sip = &si->si_entry[i];
    446       1.32     pooka 		if (sip->sip_onlist) {
    447       1.32     pooka 			si->si_flags |= SI_KILLME;
    448       1.32     pooka 			return;
    449       1.32     pooka 		}
    450       1.18     pooka 	}
    451       1.32     pooka 	free(si->si_entry, M_TEMP);
    452       1.28     pooka 	free(si, M_TEMP);
    453       1.18     pooka }
    454       1.18     pooka 
    455       1.20     pooka void
    456       1.20     pooka rump_softint_run(struct cpu_info *ci)
    457       1.20     pooka {
    458       1.22     pooka 	struct cpu_data *cd = &ci->ci_data;
    459       1.22     pooka 	struct softint_lev *si_lvl = cd->cpu_softcpu;
    460       1.20     pooka 	int i;
    461       1.20     pooka 
    462       1.22     pooka 	if (!rump_threads)
    463       1.22     pooka 		return;
    464       1.22     pooka 
    465       1.20     pooka 	for (i = 0; i < SOFTINT_COUNT; i++) {
    466  1.36.14.3  jdolecek 		if (!TAILQ_EMPTY(&si_lvl[i].si_pending))
    467       1.22     pooka 			rumpuser_cv_signal(si_lvl[i].si_cv);
    468       1.20     pooka 	}
    469       1.20     pooka }
    470       1.20     pooka 
    471        1.2        ad bool
    472        1.9  christos cpu_intr_p(void)
    473        1.2        ad {
    474        1.2        ad 
    475        1.2        ad 	return false;
    476        1.2        ad }
    477       1.19     pooka 
    478       1.19     pooka bool
    479       1.19     pooka cpu_softintr_p(void)
    480       1.19     pooka {
    481       1.19     pooka 
    482       1.20     pooka 	return curlwp->l_pflag & LP_INTR;
    483       1.19     pooka }
    484