RubyPort.hh revision 6825:104115ebc206
1#ifndef RUBYPORT_H 2#define RUBYPORT_H 3 4#include "mem/ruby/libruby.hh" 5#include <string> 6#include <assert.h> 7 8using namespace std; 9 10class RubyPort { 11public: 12 RubyPort(const string & name) 13 : m_name(name) 14 { 15 m_port_id = m_num_ports++; 16 m_request_cnt = 0; 17 m_hit_callback = NULL; 18 assert(m_num_ports <= 2048); // see below for reason 19 } 20 virtual ~RubyPort() {} 21 22 virtual int64_t makeRequest(const RubyRequest & request) = 0; 23 24 virtual bool isReady(const RubyRequest & request, bool dont_set = false) = 0; 25 26 void registerHitCallback(void (*hit_callback)(int64_t request_id)) { 27 assert(m_hit_callback == NULL); // can't assign hit_callback twice 28 m_hit_callback = hit_callback; 29 } 30 31protected: 32 const string m_name; 33 void (*m_hit_callback)(int64_t); 34 35 int64_t makeUniqueRequestID() { 36 // The request ID is generated by combining the port ID with a request count 37 // so that request IDs can be formed concurrently by multiple threads. 38 // IDs are formed as follows: 39 // 40 // 41 // 0 PortID Request Count 42 // +----+---------------+-----------------------------------------------------+ 43 // | 63 | 62-48 | 47-0 | 44 // +----+---------------+-----------------------------------------------------+ 45 // 46 // 47 // This limits the system to a maximum of 2^11 == 2048 components 48 // and 2^48 ~= 3x10^14 requests per component 49 50 int64_t id = (static_cast<uint64_t>(m_port_id) << 48) | m_request_cnt; 51 m_request_cnt++; 52 // assert((m_request_cnt & (1<<48)) == 0); 53 return id; 54 } 55 56private: 57 static uint16_t m_num_ports; 58 uint16_t m_port_id; 59 uint64_t m_request_cnt; 60}; 61 62#endif 63