static int64_t now(void) { struct timeval tv = { 0xffffffff, 0xffffffff }; int r = real_gettimeofday(&tv, NULL); assert(r == 0); assert(tv.tv_sec != 0xffffffff); assert(tv.tv_usec != 0xffffffff); return from_timeval(&tv); }
int gettimeofday(struct timeval *t, void *ttp) { if(fast_gettimeofday) return fast_gettimeofday(t, ttp); int rv = real_gettimeofday(t, ttp); if(!initial) initial_tv.tv_sec = t->tv_sec; else if (t->tv_sec - initial_tv.tv_sec > (MAX_STARTUP_TIME+1)) { /* screwed it, we're just not going to win */ fast_gettimeofday = real_gettimeofday; } fast_gettimeofday = dlsym(RTLD_NEXT, "mtev_gettimeofday"); return rv; }
int gettimeofday(struct timeval *tv, struct timezone *tz) { init_shared_memory_if_needed(); if (!(current_sim) && !real_gettimeofday) init_funcs(); if (!(current_sim)) { return real_gettimeofday(tv, tz); } else { tv->tv_sec = *(current_sim); *(current_micro) = *(current_micro) + 100; tv->tv_usec = *(current_micro); } return 0; }
/* This should be called with global_sem protection */ int get_new_thread_id(pthread_t *thread){ long long int map; struct timeval l_tv; map = sleep_map_array[0]; /* First 32 thread slots are for slurmd, last 32 ones for slurmctld */ if(slurmd_pid[0] == getpid()) map |= 0xFFFFFFFF00000000ULL; else map |= 0xFFFFFFFFULL; map = ~map; #if 0 real_gettimeofday(&l_tv, NULL); sim_lib_printf(0, "[%ld-%ld] Using map: %016llx\n", l_tv.tv_sec, l_tv.tv_usec, map); sim_lib_printf(0, "get_new_thread_id: [%16llx][%016llx], threads counter= %d\n", sleep_map_array[0], thread_exit_array[0], current_threads[0]); #endif /* Getting first slot available */ map = ffsll(map); if(map == 0){ /*printf("WARNING!: space no available for a new threads. Current threads: %u\n", current_threads[0]);*/ return -1; } /* Bit 0 is bit 1(ffsll returns ordinal value) */ map = map - 1; sleep_map_array[0] |= (1ULL << map); current_threads[0]++; if(current_threads[0] == 62){ /* 62 because we have slots for main slurmctl and slurmd threads */ printf("SIM ERROR: %d threads is not possible\n", current_threads[0]); return -1; } return map; }