/* * Called once (from main) to initialize STM infrastructure. */ _CALLCONV void stm_init(void) { #if CM == CM_MODULAR char *s; #endif /* CM == CM_MODULAR */ #ifdef SIGNAL_HANDLER struct sigaction act; #endif /* SIGNAL_HANDLER */ PRINT_DEBUG("==> stm_init()\n"); if (_tinystm.initialized) return; PRINT_DEBUG("\tsizeof(word)=%d\n", (int)sizeof(stm_word_t)); PRINT_DEBUG("\tVERSION_MAX=0x%lx\n", (unsigned long)VERSION_MAX); COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(void *)); COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(atomic_t)); #ifdef EPOCH_GC gc_init(stm_get_clock); #endif /* EPOCH_GC */ #if CM == CM_MODULAR s = getenv(VR_THRESHOLD); if (s != NULL) _tinystm.vr_threshold = (int)strtol(s, NULL, 10); else _tinystm.vr_threshold = VR_THRESHOLD_DEFAULT; PRINT_DEBUG("\tVR_THRESHOLD=%d\n", _tinystm.vr_threshold); #endif /* CM == CM_MODULAR */ /* Set locks and clock but should be already to 0 */ memset((void *)_tinystm.locks, 0, LOCK_ARRAY_SIZE * sizeof(stm_word_t)); CLOCK = 0; stm_quiesce_init(); tls_init(); #ifdef SIGNAL_HANDLER if (getenv(NO_SIGNAL_HANDLER) == NULL) { /* Catch signals for non-faulting load */ act.sa_handler = signal_catcher; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGBUS, &act, NULL) < 0 || sigaction(SIGSEGV, &act, NULL) < 0) { perror("sigaction"); exit(1); } } #endif /* SIGNAL_HANDLER */ _tinystm.initialized = 1; }
/* * Called once (from main) to initialize STM infrastructure. */ void stm_init() { struct sigaction act; PRINT_DEBUG("==> stm_init()\n"); if (initialized) return; PRINT_DEBUG("\tsizeof(word)=%d\n", (int)sizeof(stm_word_t)); PRINT_DEBUG("\tVERSION_MAX=0x%lx\n", (unsigned long)VERSION_MAX); COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(void *)); COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(atomic_t)); memset((void *)locks, 0, LOCK_ARRAY_SIZE * sizeof(stm_word_t)); CLOCK = 0; stm_quiesce_init(); if (getenv(NO_SIGNAL_HANDLER) == NULL) { /* Catch signals for non-faulting load */ act.sa_handler = signal_catcher; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGBUS, &act, NULL) < 0 || sigaction(SIGSEGV, &act, NULL) < 0) { perror("sigaction"); exit(1); } } initialized = 1; }
void stm_init(int threads) { int max_tx_per_tuning_cycle; max_concurrent_threads = threads; FILE* fid; if ((fid = fopen("mcats_conf.txt", "r")) == NULL) { printf("\nError opening F2C2 configuration file.\n"); exit(1); } if (fscanf(fid, "SCHEDULING_POLICY=%d TX_PER_CYCLE=%d ACTIVE_THREAD=%d", &scheduling_policy, &max_tx_per_tuning_cycle, &active_threads)!=3) { printf("\nThe number of input parameters of the F2C2 configuration file does not match the number of required parameters.\n"); exit(1); } tx_per_tuning_cycle = max_tx_per_tuning_cycle; last_tuning_time=0; last_throughput=0; direction=1; // 1 = direction up, 0 = direction down active_threads= (int)(max_concurrent_threads/2); key_t sem_key = 1234; /* key to pass to semget() */ int semflg = IPC_CREAT | 0666; /* semflg to pass to semget() */ int nsems = threads; /* number of sems to pass to semget() */ if ((semid = semget(sem_key, nsems, semflg)) == -1) { printf("\nSemget failed"); exit(1); } else { //fprintf(stderr, "semget: semget succeeded: semid =\%d\n", semid); } #else void stm_init() { #endif /* ! STM_F2C2 */ #if CM == CM_MODULAR char *s; #endif /* CM == CM_MODULAR */ #ifdef SIGNAL_HANDLER struct sigaction act; #endif /* SIGNAL_HANDLER */ PRINT_DEBUG("==> stm_init()\n"); if (_tinystm.initialized) return; PRINT_DEBUG("\tsizeof(word)=%d\n", (int)sizeof(stm_word_t)); PRINT_DEBUG("\tVERSION_MAX=0x%lx\n", (unsigned long)VERSION_MAX); COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(void *)); COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(atomic_t)); #ifdef EPOCH_GC gc_init(stm_get_clock); #endif /* EPOCH_GC */ #if CM == CM_MODULAR s = getenv(VR_THRESHOLD); if (s != NULL) _tinystm.vr_threshold = (int)strtol(s, NULL, 10); else _tinystm.vr_threshold = VR_THRESHOLD_DEFAULT; PRINT_DEBUG("\tVR_THRESHOLD=%d\n", _tinystm.vr_threshold); #endif /* CM == CM_MODULAR */ /* Set locks and clock but should be already to 0 */ memset((void *)_tinystm.locks, 0, LOCK_ARRAY_SIZE * sizeof(stm_word_t)); #ifdef INVISIBLE_TRACKING memset((void* )_tinystm.last_id_tx_class,-1,LOCK_ARRAY_SIZE * sizeof(stm_word_t)); #endif CLOCK = 0; stm_quiesce_init(); tls_init(); #ifdef SIGNAL_HANDLER if (getenv(NO_SIGNAL_HANDLER) == NULL) { /* Catch signals for non-faulting load */ act.sa_handler = signal_catcher; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGBUS, &act, NULL) < 0 || sigaction(SIGSEGV, &act, NULL) < 0) { perror("sigaction"); exit(1); } } #endif /* SIGNAL_HANDLER */ _tinystm.initialized = 1; }
void stm_init(int threads) { int max_tx_per_tuning_cycle; max_concurrent_threads = threads; FILE* fid; if ((fid = fopen("mcats_conf.txt", "r")) == NULL) { printf("\nError opening MCATS configuration file.\n"); exit(1); } if (fscanf(fid, "TX_PER_CYCLE=%d INITIAL_MAX_ADMITTED_TX=%d", &max_tx_per_tuning_cycle, &max_allowed_running_transactions)!=2) { printf("\nThe number of input parameters of the MCATS configuration file does not match the number of required parameters.\n"); exit(1); } tx_per_tuning_cycle = max_tx_per_tuning_cycle / max_concurrent_threads; main_thread = current_collector_thread = 0; running_transactions = 0; if (init_rapl() != 0) { printf("\nRAPL could not be initialized\n"); exit(1); } /* Set on conflict callback */ #else void stm_init() { #endif /* ! STM_MCATS */ #ifdef STM_SCA sca_saturating_threshold = 1; sca_serializing_lock = 0; #endif /* ! STM_SCA */ #if CM == CM_MODULAR char *s; #endif /* CM == CM_MODULAR */ #ifdef SIGNAL_HANDLER struct sigaction act; #endif /* SIGNAL_HANDLER */ PRINT_DEBUG("==> stm_init()\n"); if (_tinystm.initialized) return; PRINT_DEBUG("\tsizeof(word)=%d\n", (int)sizeof(stm_word_t)); PRINT_DEBUG("\tVERSION_MAX=0x%lx\n", (unsigned long)VERSION_MAX); COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(void *)); COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(atomic_t)); #ifdef EPOCH_GC gc_init(stm_get_clock); #endif /* EPOCH_GC */ #if CM == CM_MODULAR s = getenv(VR_THRESHOLD); if (s != NULL) _tinystm.vr_threshold = (int)strtol(s, NULL, 10); else _tinystm.vr_threshold = VR_THRESHOLD_DEFAULT; PRINT_DEBUG("\tVR_THRESHOLD=%d\n", _tinystm.vr_threshold); #endif /* CM == CM_MODULAR */ /* Set locks and clock but should be already to 0 */ memset((void *)_tinystm.locks, 0, LOCK_ARRAY_SIZE * sizeof(stm_word_t)); #ifdef INVISIBLE_TRACKING memset((void* )_tinystm.last_id_tx_class,-1,LOCK_ARRAY_SIZE * sizeof(stm_word_t)); #endif CLOCK = 0; stm_quiesce_init(); tls_init(); #ifdef SIGNAL_HANDLER if (getenv(NO_SIGNAL_HANDLER) == NULL) { /* Catch signals for non-faulting load */ act.sa_handler = signal_catcher; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGBUS, &act, NULL) < 0 || sigaction(SIGSEGV, &act, NULL) < 0) { perror("sigaction"); exit(1); } } #endif /* SIGNAL_HANDLER */ _tinystm.initialized = 1; }