SST  7.0.0
StructuralSimulationToolkit
simpleMem.h
1 // -*- mode: c++ -*-
2 // Copyright 2009-2017 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-2017, 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/warnmacros.h>
24 #include <sst/core/subcomponent.h>
25 #include <sst/core/params.h>
26 #include <sst/core/link.h>
27 
28 namespace SST {
29 
30 class Component;
31 class Event;
32 
33 namespace Interfaces {
34 
35 /**
36  * Simplified, generic interface to Memory models
37  */
38 class SimpleMem : public SubComponent {
39 
40 public:
41  /** All Addresses can be 64-bit */
42  typedef uint64_t Addr;
43 
44  /**
45  * Represents both memory requests and responses.
46  */
47  class Request {
48  public:
49  typedef uint64_t id_t; /*!< Request ID type */
50  typedef uint32_t flags_t; /*!< Flag type */
51 
52  /**
53  * Commands and responses possible with a Request object
54  */
55  typedef enum {
56  Read, /*!< Issue a Read from Memory */
57  Write, /*!< Issue a Write to Memory */
58  ReadResp, /*!< Response from Memory to a Read */
59  WriteResp, /*!< Response from Memory to a Write */
60  FlushLine, /*!< Cache flush request - writeback specified line throughout memory system */
61  FlushLineInv, /*!< Cache flush request - writeback and invalidate specified line throughout memory system */
62  FlushLineResp, /*!< Response to FlushLine; flag F_FLUSH_SUCCESS indicates success or failure */
63  TxBegin, /*!< Start a new transaction */
64  TxEnd, /*!< End the current lowest transaction */
65  TxResp,
66  TxAbort,
67  TxCommit
68  } Command;
69 
70  /**
71  * Flags to specify conditions on a Request
72  */
73  typedef enum {
74  F_NONCACHEABLE = 1<<1, /*!< This request should not be cached */
75  F_LOCKED = 1<<2, /*!< This request should be locked. A LOCKED read should be soon followed by a LOCKED write (to unlock) */
76  F_LLSC = 1<<3,
77  F_LLSC_RESP = 1<<4,
78  F_FLUSH_SUCCESS = 1<<5, /*!< This flag is set if the flush was successful. Flush may fail due to LOCKED lines */
79  F_TRANSACTION = 1<<6
80  } Flags;
81 
82  /** Type of the payload or data */
83  typedef std::vector<uint8_t> dataVec;
84 
85  Command cmd; /*!< Command to issue */
86  std::vector<Addr> addrs; /*!< Target address(es) */
87  Addr addr; /*!< Target address - DEPRECATED but included for backward compatibility, defaults to addrs[0] */
88  size_t size; /*!< Size of this request or response */
89  dataVec data; /*!< Payload data (for Write, or ReadResp) */
90  flags_t flags; /*!< Flags associated with this request or response */
91  flags_t memFlags; /*!< Memory flags - ignored by caches except to be passed through with request to main memory */
92  id_t id; /*!< Unique ID to identify responses with requests */
93  Addr instrPtr; /*!< Instruction pointer associated with the operation */
94  Addr virtualAddr; /*!< Virtual address associated with the operation */
95 
96  /** Constructor */
97  Request(Command cmd, Addr addr, size_t size, dataVec &data, flags_t flags = 0, flags_t memFlags = 0) :
98  cmd(cmd), addr(addr), size(size), data(data), flags(flags), memFlags(memFlags),
99  instrPtr(0), virtualAddr(0)
100  {
101  addrs.push_back(addr);
102  id = main_id++;
103  }
104 
105  /** Constructor */
106  Request(Command cmd, Addr addr, size_t size, flags_t flags = 0, flags_t memFlags = 0) :
107  cmd(cmd), addr(addr), size(size), flags(flags), memFlags(memFlags),
108  instrPtr(0), virtualAddr(0)
109  {
110  addrs.push_back(addr);
111  id = main_id++;
112  }
113 
114  void addAddress(Addr addr)
115  {
116  addrs.push_back(addr);
117  }
118 
119  /**
120  * @param[in] data_in
121  * @brief Set the contents of the payload / data field.
122  */
123  void setPayload(const std::vector<uint8_t> & data_in )
124  {
125  data = data_in;
126  }
127 
128  /**
129  * @param[in] data_in
130  * @brief Set the contents of the payload / data field.
131  */
132  void setPayload(uint8_t *data_in, size_t len) {
133  data.resize(len);
134  for ( size_t i = 0 ; i < len ; i++ ) {
135  data[i] = data_in[i];
136  }
137  }
138 
139  /**
140  * @param[in] newVA
141  * @brief Set the virtual address associated with the operation
142  */
143  void setVirtualAddress(const Addr newVA) {
144  virtualAddr = newVA;
145  }
146 
147  /**
148  * @returns the virtual address associated with the operation
149  */
150  uint64_t getVirtualAddress() {
151  return (uint64_t) virtualAddr;
152  }
153 
154  /**
155  * @param[in] newIP
156  * @brief Sets the instruction pointer associated with the operation
157  */
158  void setInstructionPointer(const Addr newIP) {
159  instrPtr = newIP;
160  }
161 
162  /**
163  * @returns the instruction pointer associated with the operation
164  */
166  return instrPtr;
167  }
168 
169  /**
170  * @brief Clears the flags associated with the operation
171  */
172  void clearFlags(void) {
173  flags = 0;
174  }
175 
176  /**
177  * @param[in] inValue Should be one of the flags beginning with F_ in simpleMem
178  */
179  void setFlags(flags_t inValue) {
180  flags = flags | inValue;
181  }
182 
183  /**
184  * @returns the flags associated with the operation
185  */
186  flags_t getFlags(void) {
187  return flags;
188  }
189 
190  /**
191  * @brief Clears the memory flags associated with the operation
192  */
193  void clearMemFlags(void) {
194  memFlags = 0;
195  }
196 
197  /**
198  * @param[in] inValue Should be one of the flags beginning with F_ in simpleMem
199  */
200  void setMemFlags(flags_t inValue) {
201  memFlags = memFlags | inValue;
202  }
203 
204  /**
205  * @returns the memory flags associated with the operation
206  */
207  flags_t getMemFlags(void) {
208  return memFlags;
209  }
210 
211 
212  private:
213  static std::atomic<id_t> main_id;
214 
215  };
216 
217  /** Functor classes for Clock handling */
218  class HandlerBase {
219  public:
220  /** Function called when Handler is invoked */
221  virtual void operator()(Request*) = 0;
222  virtual ~HandlerBase() {}
223  };
224 
225 
226  /** Event Handler class with user-data argument
227  * @tparam classT Type of the Object
228  * @tparam argT Type of the argument
229  */
230  template <typename classT, typename argT = void>
231  class Handler : public HandlerBase {
232  private:
233  typedef void (classT::*PtrMember)(Request*, argT);
234  classT* object;
235  const PtrMember member;
236  argT data;
237 
238  public:
239  /** Constructor
240  * @param object - Pointer to Object upon which to call the handler
241  * @param member - Member function to call as the handler
242  * @param data - Additional argument to pass to handler
243  */
244  Handler( classT* const object, PtrMember member, argT data ) :
245  object(object),
246  member(member),
247  data(data)
248  {}
249 
250  void operator()(Request* req) {
251  return (object->*member)(req,data);
252  }
253  };
254 
255  /** Event Handler class without user-data
256  * @tparam classT Type of the Object
257  */
258  template <typename classT>
259  class Handler<classT, void> : public HandlerBase {
260  private:
261  typedef void (classT::*PtrMember)(Request*);
262  classT* object;
263  const PtrMember member;
264 
265  public:
266  /** Constructor
267  * @param object - Pointer to Object upon which to call the handler
268  * @param member - Member function to call as the handler
269  */
270  Handler( classT* const object, PtrMember member ) :
271  object(object),
272  member(member)
273  {}
274 
275  void operator()(Request* req) {
276  return (object->*member)(req);
277  }
278  };
279 
280 
281  /** Constructor, designed to be used via 'loadSubComponent'. */
282  SimpleMem(SST::Component *comp, Params &UNUSED(params)) :
283  SubComponent(comp)
284  { }
285 
286  /** Second half of building the interface.
287  * Intialize with link name name, and handler, if any
288  * @return true if the link was able to be configured.
289  */
290  virtual bool initialize(const std::string &linkName, HandlerBase *handler = NULL) = 0;
291 
292  /**
293  * Sends a memory-based request during the init() phase
294  */
295  virtual void sendInitData(Request *req) = 0;
296 
297  /**
298  * Sends a generic Event during the init() phase
299  * (Mostly acts as a passthrough)
300  * @see SST::Link::sendInitData()
301  */
302  virtual void sendInitData(SST::Event *ev) { getLink()->sendInitData(ev); }
303 
304  /**
305  * Receive any data during the init() phase.
306  * @see SST::Link::recvInitData()
307  */
308  virtual SST::Event* recvInitData() { return getLink()->recvInitData(); }
309 
310  /**
311  * Returns a handle to the underlying SST::Link
312  */
313  virtual SST::Link* getLink(void) const = 0;
314 
315  /**
316  * Send a Request to the other side of the link.
317  */
318  virtual void sendRequest(Request *req) = 0;
319 
320  /**
321  * Receive a Request response from the side of the link.
322  *
323  * Use this method for polling-based applications.
324  * Register a handler for push-based notification of responses.
325  *
326  * @return NULL if nothing is available.
327  * @return Pointer to a Request response (that should be deleted)
328  */
329  virtual Request* recvResponse(void) = 0;
330 
331 
332 };
333 
334 }
335 }
336 
337 #endif
virtual SST::Event * recvInitData()
Receive any data during the init() phase.
Definition: simpleMem.h:308
size_t size
Definition: simpleMem.h:88
uint32_t flags_t
Definition: simpleMem.h:50
Addr getInstructionPointer()
Definition: simpleMem.h:165
Command
Commands and responses possible with a Request object.
Definition: simpleMem.h:55
Represents both memory requests and responses.
Definition: simpleMem.h:47
virtual void sendRequest(Request *req)=0
Send a Request to the other side of the link.
std::vector< Addr > addrs
Definition: simpleMem.h:86
uint64_t getVirtualAddress()
Definition: simpleMem.h:150
Command cmd
Definition: simpleMem.h:85
Main component object for the simulation.
Definition: component.h:32
Handler(classT *const object, PtrMember member, argT data)
Constructor.
Definition: simpleMem.h:244
dataVec data
Definition: simpleMem.h:89
virtual SST::Link * getLink(void) const =0
Returns a handle to the underlying SST::Link.
Definition: action.cc:17
void setFlags(flags_t inValue)
Definition: simpleMem.h:179
std::vector< uint8_t > dataVec
Type of the payload or data.
Definition: simpleMem.h:83
void setInstructionPointer(const Addr newIP)
Sets the instruction pointer associated with the operation.
Definition: simpleMem.h:158
void setPayload(const std::vector< uint8_t > &data_in)
Set the contents of the payload / data field.
Definition: simpleMem.h:123
void operator()(Request *req)
Function called when Handler is invoked.
Definition: simpleMem.h:275
Functor classes for Clock handling.
Definition: simpleMem.h:218
virtual void sendInitData(Request *req)=0
Sends a memory-based request during the init() phase.
flags_t flags
Definition: simpleMem.h:90
Simplified, generic interface to Memory models.
Definition: simpleMem.h:38
void operator()(Request *req)
Function called when Handler is invoked.
Definition: simpleMem.h:250
flags_t getMemFlags(void)
Definition: simpleMem.h:207
Handler(classT *const object, PtrMember member)
Constructor.
Definition: simpleMem.h:270
void clearFlags(void)
Clears the flags associated with the operation.
Definition: simpleMem.h:172
Addr instrPtr
Definition: simpleMem.h:93
Request(Command cmd, Addr addr, size_t size, dataVec &data, flags_t flags=0, flags_t memFlags=0)
Constructor.
Definition: simpleMem.h:97
Addr virtualAddr
Definition: simpleMem.h:94
flags_t getFlags(void)
Definition: simpleMem.h:186
Event Handler class with user-data argument.
Definition: simpleMem.h:231
virtual void sendInitData(SST::Event *ev)
Sends a generic Event during the init() phase (Mostly acts as a passthrough)
Definition: simpleMem.h:302
virtual void operator()(Request *)=0
Function called when Handler is invoked.
void setMemFlags(flags_t inValue)
Definition: simpleMem.h:200
virtual bool initialize(const std::string &linkName, HandlerBase *handler=NULL)=0
Second half of building the interface.
Parameter store.
Definition: params.h:45
uint64_t Addr
All Addresses can be 64-bit.
Definition: simpleMem.h:42
void setVirtualAddress(const Addr newVA)
Set the virtual address associated with the operation.
Definition: simpleMem.h:143
Flags
Flags to specify conditions on a Request.
Definition: simpleMem.h:73
void setPayload(uint8_t *data_in, size_t len)
Set the contents of the payload / data field.
Definition: simpleMem.h:132
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:31
SimpleMem(SST::Component *comp, Params &UNUSED(params))
Constructor, designed to be used via 'loadSubComponent'.
Definition: simpleMem.h:282
Addr addr
Definition: simpleMem.h:87
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29
uint64_t id_t
Definition: simpleMem.h:49
id_t id
Definition: simpleMem.h:92
virtual Request * recvResponse(void)=0
Receive a Request response from the side of the link.
void clearMemFlags(void)
Clears the memory flags associated with the operation.
Definition: simpleMem.h:193
Request(Command cmd, Addr addr, size_t size, flags_t flags=0, flags_t memFlags=0)
Constructor.
Definition: simpleMem.h:106
flags_t memFlags
Definition: simpleMem.h:91