Skip to content

Commit

Permalink
minor threading fix, starting MTL/BTL interfaces for packet_flow/Simp…
Browse files Browse the repository at this point in the history
…leNetwork integration
  • Loading branch information
jjwilke committed Mar 8, 2016
1 parent 0e03795 commit aa8c0cc
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 108 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ sstmac/common/config.h.in
sstmac/common/config.h.in~

*.pyc

sstmac_repo.h
19 changes: 0 additions & 19 deletions sstmac/hardware/packet_flow/packet_flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,6 @@ class packet_flow_payload :
return min_num_bytes_per_packet_;
}

/**
@return Whether the parent message is being sent as a single
packet_flow, i.e. the parent message is smaller
than the min_bytes per train.
*/
bool
is_single_packet() const {
return num_bytes_total() <= min_num_bytes_per_packet_;
}

/**
@param num_bytes The number of bytes sent in a message
@return Whether num_bytes would be sent as a single packet train
*/
static bool
is_single_packet(uint64_t num_bytes) {
return num_bytes <= min_num_bytes_per_packet_;
}

/**
@return The number of bytes in this packet_flow, NOT
the total number of bytes in the parent message.
Expand Down
107 changes: 41 additions & 66 deletions sstmac/hardware/packet_flow/packet_flow_memory_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ SpktRegister("packet_flow", memory_model, packet_flow_memory_model);

//int packet_flow_memory_model::mtu_;

packet_flow_memory_sender::packet_flow_memory_sender(node* parent) :
packet_flow_memory_system::packet_flow_memory_system(int mtu, node* parent) :
packet_flow_MTL(mtu),
bw_noise_(0),
interval_noise_(0),
num_noisy_intervals_(0),
Expand All @@ -24,12 +25,8 @@ packet_flow_memory_sender::packet_flow_memory_sender(node* parent) :
}
}

packet_flow_memory_model::packet_flow_memory_model()
{
}

void
packet_flow_memory_sender::init_params(sprockit::sim_parameters *params)
packet_flow_memory_system::init_params(sprockit::sim_parameters *params)
{
max_single_bw_ = params->get_bandwidth_param("max_single_bandwidth");
max_bw_ = params->get_bandwidth_param("total_bandwidth");
Expand All @@ -38,24 +35,17 @@ packet_flow_memory_sender::init_params(sprockit::sim_parameters *params)
"arbitrator", "cut_through", params);
endpoint_ = packet_flow_endpoint_factory::get_optional_param(
"arbitrator", "cut_through", params);
/**
sstkeyword {
docstring=The minimum number of bytes a single packet train can contain.ENDL
Raising this value increases the coarseness and lowers the accuracy.;
};
*/
mtu_ = params->get_optional_int_param("mtu", 1<<30); //Defaults to huge value
}

void
packet_flow_memory_sender::set_event_parent(event_scheduler *m)
packet_flow_memory_system::set_event_parent(event_scheduler *m)
{
endpoint_->set_event_parent(m);
packet_flow_sender::set_event_parent(m);
}

void
packet_flow_memory_sender::finalize_init()
packet_flow_memory_system::finalize_init()
{
//in and out ar the same
arb_->set_outgoing_bw(max_bw_);
Expand All @@ -66,60 +56,59 @@ packet_flow_memory_sender::finalize_init()
}

void
packet_flow_memory_model::init_factory_params(sprockit::sim_parameters *params)
{
memory_model::init_factory_params(params);
max_single_bw_ = params->get_bandwidth_param("max_single_bandwidth");
sender_ = new packet_flow_memory_sender(parent_node_);
sender_->init_params(params);
sender_->finalize_init();
}

void
packet_flow_memory_sender::init_noise_model()
packet_flow_memory_system::init_noise_model()
{
if (bw_noise_){
arb_->partition(interval_noise_, num_noisy_intervals_);
arb_->init_noise_model(bw_noise_);
}
}

packet_flow_memory_model::~packet_flow_memory_model()
int
packet_flow_memory_system::num_initial_credits() const
{
//if (bw_noise_) delete bw_noise_;
//bw_noise_ = 0;
spkt_throw_printf(sprockit::value_error,
"packet_flow_memory_model::num_initial_credits: should never be called");
}

void
packet_flow_memory_model::finalize_init()
packet_flow_memory_model::init_factory_params(sprockit::sim_parameters *params)
{
memory_model::finalize_init();
memory_model::init_factory_params(params);
int mtu = params->get_optional_int_param("mtu", 1<<30); //Defaults to huge value
max_single_bw_ = params->get_bandwidth_param("max_single_bandwidth");
mem_sys_ = new packet_flow_memory_system(mtu, parent_node_);
mem_sys_->init_params(params);
mem_sys_->finalize_init();
}

int
packet_flow_memory_sender::num_initial_credits() const
packet_flow_memory_model::~packet_flow_memory_model()
{
spkt_throw_printf(sprockit::value_error,
"packet_flow_memory_model::num_initial_credits: should never be called");
}

void
packet_flow_memory_model::finalize_init()
{
memory_model::finalize_init();
}

void
packet_flow_memory_model::set_event_parent(event_scheduler* m)
{
memory_model::set_event_parent(m);
sender_->set_event_parent(m);
mem_sys_->set_event_parent(m);
}

void
packet_flow_memory_model::access(const sst_message::ptr& msg)
{
sw::compute_message::ptr cmsg = ptr_safe_cast(sw::compute_message, msg);
cmsg->set_access_id(parent_node_->allocate_unique_id());
sender_->start(msg);
mem_sys_->mtl_send(msg);
}

int
packet_flow_memory_sender::allocate_channel()
packet_flow_memory_system::allocate_channel()
{
if (channels_available_.empty()){
int oldsize = pending_.size();
Expand All @@ -136,11 +125,13 @@ packet_flow_memory_sender::allocate_channel()
}

void
packet_flow_memory_sender::start(const sst_message::ptr& msg)
packet_flow_memory_system::mtl_send(const sst_message::ptr &msg)
{
sw::compute_message::ptr cmsg = ptr_safe_cast(sw::compute_message, msg);

packet_flow_payload::ptr payload = next_chunk(0L, cmsg);
if (cmsg->max_bw() != 0){
payload->set_bw(cmsg->max_bw());
}

if (!payload->is_tail()){
int channel = allocate_channel();
Expand All @@ -156,10 +147,8 @@ packet_flow_memory_sender::start(const sst_message::ptr& msg)

handle_payload(payload);
}


void
packet_flow_memory_sender::do_handle_payload(const packet_flow_payload::ptr& msg)
packet_flow_memory_system::do_handle_payload(const packet_flow_payload::ptr& msg)
{
//set the bandwidth to the max single bw
msg->init_bw(max_single_bw_);
Expand All @@ -181,47 +170,29 @@ packet_flow_memory_sender::do_handle_payload(const packet_flow_payload::ptr& msg
}

void
packet_flow_memory_sender::send_to_endpoint(timestamp finish, const packet_flow_payload::ptr& msg)
packet_flow_memory_system::send_to_endpoint(timestamp finish, const packet_flow_payload::ptr& msg)
{
SCHEDULE(finish, endpoint_, msg);
}

void
packet_flow_memory_sender::set_input(int my_inport, int dst_outport, event_handler* input)
packet_flow_memory_system::set_input(int my_inport, int dst_outport, event_handler* input)
{

}

void
packet_flow_memory_sender::set_output(int my_outport, int dst_inport, event_handler* output)
packet_flow_memory_system::set_output(int my_outport, int dst_inport, event_handler* output)
{
}

void
packet_flow_memory_sender::init_credits(int port, int num_credits)
packet_flow_memory_system::init_credits(int port, int num_credits)
{
}

packet_flow_payload::ptr
packet_flow_memory_sender::next_chunk(long byte_offset, const sw::compute_message::ptr& parent)
{
long bytes_left = parent->byte_length() - byte_offset;
long bytes_to_send = bytes_left > mtu_ ? mtu_ : bytes_left;

packet_flow_payload::ptr payload = new packet_flow_payload(
parent,
bytes_to_send, //only a single message
byte_offset);

if (parent->max_bw() != 0){
payload->set_bw(parent->max_bw());
}

return payload;
}

void
packet_flow_memory_sender::handle_credit(const packet_flow_credit::ptr& msg)
packet_flow_memory_system::handle_credit(const packet_flow_credit::ptr& msg)
{
int channel = msg->port();
pending_msg& p = pending_[channel];
Expand All @@ -230,6 +201,10 @@ packet_flow_memory_sender::handle_credit(const packet_flow_credit::ptr& msg)
// msg->num_credits(), channel);

packet_flow_payload::ptr payload = next_chunk(p.byte_offset, p.msg);
if (p.msg->max_bw() != 0){
payload->set_bw(p.msg->max_bw());
}

payload->set_inport(channel);
p.byte_offset += payload->num_bytes();

Expand Down
30 changes: 11 additions & 19 deletions sstmac/hardware/packet_flow/packet_flow_memory_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
namespace sstmac {
namespace hw {

class packet_flow_memory_sender :
public packet_flow_sender
class packet_flow_memory_system :
public packet_flow_sender,
public packet_flow_MTL
{
public:
packet_flow_memory_sender(node* parent_node);
packet_flow_memory_system(int mtu, node* parent_node);

std::string
packet_flow_name() const {
Expand All @@ -39,28 +40,24 @@ class packet_flow_memory_sender :
void
set_output(int my_outport, int dst_inport, event_handler* output);

virtual void
start(const sst_message::ptr& msg);
void start(const sst_message::ptr &msg){}

virtual void
init_params(sprockit::sim_parameters* params);

int
allocate_channel();

packet_flow_payload::ptr
next_chunk(long byte_offset, const sw::compute_message::ptr& parent);

void finalize_init();

void init_noise_model();

void
set_event_parent(event_scheduler *m);
void set_event_parent(event_scheduler *m);

void mtl_send(const sst_message::ptr& msg);

private:
void send_to_endpoint(timestamp t, const packet_flow_payload::ptr& msg);

int allocate_channel();

private:
double max_bw_;
double max_single_bw_;
Expand All @@ -76,9 +73,6 @@ class packet_flow_memory_sender :
long byte_offset;
sw::compute_message::ptr msg;
};

int mtu_;

std::vector<pending_msg> pending_;
std::list<int> channels_available_;

Expand All @@ -92,8 +86,6 @@ class packet_flow_memory_model :
public memory_model
{
public:
packet_flow_memory_model();

virtual ~packet_flow_memory_model();

void
Expand Down Expand Up @@ -126,7 +118,7 @@ class packet_flow_memory_model :
//static int mtu_;
double max_single_bw_;

packet_flow_memory_sender* sender_;
packet_flow_memory_system* mem_sys_;
};

}
Expand Down
16 changes: 14 additions & 2 deletions sstmac/hardware/packet_flow/packet_flow_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
namespace sstmac {
namespace hw {

packet_flow_payload::ptr
packet_flow_MTL::next_chunk(long byte_offset, const sst_message::ptr &parent)
{
long bytes_left = parent->byte_length() - byte_offset;
long bytes_to_send = bytes_left > mtu_ ? mtu_ : bytes_left;

packet_flow_payload::ptr payload = new packet_flow_payload(
parent,
bytes_to_send, //only a single message
byte_offset);

return payload;
}

packet_flow_sender::packet_flow_sender(
const timestamp& send_lat,
const timestamp& credit_lat)
Expand Down Expand Up @@ -48,9 +62,7 @@ packet_flow_sender::send_credit(
payload->to_string().c_str(),
credit_arrival.sec(), credit_lat_.sec(),
credit.get());
START_VALID_SCHEDULE(this)
schedule(credit_arrival, src.handler, credit);
STOP_VALID_SCHEDULE(this)
}

void
Expand Down
15 changes: 15 additions & 0 deletions sstmac/hardware/packet_flow/packet_flow_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
namespace sstmac {
namespace hw {

class packet_flow_MTL
{
public:
packet_flow_MTL(int mtu) : mtu_(mtu) {}

virtual void mtl_send(const sst_message::ptr& msg) = 0;

packet_flow_payload::ptr
next_chunk(long byte_offset, const sst_message::ptr& parent);

private:
int mtu_;

};

class packet_flow_sender :
public packet_flow_handler
{
Expand Down
Loading

0 comments on commit aa8c0cc

Please sign in to comment.