int set_add(intset_t* set, val_t val, int transactional) { int result = 0; if (!transactional) { return set_seq_add(set, val); } #ifdef SEQUENTIAL /* Unprotected */ return set_seq_add(set, val); #endif #ifdef EARLY_RELEASE return set_early_add(set, val); #endif #ifdef READ_VALIDATION return set_readval_add(set, val); #endif node_t prev, next; nxt_t to_store; TX_START; #ifdef DEBUG PRINT("++> set_add(%d)\tretry: %u", (int) val, tm2c_tx->retries); #endif to_store = OF(set->head); TX_LOAD_NODE(prev, set->head); TX_LOAD_NODE(next, ND(prev.next)); while (next.val < val) { to_store = prev.next; prev.val = next.val; prev.next = next.next; TX_LOAD_NODE(next, ND(prev.next)); } result = (next.val != val); if (result) { node_t* nn = new_node(val, prev.next, 1); prev.next = OF(nn); TX_STORE(ND(to_store), prev.to_int64, TYPE_INT); } TX_COMMIT_MEM; return result; }
int set_add(intset_t *set, val_t val, int transactional) { int result = 0; #ifdef DEBUG printf("++> set_add(%d)\n", (int)val); IO_FLUSH; #endif if (!transactional) { result = set_seq_add(set, val); } else { #ifdef SEQUENTIAL /* Unprotected */ result = set_seq_add(set, val); #elif defined STM node_t *prev, *next; val_t v; TX_START(EL); prev = set->head; next = (node_t *)TX_LOAD(&prev->next); while (1) { v = TX_LOAD((uintptr_t *) &next->val); if (v >= val) break; prev = next; next = (node_t *)TX_LOAD(&prev->next); } result = (v != val); if (result) { TX_STORE(&prev->next, new_node(val, next, transactional)); } TX_END; #elif defined LOCKFREE result = harris_insert(set, val); #endif } return result; }
int set_add(intset_t *set, skey_t key, skey_t val) { int result; #ifdef DEBUG_PRINT printf("++> set_add(%d)\n", (int)val); IO_FLUSH; #endif #ifdef SEQUENTIAL /* Unprotected */ result = set_seq_add(set, key, val); #elif defined LOCKFREE result = harris_insert(set, key, val); #endif return result; }
int main(int argc, char* argv[]) { TIMER_T start; TIMER_T stop; struct option long_options[] = { // These options don't set a flag {"help", no_argument, NULL, 'h'}, {"duration", required_argument, NULL, 'd'}, {"initial-size", required_argument, NULL, 'i'}, {"num-threads", required_argument, NULL, 'n'}, {"range", required_argument, NULL, 'r'}, {"seed", required_argument, NULL, 's'}, {"buckets", required_argument, NULL, 'b'}, {"update-rate", required_argument, NULL, 'u'}, {NULL, 0, NULL, 0} }; int i, c; long val; operations = DEFAULT_DURATION; unsigned int initial = DEFAULT_INITIAL; nb_threads = DEFAULT_NB_THREADS; range = DEFAULT_RANGE; update = DEFAULT_UPDATE; while(1) { i = 0; c = getopt_long(argc, argv, "hd:i:n:b:r:s:u:", long_options, &i); if(c == -1) break; if(c == 0 && long_options[i].flag == 0) c = long_options[i].val; switch(c) { case 0: /* Flag is automatically set */ break; case 'h': printf("intset -- STM stress test " "(linked list)\n" "\n" "Usage:\n" " intset [options...]\n" "\n" "Options:\n" " -h, --help\n" " Print this message\n" " -d, --duration <int>\n" " Test duration in milliseconds (0=infinite, default=" XSTR(DEFAULT_DURATION) ")\n" " -i, --initial-size <int>\n" " Number of elements to insert before test (default=" XSTR(DEFAULT_INITIAL) ")\n" " -n, --num-threads <int>\n" " Number of threads (default=" XSTR(DEFAULT_NB_THREADS) ")\n" " -r, --range <int>\n" " Range of integer values inserted in set (default=" XSTR(DEFAULT_RANGE) ")\n" " -s, --seed <int>\n" " RNG seed (0=time-based, default=" XSTR(DEFAULT_SEED) ")\n" " -u, --update-rate <int>\n" " Percentage of update transactions (default=" XSTR(DEFAULT_UPDATE) ")\n" ); exit(0); case 'd': operations = atoi(optarg); break; case 'i': initial = atoi(optarg); break; case 'n': nb_threads = atoi(optarg); break; case 'r': range = atoi(optarg); break; case 's': seed = atoi(optarg); break; case 'u': update = atoi(optarg); break; case '?': printf("Use -h or --help for help\n"); exit(0); default: exit(1); } } if (seed == 0) srand((int)time(0)); else srand(seed); thread_startup(nb_threads); set = set_new(); /* Populate set */ printf("Adding %d entries to set\n", initial); for (i = 0; i < initial; i++) { val = (rand() % range) + 1; set_seq_add(val); } printf("Initial size: %d\n", set_size(set)); seed = rand(); TIMER_READ(start); startEnergyIntel(); thread_start(test, NULL); TIMER_READ(stop); double energy = endEnergyIntel(); puts("done."); printf("\nTime = %0.6lf\n", TIMER_DIFF_SECONDS(start, stop)); printf("Energy = %0.6lf\n", energy); fflush(stdout); printf("Final size: %d\n", set_size(set)); }