SST  6.0.0
StructuralSimulationToolkit
simpleMem.h
1 // -*- mode: c++ -*-
2 // Copyright 2009-2016 Sandia Corporation. Under the terms
3 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
4 // Government retains certain rights in this software.
5 //
6 // Copyright (c) 2009-2016, Sandia Corporation
7 // All rights reserved.
8 //
9 // This file is part of the SST software package. For license
10 // information, see the LICENSE file in the top level directory of the
11 // distribution.
12 //
13 
14 #ifndef CORE_INTERFACES_SIMPLEMEM_H_
15 #define CORE_INTERFACES_SIMPLEMEM_H_
16 
17 #include <string>
18 #include <utility>
19 #include <map>
20 #include <atomic>
21 
22 #include <sst/core/sst_types.h>
23 #include <sst/core/subcomponent.h>
24 #include <sst/core/params.h>
25 #include <sst/core/link.h>
26 
27 namespace SST {
28 
29 class Component;
30 class Event;
31 
32 namespace Interfaces {
33 
34 /**
35  * Simplified, generic interface to Memory models
36  */
37 class SimpleMem : public SubComponent {
38 
39 public:
40  /** All Addresses can be 64-bit */
41  typedef uint64_t Addr;
42 
43  /**
44  * Represents both memory requests and responses.
45  */
46  class Request {
47  public:
48  typedef uint64_t id_t; /*!< Request ID type */
49  typedef uint32_t flags_t; /*!< Flag type */
50 
51  /**
52  * Commands and responses possible with a Request object
53  */
54  typedef enum {
55  Read, /*!< Issue a Read from Memory */
56  Write, /*!< Issue a Write to Memory */
57  ReadResp, /*!< Response from Memory to a Read */
58  WriteResp /*!< Response from Memory to a Write */
59  } Command;
60 
61  /**
62  * Flags to specify conditions on a Request
63  */
64  typedef enum {
65  F_NONCACHEABLE = 1<<1, /*!< This request should not be cached */
66  F_LOCKED = 1<<2, /*!< This request should be locked. A LOCKED read should be soon followed by a LOCKED write (to unlock) */
67  F_LLSC = 1<<3,
68  F_LLSC_RESP = 1<<4
69  } Flags;
70 
71  /** Type of the payload or data */
72  typedef std::vector<uint8_t> dataVec;
73 
74  Command cmd; /*!< Command to issue */
75  Addr addr; /*!< Target address */
76  size_t size; /*!< Size of this request or response */
77  dataVec data; /*!< Payload data (for Write, or ReadResp) */
78  flags_t flags; /*!< Flags associated with this request or response */
79  flags_t memFlags; /*!< Memory flags - ignored by caches except to be passed through with request to main memory */
80  id_t id; /*!< Unique ID to identify responses with requests */
81  uint32_t groupId; /* Group Id. Used to maintain group-based stats in MH */
82  Addr instrPtr; /*!< Instruction pointer associated with the operation */
83  Addr virtualAddr; /*!< Virtual address associated with the operation */
84 
85  /** Constructor */
86  Request(Command cmd, Addr addr, size_t size, dataVec &data, flags_t flags = 0, flags_t memFlags = 0) :
87  cmd(cmd), addr(addr), size(size), data(data), flags(flags), memFlags(memFlags), groupId(0),
88  instrPtr(0), virtualAddr(0)
89  {
90  id = main_id++;
91  }
92 
93  /** Constructor */
94  Request(Command cmd, Addr addr, size_t size, flags_t flags = 0, flags_t memFlags = 0) :
95  cmd(cmd), addr(addr), size(size), flags(flags), memFlags(memFlags), groupId(0),
96  instrPtr(0), virtualAddr(0)
97  {
98  id = main_id++;
99  }
100 
101  /**
102  * Set Stats Group Id
103  */
104  void setGroupId(uint32_t _groupId)
105  {
106  groupId = _groupId;
107  }
108 
109  /**
110  * Set the contents of the payload / data field.
111  */
112  void setPayload(const std::vector<uint8_t> & data_in )
113  {
114  data = data_in;
115  }
116 
117  /**
118  * Set the contents of the payload / data field.
119  */
120  void setPayload(uint8_t *data_in, size_t len)
121  {
122  data.resize(len);
123  for ( size_t i = 0 ; i < len ; i++ ) {
124  data[i] = data_in[i];
125  }
126  }
127 
128  /**
129  * Set the virtual address associated with the operation
130  */
131  void setVirtualAddress(const Addr newVA) {
132  virtualAddr = newVA;
133  }
134 
135  /**
136  * Get the virtual address associated with the operation
137  */
138  uint64_t getVirtualAddress() {
139  return (uint64_t) virtualAddr;
140  }
141 
142  /*
143  * Sets the instruction pointer associated with the operation
144  */
145  void setInstructionPointer(const Addr newIP) {
146  instrPtr = newIP;
147  }
148 
149  /**
150  * Sets the instruction pointer associated with the operation
151  */
153  return instrPtr;
154  }
155 
156  private:
157  static std::atomic<id_t> main_id;
158  };
159 
160  /** Functor classes for Clock handling */
161  class HandlerBase {
162  public:
163  /** Function called when Handler is invoked */
164  virtual void operator()(Request*) = 0;
165  virtual ~HandlerBase() {}
166  };
167 
168 
169  /** Event Handler class with user-data argument
170  * @tparam classT Type of the Object
171  * @tparam argT Type of the argument
172  */
173  template <typename classT, typename argT = void>
174  class Handler : public HandlerBase {
175  private:
176  typedef void (classT::*PtrMember)(Request*, argT);
177  classT* object;
178  const PtrMember member;
179  argT data;
180 
181  public:
182  /** Constructor
183  * @param object - Pointer to Object upon which to call the handler
184  * @param member - Member function to call as the handler
185  * @param data - Additional argument to pass to handler
186  */
187  Handler( classT* const object, PtrMember member, argT data ) :
188  object(object),
189  member(member),
190  data(data)
191  {}
192 
193  void operator()(Request* req) {
194  return (object->*member)(req,data);
195  }
196  };
197 
198  /** Event Handler class without user-data
199  * @tparam classT Type of the Object
200  */
201  template <typename classT>
202  class Handler<classT, void> : public HandlerBase {
203  private:
204  typedef void (classT::*PtrMember)(Request*);
205  classT* object;
206  const PtrMember member;
207 
208  public:
209  /** Constructor
210  * @param object - Pointer to Object upon which to call the handler
211  * @param member - Member function to call as the handler
212  */
213  Handler( classT* const object, PtrMember member ) :
214  object(object),
215  member(member)
216  {}
217 
218  void operator()(Request* req) {
219  return (object->*member)(req);
220  }
221  };
222 
223 
224  /** Constructor, designed to be used via 'loadSubComponent'. */
225  SimpleMem(SST::Component *comp, Params &params) :
226  SubComponent(comp)
227  { }
228 
229  /** Second half of building the interface.
230  * Intialize with link name name, and handler, if any
231  * @return true if the link was able to be configured.
232  */
233  virtual bool initialize(const std::string &linkName, HandlerBase *handler = NULL) = 0;
234 
235  /**
236  * Sends a memory-based request during the init() phase
237  */
238  virtual void sendInitData(Request *req) = 0;
239 
240  /**
241  * Sends a generic Event during the init() phase
242  * (Mostly acts as a passthrough)
243  * @see SST::Link::sendInitData()
244  */
245  virtual void sendInitData(SST::Event *ev) { getLink()->sendInitData(ev); }
246 
247  /**
248  * Receive any data during the init() phase.
249  * @see SST::Link::recvInitData()
250  */
251  virtual SST::Event* recvInitData() { return getLink()->recvInitData(); }
252 
253  /**
254  * Returns a handle to the underlying SST::Link
255  */
256  virtual SST::Link* getLink(void) const = 0;
257 
258  /**
259  * Send a Request to the other side of the link.
260  */
261  virtual void sendRequest(Request *req) = 0;
262 
263  /**
264  * Receive a Request response from the side of the link.
265  *
266  * Use this method for polling-based applications.
267  * Register a handler for push-based notification of responses.
268  *
269  * @return NULL if nothing is available.
270  * @return Pointer to a Request response (that should be deleted)
271  */
272  virtual Request* recvResponse(void) = 0;
273 
274 
275 };
276 
277 }
278 }
279 
280 #endif
virtual SST::Event * recvInitData()
Receive any data during the init() phase.
Definition: simpleMem.h:251
size_t size
Definition: simpleMem.h:76
uint32_t flags_t
Definition: simpleMem.h:49
Addr getInstructionPointer()
Sets the instruction pointer associated with the operation.
Definition: simpleMem.h:152
Command
Commands and responses possible with a Request object.
Definition: simpleMem.h:54
Represents both memory requests and responses.
Definition: simpleMem.h:46
virtual void sendRequest(Request *req)=0
Send a Request to the other side of the link.
uint64_t getVirtualAddress()
Get the virtual address associated with the operation.
Definition: simpleMem.h:138
Command cmd
Definition: simpleMem.h:74
Main component object for the simulation.
Definition: component.h:56
Handler(classT *const object, PtrMember member, argT data)
Constructor.
Definition: simpleMem.h:187
dataVec data
Definition: simpleMem.h:77
virtual SST::Link * getLink(void) const =0
Returns a handle to the underlying SST::Link.
void setGroupId(uint32_t _groupId)
Set Stats Group Id.
Definition: simpleMem.h:104
Definition: action.cc:17
std::vector< uint8_t > dataVec
Type of the payload or data.
Definition: simpleMem.h:72
void setPayload(const std::vector< uint8_t > &data_in)
Set the contents of the payload / data field.
Definition: simpleMem.h:112
void operator()(Request *req)
Function called when Handler is invoked.
Definition: simpleMem.h:218
Functor classes for Clock handling.
Definition: simpleMem.h:161
virtual void sendInitData(Request *req)=0
Sends a memory-based request during the init() phase.
flags_t flags
Definition: simpleMem.h:78
Simplified, generic interface to Memory models.
Definition: simpleMem.h:37
void operator()(Request *req)
Function called when Handler is invoked.
Definition: simpleMem.h:193
Handler(classT *const object, PtrMember member)
Constructor.
Definition: simpleMem.h:213
SimpleMem(SST::Component *comp, Params &params)
Constructor, designed to be used via 'loadSubComponent'.
Definition: simpleMem.h:225
Addr instrPtr
Definition: simpleMem.h:82
Request(Command cmd, Addr addr, size_t size, dataVec &data, flags_t flags=0, flags_t memFlags=0)
Constructor.
Definition: simpleMem.h:86
Addr virtualAddr
Definition: simpleMem.h:83
Event Handler class with user-data argument.
Definition: simpleMem.h:174
virtual void sendInitData(SST::Event *ev)
Sends a generic Event during the init() phase (Mostly acts as a passthrough)
Definition: simpleMem.h:245
virtual void operator()(Request *)=0
Function called when Handler is invoked.
virtual bool initialize(const std::string &linkName, HandlerBase *handler=NULL)=0
Second half of building the interface.
Parameter store.
Definition: params.h:46
uint64_t Addr
All Addresses can be 64-bit.
Definition: simpleMem.h:41
void setVirtualAddress(const Addr newVA)
Set the virtual address associated with the operation.
Definition: simpleMem.h:131
Flags
Flags to specify conditions on a Request.
Definition: simpleMem.h:64
void setPayload(uint8_t *data_in, size_t len)
Set the contents of the payload / data field.
Definition: simpleMem.h:120
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:31
Addr addr
Definition: simpleMem.h:75
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:27
uint64_t id_t
Definition: simpleMem.h:48
id_t id
Definition: simpleMem.h:80
virtual Request * recvResponse(void)=0
Receive a Request response from the side of the link.
Request(Command cmd, Addr addr, size_t size, flags_t flags=0, flags_t memFlags=0)
Constructor.
Definition: simpleMem.h:94
flags_t memFlags
Definition: simpleMem.h:79