dist_etherlink.hh revision 10923
1/* 2 * Copyright (c) 2015 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions are 16 * met: redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer; 18 * redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution; 21 * neither the name of the copyright holders nor the names of its 22 * contributors may be used to endorse or promote products derived from 23 * this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * Authors: Gabor Dozsa 38 */ 39 40/* @file 41 * Device module for a full duplex ethernet link for multi gem5 simulations. 42 * 43 * See comments in dev/multi_iface.hh for a generic description of multi 44 * gem5 simulations. 45 * 46 * This class is meant to be a drop in replacement for the EtherLink class for 47 * multi gem5 runs. 48 * 49 */ 50#ifndef __DEV_MULTIETHERLINK_HH__ 51#define __DEV_MULTIETHERLINK_HH__ 52 53#include <iostream> 54 55#include "dev/etherlink.hh" 56#include "params/MultiEtherLink.hh" 57 58class MultiIface; 59class EthPacketData; 60 61/** 62 * Model for a fixed bandwidth full duplex ethernet link. 63 */ 64class MultiEtherLink : public EtherObject 65{ 66 protected: 67 class LocalIface; 68 69 /** 70 * Model base class for a single uni-directional link. 71 * 72 * The link will encapsulate and transfer Ethernet packets to/from 73 * the message server. 74 */ 75 class Link 76 { 77 protected: 78 std::string objName; 79 MultiEtherLink *parent; 80 LocalIface *localIface; 81 EtherDump *dump; 82 MultiIface *multiIface; 83 Event *event; 84 EthPacketPtr packet; 85 86 public: 87 Link(const std::string &name, MultiEtherLink *p, 88 EtherDump *d, Event *e) : 89 objName(name), parent(p), localIface(nullptr), dump(d), 90 multiIface(nullptr), event(e) {} 91 92 ~Link() {} 93 94 const std::string name() const { return objName; } 95 bool busy() const { return (bool)packet; } 96 void setLocalInt(LocalIface *i) { assert(!localIface); localIface=i; } 97 98 void serialize(const std::string &base, CheckpointOut &cp) const; 99 void unserialize(const std::string &base, CheckpointIn &cp); 100 }; 101 102 /** 103 * Model for a send link. 104 */ 105 class TxLink : public Link 106 { 107 protected: 108 /** 109 * Per byte send delay 110 */ 111 double ticksPerByte; 112 /** 113 * Random component of the send delay 114 */ 115 Tick delayVar; 116 117 /** 118 * Send done callback. Called from doneEvent. 119 */ 120 void txDone(); 121 typedef EventWrapper<TxLink, &TxLink::txDone> DoneEvent; 122 friend void DoneEvent::process(); 123 DoneEvent doneEvent; 124 125 public: 126 TxLink(const std::string &name, MultiEtherLink *p, 127 double invBW, Tick delay_var, EtherDump *d) : 128 Link(name, p, d, &doneEvent), ticksPerByte(invBW), 129 delayVar(delay_var), doneEvent(this) {} 130 ~TxLink() {} 131 132 /** 133 * Register the multi interface to be used to talk to the 134 * peer gem5 processes. 135 */ 136 void setMultiInt(MultiIface *m) { assert(!multiIface); multiIface=m; } 137 138 /** 139 * Initiate sending of a packet via this link. 140 * 141 * @param packet Ethernet packet to send 142 */ 143 bool transmit(EthPacketPtr packet); 144 }; 145 146 /** 147 * Model for a receive link. 148 */ 149 class RxLink : public Link 150 { 151 protected: 152 153 /** 154 * Transmission delay for the simulated Ethernet link. 155 */ 156 Tick linkDelay; 157 158 /** 159 * Receive done callback method. Called from doneEvent. 160 */ 161 void rxDone() ; 162 typedef EventWrapper<RxLink, &RxLink::rxDone> DoneEvent; 163 friend void DoneEvent::process(); 164 DoneEvent doneEvent; 165 166 public: 167 168 RxLink(const std::string &name, MultiEtherLink *p, 169 Tick delay, EtherDump *d) : 170 Link(name, p, d, &doneEvent), 171 linkDelay(delay), doneEvent(this) {} 172 ~RxLink() {} 173 174 /** 175 * Register our multi interface to talk to the peer gem5 processes. 176 */ 177 void setMultiInt(MultiIface *m); 178 }; 179 180 /** 181 * Interface to the local simulated system 182 */ 183 class LocalIface : public EtherInt 184 { 185 private: 186 TxLink *txLink; 187 188 public: 189 LocalIface(const std::string &name, TxLink *tx, RxLink *rx, 190 MultiIface *m); 191 192 bool recvPacket(EthPacketPtr pkt) { return txLink->transmit(pkt); } 193 void sendDone() { peer->sendDone(); } 194 bool isBusy() { return txLink->busy(); } 195 }; 196 197 198 protected: 199 /** 200 * Interface to talk to the peer gem5 processes. 201 */ 202 MultiIface *multiIface; 203 /** 204 * Send link 205 */ 206 TxLink *txLink; 207 /** 208 * Receive link 209 */ 210 RxLink *rxLink; 211 LocalIface *localIface; 212 213 public: 214 typedef MultiEtherLinkParams Params; 215 MultiEtherLink(const Params *p); 216 ~MultiEtherLink(); 217 218 const Params * 219 params() const 220 { 221 return dynamic_cast<const Params *>(_params); 222 } 223 224 virtual EtherInt *getEthPort(const std::string &if_name, 225 int idx) M5_ATTR_OVERRIDE; 226 227 void memWriteback() M5_ATTR_OVERRIDE; 228 void init() M5_ATTR_OVERRIDE; 229 void startup() M5_ATTR_OVERRIDE; 230 231 void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; 232 void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; 233}; 234 235#endif // __DEV_MULTIETHERLINK_HH__ 236