bool cellMgr_initForMapChannel(mapChannel_t *mapChannel) { hashTable_init(&mapChannel->mapCellInfo.ht_cells, 128); mapChannel->mapCellInfo.loadedCellCount = 0; mapChannel->mapCellInfo.loadedCellLimit = 128; mapChannel->mapCellInfo.loadedCellList = (mapCell_t**)malloc(sizeof(mapCell_t*)*mapChannel->mapCellInfo.loadedCellLimit); mapChannel->mapCellInfo.time_updateVisibility = GetTickCount()+1000; return true; }
/* * Initializes the global message queue environment * Call this before any other msgQueue_.. function */ void msgQueue_init() { #ifdef _WIN32 InitializeCriticalSection(&messageQueueEnvironment.criticalSection); #else pthread_mutex_init(&messageQueueEnvironment.criticalSection, NULL); #endif hashTable_init(&messageQueueEnvironment.ht_msgQueues, 4); messageQueueEnvironment.uniqueNameCounter = 0x70000000; }
// will always return a valid cell if within valid range conditions mapCell_t* cellMgr_getCell(mapChannel_t *mapChannel, int x, int z) { unsigned cellSeed = (x&0xFFFF) | (z<<16); mapCell_t *mapCell = (mapCell_t*)hashTable_get(&mapChannel->mapCellInfo.ht_cells, cellSeed); if( mapCell == NULL ) { // create cell mapCell = (mapCell_t*)malloc(sizeof(mapCell_t)); // init cell hashTable_init(&mapCell->ht_playerList, 8); hashTable_init(&mapCell->ht_playerNotifyList, 8); hashTable_init(&mapCell->ht_objectList, 8); hashTable_init(&mapCell->ht_npcList, 8); hashTable_init(&mapCell->ht_creatureList, 8); if( mapChannel->mapCellInfo.loadedCellCount == mapChannel->mapCellInfo.loadedCellLimit ) { // enlarge buffer int newLimit = mapChannel->mapCellInfo.loadedCellLimit * 2; mapCell_t **newLoadedCellList = (mapCell_t**)malloc(sizeof(mapCell_t*) * newLimit); for(int i=0; i<mapChannel->mapCellInfo.loadedCellLimit; i++) newLoadedCellList[i] = mapChannel->mapCellInfo.loadedCellList[i]; free(mapChannel->mapCellInfo.loadedCellList); mapChannel->mapCellInfo.loadedCellList = newLoadedCellList; mapChannel->mapCellInfo.loadedCellLimit = newLimit; if( newLoadedCellList == NULL ) { printf("ERROR in 'cellMgr_getCell'\n"); Sleep(1000*30); ExitThread(-1); } } // save cell mapChannel->mapCellInfo.loadedCellList[mapChannel->mapCellInfo.loadedCellCount] = mapCell; mapChannel->mapCellInfo.loadedCellCount++; // register cell hashTable_set(&mapChannel->mapCellInfo.ht_cells, cellSeed, mapCell); return mapCell; } return mapCell; }
void entityMgr_init() { InitializeCriticalSection(&csEntityMgr); hashTable_init(&ht_entityTable, 512); // get current npc unsigned long long npceid = dataInterface_NPC_getLastNPCEntityID(); if( npceid < ENTITYID_BASE ) npceid = ENTITYID_BASE; // ceid_npc npceid = (npceid - ENTITYID_BASE) / 16; npceid++; //npceid += 16; //npceid &= ~0xF; //npceid += ENTITYTYPE_NPC; ceid_npc = npceid; }
void likwid_markerInit(void) { int i; int verbosity; bstring bThreadStr; bstring bEventStr; struct bstrList* threadTokens; struct bstrList* eventStrings; char* modeStr = getenv("LIKWID_MODE"); char* eventStr = getenv("LIKWID_EVENTS"); char* cThreadStr = getenv("LIKWID_THREADS"); char* filepath = getenv("LIKWID_FILEPATH"); /* Dirty hack to avoid nonnull warnings */ int (*ownatoi)(const char*); ownatoi = &atoi; if ((modeStr != NULL) && (filepath != NULL) && (eventStr != NULL) && (cThreadStr != NULL)) { likwid_init = 1; } else if (likwid_init == 0) { fprintf(stderr, "Cannot initalize LIKWID marker API, environment variables are not set\n"); fprintf(stderr, "You have to set the -m commandline switch for likwid-perfctr\n"); return; } else { return; } if (!lock_check()) { fprintf(stderr,"Access to performance counters is locked.\n"); exit(EXIT_FAILURE); } topology_init(); numa_init(); affinity_init(); hashTable_init(); for(int i=0; i<MAX_NUM_NODES; i++) socket_lock[i] = LOCK_INIT; HPMmode(atoi(modeStr)); if (getenv("LIKWID_DEBUG") != NULL) { perfmon_verbosity = atoi(getenv("LIKWID_DEBUG")); verbosity = perfmon_verbosity; } bThreadStr = bfromcstr(cThreadStr); threadTokens = bstrListCreate(); threadTokens = bsplit(bThreadStr,','); num_cpus = threadTokens->qty; for (i=0; i<num_cpus; i++) { threads2Cpu[i] = ownatoi(bdata(threadTokens->entry[i])); } bdestroy(bThreadStr); bstrListDestroy(threadTokens); if (getenv("LIKWID_PIN") != NULL) { likwid_pinThread(threads2Cpu[0]); if (getenv("OMP_NUM_THREADS") != NULL) { if (ownatoi(getenv("OMP_NUM_THREADS")) > num_cpus) { use_locks = 1; } } if (getenv("CILK_NWORKERS") != NULL) { if (ownatoi(getenv("CILK_NWORKERS")) > num_cpus) { use_locks = 1; } } } i = perfmon_init(num_cpus, threads2Cpu); if (i<0) { fprintf(stderr,"Failed to initialize LIKWID perfmon library.\n"); return; } bEventStr = bfromcstr(eventStr); eventStrings = bstrListCreate(); eventStrings = bsplit(bEventStr,'|'); numberOfGroups = eventStrings->qty; groups = malloc(numberOfGroups * sizeof(int)); if (!groups) { fprintf(stderr,"Cannot allocate space for group handling.\n"); bstrListDestroy(eventStrings); exit(EXIT_FAILURE); } for (i=0; i<eventStrings->qty; i++) { groups[i] = perfmon_addEventSet(bdata(eventStrings->entry[i])); } bstrListDestroy(eventStrings); bdestroy(bEventStr); for (i=0; i<num_cpus; i++) { hashTable_initThread(threads2Cpu[i]); for(int j=0; j<groupSet->groups[groups[0]].numberOfEvents;j++) { groupSet->groups[groups[0]].events[j].threadCounter[i].init = TRUE; } } groupSet->activeGroup = 0; }
void likwid_markerInit(void) { int cpuId = likwid_getProcessorId(); char* modeStr = getenv("LIKWID_MODE"); char* maskStr = getenv("LIKWID_MASK"); if ((modeStr != NULL) && (maskStr != NULL)) { likwid_init = 1; } else { return; } if (!lock_check()) { fprintf(stderr,"Access to performance counters is locked.\n"); exit(EXIT_FAILURE); } cpuid_init(); numa_init(); affinity_init(); timer_init(); hashTable_init(); for(int i=0; i<MAX_NUM_THREADS; i++) thread_socketFD[i] = -1; for(int i=0; i<MAX_NUM_NODES; i++) socket_lock[i] = LOCK_INIT; accessClient_mode = atoi(modeStr); str2BitMask(maskStr, &counterMask); if (accessClient_mode != DAEMON_AM_DIRECT) { accessClient_init(&thread_socketFD[cpuId]); } msr_init(thread_socketFD[cpuId]); thermal_init(cpuId); switch ( cpuid_info.family ) { case P6_FAMILY: switch ( cpuid_info.model ) { case PENTIUM_M_BANIAS: case PENTIUM_M_DOTHAN: perfmon_counter_map = pm_counter_map; perfmon_numCounters = NUM_COUNTERS_PM; perfmon_numCountersCore = NUM_COUNTERS_CORE_PM; break; case ATOM_45: case ATOM_32: case ATOM_22: case ATOM: perfmon_counter_map = core2_counter_map; perfmon_numCounters = NUM_COUNTERS_CORE2; perfmon_numCountersCore = NUM_COUNTERS_CORE_CORE2; break; case CORE_DUO: ERROR_PLAIN_PRINT(Unsupported Processor); break; case XEON_MP: case CORE2_65: case CORE2_45: perfmon_counter_map = core2_counter_map; perfmon_numCounters = NUM_COUNTERS_CORE2; perfmon_numCountersCore = NUM_COUNTERS_CORE_CORE2; break; case NEHALEM_EX: case WESTMERE_EX: perfmon_counter_map = westmereEX_counter_map; perfmon_numCounters = NUM_COUNTERS_WESTMEREEX; perfmon_numCountersCore = NUM_COUNTERS_CORE_WESTMEREEX; perfmon_numCountersUncore = NUM_COUNTERS_UNCORE_WESTMEREEX; break; case NEHALEM_BLOOMFIELD: case NEHALEM_LYNNFIELD: case NEHALEM_WESTMERE_M: case NEHALEM_WESTMERE: perfmon_counter_map = nehalem_counter_map; perfmon_numCounters = NUM_COUNTERS_NEHALEM; perfmon_numCountersCore = NUM_COUNTERS_CORE_NEHALEM; perfmon_numCountersUncore = NUM_COUNTERS_UNCORE_NEHALEM; break; case IVYBRIDGE: case IVYBRIDGE_EP: { int socket_fd = thread_socketFD[cpuId]; hasPCICounters = 1; power_init(0); /* FIXME Static coreId is dangerous */ pci_init(socket_fd); perfmon_counter_map = ivybridge_counter_map; perfmon_numCounters = NUM_COUNTERS_IVYBRIDGE; perfmon_numCountersCore = NUM_COUNTERS_CORE_IVYBRIDGE; perfmon_numCountersUncore = NUM_COUNTERS_UNCORE_IVYBRIDGE; } break; case HASWELL: case HASWELL_EX: case HASWELL_M1: case HASWELL_M2: power_init(0); /* FIXME Static coreId is dangerous */ perfmon_counter_map = haswell_counter_map; perfmon_numCounters = NUM_COUNTERS_HASWELL; perfmon_numCountersCore = NUM_COUNTERS_CORE_HASWELL; break; case SANDYBRIDGE: case SANDYBRIDGE_EP: { int socket_fd = thread_socketFD[cpuId]; hasPCICounters = 1; power_init(0); /* FIXME Static coreId is dangerous */ pci_init(socket_fd); perfmon_counter_map = sandybridge_counter_map; perfmon_numCounters = NUM_COUNTERS_SANDYBRIDGE; perfmon_numCountersCore = NUM_COUNTERS_CORE_SANDYBRIDGE; perfmon_numCountersUncore = NUM_COUNTERS_UNCORE_SANDYBRIDGE; } break; default: ERROR_PLAIN_PRINT(Unsupported Processor); break; } break; case MIC_FAMILY: switch ( cpuid_info.model ) { case XEON_PHI: perfmon_counter_map = phi_counter_map; perfmon_numCounters = NUM_COUNTERS_PHI; perfmon_numCountersCore = NUM_COUNTERS_CORE_PHI; break; default: ERROR_PLAIN_PRINT(Unsupported Processor); break; } break; case K8_FAMILY: perfmon_counter_map = k10_counter_map; perfmon_numCounters = NUM_COUNTERS_K10; perfmon_numCountersCore = NUM_COUNTERS_CORE_K10; break; case K10_FAMILY: perfmon_counter_map = k10_counter_map; perfmon_numCounters = NUM_COUNTERS_K10; perfmon_numCountersCore = NUM_COUNTERS_CORE_K10; break; case K15_FAMILY: perfmon_counter_map = interlagos_counter_map; perfmon_numCounters = NUM_COUNTERS_INTERLAGOS; perfmon_numCountersCore = NUM_COUNTERS_CORE_INTERLAGOS; break; case K16_FAMILY: perfmon_counter_map = kabini_counter_map; perfmon_numCounters = NUM_COUNTERS_KABINI; perfmon_numCountersCore = NUM_COUNTERS_CORE_KABINI; break; default: ERROR_PLAIN_PRINT(Unsupported Processor); break; } }
void likwid_markerInit(void) { int i; int verbosity; int setinit = 0; bstring bThreadStr; bstring bEventStr; struct bstrList* threadTokens; struct bstrList* eventStrings; char* modeStr = getenv("LIKWID_MODE"); char* eventStr = getenv("LIKWID_EVENTS"); char* cThreadStr = getenv("LIKWID_THREADS"); char* filepath = getenv("LIKWID_FILEPATH"); char* perfpid = getenv("LIKWID_PERF_EXECPID"); char execpid[20]; /* Dirty hack to avoid nonnull warnings */ int (*ownatoi)(const char*); ownatoi = &atoi; if ((modeStr != NULL) && (filepath != NULL) && (eventStr != NULL) && (cThreadStr != NULL) && likwid_init == 0) { setinit = 1; } else if (likwid_init == 0) { fprintf(stderr, "Running without Marker API. Activate Marker API with -m on commandline.\n"); return; } else { return; } if (!lock_check()) { fprintf(stderr,"Access to performance counters is locked.\n"); exit(EXIT_FAILURE); } topology_init(); numa_init(); affinity_init(); hashTable_init(); //#ifndef LIKWID_USE_PERFEVENT HPMmode(atoi(modeStr)); //#endif if (getenv("LIKWID_DEBUG") != NULL) { perfmon_verbosity = atoi(getenv("LIKWID_DEBUG")); verbosity = perfmon_verbosity; } bThreadStr = bfromcstr(cThreadStr); threadTokens = bsplit(bThreadStr,','); num_cpus = threadTokens->qty; for (i=0; i<num_cpus; i++) { threads2Cpu[i] = ownatoi(bdata(threadTokens->entry[i])); } bdestroy(bThreadStr); bstrListDestroy(threadTokens); if (getenv("LIKWID_PIN") != NULL) { likwid_pinThread(threads2Cpu[0]); if (getenv("OMP_NUM_THREADS") != NULL) { if (ownatoi(getenv("OMP_NUM_THREADS")) > num_cpus) { use_locks = 1; } } if (getenv("CILK_NWORKERS") != NULL) { if (ownatoi(getenv("CILK_NWORKERS")) > num_cpus) { use_locks = 1; } } } #ifdef LIKWID_USE_PERFEVENT if (perfpid != NULL) { snprintf(execpid, 19, "%d", getpid()); setenv("LIKWID_PERF_PID", execpid, 1); char* perfflags = getenv("LIKWID_PERF_FLAGS"); if (perfflags) { setenv("LIKWID_PERF_FLAGS", getenv("LIKWID_PERF_FLAGS"), 1); } } #endif i = perfmon_init(num_cpus, threads2Cpu); if (i<0) { //fprintf(stderr,"Failed to initialize LIKWID perfmon library.\n"); return; } bEventStr = bfromcstr(eventStr); eventStrings = bsplit(bEventStr,'|'); numberOfGroups = eventStrings->qty; groups = malloc(numberOfGroups * sizeof(int)); if (!groups) { fprintf(stderr,"Cannot allocate space for group handling.\n"); bstrListDestroy(eventStrings); exit(EXIT_FAILURE); } for (i=0; i<eventStrings->qty; i++) { groups[i] = perfmon_addEventSet(bdata(eventStrings->entry[i])); } bstrListDestroy(eventStrings); bdestroy(bEventStr); for (i=0; i<num_cpus; i++) { hashTable_initThread(threads2Cpu[i]); for(int j=0; j<groupSet->groups[groups[0]].numberOfEvents;j++) { groupSet->groups[groups[0]].events[j].threadCounter[i].init = TRUE; groupSet->groups[groups[0]].state = STATE_START; } } if (setinit) { likwid_init = 1; } threads2Pthread[registered_cpus] = pthread_self(); registered_cpus++; groupSet->activeGroup = 0; perfmon_setupCounters(groupSet->activeGroup); perfmon_startCounters(); }
int interprete_init () { hashTable_init (&tableSymboles, sdbm, cmp, NULL, symbole_destroy); }