Ignore:
Timestamp:
Sep 26, 2019, 4:25:04 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
1e24d13
Parents:
b2a37b0
Message:

Small tweaks to the memory layout

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/thierry_delisle_PhD/code/processor_list_fast.cpp

    rb2a37b0 r50aeb6f  
    1919        unsigned id;
    2020};
    21 void run(unsigned nthread, double duration, unsigned writes) {
     21void run(unsigned nthread, double duration, unsigned writes, unsigned epochs) {
    2222        assert(writes < 100);
    2323
     
    3030        // Data to check everything is OK
    3131        size_t write_committed = 0ul;
    32         std::atomic_size_t lock_cnt_write = { 0ul };
    33         std::atomic_size_t lock_cnt_read  = { 0ul };
     32        struct {
     33                std::atomic_size_t write = { 0ul };
     34                std::atomic_size_t read  = { 0ul };
     35                std::atomic_size_t epoch = { 0ul };
     36        } lock_cnt;
    3437
    3538        // Flag to signal termination
     
    3942        unsigned i = 1;
    4043        for(auto & t : threads) {
    41                 t = new std::thread([&done, &list, &barrier, &write_committed, &lock_cnt_write, &lock_cnt_read, writes](unsigned tid) {
     44                t = new std::thread([&done, &list, &barrier, &write_committed, &lock_cnt, writes, epochs](unsigned tid) {
    4245                        Random rand(tid + rdtscl());
    4346                        processor proc;
     
    4548                        size_t writes_cnt = 0;
    4649                        size_t reads_cnt = 0;
     50                        size_t epoch_cnt = 0;
    4751
    4852                        affinity(tid);
     
    5155
    5256                        while(__builtin_expect(!done, true)) {
    53                                 if ((rand.next() % 100) < writes) {
     57                                auto r = rand.next() % 100;
     58                                if (r < writes) {
    5459                                        auto n = list.write_lock();
    5560                                        write_committed++;
     
    5762                                        assert(writes_cnt < -2ul);
    5863                                        list.write_unlock(n);
     64                                }
     65                                else if(r < epochs) {
     66                                        list.epoch_check();
     67                                        epoch_cnt++;
    5968                                }
    6069                                else {
     
    7079                        auto p = list.unregister(proc.id);
    7180                        assert(&proc == p);
    72                         lock_cnt_write += writes_cnt;
    73                         lock_cnt_read  += reads_cnt;
     81                        lock_cnt.write += writes_cnt;
     82                        lock_cnt.read  += reads_cnt;
     83                        lock_cnt.epoch += epoch_cnt;
    7484                }, i++);
    7585        }
     
    98108        }
    99109
    100         assert(write_committed == lock_cnt_write);
     110        assert(write_committed == lock_cnt.write);
    101111
    102         size_t ops_sec = size_t(double(lock_cnt_read + lock_cnt_write) / duration);
     112        size_t totalop = lock_cnt.read + lock_cnt.write + lock_cnt.epoch;
     113        size_t ops_sec = size_t(double(totalop) / duration);
    103114        size_t ops_thread = ops_sec / nthread;
    104115        double dur_nano = duration_cast<std::nano>(1.0);
    105116
    106117        std::cout << "Duration      : " << duration << "s\n";
    107         std::cout << "Total ops     : " << (lock_cnt_read + lock_cnt_write) << "(" << lock_cnt_read << "r, " << lock_cnt_write << "w)\n";
     118        std::cout << "Total ops     : " << totalop << "(" << lock_cnt.read << "r, " << lock_cnt.write << "w, " << lock_cnt.epoch << "e)\n";
    108119        std::cout << "Ops/sec       : " << ops_sec << "\n";
    109120        std::cout << "Ops/sec/thread: " << ops_thread << "\n";
     
    121132        unsigned nthreads = 2;
    122133        unsigned writes   = 0;
     134        unsigned epochs   = 0;
    123135
    124136        std::cout.imbue(std::locale(""));
     
    126138        switch (argc)
    127139        {
     140        case 5:
     141                epochs = std::stoul(argv[4]);
     142                [[fallthrough]];
    128143        case 4:
    129144                writes = std::stoul(argv[3]);
    130                 if( writes >= 100 ) {
    131                         std::cerr << "Writes must be valid percentage, was " << argv[3] << "(" << writes << ")" << std::endl;
     145                if( (writes + epochs) > 100 ) {
     146                        std::cerr << "Writes + Epochs must be valid percentage, was " << argv[3] << " + " << argv[4] << "(" << writes << " + " << epochs << ")" << std::endl;
    132147                        usage(argv);
    133148                }
     
    152167        check_cache_line_size();
    153168
    154         std::cout << "Running " << nthreads << " threads for " << duration << " seconds with " << writes << "% writes" << std::endl;
    155         run(nthreads, duration, writes);
     169        std::cout << "Running " << nthreads << " threads for " << duration << " seconds with " << writes << "% writes and " << epochs << "% epochs" << std::endl;
     170        run(nthreads, duration, writes, epochs + writes);
    156171
    157172        return 0;
Note: See TracChangeset for help on using the changeset viewer.