proxygen
|
#include <FlatCombining.h>
Classes | |
class | Rec |
Combining request record. More... | |
Public Types | |
using | Pool = folly::IndexedMemPool< Rec, 32, 4, Atom, IndexedMemPoolTraitsLazyRecycle< Rec >> |
Public Member Functions | |
FlatCombining (const bool dedicated=true, const uint32_t numRecs=0, const uint32_t maxOps=0) | |
~FlatCombining () | |
void | drainAll () |
void | acquireExclusive () |
bool | tryExclusive () |
void | releaseExclusive () |
template<typename LockHolder > | |
void | holdLock (LockHolder &l) |
template<typename LockHolder > | |
void | holdLock (LockHolder &l, std::defer_lock_t) |
template<typename OpFunc > | |
void | requestNoFC (OpFunc &opFn) |
template<typename OpFunc > | |
void | requestFC (OpFunc &&opFn, Rec *rec=nullptr, bool syncop=true) |
template<typename OpFunc , typename FillFunc > | |
void | requestFC (OpFunc &&opFn, const FillFunc &fillFn, Rec *rec=nullptr, bool syncop=true) |
template<typename OpFunc , typename FillFunc , typename ResFn > | |
void | requestFC (OpFunc &&opFn, const FillFunc &fillFn, const ResFn &resFn, Rec *rec=nullptr) |
Rec * | allocRec () |
void | freeRec (Rec *rec) |
uint64_t | getNumUncombined () const |
uint64_t | getNumCombined () const |
uint64_t | getNumPasses () const |
uint64_t | getNumSessions () const |
Protected Member Functions | |
template<typename OpFunc , typename FillFunc , typename ResFn > | |
void | requestOp (OpFunc &&opFn, const FillFunc &fillFn, const ResFn &resFn, Rec *rec, bool syncop, const bool custom) |
void | pushRec (size_t idx) |
size_t | getRecsHead () |
size_t | nextIndex (size_t idx) |
void | clearPending () |
void | setPending () |
bool | isPending () const |
void | awaitPending () |
uint64_t | combiningSession () |
void | tryCombining () |
void | dedicatedCombining () |
void | awaitDone (Rec &rec) |
void | awaitDoneTryLock (Rec &rec) |
void | shutdown () |
void | combinedOp (Req &) |
The following member functions may be overridden for customization. More... | |
void | processReq (Rec &rec) |
uint64_t | combiningPass () |
Protected Attributes | |
const size_t | NULL_INDEX = 0 |
const uint32_t | kDefaultMaxOps = 100 |
const uint64_t | kDefaultNumRecs = 64 |
const uint64_t | kIdleThreshold = 10 |
Mutex | m_ |
folly::SaturatingSemaphore< true, Atom > | pending_ |
Atom< bool > | shutdown_ {false} |
uint32_t | numRecs_ |
uint32_t | maxOps_ |
Atom< size_t > | recs_ |
bool | dedicated_ |
std::thread | combiner_ |
Pool | recsPool_ |
uint64_t | uncombined_ = 0 |
uint64_t | combined_ = 0 |
uint64_t | passes_ = 0 |
uint64_t | sessions_ = 0 |
Private Types | |
using | SavedFn = folly::Function< void()> |
Flat combining (FC) was introduced in the SPAA 2010 paper Flat Combining and the Synchronization-Parallelism Tradeoff, by Danny Hendler, Itai Incze, Nir Shavit, and Moran Tzafrir. http://mcg.cs.tau.ac.il/projects/projects/flat-combining
FC is an alternative to coarse-grained locking for making sequential data structures thread-safe while minimizing the synchronization overheads and cache coherence traffic associated with locking.
Under FC, when a thread finds the lock contended, it can request (using a request record) that the lock holder execute its operation on the shared data structure. There can be a designated combiner thread or any thread can act as the combiner when it holds the lock.
Potential advantages of FC include:
This implementation of flat combining supports: - A simple interface that requires minimal extra code by the user. To use this interface efficiently the user-provided functions must be copyable to folly::Function without dynamic allocation. If this is impossible or inconvenient, the user is encouraged to use the custom interface described below.
This implementation differs from the algorithm in the SPAA 2010 paper:
The generic FC class template supports generic data structures and utilities with arbitrary operations. The template supports static polymorphism for the combining function to enable custom smart combining.
A simple example of using the FC template: class ConcurrentFoo : public FlatCombining<ConcurrentFoo> { Foo foo_; // sequential data structure public: T bar(V& v) { // thread-safe execution of foo_.bar(v) T result; // Note: fn must be copyable to folly::Function without dynamic // allocation. Otherwise, it is recommended to use the custom // interface and manage the function arguments and results // explicitly in a custom request structure. auto fn = [&] { result = foo_.bar(v); }; this->requestFC(fn); return result; } };
See test/FlatCombiningExamples.h for more examples. See the comments for requestFC() below for a list of simple and custom variants of that function.
Definition at line 109 of file FlatCombining.h.
using folly::FlatCombining< T, Mutex, Atom, Req >::Pool = folly:: IndexedMemPool<Rec, 32, 4, Atom, IndexedMemPoolTraitsLazyRecycle<Rec>> |
Definition at line 230 of file FlatCombining.h.
|
private |
Definition at line 110 of file FlatCombining.h.
|
inlineexplicit |
The constructor takes three optional arguments:
Definition at line 239 of file FlatCombining.h.
|
inline |
Destructor: If there is a dedicated combiner, the destructor flags it to shutdown. Otherwise, the destructor waits for all pending asynchronous requests to be completed.
Definition at line 258 of file FlatCombining.h.
|
inline |
Definition at line 278 of file FlatCombining.h.
|
inline |
Definition at line 379 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::requestOp().
|
inlineprotected |
Definition at line 594 of file FlatCombining.h.
|
inlineprotected |
Waits for the request to be done and occasionally tries to acquire the lock and to do combining. Used only in the absence of a dedicated combiner.
Definition at line 605 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::awaitDone().
|
inlineprotected |
Definition at line 545 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::dedicatedCombining().
|
inlineprotected |
Definition at line 533 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::dedicatedCombining(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::tryCombining().
|
inlineprotected |
The following member functions may be overridden for customization.
Definition at line 631 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::processReq().
|
inlineprotected |
Definition at line 651 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::combiningSession().
|
inlineprotected |
Definition at line 549 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::dedicatedCombining(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::tryCombining().
|
inlineprotected |
Definition at line 572 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::FlatCombining().
|
inline |
Definition at line 270 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::~FlatCombining().
|
inline |
Definition at line 390 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::requestOp().
|
inline |
Definition at line 404 of file FlatCombining.h.
|
inline |
Definition at line 409 of file FlatCombining.h.
|
inline |
Definition at line 414 of file FlatCombining.h.
|
inline |
Definition at line 399 of file FlatCombining.h.
|
inlineprotected |
Definition at line 525 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::combiningPass(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::drainAll().
|
inline |
Definition at line 295 of file FlatCombining.h.
|
inline |
Definition at line 303 of file FlatCombining.h.
|
inlineprotected |
Definition at line 541 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::tryCombining().
|
inlineprotected |
Definition at line 529 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::drainAll().
|
inlineprotected |
Definition at line 637 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::combiningPass().
|
inlineprotected |
Definition at line 514 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::requestOp().
|
inline |
Definition at line 288 of file FlatCombining.h.
|
inline |
Definition at line 337 of file FlatCombining.h.
|
inline |
Definition at line 348 of file FlatCombining.h.
|
inline |
Definition at line 363 of file FlatCombining.h.
|
inline |
Definition at line 309 of file FlatCombining.h.
|
inlineprotected |
Definition at line 443 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::requestFC().
|
inlineprotected |
Definition at line 537 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::awaitDoneTryLock(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::requestOp(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::shutdown().
|
inlineprotected |
Definition at line 624 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::~FlatCombining().
|
inlineprotected |
Definition at line 562 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::awaitDoneTryLock(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::requestOp().
|
inline |
Definition at line 283 of file FlatCombining.h.
|
protected |
Definition at line 438 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::getNumCombined().
|
protected |
Definition at line 434 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::FlatCombining(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::~FlatCombining().
|
protected |
Definition at line 433 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::FlatCombining(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::~FlatCombining().
|
protected |
Definition at line 420 of file FlatCombining.h.
|
protected |
Definition at line 421 of file FlatCombining.h.
|
protected |
Definition at line 422 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::combiningPass().
|
protected |
Definition at line 424 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::acquireExclusive(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::awaitDoneTryLock(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::dedicatedCombining(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::holdLock(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::releaseExclusive(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::requestNoFC(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::requestOp(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::tryExclusive().
|
protected |
Definition at line 431 of file FlatCombining.h.
|
protected |
Definition at line 419 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::allocRec(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::drainAll().
|
protected |
Definition at line 430 of file FlatCombining.h.
|
protected |
Definition at line 439 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::combiningSession(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::getNumPasses().
|
protected |
Definition at line 427 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::awaitPending(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::clearPending(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::isPending(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::setPending().
|
protected |
Definition at line 432 of file FlatCombining.h.
|
protected |
Definition at line 435 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::allocRec(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::drainAll(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::freeRec().
|
protected |
Definition at line 440 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::dedicatedCombining(), folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::getNumSessions(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::tryCombining().
|
protected |
Definition at line 428 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::dedicatedCombining(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::shutdown().
|
protected |
Definition at line 437 of file FlatCombining.h.
Referenced by folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::getNumUncombined(), and folly::FlatCombining< FcSimpleExample< Mutex, Atom >, Mutex, Atom >::requestOp().