示例#1
0
文件: cmd.c 项目: 0bliv10n/s2e
void
timestr(
	struct timeval	*tv,
	char		*ts,
	size_t		size,
	int		format)
{
	double		usec = (double)tv->tv_usec / 1000000.0;

	if (format & TERSE_FIXED_TIME) {
		if (!HOURS(tv->tv_sec)) {
			snprintf(ts, size, "%u:%02u.%02u",
				(unsigned int) MINUTES(tv->tv_sec),
				(unsigned int) SECONDS(tv->tv_sec),
				(unsigned int) (usec * 100));
			return;
		}
		format |= VERBOSE_FIXED_TIME;	/* fallback if hours needed */
	}

	if ((format & VERBOSE_FIXED_TIME) || tv->tv_sec) {
		snprintf(ts, size, "%u:%02u:%02u.%02u",
			(unsigned int) HOURS(tv->tv_sec),
			(unsigned int) MINUTES(tv->tv_sec),
			(unsigned int) SECONDS(tv->tv_sec),
			(unsigned int) (usec * 100));
	} else {
		snprintf(ts, size, "0.%04u sec", (unsigned int) (usec * 10000));
	}
}
void 
udtourny(void)
{
    int     trem;
    char    buf[120];
    if (!status2->league)
	return;

    /* server is configured for league play */

    if (status2->league == 1)
	return;			/* we're still prepping */

    trem = --status2->leagueticksleft;


    switch (status2->league) {
    case 2:			/* the 1-minute pre tourney warm up. */
	if (trem == SECONDS(5))
	    pmessage("5 seconds to tournament start", -1, MALL, UMPIRE);
	else if (trem == SECONDS(2))
	    pmessage("Hold on to your hats.  Everybody dies!", -1, MALL, UMPIRE);
	else if (trem <= 0) {
	    starttourn();
	}
	break;

    case 3:			/* full-on T-mode */

	buf[0] = 0;
	if (trem % MINUTES(20) == 0 ||
	    (trem < MINUTES(20) && 0 == trem % MINUTES(5)) ||
	    (trem < MINUTES(5) && 0 == trem % MINUTES(1))) {
	    sprintf(buf, "There are %d minutes remaining in regulation play",
		    trem / MINUTES(1));
	}
	else if (trem < MINUTES(1) && 0 == trem % SECONDS(10)) {
	    sprintf(buf, "There are %d seconds remaining in regulation play",
		    trem / SECONDS(1));
	}
	if (buf[0])
	    pmessage(buf, -1, MALL, UMPIRE);
	if (trem <= 0)
	    /* maybe go into overtime */
	    endtourn();
	break;
    case 4:
	/* overtime, not implemented */
	break;
    }
}
示例#3
0
/*
 * Returns max number of nsecs to wait
 */
s_time_t tpm_calc_ordinal_duration(struct tpm_chip *chip,
      uint32_t ordinal)
{
   int duration_idx = TPM_UNDEFINED;
   s_time_t duration = 0;

   if (ordinal < TPM_MAX_ORDINAL)
      duration_idx = tpm_ordinal_duration[ordinal];
   else if ((ordinal & TPM_PROTECTED_ORDINAL_MASK) <
	 TPM_MAX_PROTECTED_ORDINAL)
      duration_idx =
	 tpm_protected_ordinal_duration[ordinal &
	 TPM_PROTECTED_ORDINAL_MASK];

   if (duration_idx != TPM_UNDEFINED) {
      duration = chip->duration[duration_idx];
   }

   if (duration <= 0) {
      return SECONDS(120);
   }
   else
   {
      return duration;
   }
}
示例#4
0
/*! .

	\param [in]
	\param [out]
	\param [in,out]

	\pre
	\post
	\return

*/
NTSTATUS
FlTimerThreadStop()
{
    LARGE_INTEGER tend_timeout;


    DBGPRINT("[flmonflt] Stopping timer thread.\n");

    tend_timeout.QuadPart = RELATIVE(SECONDS(8));
    TimerThreadStopExec = TRUE;


    KeCancelTimer(DriverInfoData->Timer);
    KeSetEvent(DriverInfoData->TimerThreadSleepWakeup, 0, FALSE);

    DBGPRINT("[flmonflt] Waiting for thread to exit.\n");
    KeWaitForSingleObject(DriverInfoData->TimerThread, Executive, KernelMode, TRUE, &tend_timeout);

    DBGPRINT("[flmonflt] Thread exited, dereferencing object.\n");
    ObDereferenceObject(DriverInfoData->TimerThread);

    DBGPRINT("[flmonflt] Thread dereferenced.\n");

    return STATUS_SUCCESS;
}
示例#5
0
//--------------------------------------------------------------------------------------
VOID DriverEntryContinueThread(PVOID Param)
{
    LARGE_INTEGER Timeout = { 0 };
    Timeout.QuadPart = RELATIVE(SECONDS(3));    
    
    DbgMsg(__FILE__, __LINE__, "Unloading old driver...\n");

    NTSTATUS ns = ZwUnloadDriver(&m_RegistryPath);
    if (NT_SUCCESS(ns))
    {
        DbgMsg(__FILE__, __LINE__, "OK\n");
    }
    else
    {
        DbgMsg(__FILE__, __LINE__, "ZwUnloadDriver() fails; status: 0x%.8x\n", ns);
    }

    while (true)
    {
        DbgPrint(__FUNCTION__"(): I'm allive!\n");

        // sleep
        KeDelayExecutionThread(KernelMode, FALSE, &Timeout);        
    }
}
示例#6
0
/*
 * This program toggles PIN IO 8 so if you connect an LED to that pin you
 * should see something.
 */
void main(void)
{
	struct device *gpio_device;

	struct nano_timer timer;
	void *timer_data[1];

	int ret;
	int pin_state = 1;

	nano_timer_init(&timer, timer_data);

	gpio_device = device_get_binding(GPIO_DRV_NAME);
	if (!gpio_device) {
		return;
	}

	ret = gpio_pin_configure(gpio_device, GPIO_OUT_PIN, (GPIO_DIR_OUT));
	if (ret) {
		return;
	}

	while (1) {

		gpio_pin_write(gpio_device, GPIO_OUT_PIN, pin_state);

		pin_state = !pin_state;

		nano_timer_start(&timer, SECONDS(1));
		nano_timer_test(&timer, TICKS_UNLIMITED);
	}
}
示例#7
0
static void show_elapsed_time(int beg, int end, uint cnt, double val,
			      const char *lbl1, const char *lbl2)
{
    int tm = end - beg;
    if (!fMakeCheck)
	printf("    %dm:%02ds for %u %s.  avg: %.1f %s\n",
	       MIN(tm), SECONDS(tm), cnt, lbl1, val, lbl2);
}
示例#8
0
文件: fltime.c 项目: hzeis/flamingo
PyObject *ticks_to_seconds(PyObject *self, PyObject *args) {
    int ticks;
    if (!PyArg_ParseTuple(args, "i", &ticks)) {
        PyErr_SetString(PyExc_TypeError, "expected type 'int'");
        return NULL;
    }
    return Py_BuildValue("d", SECONDS(ticks));
}
示例#9
0
void halt(uint8_t times)
{
	while(TRUE)
	{
		blink(times);
		timer_wait(SECONDS(3));
	}
}
示例#10
0
文件: flowman.c 项目: berkus/nemesis
static void alive_thd(void *data)
{
    while(1)
    {
	PAUSE(SECONDS(1));
	eprintf("@");
    }
}
示例#11
0
void RegressionTaskEntry(void)
{
	int  tcRC;

	nano_sem_init(&test_nano_timers_sem);

	PRINT_DATA("Starting timer tests\n");
	PRINT_LINE;

	task_fiber_start(test_nano_timers_stack, 512, test_nano_timers, 0, 0, 5, 0);

	/* Test the task_timer_alloc() API */

	TC_PRINT("Test the allocation of timers\n");
	tcRC = testLowTimerGet();
	if (tcRC != TC_PASS) {
		goto exitRtn;
	}

	TC_PRINT("Test the one shot feature of a timer\n");
	tcRC = testLowTimerOneShot();
	if (tcRC != TC_PASS) {
		goto exitRtn;
	}

	TC_PRINT("Test that a timer does not start\n");
	tcRC = testLowTimerDoesNotStart();
	if (tcRC != TC_PASS) {
		goto exitRtn;
	}

	TC_PRINT("Test the periodic feature of a timer\n");
	tcRC = testLowTimerPeriodicity();
	if (tcRC != TC_PASS) {
		goto exitRtn;
	}

	TC_PRINT("Test the stopping of a timer\n");
	tcRC = testLowTimerStop();
	if (tcRC != TC_PASS) {
		goto exitRtn;
	}

	TC_PRINT("Verifying the nanokernel timer fired\n");
	if (!nano_task_sem_take(&test_nano_timers_sem)) {
		tcRC = TC_FAIL;
		goto exitRtn;
	}

	TC_PRINT("Verifying the nanokernel timeouts worked\n");
	tcRC = task_sem_take_wait_timeout(test_nano_timeouts_sem, SECONDS(5));
	tcRC = tcRC == RC_OK ? TC_PASS : TC_FAIL;

exitRtn:
	TC_END_RESULT(tcRC);
	TC_END_REPORT(tcRC);
}
示例#12
0
void upm_delay(int time){
#if defined(linux)
    sleep(time);
#elif defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB)
    struct nano_timer timer;
    void *timer_data[1];
    nano_timer_init(&timer, timer_data);
    nano_timer_start(&timer, SECONDS(time));
    nano_timer_test(&timer, TICKS_UNLIMITED);
#endif
}
示例#13
0
/* "udp_data" is where to build up the state.
 * "laddr" is the local address. Must be valid, or 0 to autoalloc.
 * "raddr" is the remote address. Can be NULL to indicate a receive stack,
 *   not yet configured for transmit 
 * Caller must hold sock->lock
 */
static int build_stack(struct udp_data *udp_data,
		struct sockaddr_in *laddr,
		struct sockaddr_in *raddr)
{
    FlowMan_SAP		lsap, rsap;
    FlowMan_RouteInfo	* NOCLOBBER ri=NULL;
    FlowMan_RouteInfoSeq * NOCLOBBER ris=NULL;
    IOOffer_clp	        rxoffer, txoffer;
    Net_EtherAddr	hwaddr;
    char		buf[32];
    EtherMod_cl        *ethmod;
    IPMod_cl           *ipmod;
    UDPMod_cl          *udpmod;
    int			i, j;
    IO_Rec		recs[3];
    pktcx_t            *pktcx;

    /*sockets get best effort transmit QoS */
    Netif_TXQoS		txqos = { SECONDS(1), 0, True }; 

    rsap.tag = FlowMan_PT_UDP;
    rsap.u.UDP.addr.a = (raddr)? raddr->sin_addr.s_addr : 0;
    rsap.u.UDP.port   = (raddr)? raddr->sin_port : 0;
    lsap.tag = FlowMan_PT_UDP;
    lsap.u.UDP.addr.a = laddr->sin_addr.s_addr;
    lsap.u.UDP.port   = laddr->sin_port;

    /* find the interface to listen on. */

    /* XXX we don't know if this is for incoming or outgoing. We can
     * guess, based on whether we have a raddr at all.  Should really
     * have multiple stacks for rx on all interfaces, and single for
     * transmit on outgoing one. For the moment, we'll route for
     * outgoing packets */
    if (raddr)  /* if we've got the raddr, then assume TX */
    {
	TRY {
	    ri = FlowMan$ActiveRoute(udp_data->fman, &rsap);
	} CATCH_FlowMan$NoRoute() {
	    ri = NULL;
	} ENDTRY;
	if (!ri)
	{
	    printf("build_stack: no route to host %x\n",
		   ntohl(rsap.u.UDP.addr.a));
	    return -1;
	}
	TRC(eprintf("build_stack: routed %x to intf %s, gateway %x\n",
		   ntohl(rsap.u.UDP.addr.a), ri->ifname, ntohl(ri->gateway)));
    }
    else /* assume RX */
    {
示例#14
0
文件: AuMod.c 项目: berkus/nemesis
Au_Rec *getaurec(const Au_Rec *in) {
    Au_Rec NOCLOBBER *myau;

    myau = in;
    while(!myau) {
	TRY {
	    myau = NAME_FIND("dev>audio0", Au_Rec);
	} CATCH_ALL {
	    PAUSE(SECONDS(1));
	} ENDTRY;
    }
    return myau;
}
示例#15
0
文件: lifo.c 项目: 32bitmicro/zephyr
int fiberLifoWaitTest(void)
{
	void *data;     /* ptr to data retrieved from LIFO */

	/*
	 * The LIFO is empty; wait for an item to be added to the LIFO
	 * from the task.
	 */

	TC_PRINT("Fiber waiting on an empty LIFO\n");
	nano_fiber_sem_give(&taskWaitSem);
	data = nano_fiber_lifo_get(&test_lifo, TICKS_UNLIMITED);
	if (data != &lifoItem[0]) {
		fiberDetectedFailure = 1;
		return -1;
	}

	nano_fiber_sem_take(&fiberWaitSem, TICKS_UNLIMITED);
	data = nano_fiber_lifo_get(&test_lifo, TICKS_UNLIMITED);
	if (data != &lifoItem[2]) {
		fiberDetectedFailure = 1;
		return -1;
	}

	/*
	 * Give the task some time to check the results.  Ideally, this would
	 * be waiting for a semaphore instead of a using a delay, but if the
	 * main task wakes the fiber before it blocks on the LIFO, the fiber
	 * will add the item to the LIFO too soon.  Obviously, a semaphore could
	 * not be given if the task is blocked on the LIFO; hence the delay.
	 */

	nano_fiber_timer_start(&timer, SECONDS(2));
	nano_fiber_timer_test(&timer, TICKS_UNLIMITED);

	/* The task is waiting on an empty LIFO.  Wake it up. */
	nano_fiber_lifo_put(&test_lifo, &lifoItem[3]);
	nano_fiber_lifo_put(&test_lifo, &lifoItem[1]);

	/*
	 * Wait for the task to check the results.  If the results pass, then the
	 * the task will wake the fiber.  If the results do not pass, then the
	 * fiber will wait forever.
	 */

	nano_fiber_sem_take(&fiberWaitSem, TICKS_UNLIMITED);

	return 0;
}
示例#16
0
void install_ipi_test(void)
{
    static struct timer initial_delay_timer;

    /* We try to delay starting the test by a few seconds, just to let
     * everything calm down a bit. */
    printk("Install IPI test\n");

    init_timer(&initial_delay_timer,
	       run_ipi_test,
	       NULL,
	       0);

    set_timer(&initial_delay_timer, NOW() + SECONDS(5));
}
示例#17
0
static void trace_message(struct io *iop)
{
	char scratch[15];
	char msg[iop->t.pdu_len + 1];

	if (!io_setup(iop, IOP_M))
		return;

	memcpy(msg, iop->pdu, iop->t.pdu_len);
	msg[iop->t.pdu_len] = '\0';

	fprintf(msgs_ofp, "%s %5d.%09lu %s\n",
		make_dev_hdr(scratch, 15, iop->dip, 1),
		(int)SECONDS(iop->t.time),
		(unsigned long)NANO_SECONDS(iop->t.time), msg);
}
示例#18
0
文件: main.c 项目: 32bitmicro/zephyr
void main(void)
{
	int cnt = 0;
	struct device *gpiob;

	gpiob = device_get_binding(PORT);

	gpio_pin_configure(gpiob, LED1, GPIO_DIR_OUT);
	gpio_pin_configure(gpiob, LED2, GPIO_DIR_OUT);

	while (1) {
		gpio_pin_write(gpiob, LED1, cnt % 2);
		gpio_pin_write(gpiob, LED2, (cnt + 1) % 2);
		task_sleep(SECONDS(1));
		cnt++;
	}
}
示例#19
0
static void test_nano_timers(int unused1, int unused2)
{
	struct nano_timer timer;

	ARG_UNUSED(unused1);
	ARG_UNUSED(unused2);

	nano_timer_init(&timer, (void *)0xdeadbeef);
	TC_PRINT("starting nano timer to expire in %d seconds\n",
				TEST_NANO_TIMERS_DELAY);
	nano_fiber_timer_start(&timer, SECONDS(TEST_NANO_TIMERS_DELAY));
	TC_PRINT("fiber pending on timer\n");
	nano_fiber_timer_wait(&timer);
	TC_PRINT("fiber back from waiting on timer: giving semaphore.\n");
	nano_task_sem_give(&test_nano_timers_sem);
	TC_PRINT("fiber semaphore given.\n");

	/* on failure, don't give semaphore, main test will not obtain it */
}
示例#20
0
文件: NashMod.c 项目: berkus/nemesis
static void WS_Closure_Apply_m (
        Closure_cl      *self )
{
    Closure_clp termclosure;
    Type_Any any;
    bool_t gotws = False;

    printf("WS Nash starting\n");
    while (!gotws) {
	gotws = Context$Get(Pvs(root), "svc>WS", &any);
	if (!gotws) PAUSE(SECONDS(1));
    }

    termclosure = NAME_FIND("modules>WSterm", Closure_clp);
    Closure$Apply(termclosure);


    PromptInterpreter(NULL);
}
示例#21
0
/**
 *
 * @brief Perform all selected benchmarks
 * see config.h to select or to unselect
 *
 * @return N/A
 */
void BenchTask(void)
{
	int autorun = 0, continuously = 0;

	init_output(&continuously, &autorun);
	bench_test_init();

	PRINT_STRING(newline, output_file);
	do {
		PRINT_STRING(dashline, output_file);
		PRINT_STRING("|          S I M P L E   S E R V I C E    "
					 "M E A S U R E M E N T S  |  nsec    |\n",
					 output_file);
		PRINT_STRING(dashline, output_file);
		task_start(RECVTASK);
		call_test();
		queue_test();
		sema_test();
		mutex_test();
		memorymap_test();
		mempool_test();
		event_test();
		mailbox_test();
		pipe_test();
		PRINT_STRING("|         END OF TESTS                     "
					 "                                   |\n",
					 output_file);
		PRINT_STRING(dashline, output_file);
		PRINT_STRING("PROJECT EXECUTION SUCCESSFUL\n",output_file);
	} while (continuously && !kbhit());

	WAIT_FOR_USER();

	if (autorun) {
		task_sleep(SECONDS(2));
	}

	output_close();
}
示例#22
0
void upm_delay(unsigned int time)
{
    if (time <= 0)
        time = 1;

#if defined(UPM_PLATFORM_LINUX)

    struct timespec delay_time;

    delay_time.tv_sec  = time;
    delay_time.tv_nsec = 0;
    // The advantage over sleep(3) here is that it will not use
    // an alarm signal or handler.

    // here we spin until the delay is complete - detecting signals
    // and continuing where we left off
    while (nanosleep(&delay_time, &delay_time) && errno == EINTR)
        ; // loop

#elif defined(UPM_PLATFORM_ZEPHYR)
# if KERNEL_VERSION_MAJOR == 1 && KERNEL_VERSION_MINOR >= 6

    struct k_timer timer;
    k_timer_init(&timer, NULL, NULL);
    k_timer_start(&timer, time * 1000, 0);
    k_timer_status_sync(&timer);

# else

    struct nano_timer timer;
    void *timer_data[1];
    nano_timer_init(&timer, timer_data);
    nano_timer_start(&timer, SECONDS(time) + 1);
    nano_timer_test(&timer, TICKS_UNLIMITED);

# endif

#endif
}
示例#23
0
文件: fifo.c 项目: 32bitmicro/zephyr
void fiber3(void)
{
	void *pData;

	/* Wait for fiber3 to be activated */
	nano_fiber_sem_take(&nanoSemObj3, TICKS_UNLIMITED);

	/* Put two items onto <nanoFifoObj2> to unblock fibers #1 and #2. */
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[0]);    /* Wake fiber1 */
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[1]);    /* Wake fiber2 */

	/* Wait for fiber3 to be re-activated */
	nano_fiber_sem_take(&nanoSemObj3, TICKS_UNLIMITED);

	/* Immediately get the data from <nanoFifoObj2>. */
	pData = nano_fiber_fifo_get(&nanoFifoObj2, TICKS_UNLIMITED);
	if (pData != pPutList2[0]) {
		retCode = TC_FAIL;
		TC_ERROR("fiber3 (1) - got 0x%x from <nanoFifoObj2>, expected 0x%x\n",
				 pData, pPutList2[0]);
	}

	/* Put three items onto the FIFO for the task to get */
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[0]);
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[1]);
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[2]);

	/* Sleep for 2 seconds */
	nano_fiber_timer_start(&timer, SECONDS(2));
	nano_fiber_timer_test(&timer, TICKS_UNLIMITED);

	/* Put final item onto the FIFO for the task to get */
	nano_fiber_fifo_put(&nanoFifoObj2, pPutList2[3]);

	/* Wait for fiber3 to be re-activated (not expected to occur) */
	nano_fiber_sem_take(&nanoSemObj3, TICKS_UNLIMITED);
}
示例#24
0
文件: sys.c 项目: jonludlam/xen-arm
int nanosleep(const struct timespec *req, struct timespec *rem)
{
    s_time_t start = NOW();
    s_time_t stop = start + SECONDS(req->tv_sec) + req->tv_nsec;
    s_time_t stopped;
    struct thread *thread = get_current();

    thread->wakeup_time = stop;
    clear_runnable(thread);
    schedule();
    stopped = NOW();

    if (rem)
    {
	s_time_t remaining = stop - stopped;
	if (remaining > 0)
	{
	    rem->tv_nsec = remaining % 1000000000ULL;
	    rem->tv_sec  = remaining / 1000000000ULL;
	} else memset(rem, 0, sizeof(*rem));
    }

    return 0;
}
示例#25
0
文件: sys.c 项目: jonludlam/xen-arm
/* Just poll without blocking */
static int select_poll(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds)
{
    int i, n = 0;
#ifdef HAVE_LWIP
    int sock_n = 0, sock_nfds = 0;
    fd_set sock_readfds, sock_writefds, sock_exceptfds;
    struct timeval timeout = { .tv_sec = 0, .tv_usec = 0};
#endif

#ifdef LIBC_VERBOSE
    static int nb;
    static int nbread[NOFILE], nbwrite[NOFILE], nbexcept[NOFILE];
    static s_time_t lastshown;

    nb++;
#endif

#ifdef HAVE_LWIP
    /* first poll network */
    FD_ZERO(&sock_readfds);
    FD_ZERO(&sock_writefds);
    FD_ZERO(&sock_exceptfds);
    for (i = 0; i < nfds; i++) {
	if (files[i].type == FTYPE_SOCKET) {
	    if (FD_ISSET(i, readfds)) {
		FD_SET(files[i].socket.fd, &sock_readfds);
		sock_nfds = i+1;
	    }
	    if (FD_ISSET(i, writefds)) {
		FD_SET(files[i].socket.fd, &sock_writefds);
		sock_nfds = i+1;
	    }
	    if (FD_ISSET(i, exceptfds)) {
		FD_SET(files[i].socket.fd, &sock_exceptfds);
		sock_nfds = i+1;
	    }
	}
    }
    if (sock_nfds > 0) {
        DEBUG("lwip_select(");
        dump_set(nfds, &sock_readfds, &sock_writefds, &sock_exceptfds, &timeout);
        DEBUG("); -> ");
        sock_n = lwip_select(sock_nfds, &sock_readfds, &sock_writefds, &sock_exceptfds, &timeout);
        dump_set(nfds, &sock_readfds, &sock_writefds, &sock_exceptfds, &timeout);
        DEBUG("\n");
    }
#endif

    /* Then see others as well. */
    for (i = 0; i < nfds; i++) {
	switch(files[i].type) {
	default:
	    if (FD_ISSET(i, readfds) || FD_ISSET(i, writefds) || FD_ISSET(i, exceptfds))
		printk("bogus fd %d in select\n", i);
	    /* Fallthrough.  */
	case FTYPE_CONSOLE:
	    if (FD_ISSET(i, readfds)) {
                if (xencons_ring_avail(files[i].cons.dev))
		    n++;
		else
		    FD_CLR(i, readfds);
            }
	    if (FD_ISSET(i, writefds))
                n++;
	    FD_CLR(i, exceptfds);
	    break;
#ifdef CONFIG_XENBUS
	case FTYPE_XENBUS:
	    if (FD_ISSET(i, readfds)) {
                if (files[i].xenbus.events)
		    n++;
		else
		    FD_CLR(i, readfds);
	    }
	    FD_CLR(i, writefds);
	    FD_CLR(i, exceptfds);
	    break;
#endif
	case FTYPE_EVTCHN:
	case FTYPE_TAP:
	case FTYPE_BLK:
	case FTYPE_KBD:
	case FTYPE_FB:
	    if (FD_ISSET(i, readfds)) {
		if (files[i].read)
		    n++;
		else
		    FD_CLR(i, readfds);
	    }
	    FD_CLR(i, writefds);
	    FD_CLR(i, exceptfds);
	    break;
#ifdef HAVE_LWIP
	case FTYPE_SOCKET:
	    if (FD_ISSET(i, readfds)) {
	        /* Optimize no-network-packet case.  */
		if (sock_n && FD_ISSET(files[i].socket.fd, &sock_readfds))
		    n++;
		else
		    FD_CLR(i, readfds);
	    }
            if (FD_ISSET(i, writefds)) {
		if (sock_n && FD_ISSET(files[i].socket.fd, &sock_writefds))
		    n++;
		else
		    FD_CLR(i, writefds);
            }
            if (FD_ISSET(i, exceptfds)) {
		if (sock_n && FD_ISSET(files[i].socket.fd, &sock_exceptfds))
		    n++;
		else
		    FD_CLR(i, exceptfds);
            }
	    break;
#endif
	}
#ifdef LIBC_VERBOSE
	if (FD_ISSET(i, readfds))
	    nbread[i]++;
	if (FD_ISSET(i, writefds))
	    nbwrite[i]++;
	if (FD_ISSET(i, exceptfds))
	    nbexcept[i]++;
#endif
    }
#ifdef LIBC_VERBOSE
    if (NOW() > lastshown + 1000000000ull) {
	lastshown = NOW();
	printk("%lu MB free, ", num_free_pages() / ((1 << 20) / PAGE_SIZE));
	printk("%d(%d): ", nb, sock_n);
	for (i = 0; i < nfds; i++) {
	    if (nbread[i] || nbwrite[i] || nbexcept[i])
		printk(" %d(%c):", i, file_types[files[i].type]);
	    if (nbread[i])
	    	printk(" %dR", nbread[i]);
	    if (nbwrite[i])
		printk(" %dW", nbwrite[i]);
	    if (nbexcept[i])
		printk(" %dE", nbexcept[i]);
	}
	printk("\n");
	memset(nbread, 0, sizeof(nbread));
	memset(nbwrite, 0, sizeof(nbwrite));
	memset(nbexcept, 0, sizeof(nbexcept));
	nb = 0;
    }
#endif
    return n;
}

/* The strategy is to
 * - announce that we will maybe sleep
 * - poll a bit ; if successful, return
 * - if timeout, return
 * - really sleep (except if somebody woke us in the meanwhile) */
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
	struct timeval *timeout)
{
    int n, ret;
    fd_set myread, mywrite, myexcept;
    struct thread *thread = get_current();
    s_time_t start = NOW(), stop;
#ifdef CONFIG_NETFRONT
    DEFINE_WAIT(netfront_w);
#endif
    DEFINE_WAIT(event_w);
#ifdef CONFIG_BLKFRONT
    DEFINE_WAIT(blkfront_w);
#endif
#ifdef CONFIG_XENBUS
    DEFINE_WAIT(xenbus_watch_w);
#endif
#ifdef CONFIG_KBDFRONT
    DEFINE_WAIT(kbdfront_w);
#endif
    DEFINE_WAIT(console_w);

    assert(thread == main_thread);

    DEBUG("select(%d, ", nfds);
    dump_set(nfds, readfds, writefds, exceptfds, timeout);
    DEBUG(");\n");

    if (timeout)
	stop = start + SECONDS(timeout->tv_sec) + timeout->tv_usec * 1000;
    else
	/* just make gcc happy */
	stop = start;

    /* Tell people we're going to sleep before looking at what they are
     * saying, hence letting them wake us if events happen between here and
     * schedule() */
#ifdef CONFIG_NETFRONT
    add_waiter(netfront_w, netfront_queue);
#endif
    add_waiter(event_w, event_queue);
#ifdef CONFIG_BLKFRONT
    add_waiter(blkfront_w, blkfront_queue);
#endif
#ifdef CONFIG_XENBUS
    add_waiter(xenbus_watch_w, xenbus_watch_queue);
#endif
#ifdef CONFIG_KBDFRONT
    add_waiter(kbdfront_w, kbdfront_queue);
#endif
    add_waiter(console_w, console_queue);

    if (readfds)
        myread = *readfds;
    else
        FD_ZERO(&myread);
    if (writefds)
        mywrite = *writefds;
    else
        FD_ZERO(&mywrite);
    if (exceptfds)
        myexcept = *exceptfds;
    else
        FD_ZERO(&myexcept);

    DEBUG("polling ");
    dump_set(nfds, &myread, &mywrite, &myexcept, timeout);
    DEBUG("\n");
    n = select_poll(nfds, &myread, &mywrite, &myexcept);

    if (n) {
	dump_set(nfds, readfds, writefds, exceptfds, timeout);
	if (readfds)
	    *readfds = myread;
	if (writefds)
	    *writefds = mywrite;
	if (exceptfds)
	    *exceptfds = myexcept;
	DEBUG(" -> ");
	dump_set(nfds, readfds, writefds, exceptfds, timeout);
	DEBUG("\n");
	wake(thread);
	ret = n;
	goto out;
    }
    if (timeout && NOW() >= stop) {
	if (readfds)
	    FD_ZERO(readfds);
	if (writefds)
	    FD_ZERO(writefds);
	if (exceptfds)
	    FD_ZERO(exceptfds);
	timeout->tv_sec = 0;
	timeout->tv_usec = 0;
	wake(thread);
	ret = 0;
	goto out;
    }

    if (timeout)
	thread->wakeup_time = stop;
    schedule();

    if (readfds)
        myread = *readfds;
    else
        FD_ZERO(&myread);
    if (writefds)
        mywrite = *writefds;
    else
        FD_ZERO(&mywrite);
    if (exceptfds)
        myexcept = *exceptfds;
    else
        FD_ZERO(&myexcept);

    n = select_poll(nfds, &myread, &mywrite, &myexcept);

    if (n) {
	if (readfds)
	    *readfds = myread;
	if (writefds)
	    *writefds = mywrite;
	if (exceptfds)
	    *exceptfds = myexcept;
	ret = n;
	goto out;
    }
    errno = EINTR;
    ret = -1;

out:
#ifdef CONFIG_NETFRONT
    remove_waiter(netfront_w, netfront_queue);
#endif
    remove_waiter(event_w, event_queue);
#ifdef CONFIG_BLKFRONT
    remove_waiter(blkfront_w, blkfront_queue);
#endif
#ifdef CONFIG_XENBUS
    remove_waiter(xenbus_watch_w, xenbus_watch_queue);
#endif
#ifdef CONFIG_KBDFRONT
    remove_waiter(kbdfront_w, kbdfront_queue);
#endif
    remove_waiter(console_w, console_queue);
    return ret;
}
示例#26
0
文件: stack.c 项目: 32bitmicro/zephyr
void fiber3(void)
{
	nano_fiber_timer_start(&timer, SECONDS(1));
	nano_fiber_timer_test(&timer, TICKS_UNLIMITED);
	nano_fiber_stack_push(&nanoStackObj, myData[0]);
}
示例#27
0
signed WaitForStart (struct plc * plc, char string [], size_t length) 

{
	struct channel * channel = (struct channel *)(plc->channel);
	struct message * message = (struct message *)(plc->message);
	struct timeval ts;
	struct timeval tc;
	unsigned timer = 0;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_sw_ver_request 
	{
		struct ethernet_std ethernet;
		struct qualcomm_std qualcomm;
		uint8_t MSTATUS;
		uint8_t MDEVICEID;
		uint8_t MVERLENGTH;
		char MVERSION [PLC_VERSION_STRING];
	}
	* request = (struct vs_sw_ver_request *) (message);
	struct __packed vs_sw_ver_confirm 
	{
		struct ethernet_std ethernet;
		struct qualcomm_std qualcomm;
		uint8_t MSTATUS;
		uint8_t MDEVICEID;
		uint8_t MVERLENGTH;
		char MVERSION [PLC_VERSION_STRING];
	}
	* confirm = (struct vs_sw_ver_confirm *) (message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	Request (plc, "Allow %d seconds for Start", plc->timer);
	if (gettimeofday (&ts, NULL) == -1) 
	{
		error (1, errno, CANT_START_TIMER);
	}
	for (timer = 0; timer < plc->timer; timer = SECONDS (ts, tc)) 
	{
		memset (message, 0, sizeof (* message));
		EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
		QualcommHeader (&request->qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
		plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
		if (SendMME (plc) <= 0) 
		{
			error ((plc->flags & PLC_BAILOUT), errno, CHANNEL_CANTSEND);
			return (-1);
		}
		if (ReadMME (plc, 0, (VS_SW_VER | MMTYPE_CNF)) < 0) 
		{
			error ((plc->flags & PLC_BAILOUT), errno, CHANNEL_CANTREAD);
			return (-1);
		}
		if (gettimeofday (&tc, NULL) == -1) 
		{
			error (1, errno, CANT_RESET_TIMER);
		}
		if (plc->packetsize) 
		{
			if (confirm->MSTATUS) 
			{
				Failure (plc, PLC_WONTDOIT);
				return (-1);
			}
			if (_allset (plc->flags, (PLC_WAITFORSTART | PLC_ANALYSE))) 
			{
				Confirm (plc, "Waited %d seconds for Start", timer);
			}
			strncpy (string, confirm->MVERSION, length);
			return (0);
		}
	}
	if (_allset (plc->flags, (PLC_WAITFORSTART | PLC_ANALYSE))) 
	{
		Confirm (plc, "Waited %d seconds for Start", timer);
	}
	return (-1);
}
示例#28
0
文件: time.c 项目: HPSI/xen-v4v
/*static inline*/ s_time_t ticks_to_ns(uint64_t ticks)
{
    return muldiv64(ticks, SECONDS(1), 1000 * cpu_khz);
}
示例#29
0
文件: time.c 项目: HPSI/xen-v4v
/*static inline*/ uint64_t ns_to_ticks(s_time_t ns)
{
    return muldiv64(ns, 1000 * cpu_khz, SECONDS(1));
}
示例#30
0
signed ResetAndWait (struct plc * plc) 

{
	struct channel * channel = (struct channel *)(plc->channel);
	struct message * message = (struct message *)(plc->message);
	struct timeval ts;
	struct timeval tc;
	unsigned timer = 0;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_rs_dev_request 
	{
		struct ethernet_std ethernet;
		struct qualcomm_std qualcomm;
	}
	* request = (struct vs_rs_dev_request *) (message);
	struct __packed vs_rs_dev_confirm 
	{
		struct ethernet_std ethernet;
		struct qualcomm_std qualcomm;
		uint8_t MSTATUS;
	}
	* confirm = (struct vs_rs_dev_confirm *) (message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	Request (plc, "Reset when Ready");
	if (gettimeofday (&ts, NULL) == -1) 
	{
		error (1, errno, CANT_START_TIMER);
	}
	for (timer = 0; timer < plc->timer; timer = SECONDS (ts, tc)) 
	{
		memset (message, 0, sizeof (* message));
		EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
		QualcommHeader (&request->qualcomm, 0, (VS_RS_DEV | MMTYPE_REQ));
		plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
		if (SendMME (plc) <= 0) 
		{
			error ((plc->flags & PLC_BAILOUT), errno, CHANNEL_CANTSEND);
			return (-1);
		}
		if (ReadMME (plc, 0, (VS_RS_DEV | MMTYPE_CNF)) < 0) 
		{
			error ((plc->flags & PLC_BAILOUT), errno, CHANNEL_CANTREAD);
			return (-1);
		}
		if (gettimeofday (&tc, NULL) == -1) 
		{
			error (1, errno, CANT_RESET_TIMER);
		}
		if (plc->packetsize) 
		{
			if (!confirm->MSTATUS) 
			{
				Confirm (plc, "Resetting ...");
				return (0);
			}
		}
	}
	return (-1);
}