Skip to content

Commit

Permalink
Merge pull request #1189 from sstsimulator/devel
Browse files Browse the repository at this point in the history
Automatically Merged using SST Master Branch Merger
  • Loading branch information
sst-autotester authored Dec 22, 2024
2 parents 744bb94 + 357aa44 commit e66203b
Show file tree
Hide file tree
Showing 21 changed files with 945 additions and 334 deletions.
1 change: 0 additions & 1 deletion src/sst/core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ sst_core_sources = \
unitAlgebra.cc \
module.cc \
realtime.cc \
ssthandler.cc \
sstpart.cc \
timeVortex.cc \
serialization/objectMap.cc \
Expand Down
6 changes: 3 additions & 3 deletions src/sst/core/baseComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ BaseComponent::registerClock_impl(TimeConverter* tc, Clock::HandlerBase* handler
for ( auto* tool : tools ) {
ClockHandlerMetaData mdata(my_info->getID(), getName(), getType());
// Add the receive profiler to the handler
handler->addProfileTool(tool, mdata);
handler->attachTool(tool, mdata);
}

// if regAll is true set tc as the default for the component and
Expand Down Expand Up @@ -295,10 +295,10 @@ BaseComponent::configureLink(const std::string& name, TimeConverter* time_base,
EventHandlerMetaData mdata(my_info->getID(), getName(), getType(), name);

// Add the receive profiler to the handler
if ( tool->profileReceives() ) handler->addProfileTool(tool, mdata);
if ( tool->profileReceives() ) handler->attachTool(tool, mdata);

// Add the send profiler to the link
if ( tool->profileSends() ) tmp->addProfileTool(tool, mdata);
if ( tool->profileSends() ) tmp->attachTool(tool, mdata);
}
}
if ( nullptr != time_base )
Expand Down
2 changes: 1 addition & 1 deletion src/sst/core/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Clock : public Action
};


class ClockHandlerMetaData : public HandlerMetaData
class ClockHandlerMetaData : public AttachPointMetaData
{
public:
const ComponentId_t comp_id;
Expand Down
2 changes: 1 addition & 1 deletion src/sst/core/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class EmptyEvent : public Event
ImplementSerializable(SST::EmptyEvent)
};

class EventHandlerMetaData : public HandlerMetaData
class EventHandlerMetaData : public AttachPointMetaData
{
public:
const ComponentId_t comp_id;
Expand Down
39 changes: 12 additions & 27 deletions src/sst/core/link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,28 +461,6 @@ class NullEvent : public Event
};


class LinkSendProfileToolList
{
public:
LinkSendProfileToolList() {}

inline void eventSent(Event* ev)
{
for ( auto& x : tools ) {
x.first->eventSent(x.second, ev);
}
}

void addProfileTool(SST::Profile::EventHandlerProfileTool* tool, const EventHandlerMetaData& mdata)
{
auto key = tool->registerHandler(mdata);
tools.push_back(std::make_pair(tool, key));
}

private:
std::vector<std::pair<SST::Profile::EventHandlerProfileTool*, uintptr_t>> tools;
};

Link::Link(LinkId_t tag) :
send_queue(nullptr),
delivery_info(0),
Expand Down Expand Up @@ -631,7 +609,7 @@ Link::replaceFunctor(Event::HandlerBase* functor)
type = HANDLER;
if ( pair_link->delivery_info ) {
auto* handler = reinterpret_cast<Event::HandlerBase*>(pair_link->delivery_info);
functor->transferProfilingInfo(handler);
functor->transferAttachedToolInfo(handler);
delete handler;
}
pair_link->delivery_info = reinterpret_cast<uintptr_t>(functor);
Expand Down Expand Up @@ -663,7 +641,13 @@ Link::send_impl(SimTime_t delay, Event* event)
event->addRecvComponent(pair_link->comp, pair_link->ctype, pair_link->port);
#endif

if ( profile_tools ) profile_tools->eventSent(event);
if ( profile_tools ) {
for ( auto& x : *profile_tools ) {
x.first->eventSent(x.second, event);
// Check to see if the event was deleted. If so, return.
if ( nullptr == event ) return;
}
}
send_queue->insert(event);
}

Expand Down Expand Up @@ -803,10 +787,11 @@ Link::createUniqueGlobalLinkName(RankInfo local_rank, uintptr_t local_ptr, RankI
}

void
Link::addProfileTool(SST::Profile::EventHandlerProfileTool* tool, const EventHandlerMetaData& mdata)
Link::attachTool(AttachPoint* tool, const AttachPointMetaData& mdata)
{
if ( !profile_tools ) profile_tools = new LinkSendProfileToolList();
profile_tools->addProfileTool(tool, mdata);
if ( !profile_tools ) profile_tools = new ToolList();
auto key = tool->registerLinkAttachTool(mdata);
profile_tools->push_back(std::make_pair(tool, key));
}


Expand Down
43 changes: 40 additions & 3 deletions src/sst/core/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class LinkPair;
class Simulation_impl;

class UnitAlgebra;
class LinkSendProfileToolList;

namespace Profile {
class EventHandlerProfileTool;
Expand Down Expand Up @@ -56,6 +55,43 @@ class alignas(64) Link
friend class SST::Core::Serialization::serialize_impl<Link*>;

public:
/**
Attach point for inspecting, modifying or dropping events
sent on the Link.
NOTE: Using the Link::AttachPoint will noticeably affect the
performance of sending events on Links and it is recommended
that, if possible, Event::HandlerBase::AttachPoint or
Event::HandlerBase::InterceptPoint be used instead.
*/
class AttachPoint
{
public:
/**
Function that will be called when an attach point is
registered with the tool implementing the attach point.
The metadata passed in will be dependent on what type of
tool this is attached to. The uintptr_t returned from this
function will be passed into the eventSent() function.
@param mdata Metadata to be passed into the tool
@return Opaque key that will be passed back into
eventSent() to identify the source of the call
*/
virtual uintptr_t registerLinkAttachTool(const AttachPointMetaData& mdata) = 0;

/**
Function that will be called when an event is sent on a
link with registered attach points. If ev is set to
nullptr, then the event will not be delivered and the tool
should delete the original event.
@param key Opaque key returned from registerLinkAttachTool()
*/
virtual void eventSent(uintptr_t key, Event*& ev) = 0;
};

friend class LinkPair;
friend class RankSync;
friend class ThreadSync;
Expand Down Expand Up @@ -285,10 +321,11 @@ class alignas(64) Link
createUniqueGlobalLinkName(RankInfo local_rank, uintptr_t local_ptr, RankInfo remote_rank, uintptr_t remote_ptr);


void addProfileTool(SST::Profile::EventHandlerProfileTool* tool, const EventHandlerMetaData& mdata);
void attachTool(AttachPoint* tool, const AttachPointMetaData& mdata);


LinkSendProfileToolList* profile_tools;
using ToolList = std::vector<std::pair<AttachPoint*, uintptr_t>>;
ToolList* profile_tools;


#ifdef __SST_DEBUG_EVENT_TRACKING__
Expand Down
10 changes: 5 additions & 5 deletions src/sst/core/profile/clockHandlerProfileTool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace SST {
namespace Profile {


ClockHandlerProfileTool::ClockHandlerProfileTool(const std::string& name, Params& params) : HandlerProfileToolAPI(name)
ClockHandlerProfileTool::ClockHandlerProfileTool(const std::string& name, Params& params) : ProfileTool(name)
{
std::string level = params.find<std::string>("level", "type");
if ( level == "global" )
Expand All @@ -41,7 +41,7 @@ ClockHandlerProfileTool::ClockHandlerProfileTool(const std::string& name, Params
}

std::string
ClockHandlerProfileTool::getKeyForHandler(const HandlerMetaData& mdata)
ClockHandlerProfileTool::getKeyForHandler(const AttachPointMetaData& mdata)
{
const ClockHandlerMetaData& data = dynamic_cast<const ClockHandlerMetaData&>(mdata);

Expand Down Expand Up @@ -71,13 +71,13 @@ ClockHandlerProfileToolCount::ClockHandlerProfileToolCount(const std::string& na
{}

uintptr_t
ClockHandlerProfileToolCount::registerHandler(const HandlerMetaData& mdata)
ClockHandlerProfileToolCount::registerHandler(const AttachPointMetaData& mdata)
{
return reinterpret_cast<uintptr_t>(&counts_[getKeyForHandler(mdata)]);
}

void
ClockHandlerProfileToolCount::handlerStart(uintptr_t key)
ClockHandlerProfileToolCount::beforeHandler(uintptr_t key, const Cycle_t& UNUSED(cycle))
{
(*reinterpret_cast<uint64_t*>(key))++;
}
Expand All @@ -101,7 +101,7 @@ ClockHandlerProfileToolTime<T>::ClockHandlerProfileToolTime(const std::string& n

template <typename T>
uintptr_t
ClockHandlerProfileToolTime<T>::registerHandler(const HandlerMetaData& mdata)
ClockHandlerProfileToolTime<T>::registerHandler(const AttachPointMetaData& mdata)
{
return reinterpret_cast<uintptr_t>(&times_[getKeyForHandler(mdata)]);
}
Expand Down
21 changes: 13 additions & 8 deletions src/sst/core/profile/clockHandlerProfileTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace SST {
namespace Profile {


class ClockHandlerProfileTool : public HandlerProfileToolAPI
class ClockHandlerProfileTool : public ProfileTool, public Clock::HandlerBase::AttachPoint
{
public:
SST_ELI_REGISTER_PROFILETOOL_DERIVED_API(SST::Profile::ClockHandlerProfileTool, SST::HandlerProfileToolAPI, Params&)
SST_ELI_REGISTER_PROFILETOOL_DERIVED_API(SST::Profile::ClockHandlerProfileTool, SST::Profile::ProfileTool, Params&)

SST_ELI_DOCUMENT_PARAMS(
{ "level", "Level at which to track profile (global, type, component, subcomponent)", "type" },
Expand All @@ -39,8 +39,13 @@ class ClockHandlerProfileTool : public HandlerProfileToolAPI

ClockHandlerProfileTool(const std::string& name, Params& params);

// Default implementations of attach point functions for profile
// tools that don't use them
void beforeHandler(uintptr_t UNUSED(key), const Cycle_t& UNUSED(cycle)) override {}
void afterHandler(uintptr_t UNUSED(key), const bool& UNUSED(remove)) override {}

protected:
std::string getKeyForHandler(const HandlerMetaData& mdata);
std::string getKeyForHandler(const AttachPointMetaData& mdata);

Profile_Level profile_level_;
};
Expand All @@ -66,9 +71,9 @@ class ClockHandlerProfileToolCount : public ClockHandlerProfileTool

virtual ~ClockHandlerProfileToolCount() {}

uintptr_t registerHandler(const HandlerMetaData& mdata) override;
uintptr_t registerHandler(const AttachPointMetaData& mdata) override;

void handlerStart(uintptr_t key) override;
void beforeHandler(uintptr_t key, const Cycle_t& cycle) override;

void outputData(FILE* fp) override;

Expand Down Expand Up @@ -96,11 +101,11 @@ class ClockHandlerProfileToolTime : public ClockHandlerProfileTool

virtual ~ClockHandlerProfileToolTime() {}

uintptr_t registerHandler(const HandlerMetaData& mdata) override;
uintptr_t registerHandler(const AttachPointMetaData& mdata) override;

void handlerStart(uintptr_t UNUSED(key)) override { start_time_ = T::now(); }
void beforeHandler(uintptr_t UNUSED(key), const Cycle_t& UNUSED(cycle)) override { start_time_ = T::now(); }

void handlerEnd(uintptr_t key) override
void afterHandler(uintptr_t key, const bool& UNUSED(remove)) override
{
auto total_time = T::now() - start_time_;
clock_data_t* entry = reinterpret_cast<clock_data_t*>(key);
Expand Down
25 changes: 19 additions & 6 deletions src/sst/core/profile/eventHandlerProfileTool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace SST {
namespace Profile {


EventHandlerProfileTool::EventHandlerProfileTool(const std::string& name, Params& params) : HandlerProfileToolAPI(name)
EventHandlerProfileTool::EventHandlerProfileTool(const std::string& name, Params& params) : ProfileTool(name)
{
std::string level = params.find<std::string>("level", "type");
if ( level == "global" )
Expand All @@ -46,7 +46,7 @@ EventHandlerProfileTool::EventHandlerProfileTool(const std::string& name, Params
}

std::string
EventHandlerProfileTool::getKeyForHandler(const HandlerMetaData& mdata)
EventHandlerProfileTool::getKeyForHandler(const AttachPointMetaData& mdata)
{
const EventHandlerMetaData& data = dynamic_cast<const EventHandlerMetaData&>(mdata);

Expand Down Expand Up @@ -78,19 +78,25 @@ EventHandlerProfileToolCount::EventHandlerProfileToolCount(const std::string& na
{}

uintptr_t
EventHandlerProfileToolCount::registerHandler(const HandlerMetaData& mdata)
EventHandlerProfileToolCount::registerHandler(const AttachPointMetaData& mdata)
{
return reinterpret_cast<uintptr_t>(&counts_[getKeyForHandler(mdata)]);
}

uintptr_t
EventHandlerProfileToolCount::registerLinkAttachTool(const AttachPointMetaData& mdata)
{
return reinterpret_cast<uintptr_t>(&counts_[getKeyForHandler(mdata)]);
}

void
EventHandlerProfileToolCount::handlerStart(uintptr_t key)
EventHandlerProfileToolCount::beforeHandler(uintptr_t key, const Event* UNUSED(event))
{
reinterpret_cast<event_data_t*>(key)->recv_count++;
}

void
EventHandlerProfileToolCount::eventSent(uintptr_t key, Event* UNUSED(ev))
EventHandlerProfileToolCount::eventSent(uintptr_t key, Event*& UNUSED(ev))
{
reinterpret_cast<event_data_t*>(key)->send_count++;
}
Expand Down Expand Up @@ -120,7 +126,14 @@ EventHandlerProfileToolTime<T>::EventHandlerProfileToolTime(const std::string& n

template <typename T>
uintptr_t
EventHandlerProfileToolTime<T>::registerHandler(const HandlerMetaData& mdata)
EventHandlerProfileToolTime<T>::registerHandler(const AttachPointMetaData& mdata)
{
return reinterpret_cast<uintptr_t>(&times_[getKeyForHandler(mdata)]);
}

template <typename T>
uintptr_t
EventHandlerProfileToolTime<T>::registerLinkAttachTool(const AttachPointMetaData& mdata)
{
return reinterpret_cast<uintptr_t>(&times_[getKeyForHandler(mdata)]);
}
Expand Down
Loading

0 comments on commit e66203b

Please sign in to comment.