예제 #1
0
void
ykbec_bell(void *arg, u_int pitch, u_int period, u_int volume, int poll)
{
	struct ykbec_softc *sc = (struct ykbec_softc *)arg;
	int bctrl;
	int s;

	s = spltty();
	bctrl = ykbec_read(sc, REG_BEEP_CONTROL);
	if (volume == 0 || timeout_pending(&sc->sc_bell_tmo)) {
		timeout_del(&sc->sc_bell_tmo);
		/* inline ykbec_bell_stop(arg); */
		ykbec_write(sc, REG_BEEP_CONTROL, bctrl & ~BEEP_ENABLE);
	}

	if (volume != 0) {
		ykbec_write(sc, REG_BEEP_CONTROL, bctrl | BEEP_ENABLE);
		if (poll) {
			delay(period * 1000);
			ykbec_write(sc, REG_BEEP_CONTROL, bctrl & ~BEEP_ENABLE);
		} else {
			timeout_add_msec(&sc->sc_bell_tmo, period);
		}
	}
	splx(s);
}
예제 #2
0
파일: pckbc.c 프로젝트: ajinkya93/OpenBSD
int
pckbcintr_internal(struct pckbc_internal *t, struct pckbc_softc *sc)
{
	u_char stat;
	pckbc_slot_t slot;
	struct pckbc_slotdata *q;
	int served = 0, data;

	/* reschedule timeout further into the idle times */
	if (timeout_pending(&t->t_poll))
		timeout_add_sec(&t->t_poll, 1);

	for(;;) {
		stat = bus_space_read_1(t->t_iot, t->t_ioh_c, 0);
		if (!(stat & KBS_DIB))
			break;

		served = 1;

		slot = (t->t_haveaux && (stat & KBS_AUXDATA)) ?
		    PCKBC_AUX_SLOT : PCKBC_KBD_SLOT;
		q = t->t_slotdata[slot];

		if (!q) {
			/* XXX do something for live insertion? */
#ifdef PCKBCDEBUG
			printf("pckbcintr: no dev for slot %d\n", slot);
#endif
			KBD_DELAY;
			(void) bus_space_read_1(t->t_iot, t->t_ioh_d, 0);
			continue;
		}

		if (q->polling)
			break; /* pckbc_poll_data() will get it */

		KBD_DELAY;
		data = bus_space_read_1(t->t_iot, t->t_ioh_d, 0);

		if (CMD_IN_QUEUE(q) && pckbc_cmdresponse(t, slot, data))
			continue;

		if (sc != NULL) {
			if (sc->inputhandler[slot])
				(*sc->inputhandler[slot])(sc->inputarg[slot],
				    data);
#ifdef PCKBCDEBUG
			else
				printf("pckbcintr: slot %d lost %d\n",
				    slot, data);
#endif
		}
	}

	return (served);
}
예제 #3
0
파일: trpt.c 프로젝트: SylvestreG/bitrig
/*ARGSUSED*/
void
tcp_trace(short act, short ostate, struct tcpcb *tp,
    struct tcpiphdr *ti, struct tcpipv6hdr *ti6, int req)
{
	tcp_seq seq, ack;
	int flags, len, win, timer;
	struct tcphdr *th;
	char hbuf[INET6_ADDRSTRLEN];

	if (ti->ti_src.s_addr)
		th = &ti->ti_t;
	else
		th = &ti6->ti6_t;

	printf("%03d %s:%s ", (ntime/10) % 1000, tcpstates[ostate],
	    tanames[act]);
	switch (act) {
	case TA_INPUT:
	case TA_OUTPUT:
	case TA_DROP:
		if (aflag) {
			if (ti->ti_src.s_addr) {
				printf("(src=%s,%u, ",
				    inet_ntoa(ti->ti_src), ntohs(ti->ti_sport));
				printf("dst=%s,%u)",
				    inet_ntoa(ti->ti_dst), ntohs(ti->ti_dport));
			} else {
				printf("(src=%s,%u, ",
				    inet_ntop(AF_INET6, &ti6->ti6_src,
				    hbuf, sizeof(hbuf)), ntohs(ti->ti_sport));
				printf("dst=%s,%u)",
				    inet_ntop(AF_INET6, &ti6->ti6_dst,
				    hbuf, sizeof(hbuf)), ntohs(ti->ti_dport));
			}
		}
		seq = th->th_seq;
		ack = th->th_ack;
		if (ti->ti_src.s_addr)
			len = ti->ti_len;
		else
			len = ti6->ti6_plen;	/*XXX intermediate header*/
		win = th->th_win;
		if (act == TA_OUTPUT) {
			NTOHL(seq);
			NTOHL(ack);
			NTOHS(win);
		}
		if (len)
			printf("[%x..%x)", seq, seq + len);
		else
			printf("%x", seq);
		printf("@%x", ack);
		if (win)
			printf("(win=%x)", win);
		flags = th->th_flags;
		if (flags) {
			char *cp = "<";
#define	pf(flag, string) { \
	if (th->th_flags & flag) { \
		(void)printf("%s%s", cp, string); \
		cp = ","; \
	} \
}
			pf(TH_SYN, "SYN");
			pf(TH_ACK, "ACK");
			pf(TH_FIN, "FIN");
			pf(TH_RST, "RST");
			pf(TH_PUSH, "PUSH");
			pf(TH_URG, "URG");
			printf(">");
		}
		break;
	case TA_USER:
		timer = req >> 8;
		req &= 0xff;
		printf("%s", prurequests[req]);
		if (req == PRU_SLOWTIMO || req == PRU_FASTTIMO)
			printf("<%s>", tcptimers[timer]);
		break;
	}
	printf(" -> %s", tcpstates[tp->t_state]);
	/* print out internal state of tp !?! */
	printf("\n");
	if (sflag) {
		printf("\trcv_nxt %x rcv_wnd %lx snd_una %x snd_nxt %x snd_max %x\n",
		    tp->rcv_nxt, tp->rcv_wnd, tp->snd_una, tp->snd_nxt,
		    tp->snd_max);
		printf("\tsnd_wl1 %x snd_wl2 %x snd_wnd %lx\n", tp->snd_wl1,
		    tp->snd_wl2, tp->snd_wnd);
	}
	/* print out timers? */
	if (tflag) {
		char *cp = "\t";
		int i;

		for (i = 0; i < TCPT_NTIMERS; i++) {
			if (timeout_pending(&tp->t_timer[i]))
				continue;
			printf("%s%s=%d", cp, tcptimers[i],
			    tp->t_timer[i].to_time);
			if (i == TCPT_REXMT)
				printf(" (t_rxtshft=%d)", tp->t_rxtshift);
			cp = ", ";
		}
		if (*cp != '\t')
			putchar('\n');
	}
}
예제 #4
0
static int check_randomized(const struct rand_cfg *cfg)
{
#define FAIL() do {					\
		printf("Failure on line %d\n", __LINE__);	\
		goto done;					\
	} while (0)

	int i, err;
	int rv = 1;
	struct timeout *t = calloc(cfg->n_timeouts, sizeof(struct timeout));
	timeout_t *timeouts = calloc(cfg->n_timeouts, sizeof(timeout_t));
	uint8_t *fired = calloc(cfg->n_timeouts, sizeof(uint8_t));
        uint8_t *found = calloc(cfg->n_timeouts, sizeof(uint8_t));
	uint8_t *deleted = calloc(cfg->n_timeouts, sizeof(uint8_t));
	struct timeouts *tos = timeouts_open(0, &err);
	timeout_t now = cfg->start_at;
	int n_added_pending = 0, cnt_added_pending = 0;
	int n_added_expired = 0, cnt_added_expired = 0;
        struct timeouts_it it_p, it_e, it_all;
        int p_done = 0, e_done = 0, all_done = 0;
	struct timeout *to = NULL;
	const int rel = cfg->relative;

	if (!t || !timeouts || !tos || !fired || !found || !deleted)
		FAIL();
	timeouts_update(tos, cfg->start_at);

	for (i = 0; i < cfg->n_timeouts; ++i) {
		if (&t[i] != timeout_init(&t[i], rel ? 0 : TIMEOUT_ABS))
			FAIL();
		if (timeout_pending(&t[i]))
			FAIL();
		if (timeout_expired(&t[i]))
			FAIL();

		timeouts[i] = random_to(cfg->min_timeout, cfg->max_timeout);

		timeouts_add(tos, &t[i], timeouts[i] - (rel ? now : 0));
		if (timeouts[i] <= cfg->start_at) {
			if (timeout_pending(&t[i]))
				FAIL();
			if (! timeout_expired(&t[i]))
				FAIL();
			++n_added_expired;
		} else {
			if (! timeout_pending(&t[i]))
				FAIL();
			if (timeout_expired(&t[i]))
				FAIL();
			++n_added_pending;
		}
	}

	if (!!n_added_pending != timeouts_pending(tos))
		FAIL();
	if (!!n_added_expired != timeouts_expired(tos))
		FAIL();

        /* Test foreach, interleaving a few iterators. */
        TIMEOUTS_IT_INIT(&it_p, TIMEOUTS_PENDING);
        TIMEOUTS_IT_INIT(&it_e, TIMEOUTS_EXPIRED);
        TIMEOUTS_IT_INIT(&it_all, TIMEOUTS_ALL);
        while (! (p_done && e_done && all_done)) {
		if (!p_done) {
			to = timeouts_next(tos, &it_p);
			if (to) {
				i = to - &t[0];
				++found[i];
				++cnt_added_pending;
			} else {
				p_done = 1;
			}
		}
		if (!e_done) {
			to = timeouts_next(tos, &it_e);
			if (to) {
				i = to - &t[0];
				++found[i];
				++cnt_added_expired;
			} else {
				e_done = 1;
			}
		}
		if (!all_done) {
			to = timeouts_next(tos, &it_all);
			if (to) {
				i = to - &t[0];
				++found[i];
			} else {
				all_done = 1;
			}
		}
        }

	for (i = 0; i < cfg->n_timeouts; ++i) {
		if (found[i] != 2)
			FAIL();
	}
	if (cnt_added_expired != n_added_expired)
		FAIL();
	if (cnt_added_pending != n_added_pending)
		FAIL();

	while (NULL != (to = timeouts_get(tos))) {
		i = to - &t[0];
		assert(&t[i] == to);
		if (timeouts[i] > cfg->start_at)
			FAIL(); /* shouldn't have happened yet */

		--n_added_expired; /* drop expired timeouts. */
		++fired[i];
	}

	if (n_added_expired != 0)
		FAIL();

	while (now < cfg->end_at) {
		int n_fired_this_time = 0;
		timeout_t first_at = timeouts_timeout(tos) + now;

		timeout_t oldtime = now;
		timeout_t step = random_to(1, cfg->max_step);
		int another;
		now += step;
		if (rel)
			timeouts_step(tos, step);
		else
			timeouts_update(tos, now);

		for (i = 0; i < cfg->try_removing; ++i) {
			int idx = random() % cfg->n_timeouts;
			if (! fired[idx]) {
				timeout_del(&t[idx]);
				++deleted[idx];
			}
		}

		another = (timeouts_timeout(tos) == 0);

		while (NULL != (to = timeouts_get(tos))) {
			if (! another)
				FAIL(); /* Thought we saw the last one! */
			i = to - &t[0];
			assert(&t[i] == to);
			if (timeouts[i] > now)
				FAIL(); /* shouldn't have happened yet */
			if (timeouts[i] <= oldtime)
				FAIL(); /* should have happened already */
			if (timeouts[i] < first_at)
				FAIL(); /* first_at should've been earlier */
			fired[i]++;
			n_fired_this_time++;
			another = (timeouts_timeout(tos) == 0);
		}
		if (n_fired_this_time && first_at > now)
			FAIL(); /* first_at should've been earlier */
		if (another)
			FAIL(); /* Huh? We think there are more? */
		if (!timeouts_check(tos, stderr))
			FAIL();
	}

	for (i = 0; i < cfg->n_timeouts; ++i) {
		if (fired[i] > 1)
			FAIL(); /* Nothing fired twice. */
		if (timeouts[i] <= now) {
			if (!(fired[i] || deleted[i]))
				FAIL();
		} else {
			if (fired[i])
				FAIL();
		}
		if (fired[i] && deleted[i])
			FAIL();
		if (cfg->finalize > 1) {
			if (!fired[i])
				timeout_del(&t[i]);
		}
	}

	/* Now nothing more should fire between now and the end of time. */
	if (cfg->finalize) {
		timeouts_update(tos, THE_END_OF_TIME);
		if (cfg->finalize > 1) {
			if (timeouts_get(tos))
				FAIL();
			TIMEOUTS_FOREACH(to, tos, TIMEOUTS_ALL)
				FAIL();
		}
	}
	rv = 0;

 done:
	if (tos) timeouts_close(tos);
	if (t) free(t);
	if (timeouts) free(timeouts);
	if (fired) free(fired);
	if (found) free(found);
	if (deleted) free(deleted);
	return rv;
}
예제 #5
0
int
check_intervals(struct intervals_cfg *cfg)
{
	int i, err;
	int rv = 1;
	struct timeout *to;
	struct timeout *t = calloc(cfg->n_timeouts, sizeof(struct timeout));
	unsigned *fired = calloc(cfg->n_timeouts, sizeof(unsigned));
	struct timeouts *tos = timeouts_open(0, &err);

	timeout_t now = cfg->start_at;
	if (!t || !tos || !fired)
		FAIL();

	timeouts_update(tos, now);

	for (i = 0; i < cfg->n_timeouts; ++i) {
		if (&t[i] != timeout_init(&t[i], TIMEOUT_INT))
			FAIL();
		if (timeout_pending(&t[i]))
			FAIL();
		if (timeout_expired(&t[i]))
			FAIL();

		timeouts_add(tos, &t[i], cfg->timeouts[i]);
		if (! timeout_pending(&t[i]))
			FAIL();
		if (timeout_expired(&t[i]))
			FAIL();
	}

	while (now < cfg->end_at) {
		timeout_t delay = timeouts_timeout(tos);
		if (cfg->skip && delay < cfg->skip)
			delay = cfg->skip;
		timeouts_step(tos, delay);
		now += delay;

		while (NULL != (to = timeouts_get(tos))) {
			i = to - &t[0];
			assert(&t[i] == to);
			fired[i]++;
			if (0 != (to->expires - cfg->start_at) % cfg->timeouts[i])
				FAIL();
			if (to->expires <= now)
				FAIL();
			if (to->expires > now + cfg->timeouts[i])
				FAIL();
		}
		if (!timeouts_check(tos, stderr))
			FAIL();
	}

	timeout_t duration = now - cfg->start_at;
	for (i = 0; i < cfg->n_timeouts; ++i) {
		if (cfg->skip) {
			if (fired[i] > duration / cfg->timeouts[i])
				FAIL();
		} else {
			if (fired[i] != duration / cfg->timeouts[i])
				FAIL();
		}
		if (!timeout_pending(&t[i]))
			FAIL();
	}

	rv = 0;
 done:
	if (t) free(t);
	if (fired) free(fired);
	if (tos) free(tos);
	return rv;
}