Esempio n. 1
0
void
poll_loop_init(void)
{
  int i;
  int size = max_fds * sizeof(struct pollfd);
  poll_array = (struct pollfd *) alloc_aligned(cache_line_size, size,
    ALLOC_MALLOC, "poll_loop_init: (poll_array)");
  printf("poll_loop_init: poll_array has %d entries and used %d bytes\n",
    max_fds, size);

  size = max_fds * sizeof(int);
  poll_map = (int *) alloc_aligned(cache_line_size, size, ALLOC_MALLOC,
    "poll_loop_init: (poll_map)");
  printf("poll_loop_init: poll_map has %d entries and used %d bytes\n",
    max_fds, size);

  /* initialize the array */
  for (i = 0; i < max_fds; i++) {
    poll_array[i].fd = -1;
    poll_array[i].events = 0;
    poll_array[i].revents = 0;
    poll_map[i] = -1;
  }

  interest_set_init(DECLARE_WITH_POLL);
}
Esempio n. 2
0
File: memcpy.c Progetto: taysom/tau
void test (char *test_name, test_loop_f test_loop, void *function)
{
	struct rusage	before;
	struct rusage	after;
	u8		*a;
	u8		*b;
	int		n;
	int		j;

	printf("%s (%s)\n", test_name, meg.legend);
	n = Option.file_size;
	a = alloc_aligned(n);
	b = alloc_aligned(n);
	if (init_buffers) {
		initMem(a, n);
		initMem(b, n);
	}
	for (j = 0; j < Option.loops; j++) {
		getrusage(RUSAGE_SELF, &before);
		test_loop(j, a, b, n, function);
		getrusage(RUSAGE_SELF, &after);
		PrUsage(&before);
		PrUsage(&after);
	}
	free(a);
	free(b);
}
Esempio n. 3
0
/* Allocates two pointers of given characteristics (size, alignement,
   overlapping, relative-position). */
static void get_two_pointers (uword size1, uword size2,
			      uword align1, uword align2,
			      uword overlap, uword two_less_that_one,
			      void ** ptr1, void ** ptr2,
			      void ** to_free1, void ** to_free2)
{
  uword len;
  void * p1, * p2;
  
  *to_free1 = NULL;
  *to_free2 = NULL;

  if (overlap)
    {
      len = size1 + size2 + (1 << align1) + (1 << align2) + overlap;

      if (two_less_that_one)
	{
	  if (align2)
	    p2 = alloc_aligned (len, align2, to_free2);
	  else
	    p2 = alloc_unaligned (len, 1, to_free2);
	    
	  p1 = p2 + overlap;
	  if (align1)
	    p1 = log2_align_ptr_up (p1, align1);
	}
      else
	{
	  if (align1)
	    p1 = alloc_aligned (len, align1, to_free1);
	  else
	    p1 = alloc_unaligned (len, 1, to_free1);
	    
	  p2 = p1 + overlap;
	  if (align2)
	    p2 = log2_align_ptr_up (p2, align2);
	}
    }
  else
    {
      if (align1)
	p1 = alloc_aligned (size1, align1, to_free1);
      else
	p1 = alloc_unaligned (size1, 1, to_free1);

      if (align2)
	p2 = alloc_aligned (size2, align2, to_free2);
      else
	p2 = alloc_unaligned (size2, 1, to_free2);
    }

  *ptr1 = p1;
  *ptr2 = p2;
}
Esempio n. 4
0
  Context::Context( const std::string & name )
  {
    _name = name;

    /* create a stream object */
    _stream = new(alloc_aligned(sizeof(Stream))) Stream;
    
    /* create the ri interface object */
    _rib = new(alloc_aligned(sizeof(RIB))) RIB ( _stream.ptr( ) );

  }
EFI_STATUS garbage_disk(void)
{
	struct gpt_partition_interface gparti;
	EFI_STATUS ret;
	VOID *chunk;
	VOID *aligned_chunk;
	UINTN size;

	ret = gpt_get_root_disk(&gparti, LOGICAL_UNIT_USER);
	if (EFI_ERROR(ret)) {
		efi_perror(ret, L"Failed to get disk information");
		return ret;
	}

	size = gparti.bio->Media->BlockSize * N_BLOCK;
	ret = alloc_aligned(&chunk, &aligned_chunk, size, gparti.bio->Media->IoAlign);
	if (EFI_ERROR(ret)) {
		error(L"Unable to allocate the garbage chunk");
		return ret;
	}

	ret = generate_random_number_chunk(aligned_chunk, size);
	if (EFI_ERROR(ret)) {
		FreePool(chunk);
		return ret;
	}

	ret = fill_with(gparti.bio, gparti.part.starting_lba,
			gparti.part.ending_lba, aligned_chunk, N_BLOCK);

	FreePool(chunk);
	return gpt_refresh();
}
Esempio n. 6
0
/* Initialize LRU queue for MAXCONN entries: */
void
lru_init(void)
{
  int i;

  gettimeofday(&lru_now, NULL);

  /* we map the sd to the lru entry so a few slots are used up for
   * stdin, stdout, stderr, listening socket descriptors, etc. 
   */
  lru_size = maxconns + options.ip_addr_count + numprocs + MAX_APPS + 1;
  printf("lru_init: lru entries = %d\n", lru_size);
  lru_bytes = (lru_size) * sizeof(struct lru);

  lru = (struct lru *) alloc_aligned(cache_line_size, lru_bytes, ALLOC_MALLOC,
    "lru_init: (lru)");

  printf("lru_init: lru = %p\n", lru);
  printf("lru_init: lru bytes = %d\n", lru_bytes);

  memset(lru, 0, lru_bytes);

  for (i = 0; i < lru_size; ++i) {
    lru[i].next = i + 1;
    lru[i].prev = i - 1;
    lru[i].sd = -1;
  }
  lru_head = 0;
  lru_tail = lru_size - 1;
}
Esempio n. 7
0
static void assert_strlen (uword iter)
{
  u8 * s;
  void * s_orig;
  uword i, size, unalign, offset, len;
  u8 c;

  for (i = 0; i < iter; i++)
    {
      size = bounded_random_u32 (&g_seed, 0, g_bytes);
      size++;
      unalign = bounded_random_u32 (&g_seed, 0, 1);

      if (unalign)
	{
	  offset = bounded_random_u32 (&g_seed, 0, 7);
	  s = alloc_unaligned (size, offset, &s_orig);
	}
      else
	{
	  s = alloc_aligned (size, g_align, &s_orig);
	}
	 
      c = bounded_random_u32 (&g_seed, 0, 255);
      memset (s, c, size - 1);
      s[size - 1] = '\0';
      
      len = strlen8 (s);
      ASSERT (len == strlen (s));

      clib_mem_free_safe (s_orig);
    }

  fformat (stdout, "strlen() validation successful!\n");
}
Esempio n. 8
0
/* ---------------------------------------------------------------------- */
void
lru_copy_init(void)
{
  assert(lru_bytes != 0);
  printf("lru_copy_init: max_fds = %d lru_bytes = %d\n", max_fds, lru_bytes);

  lru_copy = (struct lru *) alloc_aligned(cache_line_size, lru_bytes,
    ALLOC_MALLOC, "lru_copy_init: (lru_copy)");
}
Esempio n. 9
0
static void assert_memset (uword iter)
{
  u8 * s;
  void * orig;
  uword i, j, k;
  uword count, size;
  u64 val = 0xbabababababababaLL;

  for (i = 0; i < iter; i++)
    {
      size = bounded_random_u32 (&g_seed, 0, g_bytes);

      for (k = 1; k <= 8; k *= 2)
	{
	  count = size / k;
	  size = (count * k) + 1;

	  if (k == 1)
            {
              void * avoid_warnings_s;
              get_random_pointer (size, &avoid_warnings_s, &orig);
              s = avoid_warnings_s;
            }
	  else
	    s = alloc_aligned (size, min_log2 (k), &orig);

	  memset (s, 0, size);
	  s[size - 1] = MAGIC_GUARD;

	  switch (k)
	    {

#define _(type, func)				\
{						\
  type * ptr = (type *) s;			\
						\
  func (ptr, val, count);			\
						\
  for (j = 0; j < count; j++)			\
    ASSERT (ptr[j] == (type) val);		\
}

	    case 1: _(u8 , memset8);  break;
	    case 2: _(u16, memset16); break;
	    case 4: _(u32, memset32); break;
	    case 8: _(u64, memset64); break;

#undef _
	    }	  

	  ASSERT (s[size - 1] == MAGIC_GUARD);
	  clib_mem_free_safe (orig);
	}
    }

  fformat (stdout, "memset() validation successful!\n");
}
Esempio n. 10
0
void
q_init(int max_nodes)
{
  int i;
  int size;

  assert(max_nodes > 0);
  max_size = max_nodes;
  size = sizeof(q_nodeptr) * max_size;
  fd_array = (q_nodeptr *) alloc_aligned(ALLOC_NOALIGN, size,
    ALLOC_MALLOC, "q_init: (fd_array)");
  printf("fd_array = %p size = %d\n", fd_array, size);

  size = sizeof(struct q_node) * max_size;
  node_array = (q_nodeptr) alloc_aligned(ALLOC_NOALIGN, size,
    ALLOC_MALLOC, "q_init: (node_array)");
  printf("node_array = %p size = %d\n", node_array, size);

  size = sizeof(int) * max_size * 2;
  todo = (struct todo_info *) alloc_aligned(ALLOC_NOALIGN, size,
    ALLOC_MALLOC, "q_init: (todo)");
  printf("todo = %p size = %d\n", todo, size);

  DBG_Q("q_init: finished init\n");

  for (i = 0; i < max_size; i++) {
    fd_array[i] = NULL;
  }

  for (i = 0; i < max_size - 1; i++) {
    node_array[i].fd = -1;
    node_array[i].next = &node_array[i + 1];
  }
  node_array[i].next = NULL;
  first_free = &node_array[0];

  if (debug) {
    q_print_node_array();
  }
  cur_size = 0;
  todo_count = 0;
}
Esempio n. 11
0
static char*
copy_and_align_elf_data (const char *data, size_t len)
{
  size_t alignment;
  char *copy;

  alignment = elf_alignment (data, len);
  copy = alloc_aligned (len, alignment);
  memcpy(copy, data, len);

  return copy;
}
Esempio n. 12
0
static void assert_memcmp (uword iter)
{
  u8 * s, * d;
  void * s_orig, * d_orig;
  uword i;
  uword size, change;
  word res1, res2;

  for (i = 0; i < iter; i++)
    {
      size = bounded_random_u32 (&g_seed, 1, g_bytes);
      d = alloc_aligned (size, g_align, &d_orig);
      s = alloc_aligned (size, g_align, &s_orig);
      memset (d, 0xba, size);
      memset (s, 0xba, size);
      
      if (size && i % 2 == 0)
	{
	  change = bounded_random_u32 (&g_seed, 0, size - 1);
	  d[change] = 0;
	}
      
      res1 = memcmp8 (d, s, size);
      res2 = kmemcmp (d, s, size);

      if (res1 < 0)
	ASSERT (res2 < 0);
      else if (res1 > 0)
	ASSERT (res2 > 0);
      else
	ASSERT (res2 == 0);

      clib_mem_free_safe (d_orig);
      clib_mem_free_safe (s_orig);
    }

  fformat (stdout, "memcmp() validation successful!\n");
}
Esempio n. 13
0
Queue *
alloc_queue(size_t maxsize)
{
  Queue *q;
  size_t arraysize, numbytes;

  /*
   * We actually allocate an array of maxsize + 1, so that we can distinguish
   * between the queue being empty and the queue being full.
   */
  arraysize = maxsize + 1;
  assert(arraysize > 0);

  /* TBB: not sure why things are done this way but
   *      this is allocating enough memory for the structure plus
   *      an array at the end of the structure. Then it's used
   *      as though the array was a static part of the structure.
   */
  numbytes =
    (size_t) offsetof(Queue, data[0]) + (arraysize * sizeof(q->data[0]));

  printf("alloc_queue: maxsize = %lu arraysize = %lu numbytes = %lu\n",
    (unsigned long) maxsize, (unsigned long) arraysize,
    (unsigned long) numbytes);
  q =
    (Queue *) alloc_aligned(ALLOC_NOALIGN, numbytes, ALLOC_MALLOC,
    "alloc_queue");
  if (q != NULL) {
    q->arraysize = arraysize;
    q->head = 0;
    q->tail = 0;
    q->elements = 0;
#ifdef QUEUE_STATS
    q->put_count = 0;
    q->put_max_size = 0;
    q->put_total_size = 0;
    q->push_count = 0;
    q->push_total_size = 0;
    q->get_count = 0;
    q->get_total_size = 0;
    q->peek_count = 0;
    q->peek_total_size = 0;
#endif
    return q;
  }

  return NULL;
}
Esempio n. 14
0
void collect_stats(long64 *work, int phase, int local)
{
  int i;

  if (local == num_saves) {
    if (num_saves == 0)
      stats_val[0] = REDUCE_PLY - 2;
    else
      stats_val[num_saves] = stats_val[num_saves - 1] + REDUCE_PLY_RED;
  }

  if (thread_stats == NULL) {
    thread_stats = (long64 *)alloc_aligned(8 * 256 * numthreads, 64);
    for (i = 0; i < numthreads; i++)
      thread_data[i].stats = thread_stats + i * 256;
  }

  collect_stats_table(total_stats_w, table_w, 1, phase, local, work);
  collect_stats_table(total_stats_b, table_b, 0, phase, local, work);
}
Esempio n. 15
0
/* Allocates randomly-aligned pointer to memory of given size. */
static void get_random_pointer (uword size, void ** ptr, void ** to_free)
{
  uword do_align = bounded_random_u32 (&g_seed, 0, 1);
  uword align, offset;
  
  if (do_align)
    {
      align = bounded_random_u32 (&g_seed, 0, MAX_LOG2_ALIGN);
      *ptr = alloc_aligned (size, align, to_free);
      VERBOSE3 ("size %u, align %u\n", size, align);
    }
  else
    {
      offset = bounded_random_u32 (&g_seed, 0, MAX_UNALIGN_OFFSET);
      *ptr = alloc_unaligned (size, offset, to_free);
      VERBOSE3 ("size %u, offset %u\n", size, offset);
    }

  VERBOSE3 ("ptr %U (%p)\n", format_u32_binary, *ptr, *ptr);
}
Esempio n. 16
0
static int critbit_insert_inplace(critbit_root *root,
        const char *key, int keylen, const void* value) {
    const uint8_t *bytes = (void *)key;

    uint8_t *p = root->head;
    if(!p) {
        p = alloc_string(key, keylen, value);
        if(!p)
            return 1;

        root->head = p;
        return 0;
    }

    p = find_nearest(root->head, bytes, keylen);

    uint32_t newbyte;
    uint8_t newotherbits;
    for(newbyte = 0; newbyte < keylen; ++newbyte) {
        if(p[newbyte] != bytes[newbyte]) {
            newotherbits = p[newbyte] ^ bytes[newbyte];
            goto found;
        }
    }
    if(p[newbyte]) {
        newotherbits = p[newbyte];
        goto found;
    }
    return 1;

found:
    while(newotherbits & (newotherbits - 1)) {
        newotherbits &= newotherbits - 1;
    }
    newotherbits ^= 0xFF;
    uint8_t c = p[newbyte];
    int newdirection = (1 + (newotherbits | c)) >> 8;

    struct critbit_node *node = alloc_aligned(sizeof(struct critbit_node));
    if(!node)
        return 1;

    char *x = alloc_string(key, keylen, value);
    if(!x) {
        free(node);
        return 1;
    }

    node->byte = newbyte;
    node->otherbits = newotherbits;
    node->child[1 - newdirection] = x;

    void **wherep = &root->head;
    for(;;) {
        uint8_t *p = *wherep;
        if(!IS_INTERNAL(p))
            break;

        struct critbit_node *q = TO_NODE(p);
        if(q->byte > newbyte)
            break;
        if(q->byte == newbyte && q->otherbits > newotherbits)
            break;

        wherep = q->child + get_direction(q, bytes, keylen);
    }
    node->child[newdirection] = *wherep;
    __sync_synchronize();
    *wherep = FROM_NODE(node);
    __sync_synchronize();

    return 0;
}
Esempio n. 17
0
int64_t ceParallelRadixJoin::join_init_run (vector<SAP_UINT> *relR, vector<SAP_UINT> *relC, int nthreads)
{
	//#define CPU_ZERO(PTR) (*(PTR) = 0)
	//#define CPU_SET(N, PTR) (*(PTR) = (N))
	//#define pthread_attr_setaffinity_np(ATTR, SZ, PTR) setaffinity(ATTR, SZ, PTR)
	//#define sched_setaffinity(A, SZ, PTR) setaffinity(A, SZ, PTR)
    int i, rv;
    pthread_t tid[nthreads];
    pthread_attr_t attr;
    pthread_barrier_t barrier;
    int set; //cpu_set_t set;
    arg_t args[nthreads];

    int32_t ** histR, ** histS;
    //tuple_t * tmpRelR, * tmpRelS;
    int32_t numperthr[2];
    int64_t result = 0;

    task_queue_t * part_queue, * join_queue;
    
	task_queue_t * skew_queue;
    task_t * skewtask = NULL;
    skew_queue = task_queue_init(FANOUT_PASS1);
    
	part_queue = task_queue_init(FANOUT_PASS1);
    join_queue = task_queue_init((1<<NUM_RADIX_BITS));


    /* allocate temporary space for partitioning */
    //tmpRelR = (tuple_t*) alloc_aligned(relR->size() * sizeof(SAP_UINT) +
    //                                   RELATION_PADDING);
    //tmpRelS = (tuple_t*) alloc_aligned(relS->size() * sizeof(SAP_UINT) +
    //                                   RELATION_PADDING);
    //MALLOC_CHECK((tmpRelR && tmpRelS));
	vector<SAP_UINT> tmpRelR, tmpRelS;

    /** Not an elegant way of passing whether we will numa-localize, but this
        feature is experimental anyway. */
    if(numalocalize) {
        numa_localize(&tmpRelR, relR->size(), nthreads);
        numa_localize(&tmpRelS, relS->size(), nthreads);
    }

    
    /* allocate histograms arrays, actual allocation is local to threads */
    histR = (SAP_UINT**) alloc_aligned(nthreads * sizeof(SAP_UINT*));
    histS = (SAP_UINT**) alloc_aligned(nthreads * sizeof(SAP_UINT*));
    MALLOC_CHECK((histR && histS));

    rv = pthread_barrier_init(&barrier, NULL, nthreads);
    if(rv != 0){
        printf("[ERROR] Couldn't create the barrier\n");
        exit(EXIT_FAILURE);
    }

    pthread_attr_init(&attr);

    /* first assign chunks of relR & relS for each thread */
    numperthr[0] = relR->size() / nthreads;
    numperthr[1] = relS->size() / nthreads;
    for(i = 0; i < nthreads; i++){
        int cpu_idx = get_cpu_id(i);

        //DEBUGMSG(1, "Assigning thread-%d to CPU-%d\n", i, cpu_idx);

        *(&set) = 0; //CPU_ZERO(&set);
        *(&set) = cpu_idx; //CPU_SET(cpu_idx, &set);
        pthread_attr_setaffinity_np(&attr, sizeof(int), &set);

        int32_t numR = (i == (nthreads-1)) ? 
            (relR->size() - i * numperthr[0]) : numperthr[0];
        int32_t numS = (i == (nthreads-1)) ? 
            (relS->size() - i * numperthr[1]) : numperthr[1];

		vector<SAP_UINT> cpRelR(relR.begin() + (i * numperthr[0]), relR.begin + numR);
		args[i].relR = cpRelR;
        //args[i].relR = relR->tuples + i * numperthr[0];
        args[i].tmpR = tmpRelR;
        args[i].histR = histR;

		vector<SAP_UINT> cpRelS(relS.begin() + (i * numperthr[0]), relS.begin + numS);
		args[i].relS = cpRelS;
        //args[i].relS = relS->tuples + i * numperthr[1];
        args[i].tmpS = tmpRelS;
        args[i].histS = histS;

        args[i].totalR = relR->size();
        args[i].totalS = relS->size();

        args[i].my_tid = i;
        args[i].part_queue = part_queue;
        args[i].join_queue = join_queue;

        args[i].skew_queue = skew_queue;
        args[i].skewtask   = &skewtask;

        args[i].barrier = &barrier;
        args[i].nthreads = nthreads;

        rv = pthread_create(&tid[i], &attr, prj_thread, (void*)&args[i]);
        //if (rv){
        //    printf("[ERROR] return code from pthread_create() is %d\n", rv);
        //    exit(-1);
        //}
    }

    /* wait for threads to finish */
    for(i = 0; i < nthreads; i++){
        pthread_join(tid[i], NULL);
        result += args[i].result;
    }

	/* #define ABSDIFF(X,Y) (((X) > (Y)) ? ((X)-(Y)) : ((Y)-(X))) */
    //fprintf(stdout, "TID JTASKS T1.1 T1.1-IDLE T1.2 T1.2-IDLE "\
    //        "T3 T3-IDLE T4 T4-IDLE T5 T5-IDLE\n");
    //for(i = 0; i < nthreads; i++){
    //    synctimer_t * glob = args[0].globaltimer;
    //    synctimer_t * local = & args[i].localtimer;
    //    fprintf(stdout,
    //            "%d %d %llu %llu %llu %llu %llu %llu %llu %llu "\
    //            "%llu %llu\n",
    //            (i+1), args[i].parts_processed, local->sync1[0], 
    //            glob->sync1[0] - local->sync1[0], 
    //            local->sync1[1] - glob->sync1[0],
    //            glob->sync1[1] - local->sync1[1],
    //            local->sync3 - glob->sync1[1],
    //            glob->sync3 - local->sync3,
    //            local->sync4 - glob->sync3,
    //            glob->sync4 - local->sync4,
    //            local->finish_time - glob->sync4,
    //            glob->finish_time - local->finish_time);
    //}

    /* clean up */
    for(i = 0; i < nthreads; i++) {
        free(histR[i]);
        free(histS[i]);
    }
    free(histR);
    free(histS);
    task_queue_free(part_queue);
    task_queue_free(join_queue);
    
	task_queue_free(skew_queue);
    
	free(tmpRelR);
    free(tmpRelS);

    return result;
}
Esempio n. 18
0
static void time_strcpy (uword iter)
{
  u8 * s, * d;
  void * s_orig, * d_orig;
  uword size = g_bytes;
  uword i;
  f64 time[2];
  u8 c = 0x66;

  if (iter == 0 || size == 0)
    return;
  
  size &= ~((1 << 6) - 1);

  if (g_align != 0)
    {
      d = alloc_aligned (size, g_align, &d_orig);
      s = alloc_aligned (size, g_align, &s_orig);
    }
  else
    {
      d = alloc_unaligned (size, 1, &d_orig);
      s = alloc_unaligned (size, 3, &s_orig);
    }

  memset (d, 0, size);
  memset (s, 0, size);
  memset (s, c, size - 1);

#define _(func)								\
  time[0] = unix_usage_now ();						\
  for (i = 0; i < iter; i++)						\
    func (s);								\
  time[1] = unix_usage_now ();						\
									\
  fformat (stdout, "%-8.8s: %f secs.\n", # func, time[1] - time[0]);	\
  VERBOSE3 ("%U\n", format_hex_bytes, s, size);

  _ (strlen8);
  _ (kstrlen);
  _ (strlen);

#undef _

#define _(func)								\
  time[0] = unix_usage_now ();						\
  for (i = 0; i < iter; i++)						\
    func (d, s);							\
  time[1] = unix_usage_now ();						\
									\
  fformat (stdout, "%-8.8s: %f secs.\n", # func, time[1] - time[0]);	\
  VERBOSE3 ("%U\n", format_hex_bytes, s, size);

  _ (strcpy8);
  _ (alt_strcpy8);
  _ (kstrcpy);
  //_ (strcmp8);
  _ (strcpy);

#undef _

#define _(func)								\
  time[0] = unix_usage_now ();						\
  for (i = 0; i < iter; i++)						\
    func (d, s, size);							\
  time[1] = unix_usage_now ();						\
									\
  fformat (stdout, "%-8.8s: %f secs.\n", # func, time[1] - time[0]);	\
  VERBOSE3 ("%U\n", format_hex_bytes, s, size);

  //_ (strncpy8);
  //_ (strncpy);
  //_ (strncmp8);
  //_ (strncmp);

#undef _

  clib_mem_free_safe (d_orig);
  clib_mem_free_safe (s_orig);
}
Esempio n. 19
0
void
aio_loop_init(void)
{
  extern void aio_sock_purge_counts_init();
  int size;
  unsigned int all_mask;

  /* create space for 4 events per fd -- this is plenty big */
  completions_max = max_fds * 4;

  /* allocate space for get event completion events */
  size = completions_max * sizeof(compl_evt_t);
  completions = (compl_evt_t *) alloc_aligned(cache_line_size, size,
    ALLOC_MALLOC, "aio_loop_init: (completions)");
  printf("aio_loop_init: completions has %d entries and used %d bytes\n",
    completions_max, size);

  /* initialize the array */
  memset(completions, 0, size);

  printf("aio_loop_init: aio_complq_count = %d\n", options.aio_complq_count);

  switch (options.aio_complq_count) {

    case 1:
      /* TODO: figure out how to size these completion queues 
       * For 3 queues we used max_fds for each so now make this 3 x max_fds 
       * now make them equal to the maximum number of open fds
       */
      size = max_fds * 3;
      all_mask = SOCK_ACCEPT_MASK | SOCK_READ_MASK |
        SOCK_WRITE_MASK | SOCK_CLOSE_MASK;

      PRINT_TIME(NOFD, &tnow, &tprev, "aio_init: creating ONE "
        "completion queue");
      PRINT_TIME(NOFD, &tnow, &tprev, "aio_init: size = %d type = 0x%x",
        size, all_mask);

      all_cq = aio_sock_create_compl_q(size, all_mask);
      complqs[complq_count++] = all_cq;

      /* TODO: ensure that this return value is possible */
      if (all_cq < 0) {
        printf("aio_loop_init: aio_sock_create_compl_q failed with "
          "return = %d errno = %d\n", all_cq, errno);
        exit(1);
      }
      break;

    case 3:
      /* TODO: figure out how to size this completion queue */
      /* For now make it equal to the maximum number of open fds */
      /* size = options.accept_compl_qlen */
      size = max_fds;

      PRINT_TIME(NOFD, &tnow, &tprev, "aio_init: creating accept "
        "completion queue");
      PRINT_TIME(NOFD, &tnow, &tprev, "aio_init: size = %d type = 0x%x",
        size, SOCK_ACCEPT_MASK);
      accept_cq = aio_sock_create_compl_q(size, SOCK_ACCEPT_MASK);
      complqs[complq_count++] = accept_cq;

      /* TODO: ensure that this return value is possible */
      if (accept_cq < 0) {
        printf("aio_loop_init: aio_sock_create_compl_q failed with "
          "return = %d errno = %d\n", accept_cq, errno);
        exit(1);
      }

      /* TODO: figure out how to size these completion queues */
      /* For now make them equal to the maximum number of open fds */
      /* size = options.read_compl_qlen */
      size = max_fds;

      PRINT_TIME(NOFD, &tnow, &tprev, "aio_init: creating read "
        "completion queue");
      PRINT_TIME(NOFD, &tnow, &tprev, "aio_init: size = %d type = 0x%x",
        size, SOCK_READ_MASK);
      read_cq = aio_sock_create_compl_q(size, SOCK_READ_MASK);
      complqs[complq_count++] = read_cq;

      /* TODO: ensure that this return value is possible */
      if (read_cq < 0) {
        printf("aio_loop_init: aio_sock_create_compl_q failed with "
          "return = %d errno = %d\n", read_cq, errno);
        exit(1);
      }

      /* TODO: figure out how to size these completion queues */
      /* For now make them equal to the maximum number of open fds */
      /* size = options.read_compl_qlen */
      size = max_fds;

      PRINT_TIME(NOFD, &tnow, &tprev, "aio_init: creating write "
        "completion queue");
      PRINT_TIME(NOFD, &tnow, &tprev, "aio_init: size = %d type = 0x%x",
        size, SOCK_WRITE_MASK);
      write_cq = aio_sock_create_compl_q(size, SOCK_WRITE_MASK);
      complqs[complq_count++] = write_cq;

      /* TODO: ensure that this return value is possible */
      if (write_cq < 0) {
        printf("aio_loop_init: aio_sock_create_compl_q failed with "
          "return = %d errno = %d\n", write_cq, errno);
        exit(1);
      }
      break;

    default:
      printf("aio_loop_init: Specified completion queue count = %d "
        "not implemented yet\n", options.aio_complq_count);
      exit(1);
      break;
  }

  printf("aio_loop_init: read_cq = %d write_cq = %d "
    "accept_cq = %d all_cq = %d\n", read_cq, write_cq, accept_cq, all_cq);

  interest_set_init(DECLARE_WITH_AIO);

  aio_sock_purge_counts_init();
}