Exemplo n.º 1
0
void
stats(const struct rusage *begin, const struct rusage *end, size_t rounds)
{
	time_t usr_s_delta, sys_s_delta, s_delta;
	suseconds_t usr_us_delta, sys_us_delta, us_delta;
	double usr_delta, sys_delta, delta, usr_rate, rate;

	usr_s_delta = end->ru_utime.tv_sec - begin->ru_utime.tv_sec;
	sys_s_delta = end->ru_stime.tv_sec - begin->ru_stime.tv_sec;
	s_delta = usr_s_delta + sys_s_delta;

	usr_us_delta = end->ru_utime.tv_usec - begin->ru_utime.tv_usec;
	sys_us_delta = end->ru_stime.tv_usec - begin->ru_stime.tv_usec;
	us_delta = usr_us_delta + sys_us_delta;

	usr_delta = (double)usr_s_delta + USEC(usr_us_delta);
	sys_delta = (double)sys_s_delta + USEC(sys_us_delta);
	delta = (double)s_delta + USEC(us_delta);

	usr_rate = (double)rounds / usr_delta;
	rate = (double)rounds / delta;

	if (quiet)
		printf("%.0lf\t%s\n", rate, getprogname());
	else
		printf("%ld\t%lf\t%lf\t%lf\t%lf\t%lf\t%s\n",
		    rounds, usr_delta, sys_delta, delta, usr_rate, rate,
		    getprogname());
}
Exemplo n.º 2
0
static void _rfc1305_parse_timeval(unsigned char *read_buf, struct timeval_t *tv)
{
/* straight out of RFC-1305 Appendix A */
    struct ntp_packet_t ntp_packet;
    struct ntptime_t xmttime;
#ifdef NTP_DEBUG
    struct ntptime_t reftime, orgtime, rectime;
#endif
    memset(&ntp_packet, 0, sizeof(struct ntp_packet_t));

#define Data(i) _ntohl(((unsigned int *)read_buf)[i])
    ntp_packet.li      = Data(0) >> 30 & 0x03;
    ntp_packet.vn      = Data(0) >> 27 & 0x07;
    ntp_packet.mode    = Data(0) >> 24 & 0x07;
    ntp_packet.stratum = Data(0) >> 16 & 0xff;
    ntp_packet.poll    = Data(0) >>  8 & 0xff;
    ntp_packet.prec    = Data(0)       & 0xff;
    if (ntp_packet.prec & 0x80) ntp_packet.prec |= 0xffffff00;
    ntp_packet.delay   = Data(1);
    ntp_packet.disp    = Data(2);
    ntp_packet.refid   = Data(3);

#ifdef NTP_DEBUG
    reftime.coarse = Data(4);
    reftime.fine   = Data(5);
    orgtime.coarse = Data(6);
    orgtime.fine   = Data(7);
    rectime.coarse = Data(8);
    rectime.fine   = Data(9);
#endif
    xmttime.coarse = Data(10);
    xmttime.fine   = Data(11);
#undef Data

#ifdef NTP_DEBUG
    log_debug("LI=%d  VN=%d  Mode=%d  Stratum=%d  Poll=%d  Precision=%d\n",
              ntp_packet.li, ntp_packet.vn, ntp_packet.mode,
              ntp_packet.stratum, ntp_packet.poll, ntp_packet.prec);
    log_debug("Delay=%.1f  Dispersion=%.1f  Refid=%u.%u.%u.%u\n",
              sec2u(ntp_packet.delay), sec2u(ntp_packet.disp),
              ntp_packet.refid >> 24 & 0xff, ntp_packet.refid >> 16 & 0xff,
              ntp_packet.refid >> 8 & 0xff, ntp_packet.refid & 0xff);
    log_debug("Reference %u.%.6u\n", reftime.coarse - JAN_1970, USEC(reftime.fine));
    log_debug("Originate %u.%.6u\n", orgtime.coarse - JAN_1970, USEC(orgtime.fine));
    log_debug("Receive   %u.%.6u\n", rectime.coarse - JAN_1970, USEC(rectime.fine));
    log_debug("Transmit  %u.%.6u\n", xmttime.coarse - JAN_1970, USEC(xmttime.fine));
#endif

    tv->tv_sec = xmttime.coarse - JAN_1970;
    tv->tv_usec = USEC(xmttime.fine);
}
Exemplo n.º 3
0
int
main( int argc, char **argv ) {
    struct timeval start, end;
    rbudpReceiver_t *rbudpReceiver;

    if ( argc < 5 ) {
        printf
        ( "Usage: recvfile <sender> <path to the orig file> <path to the dest file name> <MTU>\n" );
        printf
        ( " \n Example : recvfile <192.168.81.100 /path/to/file/on/sender /path/to/file/on/receiver 9000 \n" );
        exit( 1 );
    }


    rbudpReceiver = malloc( sizeof( rbudpReceiver_t ) );
    memset( rbudpReceiver, 0, sizeof( rbudpReceiver_t ) );

    // the constructor
    QUANTAnet_rbudpReceiver_c( rbudpReceiver, RECEIVE_PORT );

    // the init
    initReceiver( rbudpReceiver, argv[1] );

    printf( "init finishes\n" );
    gettimeofday( &start, NULL );
    QUANTAnet_rbudpBase_c( &rbudpReceiver->rbudpBase );
    getfile( rbudpReceiver, argv[2], argv[3], atoi( argv[4] ) );
    gettimeofday( &end, NULL );
    recvClose( rbudpReceiver );

    printf( "time consumed: %d microseconds\n", USEC( &start, &end ) );
    return 1;
}
void GetSynTimeFromNtpPacked(PNTPPACKED pSynNtpPacked,struct timeval* new_time)
{
    NTPTIME trantime;
    trantime.coarse = ntohl(pSynNtpPacked->trantime.coarse);
    trantime.fine   = ntohl(pSynNtpPacked->trantime.fine);	
    new_time->tv_sec = trantime.coarse - JAN_1970;
    new_time->tv_usec = USEC(trantime.fine);	
}
Exemplo n.º 5
0
static void
rfc1305(uint32_t *data, struct timeval *tv)
{
#if 0
	tv->tv_sec  = ntohl(((uint32_t *)data)[10]) - JAN_1970 + (OUR_TZ*3600);
#else
	tv->tv_sec  = ntohl(((uint32_t *)data)[10]) - JAN_1970;
#endif
	tv->tv_usec = USEC(ntohl(((uint32_t *)data)[11]));
}
Exemplo n.º 6
0
void upm_delay_us(int time){
#if defined(linux)
    usleep(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, USEC(time));
    nano_timer_test(&timer, TICKS_UNLIMITED);
#endif
}
Exemplo n.º 7
0
static int set_time(char *srv, struct in_addr addr, uint32_t *data)
{
	struct timeval tv;

	tv.tv_sec  = ntohl(((uint32_t *)data)[10]) - JAN_1970;
	tv.tv_usec = USEC(ntohl(((uint32_t *)data)[11]));
	if (settimeofday(&tv, NULL) < 0) {
		perror("settimeofday");
		return 1;	/* Ouch, this should not happen :-( */
	}

	syslog(LOG_DAEMON | LOG_INFO, "Time set from %s [%s].", srv, inet_ntoa(addr));

	return 0;		/* All good, time set! */
}
Exemplo n.º 8
0
static int	init_new_client(t_server *serv, t_selfd *fd, t_client *client)
{
  client->type_cli = UNKNOWN;
  client->teamname = NULL;
  client->cmds = NULL;
  client->x = 0;
  client->y = 0;
  client->level = 1;
  client->orientation = DOWN;
  client->flag = OK;
  client->tmpcmd = NULL;
  client->tmpcmdsize = 0;
  memset(&(client->inv), 0, sizeof(t_map));
  fd->cli_num = serv->game.cli_num++;
  add_to_list(&(serv->watch), fd);
  send_response(fd, "BIENVENUE");
  set_timeout(serv, fd, "timeout", USEC(INIT_TIMEOUT));
  handle_client(fd, serv);
  return (EXIT_SUCCESS);
}
Exemplo n.º 9
0
void upm_delay_us(unsigned int time)
{
    if (time <= 0)
        time = 1;

#if defined(UPM_PLATFORM_LINUX)

    struct timespec delay_time;

    delay_time.tv_sec  = time / 1000000;
    delay_time.tv_nsec = (time % 1000000) * 1000;
    // 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
    // we will use a upm_clock to do microsecond timings here as k_timer has
    // only a millisecond resolution.  So we init a clock and spin.

    upm_clock_t timer;
    upm_clock_init(&timer);
    while (upm_elapsed_us(&timer) < time)
        ; // spin

# else

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

# endif

#endif
}
Exemplo n.º 10
0
/*********************
 * Generic functions *
 ********************/
static void _usleep(uint32_t usec)
{
	static void (*func[3])(int32_t timeout_in_ticks) = {
		NULL,
		fiber_sleep,
		task_sleep,
	};

	if (sys_execution_context_type_get() == 0) {
		sys_thread_busy_wait(usec);
		return;
	}

	/* Timeout in ticks: */
	usec = USEC(usec);
	/** Most likely usec will generate 0 ticks,
	 * so setting at least to 1
	 */
	if (!usec) {
		usec = 1;
	}

	func[sys_execution_context_type_get()](usec);
}
Exemplo n.º 11
0
void startToneGenerator(ToneGenerator *self,int unused){
	self -> period = USEC(2145);
	//self -> deadline = USEC(100);
	PARALLEL_PORT_INIT(&portDevice,(int)(self -> direction));
	ASYNC(self,generateTone,0);
}  //public function
Exemplo n.º 12
0
void setTone(ToneGenerator *self,int newTone){
	self -> period = USEC(newTone);
}	//public function
//
// Getting the speed of the processors in Hz. We get this from /proc/cpuinfo.
// Example output of /proc/cpuinfo:
//////////////////////////////////////////////////////////////////////
// processor    : 0
// vendor_id    : GenuineIntel
// cpu family   : 6
// model                : 7
// model name   : Pentium III (Katmai)
// stepping     : 3
// cpu MHz              : 497.845315
// cache size   : 512 KB
// ... file continues on ...
//////////////////////////////////////////////////////////////////////
// Note: We just take the first CPU we find and return its CPU speed.
double Performance::Get_Timer_Resolution()
{
#if defined(IOMTR_CPU_I386) || defined(IOMTR_CPU_XSCALE) || defined(IOMTR_CPU_X86_64) || defined(IOMTR_CPU_IA64)
	int c;
	char label[40];
	int scanDecodes;
	double result;
	FILE *cpuInfo;

	int khz;

	if (kstatfd > 0 && ioctl(kstatfd, IM_IOC_GETCPUKHZ, &khz) >= 0) {
		cout << "CPU KHZ: " << khz << endl;
		return (double)khz *1000.0;
	}

	cpuInfo = fopen("/proc/cpuinfo", "r");
	if (!cpuInfo) {
		cerr << "Error determining CPU speed.\n";
		return (0.0);
	}

	do {
		fscanf(cpuInfo, "%7c", label);
		if (!strncmp(label, "cpu MHz", 7)) {
			scanDecodes = fscanf(cpuInfo, "%*s %lf", &result);
			result *= 1000000.0;
			fclose(cpuInfo);
			if (scanDecodes == 1) {
				return (result);
			} else {
				cerr << "Error determining CPU speed.\n";
				return (0.0);
			}
		} else if (!strncmp(label, "cpu GHz", 7)) {
			scanDecodes = fscanf(cpuInfo, "%*s %lf", &result);
			result *= 1000000000.0;
			fclose(cpuInfo);
			if (scanDecodes == 1) {
				return (result);
			} else {
				cerr << "Error determining CPU speed.\n";
				return (0.0);
			}
		}
		// Skip to the next line.
		do {
			c = getc(cpuInfo);
		} while ((c != '\n') && (c != EOF));
	} while (c != EOF);
	fclose(cpuInfo);
	cerr << "Error determining CPU speed.\n";
	return (0.0);
#elif defined(IOMTR_CPU_PPC)
#define USEC(tv)	(tv.tv_sec*1000000+tv.tv_usec)

	struct timeval tv1, tv2;
	DWORD t1, t2;

	double result;

	gettimeofday(&tv1, NULL);
	t1 = get_tbl();
	sleep(1);
	t2 = get_tbl();
	gettimeofday(&tv2, NULL);

	result = ((double)(t2 - t1)) * (1000000.0 / (double)(USEC(tv2) - USEC(tv1)));

	return (result);
#else
#warning ===> WARNING: You have to do some coding here to get the port done!
#endif
}
Exemplo n.º 14
0
void rfc1305(uint32_t *data)
{
/*
	struct ntptime *arrival;
	struct timeval udp_arrival;

	gettimeofday(&udp_arrival, NULL);
	arrival->coarse = udp_arrival.tv_sec + JAN_1970;
	arrival->fine   = NTPFRAC(udp_arrival.tv_usec);
*/

/*
// straight out of RFC-1305 Appendix A
	int li, vn, mode, stratum, poll, prec;
	int delay, disp, refid;
	struct ntptime reftime, orgtime, rectime, xmttime;

#define Data(i) ntohl(((uint32_t *)data)[i])
	li      = Data(0) >> 30 & 0x03;
	vn      = Data(0) >> 27 & 0x07;
	mode    = Data(0) >> 24 & 0x07;
	stratum = Data(0) >> 16 & 0xff;
	poll    = Data(0) >>  8 & 0xff;
	prec    = Data(0)       & 0xff;
	if (prec & 0x80) prec|=0xffffff00;
	delay   = Data(1);
	disp    = Data(2);
	refid   = Data(3);
	reftime.coarse = Data(4);
	reftime.fine   = Data(5);
	orgtime.coarse = Data(6);
	orgtime.fine   = Data(7);
	rectime.coarse = Data(8);
	rectime.fine   = Data(9);
	xmttime.coarse = Data(10);
	xmttime.fine   = Data(11);
#undef Data

	struct timeval tv_set;
	// it would be even better to subtract half the slop
	tv_set.tv_sec  = xmttime.coarse - JAN_1970;
	// divide xmttime.fine by 4294.967296
	tv_set.tv_usec = USEC(xmttime.fine);
	if (settimeofday(&tv_set,NULL)<0) {
		perror("settimeofday");
		exit(1);
	}
*/

	struct timeval tv_set;
	tv_set.tv_sec  = ntohl(((uint32_t *)data)[10]) - JAN_1970;
	tv_set.tv_usec = USEC(ntohl(((uint32_t *)data)[11]));
	if (settimeofday(&tv_set, NULL) < 0) {
		perror("settimeofday");
		exit(1);
	}

/*
	double el_time,st_time;
	el_time=ntpdiff(&orgtime,arrival);   // elapsed
	st_time=ntpdiff(&rectime,&xmttime);  // stall
	return(el_time-st_time);
*/
}
Exemplo n.º 15
0
// DMA handler
// called once per byte. handles all incoming data, but only minimally
// processes received data. at the end of a packet, it enqueues the
// received packet, fetches a new buffer, and restarts RX.
void le_DMA_IRQHandler(void) {
	unsigned pos;
	int8_t rssi;
	uint32_t timestamp = NOW; // sampled early for most accurate measurement

	// channel 0
	if (DMACIntStat & (1 << 0)) {
		// terminal count - byte received
		if (DMACIntTCStat & (1 << 0)) {
			DMACIntTCClear = (1 << 0);

			// poll RSSI
			rssi = (int8_t)(cc2400_get(RSSI) >> 8);
			current_rxbuf->rssi_sum += rssi;
			if (rssi < current_rxbuf->rssi_min) current_rxbuf->rssi_min = rssi;
			if (rssi > current_rxbuf->rssi_max) current_rxbuf->rssi_max = rssi;

			// grab byte from DMA buffer
			pos = current_rxbuf->pos;
			current_rxbuf->data[pos] = le_dma_dest[pos & 1]; // dirty hack
			pos += 1;
			current_rxbuf->pos = pos;

			if (pos == 1) {
				current_rxbuf->timestamp = timestamp - USEC(8 + 32); // packet starts at preamble
				current_rxbuf->channel = rf_channel;
				current_rxbuf->access_address = conn.access_address;

				// data packet received: cancel timeout
				// new timeout or hop timer will be set at end of packet RX
				if (btle_channel_index(rf_channel) < 37) {
					timer1_clear_match();
				}
			}

			// get length from header
			if (pos == 2) {
				uint8_t length = dewhiten_length(current_rxbuf->channel, current_rxbuf->data[1]);
				current_rxbuf->size = length + 2 + 3; // two bytes for header and three for CRC
			}

			// finished packet - state transition
			if (pos > 2 && pos >= current_rxbuf->size) {
				// stop the CC2400 before flushing SSP
				cc2400_strobe(SFSON);

				// stop DMA on this channel and flush SSP
				DMACC0Config = 0;
				DMACIntTCClear = (1 << 0); // if we don't clear a second time, data is corrupt

				DIO_SSP_DMACR &= ~SSPDMACR_RXDMAE;
				while (SSP1SR & SSPSR_RNE) {
					uint8_t tmp = (uint8_t)DIO_SSP_DR;
				}

				// TODO error transition on queue_insert
				queue_insert(&packet_queue, current_rxbuf);

				// track connection events
				if (btle_channel_index(rf_channel) < 37) {
					++conn_event.num_packets;

					// first packet: set connection anchor
					if (conn_event.num_packets == 1) {
						conn_event.anchor = current_rxbuf->timestamp;
						timer1_set_match(NOW + IFS_TIMEOUT); // set a timeout for next packet
					}

					// second packet: close connection event, and set hop timer
					else if (conn_event.num_packets == 2) {
						cc2400_strobe(SRFOFF);
						current_rxbuf = buffer_get();
						finish_conn_event();
						return;
					}
				}

				// get a new packet
				// TODO handle error transition
				current_rxbuf = buffer_get();

				// restart DMA and SSP
				le_dma_init();
				dio_ssp_start();

				// wait for FS_LOCK in background
				timer1_wait_fs_lock();
			}
		}

		// error - transition to error state
		if (DMACIntErrStat & (1 << 0)) {
			// TODO error state transition
			DMACIntErrClr = (1 << 0);
		}
	}