static INLINE stm_tx_t * abi_init_thread(void) { stm_tx_t *tx = tls_get_tx(); if (tx == NULL) { /* Make sure that the main initilization is done */ if (ATOMIC_LOAD(&global_abi.status) != ABI_INITIALIZED) _ITM_initializeProcess(); //t->thread_id = (int)ATOMIC_FETCH_INC_FULL(&global_abi.thread_counter); tx = stm_init_thread(); } return tx; }
static INLINE stm_tx_t * abi_init_thread(void) { stm_tx_t *tx = tls_get_tx(); if (tx == NULL) { /* Make sure that the main initilization is done */ if (ATOMIC_LOAD(&global_abi.status) != ABI_INITIALIZED) _ITM_initializeProcess(); //t->thread_id = (int)ATOMIC_FETCH_INC_FULL(&global_abi.thread_counter); tx = stm_init_thread(); #ifdef STACK_CHECK get_stack_attr(&t->stack_addr_low, &t->stack_addr_high); #endif /* STACK_CHECK */ } return tx; }
_CALLCONV stm_tx_t *stm_pre_init_thread(int id){ stm_tx_t *tx; tx=stm_init_thread(); tx->thread_identifier=id; if (tx->thread_identifier<active_threads) { tx->thread_gate=0; } else { tx->thread_gate=1; if (scheduling_policy==2) { struct sembuf *sop = (struct sembuf *) malloc(sizeof(struct sembuf)); sop[0].sem_num = tx->thread_identifier; sop[0].sem_op = 1; /* increment semaphore to become one */ sop[0].sem_flg = SEM_UNDO | IPC_NOWAIT; /* take off semaphore */ if (semop(semid, sop, 1) == -1) { printf("Semop failed on thread %i on stm_pre_init_thread",tx->thread_identifier); exit(0); } } } //printf("\nThread %i thread_gate % i", tx->thread_identifier, tx->thread_gate); tx->committed_transactions=0; set_affinity(id); char filename[512]; int cpu_id=sched_getcpu(); sprintf(filename, "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_setspeed",cpu_id); //printf("Filename: %s", filename); tx->scaling_setspeed_fd=open(filename, O_WRONLY); if(tx->scaling_setspeed_fd==-1){ printf("\nError opening file %s \n", filename); exit(1); } char target_freq[]="2000000"; write(tx->scaling_setspeed_fd, &target_freq, sizeof(target_freq)); return tx; }
void *count(void *ptr) { long i, max = MAX_COUNT/NUM_THREADS; int tid = ((struct tdata *) ptr)->tid; int c; stm_init_thread(); for (i=0; i < max; i++) { TM_START(0, 0); c = stm_load_int(&counter); if (i % 10 == 0) { c++; stm_store_int(&counter, c); } TM_COMMIT; } printf("End %d counter: %d\n", tid, counter); stm_exit_thread(); }
int main(int argc, char **argv) { /* Init STM */ stm_init(); mod_mem_init(0); /* Create transaction */ stm_init_thread(); /* Testing */ test1load(1); test1load(0); testnload(1, 100); testnload(0, 100); testnloadnstore(100, 20); testnloadnstore(100, 20); /* Free transaction */ stm_exit_thread(); /* Cleanup STM */ stm_exit(); return 0; }
_CALLCONV stm_tx_t * stm_pre_init_thread(int id){ stm_tx_t *tx; tx=stm_init_thread(); printf("after stm_init_thread"); fflush(stdout); tx->total_tx_wasted_per_active_transactions=(stm_time_t*)malloc((max_concurrent_threads+1)*sizeof(stm_time_t)); tx->total_tx_committed_per_active_transactions=(long*)malloc((max_concurrent_threads+1)*sizeof(long)); tx->total_tx_useful_per_active_transactions = (stm_time_t *)malloc((max_concurrent_threads +1) * sizeof(stm_time_t)); tx->total_conflict_per_active_transactions=(long*)malloc((max_concurrent_threads+1)*sizeof(long)); tx->thread_identifier=id; tx->i_am_the_collector_thread=0; tx->i_am_waiting=0; reset_local_stats(tx); if(id==main_thread){ current_collector_thread=main_thread; tx->start_no_tx_time=STM_TIMER_READ(); tx->i_am_the_collector_thread=1; } return tx; }
void *test(void *v) { unsigned int seed; int i, n, irrevocable, serial; long l; sigjmp_buf *e; thread_data_t *d = (thread_data_t *)v; seed = (unsigned int)time(0); stm_init_thread(); while (stop == 0) { irrevocable = (rand_r(&seed) < RAND_MAX / 100 * d->irrevocable_percent ? 1 : 0); serial = (rand_r(&seed) < RAND_MAX / 2 ? 1 : 0); // irrevocable=1; // serial=1; e = stm_start(NULL); if (e != NULL) sigsetjmp(*e, 0); if (irrevocable == 4) { /* Aborted while in irrevocable mode => error */ fprintf(stderr, "ERROR: aborted while in irrevocable mode\n"); exit(1); } for (n = rand_r(&seed) % NB_SHUFFLES; n > 0; n--) { i = rand_r(&seed) % NB_ELEMENTS; stm_store_long(&data[i], stm_load_long(&data[i]) + 1); i = rand_r(&seed) % NB_ELEMENTS; stm_store_long(&data[i], stm_load_long(&data[i]) - 1); } if (irrevocable) { if (irrevocable == 3) { /* Already tried entering irrevocable mode once => error */ fprintf(stderr, "ERROR: failed entering irrevocable mode upon retry\n"); exit(1); } irrevocable++; if (!stm_set_irrevocable(serial)) { fprintf(stderr, "ERROR: cannot enter irrevocable mode\n"); exit(1); } irrevocable = 4; /* Once in irrevocable mode, we cannot abort */ if (serial) { /* No other transaction can execute concurrently */ for (i = 0, l = 0; i < NB_ELEMENTS; i++) l += data[i]; assert(l == 0); for (i = 0; i < NB_ELEMENTS; i++) data[i] = 0; nb_irrevocable_serial++; } else { /* Non-conflicting transactions can execute concurrently */ for (i = 0, l = 0; i < NB_ELEMENTS; i++) l += stm_load_long(&data[i]); assert(l == 0); for (i = 0; i < NB_ELEMENTS; i++) stm_store_long(&data[i], 0); nb_irrevocable_parallel++; } } for (i = 0, l = 0; i < NB_ELEMENTS; i++) l += stm_load_long(&data[i]); assert(l == 0); stm_commit(); } stm_get_stats("nb_aborts", &d->nb_aborts); stm_get_stats("nb_aborts_1", &d->nb_aborts_1); stm_get_stats("nb_aborts_2", &d->nb_aborts_2); stm_get_stats("nb_aborts_locked_read", &d->nb_aborts_locked_read); stm_get_stats("nb_aborts_locked_write", &d->nb_aborts_locked_write); stm_get_stats("nb_aborts_validate_read", &d->nb_aborts_validate_read); stm_get_stats("nb_aborts_validate_write", &d->nb_aborts_validate_write); stm_get_stats("nb_aborts_validate_commit", &d->nb_aborts_validate_commit); stm_get_stats("nb_aborts_invalid_memory", &d->nb_aborts_invalid_memory); stm_get_stats("nb_aborts_killed", &d->nb_aborts_killed); stm_get_stats("locked_reads_ok", &d->locked_reads_ok); stm_get_stats("locked_reads_failed", &d->locked_reads_failed); stm_get_stats("max_retries", &d->max_retries); stm_exit_thread(); return NULL; }
_CALLCONV stm_tx_t *stm_pre_init_thread(int id){ return stm_init_thread(); }