Skip to content

Commit

Permalink
Threadinfo is now a Masstree type parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Sep 7, 2013
1 parent d471f17 commit 407f457
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 44 deletions.
39 changes: 2 additions & 37 deletions kvthread.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
#ifndef KVTHREAD_HH
#define KVTHREAD_HH 1
#include "mtcounters.hh"
#include "compiler.hh"
#include "circular_int.hh"
#include "timestamp.hh"
Expand All @@ -25,21 +26,10 @@

class threadinfo;
class loginfo;
extern uint64_t initial_timestamp;

extern volatile uint64_t globalepoch; // global epoch, updated regularly
extern volatile bool recovering;

enum memtag {
memtag_none = 0x0,
memtag_value = 0x1,
memtag_limbo = 0x5,
memtag_masstree_leaf = 0x10,
memtag_masstree_internode = 0x11,
memtag_masstree_ksuffixes = 0x12,
memtag_masstree_gclayer = 0x13
};

struct memdebug {
#if HAVE_MEMDEBUG
enum {
Expand Down Expand Up @@ -168,32 +158,6 @@ struct limbo_group {
}
};

enum threadcounter {
// order is important among tc_alloc constants:
tc_alloc,
tc_alloc_value = tc_alloc,
tc_alloc_other = tc_alloc + 1,
// end tc_alloc constants
tc_gc,
tc_limbo_slots,
tc_replay_create_delta,
tc_replay_remove_delta,
tc_root_retry,
tc_internode_retry,
tc_leaf_retry,
tc_leaf_walk,
// order is important among tc_stable constants:
tc_stable,
tc_stable_internode_insert = tc_stable + 0,
tc_stable_internode_split = tc_stable + 1,
tc_stable_leaf_insert = tc_stable + 2,
tc_stable_leaf_split = tc_stable + 3,
// end tc_stable constants
tc_internode_lock,
tc_leaf_lock,
tc_max
};

template <int N> struct has_threadcounter {
static bool test(threadcounter ci) {
return unsigned(ci) < unsigned(N);
Expand Down Expand Up @@ -411,6 +375,7 @@ class threadinfo {
if (limbo_epoch_ && (gc_epoch - limbo_epoch_) > 2)
hard_rcu_quiesce();
}
typedef ::rcu_callback rcu_callback;
void rcu_register(rcu_callback* cb) {
record_rcu(cb, -1);
}
Expand Down
2 changes: 1 addition & 1 deletion masstree.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "compiler.hh"
#include "str.hh"
#include "ksearch.hh"
class threadinfo;

namespace Masstree {
using lcdf::Str;
Expand Down Expand Up @@ -53,6 +52,7 @@ class basic_table {
typedef P param_type;
typedef node_base<P> node_type;
typedef typename P::value_type value_type;
typedef typename P::threadinfo_type threadinfo;

basic_table()
: root_(0) {
Expand Down
3 changes: 3 additions & 0 deletions masstree_query.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "timestamp.hh"
template <typename R> class query;
template <typename R> class replay_query;
class threadinfo;
namespace lcdf { class Json; }

namespace Masstree {
Expand All @@ -29,6 +30,7 @@ class query_table {
public:
typedef P param_type;
typedef node_base<P> node_type;
typedef typename P::threadinfo_type threadinfo;

query_table() {
}
Expand Down Expand Up @@ -75,6 +77,7 @@ class query_table {

struct default_query_table_params : public nodeparams<15, 15> {
typedef row_type* value_type;
typedef ::threadinfo threadinfo_type;
};

typedef query_table<default_query_table_params> default_table;
Expand Down
4 changes: 3 additions & 1 deletion masstree_remove.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define MASSTREE_REMOVE_HH
#include "masstree_tcursor.hh"
#include "btree_leaflink.hh"
#include "circular_int.hh"
namespace Masstree {

template <typename P>
Expand Down Expand Up @@ -99,7 +100,8 @@ bool tcursor<P>::gc_layer(threadinfo& ti)
}

template <typename P>
struct gc_layer_rcu_callback : public rcu_callback {
struct gc_layer_rcu_callback : public P::threadinfo_type::rcu_callback {
typedef typename P::threadinfo_type threadinfo;
basic_table<P> *tablep_;
int len_;
char s_[0];
Expand Down
1 change: 1 addition & 0 deletions masstree_scan.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct scanstackelt {
typedef typename P::ikey_type ikey_type;
typedef key<ikey_type> key_type;
typedef typename leaf_type::permuter_type permuter_type;
typedef typename P::threadinfo_type threadinfo;

node_base<P> *root_;
leaf<P> *n_;
Expand Down
6 changes: 5 additions & 1 deletion masstree_struct.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include "masstree.hh"
#include "nodeversion.hh"
#include "stringbag.hh"
#include "kvthread.hh"
#include "mtcounters.hh"
#include "timestamp.hh"
namespace Masstree {

template <typename P>
Expand Down Expand Up @@ -48,6 +49,7 @@ class node_base : public make_nodeversion<P>::type {
typedef typename P::ikey_type ikey_type;
typedef key<ikey_type> key_type;
typedef typename make_nodeversion<P>::type nodeversion_type;
typedef typename P::threadinfo_type threadinfo;

node_base(bool isleaf)
: nodeversion_type(isleaf) {
Expand Down Expand Up @@ -106,6 +108,7 @@ class internode : public node_base<P> {
typedef key<typename P::ikey_type> key_type;
typedef typename P::ikey_type ikey_type;
typedef typename key_bound<width, P::bound_method>::type bound_type;
typedef typename P::threadinfo_type threadinfo;

uint8_t nkeys_;
ikey_type ikey0_[width];
Expand Down Expand Up @@ -236,6 +239,7 @@ class leaf : public node_base<P> {
typedef kpermuter<P::leaf_width> permuter_type;
typedef typename P::ikey_type ikey_type;
typedef typename key_bound<width, P::bound_method>::type bound_type;
typedef typename P::threadinfo_type threadinfo;

int8_t extrasize64_;
int8_t nremoved_;
Expand Down
2 changes: 2 additions & 0 deletions masstree_tcursor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class unlocked_tcursor {
public:
typedef typename P::value_type value_type;
typedef key<typename P::ikey_type> key_type;
typedef typename P::threadinfo_type threadinfo;

value_type datum_;

Expand Down Expand Up @@ -54,6 +55,7 @@ class tcursor {
typedef typename P::ikey_type ikey_type;
typedef key<ikey_type> key_type;
typedef typename leaf<P>::nodeversion_type nodeversion_type;
typedef typename P::threadinfo_type threadinfo;

tcursor(basic_table<P> &table, Str str)
: ka_(str), tablep_(&table) {
Expand Down
8 changes: 4 additions & 4 deletions masstree_traverse.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ template <typename P>
static inline int stable_last_key_compare(const typename node_base<P>::key_type &ka,
const internode<P> &n,
typename internode<P>::nodeversion_type v,
threadinfo& ti)
typename P::threadinfo_type& ti)
{
while (1) {
int cmp = key_compare(ka, n, n.size() - 1);
Expand All @@ -36,7 +36,7 @@ template <typename P>
static inline int stable_last_key_compare(const typename node_base<P>::key_type &ka,
const leaf<P> &n,
typename leaf<P>::nodeversion_type v,
threadinfo& ti)
typename P::threadinfo_type& ti)
{
while (1) {
typename leaf<P>::permuter_type perm(n.permutation_);
Expand All @@ -51,7 +51,7 @@ static inline int stable_last_key_compare(const typename node_base<P>::key_type
template <typename P>
inline leaf<P> *reach_leaf(const node_base<P> *root,
const typename node_base<P>::key_type &ka,
threadinfo& ti,
typename P::threadinfo_type& ti,
typename node_base<P>::nodeversion_type &version)
{
const node_base<P> *n[2];
Expand Down Expand Up @@ -105,7 +105,7 @@ template <typename P>
leaf<P> *forward_at_leaf(const leaf<P> *n,
typename leaf<P>::nodeversion_type &v,
const typename node_base<P>::key_type &ka,
threadinfo& ti)
typename P::threadinfo_type& ti)
{
typename leaf<P>::nodeversion_type oldv = v;
v = n->stable_annotated(ti.stable_fence());
Expand Down
55 changes: 55 additions & 0 deletions mtcounters.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Masstree
* Eddie Kohler, Yandong Mao, Robert Morris
* Copyright (c) 2012-2013 President and Fellows of Harvard College
* Copyright (c) 2012-2013 Massachusetts Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, subject to the conditions
* listed in the Masstree LICENSE file. These conditions include: you must
* preserve this copyright notice, and you cannot mention the copyright
* holders in advertising related to the Software without their permission.
* The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
* notice is a summary of the Masstree LICENSE file; the license in that file
* is legally binding.
*/
#ifndef MTCOUNTERS_HH
#define MTCOUNTERS_HH 1

enum memtag {
memtag_none = 0x0,
memtag_value = 0x1,
memtag_limbo = 0x5,
memtag_masstree_leaf = 0x10,
memtag_masstree_internode = 0x11,
memtag_masstree_ksuffixes = 0x12,
memtag_masstree_gclayer = 0x13
};

enum threadcounter {
// order is important among tc_alloc constants:
tc_alloc,
tc_alloc_value = tc_alloc,
tc_alloc_other = tc_alloc + 1,
// end tc_alloc constants
tc_gc,
tc_limbo_slots,
tc_replay_create_delta,
tc_replay_remove_delta,
tc_root_retry,
tc_internode_retry,
tc_leaf_retry,
tc_leaf_walk,
// order is important among tc_stable constants:
tc_stable,
tc_stable_internode_insert = tc_stable + 0,
tc_stable_internode_split = tc_stable + 1,
tc_stable_leaf_insert = tc_stable + 2,
tc_stable_leaf_split = tc_stable + 3,
// end tc_stable constants
tc_internode_lock,
tc_leaf_lock,
tc_max
};

#endif
2 changes: 2 additions & 0 deletions timestamp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ inline kvtimestamp_t timestamp_sub(kvtimestamp_t a, kvtimestamp_t b) {
return a;
}

extern kvtimestamp_t initial_timestamp;

inline double now() {
struct timeval tv;
gettimeofday(&tv, 0);
Expand Down

0 comments on commit 407f457

Please sign in to comment.