Thrill  0.1

Detailed Description

template<class BlockType>
class foxxll::prefetch_pool< BlockType >

Implements dynamically resizable prefetching pool.

Definition at line 34 of file prefetch_pool.hpp.

#include <prefetch_pool.hpp>

Classes

struct  bid_hash
 

Public Types

using bid_type = typename block_type::bid_type
 
using block_type = BlockType
 

Public Member Functions

 prefetch_pool (size_t init_size=1)
 
 prefetch_pool (const prefetch_pool &)=delete
 non-copyable: delete copy-constructor More...
 
virtual ~prefetch_pool ()
 Waits for completion of all ongoing read requests and frees memory. More...
 
void add (block_type *&block)
 Add a new block to prefetch pool, enlarges size of pool. More...
 
size_t busy_size () const
 Returns the number of busy prefetching blocks. More...
 
request_ptr find (bid_type bid)
 
size_t free_size () const
 Returns the number of free prefetching blocks. More...
 
bool hint (bid_type bid)
 Gives a hint for prefetching a block, the block may or may not be read into a prefetch buffer. More...
 
bool hint (bid_type bid, write_pool< block_type > &w_pool)
 Gives a hint for prefetching a block, the block may or may not be read into a prefetch buffer. More...
 
bool in_prefetching (bid_type bid)
 Checks if a block is in the hinted block set. More...
 
bool invalidate (bid_type bid)
 Cancel a hint request in case the block is no longer desired. More...
 
prefetch_pooloperator= (const prefetch_pool &)=delete
 non-copyable: delete assignment operator More...
 
bool poll (bid_type bid)
 Returns true if the blocks was hinted and the request is finished. More...
 
request_ptr read (block_type *&block, bid_type bid)
 Reads block. More...
 
request_ptr read (block_type *&block, bid_type bid, write_pool< block_type > &w_pool)
 
size_t resize (size_t new_size)
 
size_t size () const
 Returns number of owned blocks. More...
 
block_typesteal ()
 
void swap (prefetch_pool &obj)
 

Protected Types

using busy_blocks_iterator = typename unordered_map_type::iterator
 
using busy_entry = std::pair< block_type *, request_ptr >
 
using free_blocks_iterator = typename std::list< block_type * >::iterator
 
using unordered_map_type = typename std::unordered_map< bid_type, busy_entry, bid_hash >
 

Protected Attributes

unordered_map_type busy_blocks
 blocks that are in reading or already read but not retrieved by user More...
 
std::list< block_type * > free_blocks
 contains free prefetch blocks More...
 
size_t free_blocks_size
 count number of free blocks, since traversing the std::list is slow. More...
 

Static Private Attributes

static constexpr bool debug = false
 

Member Typedef Documentation

◆ bid_type

using bid_type = typename block_type::bid_type

Definition at line 40 of file prefetch_pool.hpp.

◆ block_type

using block_type = BlockType

Definition at line 39 of file prefetch_pool.hpp.

◆ busy_blocks_iterator

using busy_blocks_iterator = typename unordered_map_type::iterator
protected

Definition at line 67 of file prefetch_pool.hpp.

◆ busy_entry

using busy_entry = std::pair<block_type*, request_ptr>
protected

Definition at line 64 of file prefetch_pool.hpp.

◆ free_blocks_iterator

using free_blocks_iterator = typename std::list<block_type*>::iterator
protected

Definition at line 66 of file prefetch_pool.hpp.

◆ unordered_map_type

using unordered_map_type = typename std::unordered_map<bid_type, busy_entry, bid_hash>
protected

Definition at line 65 of file prefetch_pool.hpp.

Constructor & Destructor Documentation

◆ prefetch_pool() [1/2]

prefetch_pool ( size_t  init_size = 1)
inlineexplicit

Constructs pool.

Parameters
init_sizeinitial number of blocks in the pool

Definition at line 81 of file prefetch_pool.hpp.

References prefetch_pool< BlockType >::operator=().

◆ prefetch_pool() [2/2]

prefetch_pool ( const prefetch_pool< BlockType > &  )
delete

non-copyable: delete copy-constructor

◆ ~prefetch_pool()

virtual ~prefetch_pool ( )
inlinevirtual

Waits for completion of all ongoing read requests and frees memory.

Definition at line 102 of file prefetch_pool.hpp.

Member Function Documentation

◆ add()

void add ( block_type *&  block)
inline

Add a new block to prefetch pool, enlarges size of pool.

Definition at line 142 of file prefetch_pool.hpp.

References prefetch_pool< BlockType >::free_blocks_size.

Referenced by read_write_pool< BlockType >::add_prefetch().

◆ busy_size()

size_t busy_size ( ) const
inline

Returns the number of busy prefetching blocks.

Definition at line 136 of file prefetch_pool.hpp.

Referenced by read_write_pool< BlockType >::busy_size_prefetch().

◆ find()

request_ptr find ( bid_type  bid)
inline

Returns the request pointer for a hinted block, or an invalid nullptr request in case it was not requested due to lack of prefetch buffers.

Definition at line 270 of file prefetch_pool.hpp.

Referenced by read_write_pool< BlockType >::find_hint(), and prefetch_pool< BlockType >::poll().

◆ free_size()

size_t free_size ( ) const
inline

Returns the number of free prefetching blocks.

Definition at line 130 of file prefetch_pool.hpp.

References prefetch_pool< BlockType >::free_blocks_size.

Referenced by read_write_pool< BlockType >::free_size_prefetch().

◆ hint() [1/2]

bool hint ( bid_type  bid)
inline

Gives a hint for prefetching a block, the block may or may not be read into a prefetch buffer.

Parameters
bidaddress of a block to be prefetched
Returns
true if there was a free block to do prefetch and prefetching was scheduled, false otherwise
Note
If there are no free blocks available (all blocks are already in reading or read but not retrieved by user calling read method) calling hint function has no effect

Definition at line 174 of file prefetch_pool.hpp.

References prefetch_pool< BlockType >::free_blocks_size, prefetch_pool< BlockType >::in_prefetching(), and TLX_LOG.

Referenced by read_write_pool< BlockType >::hint(), and read_write_pool< BlockType >::write().

◆ hint() [2/2]

bool hint ( bid_type  bid,
write_pool< block_type > &  w_pool 
)
inline

Gives a hint for prefetching a block, the block may or may not be read into a prefetch buffer.

This variant checks if the write pool is currently writing said block.

Parameters
bidaddress of a block to be prefetched
Returns
true if there was a free block to do prefetch and prefetching was scheduled, false otherwise
Parameters
w_poolThe corresponding write pool; so the method can check if the block is maybe still in RAM.
Note
If there are no free blocks available (all blocks are already in reading or read but not retrieved by user calling read method) calling hint function has no effect

Definition at line 212 of file prefetch_pool.hpp.

References write_pool< BlockType >::add(), prefetch_pool< BlockType >::free_blocks_size, write_pool< BlockType >::has_request(), prefetch_pool< BlockType >::in_prefetching(), write_pool< BlockType >::steal_request(), and TLX_LOG.

◆ in_prefetching()

bool in_prefetching ( bid_type  bid)
inline

Checks if a block is in the hinted block set.

Definition at line 263 of file prefetch_pool.hpp.

Referenced by prefetch_pool< BlockType >::hint(), and read_write_pool< BlockType >::in_prefetching().

◆ invalidate()

bool invalidate ( bid_type  bid)
inline

Cancel a hint request in case the block is no longer desired.

Definition at line 244 of file prefetch_pool.hpp.

References prefetch_pool< BlockType >::free_blocks_size, and request_interface::READ.

Referenced by read_write_pool< BlockType >::invalidate(), and read_write_pool< BlockType >::write().

◆ operator=()

prefetch_pool& operator= ( const prefetch_pool< BlockType > &  )
delete

non-copyable: delete assignment operator

Referenced by prefetch_pool< BlockType >::prefetch_pool().

◆ poll()

bool poll ( bid_type  bid)
inline

Returns true if the blocks was hinted and the request is finished.

Definition at line 281 of file prefetch_pool.hpp.

References prefetch_pool< BlockType >::find(), and CountingPtr< Type, Deleter >::valid().

Referenced by read_write_pool< BlockType >::poll_hint().

◆ read() [1/2]

request_ptr read ( block_type *&  block,
bid_type  bid 
)
inline

Reads block.

If this block is cached block is not read but passed from the cache.

Parameters
blockblock object, where data to be read to. If block was cached block 's ownership goes to the pool and block from cache is returned in block value.
bidaddress of the block
Warning
block parameter must be allocated dynamically using new .
Returns
request pointer object of read operation

Definition at line 301 of file prefetch_pool.hpp.

References prefetch_pool< BlockType >::free_blocks_size, and TLX_LOG.

Referenced by read_write_pool< BlockType >::read().

◆ read() [2/2]

◆ resize()

size_t resize ( size_t  new_size)
inline

Resizes size of the pool.

Parameters
new_sizedesired size of the pool. If some blocks are used for prefetching, these blocks can't be freed. Only free blocks (not in prefetching) can be freed by reducing the size of the pool calling this method.
Returns
new size of the pool

Definition at line 359 of file prefetch_pool.hpp.

References prefetch_pool< BlockType >::free_blocks_size, and prefetch_pool< BlockType >::size().

Referenced by read_write_pool< BlockType >::resize_prefetch().

◆ size()

size_t size ( ) const
inline

Returns number of owned blocks.

Definition at line 124 of file prefetch_pool.hpp.

Referenced by prefetch_pool< BlockType >::resize(), and read_write_pool< BlockType >::size_prefetch().

◆ steal()

block_type* steal ( )
inline

Take out a block from the pool, one unhinted free block must be available.

Returns
pointer to the block. Ownership of the block goes to the caller.

Definition at line 152 of file prefetch_pool.hpp.

References prefetch_pool< BlockType >::free_blocks_size, and tlx_die_unless.

Referenced by read_write_pool< BlockType >::steal_prefetch().

◆ swap()

void swap ( prefetch_pool< BlockType > &  obj)
inline

Member Data Documentation

◆ busy_blocks

unordered_map_type busy_blocks
protected

blocks that are in reading or already read but not retrieved by user

Definition at line 73 of file prefetch_pool.hpp.

Referenced by prefetch_pool< BlockType >::swap().

◆ debug

constexpr bool debug = false
staticprivate

Definition at line 36 of file prefetch_pool.hpp.

◆ free_blocks

std::list<block_type*> free_blocks
protected

contains free prefetch blocks

Definition at line 70 of file prefetch_pool.hpp.

Referenced by prefetch_pool< BlockType >::swap().

◆ free_blocks_size


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