int test_memory() { int i, j; value var, ten = value_set_long(10); value container = value_init_nil(); printf("testing memory\n"); var.type = VALUE_VAR; var.core.u_var = "x"; for (i = 1; i < 10000000; i *= 2) { container = value_init(VALUE_MPZ); size_t start = usec(); for (j = 0; j < i; ++j) { value_add_now(&container, ten); } value_clear(&container); size_t finish = usec(); printf("time to do and clear %d elements: %ld usec\n", i, (unsigned long) finish - start); } // size_t time = usec(); // while (usec() - time < 5000000) ; return 0; }
int main(int argc, char *argv[]) { char fname[200]; FILE *f; int bc = strtoul(argv[1], NULL, 0); static struct tspoint tp[20000]; int i; snprintf(fname, sizeof(fname), "/sys/kernel/debug/cbmia/tspoints%d", bc); f = fopen(fname, "rb"); fread(tp, sizeof(struct tspoint), 20000, f); printf("sizeof(tp) = %zd\n", sizeof(tp)); printf("bc:%d rti %18s %18s %18s %18s\n", bc, "strtx", "wrttx", "inttx", "endtx"); for (i = 0; i < 20000; i++) { printf("bc:%u rti:%02u %10u.%06u %s %6u %6u %6u\n", bc, tp[i].rti, sec(tp[i].start_tx), usec(tp[i].start_tx), isotime(tp[i].start_tx), usec(tp[i].write_tx - tp[i].start_tx), usec(tp[i].int_tx - tp[i].write_tx), usec(tp[i].end_tx - tp[i].int_tx)); } return 0; }
int OTime::compare(const OTime& t) const { //if t is greater then return -1 if(usec() < t.usec()) return -1; //if t is less than return 1 else if(usec() > t.usec()) return 1; //else the two OTimes must be equal so return 0 return 0; }
// Main execution loop void *runThread(void *thisC64) { assert(thisC64 != NULL); C64 *c64 = (C64 *)thisC64; c64->debug(1, "Execution thread started\n"); c64->putMessage(MSG_RUN); c64->threadStartTime = usec(); // Configure thread properties... pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); pthread_cleanup_push(threadCleanup, thisC64); // Prepare to run... c64->cpu->clearErrorState(); c64->floppy->cpu->clearErrorState(); c64->restartTimer(); while (1) { if (!c64->executeOneLine()) break; if (c64->getRasterline() == 0 && c64->getFrame() % 8 == 0) { // Check if thread was requested to terminate pthread_testcancel(); } } pthread_cleanup_pop(1); pthread_exit(NULL); }
void C64::synchronizeTiming() { const uint64_t earlyWakeup = 1500000; /* 1.5 milliseconds */ const uint64_t maxJitter = 1000000000; /* 1 second */ // Convert usec into kernel unit and sleep uint64_t kernelTargetTime = nanos_to_abs(nanoTargetTime); int64_t jitter = sleepUntil(kernelTargetTime, earlyWakeup); // Update target time nanoTargetTime += vic->getFrameDelay(); // debug(2, "Jitter = %d", jitter); if (jitter > maxJitter) { // The emulator did not keep up with the real time clock. Instead of // running behind for a long time, we reset the synchronization timer debug(2, "Jitter exceeds limit. Restarting synchronization timer.\n"); restartTimer(); } #if 0 // Old sleep // determine how long we should wait uint64_t timeToSleep = targetTime - usec(); targetTime += vic->getFrameDelay() / 1000; // OLD if (timeToSleep > 0) { sleepMicrosec(timeToSleep); } else { restartTimer(); } #endif }
ezio::Time_Value:: operator struct timeval() const { struct timeval tv; tv.tv_sec = sec_; tv.tv_usec = usec(); return tv; }
int test_list() { value list = value_init_nil(); value num = value_set_long(10); long i, count; size_t start = usec(); for (count = 0; count < 5; ++count) { for (i = 0; i < 10000000; ++i) { value_cons_now(num, &list); } value_clear(&list); } size_t finish = usec(); printf("time to do %ld iterations: %ld\n", i, (long) (finish - start) / count); return 0; }
Time* Time::gettimeofday(STATE) { struct timeval tv; /* don't fill in the 2nd argument here. getting the timezone here * this way is not portable and broken anyway. */ ::gettimeofday(&tv, NULL); sec( state, Integer::from(state, tv.tv_sec)); usec(state, Integer::from(state, tv.tv_usec)); return this; }
void stress(int pos, int num, int maxsize, int dnum) { int i,j,k; unsigned char *zl; char posstr[2][5] = { "HEAD", "TAIL" }; long long start; for (i = 0; i < maxsize; i+=dnum) { zl = ziplistNew(); for (j = 0; j < i; j++) { zl = ziplistPush(zl,(unsigned char*)"quux",4,ZIPLIST_TAIL); } /* Do num times a push+pop from pos */ start = usec(); for (k = 0; k < num; k++) { zl = ziplistPush(zl,(unsigned char*)"quux",4,pos); zl = ziplistDeleteRange(zl,0,1); } printf("List size: %8d, bytes: %8d, %dx push+pop (%s): %6lld usec\n", i,intrev32ifbe(ZIPLIST_BYTES(zl)),num,posstr[pos],usec()-start); zfree(zl); } }
void hwMsg(int l, const char *format, ...) { va_list ap; va_start(ap, format); if (l <= hwlog.level) { if (hwIsLogReady()) { int t = usec(); hwLog(l, "%6i:", t - hwlog.timeTemp); hwlog.timeTemp = t; hwLogv(l, format, ap); } else { fprintf(stderr, hwlog.prefix); vfprintf(stderr, format, ap); } } va_end(ap); }
/** Note that a XSync() was just done on \a dmxScreen with the \a start * and \a stop times (from gettimeofday()) and the number of * pending-but-not-yet-processed XSync requests. This routine is called * from #dmxDoSync in #dmxsync.c */ void dmxStatSync(DMXScreenInfo *dmxScreen, struct timeval *stop, struct timeval *start, unsigned long pending) { DMXStatInfo *s = dmxScreen->stat; unsigned long elapsed = usec(stop, start); unsigned long thresh; int i; ++s->syncCount; dmxStatValue(&s->usec, elapsed); dmxStatValue(&s->pending, pending); for (i = 0, thresh = DMX_STAT_BIN0; i < DMX_STAT_BINS-1; i++) { if (elapsed < thresh) { ++s->bins[i]; break; } thresh *= DMX_STAT_BINMULT; } if (i == DMX_STAT_BINS-1) ++s->bins[i]; }
int main(int argc, char **argv) { uint8_t success; int i; intset *is; sranddev(); printf("Value encodings: "); { assert(_intsetValueEncoding(-32768) == INTSET_ENC_INT16); assert(_intsetValueEncoding(+32767) == INTSET_ENC_INT16); assert(_intsetValueEncoding(-32769) == INTSET_ENC_INT32); assert(_intsetValueEncoding(+32768) == INTSET_ENC_INT32); assert(_intsetValueEncoding(-2147483648) == INTSET_ENC_INT32); assert(_intsetValueEncoding(+2147483647) == INTSET_ENC_INT32); assert(_intsetValueEncoding(-2147483649) == INTSET_ENC_INT64); assert(_intsetValueEncoding(+2147483648) == INTSET_ENC_INT64); assert(_intsetValueEncoding(-9223372036854775808ull) == INTSET_ENC_INT64); assert(_intsetValueEncoding(+9223372036854775807ull) == INTSET_ENC_INT64); ok(); } printf("Basic adding: "); { is = intsetNew(); is = intsetAdd(is,5,&success); assert(success); is = intsetAdd(is,6,&success); assert(success); is = intsetAdd(is,4,&success); assert(success); is = intsetAdd(is,4,&success); assert(!success); ok(); } printf("Large number of random adds: "); { int inserts = 0; is = intsetNew(); for (i = 0; i < 1024; i++) { is = intsetAdd(is,rand()%0x800,&success); if (success) inserts++; } assert(is->length == inserts); checkConsistency(is); ok(); } printf("Upgrade from int16 to int32: "); { is = intsetNew(); is = intsetAdd(is,32,NULL); assert(is->encoding == INTSET_ENC_INT16); is = intsetAdd(is,65535,NULL); assert(is->encoding == INTSET_ENC_INT32); assert(intsetFind(is,32)); assert(intsetFind(is,65535)); checkConsistency(is); is = intsetNew(); is = intsetAdd(is,32,NULL); assert(is->encoding == INTSET_ENC_INT16); is = intsetAdd(is,-65535,NULL); assert(is->encoding == INTSET_ENC_INT32); assert(intsetFind(is,32)); assert(intsetFind(is,-65535)); checkConsistency(is); ok(); } printf("Upgrade from int16 to int64: "); { is = intsetNew(); is = intsetAdd(is,32,NULL); assert(is->encoding == INTSET_ENC_INT16); is = intsetAdd(is,4294967295,NULL); assert(is->encoding == INTSET_ENC_INT64); assert(intsetFind(is,32)); assert(intsetFind(is,4294967295)); checkConsistency(is); is = intsetNew(); is = intsetAdd(is,32,NULL); assert(is->encoding == INTSET_ENC_INT16); is = intsetAdd(is,-4294967295,NULL); assert(is->encoding == INTSET_ENC_INT64); assert(intsetFind(is,32)); assert(intsetFind(is,-4294967295)); checkConsistency(is); ok(); } printf("Upgrade from int32 to int64: "); { is = intsetNew(); is = intsetAdd(is,65535,NULL); assert(is->encoding == INTSET_ENC_INT32); is = intsetAdd(is,4294967295,NULL); assert(is->encoding == INTSET_ENC_INT64); assert(intsetFind(is,65535)); assert(intsetFind(is,4294967295)); checkConsistency(is); is = intsetNew(); is = intsetAdd(is,65535,NULL); assert(is->encoding == INTSET_ENC_INT32); is = intsetAdd(is,-4294967295,NULL); assert(is->encoding == INTSET_ENC_INT64); assert(intsetFind(is,65535)); assert(intsetFind(is,-4294967295)); checkConsistency(is); ok(); } printf("Stress lookups: "); { long num = 100000, size = 10000; int i, bits = 20; long long start; is = createSet(bits,size); checkConsistency(is); start = usec(); for (i = 0; i < num; i++) intsetSearch(is,rand() % ((1<<bits)-1),NULL); printf("%ld lookups, %ld element set, %lldusec\n",num,size,usec()-start); } printf("Stress add+delete: "); { int i, v1, v2; is = intsetNew(); for (i = 0; i < 0xffff; i++) { v1 = rand() % 0xfff; is = intsetAdd(is,v1,NULL); assert(intsetFind(is,v1)); v2 = rand() % 0xfff; is = intsetRemove(is,v2,NULL); assert(!intsetFind(is,v2)); } checkConsistency(is); ok(); } }
void start() { t0 = usec(); }
uint32_t Timer::value(void){ return usec(); }
static void test_throughput(void) { int i, num; long long t1, t2; redisContext *c = blocking_context; redisReply **replies; test("Throughput:\n"); for (i = 0; i < 500; i++) freeReplyObject(redisCommand(c,"LPUSH mylist foo")); num = 1000; replies = malloc(sizeof(redisReply*)*num); t1 = usec(); for (i = 0; i < num; i++) { replies[i] = redisCommand(c,"PING"); assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_STATUS); } t2 = usec(); for (i = 0; i < num; i++) freeReplyObject(replies[i]); free(replies); printf("\t(%dx PING: %.3fs)\n", num, (t2-t1)/1000000.0); replies = malloc(sizeof(redisReply*)*num); t1 = usec(); for (i = 0; i < num; i++) { replies[i] = redisCommand(c,"LRANGE mylist 0 499"); assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_ARRAY); assert(replies[i] != NULL && replies[i]->elements == 500); } t2 = usec(); for (i = 0; i < num; i++) freeReplyObject(replies[i]); free(replies); printf("\t(%dx LRANGE with 500 elements: %.3fs)\n", num, (t2-t1)/1000000.0); num = 10000; replies = malloc(sizeof(redisReply*)*num); for (i = 0; i < num; i++) redisAppendCommand(c,"PING"); t1 = usec(); for (i = 0; i < num; i++) { assert(redisGetReply(c, (void*)&replies[i]) == REDIS_OK); assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_STATUS); } t2 = usec(); for (i = 0; i < num; i++) freeReplyObject(replies[i]); free(replies); printf("\t(%dx PING (pipelined): %.3fs)\n", num, (t2-t1)/1000000.0); replies = malloc(sizeof(redisReply*)*num); for (i = 0; i < num; i++) redisAppendCommand(c,"LRANGE mylist 0 499"); t1 = usec(); for (i = 0; i < num; i++) { assert(redisGetReply(c, (void*)&replies[i]) == REDIS_OK); assert(replies[i] != NULL && replies[i]->type == REDIS_REPLY_ARRAY); assert(replies[i] != NULL && replies[i]->elements == 500); } t2 = usec(); for (i = 0; i < num; i++) freeReplyObject(replies[i]); free(replies); printf("\t(%dx LRANGE with 500 elements (pipelined): %.3fs)\n", num, (t2-t1)/1000000.0); }
int main (int argc, char ** argv) { u8 ** board[2]; u32 numberOfSamples = NUMBEROFSAMPLES; u32 numberOfChannels = NUMBEROFCHANNELS; u32 samplePeriodDivisor = SAMPLEPERIODDIVISOR; tBoolean continuous = kTrue; int fd, fd2, ic; struct timeval origin, before, after[8]; opterr = 0; char c; int opt_D=0, opt_o=0, D=0, opt_F=0, opt_T=0, opt_r=80; int opt_e=0, opt_I=0, opt_b=-1, opt_B=-1, opt_i=0, adc_range=0; int opt_M=0, opt_R=0, opt_at=0, opt_p=1; i32 value[8]; f32 scaled; i32 rescaled; u32 n = 0; int j; FILE * param, * calibr[2]={NULL,NULL}; int cadence; struct dma_channel dma; static struct scale_table adc_scale, dac_scale[2][2]; int scan_fd; dma.status = DMA_IDLE; printf("niconf - starting ...\n"); /* * get some setup values */ param = fopen(CHANNELS, "r"); if (!param || fscanf (param, "%d", &numberOfChannels) != 1) { printf ("niconf: could not get channels value\n"); exit (-1); } while ((c = getopt (argc, argv, "c:d:r:p:s:x:ItiDoeMRFTb:B:vh")) != -1) switch (c) { case 'c': if (optarg) numberOfChannels = atoi(optarg); break; case 'd': if (optarg) samplePeriodDivisor = atoi(optarg); break; case 'r': if (optarg) opt_r = atoi(optarg); break; case 'I': if (opt_i) { printf ("%s - the interrupt system will not " "be enabled\n", NAM); exit (-1); } opt_I = 1; break; case 't': opt_at = 1; break; case 'i': if (opt_I) { printf ("%s - the interrupt system will " "not be enabled\n", NAM); exit (-1); } opt_i = 1; break; case 'D': opt_D = 1; break; case 'o': opt_o = 1; break; case 's': if (optarg) numberOfSamples = atoi(optarg); break; case 'p': if (optarg) opt_p = atoi(optarg); break; case 'x': if (optarg) adc_range = atoi(optarg); break; case 'e': opt_e = 1; break; case 'M': opt_M = 1; break; case 'R': opt_R = 1; break; case 'F': opt_F = 1; break; case 'T': opt_T = 1; break; case 'b': opt_b = strtol(optarg, NULL, 0); break; case 'B': opt_B = strtol(optarg, NULL, 0); break; case 'v': D += 1; break; case 'h': default: if (c != 'h') { fprintf (stderr, "### Unknown option: -%c.\n", optopt); fprintf (stderr, display); exit (-1); } fprintf (stderr, display); exit (0); } /* * We need get a lock on /dev/spm/scan so nobody can * modify irq parameters during board configuration. * The lock will be released when niconf exits. */ scan_fd = open("/dev/spm/scan", O_RDWR | O_NONBLOCK); if (scan_fd < 0) { printf ("niconf: could not obtain lock on scan: %d\n", scan_fd); exit (-1); } /* * find and activate the board */ board[0] = acquire_board("/dev/spm/nibac0", D, &fd); if (board[0]) { printf ("%s - Found master board as nibac0\n", NAM); dma.fd = fd; dma.memap[0] = board[0][2] + DMA_CHANNEL_1; dma.memap[1] = board[0][3] + DMA_CHANNEL_1; if (D>1) { printf ("%s - board mapped at: %p %p %p %p %p\n", NAM, board[0][0], board[0][1], board[0][2], board[0][3], board[0][4]); } } board[1] = acquire_board("/dev/spm/nibac1", D, &fd2); if (board[1]) { printf ("%s - Found slave board as nibac1\n", NAM); if (D>1) { printf ("%s - board mapped at: %p %p %p %p %p\n", NAM, board[1][0], board[1][1], board[1][2], board[1][3], board[1][4]); } } if (board[0] == 0 && board[1] == 0) exit (-1); /* * configure the board */ if (opt_F || opt_I) { /* * Master board configuration */ if (board[0]) { /* disable all board interrupts */ write32(board[0][2], 0x10, 0x40150000); /* stop DMA operation */ NIBIT (dma.memap, ChannelOperation, write, Stop, 1); gettimeofday(&before, NULL); while (NIBIT(dma.memap, ChannelStatus, read, DmaDone) != 1) { gettimeofday(&origin, NULL); if (usec(&origin, &before) > 100000) { printf ("Could not get DMA stopped\n"); exit (-1); } } NIREG (board[0], Interrupt_A_Enable,write, 0); NIBIT (board[0], G0_DMA_Config, set, G0_DMA_Enable, 0); NIBIT (board[0], G0_DMA_Config, write, G0_DMA_Int_Enable, 0); /* disarm board and reset DMA */ ai_disarm (board[0]); NIBIT (dma.memap, ChannelOperation, write, Stop, 1); dma.state = DMA_STOPPED; NIBIT (board[0], AI_AO_Select,set,AI_DMA_Select,0); NIREG (board[0], AI_AO_Select, flush); /* Analog Input reset and configure */ board_reset(board[0]); configure_timebase (board[0]); pll_reset (board[0]); analog_trigger_reset (board[0]); ai_reset (board[0]); if (D) printf ("%s - reset and configure completed\n", NAM); /* setup for adc input */ ai_personalize (board[0], _kAI_CONVERT_Output_SelectActive_High); ai_clear_fifo (board[0]); ai_disarm (board[0]); ai_clear_configuration_memory (board[0]); u32 i; for (i = 0; i < numberOfChannels; i++) { ai_configure_channel (board[0], i, /* channel number */ adc_range, /* gain */ _kAI_Config_PolarityBipolar, _kAI_Config_Channel_TypeDifferential, /* last channel? */ (i == numberOfChannels-1)? kTrue:kFalse); } ai_set_fifo_request_mode (board[0]); ai_environmentalize (board[0]); ai_hardware_gating (board[0]); ai_trigger (board[0], _kAI_START1_SelectPulse, _kAI_START1_PolarityRising_Edge, _kAI_START2_SelectPulse, _kAI_START2_PolarityRising_Edge); ai_sample_stop (board[0], (numberOfChannels > 1)? kTrue:kFalse); /* multi channel? */ if (!opt_e) continuous = kFalse; ai_number_of_samples (board[0], numberOfSamples, /* postrigger samples */ 0, /* pretrigger samples */ continuous); /* continuous? */ param = fopen( "/sys/module/spm_dev/parameters/cadence_usec", "r"); if (param) { if (fscanf (param, "%d", &cadence) != 1) cadence = 0; fclose (param); if (cadence) { samplePeriodDivisor = cadence * 20; if (D) printf ( "%s - using divisor %d -> %d" "usec from cadence_usec\n", NAM, samplePeriodDivisor, cadence); } } else { if (D) printf ( "%s - using divisor %d -> %d usec\n", NAM, samplePeriodDivisor, samplePeriodDivisor/20); } ai_sample_start ( board[0], samplePeriodDivisor, /* period divisor */ samplePeriodDivisor, /* 3 , delay divisor */ _kAI_START_SelectSI_TC, _kAI_START_PolarityRising_Edge); ai_convert ( board[0], opt_r, /* 280 */ // convert period divisor 3, // convert delay divisor kFalse); // external sample clock? ai_clear_fifo (board[0]); if (D) printf ("%s - adc setup completed\n", NAM); } /* * read calibration data and configure DAC and digital lines * on both boards */ for ( j=0 ; j<2 ; j++ ) { if (board[j] == 0) continue; /* * read eeprom for calibration information */ u32 eeprom_size = 1024; eeprom_read_MSeries (board[j], board[j][4], eeprom_size); if (D>=2) { printf ("\n%s - %s\n\n", NAM, "Calibration memory content"); dump_memory (board[j][4], eeprom_size); } if (D) printf ("%s - eeprom reading completed\n", NAM); /* * analog output reset */ ao_reset (board[j]); ao_personalize (board[j]); ao_reset_waveform_channels (board[j]); ao_clear_fifo (board[j]); /* * unground AO reference */ NIBIT(board[j],AO_Calibration,write, AO_RefGround,kFalse); /* * analog output configure */ ao_configure_dac (board[j], 0, 0xF, _kAO_DAC_PolarityBipolar, _kAO_Update_ModeImmediate); ao_configure_dac (board[j], 1, 0xF, _kAO_DAC_PolarityBipolar, _kAO_Update_ModeImmediate); if (D) printf ("%s - DAC configuration completed " "on board %d at %p\n", NAM, j, board[j]); /* * configure digital IO */ NIREG (board[j], DIO_Direction, write, 0xff); } } /* * configure DMA */ if (opt_R) { param = fopen(DMA_USE, "r"); if (!param || fscanf (param, "%d", &opt_M) != 1) { printf ("niconf: could not get dma_use value\n"); exit (-1); } fclose (param); printf ("Keeping DMA channel to state: %d\n", opt_M); param = fopen(SAMPLES_PP, "r"); if (!param || fscanf (param, "%d", &opt_p) != 1) { printf ("niconf: could not get samples value\n"); exit (-1); } fclose (param); printf ("Keeping samples to value: %d\n", opt_p); } if (board[0]) { if (opt_I && opt_M) { printf ("%s - starting DMA configuration\n", NAM); NIBIT (board[0], AI_AO_Select,set,AI_DMA_Select,1); NIREG (board[0], AI_AO_Select, flush); dma.mode = DMA_RING; dma.direction = DMA_IN; dma.drq = 0; dma.size = 2 * numberOfChannels * opt_p; if (dma.size > 4095) { printf ("niconf: huge DMA buffer! " "Please, reduce!\n"); exit (-1); } dma.transfer_width = DMA_16_BIT; /* read from module parameters the physical address of dma buffer */ param = fopen(PHYSICAL_ADDRESS, "r"); if (!param || fscanf (param, "%u", (u32 *) &dma.physical_address) != 1) { printf ("niconf: dma address not available\n"); exit (-1); } fclose (param); dma_configure (&dma); NIBIT (dma.memap, ChannelOperation, write, Start, 1); dma.state = DMA_STARTED; printf ("%s - dma configuration complete\n", NAM); } else if (opt_I || opt_F) { /* deactivate DMA */ NIBIT (dma.memap, ChannelOperation, write, Stop, 1); dma.state = DMA_STOPPED; NIBIT (board[0], AI_AO_Select,set,AI_DMA_Select,0); NIREG (board[0], AI_AO_Select, flush); } } /* * set dma_use flag in module parameters */ if (opt_I || opt_F) { param = fopen(DMA_USE, "w"); if (!param || fprintf (param, "%c\n", opt_M ? '1' : '0') != 2) { printf ("niconf: could not set dma_use flag\n"); exit (-1); } fclose (param); } /* * activate the interrupt system */ if (opt_I && board[0]) { printf ("%s - Activating the interrupt system\n", NAM); /* enable Mite interrupt IO=1 */ write32(board[0][2], 0x08, 0x01000000); if (opt_M) { /* enable board and DMA interrupt */ write32(board[0][2], 0x10, 0x80020000); // NIBIT (board[0], G0_DMA_Config, set, G0_DMA_Enable, 1); // NIBIT (board[0], G0_DMA_Config, write, // G0_DMA_Int_Enable, 1); } else { /* enable board interrupt */ write32(board[0][2], 0x10, 0x80000000); NIBIT (board[0], Interrupt_Control, write, Interrupt_Group_A_Enable, 1); NIBIT (board[0], Interrupt_A_Enable,write, AI_STOP_Interrupt_Enable, 1); NIREG (board[0], Interrupt_B_Enable,write, 0); } if (D) printf ("%s - interrupt activation " "completed\n", NAM); } /* * read ADC and DAC scale coefficients * */ if (board[0]) { calibr[0] = fopen("/tmp/spm.calibration.master", "w"); if (!calibr[0]) { printf ("niconf: could not open %s\n", "spm.calibration.master"); exit (-1); } ai_get_scaling_coefficients (board[0][4], adc_range == 4 ? 3 : adc_range, 0, 0, &adc_scale); fprintf (calibr[0], "ADC nibac %d %g %g %g %g\n", adc_scale.order, adc_scale.c[0],adc_scale.c[1], adc_scale.c[2],adc_scale.c[3]); if (D>1) printf ( "%s - adc scaling coefficients: %d %g %g %g %g\n", NAM, adc_scale.order, adc_scale.c[0],adc_scale.c[1], adc_scale.c[2],adc_scale.c[3]); } for ( j=0 ; j<2 ; j++ ) { if (D>1) printf ("%s - DAC scale for board %d: %p\n", NAM, j, board[j]); if (board[j] == 0) continue; if (j == 1) { calibr[1] = fopen("/tmp/spm.calibration.slave", "w"); if (!calibr[1]) { printf ("niconf: could not open %s\n", "spm.calibration.slave"); exit (-1); } } ao_get_scaling_coefficients (board[j][4], 0, 0, 0, &dac_scale[j][0]); ao_get_scaling_coefficients (board[j][4], 0, 0, 1, &dac_scale[j][1]); fprintf (calibr[j], "DAC nibac %d %g %g %g %g\n", dac_scale[j][0].order, dac_scale[j][0].c[0], dac_scale[j][0].c[1], dac_scale[j][0].c[2], dac_scale[j][0].c[3]); fprintf (calibr[j], "DAC nibac %d %g %g %g %g\n", dac_scale[j][1].order, dac_scale[j][1].c[0], dac_scale[j][1].c[1], dac_scale[j][1].c[2], dac_scale[j][1].c[3]); printf ("%s - dac 0 scaling coefficients: %d %g %g\n", NAM, dac_scale[j][0].order, dac_scale[j][0].c[0], dac_scale[j][0].c[1]); printf ("%s - dac 1 scaling coefficients: %d %g %g\n", NAM, dac_scale[j][1].order, dac_scale[j][1].c[0], dac_scale[j][1].c[1]); } if (D>1) printf ("%s - scale coefficients completed\n", NAM); if (calibr[0]) fclose (calibr[0]); if (calibr[1]) fclose (calibr[1]); /* * * put out bits to digital lines * */ if (opt_b >= 0 ) { if (board[0]) { NIREG (board[0], Static_Digital_Output, write, (u8) 0xff & opt_b); printf ("%s - wrote digital output: 0x%x\n", NAM, NIREG (board[0], Static_Digital_Input, read)); } else { printf ("%s - %s\n", NAM, "sorry, '-b' option requires a master board"); } } if (opt_B >= 0) { if (board[1]) { NIREG (board[1], Static_Digital_Output, write, (u8) 0xff & opt_b); printf ("%s - wrote digital output: 0x%x\n", NAM, NIREG (board[1], Static_Digital_Input, read)); } else { printf ("%s - %s\n", NAM, "sorry, '-B' option requires a second board"); } } /* * all done - arm and start the board */ if (opt_at && board[0]) { ai_arm (board[0], kTrue); ai_start (board[0]); } /* * * read adc data from board * */ if (opt_i && board[0]) { /* read data polling fifo */ printf ("%s - going to read ADC from user space\n", NAM); /* disable the board interrupt */ write32(board[0][2], 0x10, 0x40000000); usleep (100); if (opt_o) printf ("\n"); gettimeofday(&origin, NULL); before = origin; while (opt_e || !numberOfSamples || (n < numberOfChannels*numberOfSamples)) { for ( ic=0 ; ic<numberOfChannels ; ic++ ) { while (NIBIT(board[0],AI_Status_1,read, AI_FIFO_Empty_St)) {} gettimeofday(after+ic, NULL); value[ic] = NIREG(board[0],AI_FIFO_Data,read); } if (!opt_o) printf ("\n"); printf ("\r%4d %6.3f %8ld ", n/numberOfChannels, msec(&after[0], &origin)/1000., usec(after, &before)); for ( ic=0 ; ic<numberOfChannels ; ic++ ) { ai_polynomial_scaler (value+ic, &scaled, &adc_scale); if (opt_T && ic) printf ("%6ld", usec(after+ic, after+ic-1)); printf ("%9.3f", scaled); if (opt_D && ic < 2) { /* loop to DAC */ ao_linear_scaler (&rescaled, &scaled, &dac_scale[0][ic]); NIREG(board[0], DAC_Direct_Data, ic, write,(*( value+ic))/2); } n++; fflush(NULL); } before = after[0]; } printf ("\n\n"); } close (scan_fd); return 0; }
void sleep_sync(unsigned long int t) { t *= 1000; unsigned long int u = usec(); usleep(t - (u % t)); }
void delay(int n) { std::chrono::microseconds usec(n * timeFactor); usleep(usec.count()); }
void USec::normalize() { *this = USec( usec() ); }
static double nsec() { return usec() / 1000; }
/*----------------------------------------------------------------------------- * Service MAVlink protocol message routine */ void Timer1_IRQHandler() { mavlink_message_t msg; MadgwickAHRSupdateIMU( DEG_TO_RAD(params[PARAM_GX].val), DEG_TO_RAD(params[PARAM_GY].val), DEG_TO_RAD(params[PARAM_GZ].val), params[PARAM_AX].val, params[PARAM_AY].val, params[PARAM_AZ].val); mavlink_msg_heartbeat_pack( mavlink_system.sysid, mavlink_system.compid, &msg, MAV_TYPE_GROUND_ROVER, MAV_AUTOPILOT_GENERIC, mavlink_sys_mode, 0, mavlink_sys_state); mavlink_send_msg(&msg); mavlink_msg_sys_status_pack( mavlink_system.sysid, mavlink_system.compid, &msg, MAV_SYS_STATUS_SENSOR_3D_GYRO | MAV_SYS_STATUS_SENSOR_3D_ACCEL | MAV_SYS_STATUS_SENSOR_3D_MAG | MAV_SYS_STATUS_SENSOR_ABSOLUTE_PRESSURE | MAV_SYS_STATUS_SENSOR_GPS, MAV_SYS_STATUS_SENSOR_3D_GYRO | MAV_SYS_STATUS_SENSOR_3D_ACCEL | MAV_SYS_STATUS_SENSOR_3D_MAG, MAV_SYS_STATUS_SENSOR_3D_GYRO | MAV_SYS_STATUS_SENSOR_3D_ACCEL | MAV_SYS_STATUS_SENSOR_3D_MAG | MAV_SYS_STATUS_SENSOR_ABSOLUTE_PRESSURE | MAV_SYS_STATUS_SENSOR_GPS, 50, // TODO remove hardoded values 0, -1, -1, 0, 0, 0, 0, 0, 0); mavlink_send_msg(&msg); mavlink_msg_autopilot_version_pack( mavlink_system.sysid, mavlink_system.compid, &msg, 0, // No capabilities (MAV_PROTOCOL_CAPABILITY). TBD 42, 42, 42, 42, "DEADBEEF", "DEADBEEF", "DEADBEEF", 42, 42, 42); mavlink_send_msg(&msg); mavlink_msg_highres_imu_pack( mavlink_system.sysid, mavlink_system.compid, &msg, usec(), params[PARAM_AX].val, params[PARAM_AY].val, params[PARAM_AZ].val, params[PARAM_GX].val, params[PARAM_GY].val, params[PARAM_GZ].val, params[PARAM_MX].val, params[PARAM_MY].val, params[PARAM_MZ].val, 0, 0, 0, params[PARAM_T].val, (1 << 12) | ((1 << 9) - 1)); mavlink_send_msg(&msg); mavlink_msg_attitude_quaternion_pack( mavlink_system.sysid, mavlink_system.compid, &msg, usec(), q0, q1, q2, q3, DEG_TO_RAD(params[PARAM_GX].val), DEG_TO_RAD(params[PARAM_GY].val), DEG_TO_RAD(params[PARAM_GZ].val)); mavlink_send_msg(&msg); usec_service_routine(); MSS_TIM1_clear_irq(); }
/* * For 32,000 elements * NIL: 0.01 sec * all: 0.17 sec * MPZ: 0.21 sec * MPF: 0.19 sec * STR: 0.24 sec * ID : 0.18 sec * LST: 0.04 sec * * */ int test_hash() { #define NUMBER ((1 << 15) + 1) #define REPEATS 20 value x = value_init_nil(); value val = value_set_str("result"); size_t i, j, k, start, finish; value keys[NUMBER]; char *skeys[NUMBER]; for (i = 0; i < NUMBER; ++i) { skeys[i] = value_malloc(NULL, 30); sprintf(skeys[i], "%ld", (long) i); value num = value_set_long(i); switch (i % 4) { case 0: keys[i] = value_set(num); break; case 1: keys[i] = value_set_double(i); break; case 2: keys[i] = value_cast(num, VALUE_STR); break; case 3: keys[i] = value_cast(num, VALUE_STR); keys[i].type = VALUE_ID; break; case 4: keys[i] = value_init(VALUE_LST); value_cons_now2(&num, &keys[i]); break; default: keys[i] = value_init_nil(); break; } value_clear(&num); // This overrides the setting done above. // keys[i] = value_cast(value_set_long(i), VALUE_STR); } for (i = 1 << 4; i < NUMBER; i <<= 1) { long average = 0; long difference = 0; for (j = 0; j < REPEATS; ++j) { x = value_init(VALUE_HSH); // StrMap *map = strmap_new(HASH_DEFAULT_CAPACITY); start = usec(); for (k = 0; k < i; ++k) value_hash_put(&x, keys[k], val); // strmap_put(map, skeys[k], sval); finish = usec(); average += finish - start; if (labs((long) (average / (j+1)) - (finish - start)) > difference) difference = labs((long) (average / (j+1)) - (finish - start)); value_clear(&x); // strmap_delete(map); } printf("time for %ld elements: %ld usec +/= %ld\n", (long) i, average / j, difference); } #undef NUMBER #undef REPEATS return 0; }
int main(int argc, char **argv) { int c; int r = 0; int fd = -1; drm_handle_t handle; void *address; char *pt; unsigned long count; unsigned long offset; unsigned long size; drm_context_t context; int loops; char buf[1024]; int i; drmBufInfoPtr info; drmBufMapPtr bufs; drmLockPtr lock; int secs; while ((c = getopt(argc, argv, "lc:vo:O:f:s:w:W:b:r:R:P:L:C:XS:B:F:")) != EOF) switch (c) { case 'F': count = strtoul(optarg, NULL, 0); if (!fork()) { dup(fd); sleep(count); } close(fd); break; case 'v': getversion(fd); break; case 'X': if ((r = drmCreateContext(fd, &context))) { drmError(r, argv[0]); return 1; } printf( "Got %d\n", context); break; case 'S': process_sigio(optarg); break; case 'C': if ((r = drmSwitchToContext(fd, strtoul(optarg, NULL, 0)))) { drmError(r, argv[0]); return 1; } break; case 'c': if ((r = drmSetBusid(fd,optarg))) { drmError(r, argv[0]); return 1; } break; case 'o': if ((fd = drmOpen(optarg, NULL)) < 0) { drmError(fd, argv[0]); return 1; } break; case 'O': if ((fd = drmOpen(NULL, optarg)) < 0) { drmError(fd, argv[0]); return 1; } break; case 'B': /* Test buffer allocation */ count = strtoul(optarg, &pt, 0); size = strtoul(pt+1, &pt, 0); secs = strtoul(pt+1, NULL, 0); { drmDMAReq dma; int *indices, *sizes; indices = alloca(sizeof(*indices) * count); sizes = alloca(sizeof(*sizes) * count); dma.context = context; dma.send_count = 0; dma.request_count = count; dma.request_size = size; dma.request_list = indices; dma.request_sizes = sizes; dma.flags = DRM_DMA_WAIT; if ((r = drmDMA(fd, &dma))) { drmError(r, argv[0]); return 1; } for (i = 0; i < dma.granted_count; i++) { printf("%5d: index = %d, size = %d\n", i, dma.request_list[i], dma.request_sizes[i]); } sleep(secs); drmFreeBufs(fd, dma.granted_count, indices); } break; case 'b': count = strtoul(optarg, &pt, 0); size = strtoul(pt+1, NULL, 0); if ((r = drmAddBufs(fd, count, size, 0, 65536)) < 0) { drmError(r, argv[0]); return 1; } if (!(info = drmGetBufInfo(fd))) { drmError(0, argv[0]); return 1; } for (i = 0; i < info->count; i++) { printf("%5d buffers of size %6d (low = %d, high = %d)\n", info->list[i].count, info->list[i].size, info->list[i].low_mark, info->list[i].high_mark); } if ((r = drmMarkBufs(fd, 0.50, 0.80))) { drmError(r, argv[0]); return 1; } if (!(info = drmGetBufInfo(fd))) { drmError(0, argv[0]); return 1; } for (i = 0; i < info->count; i++) { printf("%5d buffers of size %6d (low = %d, high = %d)\n", info->list[i].count, info->list[i].size, info->list[i].low_mark, info->list[i].high_mark); } printf("===== /proc/dri/0/mem =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/mem"); system(buf); #if 1 if (!(bufs = drmMapBufs(fd))) { drmError(0, argv[0]); return 1; } printf("===============================\n"); printf( "%d bufs\n", bufs->count); for (i = 0; i < bufs->count; i++) { printf( " %4d: %8d bytes at %p\n", i, bufs->list[i].total, bufs->list[i].address); } printf("===== /proc/dri/0/vma =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vma"); system(buf); #endif break; case 'f': offset = strtoul(optarg, &pt, 0); size = strtoul(pt+1, NULL, 0); handle = 0; if ((r = drmAddMap(fd, offset, size, DRM_FRAME_BUFFER, 0, &handle))) { drmError(r, argv[0]); return 1; } printf("0x%08lx:0x%04lx added\n", offset, size); printf("===== /proc/dri/0/mem =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/mem"); system(buf); break; case 'r': case 'R': offset = strtoul(optarg, &pt, 0); size = strtoul(pt+1, NULL, 0); handle = 0; if ((r = drmAddMap(fd, offset, size, DRM_REGISTERS, c == 'R' ? DRM_READ_ONLY : 0, &handle))) { drmError(r, argv[0]); return 1; } printf("0x%08lx:0x%04lx added\n", offset, size); printf("===== /proc/dri/0/mem =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/mem"); system(buf); break; case 's': size = strtoul(optarg, &pt, 0); handle = 0; if ((r = drmAddMap(fd, 0, size, DRM_SHM, DRM_CONTAINS_LOCK, &handle))) { drmError(r, argv[0]); return 1; } printf("0x%04lx byte shm added at 0x%08lx\n", size, handle); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vm"); system(buf); break; case 'P': offset = strtoul(optarg, &pt, 0); size = strtoul(pt+1, NULL, 0); address = NULL; if ((r = drmMap(fd, offset, size, &address))) { drmError(r, argv[0]); return 1; } printf("0x%08lx:0x%04lx mapped at %p for pid %d\n", offset, size, address, getpid()); printf("===== /proc/dri/0/vma =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vma"); system(buf); mprotect((void *)offset, size, PROT_READ); printf("===== /proc/dri/0/vma =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vma"); system(buf); break; case 'w': case 'W': offset = strtoul(optarg, &pt, 0); size = strtoul(pt+1, NULL, 0); address = NULL; if ((r = drmMap(fd, offset, size, &address))) { drmError(r, argv[0]); return 1; } printf("0x%08lx:0x%04lx mapped at %p for pid %d\n", offset, size, address, getpid()); printf("===== /proc/%d/maps =====\n", getpid()); snprintf(buf, sizeof(buf), "cat /proc/%d/maps", getpid()); system(buf); printf("===== /proc/dri/0/mem =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/mem"); system(buf); printf("===== /proc/dri/0/vma =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vma"); system(buf); printf("===== READING =====\n"); for (i = 0; i < 0x10; i++) printf("%02x ", (unsigned int)((unsigned char *)address)[i]); printf("\n"); if (c == 'w') { printf("===== WRITING =====\n"); for (i = 0; i < size; i+=2) { ((char *)address)[i] = i & 0xff; ((char *)address)[i+1] = i & 0xff; } } printf("===== READING =====\n"); for (i = 0; i < 0x10; i++) printf("%02x ", (unsigned int)((unsigned char *)address)[i]); printf("\n"); printf("===== /proc/dri/0/vma =====\n"); snprintf(buf, sizeof(buf), "cat /proc/dri/0/vma"); system(buf); break; case 'L': context = strtoul(optarg, &pt, 0); offset = strtoul(pt+1, &pt, 0); size = strtoul(pt+1, &pt, 0); loops = strtoul(pt+1, NULL, 0); address = NULL; if ((r = drmMap(fd, offset, size, &address))) { drmError(r, argv[0]); return 1; } lock = address; #if 1 { int counter = 0; struct timeval loop_start, loop_end; struct timeval lock_start, lock_end; double wt; #define HISTOSIZE 9 int histo[HISTOSIZE]; int output = 0; int fast = 0; if (loops < 0) { loops = -loops; ++output; } for (i = 0; i < HISTOSIZE; i++) histo[i] = 0; gettimeofday(&loop_start, NULL); for (i = 0; i < loops; i++) { gettimeofday(&lock_start, NULL); DRM_LIGHT_LOCK_COUNT(fd,lock,context,fast); gettimeofday(&lock_end, NULL); DRM_UNLOCK(fd,lock,context); ++counter; wt = usec(&lock_end, &lock_start); if (wt <= 2.5) ++histo[8]; if (wt < 5.0) ++histo[0]; else if (wt < 50.0) ++histo[1]; else if (wt < 500.0) ++histo[2]; else if (wt < 5000.0) ++histo[3]; else if (wt < 50000.0) ++histo[4]; else if (wt < 500000.0) ++histo[5]; else if (wt < 5000000.0) ++histo[6]; else ++histo[7]; if (output) printf( "%.2f uSec, %d fast\n", wt, fast); } gettimeofday(&loop_end, NULL); printf( "Average wait time = %.2f usec, %d fast\n", usec(&loop_end, &loop_start) / counter, fast); printf( "%9d <= 2.5 uS\n", histo[8]); printf( "%9d < 5 uS\n", histo[0]); printf( "%9d < 50 uS\n", histo[1]); printf( "%9d < 500 uS\n", histo[2]); printf( "%9d < 5000 uS\n", histo[3]); printf( "%9d < 50000 uS\n", histo[4]); printf( "%9d < 500000 uS\n", histo[5]); printf( "%9d < 5000000 uS\n", histo[6]); printf( "%9d >= 5000000 uS\n", histo[7]); } #else printf( "before lock: 0x%08x\n", lock->lock); printf( "lock: 0x%08x\n", lock->lock); sleep(5); printf( "unlock: 0x%08x\n", lock->lock); #endif break; default: fprintf( stderr, "Usage: drmstat [options]\n" ); return 1; } return r; }
void stop() { elapsed += usec() - t0; }
BOOST_FIXTURE_TEST_CASE( is_default_constructable, bluetoe::link_layer::delta_time ) { BOOST_CHECK_EQUAL( usec(), 0 ); BOOST_CHECK_EQUAL( bluetoe::link_layer::delta_time::now().usec(), 0 ); }
int64_t OTime::msec() const { return usec()/(int64_t)1000; }