/* us and them, after all we're only ordinary seconds */ static void rump_delay(unsigned int us) { uint64_t sec, nsec; sec = us / 1000000; nsec = (us % 1000000) * 1000; if (__predict_false(sec != 0)) printf("WARNING: over 1s delay\n"); rumpuser_clock_sleep(RUMPUSER_CLOCK_RELWALL, sec, nsec); }
/* * This locking needs work and will misbehave severely if: * 1) the backing memory has to be paged in * 2) some lockholder exits while holding the lock */ static void shmif_lockbus(struct shmif_mem *busmem) { int i = 0; while (__predict_false(atomic_cas_32(&busmem->shm_lock, LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)) { if (__predict_false(++i > LOCK_COOLDOWN)) { /* wait 1ms */ rumpuser_clock_sleep(RUMPUSER_CLOCK_RELWALL, 0, 1000*1000); i = 0; } continue; } membar_enter(); }
int kpause(const char *wmesg, bool intr, int timeo, kmutex_t *mtx) { extern int hz; int rv; uint64_t sec, nsec; if (mtx) mutex_exit(mtx); sec = timeo / hz; nsec = (timeo % hz) * (1000000000 / hz); rv = rumpuser_clock_sleep(RUMPUSER_CLOCK_RELWALL, sec, nsec); KASSERT(rv == 0); if (mtx) mutex_enter(mtx); return 0; }