RubyPort.hh revision 6285:ce086eca1ede
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 void registerHitCallback(void (*hit_callback)(int64_t request_id)) { 25 assert(m_hit_callback == NULL); // can't assign hit_callback twice 26 m_hit_callback = hit_callback; 27 } 28 29protected: 30 const string m_name; 31 void (*m_hit_callback)(int64_t); 32 33 int64_t makeUniqueRequestID() { 34 // The request ID is generated by combining the port ID with a request count 35 // so that request IDs can be formed concurrently by multiple threads. 36 // IDs are formed as follows: 37 // 38 // 39 // 0 PortID Request Count 40 // +----+---------------+-----------------------------------------------------+ 41 // | 63 | 62-48 | 47-0 | 42 // +----+---------------+-----------------------------------------------------+ 43 // 44 // 45 // This limits the system to a maximum of 2^11 == 2048 components 46 // and 2^48 ~= 3x10^14 requests per component 47 48 int64_t id = (static_cast<uint64_t>(m_port_id) << 48) | m_request_cnt; 49 m_request_cnt++; 50 // assert((m_request_cnt & (1<<48)) == 0); 51 return id; 52 } 53 54private: 55 static uint16_t m_num_ports; 56 uint16_t m_port_id; 57 uint64_t m_request_cnt; 58}; 59 60#endif 61