"git@developer.sourcefind.cn:modelzoo/resnet50_tensorflow.git" did not exist on "56bbc17eca8ac2fb68e958d6271c97af17ddebdb"
Commit 759ff692 authored by Antoine Kaufmann's avatar Antoine Kaufmann Committed by Antoine Kaufmann
Browse files

sims/nic/i40e_bm: fix logger segfault due to constructor

Depending on the order some of the constructors get executed, instances of the
logger can end up with a null pointer for the runner. This led to a segfault
when calling TimePs() on that nullptr.

Here we fix this in two steps: first the logger takes a device pointer, which
in turn contains a pointer to the runner that will eventually be initialized.
Also fix up the logger to simply use 0 as a timestamp for log events before the
runner is there.
parent b94ddfc7
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
namespace i40e { namespace i40e {
i40e_bm::i40e_bm() i40e_bm::i40e_bm()
: log("i40e", runner_), : log("i40e", *this),
pf_atq(*this, regs.pf_atqba, regs.pf_atqlen, regs.pf_atqh, regs.pf_atqt), pf_atq(*this, regs.pf_atqba, regs.pf_atqlen, regs.pf_atqh, regs.pf_atqt),
hmc(*this), hmc(*this),
shram(*this), shram(*this),
...@@ -754,7 +754,7 @@ void i40e_bm::reset(bool indicate_done) { ...@@ -754,7 +754,7 @@ void i40e_bm::reset(bool indicate_done) {
regs.glrpb_plw = 0x0846; regs.glrpb_plw = 0x0846;
} }
shadow_ram::shadow_ram(i40e_bm &dev_) : dev(dev_), log("sram", dev_.runner_) { shadow_ram::shadow_ram(i40e_bm &dev_) : dev(dev_), log("sram", dev_) {
} }
void shadow_ram::reg_updated() { void shadow_ram::reg_updated() {
......
...@@ -68,11 +68,12 @@ class logger : public std::ostream { ...@@ -68,11 +68,12 @@ class logger : public std::ostream {
protected: protected:
std::string label; std::string label;
nicbm::Runner::Device &dev;
nicbm::Runner *runner; nicbm::Runner *runner;
std::stringstream ss; std::stringstream ss;
public: public:
explicit logger(const std::string &label_, nicbm::Runner *runner_); explicit logger(const std::string &label_, nicbm::Runner::Device &dev_);
logger &operator<<(char c); logger &operator<<(char c);
logger &operator<<(int32_t c); logger &operator<<(int32_t c);
logger &operator<<(uint8_t i); logger &operator<<(uint8_t i);
......
...@@ -37,7 +37,7 @@ namespace i40e { ...@@ -37,7 +37,7 @@ namespace i40e {
lan::lan(i40e_bm &dev_, size_t num_qs_) lan::lan(i40e_bm &dev_, size_t num_qs_)
: dev(dev_), : dev(dev_),
log("lan", dev_.runner_), log("lan", dev_),
rss_kc(dev_.regs.pfqf_hkey), rss_kc(dev_.regs.pfqf_hkey),
num_qs(num_qs_) { num_qs(num_qs_) {
rxqs = new lan_queue_rx *[num_qs]; rxqs = new lan_queue_rx *[num_qs];
......
...@@ -37,7 +37,7 @@ namespace i40e { ...@@ -37,7 +37,7 @@ namespace i40e {
queue_base::queue_base(const std::string &qname_, uint32_t &reg_head_, queue_base::queue_base(const std::string &qname_, uint32_t &reg_head_,
uint32_t &reg_tail_, i40e_bm &dev_) uint32_t &reg_tail_, i40e_bm &dev_)
: qname(qname_), : qname(qname_),
log(qname_, dev_.runner_), log(qname_, dev_),
dev(dev_), dev(dev_),
active_first_pos(0), active_first_pos(0),
active_first_idx(0), active_first_idx(0),
......
...@@ -28,15 +28,26 @@ ...@@ -28,15 +28,26 @@
namespace i40e { namespace i40e {
logger::logger(const std::string &label_, nicbm::Runner *runner_) logger::logger(const std::string &label_, nicbm::Runner::Device &dev_)
: label(label_), runner(runner_) { : label(label_), dev(dev_), runner(dev_.runner_) {
ss << std::hex; ss << std::hex;
} }
logger &logger::operator<<(char c) { logger &logger::operator<<(char c) {
if (c == endl) { if (c == endl) {
std::cerr << runner->TimePs() << " " << label << ": " << ss.str() uint64_t ts;
<< std::endl;
/* runner might not be initialized yet if called from a constructor
* somewhere, in that case see if it's set now otherwise just take 0 as the
* current timestamp. */
if (!runner) {
runner = dev.runner_;
ts = runner ? runner->TimePs() : 0;
} else {
ts = runner->TimePs();
}
std::cerr << ts << " " << label << ": " << ss.str() << std::endl;
ss.str(std::string()); ss.str(std::string());
ss << std::hex; ss << std::hex;
} else { } else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment