From 38f4321ed2ad76bfabc5d89f1fff948ff3147542 Mon Sep 17 00:00:00 2001 From: ismagom Date: Wed, 1 Jul 2015 18:29:50 +0200 Subject: [PATCH] Working with 2 threads up to 3 Mbps DL, 4 UL. A few L&Us yet --- srsapps/common/include/srsapps/common/log.h | 4 ++ srsapps/radio/src/radio_uhd.cc | 2 +- srsapps/ue/mac/include/srsapps/ue/mac/demux.h | 3 ++ srsapps/ue/mac/include/srsapps/ue/mac/mac.h | 12 ++++-- srsapps/ue/mac/include/srsapps/ue/mac/mux.h | 2 +- .../ue/mac/include/srsapps/ue/mac/ul_harq.h | 2 + srsapps/ue/mac/src/demux.cc | 8 ++++ srsapps/ue/mac/src/mac.cc | 39 +++++++++++++------ srsapps/ue/mac/src/mux.cc | 14 +++---- srsapps/ue/mac/src/ul_harq.cc | 6 ++- srsapps/ue/phy/include/srsapps/ue/phy/phy.h | 2 +- .../ue/phy/include/srsapps/ue/phy/ul_buffer.h | 3 +- srsapps/ue/phy/src/phy.cc | 2 +- srsapps/ue/phy/src/ul_buffer.cc | 7 +++- srslte/lib/cuhd/src/cuhd_imp.cpp | 6 +-- 15 files changed, 76 insertions(+), 36 deletions(-) diff --git a/srsapps/common/include/srsapps/common/log.h b/srsapps/common/include/srsapps/common/log.h index 06a0b2652..3dfab5e1e 100644 --- a/srsapps/common/include/srsapps/common/log.h +++ b/srsapps/common/include/srsapps/common/log.h @@ -71,6 +71,10 @@ public: level = LOG_LEVEL_DEBUG; } + uint32_t get_tti() { + return tti; + } + // Pure virtual methods for logging virtual void error(std::string message, ...) = 0; virtual void warning(std::string message, ...) = 0; diff --git a/srsapps/radio/src/radio_uhd.cc b/srsapps/radio/src/radio_uhd.cc index 2afe32711..58b621eea 100644 --- a/srsapps/radio/src/radio_uhd.cc +++ b/srsapps/radio/src/radio_uhd.cc @@ -119,7 +119,7 @@ bool radio_uhd::tx(void* buffer, uint32_t nof_samples, srslte_timestamp_t tx_tim bool radio_uhd::tx_end() { save_trace(2, &end_of_burst_time); - cuhd_send_timed2(uhd, zeros, 10, end_of_burst_time.full_secs, end_of_burst_time.frac_secs, false, true); + cuhd_send_timed2(uhd, zeros, 0, end_of_burst_time.full_secs, end_of_burst_time.frac_secs, false, true); is_start_of_burst = true; } diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/demux.h b/srsapps/ue/mac/include/srsapps/ue/mac/demux.h index e5a168ce0..50e4a3368 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/demux.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/demux.h @@ -67,6 +67,9 @@ private: void process_pdu(sch_pdu *pdu); bool process_ce(sch_subh *subheader); + + // Mutex for exclusive access + pthread_mutex_t mutex; uint64_t contention_resolution_id; bool pending_temp_rnti; diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/mac.h b/srsapps/ue/mac/include/srsapps/ue/mac/mac.h index d061574a4..e4dbd6787 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/mac.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/mac.h @@ -27,6 +27,7 @@ +#include #include "srsapps/common/log.h" #include "srsapps/common/tti_sync.h" @@ -116,15 +117,18 @@ public: tti_sync_cv *sync; pthread_t thread; }; + + static const int NOF_TTI_THREADS = 2; private: // TTI processing threads - static const int NOF_TTI_THREADS = 1; - tti_thread tti_threads[NOF_TTI_THREADS]; - tti_sync_cv tti_threads_sync[NOF_TTI_THREADS]; - + tti_thread tti_threads[NOF_TTI_THREADS]; + tti_sync_cv tti_threads_sync[NOF_TTI_THREADS]; + pthread_mutex_t tti_threads_sync_tx[NOF_TTI_THREADS]; + bool is_first_tx; + // Interaction with PHY tti_sync *ttisync; phy *phy_h; diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/mux.h b/srsapps/ue/mac/include/srsapps/ue/mac/mux.h index 61f858b73..1ee97aca7 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/mux.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/mux.h @@ -80,7 +80,7 @@ private: uint32_t lchid_sorted[mac_io::NOF_UL_LCH]; uint32_t nof_tx_pkts[mac_io::NOF_UL_LCH]; - // Mutex for priority setting from outside MAC + // Mutex for exclusive access pthread_mutex_t mutex; log *log_h; diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/ul_harq.h b/srsapps/ue/mac/include/srsapps/ue/mac/ul_harq.h index 46aadaf59..9fea74b5a 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/ul_harq.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/ul_harq.h @@ -100,6 +100,8 @@ private: void generate_tx(uint32_t tti_tx, uint8_t *pdu_payload, ul_buffer* ul); }; + uint8_t mac_pdu_buffer[NOF_HARQ_PROC][64*1024]; + timers *timers_db; mux *mux_unit; ul_harq_process proc[NOF_HARQ_PROC]; diff --git a/srsapps/ue/mac/src/demux.cc b/srsapps/ue/mac/src/demux.cc index 36bce0301..9459df282 100644 --- a/srsapps/ue/mac/src/demux.cc +++ b/srsapps/ue/mac/src/demux.cc @@ -38,6 +38,9 @@ demux::demux() : mac_msg(20),pending_mac_msg(20) pending_temp_rnti = false; has_pending_contention_resolution_id = false; sdu_handler_ = NULL; + + pthread_mutex_init(&mutex, NULL); + } void demux::init(phy* phy_h_, log* log_h_, mac_io* mac_io_h_, timers* timers_db_) @@ -113,12 +116,17 @@ void demux::push_pdu_temp_crnti(uint8_t *mac_pdu, uint32_t nof_bits) /* Demultiplexing of logical channels and dissassemble of MAC CE */ void demux::push_pdu(uint8_t *mac_pdu, uint32_t nof_bits) { + pthread_mutex_lock(&mutex); + // Unpack DLSCH MAC PDU mac_msg.init(nof_bits/8); mac_msg.parse_packet(mac_pdu); //mac_msg.fprint(stdout); process_pdu(&mac_msg); Debug("Normal MAC PDU processed\n"); + + pthread_mutex_unlock(&mutex); + } void demux::discard_pending_pdu() diff --git a/srsapps/ue/mac/src/mac.cc b/srsapps/ue/mac/src/mac.cc index 6cecf0829..2e4ba7501 100644 --- a/srsapps/ue/mac/src/mac.cc +++ b/srsapps/ue/mac/src/mac.cc @@ -52,6 +52,7 @@ bool mac::init(phy *phy_h_, tti_sync* ttisync_, log* log_h_) is_synchronized = false; last_temporal_crnti = 0; phy_rnti = 0; + is_first_tx = true; bsr_procedure.init(log_h, &timers_db, ¶ms_db, &mac_io_lch); mux_unit.init(log_h, &mac_io_lch, &bsr_procedure); @@ -62,13 +63,14 @@ bool mac::init(phy *phy_h_, tti_sync* ttisync_, log* log_h_) reset(); for (int i=0;ilog_h; sync = sync_; - //started = threads_new_rt(&thread, tti_thread_runner, this); + started = threads_new_rt(&thread, tti_thread_runner, this); return started; } @@ -642,12 +646,13 @@ void mac::tti_thread::run() uint32_t tti = sync->wait(); if (parent->is_synchronized) { - run_tti(tti); + run_tti((tti+1)%10240); } } } void mac::tti_thread::run_tti(uint32_t tti) { + //printf("running tti=%d\n", tti); // Receive PCH, if requested parent->receive_pch(tti); @@ -675,14 +680,21 @@ void mac::tti_thread::run_tti(uint32_t tti) { if (parent->phy_h->sr_is_ready_to_send(tti+4)) { ul_buffer->generate_sr(); } + + // If the packet was not generated by an UL grant, means it's PUCCH or SRS. Generate now the signal + if (!ul_buffer->is_released() && (ul_buffer->uci_ready() || ul_buffer->srs_is_ready_to_send())) { + ul_buffer->generate_data(); + } + + // Wait for previous TTI to be transmitted + if (!parent->is_first_tx) { + pthread_mutex_lock(&parent->tti_threads_sync_tx[tti%parent->NOF_TTI_THREADS]); + } + parent->is_first_tx = false; - // The UL buffer is released when successfully transmitted. + // Send now to the radio if (ul_buffer->is_released()) { - ul_buffer->ready(); - parent->is_first_of_burst = false; - } else if (ul_buffer->uci_ready() || ul_buffer->srs_is_ready_to_send()) { - // If the packet was not generated by a call from MAC, means it's PUCCH or SRS. Generate now the signal - ul_buffer->generate_data(); + ul_buffer->send(); ul_buffer->ready(); parent->is_first_of_burst = false; } else { @@ -692,6 +704,9 @@ void mac::tti_thread::run_tti(uint32_t tti) { } } + // Allow next TTI to be transmitted + pthread_mutex_unlock(&parent->tti_threads_sync_tx[(tti+1)%parent->NOF_TTI_THREADS]); + // Check if there is pending CCCH SDU in Multiplexing Unit if (parent->mux_unit.is_pending_ccch_sdu()) { // Start RA procedure diff --git a/srsapps/ue/mac/src/mux.cc b/srsapps/ue/mac/src/mux.cc index 5dd4f3b5c..8c291cfc3 100644 --- a/srsapps/ue/mac/src/mux.cc +++ b/srsapps/ue/mac/src/mux.cc @@ -37,8 +37,8 @@ namespace ue { mux::mux() : pdu_msg(20) { - msg3_buff.init(1, MSG3_BUFF_SZ); - pdu_buff.init(1, PDU_BUFF_SZ); + msg3_buff.init(mac::NOF_TTI_THREADS, MSG3_BUFF_SZ); + pdu_buff.init(mac::NOF_TTI_THREADS, PDU_BUFF_SZ); bzero(nof_tx_pkts, sizeof(uint32_t) * mac_io::NOF_UL_LCH); pthread_mutex_init(&mutex, NULL); msg3_has_been_transmitted = false; @@ -124,6 +124,7 @@ void mux::set_priority(uint32_t lch_id, uint32_t set_priority, int set_PBR, uint void mux::pdu_release() { + pthread_mutex_unlock(&mutex); pdu_buff.release(); } @@ -152,6 +153,9 @@ bool mux::pdu_move_to_msg3(uint32_t pdu_sz) // Multiplexing and logical channel priorization as defined in Section 5.4.3 uint8_t* mux::pdu_pop(uint32_t pdu_sz) { + // Acquire mutex. Will be released after a call to pdu_release + pthread_mutex_lock(&mutex); + if (pdu_buff.isempty()) { if (assemble_pdu(pdu_sz)) { return (uint8_t*) pdu_buff.pop(); @@ -191,9 +195,6 @@ bool mux::assemble_pdu(uint32_t pdu_sz_nbits) { // Make sure pdu_sz is byte-aligned pdu_sz_nbits = 8*(pdu_sz_nbits/8); - // Acquire mutex. Cannot change priorities, PBR or BSD after assemble finishes - pthread_mutex_lock(&mutex); - // Update Bj for (int i=0;ipdu_pop(grant->get_tbs()); if (mac_pdu) { - proc[pid].generate_new_tx(tti_tx, mac_pdu, false, grant, phy_h->get_ul_buffer(tti_tx)); + // FIXME: This is inefficient. too many memcopies + memcpy(mac_pdu_buffer[pid], mac_pdu, grant->get_tbs()*sizeof(uint8_t)); mux_unit->pdu_release(); + proc[pid].generate_new_tx(tti_tx, mac_pdu_buffer[pid], false, grant, phy_h->get_ul_buffer(tti_tx)); } else { - Warning("Uplink grant with MAC PDU available in Multiplex Unit\n"); + Warning("Uplink grant but no MAC PDU in Multiplex Unit buffer\n"); } } } else { diff --git a/srsapps/ue/phy/include/srsapps/ue/phy/phy.h b/srsapps/ue/phy/include/srsapps/ue/phy/phy.h index 63a7166fe..e532bf684 100644 --- a/srsapps/ue/phy/include/srsapps/ue/phy/phy.h +++ b/srsapps/ue/phy/include/srsapps/ue/phy/phy.h @@ -134,7 +134,7 @@ private: IDLE, RXTX } phy_state; - static const int NOF_ULDL_QUEUES = 6; + static const int NOF_ULDL_QUEUES = 10; tti_sync *ttisync; radio *radio_handler; diff --git a/srsapps/ue/phy/include/srsapps/ue/phy/ul_buffer.h b/srsapps/ue/phy/include/srsapps/ue/phy/ul_buffer.h index 9712e0bf9..fe174c5ab 100644 --- a/srsapps/ue/phy/include/srsapps/ue/phy/ul_buffer.h +++ b/srsapps/ue/phy/include/srsapps/ue/phy/ul_buffer.h @@ -62,7 +62,8 @@ namespace ue { bool generate_data(ul_sched_grant *pusch_grant, uint8_t *payload); bool generate_data(ul_sched_grant *pusch_grant, srslte_softbuffer_tx_t *softbuffer, uint8_t *payload); void set_tx_params(float cfo, float time_adv_sec, srslte_timestamp_t tx_time); - void send_end_of_burst(); + void send_end_of_burst(); + void send(); static const uint32_t tx_advance_sf = 1; // Number of subframes to advance transmission static const bool normalize_amp = true; private: diff --git a/srsapps/ue/phy/src/phy.cc b/srsapps/ue/phy/src/phy.cc index da6cfede5..543bf1ab4 100644 --- a/srsapps/ue/phy/src/phy.cc +++ b/srsapps/ue/phy/src/phy.cc @@ -106,7 +106,7 @@ bool phy::init_(srslte::radio* radio_handler_, srslte::ue::tti_sync* ttisync_, l params_db.set_param(phy_params::CELLSEARCH_TIMEOUT_PSS_CORRELATION_THRESHOLD, 160); params_db.set_param(phy_params::CELLSEARCH_TIMEOUT_MIB_NFRAMES, 100); - if (threads_new_rt_prio(&phy_thread, phy_thread_fnc, this, 1)) { + if (threads_new_rt_prio(&phy_thread, phy_thread_fnc, this, 2)) { started = true; } return started; diff --git a/srsapps/ue/phy/src/ul_buffer.cc b/srsapps/ue/phy/src/ul_buffer.cc index 34a4e70d7..7966c8f7c 100644 --- a/srsapps/ue/phy/src/ul_buffer.cc +++ b/srsapps/ue/phy/src/ul_buffer.cc @@ -285,8 +285,6 @@ bool ul_buffer::generate_data(ul_sched_grant *grant, srslte_softbuffer_tx_t *sof srslte_vec_sc_prod_cfc(signal_buffer, 0.9/max, signal_buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb)); } - radio_h->tx(signal_buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb), tx_time); - release(); if (n < 0) { @@ -310,6 +308,11 @@ void ul_buffer::set_tx_params(float cfo_, float time_adv_sec, srslte_timestamp_t srslte_timestamp_add(&tx_time, 0, 4e-3 - time_adv_sec); // UL buffer is configured for tti+4 } +void ul_buffer::send() { + radio_h->tx(signal_buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb), tx_time); + Info("TX TTI=%d\n", tti); +} + void ul_buffer::send_end_of_burst() { Info("TTI %d sending end of burst\n", tti); diff --git a/srslte/lib/cuhd/src/cuhd_imp.cpp b/srslte/lib/cuhd/src/cuhd_imp.cpp index f2048f8f1..cd9456ff1 100644 --- a/srslte/lib/cuhd/src/cuhd_imp.cpp +++ b/srslte/lib/cuhd/src/cuhd_imp.cpp @@ -162,9 +162,7 @@ int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_ { cuhd_handler *handler = new cuhd_handler(); std::string _args = std::string(args); - handler->usrp = uhd::usrp::multi_usrp::make(_args + ", master_clock_rate=30720000, num_recv_frames=512"); - -// handler->usrp = uhd::usrp::multi_usrp::make(_args + ", master_clock_rate=50000000" + ", num_recv_frames=512"); + handler->usrp = uhd::usrp::multi_usrp::make(_args + ", master_clock_rate=30720000, num_recv_frames=64, num_send_frames=64"); handler->usrp->set_clock_source("internal"); #ifdef HIDE_MESSAGES @@ -177,7 +175,7 @@ int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_ uhd::stream_args_t stream_args(cpu, otw); handler->rx_stream = handler->usrp->get_rx_stream(stream_args); handler->tx_stream = handler->usrp->get_tx_stream(stream_args); - + handler->tx_gain_same_rx = tx_gain_same_rx; handler->tx_rx_gain_offset = 0.0; handler->rx_gain_range = handler->usrp->get_rx_gain_range();