Home | History | Annotate | Line # | Download | only in rumpkern
intr.c revision 1.46.4.2
      1  1.46.4.2     skrll /*	$NetBSD: intr.c,v 1.46.4.2 2015/06/06 14:40:29 skrll Exp $	*/
      2       1.2        ad 
      3       1.5     pooka /*
      4  1.46.4.1     skrll  * 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.46.4.2     skrll __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.46.4.2 2015/06/06 14:40:29 skrll 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.5     pooka #include <rump/rumpuser.h>
     42       1.5     pooka 
     43       1.5     pooka #include "rump_private.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.46.4.1     skrll 	bool sip_onlist_cpu;
     66      1.32     pooka 
     67  1.46.4.1     skrll 	TAILQ_ENTRY(softint_percpu) sip_entries;	/* scheduled */
     68  1.46.4.1     skrll 	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.46.4.1     skrll 	TAILQ_HEAD(, softint_percpu) si_pending;
     74      1.22     pooka };
     75      1.10     pooka 
     76  1.46.4.1     skrll static TAILQ_HEAD(, softint_percpu) sicpupending \
     77  1.46.4.1     skrll     = TAILQ_HEAD_INITIALIZER(sicpupending);
     78  1.46.4.1     skrll static struct rumpuser_mtx *sicpumtx;
     79  1.46.4.1     skrll static struct rumpuser_cv *sicpucv;
     80  1.46.4.1     skrll 
     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.46.4.2     skrll void noclock(void); void noclock(void) {return;}
     86  1.46.4.2     skrll __strong_alias(sched_schedclock,noclock);
     87  1.46.4.2     skrll __strong_alias(cpu_initclocks,noclock);
     88  1.46.4.2     skrll __strong_alias(addupc_intr,noclock);
     89  1.46.4.2     skrll __strong_alias(sched_tick,noclock);
     90  1.46.4.2     skrll __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.38     pooka 	struct timespec thetick, curclock;
     99  1.46.4.2     skrll 	struct clockframe *clkframe;
    100      1.40     pooka 	int64_t sec;
    101      1.40     pooka 	long nsec;
    102      1.24     pooka 	int error;
    103  1.46.4.2     skrll 	struct cpu_info *ci = curcpu();
    104      1.14     pooka 
    105      1.39     pooka 	error = rumpuser_clock_gettime(RUMPUSER_CLOCK_ABSMONO, &sec, &nsec);
    106      1.38     pooka 	if (error)
    107      1.38     pooka 		panic("clock: cannot get monotonic time");
    108      1.38     pooka 
    109      1.38     pooka 	curclock.tv_sec = sec;
    110      1.38     pooka 	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.46.4.2     skrll 	/* generate dummy clockframe for hardclock to consume */
    115  1.46.4.2     skrll 	clkframe = rump_cpu_makeclockframe();
    116  1.46.4.2     skrll 
    117      1.10     pooka 	for (;;) {
    118  1.46.4.2     skrll 		int lbolt_ticks = 0;
    119  1.46.4.2     skrll 
    120  1.46.4.2     skrll 		hardclock(clkframe);
    121  1.46.4.2     skrll 		if (CPU_IS_PRIMARY(ci)) {
    122  1.46.4.2     skrll 			if (++lbolt_ticks >= hz) {
    123  1.46.4.2     skrll 				lbolt_ticks = 0;
    124  1.46.4.2     skrll 				cv_broadcast(&lbolt);
    125  1.46.4.2     skrll 			}
    126  1.46.4.2     skrll 		}
    127       1.5     pooka 
    128      1.39     pooka 		error = rumpuser_clock_sleep(RUMPUSER_CLOCK_ABSMONO,
    129      1.39     pooka 		    curclock.tv_sec, curclock.tv_nsec);
    130      1.38     pooka 		KASSERT(!error);
    131      1.38     pooka 		timespecadd(&curclock, &thetick, &curclock);
    132      1.10     pooka 	}
    133      1.10     pooka }
    134       1.8     pooka 
    135      1.10     pooka /*
    136      1.28     pooka  * Soft interrupt execution thread.  This thread is pinned to the
    137      1.28     pooka  * same CPU that scheduled the interrupt, so we don't need to do
    138      1.28     pooka  * lock against si_lvl.
    139      1.10     pooka  */
    140      1.10     pooka static void
    141      1.10     pooka sithread(void *arg)
    142      1.10     pooka {
    143      1.32     pooka 	struct softint_percpu *sip;
    144      1.10     pooka 	struct softint *si;
    145      1.10     pooka 	void (*func)(void *) = NULL;
    146      1.10     pooka 	void *funarg;
    147      1.10     pooka 	bool mpsafe;
    148      1.20     pooka 	int mylevel = (uintptr_t)arg;
    149      1.22     pooka 	struct softint_lev *si_lvlp, *si_lvl;
    150      1.22     pooka 	struct cpu_data *cd = &curcpu()->ci_data;
    151      1.20     pooka 
    152      1.22     pooka 	si_lvlp = cd->cpu_softcpu;
    153      1.22     pooka 	si_lvl = &si_lvlp[mylevel];
    154      1.22     pooka 
    155      1.10     pooka 	for (;;) {
    156  1.46.4.1     skrll 		if (!TAILQ_EMPTY(&si_lvl->si_pending)) {
    157  1.46.4.1     skrll 			sip = TAILQ_FIRST(&si_lvl->si_pending);
    158      1.32     pooka 			si = sip->sip_parent;
    159      1.32     pooka 
    160       1.5     pooka 			func = si->si_func;
    161       1.5     pooka 			funarg = si->si_arg;
    162      1.18     pooka 			mpsafe = si->si_flags & SI_MPSAFE;
    163       1.5     pooka 
    164      1.32     pooka 			sip->sip_onlist = false;
    165  1.46.4.1     skrll 			TAILQ_REMOVE(&si_lvl->si_pending, sip, sip_entries);
    166      1.20     pooka 			if (si->si_flags & SI_KILLME) {
    167      1.18     pooka 				softint_disestablish(si);
    168      1.20     pooka 				continue;
    169      1.20     pooka 			}
    170      1.10     pooka 		} else {
    171      1.28     pooka 			rump_schedlock_cv_wait(si_lvl->si_cv);
    172      1.10     pooka 			continue;
    173       1.5     pooka 		}
    174       1.5     pooka 
    175      1.10     pooka 		if (!mpsafe)
    176      1.10     pooka 			KERNEL_LOCK(1, curlwp);
    177      1.10     pooka 		func(funarg);
    178      1.10     pooka 		if (!mpsafe)
    179      1.10     pooka 			KERNEL_UNLOCK_ONE(curlwp);
    180       1.5     pooka 	}
    181      1.20     pooka 
    182      1.20     pooka 	panic("sithread unreachable");
    183       1.5     pooka }
    184       1.2        ad 
    185  1.46.4.1     skrll /*
    186  1.46.4.1     skrll  * Helper for softint_schedule_cpu()
    187  1.46.4.1     skrll  */
    188  1.46.4.1     skrll static void
    189  1.46.4.1     skrll sithread_cpu_bouncer(void *arg)
    190  1.46.4.1     skrll {
    191  1.46.4.1     skrll 	struct lwp *me;
    192  1.46.4.1     skrll 
    193  1.46.4.1     skrll 	me = curlwp;
    194  1.46.4.1     skrll 	me->l_pflag |= LP_BOUND;
    195  1.46.4.1     skrll 
    196  1.46.4.1     skrll 	rump_unschedule();
    197  1.46.4.1     skrll 	for (;;) {
    198  1.46.4.1     skrll 		struct softint_percpu *sip;
    199  1.46.4.1     skrll 		struct softint *si;
    200  1.46.4.1     skrll 		struct cpu_info *ci;
    201  1.46.4.1     skrll 		unsigned int cidx;
    202  1.46.4.1     skrll 
    203  1.46.4.1     skrll 		rumpuser_mutex_enter_nowrap(sicpumtx);
    204  1.46.4.1     skrll 		while (TAILQ_EMPTY(&sicpupending)) {
    205  1.46.4.1     skrll 			rumpuser_cv_wait_nowrap(sicpucv, sicpumtx);
    206  1.46.4.1     skrll 		}
    207  1.46.4.1     skrll 		sip = TAILQ_FIRST(&sicpupending);
    208  1.46.4.1     skrll 		TAILQ_REMOVE(&sicpupending, sip, sip_entries_cpu);
    209  1.46.4.1     skrll 		sip->sip_onlist_cpu = false;
    210  1.46.4.1     skrll 		rumpuser_mutex_exit(sicpumtx);
    211  1.46.4.1     skrll 
    212  1.46.4.1     skrll 		/*
    213  1.46.4.1     skrll 		 * ok, now figure out which cpu we need the softint to
    214  1.46.4.1     skrll 		 * be handled on
    215  1.46.4.1     skrll 		 */
    216  1.46.4.1     skrll 		si = sip->sip_parent;
    217  1.46.4.1     skrll 		cidx = sip - si->si_entry;
    218  1.46.4.1     skrll 		ci = cpu_lookup(cidx);
    219  1.46.4.1     skrll 		me->l_target_cpu = ci;
    220  1.46.4.1     skrll 
    221  1.46.4.1     skrll 		/* schedule ourselves there, and then schedule the softint */
    222  1.46.4.1     skrll 		rump_schedule();
    223  1.46.4.1     skrll 		KASSERT(curcpu() == ci);
    224  1.46.4.1     skrll 		softint_schedule(si);
    225  1.46.4.1     skrll 		rump_unschedule();
    226  1.46.4.1     skrll 	}
    227  1.46.4.1     skrll 	panic("sithread_cpu_bouncer unreasonable");
    228  1.46.4.1     skrll }
    229  1.46.4.1     skrll 
    230      1.41     pooka static kmutex_t sithr_emtx;
    231      1.41     pooka static unsigned int sithr_est;
    232      1.41     pooka static int sithr_canest;
    233      1.41     pooka 
    234      1.41     pooka /*
    235      1.41     pooka  * Create softint handler threads when the softint for each respective
    236      1.41     pooka  * level is established for the first time.  Most rump kernels don't
    237      1.41     pooka  * need at least half of the softint levels, so on-demand saves bootstrap
    238      1.41     pooka  * time and memory resources.  Note, though, that this routine may be
    239      1.41     pooka  * called before it's possible to call kthread_create().  Creation of
    240      1.41     pooka  * those softints (SOFTINT_CLOCK, as of writing this) will be deferred
    241      1.41     pooka  * to until softint_init() is called for the main CPU.
    242      1.41     pooka  */
    243      1.41     pooka static void
    244      1.41     pooka sithread_establish(int level)
    245      1.41     pooka {
    246      1.41     pooka 	int docreate, rv;
    247      1.41     pooka 	int lvlbit = 1<<level;
    248      1.41     pooka 	int i;
    249      1.41     pooka 
    250      1.41     pooka 	KASSERT((level & ~SOFTINT_LVLMASK) == 0);
    251      1.41     pooka 	if (__predict_true(sithr_est & lvlbit))
    252      1.41     pooka 		return;
    253      1.41     pooka 
    254      1.41     pooka 	mutex_enter(&sithr_emtx);
    255      1.41     pooka 	docreate = (sithr_est & lvlbit) == 0 && sithr_canest;
    256      1.41     pooka 	sithr_est |= lvlbit;
    257      1.41     pooka 	mutex_exit(&sithr_emtx);
    258      1.41     pooka 
    259      1.41     pooka 	if (docreate) {
    260      1.41     pooka 		for (i = 0; i < ncpu_final; i++) {
    261      1.41     pooka 			if ((rv = kthread_create(PRI_NONE,
    262      1.41     pooka 			    KTHREAD_MPSAFE | KTHREAD_INTR,
    263      1.41     pooka 			    cpu_lookup(i), sithread, (void *)(uintptr_t)level,
    264      1.41     pooka 			    NULL, "rsi%d/%d", i, level)) != 0)
    265      1.41     pooka 				panic("softint thread create failed: %d", rv);
    266      1.41     pooka 		}
    267      1.41     pooka 	}
    268      1.41     pooka }
    269      1.41     pooka 
    270       1.5     pooka void
    271      1.34     pooka rump_intr_init(int numcpu)
    272      1.22     pooka {
    273      1.22     pooka 
    274      1.23     pooka 	cv_init(&lbolt, "oh kath ra");
    275      1.41     pooka 	mutex_init(&sithr_emtx, MUTEX_DEFAULT, IPL_NONE);
    276      1.34     pooka 	ncpu_final = numcpu;
    277      1.22     pooka }
    278      1.22     pooka 
    279      1.22     pooka void
    280       1.5     pooka softint_init(struct cpu_info *ci)
    281       1.2        ad {
    282      1.22     pooka 	struct cpu_data *cd = &ci->ci_data;
    283      1.22     pooka 	struct softint_lev *slev;
    284      1.20     pooka 	int rv, i;
    285       1.5     pooka 
    286      1.22     pooka 	if (!rump_threads)
    287      1.22     pooka 		return;
    288      1.22     pooka 
    289      1.46     pooka 	slev = kmem_alloc(sizeof(struct softint_lev) * SOFTINT_COUNT, KM_SLEEP);
    290      1.46     pooka 	for (i = 0; i < SOFTINT_COUNT; i++) {
    291      1.46     pooka 		rumpuser_cv_init(&slev[i].si_cv);
    292  1.46.4.1     skrll 		TAILQ_INIT(&slev[i].si_pending);
    293      1.46     pooka 	}
    294      1.46     pooka 	cd->cpu_softcpu = slev;
    295      1.46     pooka 
    296      1.41     pooka 	/* overloaded global init ... */
    297      1.46     pooka 	/* XXX: should be done the last time we are called */
    298      1.25     pooka 	if (ci->ci_index == 0) {
    299      1.41     pooka 		int sithr_swap;
    300      1.41     pooka 
    301  1.46.4.2     skrll 		/* pretend that we have our own for these */
    302  1.46.4.2     skrll 		stathz = 1;
    303  1.46.4.2     skrll 		schedhz = 1;
    304  1.46.4.2     skrll 		profhz = 1;
    305  1.46.4.2     skrll 
    306  1.46.4.2     skrll 		initclocks();
    307      1.41     pooka 
    308      1.41     pooka 		/* create deferred softint threads */
    309      1.41     pooka 		mutex_enter(&sithr_emtx);
    310      1.41     pooka 		sithr_swap = sithr_est;
    311      1.41     pooka 		sithr_est = 0;
    312      1.41     pooka 		sithr_canest = 1;
    313      1.41     pooka 		mutex_exit(&sithr_emtx);
    314      1.41     pooka 		for (i = 0; i < SOFTINT_COUNT; i++) {
    315      1.41     pooka 			if (sithr_swap & (1<<i))
    316      1.41     pooka 				sithread_establish(i);
    317      1.41     pooka 		}
    318      1.25     pooka 	}
    319      1.25     pooka 
    320      1.41     pooka 	/* well, not really a "soft" interrupt ... */
    321      1.41     pooka 	if ((rv = kthread_create(PRI_NONE, KTHREAD_MPSAFE,
    322      1.41     pooka 	    ci, doclock, NULL, NULL, "rumpclk%d", ci->ci_index)) != 0)
    323      1.25     pooka 		panic("clock thread creation failed: %d", rv);
    324  1.46.4.1     skrll 
    325  1.46.4.1     skrll 	/* not one either, but at least a softint helper */
    326  1.46.4.1     skrll 	rumpuser_mutex_init(&sicpumtx, RUMPUSER_MTX_SPIN);
    327  1.46.4.1     skrll 	rumpuser_cv_init(&sicpucv);
    328  1.46.4.1     skrll 	if ((rv = kthread_create(PRI_NONE, KTHREAD_MPSAFE,
    329  1.46.4.1     skrll 	    NULL, sithread_cpu_bouncer, NULL, NULL, "sipbnc")) != 0)
    330  1.46.4.1     skrll 		panic("softint cpu bouncer creation failed: %d", rv);
    331       1.2        ad }
    332       1.2        ad 
    333       1.5     pooka void *
    334       1.5     pooka softint_establish(u_int flags, void (*func)(void *), void *arg)
    335       1.2        ad {
    336       1.5     pooka 	struct softint *si;
    337      1.32     pooka 	struct softint_percpu *sip;
    338      1.41     pooka 	int level = flags & SOFTINT_LVLMASK;
    339      1.32     pooka 	int i;
    340       1.2        ad 
    341      1.28     pooka 	si = malloc(sizeof(*si), M_TEMP, M_WAITOK);
    342       1.5     pooka 	si->si_func = func;
    343       1.5     pooka 	si->si_arg = arg;
    344      1.18     pooka 	si->si_flags = flags & SOFTINT_MPSAFE ? SI_MPSAFE : 0;
    345      1.41     pooka 	si->si_level = level;
    346      1.20     pooka 	KASSERT(si->si_level < SOFTINT_COUNT);
    347      1.34     pooka 	si->si_entry = malloc(sizeof(*si->si_entry) * ncpu_final,
    348      1.32     pooka 	    M_TEMP, M_WAITOK | M_ZERO);
    349      1.34     pooka 	for (i = 0; i < ncpu_final; i++) {
    350      1.32     pooka 		sip = &si->si_entry[i];
    351      1.32     pooka 		sip->sip_parent = si;
    352      1.32     pooka 	}
    353      1.41     pooka 	sithread_establish(level);
    354       1.5     pooka 
    355       1.5     pooka 	return si;
    356       1.2        ad }
    357       1.2        ad 
    358  1.46.4.1     skrll static struct softint_percpu *
    359  1.46.4.1     skrll sitosip(struct softint *si, struct cpu_info *ci)
    360  1.46.4.1     skrll {
    361  1.46.4.1     skrll 
    362  1.46.4.1     skrll 	return &si->si_entry[ci->ci_index];
    363  1.46.4.1     skrll }
    364  1.46.4.1     skrll 
    365      1.33     pooka /*
    366      1.33     pooka  * Soft interrupts bring two choices.  If we are running with thread
    367      1.33     pooka  * support enabled, defer execution, otherwise execute in place.
    368      1.33     pooka  */
    369      1.33     pooka 
    370       1.2        ad void
    371       1.2        ad softint_schedule(void *arg)
    372       1.2        ad {
    373       1.5     pooka 	struct softint *si = arg;
    374      1.42     pooka 	struct cpu_info *ci = curcpu();
    375  1.46.4.1     skrll 	struct softint_percpu *sip = sitosip(si, ci);
    376      1.42     pooka 	struct cpu_data *cd = &ci->ci_data;
    377      1.22     pooka 	struct softint_lev *si_lvl = cd->cpu_softcpu;
    378       1.2        ad 
    379       1.5     pooka 	if (!rump_threads) {
    380       1.5     pooka 		si->si_func(si->si_arg);
    381       1.5     pooka 	} else {
    382      1.32     pooka 		if (!sip->sip_onlist) {
    383  1.46.4.1     skrll 			TAILQ_INSERT_TAIL(&si_lvl[si->si_level].si_pending,
    384      1.32     pooka 			    sip, sip_entries);
    385      1.32     pooka 			sip->sip_onlist = true;
    386       1.5     pooka 		}
    387       1.5     pooka 	}
    388       1.2        ad }
    389       1.2        ad 
    390  1.46.4.1     skrll /*
    391  1.46.4.1     skrll  * Like softint_schedule(), except schedule softint to be handled on
    392  1.46.4.1     skrll  * the core designated by ci_tgt instead of the core the call is made on.
    393  1.46.4.1     skrll  *
    394  1.46.4.1     skrll  * Unlike softint_schedule(), the performance is not important
    395  1.46.4.1     skrll  * (unless ci_tgt == curcpu): high-performance rump kernel I/O stacks
    396  1.46.4.1     skrll  * should arrange data to already be on the right core at the driver
    397  1.46.4.1     skrll  * layer.
    398  1.46.4.1     skrll  */
    399      1.43     rmind void
    400  1.46.4.1     skrll softint_schedule_cpu(void *arg, struct cpu_info *ci_tgt)
    401      1.43     rmind {
    402  1.46.4.1     skrll 	struct softint *si = arg;
    403  1.46.4.1     skrll 	struct cpu_info *ci_cur = curcpu();
    404  1.46.4.1     skrll 	struct softint_percpu *sip;
    405  1.46.4.1     skrll 
    406  1.46.4.1     skrll 	KASSERT(rump_threads);
    407  1.46.4.1     skrll 
    408  1.46.4.1     skrll 	/* preferred case (which can be optimized some day) */
    409  1.46.4.1     skrll 	if (ci_cur == ci_tgt) {
    410  1.46.4.1     skrll 		softint_schedule(si);
    411  1.46.4.1     skrll 		return;
    412  1.46.4.1     skrll 	}
    413  1.46.4.1     skrll 
    414      1.44     rmind 	/*
    415  1.46.4.1     skrll 	 * no?  then it's softint turtles all the way down
    416      1.44     rmind 	 */
    417  1.46.4.1     skrll 
    418  1.46.4.1     skrll 	sip = sitosip(si, ci_tgt);
    419  1.46.4.1     skrll 	rumpuser_mutex_enter_nowrap(sicpumtx);
    420  1.46.4.1     skrll 	if (sip->sip_onlist_cpu) {
    421  1.46.4.1     skrll 		rumpuser_mutex_exit(sicpumtx);
    422  1.46.4.1     skrll 		return;
    423  1.46.4.1     skrll 	}
    424  1.46.4.1     skrll 	TAILQ_INSERT_TAIL(&sicpupending, sip, sip_entries_cpu);
    425  1.46.4.1     skrll 	sip->sip_onlist_cpu = true;
    426  1.46.4.1     skrll 	rumpuser_cv_signal(sicpucv);
    427  1.46.4.1     skrll 	rumpuser_mutex_exit(sicpumtx);
    428      1.43     rmind }
    429      1.43     rmind 
    430      1.32     pooka /*
    431      1.32     pooka  * flimsy disestablish: should wait for softints to finish.
    432      1.32     pooka  */
    433      1.18     pooka void
    434      1.18     pooka softint_disestablish(void *cook)
    435      1.18     pooka {
    436      1.18     pooka 	struct softint *si = cook;
    437      1.32     pooka 	int i;
    438      1.18     pooka 
    439      1.34     pooka 	for (i = 0; i < ncpu_final; i++) {
    440      1.32     pooka 		struct softint_percpu *sip;
    441      1.32     pooka 
    442      1.32     pooka 		sip = &si->si_entry[i];
    443      1.32     pooka 		if (sip->sip_onlist) {
    444      1.32     pooka 			si->si_flags |= SI_KILLME;
    445      1.32     pooka 			return;
    446      1.32     pooka 		}
    447      1.18     pooka 	}
    448      1.32     pooka 	free(si->si_entry, M_TEMP);
    449      1.28     pooka 	free(si, M_TEMP);
    450      1.18     pooka }
    451      1.18     pooka 
    452      1.20     pooka void
    453      1.20     pooka rump_softint_run(struct cpu_info *ci)
    454      1.20     pooka {
    455      1.22     pooka 	struct cpu_data *cd = &ci->ci_data;
    456      1.22     pooka 	struct softint_lev *si_lvl = cd->cpu_softcpu;
    457      1.20     pooka 	int i;
    458      1.20     pooka 
    459      1.22     pooka 	if (!rump_threads)
    460      1.22     pooka 		return;
    461      1.22     pooka 
    462      1.20     pooka 	for (i = 0; i < SOFTINT_COUNT; i++) {
    463  1.46.4.1     skrll 		if (!TAILQ_EMPTY(&si_lvl[i].si_pending))
    464      1.22     pooka 			rumpuser_cv_signal(si_lvl[i].si_cv);
    465      1.20     pooka 	}
    466      1.20     pooka }
    467      1.20     pooka 
    468       1.2        ad bool
    469       1.9  christos cpu_intr_p(void)
    470       1.2        ad {
    471       1.2        ad 
    472       1.2        ad 	return false;
    473       1.2        ad }
    474      1.19     pooka 
    475      1.19     pooka bool
    476      1.19     pooka cpu_softintr_p(void)
    477      1.19     pooka {
    478      1.19     pooka 
    479      1.20     pooka 	return curlwp->l_pflag & LP_INTR;
    480      1.19     pooka }
    481