Example #1
0
void benchOpsThread(bench_ops_thread_arg_t * arg)
{
    wbmm_thread_init(arg->tid);

    uint32_t seed1 = arg->tid;
    uint32_t seed2 = seed1 + 1;

    uint64_t ops = 0;
    PQ * set = (PQ *)arg->set;

    while (!bench_begin);

    while (!bench_stop) {
        int op  = rand_r_32(&seed1) % 100;
        int key = rand_r_32(&seed2) % KEY_RANGE;
        if (op < 50) {
            set->add(key);
        }
        else {
            key = set->remove();
        }
        for (int i = 0; i < DELAY; i++) spin64();
        ops++;
    }
    arg->ops = ops;
}
Example #2
0
static bool sanityCheck()
{
    PQ set;

    uint32_t seed = 0;
    for (uint32_t i = 0; i < INIT_SIZE; i++) {
        int key = rand_r_32(&seed) % KEY_RANGE;
        set.add(key);
    }

    bench_begin = false;
    bench_stop = false;

    thread *              thrs[NUM_THREADS];
    sanity_thread_arg_t   args[NUM_THREADS];

    for (uint32_t j = 0; j < NUM_THREADS; j++) {
        sanity_thread_arg_t & arg = args[j];
        arg.tid = j + 1;
        arg.set = &set;
        arg.ops = 0;
        thrs[j] = new thread(sanityThread<PQ>, &arg);
    }

    // broadcast begin signal
    bench_begin = true;
    sleep(DURATION);
    bench_stop = true;

    for (uint32_t j = 0; j < NUM_THREADS; j++) thrs[j]->join();

    uint32_t old = 0;
    for (uint32_t i = 0; i < INIT_SIZE; i++) {
        uint32_t num = set.remove();
        if (old > num) {
            cout << "error: heap invariant violated: "
                      << "prev = " << old << " "
                      << "curr = " << num << endl;
            return false;
        }
        if (num == PQ_VAL_MAX) {
            cout << "error: missing element(not linearizable)" << endl;
            return false;
        }
        old = num;
    }
    uint32_t num = set.remove();
    if (num != PQ_VAL_MAX) {
        cout << "error: extra element(not linearizable)" << endl;
        return false;
    }
    cout << "Sanity check: okay." << endl;
    return true;
}
Example #3
0
static void runBench()
{
    PQ set;

    uint32_t seed = 0;
    for (uint32_t i = 0; i < INIT_SIZE; i++) {
        int key = rand_r_32(&seed) % KEY_RANGE;
        set.add(key);
    }

    bench_begin = false;
    bench_stop = false;

    thread *                 thrs[NUM_THREADS];
    bench_ops_thread_arg_t   args[NUM_THREADS];

    for (uint32_t j = 0; j < NUM_THREADS; j++) {
        bench_ops_thread_arg_t & arg = args[j];
        arg.tid = j + 1;
        arg.set = &set;
        arg.ops = 0;
        thrs[j] = new thread(benchOpsThread<PQ>, &arg);
    }

    // broadcast begin signal
    bench_begin = true;

    sleep(DURATION);

    bench_stop = true;

    for (uint32_t j = 0; j < NUM_THREADS; j++)
        thrs[j]->join();

    uint64_t totalOps = 0;
    for (uint32_t j = 0; j < NUM_THREADS; j++) {
        totalOps += args[j].ops;
    }

    cout << ("Throughput(ops/ms): ")
         << std::setprecision(6)
         << (double)totalOps / DURATION / 1000 << endl;
}
Example #4
0
void sanityThread(sanity_thread_arg_t * arg)
{
    wbmm_thread_init(arg->tid);

    uint32_t seed1 = arg->tid;
    uint32_t seed2 = seed1 + 1;

    uint64_t ops = 0;
    PQ * set = (PQ *)arg->set;

    while (!bench_begin);

    while (!bench_stop) {
        int key = rand_r_32(&seed2) % KEY_RANGE;
        set->add(key);
        key = set->remove();
        ops++;
    }
    arg->ops = ops;
}
Example #5
0
bool sanityCheckSequential()
{
    const int max = 10000;
    std::priority_queue<int32_t, vector<int32_t>, pqcompare> contrast;
    PQ m;
    uint32_t seed = 0;
    for (int i = 0; i < max; i++) {
        int32_t temp = rand_r_32(&seed) % KEY_RANGE;
        contrast.push(temp);
        m.add(temp);
    }
    for (int i = 0; i < max - 1; i++) {
        uint32_t r1 = m.remove();
        uint32_t r2 = contrast.empty() ? PQ_VAL_MAX : contrast.top();
        if (!contrast.empty()) contrast.pop();
        if (r1 != r2) {
            cout << "different element at index " << i << ":"
                 << r1 << " " << r2 <<  endl;
            return false;
        }
    }
    cout << "Sanity check: okay." << endl;
    return true;
}