libfoedus-core
FOEDUS Core Library
foedus::assorted::ProbCounter Struct Reference

Implements a probabilistic counter [Morris 1978]. More...

Detailed Description

Implements a probabilistic counter [Morris 1978].

The major user is HCC's temperature field maintained in each page header.

[Morris 1987] Robert Morris, Counting large numbers of events in small registers, Commun. ACM 21, 10 (October 1978), 840-842.

Unlike the paper, we do much simpler thing. We just compare with power of two, so that we don't need exp/log. No information stored in static/global whatever.

Definition at line 37 of file prob_counter.hpp.

#include <prob_counter.hpp>

Public Member Functions

 ProbCounter ()
 
void reset ()
 
void increment (UniformRandom *rnd)
 
void decrement_force ()
 

Public Attributes

uint8_t value_
 Log arithmic counter of aborts. More...
 

Constructor & Destructor Documentation

foedus::assorted::ProbCounter::ProbCounter ( )
inline

Definition at line 45 of file prob_counter.hpp.

References ASSERT_ND.

45  : value_(0) {
46  ASSERT_ND(sizeof(uint8_t) == sizeof(ProbCounter));
47  }
uint8_t value_
Log arithmic counter of aborts.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Member Function Documentation

void foedus::assorted::ProbCounter::decrement_force ( )
inline

Definition at line 69 of file prob_counter.hpp.

References value_.

69  {
70  --value_;
71  }
uint8_t value_
Log arithmic counter of aborts.
void foedus::assorted::ProbCounter::increment ( UniformRandom rnd)
inline

Definition at line 51 of file prob_counter.hpp.

References foedus::assorted::UniformRandom::next_uint32(), and value_.

Referenced by foedus::xct::RwLockableXctId::hotter().

51  {
52  // We increment the value_ for exponentially smaller probability.
53  // value_==0: always
54  // value_==1: 50% chance
55  // value_==2: 25% chance... etc
56  // We can implement this by simple bit-shifts.
57 
58  // Extract middle 24-bits, which is typically done in hashing. This is kinda hashing too.
59  // This also means the following makes sense only for value_<=24. Should be a reasonable assmp.
60  const uint32_t int_val = rnd->next_uint32();
61  const uint32_t int24_val = (int_val >> 4) & 0xFFFFFFU;
62  const uint32_t threshold = 1U << (24 - value_);
63  if (int24_val < threshold) {
64  ++value_;
65  }
66  }
uint8_t value_
Log arithmic counter of aborts.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

uint8_t foedus::assorted::ProbCounter::value_

Log arithmic counter of aborts.

There were about 2^value_ aborts. Keep it single member so sizeof(ProbCounter) == sizeof(uint8_t).

Definition at line 43 of file prob_counter.hpp.

Referenced by foedus::xct::RetrospectiveLockList::construct(), foedus::storage::PageHeader::contains_hot_records(), decrement_force(), increment(), foedus::thread::Thread::is_hot_page(), and foedus::storage::operator<<().


The documentation for this struct was generated from the following file: