Git Product home page Git Product logo

Comments (6)

jafingerhut avatar jafingerhut commented on August 20, 2024

Interesting find.

I am not familiar enough with this code to be certain, but I would not be surprised if this set_source_info() call here: https://github.com/p4lang/behavioral-model/blob/main/src/bm_sim/actions.cpp#L371

would be best done once at P4 program load time, rather than once every time an action is invoked while processing a packet. That would be somewhat more efficient, as well as hopefully avoiding this data race.

from behavioral-model.

antoninbas avatar antoninbas commented on August 20, 2024

would be best done once at P4 program load time, rather than once every time an action is invoked while processing a packet. That would be somewhat more efficient, as well as hopefully avoiding this data race.

This was my first thought, but it is not an option here. There is a single ActionPrimitive object instantiated for each primitive action, and it is shared by all pipelines whenever the primitive is executed, no matter which action it is executed from.

The source info we store here is related to the primitive action "call", and so it depends on the location of the actual call site. On primitive can be used many times in a given program.

Fortunately, there is a simple fix here. The field needs to be switched to a static thread_local one. It is no different from how the pkt and phv fields are handled.

// This used to be regular members in ActionPrimitive, but there could be a
// race condition. Making them thread_local solves the issue. I moved these
// from ActionPrimitive because g++4.8 has a bug when using thread_local class
// variables with templates
// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60056).
static thread_local Packet *pkt;
static thread_local PHV *phv;
SourceInfo *call_source_info{nullptr};

I can take care of it a bit later, unless someone wants to beat me to it.

from behavioral-model.

matthewtlam avatar matthewtlam commented on August 20, 2024

Sorry, I got a bit confused regarding which field you are referring to that needs to be switched to a static thread_local

from behavioral-model.

antoninbas avatar antoninbas commented on August 20, 2024

I included a code snippet in my post. It's the only field shown there that is not static thread_local.

from behavioral-model.

matthewtlam avatar matthewtlam commented on August 20, 2024

I tried to change the field to a static thread_local SourceInfo *call_source_info. I had issues with building and running my tests. Not entirely clear what's wrong.

error: undefined symbol: bm::ActionPrimitive_::call_source_info
>>> referenced by primitives.cpp
>>>               blaze-out/k8-fastbuild/bin/third_party/p4lang_behavioral_model/_objs/bm_sim/primitives.pic.o:(bm::core::assert_::operator()(bm::Data const&))
>>> referenced by primitives.cpp
>>>               blaze-out/k8-fastbuild/bin/third_party/p4lang_behavioral_model/_objs/bm_sim/primitives.pic.o:(bm::core::assume_::operator()(bm::Data const&))
>>> referenced by primitives.cpp
>>>               blaze-out/k8-fastbuild/bin/third_party/p4lang_behavioral_model/_objs/bm_sim/primitives.pic.o:(bm::core::log_msg::operator()(std::__u::basic_string<char, std::__u::char_traits<char>, std::__u::allocator<char>> const&, std::__u::vector<bm::Data, std::__u::allocator<bm::Data>>))
>>> referenced 2 more times
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I see that there are references to call_source_info inside other files like primitives.cpp from a quick search, not particularly sure if these get affected or not.

from behavioral-model.

antoninbas avatar antoninbas commented on August 20, 2024

Did you define the static field in actions.cpp as well?

thread_local Packet *ActionPrimitive_::pkt = nullptr;
thread_local PHV *ActionPrimitive_::phv = nullptr;

from behavioral-model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.