Skip to content

Commit

Permalink
feat(rpaid):to use build-in-prefect in rapid table scan (#268)
Browse files Browse the repository at this point in the history
Co-authored-by: shannon data ai <[email protected]>
  • Loading branch information
RingsC and ShannonBase authored Oct 15, 2024
1 parent f7aea57 commit 3ebefc4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion storage/rapid_engine/imcs/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Chunk : public MemoryObject {
// the data write to where in this chunk.
inline uchar *where() {
assert(m_data < m_end);
return m_data;
return m_data.load();
}

// return the real time chunk size.
Expand Down
8 changes: 8 additions & 0 deletions storage/rapid_engine/imcs/data_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ int DataTable::next(uchar *buf) {
auto offset_in_chunk = m_rowid % SHANNON_ROWS_IN_CHUNK;
ut_a(m_context->m_trx_id_cu);
auto trx_id_ptr = m_context->m_trx_id_cu->chunk(current_chunk)->seek(offset_in_chunk);
// more info for __builtin_prefetch: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
if ((trx_id_ptr + CACHE_LINE_SIZE) < m_context->m_trx_id_cu->chunk(current_chunk)->where())
__builtin_prefetch(trx_id_ptr + CACHE_LINE_SIZE, SHANNON_PREFETCH_FOR_READ, SHANNON_PREFETCH_L3_LOCALITY);
Transaction::ID trx_id = mach_read_from_6(trx_id_ptr);

for (auto idx = 0u; idx < m_field_cus.size(); idx++) {
Expand All @@ -130,6 +133,11 @@ int DataTable::next(uchar *buf) {
return HA_ERR_GENERIC;
});

// prefetch data for cpu to reduce the data cache miss.
if (cu->chunk(current_chunk)->seek(offset_in_chunk) + CACHE_LINE_SIZE < cu->chunk(current_chunk)->where())
__builtin_prefetch(cu->chunk(current_chunk)->seek(offset_in_chunk) + CACHE_LINE_SIZE, SHANNON_PREFETCH_FOR_READ,
SHANNON_PREFETCH_L3_LOCALITY);

// visibility check. if it's not visibile and does not have old version, go to next.
if (!m_context->m_trx->is_visible(trx_id, m_context->m_table_name) &&
!cu->chunk(current_chunk)->get_header()->m_smu) {
Expand Down
9 changes: 9 additions & 0 deletions storage/rapid_engine/include/rapid_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@

#define SHANNON_ALIGNAS alignas(CACHE_LINE_SIZE)

// THE FOLLOWING FOR PREFETCH CPU INSTRUCTION.
#define SHANNON_PREFETCH_FOR_READ 0
#define SHANNON_PREFETCH_FOR_WRITE 1

#define SHANNON_PREFETCH__NONE_LOCALITY 0
#define SHANNON_PREFETCH_L3_LOCALITY 1
#define SHANNON_PREFETCH_L2_LOCALITY 2
#define SAHNNON_PREFETCH_L1_LOCALITY 3

namespace ShannonBase {
using row_id_t = size_t;
/** Handler name for rapid */
Expand Down

0 comments on commit 3ebefc4

Please sign in to comment.