コード例 #1
0
ファイル: main.cpp プロジェクト: Lunavast/bullet-physics
int init(void)
{
// ARA begin insert new code
#ifdef __ANDROID__
	runNEONTests();
#endif
// ARA end

	perf_init();
	ctrl_init();
	render_init();
	physics_init();

	landscapeMeshId = render_init_mesh(
		LargeMeshVtx,sizeof(float)*6,
		LargeMeshVtx+3,sizeof(float)*6,
		LargeMeshIdx,sizeof(unsigned short)*3,
		LargeMeshVtxCount,LargeMeshIdxCount/3);

	convexMeshId = render_init_mesh(
		BarrelVtx,sizeof(float)*6,
		BarrelVtx+3,sizeof(float)*6,
		BarrelIdx,sizeof(unsigned short)*3,
		BarrelVtxCount,BarrelIdxCount/3);

	return 0;
}
コード例 #2
0
ファイル: ethernetif.c プロジェクト: wosayttn/aos
/********************************************************************************
 * Name:
 *          netif_proto_init
 *
 * Description:
 *          the network card init call low_level_init()
 *
 * Parameter:
 *          netif:struct for network card
 *
 * Return:
 *          the status of init
 ********************************************************************************/
int lwip_tcpip_init(void)
{
#ifdef PERF
    perf_init("/tmp/minimal.perf");
#endif /* PERF */

    tcpip_init(tcpip_init_done, NULL);
    LOGI(TAG, "TCP/IP initialized.");

    return 0;
}
コード例 #3
0
ファイル: font_perf.c プロジェクト: mmmmhack/vblend
int main(int argc, char* argv[]) {
  win_new();

  glfwSetWindowTitle("font_perf");
//  font_set_color(1, 1, 1, 0);

	perf_init();

  // main loop
  glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
  while(1) {
		perf_mark_beg("glClear");
    glClear(GL_COLOR_BUFFER_BIT);
		perf_mark_end("glClear");

		perf_mark_beg("ortho");
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    int l = 0;
    int r = win_width();
    int b = 0;
    int t = win_height();
    gluOrtho2D(l, r, b, t);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
		perf_mark_end("ortho");


     // draw bitmap letter
//		perf_mark_beg("draw_letter");
//		int i;
//		for(i = 0; i < 50; ++i) {
    	draw_letter();
//		}
//		perf_mark_end("draw_letter");

//    font_draw(100, 100, "bitchin camaro!");

		perf_mark_beg("swap");
    glfwSwapBuffers();
		perf_mark_end("swap");
    if(!glfwGetWindowParam(GLFW_OPENED))
      break;

//    fps_inc_frames_drawn();
	  perf_report();
  }

	perf_terminate();
  glfwTerminate();
  return 0;
}
コード例 #4
0
ファイル: bench.cpp プロジェクト: SergioDemianLerner/bitcoin
void
benchmark::BenchRunner::RunAll(double elapsedTimeForOne)
{
    perf_init();
    std::cout << "#Benchmark" << "," << "count" << "," << "min" << "," << "max" << "," << "average" << ","
              << "min_cycles" << "," << "max_cycles" << "," << "average_cycles" << "\n";

    for (const auto &p: benchmarks()) {
        State state(p.first, elapsedTimeForOne);
        p.second(state);
    }
    perf_fini();
}
コード例 #5
0
ファイル: main.cpp プロジェクト: Lunavast/bullet-physics
int init(void)
{
	perf_init();
	ctrl_init();
	render_init();
	physics_init();

	float angX,angY,r;
	render_get_view_angle(angX,angY,r);
	r *= 0.5f;
	render_set_view_angle(angX,angY,r);

	return 0;
}
コード例 #6
0
ファイル: simnode.c プロジェクト: Kavetron/lwip_contrib
/*-----------------------------------------------------------------------------------*/
int
main(void)
{
#ifdef PERF
  perf_init("/tmp/client.perf");
#endif /* PERF */

  tcpdump_init();

  printf("System initialized.\n");

  sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  pause();
  return 0;
}
コード例 #7
0
ファイル: testTimer.c プロジェクト: uberflyx/easyperf
int main(void) {
	long unsigned int start[2], end[2];
	unsigned long i;
	perf_init(2, EV_CYCLES, EV_INSTRUCTIONS);


	for (i = 0; i<10; i++) {
		unsigned long loops = 1ul << (i + 10);
		perf_read_all(start);

		foo(loops);

		perf_read_all(end);

		printf("[%6lu] Cycles: %10lu, Instrs: %10lu\n",
				loops, end[0] - start[0], end[1] - start[1]);
	}

	perf_close();
	return 0;
}
コード例 #8
0
ファイル: main.cpp プロジェクト: NetjerDjehuty/INFOMGP
int init(void)
{
	perf_init();
	ctrl_init();
	render_init();
	physics_init();

	landscapeMeshId = render_init_mesh(
		LargeMeshVtx,sizeof(float)*6,
		LargeMeshVtx+3,sizeof(float)*6,
		LargeMeshIdx,sizeof(unsigned short)*3,
		LargeMeshVtxCount,LargeMeshIdxCount/3);

	convexMeshId = render_init_mesh(
		BarrelVtx,sizeof(float)*6,
		BarrelVtx+3,sizeof(float)*6,
		BarrelIdx,sizeof(unsigned short)*3,
		BarrelVtxCount,BarrelIdxCount/3);

	return 0;
}
コード例 #9
0
ファイル: simhost.c プロジェクト: NKSG/INTER_MANET_NS3
/*-----------------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
#ifdef PERF
  perf_init("/tmp/simhost.perf");
#endif /* PERF */
#if LWIP_STATS
  stats_init();
#endif /* STATS */
  sys_init();
  mem_init();
  memp_init();
  pbuf_init();
#ifdef LWIP_TCPDUMP
  tcpdump_init();
#endif
  
  printf("System initialized.\n");
    
  sys_thread_new(main_thread, NULL, DEFAULT_THREAD_PRIO);
  pause();
  return 0;
}
コード例 #10
0
ファイル: simhost.c プロジェクト: kingcope/LikeOS
/*-----------------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
#ifdef PERF
  perf_init("/tmp/simhost.perf");
#endif /* PERF */
#ifdef STATS
  stats_init();
#endif /* STATS */
  sys_init();
  mem_init();
  memp_init();
  pbuf_init();

  tcpdump_init();

  
  printf("System initialized.\n");
    
  sys_thread_new((void *)(main_thread), NULL);
  pause();
  return 0;
}
コード例 #11
0
ファイル: simhost.c プロジェクト: malooei/yeejoin-workspace
/*-----------------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
	struct in_addr inaddr;
	int ch;
	char ip_str[16] = {0}, nm_str[16] = {0}, gw_str[16] = {0};

	/* startup defaults (may be overridden by one or more opts) */
	IP4_ADDR(&gw, 192,168,0,1);
	IP4_ADDR(&netmask, 255,255,255,0);
	IP4_ADDR(&ipaddr, 192,168,0,2);

	ping_flag = 0;
	/* use debug flags defined by debug.h */
	debug_flags = LWIP_DBG_OFF;

	while ((ch = getopt_long(argc, argv, "dhg:i:m:p:", longopts, NULL)) != -1) {
		switch (ch) {
		case 'd':
			debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT);
			break;
		case 'h':
			usage();
			exit(0);
			break;
		case 'g':
			inet_aton(optarg, &inaddr);
			gw.addr = inaddr.s_addr;
			break;
		case 'i':
			inet_aton(optarg, &inaddr);
			ipaddr.addr = inaddr.s_addr;
			break;
		case 'm':
			inet_aton(optarg, &inaddr);
			netmask.addr = inaddr.s_addr;
			break;
		case 'p':
			ping_flag = !0;
			inet_aton(optarg, &inaddr);
			/* lwip inet.h oddity workaround */
			ping_addr.addr = inaddr.s_addr;
			strncpy(ip_str,inet_ntoa(inaddr),sizeof(ip_str));
			printf("Using %s to ping\n", ip_str);
			break;
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	inaddr.s_addr = ipaddr.addr;
	strncpy(ip_str,inet_ntoa(inaddr),sizeof(ip_str));
	inaddr.s_addr = netmask.addr;
	strncpy(nm_str,inet_ntoa(inaddr),sizeof(nm_str));
	inaddr.s_addr = gw.addr;
	strncpy(gw_str,inet_ntoa(inaddr),sizeof(gw_str));
	printf("Host at %s mask %s gateway %s\n", ip_str, nm_str, gw_str);

#ifdef PERF
	perf_init("/tmp/simhost.perf");
#endif /* PERF */

	printf("System initialized.\n");

	sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
	pause();
	return 0;
}
コード例 #12
0
ファイル: example.c プロジェクト: d-s-d/FNC14-BST
int main(int argc, char *argv[])
{
    int ret;

    // For a list of valid performance events, see
    //   libpfm/examples/showevtinfo -L
    // or
    //   Intel 64 and IA-32 Architectures Software Developer’s Manual,
    //     Volume 3B: System Programming Guide, Part 2
    
    // Initialize perfmon -------------------------------------------------
    char *events[] = {
        // on Haswell, can use at most 4, otherwise '0' results
        "PERF_COUNT_HW_CPU_CYCLES",
        "CACHE-REFERENCES",
        "CACHE-MISSES",
        "DTLB-LOAD-MISSES",
        NULL
    };

    struct perf_data *data;
    
    ret = perf_init(events, &data);
    if (ret < 0) {
        fprintf(stderr, "Could not initialize perfmon.\n");
        perf_cleanup(data);
        return 0;
    }

    // Example 1: Measure performance for MMM in this file. ---------------

    perf_start(data);

    for (int i=0; i<N; ++i) {
        for (int j=0; j<N; ++j) {
            for (int k=0; k<N; ++k) {
                COST_INC_ADD(1); COST_INC_MUL(1);
                C[i*N+j] = A[i*N+k] * B[k*N+j] + C[i*N+j];
            }
        }
    }

    ret = perf_stop(data);
    if (ret < 0) {
        fprintf(stderr, "Error measuring performance.\n");
        perf_cleanup(data);
        return 0;
    }

    // short cycles check
    perf_update_values(data);
    printf("Cycles after example 1: %llu\n", data[0].value);

    // Example 2: Measure external computation ----------------------------

    perf_start(data);    // if desired, do perf_reset() first
    other_computation();
    perf_stop(data);

    // Report results -----------------------------------------------------

    perf_update_values(data);

    printf("Overall results:\n");
    printf("Performance Counters:\n");
    for (struct perf_data *iter = data; iter->name; ++iter) {
        printf("  %-50s : %"PRId64"\n", iter->name, iter->value);
    }

    printf("Cost Model:\n");
    printf("  Add: %"PRI_COST"\n", COST_ADD);
    printf("  Mul: %"PRI_COST"\n", COST_MUL);
    printf("  Div: %"PRI_COST"\n", COST_DIV);
    printf("  Pow: %"PRI_COST"\n", COST_POW);
    printf("  Abs: %"PRI_COST"\n", COST_ABS);

    printf("Derived Results\n");
    double flops      = COST_ADD + COST_MUL + COST_DIV;
    double cycles     = data[0].value; // index as in 'events'
    double cache_load = data[1].value;
    double cache_miss = data[2].value;
    printf("  Flops           : %.0lf\n", flops);
    printf("  Performance     : %.3lf\n", flops/cycles);
    printf("  Cache Miss Rate : %.3lf\n", cache_miss/cache_load);

    // Cleanup ------------------------------------------------------------
    perf_cleanup(data);

    return 0;
}
コード例 #13
0
ファイル: main.c プロジェクト: 1847123212/lwBT
/*-----------------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  struct phybusif_cb *cb;
  struct timeval tcptv, bttv, now;
  struct timezone tz;
  u8_t btiptmr = 0;
  
#ifdef PERF
  perf_init("/tmp/minimal.perf");
#endif /* PERF */
#ifdef STATS
  stats_init();
#endif /* STATS */

  mem_init();
  memp_init();
  pbuf_init(); 
  netif_init();
  ip_init();
  //udp_init();
  tcp_init();
  printf("TCP/IP initialized.\n");
  lwbt_memp_init();
  phybusif_init();
  if(hci_init() != ERR_OK) {
    printf("HCI initialization failed!");
    exit(-1);
  }
  l2cap_init();
  sdp_init();
  rfcomm_init();
  ppp_init();
  printf("Bluetooth initialized.\n");

  //echo_init();
  httpd_init();
  printf("Applications started.\n");

  cb = malloc(sizeof(struct phybusif_cb));
  phybusif_reset(cb);

  gettimeofday(&bttv, &tz); /* Initialize Bluetooth timer (1s) */
  gettimeofday(&tcptv, &tz); /* Initialize TCP timer (TCP_TMR_INTERVAL) */

  /* Host controller initialization for DTs according to LAN access point (LAP) and dial up networking (DUN) profile */
  bt_ip_start(NULL);

  while(1) {
    phybusif_input(cb); /* Check for input */

    gettimeofday(&now, &tz); /* Get current time */

    /* Check if TCP timer  should be called */
    if((now.tv_sec - tcptv.tv_sec) * 1000000 + (now.tv_usec - tcptv.tv_usec) >= TCP_TMR_INTERVAL * 1000) {
      gettimeofday(&tcptv, &tz); /* Reset TCP timer */
      tcp_tmr();
    }

    /* Check if Bluetooth and NAT timers should be called */ 
    if((now.tv_sec - bttv.tv_sec) * 1000000 + (now.tv_usec - bttv.tv_usec) >= 1000000) {
      gettimeofday(&bttv, &tz); /* Restart Bluetooth timer */
      l2cap_tmr();
      rfcomm_tmr();
      ppp_tmr();
      nat_tmr();
      if(++btiptmr == 240) { /* Akes server special */
	bt_ip_tmr();
	btiptmr = 0;
      }
    }
  }
  
  return 0;
}
コード例 #14
0
ファイル: main.c プロジェクト: 10code/lwip
int
main(int argc, char **argv)
{
  struct netif netif;
  sigset_t mask, oldmask, empty;
  int ch;
  char ip_str[16] = {0}, nm_str[16] = {0}, gw_str[16] = {0};

  /* startup defaults (may be overridden by one or more opts) */
  IP4_ADDR(&gw, 192,168,0,1);
  IP4_ADDR(&ipaddr, 192,168,0,2);
  IP4_ADDR(&netmask, 255,255,255,0);

  trap_flag = 0;
  /* use debug flags defined by debug.h */
  debug_flags = LWIP_DBG_OFF;

  while ((ch = getopt_long(argc, argv, "dhg:i:m:t:", longopts, NULL)) != -1) {
    switch (ch) {
      case 'd':
        debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT);
        break;
      case 'h':
        usage();
        exit(0);
        break;
      case 'g':
        ipaddr_aton(optarg, &gw);
        break;
      case 'i':
        ipaddr_aton(optarg, &ipaddr);
        break;
      case 'm':
        ipaddr_aton(optarg, &netmask);
        break;
      case 't':
        trap_flag = !0;
        /* @todo: remove this authentraps tweak 
          when we have proper SET & non-volatile mem */
        snmpauthentraps_set = 1;
        ipaddr_aton(optarg, &trap_addr);
        strncpy(ip_str, ipaddr_ntoa(&trap_addr),sizeof(ip_str));
        printf("SNMP trap destination %s\n", ip_str);
        break;
      default:
        usage();
        break;
    }
  }
  argc -= optind;
  argv += optind;

  strncpy(ip_str, ipaddr_ntoa(&ipaddr), sizeof(ip_str));
  strncpy(nm_str, ipaddr_ntoa(&netmask), sizeof(nm_str));
  strncpy(gw_str, ipaddr_ntoa(&gw), sizeof(gw_str));
  printf("Host at %s mask %s gateway %s\n", ip_str, nm_str, gw_str);


#ifdef PERF
  perf_init("/tmp/minimal.perf");
#endif /* PERF */

  lwip_init();

  printf("TCP/IP initialized.\n");

  netif_add(&netif, &ipaddr, &netmask, &gw, NULL, mintapif_init, ethernet_input);
  netif_set_default(&netif);
  netif_set_up(&netif);


#if SNMP_PRIVATE_MIB != 0
  /* initialize our private example MIB */
  lwip_privmib_init();
#endif
  snmp_trap_dst_ip_set(0,&trap_addr);
  snmp_trap_dst_enable(0,trap_flag);
  snmp_set_syscontact(syscontact_str,&syscontact_len);
  snmp_set_syslocation(syslocation_str,&syslocation_len);
  snmp_set_snmpenableauthentraps(&snmpauthentraps_set);
  snmp_init();

  echo_init();

  timer_init();
  timer_set_interval(TIMER_EVT_ETHARPTMR, ARP_TMR_INTERVAL / 10);
  timer_set_interval(TIMER_EVT_TCPTMR, TCP_TMR_INTERVAL / 10);
#if IP_REASSEMBLY
  timer_set_interval(TIMER_EVT_IPREASSTMR, IP_TMR_INTERVAL / 10);
#endif
  
  printf("Applications started.\n");
    

  while (1) {
    
      /* poll for input packet and ensure
         select() or read() arn't interrupted */
      sigemptyset(&mask);
      sigaddset(&mask, SIGALRM);
      sigprocmask(SIG_BLOCK, &mask, &oldmask);

      /* start of critical section,
         poll netif, pass packet to lwIP */
      if (mintapif_select(&netif) > 0)
      {
        /* work, immediatly end critical section 
           hoping lwIP ended quickly ... */
        sigprocmask(SIG_SETMASK, &oldmask, NULL);
      }
      else
      {
        /* no work, wait a little (10 msec) for SIGALRM */
          sigemptyset(&empty);
          sigsuspend(&empty);
        /* ... end critical section */
          sigprocmask(SIG_SETMASK, &oldmask, NULL);
      }
    
      if(timer_testclr_evt(TIMER_EVT_TCPTMR))
      {
        tcp_tmr();
      }
#if IP_REASSEMBLY
      if(timer_testclr_evt(TIMER_EVT_IPREASSTMR))
      {
        ip_reass_tmr();
      }
#endif
      if(timer_testclr_evt(TIMER_EVT_ETHARPTMR))
      {
        etharp_tmr();
      }
      
  }
  
  return 0;
}
コード例 #15
0
ファイル: simhost.c プロジェクト: aps243/2A-lwIP
/*-----------------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  int ch;
  char ip_str[16] = {0};

  /* startup defaults (may be overridden by one or more opts) */
#if LWIP_IPV4
  IP_ADDR4(&gw,      192,168,  0,1);
  IP_ADDR4(&netmask, 255,255,255,0);
  IP_ADDR4(&ipaddr,  192,168,  0,2);
#if LWIP_HAVE_SLIPIF
  IP_ADDR4(&gw_slip,      192,168,  2,  1);
  IP_ADDR4(&netmask_slip, 255,255,255,255);
  IP_ADDR4(&ipaddr_slip,  192,168,  2,  2);
#endif
#endif /* LWIP_IPV4 */
  
  ping_flag = 0;
  /* use debug flags defined by debug.h */
  debug_flags = LWIP_DBG_OFF;
  
  while ((ch = getopt_long(argc, argv, "dhg:i:m:p:", longopts, NULL)) != -1) {
    switch (ch) {
      case 'd':
        debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT);
        break;
      case 'h':
        usage();
        exit(0);
        break;
#if LWIP_IPV4
      case 'g':
        ipaddr_aton(optarg, &gw);
        break;
      case 'i':
        ipaddr_aton(optarg, &ipaddr);
        break;
      case 'm':
        ipaddr_aton(optarg, &netmask);
        break;
#endif /* LWIP_IPV4 */
      case 'p':
        ping_flag = !0;
        ipaddr_aton(optarg, &ping_addr);
        strncpy(ip_str,ipaddr_ntoa(&ping_addr),sizeof(ip_str));
        ip_str[sizeof(ip_str)-1] = 0; /* ensure \0 termination */
        printf("Using %s to ping\n", ip_str);
        break;
      default:
        usage();
        break;
    }
  }
  argc -= optind;
  argv += optind;
  
#ifdef PERF
  perf_init("/tmp/simhost.perf");
#endif /* PERF */

  printf("System initialized.\n");
    
  sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  pause();
  return 0;
}
コード例 #16
0
ファイル: main.c プロジェクト: NCTU-ivan/embarc_osp
/**
 * \brief  task2 in FreeRTOS
 * \details Print information in task2 and suspend task2.
 * \param[in] *par
 */
static void task2(void *par)
{
	static uint32_t perf_times = 0;
	uint32_t queue_data = 0;
	perf_init(TIMER_1);

	while (1) {
		//// 1-S: Task2 --> Task1
		perf_start();
		vTaskSuspend(task2_handle); /*!< suspend task2 */
		//// 6-E: Task1 --> Task2
		x.t_t1_t2 = perf_end();
		//// 7-S: Benchmark extra cost
		perf_start();
		//// 7-E: Benchmark extra cost
		x.t_measure = perf_end();

		// Task 2 wait for task 1 release mutex
		xSemaphoreTake(mux1_id, portMAX_DELAY);
		//// 8-E: Mutex Release -> Mutex Acquire
		x.t_mux_rls = perf_end();
		xSemaphoreGive(mux1_id);

		// Task 2 wait for task 1 release sem
		xSemaphoreTake(sem1_id, portMAX_DELAY);
		//// 9-E: Sem Post -> Sem Acquire
		x.t_sem_snd = perf_end();
		xSemaphoreGive(sem1_id);

		// Task 2 wait for task 1 set event
		xEventGroupWaitBits(evt1_cb, EVENT_WAIT_BITS, pdTRUE, pdFALSE, portMAX_DELAY);

		//// 10-E: Event Write -> Event Read
		x.t_evt_snd = perf_end();

		// Task 2 read queue
		xQueueReceive(dtq1_id, (void *)(&queue_data), portMAX_DELAY);
		//// 11-E: Queue Write -> Queue Read
		x.t_dtq_wri = perf_end();

		if (perf_times) {
			if (sample_count < MAX_SAMPLES) {
				sample_array[sample_count] = x;
			} else {
				/* Suspend task 1 */
				vTaskSuspend(task1_handle);

				for (int i = 0; i < MAX_SAMPLES; i ++) {
					x_aver.t_measure += sample_array[i].t_measure;
					x_aver.t_t2_t1 += sample_array[i].t_t2_t1;
					x_aver.t_int_t1 += sample_array[i].t_int_t1;
					x_aver.t_t1_t2 += sample_array[i].t_t1_t2;
					x_aver.t_t1_int += sample_array[i].t_t1_int;
					x_aver.t_int_nest += sample_array[i].t_int_nest;
					x_aver.t_nest_int += sample_array[i].t_nest_int;
					x_aver.t_mux_rls += sample_array[i].t_mux_rls;
					x_aver.t_sem_snd += sample_array[i].t_sem_snd;
					x_aver.t_evt_snd += sample_array[i].t_evt_snd;
					x_aver.t_dtq_wri += sample_array[i].t_dtq_wri;
				}

				x_aver.t_measure /= MAX_SAMPLES;
				x_aver.t_t2_t1 /= MAX_SAMPLES;
				x_aver.t_int_t1 /= MAX_SAMPLES;
				x_aver.t_t1_t2 /= MAX_SAMPLES;
				x_aver.t_t1_int /= MAX_SAMPLES;
				x_aver.t_int_nest /= MAX_SAMPLES;
				x_aver.t_nest_int /= MAX_SAMPLES;
				x_aver.t_mux_rls /= MAX_SAMPLES;
				x_aver.t_sem_snd /= MAX_SAMPLES;
				x_aver.t_evt_snd /= MAX_SAMPLES;
				x_aver.t_dtq_wri /= MAX_SAMPLES;

				EMBARC_PRINTF("\r\n");
				EMBARC_PRINTF("Average benchmark result list as follows:\r\n");
				EMBARC_PRINTF("extra measurement cost : %d cycles\r\n", x_aver.t_measure);
				EMBARC_PRINTF("task2     ->  task1    : %d cycles\r\n", x_aver.t_t2_t1);
				EMBARC_PRINTF("task1     ->  int      : %d cycles\r\n", x_aver.t_t1_int);
				EMBARC_PRINTF("int       ->  nest int : %d cycles\r\n", x_aver.t_int_nest);
				EMBARC_PRINTF("nest int  ->  int      : %d cycles\r\n", x_aver.t_nest_int);
				EMBARC_PRINTF("int       ->  task1    : %d cycles\r\n", x_aver.t_int_t1);
				EMBARC_PRINTF("task1     ->  task2    : %d cycles\r\n", x_aver.t_t1_t2);
				EMBARC_PRINTF("mux: tsk1 ->  tsk2     : %d cycles\r\n", x_aver.t_mux_rls);
				EMBARC_PRINTF("sem: tsk1 ->  tsk2     : %d cycles\r\n", x_aver.t_sem_snd);
				EMBARC_PRINTF("evt: tsk1 ->  tsk2     : %d cycles\r\n", x_aver.t_evt_snd);
				EMBARC_PRINTF("dtq: tsk1 ->  tsk2     : %d cycles\r\n", x_aver.t_dtq_wri);
				EMBARC_PRINTF("\r\n");

#ifdef ENABLE_DETAILED_RESULT_OUTPUT
				EMBARC_PRINTF("Detailed benchmark result table list as follows:\r\n");
				EMBARC_PRINTF("t_measure t_t2_t1 t_t1_int t_int_nest t_nest_int t_int_t1 t_t1_t2 t_mux_rls t_sem_snd t_evt_snd t_dtq_wri\r\n");

				for (int i = 0; i < MAX_SAMPLES; i ++) {
					EMBARC_PRINTF("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n", \
					              sample_array[i].t_measure, sample_array[i].t_t2_t1, \
					              sample_array[i].t_t1_int, sample_array[i].t_int_nest, \
					              sample_array[i].t_nest_int, sample_array[i].t_int_t1, \
					              sample_array[i].t_t1_t2, sample_array[i].t_mux_rls, \
					              sample_array[i].t_sem_snd, sample_array[i].t_evt_snd, \
					              sample_array[i].t_dtq_wri);
				}

#endif
				exit(0); /* Exit benchmark application */
			}

			sample_count ++;
		}

		perf_times ++;
	}
}
コード例 #17
0
ファイル: numatop.c プロジェクト: anyc/numatop
/*
 * The main function.
 */
int
main(int argc, char *argv[])
{
	int ret = 1, debug_level = 0;
	FILE *log = NULL, *dump = NULL;
	char c;

	/*
	 * The numatop requires some authorities to setup perf and increase the hard limit of
	 * fd. So either the user runs as root or following condtions need to be satisfied.
	 *
	 * 1. Set "-1" in /proc/sys/kernel/perf_event_paranoid to let the non-root be able to
	 *    setup perf. e.g.
	 *    echo -1 > /proc/sys/kernel/perf_event_paranoid
	 *
	 * 2. The CAP_SYS_RESOURCE capability is required to user for increasing the hard
	 *    limit of fd.
	 */

	g_sortkey = SORT_KEY_CPU;
	g_precise = PRECISE_NORMAL;
	g_numatop_pid = getpid();
	g_run_secs = TIME_NSEC_MAX;
	optind = 1;
	opterr = 0;

	/*
	 * Parse command line arguments.
	 */
	while ((c = getopt(argc, argv, "d:l:o:f:t:hf:s:")) != EOF) {
		switch (c) {
		case 'h':
			print_usage(argv[0]);
			ret = 0;
			goto L_EXIT0;

		case 'l':
			debug_level = atoi(optarg);
			if ((debug_level < 0) || (debug_level > 2)) {
				stderr_print("Invalid log_level %d.\n",
				    debug_level);
				print_usage(argv[0]);
				goto L_EXIT0;
			}
			break;

		case 'f':
			if (optarg == NULL) {
				stderr_print("Invalid output file.\n");
				goto L_EXIT0;
			}

			if ((log = fopen(optarg, "w")) == NULL) {
				stderr_print("Cannot open '%s' for writing.\n",
				    optarg);
				goto L_EXIT0;
			}
			break;

		case 's':
			if (optarg == NULL) {
				print_usage(argv[0]);
				goto L_EXIT0;
			}

			if (strcasecmp(optarg, "high") == 0) {
				g_precise = PRECISE_HIGH;
				break;
			}

			if (strcasecmp(optarg, "low") == 0) {
				g_precise = PRECISE_LOW;
				break;
			}

			if (strcasecmp(optarg, "normal") == 0) {
				g_precise = PRECISE_NORMAL;
				break;
			}

			stderr_print("Invalid sampling_precision '%s'.\n",
			    optarg);
			print_usage(argv[0]);
			goto L_EXIT0;

		case 'd':
			if (optarg == NULL) {
				stderr_print("Invalid dump file.\n");
				goto L_EXIT0;
			}

			if ((dump = fopen(optarg, "w")) == NULL) {
				stderr_print("Cannot open '%s' for dump.\n",
				    optarg);
				goto L_EXIT0;
			}
			break;

		case 't':
			g_run_secs = atoi(optarg);
			if (g_run_secs <= 0) {
				stderr_print("Invalid run time %d.\n",
				    g_run_secs);
				print_usage(argv[0]);
				goto L_EXIT0;
			}
			break;

		case ':':
			stderr_print("Missed argument for option %c.\n",
			    optopt);
			print_usage(argv[0]);
			goto L_EXIT0;

		case '?':
			stderr_print("Unrecognized option %c.\n", optopt);
			print_usage(argv[0]);
			goto L_EXIT0;
		}
	}

	if (plat_detect() != 0) {
		stderr_print("CPU is not supported!\n");
		ret = 2;
		goto L_EXIT0;
	}

	/*
	 * It could be failed if user doesn't have authority.
	 */
	(void) ulimit_expand(PERF_FD_NUM);

	/*
	 * Get the number of online cores in system.
	 */
	if ((g_ncpus = sysfs_online_ncpus()) == -1) {
		stderr_print("Platform is not supported "
		    "(numatop supports up to %d CPUs)\n", NCPUS_MAX);
		goto L_EXIT0;
	}

	pagesize_init();
	gettimeofday(&g_tvbase, 0);

	if (debug_init(debug_level, log) != 0) {
		goto L_EXIT1;
	}

	debug_print(NULL, 2, "Detected %d online CPU.\n", g_ncpus);
	log = NULL;
	sym_init();

	if (dump_init(dump) != 0) {
		goto L_EXIT2;
	}

	dump = NULL;

	/*
	 * Calculate how many nanoseconds for a TSC cycle.
	 */
	calibrate();

	/*
	 * Initialize for the "window-switching" table.
	 */
	switch_table_init();

	if (proc_group_init() != 0) {
		goto L_EXIT3;
	}

	if (node_group_init() != 0) {
		stderr_print("The node/cpu number is out of range, \n"
			"numatop supports up to %d nodes and %d CPUs\n",
			NNODES_MAX, NCPUS_MAX);
		goto L_EXIT4;
	}

	if (disp_cons_ctl_init() != 0) {
		goto L_EXIT5;
	}

	/*
	 * Catch signals from terminal.
	 */
	if ((signal(SIGINT, sigint_handler) == SIG_ERR) ||
	    (signal(SIGHUP, sigint_handler) == SIG_ERR) ||
	    (signal(SIGQUIT, sigint_handler) == SIG_ERR) ||
	    (signal(SIGTERM, sigint_handler) == SIG_ERR) ||
	    (signal(SIGPIPE, sigint_handler) == SIG_ERR)) {
		goto L_EXIT6;
	}

	/*
	 * Initialize the perf sampling facility.
	 */
	if (perf_init() != 0) {
		debug_print(NULL, 2, "perf_init() is failed\n");
		goto L_EXIT6;
	}

	/*
	 * Initialize for display and create console thread & display thread.
	 */
	if (disp_init() != 0) {
		perf_fini();
		goto L_EXIT6;
	}

	/*
	 * Wait the disp thread to exit. The disp thread would
	 * exit when user hits the hotkey 'Q' or press "CTRL+C".
	 */
	disp_dispthr_quit_wait();

	/*
	 * Notify cons thread to exit.
	 */
	disp_consthr_quit();
	
	disp_fini();
	stderr_print("NumaTOP is exiting ...\n");
	(void) fflush(stdout);
	ret = 0;

L_EXIT6:
	disp_cons_ctl_fini();

L_EXIT5:
	node_group_fini();

L_EXIT4:
	proc_group_fini();

L_EXIT3:
	dump_fini();

L_EXIT2:
	sym_fini();
	debug_fini();

L_EXIT1:
	exit_msg_print();

L_EXIT0:
	if (dump != NULL) {
		(void) fclose(dump);
	}

	if (log != NULL) {
		(void) fclose(log);
	}

	return (ret);
}