예제 #1
0
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;
}
예제 #2
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;
}
예제 #3
0
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;
}