1 // Copyright 2006 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // pattern.cc : library of stressful data patterns
17 #include <sys/types.h>
19 // This file must work with autoconf on its public version,
20 // so these includes are correct.
24 // Static data patterns.
26 static unsigned int walkingOnes_data[] = {
27 0x00000001, 0x00000002, 0x00000004, 0x00000008,
28 0x00000010, 0x00000020, 0x00000040, 0x00000080,
29 0x00000100, 0x00000200, 0x00000400, 0x00000800,
30 0x00001000, 0x00002000, 0x00004000, 0x00008000,
31 0x00010000, 0x00020000, 0x00040000, 0x00080000,
32 0x00100000, 0x00200000, 0x00400000, 0x00800000,
33 0x01000000, 0x02000000, 0x04000000, 0x08000000,
34 0x10000000, 0x20000000, 0x40000000, 0x80000000,
35 0x40000000, 0x20000000, 0x10000000, 0x08000000,
36 0x04000000, 0x02000000, 0x01000000, 0x00800000,
37 0x00400000, 0x00200000, 0x00100000, 0x00080000,
38 0x00040000, 0x00020000, 0x00010000, 0x00008000,
39 0x00004000, 0x00002000, 0x00001000, 0x00000800,
40 0x00000400, 0x00000200, 0x00000100, 0x00000080,
41 0x00000040, 0x00000020, 0x00000010, 0x00000008,
42 0x00000004, 0x00000002, 0x00000001, 0x00000000
44 static const struct PatternData walkingOnes = {
47 (sizeof walkingOnes_data / sizeof walkingOnes_data[0]) - 1,
48 {1, 1, 2, 1} // Weight for choosing 32/64/128/256 bit wide of this pattern
51 static unsigned int walkingInvOnes_data[] = {
52 0x00000001, 0xfffffffe, 0x00000002, 0xfffffffd,
53 0x00000004, 0xfffffffb, 0x00000008, 0xfffffff7,
54 0x00000010, 0xffffffef, 0x00000020, 0xffffffdf,
55 0x00000040, 0xffffffbf, 0x00000080, 0xffffff7f,
56 0x00000100, 0xfffffeff, 0x00000200, 0xfffffdff,
57 0x00000400, 0xfffffbff, 0x00000800, 0xfffff7ff,
58 0x00001000, 0xffffefff, 0x00002000, 0xffffdfff,
59 0x00004000, 0xffffbfff, 0x00008000, 0xffff7fff,
60 0x00010000, 0xfffeffff, 0x00020000, 0xfffdffff,
61 0x00040000, 0xfffbffff, 0x00080000, 0xfff7ffff,
62 0x00100000, 0xffefffff, 0x00200000, 0xffdfffff,
63 0x00400000, 0xffbfffff, 0x00800000, 0xff7fffff,
64 0x01000000, 0xfeffffff, 0x02000000, 0xfdffffff,
65 0x04000000, 0xfbffffff, 0x08000000, 0xf7ffffff,
66 0x10000000, 0xefffffff, 0x20000000, 0xdfffffff,
67 0x40000000, 0xbfffffff, 0x80000000, 0x7fffffff,
68 0x40000000, 0xbfffffff, 0x20000000, 0xdfffffff,
69 0x10000000, 0xefffffff, 0x08000000, 0xf7ffffff,
70 0x04000000, 0xfbffffff, 0x02000000, 0xfdffffff,
71 0x01000000, 0xfeffffff, 0x00800000, 0xff7fffff,
72 0x00400000, 0xffbfffff, 0x00200000, 0xffdfffff,
73 0x00100000, 0xffefffff, 0x00080000, 0xfff7ffff,
74 0x00040000, 0xfffbffff, 0x00020000, 0xfffdffff,
75 0x00010000, 0xfffeffff, 0x00008000, 0xffff7fff,
76 0x00004000, 0xffffbfff, 0x00002000, 0xffffdfff,
77 0x00001000, 0xffffefff, 0x00000800, 0xfffff7ff,
78 0x00000400, 0xfffffbff, 0x00000200, 0xfffffdff,
79 0x00000100, 0xfffffeff, 0x00000080, 0xffffff7f,
80 0x00000040, 0xffffffbf, 0x00000020, 0xffffffdf,
81 0x00000010, 0xffffffef, 0x00000008, 0xfffffff7,
82 0x00000004, 0xfffffffb, 0x00000002, 0xfffffffd,
83 0x00000001, 0xfffffffe, 0x00000000, 0xffffffff
85 static const struct PatternData walkingInvOnes = {
88 (sizeof walkingInvOnes_data / sizeof walkingInvOnes_data[0]) - 1,
92 static unsigned int walkingZeros_data[] = {
93 0xfffffffe, 0xfffffffd, 0xfffffffb, 0xfffffff7,
94 0xffffffef, 0xffffffdf, 0xffffffbf, 0xffffff7f,
95 0xfffffeff, 0xfffffdff, 0xfffffbff, 0xfffff7ff,
96 0xffffefff, 0xffffdfff, 0xffffbfff, 0xffff7fff,
97 0xfffeffff, 0xfffdffff, 0xfffbffff, 0xfff7ffff,
98 0xffefffff, 0xffdfffff, 0xffbfffff, 0xff7fffff,
99 0xfeffffff, 0xfdffffff, 0xfbffffff, 0xf7ffffff,
100 0xefffffff, 0xdfffffff, 0xbfffffff, 0x7fffffff,
101 0xbfffffff, 0xdfffffff, 0xefffffff, 0xf7ffffff,
102 0xfbffffff, 0xfdffffff, 0xfeffffff, 0xff7fffff,
103 0xffbfffff, 0xffdfffff, 0xffefffff, 0xfff7ffff,
104 0xfffbffff, 0xfffdffff, 0xfffeffff, 0xffff7fff,
105 0xffffbfff, 0xffffdfff, 0xffffefff, 0xfffff7ff,
106 0xfffffbff, 0xfffffdff, 0xfffffeff, 0xffffff7f,
107 0xffffffbf, 0xffffffdf, 0xffffffef, 0xfffffff7,
108 0xfffffffb, 0xfffffffd, 0xfffffffe, 0xffffffff
110 static const struct PatternData walkingZeros = {
113 (sizeof walkingZeros_data / sizeof walkingZeros_data[0]) - 1,
117 static unsigned int OneZero_data[] = { 0x00000000, 0xffffffff};
118 static const struct PatternData OneZero = {
121 (sizeof OneZero_data / sizeof OneZero_data[0]) - 1,
125 static unsigned int JustZero_data[] = { 0x00000000, 0x00000000};
126 static const struct PatternData JustZero = {
129 (sizeof JustZero_data / sizeof JustZero_data[0]) - 1,
133 static unsigned int JustOne_data[] = { 0xffffffff, 0xffffffff};
134 static const struct PatternData JustOne = {
137 (sizeof JustOne_data / sizeof JustOne_data[0]) - 1,
141 static unsigned int JustFive_data[] = { 0x55555555, 0x55555555};
142 static const struct PatternData JustFive = {
145 (sizeof JustFive_data / sizeof JustFive_data[0]) - 1,
149 static unsigned int JustA_data[] = { 0xaaaaaaaa, 0xaaaaaaaa};
150 static const struct PatternData JustA = {
153 (sizeof JustA_data / sizeof JustA_data[0]) - 1,
157 static unsigned int FiveA_data[] = { 0x55555555, 0xaaaaaaaa};
158 static const struct PatternData FiveA = {
161 (sizeof FiveA_data / sizeof FiveA_data[0]) - 1,
165 static unsigned int FiveA8_data[] = {
166 0x5aa5a55a, 0xa55a5aa5, 0xa55a5aa5, 0x5aa5a55a
168 static const struct PatternData FiveA8 = {
171 (sizeof FiveA8_data / sizeof FiveA8_data[0]) - 1,
175 static unsigned int Long8b10b_data[] = { 0x16161616, 0x16161616 };
176 static const struct PatternData Long8b10b = {
179 (sizeof Long8b10b_data / sizeof Long8b10b_data[0]) - 1,
183 static unsigned int Short8b10b_data[] = { 0xb5b5b5b5, 0xb5b5b5b5 };
184 static const struct PatternData Short8b10b = {
187 (sizeof Short8b10b_data / sizeof Short8b10b_data[0]) - 1,
191 static unsigned int Checker8b10b_data[] = { 0xb5b5b5b5, 0x4a4a4a4a };
192 static const struct PatternData Checker8b10b = {
195 (sizeof Checker8b10b_data / sizeof Checker8b10b_data[0]) - 1,
199 static unsigned int Five7_data[] = { 0x55555557, 0x55575555 };
200 static const struct PatternData Five7 = {
203 (sizeof Five7_data / sizeof Five7_data[0]) - 1,
207 static unsigned int Zero2fd_data[] = { 0x00020002, 0xfffdfffd };
208 static const struct PatternData Zero2fd = {
211 (sizeof Zero2fd_data / sizeof Zero2fd_data[0]) - 1,
215 // Extern array of useable patterns.
216 static const struct PatternData pattern_array[] = {
233 static const int pattern_array_size =
234 sizeof pattern_array / sizeof pattern_array[0];
240 Pattern::~Pattern() {
246 // Calculate CRC for this pattern. This must match
247 // the CRC calculation in worker.cc.
248 int Pattern::CalculateCrc() {
250 // Consider refactoring to the form:
251 // while (i < count) AdlerInc(uint64, uint64, AdlerChecksum*)
257 // checksum is calculated using only the first 4096 bytes of data.
259 int blocksize = 4096;
260 int count = blocksize / sizeof i;
279 crc_ = new AdlerChecksum();
280 crc_->Set(a1, a2, b1, b2);
284 // Initialize pattern's CRC.
285 int Pattern::Initialize(const struct PatternData &pattern_init,
291 pattern_ = &pattern_init;
297 name_.append(pattern_->name);
302 if (buswidth == 32) {
305 } else if (buswidth == 64) {
308 } else if (buswidth == 128) {
311 } else if (buswidth == 256) {
315 logprintf(0, "Process Error: Confused by bus width %d\n",
317 name_.append("Broken");
327 PatternList::PatternList() {
332 PatternList::~PatternList() {
338 // Fill in the class with references to the static data patterns
339 int PatternList::Initialize() {
340 int patterncount = 0;
343 patterns_.resize(pattern_array_size * 8);
344 for (int i = 0; i < pattern_array_size; i++) {
346 weightcount += pattern_array[i].weight[0];
347 patterns_[patterncount++].Initialize(pattern_array[i], 32, false,
348 pattern_array[i].weight[0]);
349 weightcount += pattern_array[i].weight[1];
350 patterns_[patterncount++].Initialize(pattern_array[i], 64, false,
351 pattern_array[i].weight[1]);
352 weightcount += pattern_array[i].weight[2];
353 patterns_[patterncount++].Initialize(pattern_array[i], 128, false,
354 pattern_array[i].weight[2]);
355 weightcount += pattern_array[i].weight[3];
356 patterns_[patterncount++].Initialize(pattern_array[i], 256, false,
357 pattern_array[i].weight[3]);
360 weightcount += pattern_array[i].weight[0];
361 patterns_[patterncount++].Initialize(pattern_array[i], 32, true,
362 pattern_array[i].weight[0]);
363 weightcount += pattern_array[i].weight[1];
364 patterns_[patterncount++].Initialize(pattern_array[i], 64, true,
365 pattern_array[i].weight[1]);
366 weightcount += pattern_array[i].weight[2];
367 patterns_[patterncount++].Initialize(pattern_array[i], 128, true,
368 pattern_array[i].weight[2]);
369 weightcount += pattern_array[i].weight[3];
370 patterns_[patterncount++].Initialize(pattern_array[i], 256, true,
371 pattern_array[i].weight[3]);
373 size_ = patterncount;
374 weightcount_ = weightcount;
377 logprintf(12, "Log: initialized %d data patterns\n", size_);
383 int PatternList::Destroy() {
394 // Return pattern numbered "i"
395 Pattern *PatternList::GetPattern(int i) {
396 if (static_cast<unsigned int>(i) < size_) {
397 return &patterns_[i];
400 logprintf(0, "Process Error: Out of bounds pattern access\n");
404 // Return a randomly selected pattern.
405 Pattern *PatternList::GetRandomPattern() {
406 unsigned int target = random();
407 target = target % weightcount_;
410 unsigned int sum = 0;
411 while (target > sum) {
412 sum += patterns_[i].weight();
416 return &patterns_[i];
419 logprintf(0, "Process Error: Out of bounds pattern access\n");