Skip to content

Commit

Permalink
format code.
Browse files Browse the repository at this point in the history
  • Loading branch information
thawk105 committed Jun 12, 2020
1 parent 5a6f58a commit 785d6ba
Show file tree
Hide file tree
Showing 97 changed files with 1,363 additions and 1,214 deletions.
13 changes: 7 additions & 6 deletions cicada/cicada.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <thread>

#define GLOBAL_VALUE_DEFINE

#include "../include/atomic_wrapper.hh"
#include "../include/backoff.hh"
#include "../include/compiler.hh"
Expand All @@ -33,11 +34,11 @@

using namespace std;

void worker(size_t thid, char& ready, const bool& start, const bool& quit) {
void worker(size_t thid, char &ready, const bool &start, const bool &quit) {
Xoroshiro128Plus rnd;
rnd.init();
TxExecutor trans(thid, (Result*)&CicadaResult[thid]);
Result& myres = std::ref(CicadaResult[thid]);
TxExecutor trans(thid, (Result *) &CicadaResult[thid]);
Result &myres = std::ref(CicadaResult[thid]);
FastZipf zipf(&rnd, FLAGS_zipf_skew, FLAGS_tuple_num);
Backoff backoff(FLAGS_clocks_per_us);

Expand Down Expand Up @@ -79,7 +80,7 @@ void worker(size_t thid, char& ready, const bool& start, const bool& quit) {
#endif
#endif

RETRY:
RETRY:
if (thid == 0) {
leaderWork(std::ref(backoff));
#if BACK_OFF
Expand Down Expand Up @@ -173,7 +174,7 @@ void worker(size_t thid, char& ready, const bool& start, const bool& quit) {
return;
}

int main(int argc, char* argv[]) try {
int main(int argc, char *argv[]) try {
gflags::SetUsageMessage("Cicada benchmark.");
gflags::ParseCommandLineFlags(&argc, &argv, true);
chkArg();
Expand All @@ -195,7 +196,7 @@ int main(int argc, char* argv[]) try {
sleepMs(1000);
}
storeRelease(quit, true);
for (auto& th : thv) th.join();
for (auto &th : thv) th.join();

for (unsigned int i = 0; i < FLAGS_thread_num; ++i) {
CicadaResult[0].addLocalAllResult(CicadaResult[i]);
Expand Down
18 changes: 9 additions & 9 deletions cicada/include/cicada_op_element.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

#include "version.hh"

template <typename T>
template<typename T>
class ReadElement : public OpElement<T> {
public:
public:
using OpElement<T>::OpElement;

Version *later_ver_, *ver_;

ReadElement(uint64_t key, T *rcdptr, Version *later_ver, Version *ver)
: OpElement<T>::OpElement(key, rcdptr) {
: OpElement<T>::OpElement(key, rcdptr) {
later_ver_ = later_ver;
ver_ = ver;
}
Expand All @@ -20,9 +20,9 @@ class ReadElement : public OpElement<T> {
}
};

template <typename T>
template<typename T>
class WriteElement : public OpElement<T> {
public:
public:
using OpElement<T>::OpElement;

Version *later_ver_, *new_ver_;
Expand All @@ -31,7 +31,7 @@ class WriteElement : public OpElement<T> {

WriteElement(uint64_t key, T *rcdptr, Version *later_ver, Version *new_ver,
bool rmw)
: OpElement<T>::OpElement(key, rcdptr) {
: OpElement<T>::OpElement(key, rcdptr) {
later_ver_ = later_ver;
new_ver_ = new_ver;
rmw_ = rmw;
Expand All @@ -43,9 +43,9 @@ class WriteElement : public OpElement<T> {
}
};

template <typename T>
template<typename T>
class GCElement : public OpElement<T> {
public:
public:
using OpElement<T>::OpElement;

Version *ver_;
Expand All @@ -54,7 +54,7 @@ class GCElement : public OpElement<T> {
GCElement() : ver_(nullptr), wts_(0) { this->key_ = 0; }

GCElement(uint64_t key, T *rcdptr, Version *ver, uint64_t wts)
: OpElement<T>::OpElement(key, rcdptr) {
: OpElement<T>::OpElement(key, rcdptr) {
this->ver_ = ver;
this->wts_ = wts;
}
Expand Down
8 changes: 4 additions & 4 deletions cicada/include/common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ alignas(CACHE_LINE_SIZE) GLOBAL MasstreeWrapper<Tuple> MT;
alignas(CACHE_LINE_SIZE) GLOBAL std::atomic<uint64_t> MinRts;
alignas(CACHE_LINE_SIZE) GLOBAL std::atomic<uint64_t> MinWts;
alignas(
CACHE_LINE_SIZE) GLOBAL std::atomic<unsigned int> FirstAllocateTimestamp;
CACHE_LINE_SIZE) GLOBAL std::atomic<unsigned int> FirstAllocateTimestamp;
#if MASSTREE_USE
alignas(CACHE_LINE_SIZE) GLOBAL MasstreeWrapper<Tuple> MT;
#endif
Expand Down Expand Up @@ -79,14 +79,14 @@ DECLARE_double(zipf_skew);
alignas(CACHE_LINE_SIZE) GLOBAL uint64_t_64byte *ThreadWtsArray;
alignas(CACHE_LINE_SIZE) GLOBAL uint64_t_64byte *ThreadRtsArray;
alignas(CACHE_LINE_SIZE) GLOBAL uint64_t_64byte
*ThreadRtsArrayForGroup; // グループコミットをする時,これが必要である.
*ThreadRtsArrayForGroup; // グループコミットをする時,これが必要である.

alignas(CACHE_LINE_SIZE) GLOBAL uint64_t_64byte *GROUP_COMMIT_INDEX;
alignas(CACHE_LINE_SIZE) GLOBAL uint64_t_64byte
*GROUP_COMMIT_COUNTER; // s-walの時は[0]のみ使用。全スレッドで共有。
*GROUP_COMMIT_COUNTER; // s-walの時は[0]のみ使用。全スレッドで共有。

alignas(
CACHE_LINE_SIZE) GLOBAL Version ***PLogSet; // [thID][index] pointer array
CACHE_LINE_SIZE) GLOBAL Version ***PLogSet; // [thID][index] pointer array
alignas(CACHE_LINE_SIZE) GLOBAL Version **SLogSet; // [index] pointer array
GLOBAL RWLock SwalLock;
GLOBAL RWLock CtrLock;
Expand Down
12 changes: 9 additions & 3 deletions cicada/include/lock.hh
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#pragma once

#include <xmmintrin.h>
#include <atomic>

using namespace std;

class RWLock {
public:
public:
std::atomic<int> counter;
// counter == -1, write locked;
// counter == 0, not locked;
// counter > 0, there are $counter readers who acquires read-lock.

RWLock() { counter.store(0, std::memory_order_release); }

// Read lock
void r_lock() {
int expected, desired;
for (;;) {
expected = counter.load(std::memory_order_acquire);
RETRY_R_LOCK:
RETRY_R_LOCK:
if (expected != -1)
desired = expected + 1;
else {
Expand All @@ -30,13 +32,15 @@ class RWLock {
goto RETRY_R_LOCK;
}
}

void r_unlock() { counter--; }

// Write lock
void w_lock() {
int expected;
for (;;) {
expected = counter.load(memory_order_acquire);
RETRY_W_LOCK:
RETRY_W_LOCK:
if (expected != 0) continue;
if (counter.compare_exchange_strong(expected, -1, memory_order_acq_rel,
memory_order_acquire))
Expand All @@ -45,7 +49,9 @@ class RWLock {
goto RETRY_W_LOCK;
}
}

void w_unlock() { counter++; }

// Upgrae, read -> write
void upgrade() {
int one = 1;
Expand Down
2 changes: 1 addition & 1 deletion cicada/include/result.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

#include "../../include/result.hh"

extern std::vector<Result> CicadaResult;
extern std::vector <Result> CicadaResult;

extern void initResult();
4 changes: 3 additions & 1 deletion cicada/include/time_stamp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
#include "../../include/tsc.hh"

class TimeStamp {
public:
public:
alignas(CACHE_LINE_SIZE) uint64_t ts_ = 0;
uint64_t localClock_ = 0;
uint64_t clockBoost_ = 0;
uint8_t thid_;

TimeStamp() {}

inline uint64_t get_ts() { return ts_; }

inline void set_ts(uint64_t &ts) { this->ts_ = ts; }

inline void set_clockBoost(unsigned int CLOCK_PER_US) {
Expand Down
38 changes: 23 additions & 15 deletions cicada/include/transaction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ enum class TransactionStatus : uint8_t {
};

class TxExecutor {
public:
public:
TransactionStatus status_ = TransactionStatus::invalid;
TimeStamp wts_;
std::vector<ReadElement<Tuple>> read_set_;
std::vector<WriteElement<Tuple>> write_set_;
std::deque<GCElement<Tuple>> gcq_;
std::deque<Version*> reuse_version_from_gc_;
std::deque<Version *> reuse_version_from_gc_;
std::vector<Procedure> pro_set_;
Result* cres_ = nullptr;
Result *cres_ = nullptr;

bool ronly_;
uint8_t thid_ = 0;
Expand All @@ -50,10 +50,9 @@ class TxExecutor {
char return_val_[VAL_SIZE] = {};
char write_val_[VAL_SIZE] = {};

TxExecutor(uint8_t thid, Result* cres) : cres_(cres), thid_(thid) {
TxExecutor(uint8_t thid, Result *cres) : cres_(cres), thid_(thid) {
// wait to initialize MinWts
while (MinWts.load(memory_order_acquire) == 0)
;
while (MinWts.load(memory_order_acquire) == 0);
rts_ = MinWts.load(memory_order_acquire) - 1;
wts_.generateTimeStampFirst(thid_);

Expand Down Expand Up @@ -95,19 +94,28 @@ class TxExecutor {
}

void abort();

bool chkGcpvTimeout();

void cpv(); // commit pending versions
void displayWriteSet();

void earlyAbort();

void mainte(); // maintenance
void gcpv(); // group commit pending versions
void precpv(); // pre-commit pending versions
void pwal(); // parallel write ahead log.
void swal();

void tbegin();

void tread(const uint64_t key);

void twrite(const uint64_t key);

bool validation();

void writePhase();

void backoff() {
Expand All @@ -122,10 +130,10 @@ class TxExecutor {
#endif
}

void gcAfterThisVersion([[maybe_unused]] Tuple* tuple, Version* delTarget) {
void gcAfterThisVersion([[maybe_unused]] Tuple *tuple, Version *delTarget) {
while (delTarget != nullptr) {
// escape next pointer
Version* tmp = delTarget->next_.load(std::memory_order_acquire);
Version *tmp = delTarget->next_.load(std::memory_order_acquire);

#if INLINE_VERSION_OPT
if (delTarget == &(tuple->inline_ver_)) {
Expand All @@ -140,9 +148,9 @@ class TxExecutor {
delete delTarget;
#endif // if REUSE_VERSION

[[maybe_unused]] gcAfterThisVersion_NEXT_LOOP :
[[maybe_unused]] gcAfterThisVersion_NEXT_LOOP :
#if ADD_ANALYSIS
++cres_->local_gc_version_counts_;
++cres_->local_gc_version_counts_;
#endif
delTarget = tmp;
}
Expand All @@ -166,7 +174,7 @@ class TxExecutor {
#endif
#endif

Version* newVersionGeneration([[maybe_unused]] Tuple* tuple) {
Version *newVersionGeneration([[maybe_unused]] Tuple *tuple) {
#if INLINE_VERSION_OPT
if (tuple->getInlineVersionRight()) {
tuple->inline_ver_.set(0, this->wts_.ts_);
Expand Down Expand Up @@ -215,7 +223,7 @@ class TxExecutor {
itr != write_set_.begin() + (write_set_.size() / 2); ++itr) {
if ((*itr).rcdptr_->continuing_commit_.load(memory_order_acquire) <
CONTINUING_COMMIT_THRESHOLD) {
Version* ver;
Version *ver;
if ((*itr).rmw_) {
ver = (*itr).rcdptr_->ldAcqLatest();
if (ver->ldAcqWts() > this->wts_.ts_ ||
Expand Down Expand Up @@ -263,7 +271,7 @@ class TxExecutor {
* @param Key [in] the key of key-value
* @return Corresponding element of local set
*/
ReadElement<Tuple>* searchReadSet(const uint64_t key) {
ReadElement<Tuple> *searchReadSet(const uint64_t key) {
for (auto itr = read_set_.begin(); itr != read_set_.end(); ++itr) {
if ((*itr).key_ == key) return &(*itr);
}
Expand All @@ -279,7 +287,7 @@ class TxExecutor {
* @param Key [in] the key of key-value
* @return Corresponding element of local set
*/
WriteElement<Tuple>* searchWriteSet(const uint64_t key) {
WriteElement<Tuple> *searchWriteSet(const uint64_t key) {
for (auto itr = write_set_.begin(); itr != write_set_.end(); ++itr) {
if ((*itr).key_ == key) return &(*itr);
}
Expand Down Expand Up @@ -314,7 +322,7 @@ class TxExecutor {
write_set_.clear();
}

static INLINE Tuple* get_tuple(Tuple* table, uint64_t key) {
static INLINE Tuple *get_tuple(Tuple *table, uint64_t key) {
return &table[key];
}
};
11 changes: 6 additions & 5 deletions cicada/include/tuple.hh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include <atomic>
#include <cstdint>

Expand All @@ -9,15 +10,15 @@
using namespace std;

class Tuple {
public:
public:
alignas(CACHE_LINE_SIZE)
#if INLINE_VERSION_OPT
Version inline_ver_;
Version inline_ver_;
#endif
atomic<Version *> latest_;
atomic<uint64_t> min_wts_;
atomic<uint64_t> continuing_commit_;
atomic<uint8_t> gc_lock_;
atomic <uint64_t> min_wts_;
atomic <uint64_t> continuing_commit_;
atomic <uint8_t> gc_lock_;

Tuple() : latest_(nullptr), gc_lock_(0) {}

Expand Down
Loading

0 comments on commit 785d6ba

Please sign in to comment.