HewlettPackard / quartz

Quartz: A DRAM-based performance emulator for NVM
https://github.com/HewlettPackard/quartz
Other
158 stars 66 forks source link

Quartz affecting the application thread sleep time in hybrid (DRAM+NVM) mode. #33

Open hkundnani opened 5 years ago

hkundnani commented 5 years ago

I wrote a sample program in which I allocate memory randomly to dram (using malloc) and nvm (using pmalloc) and a background thread which is supposed to print out the total bytes allocated to NVM and DRAM after every 1 second.

#include <iostream>
#include <cstdlib>
#include <chrono>
#include <thread>
#include <pthread.h>

using namespace std::chrono;

size_t nvm_size = 0;
size_t dram_size = 0;
high_resolution_clock::time_point start;
high_resolution_clock::time_point stop;
bool status = true;

void print_all() {
    stop = high_resolution_clock::now();
    milliseconds time = duration_cast<milliseconds>(stop-start);
    std::cout << time.count() << "\t" << nvm_size << "\t" << dram_size << std::endl;
}

void start_time() {
    start = high_resolution_clock::now();
    while (status) {
        print_all();
        std::this_thread::sleep_for(seconds(1));
    }
}

void stop_time() {
    status = false;
}

void add_nvm_size(size_t size) {
    nvm_size += size;
}

void remove_nvm_size(size_t size) {
    nvm_size -= size;
}

void add_dram_size(size_t size) {
    dram_size += size;
}

void remove_dram_size(size_t size) {
    dram_size -= size;
}

// void *allocate_nvm(size_t size) {
//     return pmalloc(size);
// }

void *allocate_dram (size_t size) {
    return malloc(size);
}

int main(int argc, char *argv[]) {
    std::thread (start_time).detach();

    int count=1;

    while(count<=10000000) {
        int random = rand() % 4;

        if (random==0) {

            allocate_dram (67108864);
            add_dram_size(67108864);
            // std::cout<<count<<"- Allocated in DRAM"<<"\tDRAM SIZE: "<<dram_size<<std::endl;

        }
        else if(random==1){

            allocate_dram (67108864);
            add_nvm_size(67108864);
            // std::cout<<count<<"- Allocated in NVRAM"<<"\tNVRAM SIZE: "<<nvm_size<<std::endl;

        }
        else if(random==2){

            if(dram_size>=67108864) {
                remove_dram_size(67108864);
                // std::cout<<count<<"- Freed from DRAM"<<"\tDRAM SIZE: "<<dram_size<<std::endl;

            }
            // else
                // std::cout<<count<<"- Not Enough Memory Allocated in DRAM to be freed"<<"\tDRAM SIZE: "<<dram_size<<std::endl;

        }
        else if(random==3){

            if(nvm_size>=67108864) {
                remove_nvm_size(67108864);
                // std::cout<<count<<"- Freed from NVRAM"<<"\tNVRAM SIZE: "<<nvm_size<<std::endl;

            }
            // else
                // std::cout<<count<<"- Not Enough Memory Allocated in NVRAM to be freed"<<"\tNVRAM SIZE: "<<nvm_size<<std::endl;

        }

        count++;

    }
    stop_time();
    return 0;
}

The following program ouputs correctly outside quartz. It displays the ouput after every 1 second. So on the left is time in milliseconds, followed by bytes allocated on NVM and bytes allocated on DRAM.

time    NVM    DRAM
0   201326592   0
1000    2885681152  1275068416
2000    30735859712 3288334336
3000    16911433728 138512695296
4040    37983617024 191797133312
5042    14159970304 129654325248
6361    38453379072 189918085120
7363    33554432000 108045271040
8365    15099494400 109521666048
9366    24763170816 117306294272

When I run this program with the quartz in hybrid mode it prints output after 10 milliseconds.

0   268435456   7650410496
10  1879048192  10401873920
20  2415919104  6845104128
30  2483027968  12616466432
40  3556769792  11811160064
50  4496293888  11408506880
60  536870912   17783848960
70  11072962560 16575889408
80  8120172544  9663676416
90  8657043456  7583301632
100 4966055936  268435456
110 939524096   1006632960
120 1476395008  2617245696
130 1946157056  10066329600
140 1073741824  14898167808
150 2281701376  15502147584
160 1744830464  17448304640
...

So quartz is not affecting the functionality of the thread but it's affecting the sleep time of thread. I have not set EMUL_LOCAL_PROCESSES. Do I need to? Also why will quartz affect only the sleep time of a application thread?