srsran / srsRAN_4G

Open source SDR 4G software suite from Software Radio Systems (SRS) https://docs.srsran.com/projects/4g
https://www.srsran.com
GNU Affero General Public License v3.0
3.42k stars 1.13k forks source link

short circuit return leaves mutex locked #344

Closed jgiovatto closed 5 years ago

jgiovatto commented 5 years ago

Im running into a condition where tbs < 4. Note this is in an emulated rf environment which Im still looking into the inputs.

 SCHED: Allocation of TBS=2 that does not account header

After this log the enb stops transmitting so I think this needs some attention.

srsenb/src/mac/scheduler_ue.cc

int sched_ue::generate_format1(dl_harq_proc* h, sched_interface::dl_sched_data_t* data, uint32_t tti, uint32_t cfi)
{
  pthread_mutex_lock(&mutex);
...
    if (need_conres_ce and cell.nof_prb < 10) { // SRB0 Tx. Use a higher MCS for the PRACH to fit in 6 PRBs
      tbs = srslte_ra_tbs_from_idx(srslte_ra_tbs_idx_from_mcs(MCS_FIRST_DL, false), nof_prb) / 8;
      mcs = MCS_FIRST_DL;
    } else if (fixed_mcs_dl < 0) {
      tbs = alloc_tbs_dl(nof_prb, nof_re, req_bytes, &mcs);
    } else {
      tbs = srslte_ra_tbs_from_idx(srslte_ra_tbs_idx_from_mcs(fixed_mcs_dl, false), nof_prb) / 8;
      mcs = fixed_mcs_dl;
    }
...
    if (tbs < MIN_DATA_TBS) {
      log_h->warning("SCHED: Allocation of TBS=%d < %d that does not account header\n", tbs, MIN_DATA_TBS);
      return 0;   <<<< short circuit return
    }
...

  pthread_mutex_unlock(&mutex); <<<< normal return
  return tbs;
}
andrepuschmann commented 5 years ago

Very nice catch Joe! Thanks for that. We look after it. Will be fixed in the next release.

jgiovatto commented 5 years ago

We try to use these when possible.

https://en.cppreference.com/w/cpp/thread/lock_guard

andrepuschmann commented 5 years ago

Yes, we'll migrate all pthread mutexes to std::mutex and lock_guard/unique_lock

andrepuschmann commented 5 years ago

Fixed in new release.