SST  6.1.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  FlushLine, /*!< Cache flush request - writeback specified line throughout memory system */
60  FlushLineInv, /*!< Cache flush request - writeback and invalidate specified line throughout memory system */
61  FlushLineResp, /*!< Response to FlushLine; flag F_FLUSH_SUCCESS indicates success or failure */
62  } Command;
63 
64  /**
65  * Flags to specify conditions on a Request
66  */
67  typedef enum {
68  F_NONCACHEABLE = 1<<1, /*!< This request should not be cached */
69  F_LOCKED = 1<<2, /*!< This request should be locked. A LOCKED read should be soon followed by a LOCKED write (to unlock) */
70  F_LLSC = 1<<3,
71  F_LLSC_RESP = 1<<4,
72  F_FLUSH_SUCCESS = 1<<5 /*!< This flag is set if the flush was successful. Flush may fail due to LOCKED lines */
73  } Flags;
74 
75  /** Type of the payload or data */
76  typedef std::vector<uint8_t> dataVec;
77 
78  Command cmd; /*!< Command to issue */
79  Addr addr; /*!< Target address */
80  size_t size; /*!< Size of this request or response */
81  dataVec data; /*!< Payload data (for Write, or ReadResp) */
82  flags_t flags; /*!< Flags associated with this request or response */
83  flags_t memFlags; /*!< Memory flags - ignored by caches except to be passed through with request to main memory */
84  id_t id; /*!< Unique ID to identify responses with requests */
85  uint32_t groupId; /* Group Id. Used to maintain group-based stats in MH */
86  Addr instrPtr; /*!< Instruction pointer associated with the operation */
87  Addr virtualAddr; /*!< Virtual address associated with the operation */
88 
89  /** Constructor */
90  Request(Command cmd, Addr addr, size_t size, dataVec &data, flags_t flags = 0, flags_t memFlags = 0) :
91  cmd(cmd), addr(addr), size(size), data(data), flags(flags), memFlags(memFlags), groupId(0),
92  instrPtr(0), virtualAddr(0)
93  {
94  id = main_id++;
95  }
96 
97  /** Constructor */
98  Request(Command cmd, Addr addr, size_t size, flags_t flags = 0, flags_t memFlags = 0) :
99  cmd(cmd), addr(addr), size(size), flags(flags), memFlags(memFlags), groupId(0),
100  instrPtr(0), virtualAddr(0)
101  {
102  id = main_id++;
103  }
104 
105  /**
106  * Set Stats Group Id
107  */
108  void setGroupId(uint32_t _groupId)
109  {
110  groupId = _groupId;
111  }
112 
113  /**
114  * Set the contents of the payload / data field.
115  */
116  void setPayload(const std::vector<uint8_t> & data_in )
117  {
118  data = data_in;
119  }
120 
121  /**
122  * Set the contents of the payload / data field.
123  */
124  void setPayload(uint8_t *data_in, size_t len)
125  {
126  data.resize(len);
127  for ( size_t i = 0 ; i < len ; i++ ) {
128  data[i] = data_in[i];
129  }
130  }
131 
132  /**
133  * Set the virtual address associated with the operation
134  */
135  void setVirtualAddress(const Addr newVA) {
136  virtualAddr = newVA;
137  }
138 
139  /**
140  * Get the virtual address associated with the operation
141  */
142  uint64_t getVirtualAddress() {
143  return (uint64_t) virtualAddr;
144  }
145 
146  /*
147  * Sets the instruction pointer associated with the operation
148  */
149  void setInstructionPointer(const Addr newIP) {
150  instrPtr = newIP;
151  }
152 
153  /**
154  * Sets the instruction pointer associated with the operation
155  */
157  return instrPtr;
158  }
159 
160  private:
161  static std::atomic<id_t> main_id;
162  };
163 
164  /** Functor classes for Clock handling */
165  class HandlerBase {
166  public:
167  /** Function called when Handler is invoked */
168  virtual void operator()(Request*) = 0;
169  virtual ~HandlerBase() {}
170  };
171 
172 
173  /** Event Handler class with user-data argument
174  * @tparam classT Type of the Object
175  * @tparam argT Type of the argument
176  */
177  template <typename classT, typename argT = void>
178  class Handler : public HandlerBase {
179  private:
180  typedef void (classT::*PtrMember)(Request*, argT);
181  classT* object;
182  const PtrMember member;
183  argT data;
184 
185  public:
186  /** Constructor
187  * @param object - Pointer to Object upon which to call the handler
188  * @param member - Member function to call as the handler
189  * @param data - Additional argument to pass to handler
190  */
191  Handler( classT* const object, PtrMember member, argT data ) :
192  object(object),
193  member(member),
194  data(data)
195  {}
196 
197  void operator()(Request* req) {
198  return (object->*member)(req,data);
199  }
200  };
201 
202  /** Event Handler class without user-data
203  * @tparam classT Type of the Object
204  */
205  template <typename classT>
206  class Handler<classT, void> : public HandlerBase {
207  private:
208  typedef void (classT::*PtrMember)(Request*);
209  classT* object;
210  const PtrMember member;
211 
212  public:
213  /** Constructor
214  * @param object - Pointer to Object upon which to call the handler
215  * @param member - Member function to call as the handler
216  */
217  Handler( classT* const object, PtrMember member ) :
218  object(object),
219  member(member)
220  {}
221 
222  void operator()(Request* req) {
223  return (object->*member)(req);
224  }
225  };
226 
227 
228  /** Constructor, designed to be used via 'loadSubComponent'. */
229  SimpleMem(SST::Component *comp, Params &params) :
230  SubComponent(comp)
231  { }
232 
233  /** Second half of building the interface.
234  * Intialize with link name name, and handler, if any
235  * @return true if the link was able to be configured.
236  */
237  virtual bool initialize(const std::string &linkName, HandlerBase *handler = NULL) = 0;
238 
239  /**
240  * Sends a memory-based request during the init() phase
241  */
242  virtual void sendInitData(Request *req) = 0;
243 
244  /**
245  * Sends a generic Event during the init() phase
246  * (Mostly acts as a passthrough)
247  * @see SST::Link::sendInitData()
248  */
249  virtual void sendInitData(SST::Event *ev) { getLink()->sendInitData(ev); }
250 
251  /**
252  * Receive any data during the init() phase.
253  * @see SST::Link::recvInitData()
254  */
255  virtual SST::Event* recvInitData() { return getLink()->recvInitData(); }
256 
257  /**
258  * Returns a handle to the underlying SST::Link
259  */
260  virtual SST::Link* getLink(void) const = 0;
261 
262  /**
263  * Send a Request to the other side of the link.
264  */
265  virtual void sendRequest(Request *req) = 0;
266 
267  /**
268  * Receive a Request response from the side of the link.
269  *
270  * Use this method for polling-based applications.
271  * Register a handler for push-based notification of responses.
272  *
273  * @return NULL if nothing is available.
274  * @return Pointer to a Request response (that should be deleted)
275  */
276  virtual Request* recvResponse(void) = 0;
277 
278 
279 };
280 
281 }
282 }
283 
284 #endif
virtual SST::Event * recvInitData()
Receive any data during the init() phase.
Definition: simpleMem.h:255
size_t size
Definition: simpleMem.h:80
uint32_t flags_t
Definition: simpleMem.h:49
Addr getInstructionPointer()
Sets the instruction pointer associated with the operation.
Definition: simpleMem.h:156
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:142
Command cmd
Definition: simpleMem.h:78
Main component object for the simulation.
Definition: component.h:56
Handler(classT *const object, PtrMember member, argT data)
Constructor.
Definition: simpleMem.h:191
dataVec data
Definition: simpleMem.h:81
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:108
Definition: action.cc:17
std::vector< uint8_t > dataVec
Type of the payload or data.
Definition: simpleMem.h:76
void setPayload(const std::vector< uint8_t > &data_in)
Set the contents of the payload / data field.
Definition: simpleMem.h:116
void operator()(Request *req)
Function called when Handler is invoked.
Definition: simpleMem.h:222
Functor classes for Clock handling.
Definition: simpleMem.h:165
virtual void sendInitData(Request *req)=0
Sends a memory-based request during the init() phase.
flags_t flags
Definition: simpleMem.h:82
Simplified, generic interface to Memory models.
Definition: simpleMem.h:37
void operator()(Request *req)
Function called when Handler is invoked.
Definition: simpleMem.h:197
Handler(classT *const object, PtrMember member)
Constructor.
Definition: simpleMem.h:217
SimpleMem(SST::Component *comp, Params &params)
Constructor, designed to be used via 'loadSubComponent'.
Definition: simpleMem.h:229
Addr instrPtr
Definition: simpleMem.h:86
Request(Command cmd, Addr addr, size_t size, dataVec &data, flags_t flags=0, flags_t memFlags=0)
Constructor.
Definition: simpleMem.h:90
Addr virtualAddr
Definition: simpleMem.h:87
Event Handler class with user-data argument.
Definition: simpleMem.h:178
virtual void sendInitData(SST::Event *ev)
Sends a generic Event during the init() phase (Mostly acts as a passthrough)
Definition: simpleMem.h:249
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:44
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:135
Flags
Flags to specify conditions on a Request.
Definition: simpleMem.h:67
void setPayload(uint8_t *data_in, size_t len)
Set the contents of the payload / data field.
Definition: simpleMem.h:124
Base class for Events - Items sent across links to communicate between components.
Definition: event.h:31
Addr addr
Definition: simpleMem.h:79
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:84
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:98
flags_t memFlags
Definition: simpleMem.h:83