• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/core/cpunicEvent.h

00001 // Copyright 2009-2010 Sandia Corporation. Under the terms
00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
00003 // Government retains certain rights in this software.
00004 // 
00005 // Copyright (c) 2009-2010, Sandia Corporation
00006 // All rights reserved.
00007 // 
00008 // This file is part of the SST software package. For license
00009 // information, see the LICENSE file in the top level directory of the
00010 // distribution.
00011 
00012 
00013 // This type of event is used to transmit an arbitrary chunk of
00014 // data between a CPU and an attached NIC. I guess it could be
00015 // used anywhere a chunk of data and length is sufficient.
00016 //
00017 // The idea is to pack netsim API info into a data structure and
00018 // send it off to the NIC which will know what to do with the
00019 // data.
00020 //
00021 #ifndef SST_CPUNICEVENT_H
00022 #define SST_CPUNICEVENT_H
00023 
00024 #include <cstring>
00025 
00026 #include "sst/core/event.h"
00027 
00028 namespace SST {
00029 
00030 // We hardcode this here so we don't have to include netsim_internal.h
00031 #define CPUNICEVENT_MAX_PARAMS          (64)
00032 
00033 class CPUNicEvent : public Event {
00034     public:
00035         CPUNicEvent() : Event()   {
00036             params_present= false;
00037             params_len= 0;
00038             routine= -1;
00039             payload_len= 0;
00040             payload_present= false;
00041             hops= 0;
00042             congestion_cnt= 0;
00043             congestion_delay= 0;
00044             entry_port= -1;
00045             dest= -1;
00046             local_traffic= false;
00047             msg_id= 0;
00048         }
00049 
00050         // How to route this event through the network
00051         std::vector<int>route;
00052         std::vector<int>reverse_route; // Needed for bit_bucket
00053         SimTime_t router_delay;
00054         int hops;
00055         long long congestion_cnt;
00056         SimTime_t congestion_delay;
00057 
00058         // If this is data between cores sharing a cache, do not count
00059         // this as a router access.
00060         bool local_traffic;
00061 
00062         // The router model uses this to carry over input port info
00063         int entry_port;
00064 
00065         // Bit bucket uses this event on return sends.
00066         int return_event;
00067 
00068         // The destination rank for routing verification purposes
00069         int dest;
00070         uint64_t msg_id;// Each message event should have a unique ID for debugging
00071 
00072         // Some envelope info
00073         uint64_t msg_match_bits;
00074         uint64_t buf;
00075         uint32_t msg_len;
00076 
00077         // Functions to attach and detach parameters
00078         inline void AttachParams(const void *input, int len)   {
00079             if (len > CPUNICEVENT_MAX_PARAMS)   {
00080                 _ABORT(CPUNicEvent, "Only have room for %d bytes!!\n", CPUNICEVENT_MAX_PARAMS);
00081             }
00082             params_present= true;
00083             params_len= len;
00084             std::memcpy(event_params, input, len);
00085         }
00086 
00087         inline void DetachParams(void *output, int *len)   {
00088             if (!params_present)   {
00089                 _ABORT(CPUNicEvent, "No params present!\n");
00090             }
00091             if (*len > CPUNICEVENT_MAX_PARAMS)   {
00092                 _ABORT(CPUNicEvent, "Can't detach %d bytes. Only have %d bytes (%d max) of params!!\n",
00093                     *len, params_len, CPUNICEVENT_MAX_PARAMS);
00094             }
00095             if ((int) params_len > *len)   {
00096                 _ABORT(CPUNicEvent, "Have %d bytes of params, but user only wants %d!\n",
00097                     params_len, *len);
00098             }
00099 
00100             std::memcpy(output, event_params, params_len);
00101             *len= params_len;
00102         }
00103 
00104         inline void SetRoutine(int r)   {
00105             routine= r;
00106         }
00107 
00108         inline int GetRoutine(void)   {
00109             return routine;
00110         }
00111 
00112 
00113 
00114         // Functions to attach and detach a message payload
00115         inline void AttachPayload(const char *payload, int len)   {
00116             if (payload_present)   {
00117                 _ABORT(NicEvent, "Payload data already present!\n");
00118             }
00119             payload_present= true;
00120             msg_payload.reserve(len);
00121             payload_len= len;
00122             msg_payload.insert(msg_payload.end(), payload, payload + len);
00123         }
00124 
00125         inline void DetachPayload(void *output, int *len)   {
00126             if (!payload_present)   {
00127                 _ABORT(CPUNicEvent, "No payload present!\n");
00128             }
00129             if (*len > payload_len)   {
00130                 _ABORT(CPUNicEvent, "Have %d bytes of payload, but user wants %d!\n",
00131                     payload_len, *len);
00132             }
00133 
00134             std::memcpy(output, &msg_payload[0], payload_len);
00135             *len= payload_len;
00136         }
00137 
00138         inline int GetPayloadLen(void)   {
00139             return payload_len;
00140         }
00141 
00142 
00143     private:
00144         bool params_present;
00145         int routine;
00146         unsigned int params_len;
00147         uint8_t event_params[CPUNICEVENT_MAX_PARAMS];
00148         std::vector<uint8_t>msg_payload;
00149         bool payload_present;
00150         int payload_len;
00151 
00152         friend class boost::serialization::access;
00153         template<class Archive>
00154         void serialize(Archive & ar, const unsigned int version )
00155         {
00156             ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Event);
00157             ar & BOOST_SERIALIZATION_NVP(route);
00158             ar & BOOST_SERIALIZATION_NVP(reverse_route);
00159             ar & BOOST_SERIALIZATION_NVP(router_delay);
00160             ar & BOOST_SERIALIZATION_NVP(hops);
00161             ar & BOOST_SERIALIZATION_NVP(congestion_cnt);
00162             ar & BOOST_SERIALIZATION_NVP(congestion_delay);
00163             ar & BOOST_SERIALIZATION_NVP(msg_match_bits);
00164             ar & BOOST_SERIALIZATION_NVP(msg_len);
00165             ar & BOOST_SERIALIZATION_NVP(event_params);
00166             ar & BOOST_SERIALIZATION_NVP(routine);
00167             ar & BOOST_SERIALIZATION_NVP(params_len);
00168             ar & BOOST_SERIALIZATION_NVP(params_present);
00169             ar & BOOST_SERIALIZATION_NVP(payload_len);
00170             ar & BOOST_SERIALIZATION_NVP(msg_payload);
00171             ar & BOOST_SERIALIZATION_NVP(payload_present);
00172         }
00173 };
00174 } //namespace SST
00175 
00176 #endif // SST_CPUNICEVENT_H

Generated on Fri Oct 22 2010 11:02:13 for SST by  doxygen 1.7.1