From 8b26ac44562e01572ff91a2ed6bcd944e8fc0457 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 8 Feb 2023 11:02:25 -0500 Subject: [PATCH] chore: Remove unused code --- .../dspark/mirage/quick_queue/quick_queue.cpp | 190 ------------------ 1 file changed, 190 deletions(-) delete mode 100644 src/server/sparkd/dspark/mirage/quick_queue/quick_queue.cpp diff --git a/src/server/sparkd/dspark/mirage/quick_queue/quick_queue.cpp b/src/server/sparkd/dspark/mirage/quick_queue/quick_queue.cpp deleted file mode 100644 index f14696300..000000000 --- a/src/server/sparkd/dspark/mirage/quick_queue/quick_queue.cpp +++ /dev/null @@ -1,190 +0,0 @@ -#include -#include -#include -#include - -#include "lib/utils/bts_assert.h" - -namespace bts { -namespace mirage { - -class QuickQueue { - public: - QuickQueue(size_t n_slots, uint32_t slot_sz) - : _buffer(new uint8_t[n_slots * (sizeof(SlotHeader) + slot_sz)]), - _n_slots(n_slots), _slot_sz(slot_sz), _max_msg_sz(n_slots * slot_sz), - _current_slot(0), _current_sn(0) { - bts_assert(slot_sz > 0); - bts_assert(n_slots > 0); - do { - auto p = current_slot(); - auto &slot = *p.first; - slot.seq_n = 0; - move_to_next_slot(); - } while (_current_slot > 0); - } - - enum class Result { MSG_TO_LARGE, OK }; - Result put(uint8_t const *msg, size_t msg_sz) { - if (msg_sz > _max_msg_sz) - return Result::MSG_TO_LARGE; - if (msg_sz == 0) - return Result::OK; - - auto remaining = msg_sz; - auto msg_cursor = msg; - - while (remaining > 0) { - auto p = current_slot(); - auto &slot = *p.first; - auto slot_buffer = p.second; - - // mark slot as in use - slot.seq_n = 0; - - if (remaining > slot_sz()) { - slot.bytes_in_slot = 0; // signal slot is full - memcpy(slot_buffer, msg_cursor, slot_sz()); - msg_cursor += slot_sz(); - remaining -= slot_sz(); - } else { - slot.bytes_in_slot = remaining; - memcpy(slot_buffer, msg_cursor, remaining); - remaining = 0; - } - move_to_next_slot(); - - // done with slot - slot.seq_n = ++_current_sn; - } - return Result::OK; - } - - protected: - friend class QuickQueueReader; - struct SlotHeader { - std::atomic seq_n; - uint32_t bytes_in_slot; - }; - uint32_t slot_sz() const { return _slot_sz; } - size_t n_slots() const { return _n_slots; } - uint8_t const *buffer() const { return _buffer.get(); } - - private: - std::pair current_slot() { - auto offset = - _buffer.get() + _current_slot * (_slot_sz + sizeof(SlotHeader)); - SlotHeader *h = (SlotHeader *)offset; - return std::make_pair(h, offset + sizeof(SlotHeader)); - } - - void move_to_next_slot() { - if (_current_slot == _n_slots) - _current_slot = 0; - else - _current_slot++; - } - - const std::unique_ptr _buffer; - const size_t _n_slots; - const uint32_t _slot_sz; - const size_t _max_msg_sz; - size_t _current_slot; - size_t _current_sn; -}; - -class QuickQueueReader { - public: - QuickQueueReader(QuickQueue const &q) - : _queue(q), _expected_sn(1), _current_slot(0), - _local_buffer_sz(q.slot_sz() * 10), - _local_buffer(new uint8_t[_local_buffer_sz]), _state(ReaderState::OK) { - } - - struct Result { - enum { MISSING_MSGS, NO_MSG, OK } result; - uint8_t const *msg; - size_t msg_size; - }; - Result get() { - if (_state == ReaderState::LOST_MSGS) - return Result{Result::MISSING_MSGS, nullptr, 0}; - - auto p = current_slot(); - auto &slot = *p.first; - auto slot_buffer = p.second; - - // read sn - size_t sn = slot.seq_n; - auto bytes_in_slot = slot.bytes_in_slot; - - if (sn == 0) - return Result{Result::NO_MSG, nullptr, 0}; - if (sn > _expected_sn) { - _state = ReaderState::LOST_MSGS; - return Result{Result::MISSING_MSGS, nullptr, 0}; - } - - if (slot.bytes_in_slot != 0) { - // single slot msg - memcpy(_local_buffer.get(), slot_buffer, bytes_in_slot); - size_t sn2 = slot.seq_n; - if (sn == sn2) { - // we read atomically, we are good to go - move_to_next_slot(); - return Result{Result::OK, _local_buffer.get(), bytes_in_slot}; - } else { - // the message we needed to read was overwritten - _state = ReaderState::LOST_MSGS; - return Result{Result::MISSING_MSGS, nullptr, 0}; - } - } else - // multi-slot msg - return get_multi_slot(sn, slot, slot_buffer); - } - - private: - enum class ReaderState { OK, LOST_MSGS }; - - QuickQueue const &_queue; - size_t _expected_sn; - size_t _current_slot; - size_t _local_buffer_sz; - std::unique_ptr _local_buffer; - ReaderState _state; - - std::pair current_slot() { - auto offset = - _queue.buffer() + - _current_slot * (_queue.slot_sz() + sizeof(QuickQueue::SlotHeader)); - auto h = (QuickQueue::SlotHeader const *)offset; - return std::make_pair(h, offset + sizeof(QuickQueue::SlotHeader)); - } - - void move_to_next_slot() { - if (_current_slot == _queue.n_slots()) - _current_slot = 0; - else - _current_slot++; - _expected_sn++; - } - - Result get_multi_slot( - size_t first_sn, - QuickQueue::SlotHeader const &slot, - uint8_t const *slot_buffer) { - memcpy(_local_buffer.get(), slot_buffer, _queue.slot_sz()); - size_t sn2 = slot.seq_n; - if (sn2 != first_sn) { - // the message we needed to read was overwritten - _state = ReaderState::LOST_MSGS; - return Result{Result::MISSING_MSGS, nullptr, 0}; - } - - // firt slot was read successfully, read the rest - return Result{Result::MISSING_MSGS, nullptr, 0}; - } -}; - -} // namespace mirage -} // namespace bts