ruby: Migrate all of ruby and slicc to SCons.
[gem5.git] / src / mem / ruby / config / RubyConfig.cc
1
2 /*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /*
31 * RubyConfig.C
32 *
33 * Description: See RubyConfig.h
34 *
35 * $Id$
36 *
37 */
38
39 #include "config/ruby_debug.hh"
40 #include "mem/ruby/config/RubyConfig.hh"
41 #include "mem/protocol/protocol_name.hh"
42 #include "mem/gems_common/util.hh"
43 #include "mem/protocol/Protocol.hh"
44
45 #define CHECK_POWER_OF_2(N) { if (!is_power_of_2(N)) { ERROR_MSG(#N " must be a power of 2."); }}
46 #define CHECK_ZERO(N) { if (N != 0) { ERROR_MSG(#N " must be zero at initialization."); }}
47 #define CHECK_NON_ZERO(N) { if (N == 0) { ERROR_MSG(#N " must be non-zero."); }}
48
49
50 void RubyConfig::init()
51 {
52 // MemoryControl:
53 CHECK_NON_ZERO(MEM_BUS_CYCLE_MULTIPLIER);
54 CHECK_NON_ZERO(BANKS_PER_RANK);
55 CHECK_NON_ZERO(RANKS_PER_DIMM);
56 CHECK_NON_ZERO(DIMMS_PER_CHANNEL);
57 CHECK_NON_ZERO(BANK_QUEUE_SIZE);
58 CHECK_NON_ZERO(BANK_BUSY_TIME);
59 CHECK_NON_ZERO(MEM_CTL_LATENCY);
60 CHECK_NON_ZERO(REFRESH_PERIOD);
61 CHECK_NON_ZERO(BASIC_BUS_BUSY_TIME);
62
63 CHECK_POWER_OF_2(BANKS_PER_RANK);
64 CHECK_POWER_OF_2(RANKS_PER_DIMM);
65 CHECK_POWER_OF_2(DIMMS_PER_CHANNEL);
66
67 CHECK_NON_ZERO(g_MEMORY_SIZE_BYTES);
68 CHECK_NON_ZERO(g_DATA_BLOCK_BYTES);
69 CHECK_NON_ZERO(g_PAGE_SIZE_BYTES);
70 CHECK_NON_ZERO(g_NUM_PROCESSORS);
71 CHECK_NON_ZERO(g_PROCS_PER_CHIP);
72 if(g_NUM_SMT_THREADS == 0){ //defaults to single-threaded
73 g_NUM_SMT_THREADS = 1;
74 }
75 if (g_NUM_L2_BANKS == 0) { // defaults to number of ruby nodes
76 g_NUM_L2_BANKS = g_NUM_PROCESSORS;
77 }
78 if (g_NUM_MEMORIES == 0) { // defaults to number of ruby nodes
79 g_NUM_MEMORIES = g_NUM_PROCESSORS;
80 }
81
82 CHECK_ZERO(g_MEMORY_SIZE_BITS);
83 CHECK_ZERO(g_DATA_BLOCK_BITS);
84 CHECK_ZERO(g_PAGE_SIZE_BITS);
85 CHECK_ZERO(g_NUM_PROCESSORS_BITS);
86 CHECK_ZERO(g_NUM_CHIP_BITS);
87 CHECK_ZERO(g_NUM_L2_BANKS_BITS);
88 CHECK_ZERO(g_NUM_MEMORIES_BITS);
89 CHECK_ZERO(g_PROCS_PER_CHIP_BITS);
90 CHECK_ZERO(g_NUM_L2_BANKS_PER_CHIP);
91 CHECK_ZERO(g_NUM_L2_BANKS_PER_CHIP_BITS);
92 CHECK_ZERO(g_NUM_MEMORIES_BITS);
93 CHECK_ZERO(g_MEMORY_MODULE_BLOCKS);
94 CHECK_ZERO(g_MEMORY_MODULE_BITS);
95 CHECK_ZERO(g_NUM_MEMORIES_PER_CHIP);
96
97 CHECK_POWER_OF_2(g_MEMORY_SIZE_BYTES);
98 CHECK_POWER_OF_2(g_DATA_BLOCK_BYTES);
99 CHECK_POWER_OF_2(g_NUM_PROCESSORS);
100 CHECK_POWER_OF_2(g_NUM_L2_BANKS);
101 CHECK_POWER_OF_2(g_NUM_MEMORIES);
102 CHECK_POWER_OF_2(g_PROCS_PER_CHIP);
103
104 ASSERT(g_NUM_PROCESSORS >= g_PROCS_PER_CHIP); // obviously can't have less processors than procs/chip
105 g_NUM_CHIPS = g_NUM_PROCESSORS/g_PROCS_PER_CHIP;
106 ASSERT(g_NUM_L2_BANKS >= g_NUM_CHIPS); // cannot have a single L2cache across multiple chips
107
108 g_NUM_L2_BANKS_PER_CHIP = g_NUM_L2_BANKS/g_NUM_CHIPS;
109
110 ASSERT(L2_CACHE_NUM_SETS_BITS > log_int(g_NUM_L2_BANKS_PER_CHIP)); // cannot have less than one set per bank
111 L2_CACHE_NUM_SETS_BITS = L2_CACHE_NUM_SETS_BITS - log_int(g_NUM_L2_BANKS_PER_CHIP);
112
113 if (g_NUM_CHIPS > g_NUM_MEMORIES) {
114 g_NUM_MEMORIES_PER_CHIP = 1; // some chips have a memory, others don't
115 } else {
116 g_NUM_MEMORIES_PER_CHIP = g_NUM_MEMORIES/g_NUM_CHIPS;
117 }
118
119 g_NUM_CHIP_BITS = log_int(g_NUM_CHIPS);
120 g_MEMORY_SIZE_BITS = log_int(g_MEMORY_SIZE_BYTES);
121 g_DATA_BLOCK_BITS = log_int(g_DATA_BLOCK_BYTES);
122 g_PAGE_SIZE_BITS = log_int(g_PAGE_SIZE_BYTES);
123 g_NUM_PROCESSORS_BITS = log_int(g_NUM_PROCESSORS);
124 g_NUM_L2_BANKS_BITS = log_int(g_NUM_L2_BANKS);
125 g_NUM_L2_BANKS_PER_CHIP_BITS = log_int(g_NUM_L2_BANKS_PER_CHIP);
126 g_NUM_MEMORIES_BITS = log_int(g_NUM_MEMORIES);
127 g_PROCS_PER_CHIP_BITS = log_int(g_PROCS_PER_CHIP);
128
129 g_MEMORY_MODULE_BITS = g_MEMORY_SIZE_BITS - g_DATA_BLOCK_BITS - g_NUM_MEMORIES_BITS;
130 g_MEMORY_MODULE_BLOCKS = (int64(1) << g_MEMORY_MODULE_BITS);
131
132 if ((!Protocol::m_CMP) && (g_PROCS_PER_CHIP > 1)) {
133 ERROR_MSG("Non-CMP protocol should set g_PROCS_PER_CHIP to 1");
134 }
135
136 // Randomize the execution
137 srandom(g_RANDOM_SEED);
138 }
139
140 int RubyConfig::L1CacheNumToL2Base(NodeID L1CacheNum)
141 {
142 return L1CacheNum/g_PROCS_PER_CHIP;
143 }
144
145 static void print_parameters(ostream& out)
146 {
147
148 #define PARAM(NAME) { out << #NAME << ": " << NAME << endl; }
149 #define PARAM_UINT(NAME) { out << #NAME << ": " << NAME << endl; }
150 #define PARAM_ULONG(NAME) { out << #NAME << ": " << NAME << endl; }
151 #define PARAM_BOOL(NAME) { out << #NAME << ": " << bool_to_string(NAME) << endl; }
152 #define PARAM_DOUBLE(NAME) { out << #NAME << ": " << NAME << endl; }
153 #define PARAM_STRING(NAME) { assert(NAME != NULL); out << #NAME << ": " << string(NAME) << endl; }
154 #define PARAM_ARRAY(PTYPE, NAME, ARRAY_SIZE) \
155 { \
156 out << #NAME << ": ("; \
157 for (int i = 0; i < ARRAY_SIZE; i++) { \
158 if (i != 0) { \
159 out << ", "; \
160 } \
161 out << NAME[i]; \
162 } \
163 out << ")" << endl; \
164 } \
165
166
167 #include "mem/ruby/config/config.hh"
168 #undef PARAM
169 #undef PARAM_UINT
170 #undef PARAM_ULONG
171 #undef PARAM_BOOL
172 #undef PARAM_DOUBLE
173 #undef PARAM_STRING
174 #undef PARAM_ARRAY
175 }
176
177 void RubyConfig::printConfiguration(ostream& out) {
178 out << "Ruby Configuration" << endl;
179 out << "------------------" << endl;
180
181 out << "protocol: " << CURRENT_PROTOCOL << endl;
182 out << "compiled_at: " << __TIME__ << ", " << __DATE__ << endl;
183 out << "RUBY_DEBUG: " << bool_to_string(RUBY_DEBUG) << endl;
184
185 char buffer[100];
186 gethostname(buffer, 50);
187 out << "hostname: " << buffer << endl;
188
189 print_parameters(out);
190 }
191
192