Example #1
0
void initProfiling (void)
{
    // initialise our arena
    prof_arena = newArena();

    /* for the benefit of allocate()... */
    {
        nat n;
        for (n=0; n < n_capabilities; n++) {
            capabilities[n]->r.rCCCS = CCS_SYSTEM;
        }
    }

#ifdef THREADED_RTS
    initMutex(&ccs_mutex);
#endif

    /* Set up the log file, and dump the header and cost centre
     * information into it.
     */
    initProfilingLogFile();

    /* Register all the cost centres / stacks in the program
     * CC_MAIN gets link = 0, all others have non-zero link.
     */
    REGISTER_CC(CC_MAIN);
    REGISTER_CC(CC_SYSTEM);
    REGISTER_CC(CC_GC);
    REGISTER_CC(CC_OVERHEAD);
    REGISTER_CC(CC_DONT_CARE);
    REGISTER_CC(CC_PINNED);
    REGISTER_CC(CC_IDLE);

    REGISTER_CCS(CCS_SYSTEM);
    REGISTER_CCS(CCS_GC);
    REGISTER_CCS(CCS_OVERHEAD);
    REGISTER_CCS(CCS_DONT_CARE);
    REGISTER_CCS(CCS_PINNED);
    REGISTER_CCS(CCS_IDLE);
    REGISTER_CCS(CCS_MAIN);

    /* find all the registered cost centre stacks, and make them
     * children of CCS_MAIN.
     */
    ASSERT(CCS_LIST == CCS_MAIN);
    CCS_LIST = CCS_LIST->prevStack;
    CCS_MAIN->prevStack = NULL;
    CCS_MAIN->root = CCS_MAIN;
    ccsSetSelected(CCS_MAIN);

    initProfiling2();

    if (RtsFlags.CcFlags.doCostCentres) {
        initTimeProfiling();
    }

    if (RtsFlags.ProfFlags.doHeapProfile) {
        initHeapProfiling();
    }
}
Example #2
0
/* -----------------------------------------------------------------------------
 * Creates the first pool and initializes hashTable[].
 * Frees all pools if any.
 * -------------------------------------------------------------------------- */
void
initializeAllRetainerSet(void)
{
    int i;

    arena = newArena();

    for (i = 0; i < HASH_TABLE_SIZE; i++)
	hashTable[i] = NULL;
    nextId = 2;   // Initial value must be positive, 2 is MANY.
}
Example #3
0
int main(int argc, char **argv) {

  // 
  // Make sure we've been given a port to listen on.
  //
  if (argc != 2) {
    fprintf(stderr, "usage: %s <port>\n", argv[0]);
    exit(0);
  }
  
  arena_t *arena = newArena();
  int listener = initConnection(atoi(argv[1]));
  
  int clients = 0
  while (1) {
  	clients++;
  	
  //
  // Build a client's profile to send to a handler thread
  //
  client_t *client = (client_t *)malloc(sizeof(client_t));
  
  //
  // Accept a connection from a client, get a file descriptor for communicating
  // with the client
  //
  client->id = clients;
  int client = acceptClientOn(listener);
  }
  
  //
  // create a thread to handle the client
  //
  pthread_t tid;
  pthread_create(&tid,NULL,playSolitaire, (void *)client);

  unsigned long seed = 0;
  if (argc == 1) {
    struct timeval tp; 
    gettimeofday(&tp,NULL); 
    seed = tp.tv_sec;
  } else {
    seed = atol(argv[1]);
  }
  printf("Shuffling with seed %ld.\n",seed);
  srand48(seed);


  deck_t *deck = newDeck();
  shuffle(deck);
  playSolitaire(client);
}
Example #4
0
/* -----------------------------------------------------------------------------
 * Refreshes all pools for reuse and initializes hashTable[].
 * -------------------------------------------------------------------------- */
void
refreshAllRetainerSet(void)
{
#ifdef FIRST_APPROACH
    int i;

    // first approach: completely refresh
    arenaFree(arena);
    arena = newArena();

    for (i = 0; i < HASH_TABLE_SIZE; i++)
	hashTable[i] = NULL;
    nextId = 2;
#endif /* FIRST_APPROACH */
}
Example #5
0
void
initProfiling1 (void)
{
    // initialise our arena
    prof_arena = newArena();

    /* for the benefit of allocate()... */
    {
        nat n;
        for (n=0; n < n_capabilities; n++) {
            capabilities[n].r.rCCCS = CCS_SYSTEM;
        }
    }

#ifdef THREADED_RTS
    initMutex(&ccs_mutex);
#endif
}
Example #6
0
void playSolitaire(deck_t *deck) {

  // initialize
  arena_t *arena = newArena();
  deal_t *deal = newDeal(deck);

  play_t play;
  int status = SUCCESS;
  while (1) {
    putArena(arena);
    printf("\n");
    putDeal(deal);
    printf("\nEnter your play: ");
    getNextPlay(&play,deck);
    switch (play.type) {
    case ARENA_PLAY:
      // Play a card into the arena.
      status = makeArenaPlay(play.from,arena);
      break;
    case KING_PLAY:
      // Move a king card onto an empty lain stack.
      status = moveKingOntoFree(play.from,deal);
      break;
    case MOVE_PLAY:
      // Move a card (possibly with cards above it) onto some lain stack. 
      status = moveCardOntoAnother(play.from,play.onto);
      break;
    case DRAW_PLAY:
      // Draws the next card and puts it on top of the discard pile.
      status = pullFromDrawPile(deal);
      break;
    }
    
    if (status == SUCCESS) {
      printf("Done!\n");
    } else {
      printf("That play wasn't made.\n");
    } 

  }
}
Example #7
0
void
initProfiling1 (void)
{
  // initialise our arena
  prof_arena = newArena();

  /* for the benefit of allocate()... */
  CCCS = CCS_SYSTEM;
  
  /* Initialize counters for IDs */
  CC_ID  = 1;
  CCS_ID = 1;
  HP_ID  = 1;
  
  /* Initialize Declaration lists to NULL */
  CC_LIST  = NULL;
  CCS_LIST = NULL;

  /* Register all the cost centres / stacks in the program 
   * CC_MAIN gets link = 0, all others have non-zero link.
   */
  REGISTER_CC(CC_MAIN);
  REGISTER_CC(CC_SYSTEM);
  REGISTER_CC(CC_GC);
  REGISTER_CC(CC_OVERHEAD);
  REGISTER_CC(CC_SUBSUMED);
  REGISTER_CC(CC_DONT_CARE);
  REGISTER_CCS(CCS_MAIN);
  REGISTER_CCS(CCS_SYSTEM);
  REGISTER_CCS(CCS_GC);
  REGISTER_CCS(CCS_OVERHEAD);
  REGISTER_CCS(CCS_SUBSUMED);
  REGISTER_CCS(CCS_DONT_CARE);

  CCCS = CCS_OVERHEAD;

  /* cost centres are registered by the per-module 
   * initialisation code now... 
   */
}
Example #8
0
    void* MemoryPool::alloc(size_t size)
    {
        Arena* arena = nullptr;

        if (size < mArenaSize) {
            arena = mArenas;
            while (arena && arena->bytesLeft < size)
                arena = arena->next;
        }

        size_t arenaSize = mArenaSize;
        if (!arena) {
            arenaSize = std::max(size, arenaSize);
            arena = newArena(arenaSize);
            if (!arena)
                return nullptr;
        }

        void* ptr = reinterpret_cast<uint8_t*>(arena + 1) + (arenaSize - arena->bytesLeft);
        arena->bytesLeft -= size;

        return ptr;
    }