From a85b48f48d41dcd8b5acf190b3f7ab8c1edee3b6 Mon Sep 17 00:00:00 2001 From: Peizhao Ou Date: Tue, 25 Mar 2014 14:14:48 -0700 Subject: [PATCH] benchmark for performance results --- benchmark/cliffc-hashtable/cliffc_hashtable.h | 35 ++++- benchmark/cliffc-hashtable/main.cc | 57 ++------ benchmark/cliffc-hashtable/main.cc.backup | 133 ++++++++++++++++++ benchmark/linuxrwlocks/linuxrwlocks.c | 6 +- benchmark/mcs-lock/mcs-lock.cc | 8 +- benchmark/ms-queue/main.c | 5 +- benchmark/ms-queue/my_queue.c | 20 +-- 7 files changed, 194 insertions(+), 70 deletions(-) create mode 100644 benchmark/cliffc-hashtable/main.cc.backup diff --git a/benchmark/cliffc-hashtable/cliffc_hashtable.h b/benchmark/cliffc-hashtable/cliffc_hashtable.h index 3cef980..b5b941e 100644 --- a/benchmark/cliffc-hashtable/cliffc_hashtable.h +++ b/benchmark/cliffc-hashtable/cliffc_hashtable.h @@ -3,6 +3,7 @@ #include #include +#include "stdio.h" //#include #ifdef STANDALONE #include @@ -413,8 +414,9 @@ friend class CHM; /** @Begin @Interface: Get - //@Commit_point_set: Get_Point1 | Get_Point2 | Get_Point3 | Get_ReadKVS - @Commit_point_set: Get_Point1 | Get_Point2 | Get_Point3 + //@Commit_point_set: Get_Point1 | Get_Point2 | Get_ReadKVS | Get_ReadNewKVS | Get_Clear + @Commit_point_set: Get_Point1 | Get_Point2 | Get_Clear + //@Commit_point_set: Get_Point1 | Get_Point2 | Get_Point3 @ID: getKeyTag(key) @Action: TypeV *_Old_Val = (TypeV*) spec_table_get(map, key); @@ -451,7 +453,8 @@ friend class CHM; /** @Begin @Interface: Put - @Commit_point_set: Put_Point + //@Commit_point_set: Put_Point | Put_ReadKVS | Put_ReadNewKVS | Put_WriteKey + @Commit_point_set: Put_Point | Put_WriteKey @ID: getKeyTag(key) @Action: # Remember this old value at checking point @@ -735,6 +738,13 @@ friend class CHM; if (keyeq(K, key_slot, hashes, idx, fullhash)) { // Key hit! Check if table-resize in progress if (!is_prime(V)) { + /** + @Begin + @Commit_point_clear: true + @Label: Get_Clear + @End + */ + /** @Begin @Commit_point_define: true @@ -756,9 +766,9 @@ friend class CHM; /**** FIXME: miss ****/ kvs_data *newkvs = chm->_newkvs.load(memory_order_acquire); /** - @Begin - @Commit_point_define_check: newkvs == NULL - @Label: Get_Point3 + //@Begin + @Commit_point_define_check: true + @Label: Get_ReadNewKVS @End */ return newkvs == NULL ? NULL : get_impl(topmap, @@ -825,6 +835,13 @@ friend class CHM; if (val_slot == TOMBSTONE) return val_slot; // Claim the null key-slot if (CAS_key(kvs, idx, NULL, key_slot)) { + /** + @Begin + @Commit_point_define: true + @Potential_commit_point_label: Write_Key_Point + @Label: Put_WriteKey + @End + */ chm->_slots.fetch_add(1, memory_order_relaxed); // Inc key-slots-used count hashes[idx] = fullhash; // Memorize full hash break; @@ -858,6 +875,12 @@ friend class CHM; // its progress (eagerly try to resize soon) /**** FIXME: miss ****/ newkvs = chm->_newkvs.load(memory_order_acquire); + /** + //@Begin + @Commit_point_define_check: true + @Label: Put_ReadNewKVS + @End + */ if (newkvs == NULL && ((V == NULL && chm->table_full(reprobe_cnt, len)) || is_prime(V))) { //model_print("resize2\n"); diff --git a/benchmark/cliffc-hashtable/main.cc b/benchmark/cliffc-hashtable/main.cc index 7e7a305..302a7ae 100644 --- a/benchmark/cliffc-hashtable/main.cc +++ b/benchmark/cliffc-hashtable/main.cc @@ -55,43 +55,24 @@ IntWrapper *k0, *k1, *k2, *k3, *k4, *k5; IntWrapper *v0, *v1, *v2, *v3, *v4, *v5; void threadA(void *arg) { - table->put(k1, v4); - table->put(k3, v3); - //table->put(k2, v2); - //table->put(k3, v3); - /* - val1 = table->get(k3); - if (val1 != NULL) - model_print("val1: %d\n", val1->_val); - else - model_print("val1: NULL\n");*/ - //table->put(k3, v3); - + table->put(k3, v3); + val1 = table->get(k2); + + } void threadB(void *arg) { - //table->put(k1, v1); - //table->put(k2, v4); - //table->put(k3, v3); -} + } void threadMain(void *arg) { - val1 = table->get(k1); - //val2 = table->get(k2); - /* - if (val1 != NULL) - model_print("val1: %d\n", val1->_val); - else - model_print("val1: NULL\n"); - if (val2 != NULL) - model_print("val2: %d\n", val2->_val); - else - model_print("val2: NULL\n");*/ + table->put(k2, v2); + val1 = table->get(k3); + } int user_main(int argc, char *argv[]) { thrd_t t1, t2; - table = new cliffc_hashtable(2); + table = new cliffc_hashtable(32); k1 = new IntWrapper(3); k2 = new IntWrapper(5); k3 = new IntWrapper(11); @@ -105,28 +86,14 @@ int user_main(int argc, char *argv[]) { v5 = new IntWrapper(99); v0 = new IntWrapper(2048); - table->put(k1, v0); - table->put(k2, v0); - //model_print("hey\n"); - thrd_create(&t1, threadA, NULL); + thrd_create(&t1, threadA, NULL); thrd_create(&t2, threadB, NULL); threadMain(NULL); thrd_join(t1); thrd_join(t2); - /* - if (val1 == NULL) { - cout << "val1: NULL" << endl; - } else { - cout << val1->get() << endl; - } - //MODEL_ASSERT(val1 == NULL || val1->get() == 2 || val1->get() == 81); - if (val2 == NULL) { - cout << "val2: NULL" << endl; - } else { - cout << val2->get() << endl; - } - */ + return 0; } + diff --git a/benchmark/cliffc-hashtable/main.cc.backup b/benchmark/cliffc-hashtable/main.cc.backup new file mode 100644 index 0000000..4806fca --- /dev/null +++ b/benchmark/cliffc-hashtable/main.cc.backup @@ -0,0 +1,133 @@ +#include +#include +#include "cliffc_hashtable.h" + +using namespace std; + +template +slot* const cliffc_hashtable::MATCH_ANY = new slot(false, NULL); + +template +slot* const cliffc_hashtable::NO_MATCH_OLD = new slot(false, NULL); + +template +slot* const cliffc_hashtable::TOMBPRIME = new slot(true, NULL); + +template +slot* const cliffc_hashtable::TOMBSTONE = new slot(false, NULL); + + +class IntWrapper { + private: + public: + int _val; + + IntWrapper(int val) : _val(val) {} + + IntWrapper() : _val(0) {} + + IntWrapper(IntWrapper& copy) : _val(copy._val) {} + + int get() { + return _val; + } + + int hashCode() { + return _val; + } + + bool operator==(const IntWrapper& rhs) { + return false; + } + + bool equals(const void *another) { + if (another == NULL) + return false; + IntWrapper *ptr = + (IntWrapper*) another; + return ptr->_val == _val; + } +}; + +cliffc_hashtable *table; +IntWrapper *val1, *val2; +IntWrapper *k0, *k1, *k2, *k3, *k4, *k5; +IntWrapper *v0, *v1, *v2, *v3, *v4, *v5; + +void threadA(void *arg) { + //table->put(k1, v4); + table->put(k3, v3); + val1 = table->get(k2); + //table->put(k3, v3); + /* + val1 = table->get(k3); + if (val1 != NULL) + model_print("val1: %d\n", val1->_val); + else + model_print("val1: NULL\n");*/ + //table->put(k3, v3); + +} + +void threadB(void *arg) { + //table->put(k1, v1); + //table->put(k2, v4); + //table->put(k3, v3); +} + +void threadMain(void *arg) { + table->put(k2, v2); + val1 = table->get(k3); + //val2 = table->get(k2); + /* + if (val1 != NULL) + model_print("val1: %d\n", val1->_val); + else + model_print("val1: NULL\n"); + if (val2 != NULL) + model_print("val2: %d\n", val2->_val); + else + model_print("val2: NULL\n");*/ +} + +int user_main(int argc, char *argv[]) { + thrd_t t1, t2; + table = new cliffc_hashtable(32); + k1 = new IntWrapper(3); + k2 = new IntWrapper(5); + k3 = new IntWrapper(11); + k4 = new IntWrapper(7); + k5 = new IntWrapper(13); + + v1 = new IntWrapper(1024); + v2 = new IntWrapper(47); + v3 = new IntWrapper(73); + v4 = new IntWrapper(81); + v5 = new IntWrapper(99); + + v0 = new IntWrapper(2048); + //table->put(k1, v0); + //table->put(k2, v0); + //model_print("hey\n"); + thrd_create(&t1, threadA, NULL); + thrd_create(&t2, threadB, NULL); + threadMain(NULL); + + thrd_join(t1); + thrd_join(t2); + /* + if (val1 == NULL) { + cout << "val1: NULL" << endl; + } else { + cout << val1->get() << endl; + } + //MODEL_ASSERT(val1 == NULL || val1->get() == 2 || val1->get() == 81); + if (val2 == NULL) { + cout << "val2: NULL" << endl; + } else { + cout << val2->get() << endl; + } + */ + return 0; +} + diff --git a/benchmark/linuxrwlocks/linuxrwlocks.c b/benchmark/linuxrwlocks/linuxrwlocks.c index a4e58b6..936a16a 100644 --- a/benchmark/linuxrwlocks/linuxrwlocks.c +++ b/benchmark/linuxrwlocks/linuxrwlocks.c @@ -304,7 +304,7 @@ static void a(void *obj) if ((i % 2) == 0) { read_lock(&mylock); //load_32(&shareddata); - printf("%d\n", shareddata); + //printf("%d\n", shareddata); read_unlock(&mylock); } else { write_lock(&mylock); @@ -321,12 +321,12 @@ static void b(void *obj) for(i = 0; i < 2; i++) { if ((i % 2) == 0) { if (read_trylock(&mylock) == 1) { - printf("%d\n", shareddata); + //printf("%d\n", shareddata); read_unlock(&mylock); } } else { if (write_trylock(&mylock) == 1) { - shareddata = 47; + //shareddata = 47; write_unlock(&mylock); } } diff --git a/benchmark/mcs-lock/mcs-lock.cc b/benchmark/mcs-lock/mcs-lock.cc index 0be129f..43435b4 100644 --- a/benchmark/mcs-lock/mcs-lock.cc +++ b/benchmark/mcs-lock/mcs-lock.cc @@ -13,8 +13,8 @@ void threadA(void *arg) { mcs_mutex::guard g(mutex); //printf("store: %d\n", 17); - store_32(&shared, 17); - //shared = 17; + //store_32(&shared, 17); + shared = 17; mutex->unlock(&g); mutex->lock(&g); //printf("load: %u\n", load_32(&shared)); @@ -29,8 +29,8 @@ void threadB(void *arg) mutex->unlock(&g); mutex->lock(&g); //printf("store: %d\n", 17); - //shared = 17; - store_32(&shared, 17); + shared = 17; + //store_32(&shared, 17); } int user_main(int argc, char **argv) diff --git a/benchmark/ms-queue/main.c b/benchmark/ms-queue/main.c index 83bd81a..a2e8e9a 100644 --- a/benchmark/ms-queue/main.c +++ b/benchmark/ms-queue/main.c @@ -54,7 +54,7 @@ int user_main(int argc, char **argv) unsigned int in_sum = 0, out_sum = 0; queue = calloc(1, sizeof(*queue)); - MODEL_ASSERT(queue); + //MODEL_ASSERT(queue); num_threads = procs; threads = malloc(num_threads * sizeof(thrd_t)); @@ -69,7 +69,7 @@ int user_main(int argc, char **argv) } for (i = 0; i < num_threads; i++) thrd_join(threads[i]); - +/* for (i = 0; i < num_threads; i++) { in_sum += input[i]; out_sum += output[i]; @@ -79,6 +79,7 @@ int user_main(int argc, char **argv) for (i = 0; i < num_threads; i++) printf("output[%d] = %u\n", i, output[i]); //MODEL_ASSERT(in_sum == out_sum); + */ free(param); free(threads); diff --git a/benchmark/ms-queue/my_queue.c b/benchmark/ms-queue/my_queue.c index 0d64ed8..1f4835e 100644 --- a/benchmark/ms-queue/my_queue.c +++ b/benchmark/ms-queue/my_queue.c @@ -31,7 +31,7 @@ static unsigned int new_node() } } /* free_list is empty? */ - MODEL_ASSERT(0); + //MODEL_ASSERT(0); return 0; } @@ -42,7 +42,7 @@ static void reclaim(unsigned int node) int t = get_thread_num(); /* Don't reclaim NULL node */ - MODEL_ASSERT(node); + //MODEL_ASSERT(node); for (i = 0; i < MAX_FREELIST; i++) { /* Should never race with our own thread here */ @@ -57,7 +57,7 @@ static void reclaim(unsigned int node) } } /* free list is full? */ - MODEL_ASSERT(0); + //MODEL_ASSERT(0); } void init_queue(queue_t *q, int num_threads) @@ -105,7 +105,7 @@ void enqueue(queue_t *q, unsigned int val) tail = atomic_load_explicit(&q->tail, acquire); /****FIXME: miss ****/ next = atomic_load_explicit(&q->nodes[get_ptr(tail)].next, acquire); - printf("miss1_enqueue\n"); + //printf("miss1_enqueue\n"); if (tail == atomic_load_explicit(&q->tail, relaxed)) { /* Check for uninitialized 'next' */ @@ -136,9 +136,9 @@ void enqueue(queue_t *q, unsigned int val) succ = atomic_compare_exchange_strong_explicit(&q->tail, &tail, value, release, relaxed); if (succ) { - printf("miss2_enqueue CAS succ\n"); + //printf("miss2_enqueue CAS succ\n"); } - printf("miss2_enqueue\n"); + //printf("miss2_enqueue\n"); thrd_yield(); } } @@ -170,12 +170,12 @@ unsigned int dequeue(queue_t *q) tail = atomic_load_explicit(&q->tail, relaxed); /****FIXME: miss ****/ next = atomic_load_explicit(&q->nodes[get_ptr(head)].next, acquire); - printf("miss3_dequeue\n"); + //printf("miss3_dequeue\n"); if (atomic_load_explicit(&q->head, relaxed) == head) { if (get_ptr(head) == get_ptr(tail)) { /* Check for uninitialized 'next' */ - MODEL_ASSERT(get_ptr(next) != POISON_IDX); + //MODEL_ASSERT(get_ptr(next) != POISON_IDX); if (get_ptr(next) == 0) { // NULL /** @@ -194,9 +194,9 @@ unsigned int dequeue(queue_t *q) MAKE_POINTER(get_ptr(next), get_count(tail) + 1), release, relaxed); if (succ) { - printf("miss4_dequeue CAS succ\n"); + //printf("miss4_dequeue CAS succ\n"); } - printf("miss4_dequeue\n"); + //printf("miss4_dequeue\n"); thrd_yield(); } else { value = load_32(&q->nodes[get_ptr(next)].value); -- 2.34.1