tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Disjoint.hpp
Go to the documentation of this file.
1 /**
2  * Copyright (C) 2011
3  * University of Rochester Department of Computer Science
4  * and
5  * Lehigh University Department of Computer Science and Engineering
6  *
7  * License: Modified BSD
8  * Please see the file LICENSE.RSTM for licensing information
9  */
10 
11 #ifndef DISJOINT_HPP__
12 #define DISJOINT_HPP__
13 
14 #include <api/api.hpp>
15 
16  // this is a benchmark for evaluating the overhead that TM induces for a
17  // variety of read/write ratios when there are no conflicts. The benchmark
18  // is templated so that we can (at compile time) specify the number of
19  // locations that a transaction will touch, and the percentage of those
20  // locations that are to be written. We don't actually care about the values
21  // read or written, since it's a microbenchmark.
22 struct Disjoint
23  {
24  // const for keeping things from being 'too regular'
25  static const unsigned DJBUFFER_SIZE = 1009;
26  static const unsigned BUFFER_COUNT = 256;
27 
28  // each transaction will work on special buffers, where entries in the
29  // buffer are pretty far apart
31  {
32  uint32_t value;
33  char padding[64-sizeof(uint32_t)];
35  };
36 
37  // array of padded entries
38  struct PaddedBuffer
39  {
41  PaddedBuffer() : buffer() { }
42  };
43 
44  // private buffers for upto BUFFER_COUNT transactions
46 
47  // public buffer (in case we need it)
49 
50  unsigned reads_per_ten;
51  unsigned writes_per_ten;
54 
55  // constructor just sets up the execution parameters
56  // R : reads_per_10
57  // W : writes_per_10
58  // L : locations_per_transaction
59  // S : use_shared_read_buffer
60  Disjoint(unsigned R, unsigned W, unsigned L, bool S)
65  {
66  unsigned int s = W;
67  for (uint32_t i = 0; i < BUFFER_COUNT; ++i)
68  for (unsigned j = 0; j < DJBUFFER_SIZE; ++j)
69  privateBuffers[i].buffer[j].value = rand_r_32(&s);
70  for (unsigned j = 0; j < DJBUFFER_SIZE; ++j)
72  }
73 
74  /**
75  * do some reads only... bool return type to keep it from being
76  * optimized out
77  */
79  bool ro_transaction(uint32_t id, uint32_t startpoint TM_ARG)
80  __attribute__((noinline));
81 
82  /**
83  * do some reads, do some rmw's
84  */
86  void r_rw_transaction(uint32_t id, uint32_t startpoint TM_ARG)
87  {
88  PaddedBuffer& rBuffer =
90  PaddedBuffer& wBuffer = privateBuffers[id];
91  unsigned index = startpoint, writes = 0, reads = 0, buff = 0;
92 
93  for (unsigned i = 0; i < locations_per_transaction; i++) {
94  // if we've done ten things, then reset the read and write
95  // counters
96  if ((writes + reads) == 10)
97  writes = reads = 0;
98  // should_write determies action to do on this loop iteration
99  bool should_write = false;
100  // set should_write based on /i/:
101  // on odd, do a read/write if there are writes left to do
102  // on even, do a read if there are reads left to do
103  if (i && 0x1)
104  should_write = (writes < writes_per_ten);
105  else
106  should_write = !(reads < reads_per_ten);
107 
108  // perform the selected action
109  if (should_write) {
110  // increment the item (read and write it)
111  unsigned oldval = TM_READ(wBuffer.buffer[index].value);
112  TM_WRITE(wBuffer.buffer[index].value, (uint32_t)(oldval + 1));
113  writes++;
114  }
115  else {
116  buff += TM_READ(rBuffer.buffer[index].value);
117  reads++;
118  }
119 
120  // compute the next index
121  index = (index + 1) % DJBUFFER_SIZE;
122  }
123  }
124 };
125 
126 #endif // DISJOINT_HPP__
static const unsigned BUFFER_COUNT
Definition: Disjoint.hpp:26
#define TM_CALLABLE
Definition: cxxtm.hpp:32
unsigned reads_per_ten
Definition: Disjoint.hpp:50
uint32_t value
Definition: Disjoint.hpp:32
#define TM_WRITE(x, y)
Definition: cxxtm.hpp:46
TM_CALLABLE bool ro_transaction(uint32_t id, uint32_t startpoint TM_ARG) __attribute__((noinline))
Definition: DisjointBench.cpp:53
Definition: Disjoint.hpp:22
PaddedBufferEntry()
Definition: Disjoint.hpp:34
unsigned writes_per_ten
Definition: Disjoint.hpp:51
Definition: policies.hpp:256
#define TM_ARG
Definition: cxxtm.hpp:40
PaddedBuffer privateBuffers[BUFFER_COUNT]
Definition: Disjoint.hpp:45
char padding[64-sizeof(uint32_t)]
Definition: Disjoint.hpp:33
unsigned locations_per_transaction
Definition: Disjoint.hpp:52
Disjoint(unsigned R, unsigned W, unsigned L, bool S)
Definition: Disjoint.hpp:60
#define TM_READ(x)
Definition: cxxtm.hpp:45
class simple_queue __attribute__
int rand_r_32(unsigned int *seed)
Definition: rand_r_32.h:43
Definition: Disjoint.hpp:30
TM_CALLABLE void r_rw_transaction(uint32_t id, uint32_t startpoint TM_ARG)
Definition: Disjoint.hpp:86
Definition: Disjoint.hpp:38
PaddedBufferEntry buffer[DJBUFFER_SIZE]
Definition: Disjoint.hpp:40
PaddedBuffer publicBuffer
Definition: Disjoint.hpp:48
bool use_shared_read_buffer
Definition: Disjoint.hpp:53
static const unsigned DJBUFFER_SIZE
Definition: Disjoint.hpp:25
PaddedBuffer()
Definition: Disjoint.hpp:41