Ejemplo n.º 1
0
static void __init omap2_gp_clockevent_init(void)
{
	u32 tick_rate;
	int src;
	u32* time_base = ioremap(0x4A318000, SZ_4K); 
	inited = 1;

	gptimer = omap_dm_timer_request_specific(gptimer_id);
	BUG_ON(gptimer == NULL);
	gptimer_wakeup = gptimer;

#if defined(CONFIG_OMAP_32K_TIMER)
	src = OMAP_TIMER_SRC_32_KHZ;
#else
	src = OMAP_TIMER_SRC_SYS_CLK;
	WARN(gptimer_id == 12, "WARNING: GPTIMER12 can only use the "
	     "secure 32KiHz clock source\n");
#endif

	if (gptimer_id != 12)
		WARN(IS_ERR_VALUE(omap_dm_timer_set_source(gptimer, src)),
		     "timer-gp: omap_dm_timer_set_source() failed\n");

	tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gptimer));

	pr_info("OMAP clockevent source: GPTIMER%d at %u Hz\n",
		gptimer_id, tick_rate);
	print_timer(time_base);

	omap2_gp_timer_irq.dev_id = (void *)gptimer;

	//TODO: slow for safety
	omap_dm_timer_set_load_start(gptimer, 1, 0);
	print_timer(time_base);

	setup_irq(omap_dm_timer_get_irq(gptimer), &omap2_gp_timer_irq);

	clockevent_gpt.mult = div_sc(tick_rate, NSEC_PER_SEC,
				     clockevent_gpt.shift);
	clockevent_gpt.max_delta_ns =
		clockevent_delta2ns(0xffffffff, &clockevent_gpt);
	clockevent_gpt.min_delta_ns =
		clockevent_delta2ns(3, &clockevent_gpt);
		/* Timer internal resynch latency. */

	clockevent_gpt.cpumask = cpumask_of(0);
	clockevents_register_device(&clockevent_gpt);

	omap_dm_timer_set_int_enable(gptimer, OMAP_TIMER_INT_OVERFLOW);

	print_timer(time_base);
}
Ejemplo n.º 2
0
int main(int argc,char **argv){
	char lcd1[]="ボクニモワカル";				// 液晶1行目(8文字)
	char lcd2[]=" XBee ZB";				// 液晶2行目(8文字)
	byte data[2];
	byte i;	// ↓お手持ちのXBeeモジュールのIEEEアドレスに変更する
	byte dev[]   = {0x00,0x13,0xA2,0x00,0x40,0x30,0xC1,0x6F};	// PIO デバイス

	byte port=0;
	
	// 初期化処理
	if( argc==2 ) port = (byte)(argv[1][0]-'0');
	xbee_init( port );					// XBee用COMポートの初期化(引数はポート番号)
	xbee_atnj( 0xFF );					// デバイスを常に参加受け入れ(テスト用)
	xbee_i2c_init(dev);					// I2Cインタフェースの初期化
	
	// メイン処理
	
	print_timer();printf("LCD Init\n");
//	data[0]=0x00; data[1]=0x38; xbee_i2c_write(dev,0x7C,data,2);	// IS=0
	data[0]=0x00; data[1]=0x39; xbee_i2c_write(dev,0x7C,data,2);	// IS=1
//	data[0]=0x00; data[1]=0x14; xbee_i2c_write(dev,0x7C,data,2);	// OSC Freq.	4
	data[0]=0x00; data[1]=0x7E; xbee_i2c_write(dev,0x7C,data,2);	// コントラスト	E
	data[0]=0x00; data[1]=0x5D; xbee_i2c_write(dev,0x7C,data,2);	// Power/Cont	D
	data[0]=0x00; data[1]=0x6C; xbee_i2c_write(dev,0x7C,data,2);	// FollowerCtrl	C
	delay(200);
	data[0]=0x00; data[1]=0x38; xbee_i2c_write(dev,0x7C,data,2);	// IS=0
	data[0]=0x00; data[1]=0x0C; xbee_i2c_write(dev,0x7C,data,2);	// DisplayON	C
//	data[0]=0x00; data[1]=0x01; xbee_i2c_write(dev,0x7C,data,2);	// ClearDisplay
//	data[0]=0x00; data[1]=0x06; xbee_i2c_write(dev,0x7C,data,2);	// EntryMode	6
	
	print_timer();printf("LCD Data 1\n");
	data[0]=0x00; data[1]=0x80; xbee_i2c_write(dev,0x7C,data,2);	// 1行目
	for(i=0;i<8;i++){
		data[0]=0x40;
		data[1]=(byte)lcd1[i];
		xbee_i2c_write(dev,0x7C,data,2);
	}
	
	print_timer();printf("LCD Data 2\n");
	data[0]=0x00; data[1]=0xC0; xbee_i2c_write(dev,0x7C,data,2);	// 2行目
	for(i=0;i<8;i++){
		data[0]=0x40;
		data[1]=(byte)lcd2[i];
		xbee_i2c_write(dev,0x7C,data,2);
	}
	
	print_timer();printf("Done\n");
	return(0);
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: zencoder/zpv
static void stdin_callback (EV_P_ ev_io *w, int revents)
{
    if ( 0 == data_size )
    {
        if ( 0 >= ( data_size = read( STDIN_FILENO, &data[ 0 ], BUFFER_SIZE ) ) )
        {
            print_timer();
            if ( 0 == data_size )
                fprintf(stderr, "{ \"posix_time\": %f, \"exit_status\": \"Success\", \"msg\": \"End of file reached\" }\n", ev_time());
            else
                fprintf(stderr, "{ \"posix_time\": %f, \"exit_status\": \"Error\",  \"msg\": \"Error reading from stdin\", \"errno\": %d }\n", ev_time(), errno);

            exit(data_size);
        }
    }

    if( 0 < data_size )
    {
        // switch to write mode
        ev_tstamp now = ev_now( loop );

        mode = WRITING;
        stdout_pipe.timer_start = now;

        if( 0 < stdin_pipe.timer_start )
            stdin_pipe.time_waiting += now - stdin_pipe.timer_start;

        ev_io_init (&stdout_pipe.watcher, stdout_callback, STDOUT_FILENO, EV_WRITE);
        ev_io_start( loop, &stdout_pipe.watcher ); // start stdout
        ev_io_stop( loop, &stdin_pipe.watcher ); // stop stdin
    }
}
Ejemplo n.º 4
0
static void
print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,
		    u64 now)
{
	struct hrtimer *timer, tmp;
	unsigned long next = 0, i;
	struct rb_node *curr;
	unsigned long flags;

next_one:
	i = 0;
	spin_lock_irqsave(&base->cpu_base->lock, flags);

	curr = base->first;
	/*
	 * Crude but we have to do this O(N*N) thing, because
	 * we have to unlock the base when printing:
	 */
	while (curr && i < next) {
		curr = rb_next(curr);
		i++;
	}

	if (curr) {

		timer = rb_entry(curr, struct hrtimer, node);
		tmp = *timer;
		spin_unlock_irqrestore(&base->cpu_base->lock, flags);

		print_timer(m, &tmp, i, now);
		next++;
		goto next_one;
	}
	spin_unlock_irqrestore(&base->cpu_base->lock, flags);
}
Ejemplo n.º 5
0
/**
 * print_timer() 関数テスト
 *
 * @return なし
 */
void
test_print_timer(void)
{
    unsigned int t = 0, time = 0; /* タイマ用変数 */
    int fd = -1;                  /* ファイルディスクリプタ */
    int retval = 0;               /* 戻り値 */
    char actual[BUF_SIZE] = {0};  /* 実際の文字列 */
    const char expected[] =       /* 期待する文字列 */
        "time of time: [0-9]+\\.[0-9]+\\[msec\\]";

    start_timer(&t);
    time = stop_timer(&t);
    fd = pipe_fd(STDERR_FILENO);
    if (fd < 0) {
        cut_error("pipe_fd=%d(%d)", fd, errno);
        return;
    }

    print_timer(time);

    retval = read(fd, actual, sizeof(actual));
    if (retval < 0) {
        cut_fail("read=%d(%d)", fd, errno);
        goto error_handler;
    }
    dbglog("actual=%s", actual);

    cut_assert_match(expected, actual,
                     cut_message("expected=%s actual=%s",
                                 expected, actual));

error_handler:
    close_fd(&fd, NULL);
}
Ejemplo n.º 6
0
int main(int argc, char**argv){
	char * evar = getenv("RELY_SRAND_DATA");
	if(evar != NULL) srand(atoi(evar));
	else srand(0);
	
	if(argc <= 3){
		printf("USAGE: scale FACTOR INPUT OUTPUT\n");
		return 1;
	}
	inst_timer GLOBAL_TIMER = create_timer();
	start_timer(&GLOBAL_TIMER);
	double scale_factor = atof(argv[1]);
	char* in_filename = argv[2];
	char * out_filename = argv[3];
	printf("scale by %f: %s -> %s\n", scale_factor, in_filename, out_filename);

    int* src, * transformed;

	size_t sw, sh, dw, dh;
	printf("read from \"%s\" ...\n", in_filename);
	src = read_image(in_filename, &sw, &sh);
	if(src == NULL){
		fprintf(stderr, ">> Failed to read image %s\n", in_filename);
		exit(1);
	}
	transformed = allocate_transform_image(scale_factor, sw, sh, &dw, &dh);
	scale(scale_factor, src, sw, sh, transformed, dw, dh);
	printf("write to \"%s\" ...\n", out_filename);
	write_image(out_filename, transformed, dw, dh);
	free((void *) src);
	free((void *) transformed);
	end_timer(&GLOBAL_TIMER);
	printf("GLOBAL TIME\n");
	print_timer(&GLOBAL_TIMER);
}
Ejemplo n.º 7
0
static void
print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,
		    u64 now)
{
	struct hrtimer *timer, tmp;
	unsigned long next = 0, i;
	struct timerqueue_node *curr;
	unsigned long flags;

next_one:
	i = 0;
	raw_spin_lock_irqsave(&base->cpu_base->lock, flags);

	curr = timerqueue_getnext(&base->active);
	/*
	 * Crude but we have to do this O(N*N) thing, because
	 * we have to unlock the base when printing:
	 */
	while (curr && i < next) {
		curr = timerqueue_iterate_next(curr);
		i++;
	}

	if (curr) {

		timer = container_of(curr, struct hrtimer, node);
		tmp = *timer;
		raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);

		print_timer(m, timer, &tmp, i, now);
		next++;
		goto next_one;
	}
	raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
}
Ejemplo n.º 8
0
Archivo: main.c Proyecto: zencoder/zpv
static void stdout_callback (EV_P_ ev_io *w, int revents)
{
    if ( 0 < data_size )
    {
        if ( data_size != write( STDOUT_FILENO, &data[ 0 ], data_size ) )
        {
            print_timer();
            fprintf(stderr, "{ \"posix_time\": %f, \"exit_status\": \"Error\",  \"msg\": \"Error writing to stdout\" }\n", ev_time());
            exit(data_size);
        }

        bytes_out += data_size;
        data_size = 0;
    }

    if ( 0 == data_size )
    {
        // Switch to read mode

        ev_tstamp now = ev_now( loop );
        mode = READING;

        stdin_pipe.timer_start = now;

        if ( 0 < stdout_pipe.timer_start )
            stdout_pipe.time_waiting += now - stdout_pipe.timer_start;

        ev_io_init (&stdin_pipe.watcher, stdin_callback, STDIN_FILENO, EV_READ);
        ev_io_start( loop, &stdin_pipe.watcher );
        ev_io_stop( loop, &stdout_pipe.watcher );
    }
}
Ejemplo n.º 9
0
time_sort(void sort(Item*, int), char* description) {
	memcpy(random_array2, random_array, 
			RANDOM_SIZE * sizeof(int));
	start_timer();
	sort(random_array2, RANDOM_SIZE);
	stop_timer();
	print_timer(description);
	test_array(description);
}
Ejemplo n.º 10
0
void main() {
    setup_timer();
    start_timer();
    int a = 0;
    for(a; a < 10; a++) {
    }

    stop_timer();
    print_timer();
}
int main (void)
{
  int err;
  int rank = 1;
  int nproc = 2;
  timer tmr;

  start_timer(&tmr);
  err = print_timer(&tmr, rank, nproc, "hello", "goodbye");
  if (err != 0) return err;

  /* success! */
  return EXIT_SUCCESS;
}
Ejemplo n.º 12
0
Archivo: main.c Proyecto: zencoder/zpv
static void timer_callback(struct ev_loop *loop, ev_timer *w, int revents)
{
    static int bytes = 0;
    if ( bytes > 0 && bytes >= bytes_out )
    {
        if( mode == READING )
            fprintf(stderr, "{ \"posix_time\": %f, \"msg\": \"Stalled reading from stdin\" }\n", ev_time());
        else
            fprintf(stderr, "{ \"posix_time\": %f, \"msg\": \"Stalled writing to stdout\" }\n", ev_time());
    }

    bytes = bytes_out;
    print_timer();
}
Ejemplo n.º 13
0
/**
 * ソケット受信
 *
 * @param[in] sock ソケット
 * @return ステータス
 */
static st_client
read_sock(int sock)
{
    int retval = 0;    /* 戻り値 */
    size_t length = 0; /* 送信または受信する長さ */
    struct header hd;  /* ヘッダ */

    dbglog("start");

    /* ヘッダ受信 */
    length = sizeof(struct header);
    (void)memset(&hd, 0, length);
    retval = recv_data(sock, &hd, &length);
    if (retval < 0) /* エラー */
        return EX_RECV_ERR;
    dbglog("recv_data: hd=%p, length=%zu", &hd, length);

    if (g_gflag)
        outdump(&hd, length, "recv: hd=%p, length=%zu", &hd, length);
    stddump(&hd, length, "recv: hd=%p, length=%zu", &hd, length);

    length = (size_t)ntohl((uint32_t)hd.length); /* データ長を保持 */

    /* データ受信 */
    answer = (unsigned char *)recv_data_new(sock, &length);
    if (!answer) /* メモリ確保できない */
        return EX_ALLOC_ERR;
    if (!length) /* 受信エラー */
        return EX_RECV_ERR;
    dbglog("answer=%p, length=%zu", answer, length);

    if (g_gflag)
        outdump(answer, length,
                "recv: answer=%p, length=%zu", answer, length);
    stddump(answer, length,
            "recv: answer=%p, length=%zu", answer, length);

    if (g_tflag) {
        unsigned int client_time = stop_timer(&start_time);
        print_timer(client_time);
    }

    retval = fprintf(stdout, "%s\n", answer);
    if (retval < 0)
        outlog("fprintf=%d", retval);

    memfree((void **)&answer, NULL);
    return EX_SUCCESS;
}
Ejemplo n.º 14
0
int
main(int argc, char *argv[])
{
	struct sockaddr_in	serv;
	char				request[5000], reply[5000];
	int					sockfd, n, len, i;
	double				rtt, minrtt;

	if (argc != 2)
		err_quit("usage: tcpcli <IP address of server>");

	memset(&serv, sizeof(serv), 0);
	serv.sin_family		 = AF_INET;
	serv.sin_addr.s_addr = inet_addr(argv[1]);
	serv.sin_port		 = htons(TCP_SERV_PORT);

	for (len = 0; len <= 1400; len += 100) {
		printf("len = %d\n", len);
		minrtt = 9999999;
		for (i = 0; i < 30; i++) {
			if ( (sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
				err_sys("socket error");

			start_timer();
			if (connect(sockfd, (SA) &serv, sizeof(serv)) < 0)
				err_sys("connect error");

			/* form request[] ... */

			if (write(sockfd, request, len) != len)
				err_sys("write error");
			if (shutdown(sockfd, 1) < 0)
				err_sys("shutdown error");

			if ( (n = read_stream(sockfd, reply, len)) != len)
				err_sys("read error, n = %d", n);

			rtt = print_timer();
			minrtt = min(minrtt, rtt);

			/* process "n" bytes of reply[] ... */
			close(sockfd);
		}
		printf("min rtt = %9.3f\n\n", minrtt);
	}

	exit(0);
}
Ejemplo n.º 15
0
int main(int argc, char **argv)
{
  start_timer();

  Setup_Grid();

  Solve();

  Write_Grid();

  print_timer();

  Clean_Up();

  return 0;
}
Ejemplo n.º 16
0
void TASK_dump(u8_t io) {
  ioprint(io, "TASK SYSTEM\n-----------\n");
  print_task(io, task_sys.current, "  current");

  char lst[sizeof(TASK_DUMP_OUTPUT)];
  memcpy(lst, TASK_DUMP_OUTPUT, sizeof(TASK_DUMP_OUTPUT));
  char* p = (char*)strchr(lst, '_');
  task* ct = (task *)task_sys.head;
  int ix = 1;
  while (ct) {
    sprint(p, "%02i", ix++);
    print_task(io, ct, lst);
    ct = ct->_next;
  }
  print_task(io, (task *)task_sys.last, "  last   ");

  ioprint(io, "  pool bitmap ");
  for (ix = 0; ix < sizeof(task_pool.mask)/sizeof(task_pool.mask[0]); ix++) {
    ioprint(io, "%032b ", task_pool.mask[ix]);
  }
  ioprint(io, "\n");

  for (ix = 0; ix < sizeof(task_pool.mask)/sizeof(task_pool.mask[0]); ix++) {
    int bit;
    for (bit = 0; bit < 32; bit++) {
      if ((task_pool.mask[ix] & (1<<bit)) == 0) {
        print_task(io, &task_pool.task[ix*32 + bit], " ");
      }
    }
  }
  ioprint(io, "\n");

  ioprint(io, "  timers\n");
  char lst2[sizeof(TASK_TIM_DUMP_OUTPUT)];
  memcpy(lst2, TASK_TIM_DUMP_OUTPUT, sizeof(TASK_TIM_DUMP_OUTPUT));
  p = (char*)strchr(lst2, '_');
  task_timer* tt = task_sys.first_timer;
  ix = 1;
  time now = SYS_get_time_ms();
  while (tt) {
    sprint(p, "%02i", ix++);
    print_timer(io, tt, lst2, now);
    tt = tt->_next;
  }
}
Ejemplo n.º 17
0
Archivo: main.c Proyecto: zencoder/zpv
int main(int argc, char **argv)
{
    int flags;
    mode = READING;
    data_size = 0;
    bytes_out = 0;
    loop = ev_loop_new( EVBACKEND_SELECT );
    start_time = ev_time();
    stdout_pipe.time_waiting = 0;
    stdout_pipe.timer_start = -1;
    stdin_pipe.time_waiting = 0;
    stdin_pipe.timer_start = -1;

/*
    flags = fcntl(STDIN_FILENO, F_GETFL, 0);
    if ( fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK | flags ) == -1 )
        fprintf(stderr, "{ \"msg\": \"Could not set O_NONBLOCK on stdin\" }\n", data_size, errno);

    flags = fcntl(STDOUT_FILENO, F_GETFL, 0);
    if ( fcntl(STDOUT_FILENO, F_SETFL, O_NONBLOCK | flags ) == -1 )
        fprintf(stderr, "{ \"msg\": \"Could not set O_NONBLOCK on stdout\" }\n", data_size, errno);
*/

    ev_io_init (&stdout_pipe.watcher, stdout_callback, STDOUT_FILENO, EV_WRITE);
    ev_io_init (&stdin_pipe.watcher, stdin_callback, STDIN_FILENO, EV_READ);
    ev_io_start( loop, &stdin_pipe.watcher );

    ev_timer_init (&timer, timer_callback, 2.0, 2.0);
    ev_timer_start (loop, &timer);

    ev_signal_init (&exitsig, sigint_callback, SIGINT);
    ev_signal_start (loop, &exitsig);

    print_timer();
    ev_run (loop, 0);
}
Ejemplo n.º 18
0
int main(int argc, char **argv)
{
  int size_mpi_double;
  long data_communicated_bytes;
  long global_communicated_bytes = 0;

  MPI_Init(&argc, &argv);
   
  Setup_Proc_Grid(argc, argv);

  // start_timer();

  Setup_Grid();

  Setup_MPI_Datatypes();

  Solve();

  Write_Grid();

  print_timer();

  MPI_Type_size(MPI_DOUBLE, &size_mpi_double);
  data_communicated_bytes = data_communicated * size_mpi_double;
  MPI_Reduce(&data_communicated_bytes, &global_communicated_bytes, 1, MPI_LONG, MPI_SUM, 0, grid_comm);

  if (proc_rank == 0) {
    printf("ds: Data sent = %ld\n", global_communicated_bytes);
  }

  Clean_Up();

  MPI_Finalize();

  return 0;
}
Ejemplo n.º 19
0
int main(int argc, char* argv[]) {
  int i;
  grib_handle *h=NULL;
  grib_handle *hso=NULL;
  grib_context* c=NULL;
  FILE* fin=NULL;
  FILE* fout=NULL;
  char* finname;
  char* ofilename;
  char defofilename[]="so_perf.out";
  double *values=NULL;
  double gvalues[1000000]={0,};
  double sovalues[1000000]={0,};
  int append=0;
  size_t nvalues=0;
  int count,e=0;
  int repeatso=1;
  int repeatsimple=1;
  grib_timer *tes,*tds,*teso,*tdso;
  char grid_simple[]="grid_simple";
  size_t grid_simple_l=strlen(grid_simple);
  char packingType[50]={0,};
  size_t len=50;
  char param[50]={0,};
  char gridType[50]={0,};
  char outfilename[255]={0,};
  size_t filesize_so=0;
  size_t filesize_simple=0;
  double perc=0;
  long bitsPerValue=0;
  int iarg=1;
  char grid[20]={0,};
  char shortName[20]={0,};
  long level;
  char levelType[20]={0,};
  char buffer[BUFF_SIZE]={0,};
  char buf[BUFF_SIZE]={0,};
  size_t length;
  int sec4len;
  flong ksec0[ISECTION_0];
  flong ksec1[ISECTION_1];
  flong ksec2[ISECTION_2];
  flong ksec3[ISECTION_3];
  flong ksec4[ISECTION_4];
  flong miss=0;
  const void *msg;
  flong gribex_msg_len=0;
  double packingError=0;


  double rsec2[RSECTION_2];
  double rsec3[RSECTION_3];

  tes=grib_get_timer(0,"encoding simple", 0, 0);
  tds=grib_get_timer(0,"decoding simple", 0, 0);
  teso=grib_get_timer(0,"encoding so", 0, 0);
  tdso=grib_get_timer(0,"decoding so", 0, 0);

  if (argc != 4 && argc != 6 ) usage(argv[0]);
  if (!strcmp(argv[iarg],"-w")) {
	append=0;
	iarg++;
	ofilename=argv[iarg];
	iarg++;
  } else if (!strcmp(argv[iarg],"-a")) {
	append=1;
	iarg++;
	ofilename=argv[iarg];
	iarg++;
  } else {
	append=0;
  	ofilename=defofilename;
  }
  finname=argv[iarg++];
  repeatsimple=atoi(argv[iarg++]);
  bitsPerValue=atoi(argv[iarg++]);

  fin = fopen(finname,"r");
  if(!fin) {perror(finname);exit(1);}

  c=grib_context_get_default();
  length=BUFF_SIZE;
  GRIB_CHECK(grib_read_any_from_file(c,fin,buffer,&length),0);
  fclose(fin);


  if (append) 
	  fout = fopen(ofilename,"a");
  else
	  fout = fopen(ofilename,"w");

  if(!fout) {perror(ofilename);exit(1);}

  c=grib_context_get_default();
  e=0;
  h=grib_handle_new_from_message_copy(c,buffer,length);

  GRIB_CHECK(e,0);

  len=50;
  grib_get_string(h,"shortName",param,&len);

  len=20;
  grib_get_string(h,"levelType",levelType,&len);

  if (!strcmp(levelType,"pl")) {
  	GRIB_CHECK(grib_get_long(h,"level",&level),0);
	sprintf(shortName,"%s%ld",param,level);
  } else {
	sprintf(shortName,"%s",param);
  }

  /* grib_set_long(h,"editionNumber",2); */
  GRIB_CHECK(grib_get_size(h,"values",&nvalues),0);
  values=(double*)grib_context_malloc_clear(c,sizeof(double)*nvalues);
  if (!values) { printf("%s: memory allocation error\n",argv[0]); exit(1); }

  len=50;
  grib_get_string(h,"gridType",gridType,&len);

  len=50;
  grib_get_string(h,"packingType",packingType,&len);

  GRIB_CHECK(grib_get_double_array(h,"values",values,&nvalues),0);
  grib_set_long(h,"bitsPerValue",bitsPerValue);
  GRIB_CHECK(grib_set_double_array(h,"values",values,nvalues),0);
  GRIB_CHECK(grib_get_double(h,"packingError",&packingError),0);

  printf("--------------------------------\n");
  printf("- %s - gridType=%s packingType=%s numberOfValues=%ld bitsPerValue=%ld\n",
	param,gridType,packingType,(long)nvalues,bitsPerValue);

  if (!strcmp(packingType,"spectral_complex") || !strcmp(packingType,"spectral_simple")) {
	 printf("unable to process spectral data\n");
	 exit(1);
  }

  if (!strcmp(gridType,"reduced_gg") || !strcmp(gridType,"regular_gg")) {
	 long N;
	 grib_get_long(h,"N",&N);
	 printf("    N=%ld\n",N);
	 sprintf(grid,"%ld",N);
  }
  if (!strcmp(gridType,"regular_ll")) {
	 double Di,Dj;
	 grib_get_double(h,"DiInDegrees",&Di);
	 grib_get_double(h,"DjInDegrees",&Dj);
	 printf("    Di=%g Dj=%g\n",Di,Dj);
	 sprintf(grid,"%g/%g",Di,Dj);
  }


  if (!append) 
    fprintf(fout,
	"shortName gridType numberOfValues bitsPerValue grid sizeSimple sizeso encodeso encodeSimple decodeso decodeSimple\n");

  sec4len=nvalues+100000;

  /* decode values grid_simple */
  if (strcmp(packingType,grid_simple))
    grib_set_string(h,"packingType",grid_simple,&grid_simple_l);
  grib_timer_start(tds);
  for (count=0;count<repeatsimple;count++) 
    GRIB_CHECK(grib_get_double_array(h,"values",values,&nvalues),0);
  grib_timer_stop(tds,0);

  *outfilename='\0';
  sprintf(outfilename,"%s_%s_%ld_%ld_simple.grib1",param,gridType,bitsPerValue,(long)nvalues);
  filesize_simple=grib_handle_write(h,outfilename);
  printf("file size simple = %ld\n",(long)filesize_simple);

  /* encode values grid_simple*/
  grib_timer_start(tes);
  for (count=0;count<repeatsimple;count++) 
    GRIB_CHECK(grib_set_double_array(h,"values",values,nvalues),0);
  grib_timer_stop(tes,0);

  /* decode with gribex*/
  msg=(char*)buffer;
  gribex_msg_len=BUFF_SIZE;
  sec4len=nvalues+100000;
  gribex_check(cgribex(  miss, ksec0,ksec1,ksec2,rsec2,ksec3,rsec3,
                      ksec4,gvalues,sec4len, (char*)msg,&gribex_msg_len,"D")); 

  /* encode values second order with gribex*/
  ksec4[1] = bitsPerValue;
  /* to indicate complex packing. */
  ksec4[3] = 64;

  /* to indicate extended flags are present. */
  ksec4[5] = 16;

  ksec4[9] = 16; 
  ksec4[11] = 8; 
  ksec4[12] = 4; 
  ksec4[13] = 0; 
  ksec4[14] = -1; 

  gribex_msg_len=BUFF_SIZE;
  grib_timer_start(teso);
  gribex_check(cgribex(  miss, ksec0,ksec1,ksec2,rsec2,ksec3,rsec3,
                      ksec4,gvalues,nvalues, buf,&gribex_msg_len,"K"));
  grib_timer_stop(teso,0);

  hso=grib_handle_new_from_message_copy(c,buf,gribex_msg_len);

  GRIB_CHECK(grib_get_double_array(h,"values",sovalues,&nvalues),0);

  *outfilename='\0';
  sprintf(outfilename,"%s_%s_%ld_%ld_so.grib1",param,gridType,bitsPerValue,(long)nvalues);
  filesize_so=grib_handle_write(hso,outfilename);
  printf("file size so   = %ld\n",(long)filesize_so);

  perc=(double)filesize_simple/(double)filesize_so; 

  printf("compression ratio = %g \n",perc);
  printf("space savings = %g \n",(1.0-1.0/perc)*100);

  grib_handle_delete(h);
  /* decode values second order */
  /* decode with gribex*/
  msg=(char*)buf;
  gribex_msg_len=BUFF_SIZE;
  sec4len=nvalues+100000;
  grib_timer_start(tdso);
  gribex_check(cgribex(  miss, ksec0,ksec1,ksec2,rsec2,ksec3,rsec3,
                      ksec4,gvalues,sec4len, (char*)msg,&gribex_msg_len,"D")); 
  grib_timer_stop(tdso,0);

  for (i=0;i<nvalues;i++) {
	if (fabs(gvalues[i]-values[i])>packingError) {
	  printf("++++++++ Wrong coding\n");
	  printf("packingError=%g gvalues[%d]=%.20e values[%d]=%.20e abs. err=%g \n",packingError,i,
	  gvalues[i],i,values[i],gvalues[i]-values[i]);
	}
  }

  for (i=0;i<nvalues;i++) {
	if (fabs(gvalues[i]-sovalues[i])>packingError) {
	  printf("++++++++ Wrong coding\n");
	  printf("packingError=%g gvalues[%d]=%.20e sovalues[%d]=%.20e abs. err=%g \n",packingError,i,
	  gvalues[i],i,sovalues[i],gvalues[i]-sovalues[i]);
	}
  }

  grib_handle_delete(hso);
  grib_context_free(c,values);

  print_timer(teso,repeatso);
  print_timer(tdso,repeatso);
  print_timer(tes,repeatsimple);
  print_timer(tds,repeatsimple);

  fprintf(fout,"%s %s %ld %ld %s %ld %ld %g %g %g %g\n",
	shortName,gridType,(long)nvalues,bitsPerValue,
  	grid,(long)filesize_simple,(long)filesize_so,teso->timer_/repeatso,tes->timer_/repeatsimple,tdso->timer_/repeatso,tds->timer_/repeatsimple);

  fclose(fout);
  return 0;
}
Ejemplo n.º 20
0
int
main(int argc, char *argv[])
{
	int ret = 1, i, idx;
	dldev_t dev;
	tymer_t db;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	i = strlen(argv[0]) - 1;
	for(; i >= 0 && argv[0][i] != '/'; i--);
	i++;
	if(strstr(argv[0] + i, "interval")){
		set_timer(POR_INTERVAL);
		is_countdn = 0;
	}

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if((idx = find_app(&dev, uapp_name)) < 0){
		ERROR("%s application not found", uapp_name);
		goto end;
	}

	if(dump_add(&dev, idx, &data, &len)){
		ERROR("dump_add");
		goto end;
	}
	read_timer(&db, data);
	free(data);

	print_timer(&db, stdout);
	free_timer(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
Ejemplo n.º 21
0
int
main(int argc, char *argv[])
{
	int ret = 1, istty, i, idx;
	char *msg = NULL, *timer = NULL, *at_end = NULL, *halfway = NULL;
	dldev_t dev;
	tymer_t db;
	u8 *data;
	u16 len;

	/* for data security */
	/*
	umask(S_IRWXG | S_IRWXO);
	*/

	istty = isatty(0);

	i = strlen(argv[0]) - 1;
	for(; i >= 0 && argv[0][i] != '/'; i--);
	i++;
	if(strstr(argv[0] + i, "interval")){
		set_timer(POR_INTERVAL);
		is_countdn = 0;
	}

	while((i = getopt(argc, argv, "hd:")) != -1){
		switch(i){
		case 'd':
			dev_file = optarg;
			break;
		case 'h':
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

#ifdef USB_USBHID
	dev.usb.file = dev_file;
#endif

	BEGIN_OPT()
		OPT("msg", msg)
		OPT("timer", timer)
		OPT("at_end", at_end)
		OPT("halfway", halfway)
	END_OPT()

	/* allows the user to change only at_end in interval timer */
	if(istty && ((!msg || !timer) && (is_countdn || !at_end)))
		usage();

	if(open_dev(&dev)){
		ERROR("open_dev");
		goto exit;
	}

	if(start_session(&dev)){
		ERROR("read_app_info");
		goto exit;
	}

/******************************************************************************/
#ifdef DEBUG
	for(i = 0; i < NUM_APPS; i++){
		if(!dev.app[i].acd.app_idx)
			continue;
		printf("%2d: %d%d%d%d%d%d%d%d %02x %02x %04x %04x %04x %04x %04x %04x %s\n", i,
				dev.app[i].acd.app_idx,
				dev.app[i].acd.code_loc,
				dev.app[i].acd.db_loc,
				dev.app[i].acd.code_invalid,
				dev.app[i].acd.db_modified,
				dev.app[i].acd.db_invalid,
				dev.app[i].acd.passwd_req,
				dev.app[i].acd.mode_name,

				dev.app[i].acb.app_type,
				dev.app[i].acb.app_inst,
				dev.app[i].acb.asd_addr,
				dev.app[i].acb.add_addr,
				dev.app[i].acb.state_mgr_addr,
				dev.app[i].acb.refresh_addr,
				dev.app[i].acb.banner_addr,
				dev.app[i].acb.code_addr,
				dev.app[i].banner
		);
	}
#endif
/******************************************************************************/

	if((idx = find_app(&dev, uapp_name)) < 0){
		ERROR("%s application not found", uapp_name);
		goto end;
	}

	if(dump_add(&dev, idx, &data, &len)){
		ERROR("dump_add");
		goto end;
	}
	read_timer(&db, data);
	free(data);

	if(!istty)
		add_timer_file(&db, stdin);

	if(msg && timer){
		char buf[BUFSIZ];
		timer_data_t rec;

		sprintf(buf, "%s\t%s\t%s%s", msg, timer,
			(at_end ? at_end : "stop"),
			(halfway && strcmp(halfway, "no") ? "\thalfway" : ""));
		if(read_timer_line(&rec, buf))
			fprintf(stderr, "add_%s: format error!\n", lapp_name);
		else
		if(find_timer(&db, &rec) < 0)
			add_timer(&db, &rec);
	}
	if(!is_countdn && at_end){
		int i;

		for(i = 0; i < 3 && strcmp(at_end, timer_at_end[i]); i++);
		if(i < 3){
			set_timer_at_end(i);
			update_timer_at_end(&db);
		}
	}

	create_timer(&db, &data, &len);
	if(load_add(&dev, idx, data)){
		ERROR("load_add");
		goto end;
	}
	free(data);

	print_timer(&db, stdout);
	free_timer(&db);

/******************************************************************************/
end:
	if(end_session(&dev)){
		ERROR("end_session");
		goto exit;
	}

	ret = 0;
exit:
	close_dev(&dev);

	exit(ret);
}
Ejemplo n.º 22
0
int main( int argc, char *argv[] )
{
    db_clt_typ *pclt = NULL;
    char hostname[MAXHOSTNAMELEN+1];
    db_data_typ db_data;
    posix_timer_typ *ptmr;
    int recv_type;
    int millisec = 5000;
    trig_info_typ trig_info;
    uint64_t ticksPerMilliSec = SYSPAGE_ENTRY(qtime)->cycles_per_sec / 1000000;
    unsigned count = 0;
    unsigned total_diff = 0;

    /* Initialize the database. */
    get_local_name(hostname, MAXHOSTNAMELEN);
    if( (pclt = database_init(argv[0], hostname, DEFAULT_SERVICE,
			      COMM_QNX6_XPORT )) == NULL )
    {
	fprintf(stderr, "Database initialization error in ids_io\n");
	veh_done( pclt );
	exit( EXIT_FAILURE );
    }

    /* Initialize the timer. */
    if ((ptmr = timer_init(millisec, DB_CHANNEL(pclt))) == NULL)
    {
	printf("timer_init failed\n");
	exit( EXIT_FAILURE );
    }
	    
    print_timer(ptmr);
    if( setjmp( exit_env ) != 0 )
    {
	printf("average timediff = %u\n", total_diff / count);
	veh_done( pclt );
	exit( EXIT_SUCCESS );
    }
    else
	sig_ign( sig_list, sig_hand );

    for( ;; )
    {
	/* Now wait for a trigger. */
	recv_type= clt_ipc_receive(pclt, &trig_info, sizeof(trig_info));

	if (recv_type == DB_TIMER)
	{
	    printf("received timer alarm\n");
	}
	else if(DB_TRIG_VAR(&trig_info) ==  200)
	{
	    fflush(stdout);
	    /* Read DB_DII_OUT_VAR and send DII control
	     * to the hardware. */
	    if( clt_read( pclt, 200, 200, &db_data ) == FALSE)
	    {
		fprintf( stderr, "clt_read( DB_DII_OUT_VAR ).\n" );
	    }

	    else
	    {
		uint64_t *incoming_time = (uint64_t*) db_data.value.user;
		uint64_t timediff = ClockCycles() - *incoming_time;
		
		timediff /= ticksPerMilliSec;
		total_diff += timediff;
		++count;
	    }
	}
		
	else
	    printf("Unknown trigger, recv_type %d\n", recv_type);
    }
}
Ejemplo n.º 23
0
/**
 * 計算結果
 *
 * @param[in] calc calcinfo構造体
 * @param[in] expr 式
 * @return 新たに領域確保された結果文字列ポインタ
 * @retval NULL エラー
 * @attention destroy_answerを必ず呼ぶこと.
 */
uchar *
create_answer(calcinfo *calc, const uchar *expr)
{
    dbl val = 0.0;     /* 値 */
    size_t length = 0; /* 文字数 */
    int retval = 0;    /* 戻り値 */
    uint start = 0;    /* タイマ開始 */

    dbglog("start");

    calc->ptr = (uchar *)expr; /* 走査用ポインタ */
    dbglog("ptr=%p", calc->ptr);

    /* フォーマット設定 */
    retval = snprintf(calc->fmt, sizeof(calc->fmt),
                      "%s%ld%s", "%.", digit, "g");
    if (retval < 0) {
        outlog("snprintf");
        return NULL;
    }
    dbglog("fmt=%s", calc->fmt);

    readch(calc);

    if (g_tflag)
        start_timer(&start);

    val = expression(calc);
    dbglog(calc->fmt, val);
    dbglog("ptr=%p, ch=%c", calc->ptr, calc->ch);

    check_validate(calc, val);
    if (calc->ch != '\0') /* エラー */
        set_errorcode(calc, E_SYNTAX);

    if (g_tflag) {
        uint calc_time = stop_timer(&start);
        print_timer(calc_time);
    }

    if (is_error(calc)) { /* エラー */
        calc->answer = get_errormsg(calc);
        clear_error(calc);
        if (!calc->answer)
            return NULL;
        dbglog("answer=%p, length=%zu", calc->answer, length);
    } else {
        /* 文字数取得 */
        retval = get_strlen(val, calc->fmt);
        if (retval <= 0) { /* エラー */
            outlog("get_strlen=%d", retval);
            return NULL;
        }
        dbglog("get_strlen=%d, INT_MAX=%d", retval, INT_MAX);
        length = (size_t)retval + 1; /* 文字数 + 1 */

        /* メモリ確保 */
        calc->answer = (uchar *)malloc(length * sizeof(uchar));
        if (!calc->answer) {
            outlog("malloc: length=%zu", length);
            return NULL;
        }
        (void)memset(calc->answer, 0, length * sizeof(uchar));

        /* 値を文字列に変換 */
        retval = snprintf((char *)calc->answer, length, calc->fmt, val);
        if (retval < 0) {
            outlog("snprintf: answer=%p, length=%zu", calc->answer, length);
            return NULL;
        }
        dbglog(calc->fmt, val);
        dbglog("answer=%s, length=%zu", calc->answer, length);
    }
    return calc->answer;
}
/*---------------------------------------------------------------------------
Function: main
Purpose : benchmark entry point
In      : none
Out     : none
Return  : status

History
----------------------------------------------------------------------------
Date        : Author                  Modification
----------------------------------------------------------------------------
04/16/2009    Jamel Tayeb             Creation.
*/
int main(void) {

    //----------------------------------------------------------------------
    // timing data
    //----------------------------------------------------------------------
#ifdef __PL_WINDOWS__
    __int64 start_counter = 0;
    __int64 stop_counter = 0;
    __int64 average_counter = 0;
    __int64 base_average_cycles = 0;
    __int64 pl_write_average_cycles = 0;
    __int64 pl_read_average_cycles = 0;
#endif // __PL_WINDOWS__
#if defined (__PL_LINUX__) || (__PL_SOLARIS__) || (__PL_MACOSX__)
    unsigned long long start_counter = 0;
    unsigned long long stop_counter = 0;
    unsigned long long average_counter = 0;
    unsigned long long base_average_cycles = 0;
    unsigned long long pl_write_average_cycles = 0;
    unsigned long long pl_read_average_cycles = 0;
#endif // __PL_LINUX__ || __PL_SOLARIS__ || __PL_MACOSX__

    //----------------------------------------------------------------------
    // Test PL data
    //----------------------------------------------------------------------
    PL_STATUS ret = PL_FAILURE;
    int pld = PL_INVALID_DESCRIPTOR;
    uuid_t uuid;
    char application_name[] = "benchmark";
    const char *counter_names[] = { "test_counter" };
    unsigned int counter_count = 1;
    unsigned long long i = 0;
    unsigned long long x = 0;
    int j = 0;

    //-----------------------------------------------------------------------
    // open test PL
    //-----------------------------------------------------------------------
    fprintf(stdout, "\n");
    fprintf(stdout, "************************************************************\n");
    fprintf(stdout, "* This micro-benchmark uses RDTSC / _IA64_REG_AR_ITC to    *\n");
    fprintf(stdout, "* evaluate the processor cycles required to carry-out the  *\n");
    fprintf(stdout, "* pl_write() and pl_read() Productivity Link API calls     *\n");
#ifdef __PL_WINDOWS__
    fprintf(stdout, "* (%12I64u write and read operations are performed    *\n", (unsigned long long)(MAX_ITERATIONS * MAX_OPERATIONS));
#endif // __PL_WINDOWS__
#if defined (__PL_LINUX__) || (__PL_SOLARIS__) || (__PL_MACOSX__)
    fprintf(stdout, "* (%12llu write and read operations are performed    *\n", (unsigned long long)(MAX_ITERATIONS * MAX_OPERATIONS));
#endif // __PL_LINUX__ || __PL_SOLARIS__ || __PL_MACOSX__
    fprintf(stdout, "* in sequence).                                            *\n");
    fprintf(stdout, "*                                                          *\n");
    fprintf(stdout, "* This method is imperfect as it will catch cycles         *\n");
    fprintf(stdout, "* consumed by interrupt routines.  Therefore, consider     *\n");
    fprintf(stdout, "* numbers as indications, not exact values.                *\n");
    fprintf(stdout, "* When running the benchmark, stop all other applications. *\n");
    fprintf(stdout, "*                                                          *\n");
    fprintf(stdout, "* When compiling the benchmark, deactivate all compiler    *\n");
    fprintf(stdout, "* optimizations.  Run in single processor configuration.   *\n");
    fprintf(stdout, "* Deactivate all frequency and voltage adjustment          *\n");
    fprintf(stdout, "* features before running this micro-benchmark.            *\n");
    fprintf(stdout, "************************************************************\n");
    fprintf(stdout, "\n");

    fprintf(stdout, "Opening Test PL:\n");
    pld = pl_open(application_name, counter_count, counter_names, &uuid);
    assert(pld != PL_INVALID_DESCRIPTOR);

    //-- test zone ----------------------------------------------------------

    /*
    @@@@@    @@    @@@@  @@@@@@         @@@@@ @@@@@@  @@@@   @@@@@
    @    @  @  @  @    @ @                @   @      @    @    @
    @    @ @    @ @      @                @   @      @         @
    @@@@@  @    @  @@@@  @@@@@@           @   @@@@@@  @@@@     @
    @    @ @@@@@@      @ @                @   @           @    @
    @    @ @    @      @ @                @   @           @    @
    @@@@@  @    @ @@@@@  @@@@@@           @   @@@@@@ @@@@@     @
    */
    //-----------------------------------------------------------------------
    // reference loop
    //-----------------------------------------------------------------------
    init_average();
    fprintf(stdout, "Measuring Base Data       : ");
    for(j = 0; j < MAX_ITERATIONS; j++) {
        fprintf(stdout, "*");
        start_timer();
        for(i = 0; i < MAX_OPERATIONS; i++) {
            ;
        }
        stop_timer();
        x = i; // consume i in case optimization is activated
        sum_average();
    }
    print_timer();
    fprintf(stdout, "\n");
    compute_average(MAX_ITERATIONS * MAX_OPERATIONS);
    base_average_cycles = average_counter;

    /*
    @    @ @@@@@  @@@@@   @@@@@ @@@@@@         @@@@@ @@@@@@  @@@@   @@@@@
    @    @ @    @   @       @   @                @   @      @    @    @
    @  @ @ @    @   @       @   @                @   @      @         @
    @  @ @ @@@@@    @       @   @@@@@@           @   @@@@@@  @@@@     @
    @  @ @ @  @     @       @   @                @   @           @    @
     @ @ @ @   @    @       @   @                @   @           @    @
      @ @  @    @ @@@@@     @   @@@@@@           @   @@@@@@ @@@@@     @
    */
    //----------------------------------------------------------------------
    // write loop
    //----------------------------------------------------------------------
    init_average();
    fprintf(stdout, "Measuring pl_write() Data : ");
    for(j = 0; j < MAX_ITERATIONS; j++) {
        fprintf(stdout, "*");
        start_timer();
        for(i = 0; i < MAX_OPERATIONS; i++) {
            pl_write(pld, &i, 0);
        }
        stop_timer();
        sum_average();
    }
    print_timer();
    fprintf(stdout, "\n");
    compute_average(MAX_ITERATIONS * MAX_OPERATIONS);
    pl_write_average_cycles = average_counter;

    /*
    @@@@@  @@@@@@   @@   @@@@@          @@@@@ @@@@@@  @@@@   @@@@@
    @    @ @       @  @  @    @           @   @      @    @    @
    @    @ @      @    @ @    @           @   @      @         @
    @@@@@  @@@@@@ @    @ @    @           @   @@@@@@  @@@@     @
    @  @   @      @@@@@@ @    @           @   @           @    @
    @   @  @      @    @ @    @           @   @           @    @
    @    @ @@@@@@ @    @ @@@@@            @   @@@@@@ @@@@@     @
    */
    //----------------------------------------------------------------------
    // read loop
    //----------------------------------------------------------------------
    init_average();
    fprintf(stdout, "Measuring pl_read() Data  : ");
    for(j = 0; j < MAX_ITERATIONS; j++) {
        fprintf(stdout, "*");
        start_timer();
        for(i = 0; i < MAX_OPERATIONS; i++) {
            pl_read(pld, &x, 0);
        }
        stop_timer();
        sum_average();
    }
    print_timer();
    fprintf(stdout, "\n");
    compute_average(MAX_ITERATIONS * MAX_OPERATIONS);
    pl_read_average_cycles = average_counter;

    //-- end test zone -----------------------------------------------------

    //----------------------------------------------------------------------
    // close test PL
    //----------------------------------------------------------------------
    fprintf(stdout, "Closing Test PL.\n");
    ret = pl_close(pld);
    assert(ret == PL_SUCCESS);

    //----------------------------------------------------------------------
    // report test results
    //----------------------------------------------------------------------
    fprintf(stdout, "\n");
    fprintf(stdout, "Test Report:\n");
    fprintf(stdout, "=============\n");
    fprintf(stdout, "\n");
#ifdef __PL_WINDOWS__
    fprintf(stdout, "Average CPU cycles per pl_write() call :       %12I64u.\n", pl_write_average_cycles);
    fprintf(stdout, "Average CPU cycles per pl_read() call  :       %12I64u.\n", pl_read_average_cycles);
#endif // __PL_WINDOWS__
#if defined (__PL_LINUX__) || (__PL_SOLARIS__) || (__PL_MACOSX__)
    fprintf(stdout, "Average CPU cycles per pl_write() call :       %12llu.\n", pl_write_average_cycles);
    fprintf(stdout, "Average CPU cycles per pl_read() call  :       %12llu.\n", pl_read_average_cycles);
#endif // __PL_LINUX__ || __PL_SOLARIS__ || __PL_MACOSX__
    fprintf(stdout, "\n");
    fprintf(stdout, "Notes:\n");
    fprintf(stdout, "======\n");
    fprintf(stdout, " *  A 2.0 GHz processor with two cores processes ~4 billion\n");
    fprintf(stdout, "instructions per second (~2 billion per core).   Allocation\n");
    fprintf(stdout, "of system CPU cycles under the following conditions:\n");
#ifdef __PL_WINDOWS__
    fprintf(stdout, "1000 pl_write() calls per second:                   ~%1.3f%%\n", (double)pl_write_average_cycles / 40000.0);
    fprintf(stdout, "1000 pl_read() calls per second:                    ~%1.3f%%\n", (double)pl_read_average_cycles / 40000.0);
#endif // __PL_WINDOWS__
#if defined (__PL_LINUX__) || (__PL_SOLARIS__) || (__PL_MACOSX__)
    fprintf(stdout, "1000 pl_write() calls per second:                   ~%1.3f%%\n", (double)pl_write_average_cycles / 40000.0);
    fprintf(stdout, "1000 pl_read() calls per second:                    ~%1.3f%%\n", (double)pl_read_average_cycles / 40000.0);
#endif // __PL_LINUX__ || __PL_SOLARIS__ || __PL_MACOSX__	fprintf(stdout, "\n");
    fprintf(stdout, "\n");
    fprintf(stdout, " *  1.0 GHz cycle = 1.0 nanosecond = 1.0 x 10-9 second.\n");
    fprintf(stdout, "                10 nanoseconds   =   1.0 x 10-5 millisecond.\n");
    fprintf(stdout, "               100 nanoseconds   =       0.0001 millisecond.\n");
    fprintf(stdout, "             1,000 nanoseconds   =        0.001 millisecond.\n");
    fprintf(stdout, "            10,000 nanoseconds   =         0.01 millisecond.\n");
    fprintf(stdout, "          100,000 nanoseconds    =          0.1 millisecond.\n");
    fprintf(stdout, "        1,000,000 nanoseconds    =            1 millisecond.\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "************************************************************\n");
    fprintf(stdout, "*               End of micro-benchmark                     *\n");
    fprintf(stdout, "************************************************************\n");
    fprintf(stdout, "\n");

    return(PL_SUCCESS);
}
Ejemplo n.º 25
0
Archivo: timer.c Proyecto: LGTMCU/f32c
void
main(void)
{
        char inkey;

	*LED = 0;

	TIMER[TC_INCREMENT] = 1;
	TIMER[TC_APPLY] = (1<<TC_INCREMENT);

#if 1
	TIMER[TC_OCP1_START] = 0;
	TIMER[TC_OCP1_STOP]  = (1<<(TIMER_BITS-2))-1;
	TIMER[TC_OCP2_START] = (1<<(TIMER_BITS-2));
	TIMER[TC_OCP2_STOP]  = (1<<(TIMER_BITS-1))-1;
#else
	TIMER[TC_OCP1_START] = 0;
	TIMER[TC_OCP1_STOP]  = (1<<(TIMER_BITS-1))-1;
	TIMER[TC_OCP2_START] = (1<<(TIMER_BITS-1));
	TIMER[TC_OCP2_STOP]  = (1<<(TIMER_BITS-0))-1;
#endif

#if 0
        /* icp in the same time window as ocp */
	TIMER[TC_ICP1_START] = 0;
	TIMER[TC_ICP1_STOP]  = (1<<(TIMER_BITS-2))-1;
	TIMER[TC_ICP2_START] = (1<<(TIMER_BITS-2));
	TIMER[TC_ICP2_STOP]  = (1<<(TIMER_BITS-1))-1;
#else
        /* icp wide open window */
	TIMER[TC_ICP1_START] = 0;
	TIMER[TC_ICP1_STOP]  = (1<<(TIMER_BITS))-1;
	TIMER[TC_ICP2_START] = 0;
	TIMER[TC_ICP2_STOP]  = (1<<(TIMER_BITS))-1;
#endif
	TIMER[TC_INC_MIN]    = 300;
	TIMER[TC_INC_MAX]    = 600;
	
	TIMER[TC_ICP1]       = 173; // setpoint ICP1
	TIMER[TC_ICP2]       = 689; // setpoint ICP2

	TIMER[TC_CONTROL] = (1<<TCTRL_AND_OR_OCP1) | (1<<TCTRL_AND_OR_OCP2)
	                  | (1<<TCTRL_AND_OR_ICP1) | (1<<TCTRL_AND_OR_ICP2)
	                  | (1<<TCTRL_IE_OCP1)     | (1<<TCTRL_IE_OCP2)
	                  | (1<<TCTRL_IE_ICP1)     | (1<<TCTRL_IE_ICP2)
	                  | (1<<TCTRL_AFCEN_ICP1)  | (0<<TCTRL_AFCINV_ICP1)
	                  | (0<<TCTRL_AFCEN_ICP2)  | (0<<TCTRL_AFCINV_ICP2)
	                  | (1<<TCTRL_XOR_OCP1)    | (1<<TCTRL_XOR_OCP2)
	                  | (1<<TCTRL_XOR_ICP1)    | (1<<TCTRL_XOR_ICP2)
	                  | (1<<TCTRL_ENABLE_OCP1) | (1<<TCTRL_ENABLE_OCP2)
	                  | (1<<TCTRL_ENABLE_ICP1) | (1<<TCTRL_ENABLE_ICP2)
	                  ;

        TIMER[TC_APPLY] = (1<<TC_CONTROL)
                        | (1<<TC_OCP1_START) | (1<<TC_OCP1_STOP) 
                        | (1<<TC_OCP2_START) | (1<<TC_OCP2_STOP)
                        | (1<<TC_ICP1_START) | (1<<TC_ICP1_STOP) 
                        | (1<<TC_ICP2_START) | (1<<TC_ICP2_STOP)
                        | (1<<TC_INC_MIN)    | (1<<TC_INC_MAX)
                        | (1<<TC_ICP1)       | (1<<TC_ICP2)
                        ;

        /* isr_register_handler(interrput number, *isr_link) */
        /* 2 is frame interrupt 
        ** 3 is serial interrupt
        ** 4 is timer interrupt
        */
	isr_register_handler(4, &timer_isr); 
	asm("ei");

        for(;;)
	{
		DELAY(2000000);
		inkey = sio_getchar(0);
		switch(inkey)
		{
		  case 3:
		      exit(0); /* CTRL+C */
                  case '-':
                      TIMER[TC_INCREMENT] -= 1;
                      TIMER[TC_APPLY] = (1<<TC_INCREMENT);
                      break;
                  case '+':
                      TIMER[TC_INCREMENT] += 1;
                      TIMER[TC_APPLY] = (1<<TC_INCREMENT);
                      break;
                  case ',':
                      TIMER[TC_INCREMENT] -= 100;
                      TIMER[TC_APPLY] = (1<<TC_INCREMENT);
                      break;
                  case '.':
                      TIMER[TC_INCREMENT] += 100;
                      TIMER[TC_APPLY] = (1<<TC_INCREMENT);
                      break;
                }
                switch(inkey)
                {
                  case '\r':
                  case '-':
                  case '+':
                  case ',':
                  case '.':
                      print_timer();
                      break;
                }

	}
}
Ejemplo n.º 26
0
/*
 * Pretty print channel
 */
static void print_channel(struct lttng_channel *channel)
{
	int ret;
	uint64_t discarded_events, lost_packets, monitor_timer_interval;
	int64_t blocking_timeout;

	ret = lttng_channel_get_discarded_event_count(channel,
			&discarded_events);
	if (ret) {
		ERR("Failed to retrieve discarded event count of channel");
		return;
	}

	ret = lttng_channel_get_lost_packet_count(channel,
			&lost_packets);
	if (ret) {
		ERR("Failed to retrieve lost packet count of channel");
		return;
	}

	ret = lttng_channel_get_monitor_timer_interval(channel,
			&monitor_timer_interval);
	if (ret) {
		ERR("Failed to retrieve monitor interval of channel");
		return;
	}

	ret = lttng_channel_get_blocking_timeout(channel,
			&blocking_timeout);
	if (ret) {
		ERR("Failed to retrieve blocking timeout of channel");
		return;
	}

	MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
	MSG("%sAttributes:", indent4);
	MSG("%sEvent-loss mode:  %s", indent6, channel->attr.overwrite ? "overwrite" : "discard");
	MSG("%sSub-buffer size:  %" PRIu64 " bytes", indent6, channel->attr.subbuf_size);
	MSG("%sSub-buffer count: %" PRIu64, indent6, channel->attr.num_subbuf);

	print_timer("Switch timer", 5, channel->attr.switch_timer_interval);
	print_timer("Read timer",  7, channel->attr.read_timer_interval);
	print_timer("Monitor timer", 4, monitor_timer_interval);

	if (!channel->attr.overwrite) {
		if (blocking_timeout == -1) {
			MSG("%sBlocking timeout: infinite", indent6);
		} else {
			MSG("%sBlocking timeout: %" PRId64 " µs", indent6, blocking_timeout);
		}
	}

	MSG("%sTrace file count: %" PRIu64 " per stream", indent6,
			channel->attr.tracefile_count == 0 ?
				1 : channel->attr.tracefile_count);
	if (channel->attr.tracefile_size != 0 ) {
		MSG("%sTrace file size:  %" PRIu64 " bytes", indent6,
				channel->attr.tracefile_size);
	} else {
		MSG("%sTrace file size:  %s", indent6, "unlimited");
	}
	switch (channel->attr.output) {
		case LTTNG_EVENT_SPLICE:
			MSG("%sOutput mode:      splice", indent6);
			break;
		case LTTNG_EVENT_MMAP:
			MSG("%sOutput mode:      mmap", indent6);
			break;
	}

	MSG("\n%sStatistics:", indent4);
	if (listed_session.snapshot_mode) {
		/*
		 * The lost packet count is omitted for sessions in snapshot
		 * mode as it is misleading: it would indicate the number of
		 * packets that the consumer could not extract during the
		 * course of recording the snapshot. It does not have the
		 * same meaning as the "regular" lost packet count that
		 * would result from the consumer not keeping up with
		 * event production in an overwrite-mode channel.
		 *
		 * A more interesting statistic would be the number of
		 * packets lost between the first and last extracted
		 * packets of a given snapshot (which prevents most analyses).
		 */
		MSG("%sNone", indent6);
		goto skip_stats_printing;
	}

	if (!channel->attr.overwrite) {
		MSG("%sDiscarded events: %" PRIu64, indent6, discarded_events);
	} else {
		MSG("%sLost packets:     %" PRIu64, indent6, lost_packets);
	}
skip_stats_printing:
	return;
}
Ejemplo n.º 27
0
Archivo: main.c Proyecto: zencoder/zpv
static void sigint_callback (struct ev_loop *loop, ev_signal *w, int revents)
{
    print_timer();
    fprintf(stderr, "{ \"posix_time\": %f, \"exit_status\": \"Success\", \"msg\": \"Received SIGINT\" }\n", ev_time() );
    exit(0);
}
Ejemplo n.º 28
0
int main(int argc, char* argv[]) {
  grib_handle *h=NULL;
  grib_context* c=NULL;
  FILE* fin=NULL;
  FILE* fout=NULL;
  char* finname;
  char* ofilename;
  char defofilename[]="ccsds_perf.out";
  double *values=NULL;
  int append=0;
  size_t nvalues=0;
  int count,e=0;
  int repeatccsds=1;
  int repeatsimple=1;
  grib_timer *tes,*tds,*tej,*tdj;
  char grid_ccsds[]="grid_ccsds";
  size_t grid_ccsds_l=strlen(grid_ccsds);
  char grid_simple[]="grid_simple";
  size_t grid_simple_l=strlen(grid_simple);
  char packingType[50]={0,};
  size_t len=50;
  char param[50]={0,};
  char gridType[50]={0,};
  char outfilename[255]={0,};
  size_t filesize_ccsds=0;
  size_t filesize_simple=0;
  double perc=0;
  long bitsPerValue=0;
  int iarg=1;
  char grid[20]={0,};
  char shortName[20]={0,};
  long level;
  char levelType[20]={0,};

  tes=grib_get_timer(0,"encoding simple", 0, 0);
  tds=grib_get_timer(0,"decoding simple", 0, 0);
  tej=grib_get_timer(0,"encoding ccsds", 0, 0);
  tdj=grib_get_timer(0,"decoding ccsds", 0, 0);

  if (argc != 4 && argc != 6 ) usage(argv[0]);
  if (!strcmp(argv[iarg],"-w")) {
    append=0;
    iarg++;
    ofilename=argv[iarg];
    iarg++;
  } else if (!strcmp(argv[iarg],"-a")) {
    append=1;
    iarg++;
    ofilename=argv[iarg];
    iarg++;
  } else {
    append=0;
    ofilename=defofilename;
  }
  finname=argv[iarg++];
  repeatsimple=atoi(argv[iarg++]);
  bitsPerValue=atoi(argv[iarg++]);

  fin = fopen(finname,"r");
  if(!fin) {perror(finname);exit(1);}

  if (append)
      fout = fopen(ofilename,"a");
  else
      fout = fopen(ofilename,"w");

  if(!fout) {perror(ofilename);exit(1);}

  c=grib_context_get_default();
  e=0;
  h=grib_handle_new_from_file(c,fin,&e);
  fclose(fin);

  GRIB_CHECK(e,0);

  len=50;
  grib_get_string(h,"shortName",param,&len);

  len=20;
  grib_get_string(h,"levelType",levelType,&len);

  if (!strcmp(levelType,"pl")) {
    GRIB_CHECK(grib_get_long(h,"level",&level),0);
    sprintf(shortName,"%s%ld",param,level);
  } else {
    sprintf(shortName,"%s",param);
  }


  grib_set_long(h,"editionNumber",2);
  GRIB_CHECK(grib_get_size(h,"values",&nvalues),0);
  values=(double*)grib_context_malloc(c,sizeof(double)*nvalues);
  if (!values) { printf("%s: memory allocation error\n",argv[0]); exit(1); }

  len=50;
  grib_get_string(h,"gridType",gridType,&len);

  len=50;
  grib_get_string(h,"packingType",packingType,&len);

  GRIB_CHECK(grib_get_double_array(h,"values",values,&nvalues),0);
  grib_set_long(h,"bitsPerValue",bitsPerValue);
  GRIB_CHECK(grib_set_double_array(h,"values",values,nvalues),0);

  printf("--------------------------------\n");
  printf("- %s - gridType=%s packingType=%s numberOfValues=%ld bitsPerValue=%ld\n",
    param,gridType,packingType,(long)nvalues,bitsPerValue);

  if (!strcmp(packingType,"spectral_complex") || !strcmp(packingType,"spectral_simple")) {
     printf("unable to process spectral data\n");
     exit(1);
  }

  if (!strcmp(gridType,"reduced_gg") || !strcmp(gridType,"regular_gg")) {
     long N;
     grib_get_long(h,"N",&N);
     printf("    N=%ld\n",N);
     sprintf(grid,"%ld",N);
  }
  if (!strcmp(gridType,"regular_ll")) {
     double Di,Dj;
     grib_get_double(h,"DiInDegrees",&Di);
     grib_get_double(h,"DjInDegrees",&Dj);
     printf("    Di=%g Dj=%g\n",Di,Dj);
     sprintf(grid,"%g/%g",Di,Dj);
  }


  if (!append)
    fprintf(fout,
    "shortName gridType numberOfValues bitsPerValue grid sizeSimple sizeccsds encodeccsds encodeSimple decodeccsds decodeSimple\n");

  /* decode values grid_simple */
  if (strcmp(packingType,grid_simple))
    grib_set_string(h,"packingType",grid_simple,&grid_simple_l);
  /* printf("decoding simple\n"); */
  grib_timer_start(tds);
  for (count=0;count<repeatsimple;count++)
    GRIB_CHECK(grib_get_double_array(h,"values",values,&nvalues),0);
  grib_timer_stop(tds,0);
  /* printf("%d messages decoded\n\n",count); */

  *outfilename='\0';
  sprintf(outfilename,"%s_%s_%ld_simple.grib2",param,gridType,bitsPerValue);
  filesize_simple=grib_handle_write(h,outfilename);
  printf("file size simple = %ld\n",(long)filesize_simple);

  /* encode values grid_simple*/
  /* printf("encoding simple\n"); */
  grib_timer_start(tes);
  for (count=0;count<repeatsimple;count++)
    GRIB_CHECK(grib_set_double_array(h,"values",values,nvalues),0);
  grib_timer_stop(tes,0);
  /* printf("%d messages encoded \n\n",count); */

  /* decode values grid_ccsds */
  grib_set_string(h,"packingType",grid_ccsds,&grid_ccsds_l);
  /* printf("decoding ccsds\n"); */
  grib_timer_start(tdj);
  for (count=0;count<repeatccsds;count++)
    GRIB_CHECK(grib_get_double_array(h,"values",values,&nvalues),0);
  grib_timer_stop(tdj,0);
  /* printf("%d messages decoded\n\n",count); */

  *outfilename='\0';
  sprintf(outfilename,"%s_%s_%ld_ccsds.grib2",param,gridType,bitsPerValue);
  filesize_ccsds=grib_handle_write(h,outfilename);
  printf("file size ccsds   = %ld\n",(long)filesize_ccsds);

  perc=(double)filesize_simple/(double)filesize_ccsds;

  printf("compression ratio = %g \n",perc);
  printf("space savings = %g \n",(1.0-1.0/perc)*100);

  /* encode values grid_ccsds*/
  /* printf("encoding ccsds\n"); */
  grib_timer_start(tej);
  for (count=0;count<repeatccsds;count++)
    GRIB_CHECK(grib_set_double_array(h,"values",values,nvalues),0);
  grib_timer_stop(tej,0);
  /* printf("%d messages encoded \n\n",count); */

  grib_handle_delete(h);
  grib_context_free(c,values);

  print_timer(tej,repeatccsds);
  print_timer(tdj,repeatccsds);
  print_timer(tes,repeatsimple);
  print_timer(tds,repeatsimple);
  printf("--------------------------------\n\n");
  fprintf(fout,"%s %s %ld %ld %s %ld %ld %g %g %g %g\n",
    shortName,gridType,(long)nvalues,bitsPerValue,
    grid,(long)filesize_simple,(long)filesize_ccsds,tej->timer_/repeatccsds,tes->timer_/repeatsimple,tdj->timer_/repeatccsds,tds->timer_/repeatsimple);

  return 0;
}