Simplify relationship between BSR, SR and RA procedures. Fix issue #1346

This commit is contained in:
Ismael Gomez 2020-05-20 12:16:44 +02:00 committed by Francisco Paisana
parent 1eaa99530f
commit b5ccbf1891
7 changed files with 47 additions and 102 deletions

View File

@ -85,7 +85,7 @@ private:
// Determine if it's a new transmission 5.3.2.2
bool calc_is_new_transmission(mac_interface_phy_lte::mac_grant_dl_t grant);
pthread_mutex_t mutex;
std::mutex mutex;
bool is_initiated;
dl_harq_entity* harq_entity;

View File

@ -25,6 +25,7 @@
#include <map>
#include <stdint.h>
#include "proc_sr.h"
#include "srslte/common/logmap.h"
#include "srslte/common/timers.h"
#include "srslte/interfaces/ue_interfaces.h"
@ -55,7 +56,8 @@ class bsr_proc : public srslte::timer_callback, public bsr_interface_mux
{
public:
bsr_proc();
void init(rlc_interface_mac* rlc, srslte::log_ref log_h, srslte::task_handler_interface* task_handler_);
void
init(sr_proc* sr_proc, rlc_interface_mac* rlc, srslte::log_ref log_h, srslte::task_handler_interface* task_handler_);
void step(uint32_t tti);
void reset();
void set_config(srslte::bsr_cfg_t& bsr_cfg);
@ -65,18 +67,16 @@ public:
uint32_t get_buffer_state();
bool need_to_send_bsr_on_ul_grant(uint32_t grant_size, bsr_t* bsr);
bool generate_padding_bsr(uint32_t nof_padding_bytes, bsr_t* bsr);
bool need_to_send_sr(uint32_t tti);
bool need_to_reset_sr();
private:
const static int QUEUE_STATUS_PERIOD_MS = 1000;
pthread_mutex_t mutex;
std::mutex mutex;
bool reset_sr;
srslte::task_handler_interface* task_handler;
srslte::log_ref log_h;
rlc_interface_mac* rlc;
sr_proc* sr;
srslte::bsr_cfg_t bsr_cfg;
@ -96,7 +96,6 @@ private:
typedef enum { NONE, REGULAR, PADDING, PERIODIC } triggered_bsr_type_t;
triggered_bsr_type_t triggered_bsr_type;
bool sr_is_sent;
uint32_t current_tti;
uint32_t trigger_tti;

View File

@ -30,16 +30,18 @@
namespace srsue {
// Forward-declare ra_proc
class ra_proc;
class sr_proc
{
public:
sr_proc();
void init(phy_interface_mac_lte* phy_h, rrc_interface_mac* rrc, srslte::log_ref log_h);
void init(ra_proc* ra, phy_interface_mac_lte* phy_h, rrc_interface_mac* rrc, srslte::log_ref log_h);
void step(uint32_t tti);
void set_config(srslte::sr_cfg_t& cfg);
void reset();
void start();
bool need_random_access();
private:
bool need_tx(uint32_t tti);
@ -49,12 +51,12 @@ private:
srslte::sr_cfg_t sr_cfg;
ra_proc* ra;
rrc_interface_mac* rrc;
phy_interface_mac_lte* phy_h;
srslte::log_ref log_h;
bool initiated;
bool do_ra;
};
} // namespace srsue

View File

@ -175,7 +175,6 @@ dl_harq_entity::dl_harq_process::dl_tb_process::dl_tb_process()
n_retx = 0;
bzero(&cur_grant, sizeof(mac_interface_phy_lte::mac_grant_dl_t));
payload_buffer_ptr = NULL;
pthread_mutex_init(&mutex, NULL);
}
dl_harq_entity::dl_harq_process::dl_tb_process::~dl_tb_process()
@ -211,7 +210,7 @@ bool dl_harq_entity::dl_harq_process::dl_tb_process::init(int pid, dl_harq_entit
void dl_harq_entity::dl_harq_process::dl_tb_process::reset(bool lock)
{
if (lock) {
pthread_mutex_lock(&mutex);
mutex.lock();
}
bzero(&cur_grant, sizeof(mac_interface_phy_lte::mac_grant_dl_t));
@ -231,7 +230,7 @@ void dl_harq_entity::dl_harq_process::dl_tb_process::reset(bool lock)
}
if (lock) {
pthread_mutex_unlock(&mutex);
mutex.unlock();
}
}
@ -244,7 +243,7 @@ void dl_harq_entity::dl_harq_process::dl_tb_process::new_grant_dl(mac_interface_
mac_interface_phy_lte::tb_action_dl_t* action)
{
pthread_mutex_lock(&mutex);
mutex.lock();
// Compute RV for BCCH when not specified in PDCCH format
if (is_bcch && grant.tb[tid].rv == -1) {
@ -369,7 +368,7 @@ void dl_harq_entity::dl_harq_process::dl_tb_process::tb_decoded(mac_interface_ph
cur_grant.tb[tid].ndi);
}
pthread_mutex_unlock(&mutex);
mutex.unlock();
if (ack && is_bcch) {
reset();

View File

@ -85,12 +85,12 @@ bool mac::init(phy_interface_mac_lte* phy,
// Create Stack task dispatch queue
stack_task_dispatch_queue = stack_h->make_task_queue();
bsr_procedure.init(rlc_h, log_h, stack_h);
bsr_procedure.init(&sr_procedure, rlc_h, log_h, stack_h);
phr_procedure.init(phy_h, log_h, stack_h);
mux_unit.init(rlc_h, &bsr_procedure, &phr_procedure);
demux_unit.init(phy_h, rlc_h, this, &timer_alignment);
ra_procedure.init(phy_h, rrc, log_h, &uernti, &timer_alignment, &mux_unit, stack_h);
sr_procedure.init(phy_h, rrc, log_h);
sr_procedure.init(&ra_procedure, phy_h, rrc, log_h);
// Create UL/DL unique HARQ pointers
ul_harq.at(0)->init(log_h, &uernti, &ra_procedure, &mux_unit);
@ -214,28 +214,12 @@ void mac::run_tti(const uint32_t tti)
/* Warning: Here order of invocation of procedures is important!! */
// Step all procedures
// Step all procedures (must follow this order)
Debug("Running MAC tti=%d\n", tti);
mux_unit.step();
bsr_procedure.step(tti);
phr_procedure.step();
// Check if BSR procedure need to start SR
if (bsr_procedure.need_to_send_sr(tti)) {
Debug("Starting SR procedure by BSR request, PHY TTI=%d\n", tti);
sr_procedure.start();
}
if (bsr_procedure.need_to_reset_sr()) {
Debug("Resetting SR procedure by BSR request\n");
sr_procedure.reset();
}
sr_procedure.step(tti);
// Check SR if we need to start RA
if (sr_procedure.need_random_access()) {
ra_procedure.start_mac_order();
}
phr_procedure.step();
ra_procedure.step(tti);
ra_procedure.update_rar_window(ra_window_start, ra_window_length);

View File

@ -31,14 +31,16 @@ bsr_proc::bsr_proc()
current_tti = 0;
trigger_tti = 0;
triggered_bsr_type = NONE;
pthread_mutex_init(&mutex, NULL);
}
void bsr_proc::init(rlc_interface_mac* rlc_, srslte::log_ref log_h_, srslte::task_handler_interface* task_handler_)
void bsr_proc::init(sr_proc* sr_,
rlc_interface_mac* rlc_,
srslte::log_ref log_h_,
srslte::task_handler_interface* task_handler_)
{
log_h = log_h_;
rlc = rlc_;
sr = sr_;
task_handler = task_handler_;
timer_periodic = task_handler->get_unique_timer();
@ -77,8 +79,6 @@ void bsr_proc::reset()
timer_periodic.stop();
timer_retx.stop();
reset_sr = false;
sr_is_sent = false;
triggered_bsr_type = NONE;
trigger_tti = 0;
@ -86,7 +86,7 @@ void bsr_proc::reset()
void bsr_proc::set_config(srslte::bsr_cfg_t& bsr_cfg_)
{
pthread_mutex_lock(&mutex);
std::lock_guard<std::mutex> lock(mutex);
bsr_cfg = bsr_cfg_;
@ -98,13 +98,13 @@ void bsr_proc::set_config(srslte::bsr_cfg_t& bsr_cfg_)
timer_retx.set(bsr_cfg_.retx_timer, [this](uint32_t tid) { timer_expired(tid); });
Info("BSR: Configured timer reTX %d ms\n", bsr_cfg_.retx_timer);
}
pthread_mutex_unlock(&mutex);
}
/* Process Periodic BSR */
void bsr_proc::timer_expired(uint32_t timer_id)
{
pthread_mutex_lock(&mutex);
std::lock_guard<std::mutex> lock(mutex);
// periodicBSR-Timer
if (timer_id == timer_periodic.id()) {
if (triggered_bsr_type == NONE) {
@ -119,10 +119,8 @@ void bsr_proc::timer_expired(uint32_t timer_id)
if (check_any_channel()) {
set_trigger(REGULAR);
Debug("BSR: Triggering BSR reTX\n");
sr_is_sent = false;
}
}
pthread_mutex_unlock(&mutex);
}
uint32_t bsr_proc::get_buffer_state()
@ -275,12 +273,12 @@ bool bsr_proc::generate_bsr(bsr_t* bsr, uint32_t nof_padding_bytes)
// Periodic BSR is triggered by the expiration of the timers
void bsr_proc::step(uint32_t tti)
{
std::lock_guard<std::mutex> lock(mutex);
if (!initiated) {
return;
}
pthread_mutex_lock(&mutex);
current_tti = tti;
update_new_data();
@ -292,7 +290,12 @@ void bsr_proc::step(uint32_t tti)
update_buffer_state();
pthread_mutex_unlock(&mutex);
// Trigger SR if Regular BSR is triggered
if (triggered_bsr_type == REGULAR) {
set_trigger(NONE);
Debug("BSR: Triggering SR procedure: tti=%d, trigger_tti=%d\n", tti, trigger_tti);
sr->start();
}
}
char* bsr_proc::bsr_type_tostring(triggered_bsr_type_t type)
@ -325,9 +328,9 @@ char* bsr_proc::bsr_format_tostring(bsr_format_t format)
bool bsr_proc::need_to_send_bsr_on_ul_grant(uint32_t grant_size, bsr_t* bsr)
{
bool bsr_included = false;
std::lock_guard<std::mutex> lock(mutex);
pthread_mutex_lock(&mutex);
bool bsr_included = false;
uint32_t bsr_sz = 0;
if (triggered_bsr_type == PERIODIC || triggered_bsr_type == REGULAR) {
@ -362,22 +365,22 @@ bool bsr_proc::need_to_send_bsr_on_ul_grant(uint32_t grant_size, bsr_t* bsr)
}
// Cancel SR if an Uplink grant is received
reset_sr = true;
Debug("BSR: Cancelling SR procedure due to uplink grant\n");
sr->reset();
// Restart or Start ReTX timer upon indication of a grant
if (timer_retx.duration()) {
timer_retx.run();
Debug("BSR: Started retxBSR-Timer\n");
}
pthread_mutex_unlock(&mutex);
return bsr_included;
}
bool bsr_proc::generate_padding_bsr(uint32_t nof_padding_bytes, bsr_t* bsr)
{
bool ret = false;
std::lock_guard<std::mutex> lock(mutex);
pthread_mutex_lock(&mutex);
bool ret = false;
// This function is called by MUX only if Regular BSR has not been triggered before
if (nof_padding_bytes >= 2) {
@ -387,43 +390,15 @@ bool bsr_proc::generate_padding_bsr(uint32_t nof_padding_bytes, bsr_t* bsr)
set_trigger(NONE);
ret = true;
}
pthread_mutex_unlock(&mutex);
return ret;
}
bool bsr_proc::need_to_reset_sr()
{
bool ret = false;
pthread_mutex_lock(&mutex);
if (reset_sr) {
reset_sr = false;
sr_is_sent = false;
Debug("BSR: SR reset. sr_is_sent and reset_rs false\n");
ret = true;
}
pthread_mutex_unlock(&mutex);
return ret;
}
bool bsr_proc::need_to_send_sr(uint32_t tti)
{
bool ret = false;
pthread_mutex_lock(&mutex);
if (!sr_is_sent && triggered_bsr_type == REGULAR) {
reset_sr = false;
sr_is_sent = true;
Debug("BSR: Need to send sr: sr_is_sent=true, reset_sr=false, tti=%d, trigger_tti=%d\n", tti, trigger_tti);
ret = true;
}
pthread_mutex_unlock(&mutex);
return ret;
}
void bsr_proc::setup_lcid(uint32_t lcid, uint32_t new_lcg, uint32_t priority)
{
std::lock_guard<std::mutex> lock(mutex);
if (new_lcg < NOF_LCG) {
pthread_mutex_lock(&mutex);
// First see if it already exists and eliminate it
for (int i = 0; i < NOF_LCG; i++) {
if (lcgs[i].count(lcid)) {
@ -433,7 +408,6 @@ void bsr_proc::setup_lcid(uint32_t lcid, uint32_t new_lcg, uint32_t priority)
// Now add it
lcgs[new_lcg][lcid].priority = priority;
lcgs[new_lcg][lcid].old_buffer = 0;
pthread_mutex_unlock(&mutex);
} else {
Error("BSR: Invalid lcg=%d for lcid=%d\n", new_lcg, lcid);
}

View File

@ -25,6 +25,7 @@
#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__)
#include "srsue/hdr/stack/mac/proc_sr.h"
#include "srsue/hdr/stack/mac/proc_ra.h"
namespace srsue {
@ -33,14 +34,14 @@ sr_proc::sr_proc()
initiated = false;
}
void sr_proc::init(phy_interface_mac_lte* phy_h_, rrc_interface_mac* rrc_, srslte::log_ref log_h_)
void sr_proc::init(ra_proc* ra_, phy_interface_mac_lte* phy_h_, rrc_interface_mac* rrc_, srslte::log_ref log_h_)
{
log_h = log_h_;
rrc = rrc_;
ra = ra_;
phy_h = phy_h_;
initiated = true;
sr_counter = 0;
do_ra = false;
}
void sr_proc::reset()
@ -90,32 +91,18 @@ void sr_proc::step(uint32_t tti)
sr_cfg.dsr_transmax);
log_h->console("Scheduling request failed: releasing RRC connection...\n");
rrc->release_pucch_srs();
do_ra = true;
is_pending_sr = false;
}
}
} else {
Info("SR: PUCCH not configured. Starting RA procedure\n");
do_ra = true;
ra->start_mac_order();
reset();
}
}
}
}
bool sr_proc::need_random_access()
{
if (initiated) {
if (do_ra) {
do_ra = false;
return true;
} else {
return false;
}
}
return false;
}
void sr_proc::start()
{
if (initiated) {