summaryrefslogtreecommitdiff
path: root/src/mem/ruby/slicc_interface/RubySlicc_ComponentMapping.hh
blob: bf5778479aeef123fdfe51491780c9adc5fd9465 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

/*
 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer;
 * redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution;
 * neither the name of the copyright holders nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * $Id$
 */

#ifndef COMPONENTMAPPINGFNS_H
#define COMPONENTMAPPINGFNS_H

#include "mem/ruby/common/Global.hh"
#include "mem/ruby/config/RubyConfig.hh"
#include "mem/ruby/system/NodeID.hh"
#include "mem/ruby/system/MachineID.hh"
#include "mem/ruby/common/Address.hh"
#include "mem/ruby/common/Set.hh"
#include "mem/ruby/common/NetDest.hh"
#include "mem/protocol/GenericMachineType.hh"

#ifdef MACHINETYPE_L1Cache
#define MACHINETYPE_L1CACHE_ENUM MachineType_L1Cache
#else
#define MACHINETYPE_L1CACHE_ENUM MachineType_NUM
#endif

#ifdef MACHINETYPE_L2Cache
#define MACHINETYPE_L2CACHE_ENUM MachineType_L2Cache
#else
#define MACHINETYPE_L2CACHE_ENUM MachineType_NUM
#endif

#ifdef MACHINETYPE_L3Cache
#define MACHINETYPE_L3CACHE_ENUM MachineType_L3Cache
#else
#define MACHINETYPE_L3CACHE_ENUM MachineType_NUM
#endif

#ifdef MACHINETYPE_PersistentArbiter
#define MACHINETYPE_PERSISTENTARBITER_ENUM MachineType_PersistentArbiter
#else
#define MACHINETYPE_PERSISTENTARBITER_ENUM MachineType_NUM
#endif

#ifdef MACHINETYPE_Collector
#define MACHINETYPE_COLLECTOR_ENUM MachineType_Collector
#else
#define MACHINETYPE_COLLECTOR_ENUM MachineType_NUM
#endif


// used to determine the correct L1 set
// input parameters are the address and number of set bits for the L1 cache
// returns a value between 0 and the total number of L1 cache sets
inline
int map_address_to_L1CacheSet(const Address& addr, int cache_num_set_bits)
{
  return addr.bitSelect(RubyConfig::dataBlockBits(),
                        RubyConfig::dataBlockBits()+cache_num_set_bits-1);
}

// used to determine the correct L2 set
// input parameters are the address and number of set bits for the L2 cache
// returns a value between 0 and the total number of L2 cache sets
inline
int map_address_to_L2CacheSet(const Address& addr, int cache_num_set_bits)
{
  assert(cache_num_set_bits == L2_CACHE_NUM_SETS_BITS);  // ensure the l2 bank mapping functions agree with l2 set bits

  if (MAP_L2BANKS_TO_LOWEST_BITS) {
    return addr.bitSelect(RubyConfig::dataBlockBits()+RubyConfig::L2CachePerChipBits(),
                          RubyConfig::dataBlockBits()+RubyConfig::L2CachePerChipBits()+cache_num_set_bits-1);
  } else {
    return addr.bitSelect(RubyConfig::dataBlockBits(),
                          RubyConfig::dataBlockBits()+cache_num_set_bits-1);
  }
}

// input parameter is the base ruby node of the L1 cache
// returns a value between 0 and total_L2_Caches_within_the_system
inline
MachineID map_L1CacheMachId_to_L2Cache(const Address& addr, MachineID L1CacheMachId)
{
  int L2bank = 0;
  MachineID mach = {MACHINETYPE_L2CACHE_ENUM, 0};

  if (RubyConfig::L2CachePerChipBits() > 0) {
    if (MAP_L2BANKS_TO_LOWEST_BITS) {
      L2bank = addr.bitSelect(RubyConfig::dataBlockBits(),
                         RubyConfig::dataBlockBits()+RubyConfig::L2CachePerChipBits()-1);
    } else {
      L2bank = addr.bitSelect(RubyConfig::dataBlockBits()+L2_CACHE_NUM_SETS_BITS,
                         RubyConfig::dataBlockBits()+L2_CACHE_NUM_SETS_BITS+RubyConfig::L2CachePerChipBits()-1);
    }
  }

  assert(L2bank < RubyConfig::numberOfL2CachePerChip());
  assert(L2bank >= 0);

  mach.num = RubyConfig::L1CacheNumToL2Base(L1CacheMachId.num)*RubyConfig::numberOfL2CachePerChip() // base #
    + L2bank;  // bank #
  assert(mach.num < RubyConfig::numberOfL2Cache());
  return mach;
}

// used to determine the correct L2 bank
// input parameter is the base ruby node of the L2 cache
// returns a value between 0 and total_L2_Caches_within_the_system
inline
MachineID map_L2ChipId_to_L2Cache(const Address& addr, NodeID L2ChipId)
{
  assert(L2ChipId < RubyConfig::numberOfChips());

  int L2bank = 0;
  MachineID mach = {MACHINETYPE_L2CACHE_ENUM, 0};

  if (RubyConfig::L2CachePerChipBits() > 0) {
    if (MAP_L2BANKS_TO_LOWEST_BITS) {
      L2bank = addr.bitSelect(RubyConfig::dataBlockBits(),
                         RubyConfig::dataBlockBits()+RubyConfig::L2CachePerChipBits()-1);
    } else {
      L2bank = addr.bitSelect(RubyConfig::dataBlockBits()+L2_CACHE_NUM_SETS_BITS,
                         RubyConfig::dataBlockBits()+L2_CACHE_NUM_SETS_BITS+RubyConfig::L2CachePerChipBits()-1);
    }
  }

  assert(L2bank < RubyConfig::numberOfL2CachePerChip());
  assert(L2bank >= 0);

  mach.num = L2ChipId*RubyConfig::numberOfL2CachePerChip() // base #
    + L2bank; // bank #
  assert(mach.num < RubyConfig::numberOfL2Cache());
  return mach;
}

// used to determine the home directory
// returns a value between 0 and total_directories_within_the_system
inline
NodeID map_Address_to_DirectoryNode(const Address& addr)
{
  NodeID dirNode = 0;

  if (RubyConfig::memoryBits() > 0) {
    dirNode = addr.bitSelect(RubyConfig::dataBlockBits(),
                        RubyConfig::dataBlockBits()+RubyConfig::memoryBits()-1);
  }

  //  Index indexHighPortion = address.bitSelect(MEMORY_SIZE_BITS-1, PAGE_SIZE_BITS+NUMBER_OF_MEMORY_MODULE_BITS);
  //  Index indexLowPortion  = address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS-1);

  //Index index = indexLowPortion | (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));

/*

ADDRESS_WIDTH    MEMORY_SIZE_BITS        PAGE_SIZE_BITS  DATA_BLOCK_BITS
  |                    |                       |               |
 \ /                  \ /                     \ /             \ /       0
  -----------------------------------------------------------------------
  |       unused        |xxxxxxxxxxxxxxx|       |xxxxxxxxxxxxxxx|       |
  |                     |xxxxxxxxxxxxxxx|       |xxxxxxxxxxxxxxx|       |
  -----------------------------------------------------------------------
                        indexHighPortion         indexLowPortion
                                        <------->
                               NUMBER_OF_MEMORY_MODULE_BITS
  */

  assert(dirNode < RubyConfig::numberOfMemories());
  assert(dirNode >= 0);
  return dirNode;
}

// used to determine the home directory
// returns a value between 0 and total_directories_within_the_system
inline
MachineID map_Address_to_Directory(const Address &addr)
{
  MachineID mach = {MachineType_Directory, map_Address_to_DirectoryNode(addr)};
  return mach;
}

inline
MachineID map_Address_to_CentralArbiterNode(const Address& addr)
{
  MachineType t = MACHINETYPE_PERSISTENTARBITER_ENUM;
  MachineID mach = {t, map_Address_to_DirectoryNode(addr)};

  assert(mach.num < RubyConfig::numberOfMemories());
  assert(mach.num >= 0);
  return mach;
}

inline
NetDest getMultiStaticL2BankNetDest(const Address& addr, const Set& sharers)  // set of L2RubyNodes
{
  NetDest dest;

  for (int i = 0; i < sharers.getSize(); i++) {
    if (sharers.isElement(i)) {
      dest.add(map_L2ChipId_to_L2Cache(addr,i));
    }
  }
  return dest;
}

inline
NetDest getOtherLocalL1IDs(MachineID L1)
{
  int start = (L1.num / RubyConfig::numberOfProcsPerChip()) * RubyConfig::numberOfProcsPerChip();
  NetDest ret;

  assert(MACHINETYPE_L1CACHE_ENUM != MachineType_NUM);

  for (int i = start; i < (start + RubyConfig::numberOfProcsPerChip()); i++) {
    if (i != L1.num) {
      MachineID mach = { MACHINETYPE_L1CACHE_ENUM, i };
      ret.add( mach );
    }
  }

  return ret;
}

inline
NetDest getLocalL1IDs(MachineID mach)
{
  assert(MACHINETYPE_L1CACHE_ENUM != MachineType_NUM);

  NetDest ret;

  if (mach.type == MACHINETYPE_L1CACHE_ENUM) {

    int start = (mach.num / RubyConfig::numberOfL1CachePerChip()) * RubyConfig::numberOfProcsPerChip();

    for (int i = start; i < (start + RubyConfig::numberOfProcsPerChip()); i++) {
      MachineID mach = { MACHINETYPE_L1CACHE_ENUM, i };
      ret.add( mach );
    }
  }
  else if (mach.type == MACHINETYPE_L2CACHE_ENUM) {

    int chip = mach.num/RubyConfig::numberOfL2CachePerChip();
    int start = ( chip*RubyConfig::numberOfL1CachePerChip());
    for (int i = start; i < (start + RubyConfig::numberOfL1CachePerChip()); i++) {
      MachineID mach = { MACHINETYPE_L1CACHE_ENUM, i };
      ret.add( mach );
    }
  }

  return ret;
}

inline
NetDest getExternalL1IDs(MachineID L1)
{
  NetDest ret;

  assert(MACHINETYPE_L1CACHE_ENUM != MachineType_NUM);

  for (int i = 0; i < RubyConfig::numberOfProcessors(); i++) {
    // ret.add( (NodeID) i);
    MachineID mach = { MACHINETYPE_L1CACHE_ENUM, i };
    ret.add( mach );
  }

  ret.removeNetDest(getLocalL1IDs(L1));

  return ret;
}

inline
bool isLocalProcessor(MachineID thisId, MachineID tarID)
{
  int start = (thisId.num / RubyConfig::numberOfProcsPerChip()) * RubyConfig::numberOfProcsPerChip();

  for (int i = start; i < (start + RubyConfig::numberOfProcsPerChip()); i++) {
    if (i == tarID.num) {
      return true;
    }
  }
  return false;
}


inline
NetDest getAllPertinentL2Banks(const Address& addr)  // set of L2RubyNodes
{
  NetDest dest;

  for (int i = 0; i < RubyConfig::numberOfChips(); i++) {
    dest.add(map_L2ChipId_to_L2Cache(addr,i));
  }
  return dest;
}

inline
bool isL1OnChip(MachineID L1machID, NodeID L2NodeID)
{
  if (L1machID.type == MACHINETYPE_L1CACHE_ENUM) {
    return (L1machID.num == L2NodeID);
  } else {
    return false;
  }
}

inline
bool isL2OnChip(MachineID L2machID, NodeID L2NodeID)
{
  if (L2machID.type == MACHINETYPE_L2CACHE_ENUM) {
    return (L2machID.num == L2NodeID);
  } else {
    return false;
  }
}

inline
NodeID closest_clockwise_distance(NodeID this_node, NodeID next_node)
{
  if (this_node <= next_node) {
    return (next_node - this_node);
  } else {
    return (next_node - this_node + RubyConfig::numberOfChips());
  }
}

inline
bool closer_clockwise_processor(NodeID this_node, NodeID newer, NodeID older)
{
  return (closest_clockwise_distance(this_node, newer) < closest_clockwise_distance(this_node, older));
}

extern inline NodeID getChipID(MachineID L2machID)
{
  return (L2machID.num%RubyConfig::numberOfChips())/RubyConfig::numberOfProcsPerChip();
}

extern inline NodeID machineIDToNodeID(MachineID machID)
{
  // return machID.num%RubyConfig::numberOfChips();
  return machID.num;
}

extern inline NodeID machineIDToVersion(MachineID machID)
{
  return machID.num/RubyConfig::numberOfChips();
}

extern inline MachineType machineIDToMachineType(MachineID machID)
{
  return machID.type;
}

extern inline NodeID L1CacheMachIDToProcessorNum(MachineID machID)
{
  assert(machID.type == MachineType_L1Cache);
  return machID.num;
}

extern inline NodeID L2CacheMachIDToChipID(MachineID machID)
{
  assert(machID.type == MACHINETYPE_L2CACHE_ENUM);
  return machID.num/RubyConfig::numberOfL2CachePerChip();
}

extern inline MachineID getCollectorDest(MachineID L1MachID)
{
  MachineID mach = {MACHINETYPE_COLLECTOR_ENUM, L1MachID.num};
  return mach;
}

extern inline MachineID getCollectorL1Cache(MachineID colID)
{
  MachineID mach = {MACHINETYPE_L1CACHE_ENUM, colID.num};
  return mach;
}

extern inline MachineID getL1MachineID(NodeID L1RubyNode)
{
  MachineID mach = {MACHINETYPE_L1CACHE_ENUM, L1RubyNode};
  return mach;
}

extern inline GenericMachineType ConvertMachToGenericMach(MachineType machType) {
  if (machType == MACHINETYPE_L1CACHE_ENUM) {
    return GenericMachineType_L1Cache;
  } else if (machType == MACHINETYPE_L2CACHE_ENUM) {
    return GenericMachineType_L2Cache;
  } else if (machType == MACHINETYPE_L3CACHE_ENUM) {
    return GenericMachineType_L3Cache;
  } else if (machType == MachineType_Directory) {
    return GenericMachineType_Directory;
  } else if (machType == MACHINETYPE_COLLECTOR_ENUM) {
    return GenericMachineType_Collector;
  } else {
    ERROR_MSG("cannot convert to a GenericMachineType");
    return GenericMachineType_NULL;
  }
}


#endif  // COMPONENTMAPPINGFNS_H