extend thread class to set unique thread name in ctor

this will also extend all classes that use srslte::thread
to specify the name of the thread in the ctor as well
as to set the name of the worker threads in the thread pool
the thread name will be displayed in gdb.
master
Andre Puschmann 6 years ago
parent 0e95867f13
commit e47010130f

@ -63,8 +63,7 @@ private:
std::string filename; std::string filename;
pthread_cond_t not_empty; pthread_cond_t not_empty;
pthread_mutex_t mutex; pthread_mutex_t mutex;
pthread_t thread; std::deque<str_ptr> buffer;
std::deque<str_ptr> buffer;
}; };
} // namespace srslte } // namespace srslte

@ -54,8 +54,9 @@ template<typename metrics_t>
class metrics_hub : public periodic_thread class metrics_hub : public periodic_thread
{ {
public: public:
metrics_hub() : m(nullptr), sleep_start(std::chrono::steady_clock::now()) {} metrics_hub() : m(nullptr), sleep_start(std::chrono::steady_clock::now()), periodic_thread("METRICS_HUB") {}
bool init(metrics_interface<metrics_t> *m_, float report_period_secs_=1.0) { bool init(metrics_interface<metrics_t>* m_, float report_period_secs_ = 1.0)
{
m = m_; m = m_;
// Start with user-default priority // Start with user-default priority
start_periodic(report_period_secs_*1e6, -2); start_periodic(report_period_secs_*1e6, -2);

@ -39,28 +39,32 @@
void threads_print_self(); void threads_print_self();
#ifdef __cplusplus #ifdef __cplusplus
} }
#include <string>
#ifndef SRSLTE_THREADS_H #ifndef SRSLTE_THREADS_H
#define SRSLTE_THREADS_H #define SRSLTE_THREADS_H
class thread class thread
{ {
public: public:
thread() { thread(const std::string& name_) : _thread(0), name(name_) {}
_thread = 0;
}
bool start(int prio = -1) { bool start(int prio = -1) {
return threads_new_rt_prio(&_thread, thread_function_entry, this, prio); return threads_new_rt_prio(&_thread, thread_function_entry, this, prio);
} }
bool start_cpu(int prio, int cpu) { bool start_cpu(int prio, int cpu) {
return threads_new_rt_cpu(&_thread, thread_function_entry, this, cpu, prio); return threads_new_rt_cpu(&_thread, thread_function_entry, this, cpu, prio);
} }
bool start_cpu_mask(int prio, int mask){ bool start_cpu_mask(int prio, int mask)
return threads_new_rt_mask(&_thread, thread_function_entry, this, mask, prio); {
} return threads_new_rt_mask(&_thread, thread_function_entry, this, mask, prio);
void print_priority() { }
threads_print_self(); void print_priority() { threads_print_self(); }
void set_name(const std::string& name_)
{
name = name_;
pthread_setname_np(pthread_self(), name.c_str());
} }
void wait_thread_finish() { void wait_thread_finish() {
pthread_join(_thread, NULL); pthread_join(_thread, NULL);
@ -68,16 +72,25 @@ public:
void thread_cancel() { void thread_cancel() {
pthread_cancel(_thread); pthread_cancel(_thread);
} }
protected: protected:
virtual void run_thread() = 0; virtual void run_thread() = 0;
private: private:
static void *thread_function_entry(void *_this) { ((thread*) _this)->run_thread(); return NULL; } static void* thread_function_entry(void* _this)
pthread_t _thread; {
pthread_setname_np(pthread_self(), ((thread*)_this)->name.c_str());
((thread*)_this)->run_thread();
return NULL;
}
pthread_t _thread;
std::string name;
}; };
class periodic_thread : public thread class periodic_thread : public thread
{ {
public: public:
periodic_thread(const std::string name_) : thread(name_) {}
void start_periodic(int period_us_, int priority = -1) { void start_periodic(int period_us_, int priority = -1) {
run_enable = true; run_enable = true;
period_us = period_us_; period_us = period_us_;
@ -156,5 +169,4 @@ private:
#endif // SRSLTE_THREADS_H #endif // SRSLTE_THREADS_H
#endif // __cplusplus #endif // __cplusplus

@ -27,12 +27,11 @@ using namespace std;
namespace srslte{ namespace srslte{
logger_file::logger_file() logger_file::logger_file() : logfile(NULL), is_running(false), cur_length(0), max_length(0), thread("LOGGER_FILE")
:logfile(NULL) {
,is_running(false) pthread_mutex_init(&mutex, NULL);
,cur_length(0) pthread_cond_init(&not_empty, NULL);
,max_length(0) }
{}
logger_file::~logger_file() { logger_file::~logger_file() {
if(is_running) { if(is_running) {
@ -46,9 +45,9 @@ logger_file::~logger_file() {
if (logfile) { if (logfile) {
fclose(logfile); fclose(logfile);
} }
pthread_mutex_destroy(&mutex);
pthread_cond_destroy(&not_empty);
} }
pthread_mutex_destroy(&mutex);
pthread_cond_destroy(&not_empty);
} }
void logger_file::init(std::string file, int max_length_) { void logger_file::init(std::string file, int max_length_) {

@ -30,12 +30,13 @@
namespace srslte { namespace srslte {
thread_pool::worker::worker() : my_id(0), running(false), my_parent(NULL) {} thread_pool::worker::worker() : my_id(0), running(false), my_parent(NULL), thread("THREAD_POOL_WORKER") {}
void thread_pool::worker::setup(uint32_t id, thread_pool *parent, uint32_t prio, uint32_t mask) void thread_pool::worker::setup(uint32_t id, thread_pool *parent, uint32_t prio, uint32_t mask)
{ {
my_id = id; my_id = id;
my_parent = parent; my_parent = parent;
if(mask == 255) if(mask == 255)
{ {
start(prio); start(prio);
@ -49,6 +50,7 @@ void thread_pool::worker::setup(uint32_t id, thread_pool *parent, uint32_t prio,
void thread_pool::worker::run_thread() void thread_pool::worker::run_thread()
{ {
set_name(std::string("WORKER") + std::to_string(my_id));
running = true; running = true;
while(running) { while(running) {
wait_to_start(); wait_to_start();

@ -89,7 +89,7 @@ public:
class ul_writer : public thread class ul_writer : public thread
{ {
public: public:
ul_writer(rlc_am* rlc_) : rlc(rlc_), running(false) {} ul_writer(rlc_am* rlc_) : rlc(rlc_), running(false), thread("UL_WRITER") {}
~ul_writer() { stop(); } ~ul_writer() { stop(); }
void stop() void stop()
{ {

@ -109,15 +109,20 @@ class mac_dummy
,public thread ,public thread
{ {
public: public:
mac_dummy(rlc_interface_mac *rlc1_, rlc_interface_mac *rlc2_, stress_test_args_t args_, uint32_t lcid_, rlc_pcap* pcap_ = NULL) mac_dummy(rlc_interface_mac* rlc1_,
:timers(8) rlc_interface_mac* rlc2_,
,run_enable(true) stress_test_args_t args_,
,rlc1(rlc1_) uint32_t lcid_,
,rlc2(rlc2_) rlc_pcap* pcap_ = NULL) :
,args(args_) timers(8),
,pcap(pcap_) run_enable(true),
,lcid(lcid_) rlc1(rlc1_),
,log("MAC ") rlc2(rlc2_),
args(args_),
pcap(pcap_),
lcid(lcid_),
log("MAC "),
thread("MAC_DUMMY")
{ {
log.set_level(static_cast<LOG_LEVEL_ENUM>(args.log_level)); log.set_level(static_cast<LOG_LEVEL_ENUM>(args.log_level));
log.set_hex_limit(LOG_HEX_LIMIT); log.set_hex_limit(LOG_HEX_LIMIT);
@ -209,14 +214,15 @@ class rlc_tester
,public thread ,public thread
{ {
public: public:
rlc_tester(rlc_interface_pdcp *rlc_, std::string name_, stress_test_args_t args_, uint32_t lcid_) rlc_tester(rlc_interface_pdcp* rlc_, std::string name_, stress_test_args_t args_, uint32_t lcid_) :
:log("Testr") log("Testr"),
,rlc(rlc_) rlc(rlc_),
,run_enable(true) run_enable(true),
,rx_pdus() rx_pdus(),
,name(name_) name(name_),
,args(args_) args(args_),
,lcid(lcid_) lcid(lcid_),
thread("RLC_TESTER")
{ {
log.set_level(srslte::LOG_LEVEL_ERROR); log.set_level(srslte::LOG_LEVEL_ERROR);
log.set_hex_limit(LOG_HEX_LIMIT); log.set_hex_limit(LOG_HEX_LIMIT);

@ -196,7 +196,7 @@ private:
/* Class to run upper-layer timers with normal priority */ /* Class to run upper-layer timers with normal priority */
class timer_thread : public thread { class timer_thread : public thread {
public: public:
timer_thread(srslte::timers *t) : ttisync(10240),timers(t),running(false) {start();} timer_thread(srslte::timers* t) : ttisync(10240), timers(t), running(false), thread("MAC_TIMER") { start(); }
void tti_clock(); void tti_clock();
void stop(); void stop();
private: private:

@ -33,8 +33,16 @@ namespace srsenb {
class prach_worker : thread class prach_worker : thread
{ {
public: public:
prach_worker() : initiated(false), prach_nof_det(0), max_prach_offset_us(0), buffer_pool(8), prach_worker() :
running(false), nof_sf(0), sf_cnt(0) { initiated(false),
prach_nof_det(0),
max_prach_offset_us(0),
buffer_pool(8),
running(false),
nof_sf(0),
sf_cnt(0),
thread("PRACH_WORKER")
{
log_h = NULL; log_h = NULL;
mac = NULL; mac = NULL;
bzero(&prach, sizeof(srslte_prach_t)); bzero(&prach, sizeof(srslte_prach_t));

@ -71,7 +71,7 @@ private:
// Class to create // Class to create
class mch_thread : public thread { class mch_thread : public thread {
public: public:
mch_thread() : initiated(false), running(false), run_enable(false), pool(NULL), lcid_counter(0) {} mch_thread() : initiated(false), running(false), run_enable(false), pool(NULL), lcid_counter(0), thread("MCH") {}
bool init(std::string m1u_multiaddr_, std::string m1u_if_addr_, pdcp_interface_gtpu *pdcp_, srslte::log *gtpu_log_); bool init(std::string m1u_multiaddr_, std::string m1u_if_addr_, pdcp_interface_gtpu *pdcp_, srslte::log *gtpu_log_);
void stop(); void stop();
private: private:

@ -106,8 +106,8 @@ class rrc : public rrc_interface_pdcp,
public thread public thread
{ {
public: public:
rrc() : act_monitor(this), cnotifier(NULL), running(false), nof_si_messages(0), thread("RRC")
rrc() : act_monitor(this), cnotifier(NULL), running(false), nof_si_messages(0) { {
users.clear(); users.clear();
pending_paging.clear(); pending_paging.clear();

@ -61,6 +61,8 @@ class s1ap
,public thread ,public thread
{ {
public: public:
s1ap();
~s1ap();
bool init(s1ap_args_t args_, rrc_interface_s1ap *rrc_, srslte::log *s1ap_log_); bool init(s1ap_args_t args_, rrc_interface_s1ap *rrc_, srslte::log *s1ap_log_);
void stop(); void stop();
void get_metrics(s1ap_metrics_t &m); void get_metrics(s1ap_metrics_t &m);

@ -901,7 +901,8 @@ void mac::timer_thread::tti_clock()
* DEMUX unit * DEMUX unit
* *
*******************************************************/ *******************************************************/
mac::pdu_process::pdu_process(pdu_process_handler *h) : running(false) { mac::pdu_process::pdu_process(pdu_process_handler* h) : running(false), thread("MAC_PDU_PROCESS")
{
handler = h; handler = h;
pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cvar, NULL); pthread_cond_init(&cvar, NULL);

@ -37,7 +37,8 @@ using namespace std;
namespace srsenb { namespace srsenb {
txrx::txrx() : tx_worker_cnt(0), nof_workers(0), tti(0) { txrx::txrx() : tx_worker_cnt(0), nof_workers(0), tti(0), thread("TXRX")
{
running = false; running = false;
radio_h = NULL; radio_h = NULL;
log_h = NULL; log_h = NULL;

@ -28,7 +28,7 @@
using namespace srslte; using namespace srslte;
namespace srsenb { namespace srsenb {
gtpu::gtpu():mchthread() gtpu::gtpu() : mchthread(), thread("GTPU")
{ {
pdcp = NULL; pdcp = NULL;
gtpu_log = NULL; gtpu_log = NULL;

@ -865,7 +865,7 @@ void rrc::run_thread()
Activity monitor class Activity monitor class
*******************************************************************************/ *******************************************************************************/
rrc::activity_monitor::activity_monitor(rrc* parent_) rrc::activity_monitor::activity_monitor(rrc* parent_) : thread("RRC_ACTIVITY_MONITOR")
{ {
running = true; running = true;
parent = parent_; parent = parent_;

@ -38,6 +38,17 @@ using srslte::uint32_to_uint8;
namespace srsenb{ namespace srsenb{
s1ap::s1ap() :
thread("S1AP"),
rrc(nullptr),
s1ap_log(nullptr),
pool(nullptr),
mme_connected(false),
running(false),
next_eNB_UE_S1AP_ID(1),
next_ue_stream_id(1){};
s1ap::~s1ap(){};
bool s1ap::init(s1ap_args_t args_, rrc_interface_s1ap *rrc_, srslte::log *s1ap_log_) bool s1ap::init(s1ap_args_t args_, rrc_interface_s1ap *rrc_, srslte::log *s1ap_log_)
{ {
rrc = rrc_; rrc = rrc_;

@ -39,9 +39,7 @@ pthread_mutex_t mbms_gw_instance_mutex = PTHREAD_MUTEX_INITIALIZER;
const uint16_t MBMS_GW_BUFFER_SIZE = 2500; const uint16_t MBMS_GW_BUFFER_SIZE = 2500;
mbms_gw::mbms_gw(): mbms_gw::mbms_gw() : m_running(false), m_sgi_mb_up(false), thread("MBMS_GW")
m_running(false),
m_sgi_mb_up(false)
{ {
return; return;
} }

@ -31,7 +31,7 @@ namespace srsepc {
mme* mme::m_instance = NULL; mme* mme::m_instance = NULL;
pthread_mutex_t mme_instance_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mme_instance_mutex = PTHREAD_MUTEX_INITIALIZER;
mme::mme() : m_running(false) mme::mme() : m_running(false), thread("MME")
{ {
m_pool = srslte::byte_buffer_pool::get_instance(); m_pool = srslte::byte_buffer_pool::get_instance();
return; return;

@ -31,7 +31,7 @@ namespace srsepc {
spgw* spgw::m_instance = NULL; spgw* spgw::m_instance = NULL;
pthread_mutex_t spgw_instance_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t spgw_instance_mutex = PTHREAD_MUTEX_INITIALIZER;
spgw::spgw() : m_running(false) spgw::spgw() : m_running(false), thread("SPGW")
{ {
m_gtpc = new spgw::gtpc; m_gtpc = new spgw::gtpc;
m_gtpu = new spgw::gtpu; m_gtpu = new spgw::gtpu;

@ -45,7 +45,7 @@
namespace srsue { namespace srsue {
async_scell_recv::async_scell_recv() : thread() async_scell_recv::async_scell_recv() : thread("ASYNC_SCELL_RECV")
{ {
initiated = false; initiated = false;
buffer_write_idx = 0; buffer_write_idx = 0;

@ -42,7 +42,7 @@ using namespace asn1::rrc;
namespace srsue { namespace srsue {
phy::phy() : workers_pool(MAX_WORKERS), workers(0), common(MAX_WORKERS), scell_sync() phy::phy() : workers_pool(MAX_WORKERS), workers(0), common(MAX_WORKERS), scell_sync(), thread("PHY")
{ {
tdd_config = {}; tdd_config = {};
prach_cfg = {}; prach_cfg = {};

@ -42,7 +42,7 @@ double callback_set_rx_gain(void *h, double gain) {
return ((sync*)h)->set_rx_gain(gain); return ((sync*)h)->set_rx_gain(gain);
} }
sync::sync() sync::sync() : thread("SYNC")
{ {
cellsearch_earfcn_index = 0; cellsearch_earfcn_index = 0;
current_sflen = 0; current_sflen = 0;
@ -1665,7 +1665,7 @@ int sync::meas_stop(uint32_t earfcn, int pci)
return -1; return -1;
} }
sync::intra_measure::intra_measure() : scell() sync::intra_measure::intra_measure() : scell(), thread("SYNC_INTRA_MEASURE")
{ {
rrc = NULL; rrc = NULL;

@ -37,7 +37,7 @@ using namespace asn1::rrc;
namespace srsue { namespace srsue {
mac::mac() : timers(64), pdu_process_thread(&demux_unit), mch_msg(10), running(false), pcap(nullptr) mac::mac() : timers(64), pdu_process_thread(&demux_unit), mch_msg(10), running(false), pcap(nullptr), thread("MAC")
{ {
// Create PCell HARQ entities // Create PCell HARQ entities
auto ul = ul_harq_entity_ptr(new ul_harq_entity()); auto ul = ul_harq_entity_ptr(new ul_harq_entity());
@ -646,7 +646,7 @@ uint32_t mac::timer_get_unique_id()
* DEMUX unit * DEMUX unit
* *
*******************************************************/ *******************************************************/
mac::pdu_process::pdu_process(demux *demux_unit_) mac::pdu_process::pdu_process(demux* demux_unit_) : thread("MAC_PDU_PROCESS")
{ {
demux_unit = demux_unit_; demux_unit = demux_unit_;
pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&mutex, NULL);

@ -51,7 +51,8 @@ rrc::rrc() :
last_state(RRC_STATE_CONNECTED), last_state(RRC_STATE_CONNECTED),
drb_up(false), drb_up(false),
rlc_flush_timeout(2000), rlc_flush_timeout(2000),
rlc_flush_counter(0) rlc_flush_counter(0),
thread("RRC")
{ {
n310_cnt = 0; n310_cnt = 0;
n311_cnt = 0; n311_cnt = 0;

@ -69,8 +69,7 @@ namespace srsue {
#define DRB1_LCID 3 #define DRB1_LCID 3
gw::gw() gw::gw() : if_up(false), thread("GW")
:if_up(false)
{ {
current_ip_addr = 0; current_ip_addr = 0;
} }

Loading…
Cancel
Save