Agora  1.2.0
Agora project
simulator.h
Go to the documentation of this file.
1 
5 #ifndef SIMULATOR_H_
6 #define SIMULATOR_H_
7 
8 #include <emmintrin.h>
9 #include <immintrin.h>
10 #include <unistd.h>
11 
12 #include <algorithm>
13 #include <iostream>
14 #include <memory>
15 #include <queue>
16 #include <system_error>
17 #include <tuple>
18 #include <vector>
19 
20 #include "concurrentqueue.h"
21 #include "config.h"
22 #include "gettime.h"
23 #include "memory_manage.h"
24 #include "message.h"
25 #include "receiver.h"
26 #include "sender.h"
27 #include "signal_handler.h"
28 
29 class Simulator {
30  public:
31  /* optimization parameters for block transpose (see the slides for more
32  * details) */
33  static constexpr size_t kTransposeBlockSize = 8;
34  static constexpr size_t kTransposeBlockNum = 256;
35  /* dequeue bulk size, used to reduce the overhead of dequeue in main thread
36  */
37  static constexpr size_t kDequeueBulkSize = 32;
38  static constexpr size_t kDequeueBulkSizeSingle = 8;
39 
40  Simulator(Config* cfg, size_t task_thread_num, size_t core_offset,
41  size_t sender_delay);
42 
43  ~Simulator();
44 
45  void Start();
46  void Stop();
47 
48  inline void UpdateFrameCount(int* frame_count);
49  void UpdateRxCounters(size_t frame_id, size_t frame_id_in_buffer,
50  size_t symbol_id, size_t ant_id);
51  void PrintPerFrameDone(PrintType print_type, size_t frame_id);
52 
53  private:
57  size_t core_offset_;
58 
59  /* lookup table for 16 QAM, real and imag */
60 
62  std::unique_ptr<Receiver> receiver_;
63  std::unique_ptr<Sender> sender_;
64 
78 
79  /* status checkers used by master thread */
80  /* used to check if RX for all antennas and all symbols in a frame is done
81  * (max: BS_ANT_NUM * dl symbols) */
83 
84  /*****************************************************
85  * Concurrent queues
86  *****************************************************/
87  /* main thread message queue for data receiving */
89  /* main thread message queue for task completion*/
91 
92  /* Tokens */
94 
95  /*****************************************************
96  * Timestamps and counters used in worker threads
97  *****************************************************/
102  double* frame_end_tx_;
103 
104  void InitializeQueues();
105  void InitializeBuffers();
106  void FreeBuffers();
107  void FreeQueues();
108 };
109 
110 #endif // SIMULATOR_H_
Simulator::frame_end_tx_
double * frame_end_tx_
Definition: simulator.h:102
DEFINE_uint64
DEFINE_uint64(num_threads, 4, "Number of sender threads")
Simulator::frame_end_receive_
double * frame_end_receive_
Definition: simulator.h:100
Simulator::PrintPerFrameDone
void PrintPerFrameDone(PrintType print_type, size_t frame_id)
Definition: simulator.cc:187
Simulator::Stop
void Stop()
Definition: simulator.cc:54
moodycamel::ProducerToken
Definition: concurrentqueue.h:630
Config::Running
void Running(bool value)
Definition: config.h:33
kMessageQueueSize
static const size_t kMessageQueueSize
Definition: simulator.cc:14
Packet::frame_id_
uint32_t frame_id_
Definition: message.h:168
Table::Calloc
void Calloc(size_t dim1, size_t dim2, Agora_memory::Alignment_t alignment)
Definition: memory_manage.h:45
PinToCoreWithOffset
void PinToCoreWithOffset(ThreadType thread_type, size_t core_offset, size_t thread_id, bool allow_reuse, bool verbose)
Definition: utils.cc:157
frame_count
frame_count
Definition: parse_dl_file.m:28
PrintType
PrintType
Definition: symbols.h:96
fmt::v8::printf
auto printf(const S &fmt, const T &... args) -> int
Definition: printf.h:631
version_config.h
Agora project version configuration file.
FreeBuffer1d
static void FreeBuffer1d(T **buffer)
Definition: memory_manage.h:116
sender.h
Declaration file for the sender class.
kDebugPrintSimSetup
static const bool kDebugPrintSimSetup
Definition: simulator.cc:12
Simulator::UpdateFrameCount
void UpdateFrameCount(int *frame_count)
Definition: simulator.cc:148
Simulator::frame_start_
Table< double > frame_start_
Definition: simulator.h:98
Simulator::~Simulator
~Simulator()
Definition: simulator.cc:49
moodycamel::ConcurrentQueue::try_dequeue_bulk
size_t try_dequeue_bulk(It itemFirst, size_t max)
Definition: concurrentqueue.h:1210
GetAgoraProjectVersion
const std::string & GetAgoraProjectVersion()
Definition: version_config.h:10
kFrameWnd
static constexpr size_t kFrameWnd
Definition: symbols.h:18
AGORA_LOG_INIT
#define AGORA_LOG_INIT()
Definition: logger.h:35
Agora_memory::PaddedAlignedAlloc
void * PaddedAlignedAlloc(Alignment_t alignment, size_t size)
Definition: memory_manage.cc:15
Simulator::Start
void Start()
Definition: simulator.cc:61
GetTime::GetTimeUs
static double GetTimeUs()
Definition: gettime.h:14
Simulator::kTransposeBlockSize
static constexpr size_t kTransposeBlockSize
Definition: simulator.h:33
SignalHandler::GotExitSignal
static bool GotExitSignal()
Definition: signal_handler.cc:23
memory_manage.h
Config::BsAntNum
size_t BsAntNum() const
Definition: config.h:35
Packet::ant_id_
uint32_t ant_id_
Definition: message.h:171
Simulator::kDequeueBulkSizeSingle
static constexpr size_t kDequeueBulkSizeSingle
Definition: simulator.h:38
Simulator::receiver_
std::unique_ptr< Receiver > receiver_
Definition: simulator.h:62
TOSTRING
#define TOSTRING(x)
Definition: symbols.h:14
signal_handler.h
Config::Frame
const FrameStats & Frame() const
Definition: config.h:340
Catch::cerr
std::ostream & cerr()
rx_tag_t
Definition: message.h:227
Simulator::InitializeQueues
void InitializeQueues()
Definition: simulator.cc:204
Simulator
Definition: simulator.h:29
AllocBuffer1d
static void AllocBuffer1d(T **buffer, U dim, Agora_memory::Alignment_t alignment, int init_zero)
Definition: memory_manage.h:105
Table< char >
Simulator::Simulator
Simulator(Config *cfg, size_t task_thread_num, size_t core_offset, size_t sender_delay)
Definition: simulator.cc:16
filename
filename
Definition: parse_all_dl.m:14
Simulator::socket_tx_thread_num_
size_t socket_tx_thread_num_
Definition: simulator.h:56
Simulator::rx_ptoks_ptr_
moodycamel::ProducerToken ** rx_ptoks_ptr_
Definition: simulator.h:93
EventData
Definition: message.h:142
Simulator::socket_rx_thread_num_
size_t socket_rx_thread_num_
Definition: simulator.h:55
message.h
Self defined functions for message storage and passing.
Table::Free
void Free()
Definition: memory_manage.h:84
i
for i
Definition: generate_data.m:107
Simulator::frame_start_receive_
double * frame_start_receive_
Definition: simulator.h:99
Simulator::complete_task_queue_
moodycamel::ConcurrentQueue< EventData > complete_task_queue_
Definition: simulator.h:90
Catch::cout
std::ostream & cout()
Simulator::UpdateRxCounters
void UpdateRxCounters(size_t frame_id, size_t frame_id_in_buffer, size_t symbol_id, size_t ant_id)
Definition: simulator.cc:155
fmt::v8::fprintf
auto fprintf(std::FILE *f, const S &fmt, const T &... args) -> int
Definition: printf.h:607
Agora_memory::Alignment_t::kAlign64
@ kAlign64
Simulator::socket_buffer_size_
size_t socket_buffer_size_
Definition: simulator.h:77
Packet
Definition: message.h:164
EventType::kPacketRX
@ kPacketRX
Packet::symbol_id_
uint32_t symbol_id_
Definition: message.h:169
main
int main(int argc, char *argv[])
Definition: sender_cli.cc:25
Config::FramesToTest
size_t FramesToTest() const
Definition: config.h:309
kNumStatsFrames
static constexpr size_t kNumStatsFrames
Definition: symbols.h:300
Simulator::task_thread_num_
size_t task_thread_num_
Definition: simulator.h:54
kDebugPrintPerFrameStart
static constexpr bool kDebugPrintPerFrameStart
Definition: symbols.h:197
PrintType::kPacketRX
@ kPacketRX
RxPacket::RawPacket
Packet * RawPacket()
Definition: message.h:213
DEFINE_string
DEFINE_string(server_mac_addr, "ff:ff:ff:ff:ff:ff", "MAC address of the remote Agora server to send data to")
Simulator::kDequeueBulkSize
static constexpr size_t kDequeueBulkSize
Definition: simulator.h:37
Simulator::socket_buffer_
Table< char > socket_buffer_
Definition: simulator.h:76
FrameStats::NumDLSyms
size_t NumDLSyms() const
Definition: framestats.cc:83
moodycamel::ConcurrentQueue< EventData >
Config::GetSymbolType
SymbolType GetSymbolType(size_t symbol_id) const
Return the symbol type of this symbol in this frame.
Definition: config.cc:1557
Simulator::message_queue_
moodycamel::ConcurrentQueue< EventData > message_queue_
Definition: simulator.h:88
Config
Definition: config.h:26
simulator.h
Declaration file for the simulator class.
FrameStats::NumDataSyms
size_t NumDataSyms() const
Definition: framestats.cc:101
Simulator::InitializeBuffers
void InitializeBuffers()
Definition: simulator.cc:228
AGORA_LOG_SHUTDOWN
#define AGORA_LOG_SHUTDOWN()
Definition: logger.h:36
receiver.h
Declaration file for the receiver class.
Agora_memory::Alignment_t::kAlign4096
@ kAlign4096
ThreadType::kMaster
@ kMaster
PrintCoreAssignmentSummary
void PrintCoreAssignmentSummary()
Definition: utils.cc:85
RxPacket
Definition: message.h:186
Simulator::frame_start_tx_
double * frame_start_tx_
Definition: simulator.h:101
Simulator::sender_
std::unique_ptr< Sender > sender_
Definition: simulator.h:63
config.h
Declaration file for the configuration class which importants json configuration values into class va...
SymbolType
SymbolType
Definition: symbols.h:261
Simulator::core_offset_
size_t core_offset_
Definition: simulator.h:57
moodycamel::ConsumerToken
Definition: concurrentqueue.h:695
gettime.h
Config::PacketLength
size_t PacketLength() const
Definition: config.h:238
Simulator::FreeQueues
void FreeQueues()
Definition: simulator.cc:219
Simulator::config_
Config * config_
Definition: simulator.h:61
frame_duration
frame_duration
Definition: parse_dl_file.m:27
Simulator::kTransposeBlockNum
static constexpr size_t kTransposeBlockNum
Definition: simulator.h:34
kDebugPrintPerFrameDone
static constexpr bool kDebugPrintPerFrameDone
Definition: symbols.h:196
RxPacket::Free
void Free()
Definition: message.h:216
concurrentqueue.h
Simulator::FreeBuffers
void FreeBuffers()
Definition: simulator.cc:249
kDebugPrintAllRxSymbols
static const bool kDebugPrintAllRxSymbols
Definition: simulator.cc:11
FrameStats::NumTotalSyms
size_t NumTotalSyms() const
Definition: framestats.cc:93
SymbolType::kDL
@ kDL
Simulator::rx_counter_packets_
size_t * rx_counter_packets_
Definition: simulator.h:82
rx_tag_t::rx_packet_
RxPacket * rx_packet_
Definition: message.h:228