コード例 #1
0
ファイル: test_mheap.c プロジェクト: chrisy/vpp
int
test1 (void)
{
  clib_time_t clib_time;
  void *h_mem = clib_mem_alloc (2ULL << 30);
  void *h;
  uword *objects = 0;
  int i;
  f64 before, after;

  clib_time_init (&clib_time);

  vec_validate (objects, 2000000 - 1);

  h = mheap_alloc (h_mem, (uword) (2 << 30));

  before = clib_time_now (&clib_time);

  for (i = 0; i < vec_len (objects); i++)
    {
      h = mheap_get_aligned (h, 24 /* size */ ,
			     64 /* align */ ,
			     16 /* align at offset */ , &objects[i]);
    }

  after = clib_time_now (&clib_time);

  fformat (stdout, "alloc: %u objects in %.2f seconds, %.2f objects/second\n",
	   vec_len (objects), (after - before),
	   ((f64) vec_len (objects)) / (after - before));

  return 0;
}
コード例 #2
0
ファイル: time_range.c プロジェクト: chrisy/vpp
void
clib_timebase_init (clib_timebase_t * tb, i32 timezone_offset_in_hours,
		    clib_timebase_daylight_time_t daylight_type)
{
  clib_memset (tb, 0, sizeof (*tb));

  clib_time_init (&tb->clib_time);
  tb->time_zero = unix_time_now ();

  tb->timezone_offset = ((f64) (timezone_offset_in_hours)) * 3600.0;
  tb->daylight_time_type = daylight_type;
  switch (tb->daylight_time_type)
    {
    case CLIB_TIMEBASE_DAYLIGHT_NONE:
      tb->summer_offset = 0.0;
      break;
    case CLIB_TIMEBASE_DAYLIGHT_USA:
      tb->summer_offset = 3600.0;
      break;
    default:
      clib_warning ("unknown daylight type %d", tb->daylight_time_type);
      tb->daylight_time_type = CLIB_TIMEBASE_DAYLIGHT_NONE;
      tb->summer_offset = 0.0;
    }
}
コード例 #3
0
ファイル: test_time.c プロジェクト: JehandadKhan/vpp
static int test_time_main (unformat_input_t * input)
{
  f64 wait, error;
  f64 t, tu[3], ave, rms;
  clib_time_t c;
  int i, n, j;

  clib_time_init (&c);
  wait = 1e-3;
  n = 1000;
  unformat (input, "%f %d", &wait, &n);
  ave = rms = 0;
  tu[0] = unix_time_now ();
  tu[1] = unix_time_now ();
  for (i = 0; i < n; i++) {
    j = 0;
    t = clib_time_now (&c);
    while (clib_time_now (&c) < t + wait)
      j++;
    t = j;
    ave += t;
    rms += t*t;
  }
  tu[2] = unix_time_now ();
  ave /= n;
  rms = sqrt (rms/n - ave*ave);

  error = ((tu[2] - tu[1]) - 2 * (tu[1] - tu[0]) - n*wait) / n;
  if_verbose   ("tested %d x %.6e sec waits, error %.6e loops %.6e +- %.6e\n",
		n, wait, error, ave, rms);

  return 0;
}
コード例 #4
0
ファイル: memory_client.c プロジェクト: JehandadKhan/vpp
u16 vl_client_get_first_plugin_msg_id (char * plugin_name)
{
    vl_api_get_first_msg_id_t * mp;
    api_main_t * am = &api_main;
    memory_client_main_t * mm = &memory_client_main;
    f64 timeout;
    void * old_handler;
    clib_time_t clib_time;
    u16 rv = ~0;

    if (strlen(plugin_name) + 1 > sizeof (mp->name))
        return (rv);

    memset (&clib_time, 0, sizeof (clib_time));
    clib_time_init (&clib_time);

    /* Push this plugin's first_msg_id_reply handler */
    old_handler = am->msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY];
    am->msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY] = (void *)
        vl_api_get_first_msg_id_reply_t_handler;

    /* Ask the data-plane for the message-ID base of the indicated plugin */
    mm->first_msg_id_reply_ready = 0;

    mp = vl_msg_api_alloc (sizeof(*mp));
    memset (mp, 0, sizeof (*mp));
    mp->_vl_msg_id = ntohs(VL_API_GET_FIRST_MSG_ID);
    mp->client_index = am->my_client_index;
    strncpy ((char *) mp->name, plugin_name, sizeof (mp->name) - 1);

    vl_msg_api_send_shmem (am->shmem_hdr->vl_input_queue, (u8 *)&mp);

    /* Synchronously wait for the answer */
    do {                                          
        timeout = clib_time_now (&clib_time) + 1.0;       
        
        while (clib_time_now (&clib_time) < timeout) {    
            if (mm->first_msg_id_reply_ready == 1) {         
                rv = mm->first_msg_id_reply;
                goto result;
            }                                     
        }                                         
        /* Restore old handler */
        am->msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY] = old_handler;

        return rv;
    } while(0);

result:

    /* Restore the old handler */
    am->msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY] = old_handler;

    if (rv == (u16) ~0)
        clib_warning ("plugin '%s' not registered", plugin_name);

    return rv;
}
コード例 #5
0
ファイル: unix-kelog.c プロジェクト: JehandadKhan/vpp
void kelog_init (elog_main_t * em, char * kernel_tracer, u32 n_events)
{
  int enable_fd, current_tracer_fd, data_fd;
  int len;
  struct timespec ts, ts2;
  char *trace_enable = "/debug/tracing/tracing_enabled";
  char *current_tracer = "/debug/tracing/current_tracer";
  char *trace_data = "/debug/tracing/trace";
  f64 realtime, monotonic;
  f64 freq, secs_per_clock;

  ASSERT (kernel_tracer);

  /*$$$$ fixme */
  n_events = 1<<18;

  /* init first so we won't hurt ourselves if we bail */
  elog_init (em, n_events);

  enable_fd = open (trace_enable, O_RDWR);
  if (enable_fd < 0)
    {
      clib_warning ("Couldn't open %s", trace_enable);
      return;
    }
  /* disable kernel tracing */
  if (write (enable_fd, "0\n", 2) != 2) 
    {
      clib_unix_warning ("disable tracing");
      close(enable_fd);
      return;
    }
    
  /* 
   * open + clear the data buffer.
   * see .../linux/kernel/trace/trace.c:tracing_open()
   */
  data_fd = open (trace_data, O_RDWR | O_TRUNC);
  if (data_fd < 0) 
    {
      clib_warning ("Couldn't open+clear %s", trace_data);
      return;
    }
  close(data_fd);

  /* configure tracing */
  current_tracer_fd = open (current_tracer, O_RDWR);

  if (current_tracer_fd < 0)
    {
      clib_warning ("Couldn't open %s", current_tracer);
      close(enable_fd);
      return;
    }

  len = strlen(kernel_tracer);

  if (write (current_tracer_fd, kernel_tracer, len) != len) 
    {
      clib_unix_warning ("configure trace");
      close(current_tracer_fd);
      close(enable_fd);
      return;
    }
  
  close(current_tracer_fd);

  /* 
   * The kernel event log uses CLOCK_MONOTONIC timestamps,
   * not CLOCK_REALTIME timestamps. These differ by a constant
   * but the constant is not available in user mode.
   * This estimate will be off by one syscall round-trip.
   */
  clib_time_init (&em->cpu_timer);
  em->init_time.cpu = em->cpu_timer.init_cpu_time;
  syscall (SYS_clock_gettime, CLOCK_MONOTONIC, &ts);
  
  /* enable kernel tracing */
  if (write (enable_fd, "1\n", 2) != 2) 
    {
      clib_unix_warning ("enable tracing");
      close(enable_fd);
      return;
    }

  close(enable_fd);
}