1b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// Copyright 2006 Google Inc. All Rights Reserved.
2b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
3b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// Licensed under the Apache License, Version 2.0 (the "License");
4b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// you may not use this file except in compliance with the License.
5b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// You may obtain a copy of the License at
6b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
7b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson//      http://www.apache.org/licenses/LICENSE-2.0
8b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
9b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// Unless required by applicable law or agreed to in writing, software
10b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// distributed under the License is distributed on an "AS IS" BASIS,
11b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// See the License for the specific language governing permissions and
13b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// limitations under the License.
14b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
15b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// sat.h : sat stress test object interface and data structures
16b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
17b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#ifndef STRESSAPPTEST_SAT_H_
18b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#define STRESSAPPTEST_SAT_H_
19b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
20b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include <signal.h>
21b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
22b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include <map>
23b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include <string>
24b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include <vector>
25b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
26b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// This file must work with autoconf on its public version,
27b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// so these includes are correct.
28b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include "finelock_queue.h"
29b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include "queue.h"
30b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include "sattypes.h"
31b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include "worker.h"
32b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#include "os.h"
33b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
34b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson// SAT stress test class.
35b0114cb9f332db144f65291211ae65f7f0e814e6Scott Andersonclass Sat {
36b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson public:
37b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Enum for page queue implementation switch.
38b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  enum PageQueueType { SAT_ONELOCK, SAT_FINELOCK };
39b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
40b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  Sat();
41b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual ~Sat();
42b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
43b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Read configuration from arguments. Called first.
44b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool ParseArgs(int argc, char **argv);
45b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual bool CheckGoogleSpecificArgs(int argc, char **argv, int *i);
46b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Initialize data structures, subclasses, and resources,
47b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // based on command line args.
48b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Called after ParseArgs().
49b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool Initialize();
50b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
51b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Execute the test. Initialize() and ParseArgs() must be called first.
52b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // This must be called from a single-threaded program.
53b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool Run();
54b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
55b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Pretty print result summary.
56b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Called after Run().
57b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Return value is success or failure of the SAT run, *not* of this function!
58b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool PrintResults();
59b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
60b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Pretty print version info.
61b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool PrintVersion();
62b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
63b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Pretty print help.
64b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void PrintHelp();
65b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
66b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Clean up allocations and resources.
67b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Called last.
68b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool Cleanup();
69b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
70b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Abort Run().  Only for use by Run()-installed signal handlers.
71b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void Break() { user_break_ = true; }
72b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
73b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Fetch and return empty and full pages into the empty and full pools.
74b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool GetValid(struct page_entry *pe);
75b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool PutValid(struct page_entry *pe);
76b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool GetEmpty(struct page_entry *pe);
77b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool PutEmpty(struct page_entry *pe);
78b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
79b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool GetValid(struct page_entry *pe, int32 tag);
80b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool GetEmpty(struct page_entry *pe, int32 tag);
81b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
82b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Accessor functions.
83b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int verbosity() const { return verbosity_; }
84b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int logfile() const { return logfile_; }
85b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int page_length() const { return page_length_; }
86b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int disk_pages() const { return disk_pages_; }
87b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int strict() const { return strict_; }
88b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int tag_mode() const { return tag_mode_; }
89b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int status() const { return statuscount_; }
90b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void bad_status() { statuscount_++; }
91b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int errors() const { return errorcount_; }
92b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int warm() const { return warm_; }
93b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool stop_on_error() const { return stop_on_error_; }
94b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int32 region_mask() const { return region_mask_; }
95b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Semi-accessor to find the "nth" region to avoid replicated bit searching..
96b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int32 region_find(int32 num) const {
97b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    for (int i = 0; i < 32; i++) {
98b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson      if ((1 << i) & region_mask_) {
99b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson        if (num == 0)
100b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson          return i;
101b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson        num--;
102b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson      }
103b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    }
104b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    return 0;
105b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  }
106b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
107b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Causes false errors for unittesting.
108b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Setting to "true" causes errors to be injected.
109b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void set_error_injection(bool errors) { error_injection_ = errors; }
110b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool error_injection() const { return error_injection_; }
111b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
112b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson protected:
113b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Opens log file for writing. Returns 0 on failure.
114b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool InitializeLogfile();
115b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Checks for supported environment. Returns 0 on failure.
116b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool CheckEnvironment();
117b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Allocates size_ bytes of test memory.
118b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool AllocateMemory();
119b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Initializes datapattern reference structures.
120b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool InitializePatterns();
121b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Initializes test memory with datapatterns.
122b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool InitializePages();
123b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
124b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Start up worker threads.
125b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void InitializeThreads();
126b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Spawn worker threads.
127b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void SpawnThreads();
128b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Reap worker threads.
129b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void JoinThreads();
130b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Run bandwidth and error analysis.
131b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void RunAnalysis();
132b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Delete worker threads.
133b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void DeleteThreads();
134b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
135b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Return the number of cpus in the system.
136b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int CpuCount();
137241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  // Return the worst-case (largest) cache line size of the system.
138241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  int CacheLineSize();
139b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
140b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Collect error counts from threads.
141b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 GetTotalErrorCount();
142b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
143b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Command line arguments.
144b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  string cmdline_;
145b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
146b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Memory and test configuration.
147b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int runtime_seconds_;               // Seconds to run.
148b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int page_length_;                   // Length of each memory block.
149b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 pages_;                       // Number of memory blocks.
150b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 size_;                        // Size of memory tested, in bytes.
151b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 size_mb_;                     // Size of memory tested, in MB.
152241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  int64 reserve_mb_;                  // Reserve at least this amount of memory
153241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders                                      // for the system, in MB.
154b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 min_hugepages_mbytes_;        // Minimum hugepages size.
155b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 freepages_;                   // How many invalid pages we need.
156b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int disk_pages_;                    // Number of pages per temp file.
157b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  uint64 paddr_base_;                 // Physical address base.
158241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  uint64 channel_hash_;               // Mask of address bits XORed for channel.
159241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  int channel_width_;                 // Channel width in bits.
160241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  vector< vector<string> > channels_;  // Memory module names per channel.
161b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
162b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Control flags.
163b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  volatile sig_atomic_t user_break_;  // User has signalled early exit.  Used as
164b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // a boolean.
165b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int verbosity_;                     // How much to print.
166241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  int print_delay_;                   // Chatty update frequency.
167b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int strict_;                        // Check results per transaction.
168241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  int warm_;                          // FPU warms CPU while copying.
169b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int address_mode_;                  // 32 or 64 bit binary.
170b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool stop_on_error_;                // Exit immendiately on any error.
171b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool findfiles_;                    // Autodetect tempfile locations.
172b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
173b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool error_injection_;              // Simulate errors, for unittests.
174b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool crazy_error_injection_;        // Simulate lots of errors.
175b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  uint64 max_errorcount_;             // Number of errors before forced exit.
176b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int run_on_anything_;               // Ignore unknown machine ereor.
177b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int use_logfile_;                   // Log to a file.
178b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  char logfilename_[255];             // Name of file to log to.
179b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int logfile_;                       // File handle to log to.
180241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  bool log_timestamps_;               // Whether to add timestamps to log lines.
181b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
182b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Disk thread options.
183b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int read_block_size_;               // Size of block to read from disk.
184b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int write_block_size_;              // Size of block to write to disk.
185b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 segment_size_;                // Size of segment to split disk into.
186b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int cache_size_;                    // Size of disk cache.
187b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int blocks_per_segment_;            // Number of blocks to test per segment.
188b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int read_threshold_;                // Maximum time (in us) a read should take
189b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // before warning of a slow read.
190b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int write_threshold_;               // Maximum time (in us) a write should
191b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // take before warning of a slow write.
192b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int non_destructive_;               // Whether to use non-destructive mode for
193b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // the disk test.
194b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
195b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Generic Options.
196b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int monitor_mode_;                  // Switch for monitor-only mode SAT.
197b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // This switch trumps most of the other
198b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // argument, as SAT will only run error
199b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // polling threads.
200b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int tag_mode_;                      // Do tagging of memory and strict
201b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // checking for misplaced cachelines.
202b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
203b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool do_page_map_;                  // Should we print a list of used pages?
204b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  unsigned char *page_bitmap_;        // Store bitmap of physical pages seen.
205b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  uint64 page_bitmap_size_;           // Length of physical memory represented.
206b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
207b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Cpu Cache Coherency Options.
208b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool cc_test_;                      // Flag to decide whether to start the
209b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // cache coherency threads.
210b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int cc_cacheline_count_;            // Number of cache line size structures.
211241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  int cc_cacheline_size_;             // Size of a cache line.
212b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int cc_inc_count_;                  // Number of times to increment the shared
213b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // cache lines structure members.
214b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
215241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  // Cpu Frequency Options.
216241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  bool cpu_freq_test_;                // Flag to decide whether to start the
217241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders                                      // cpu frequency thread.
218241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  int cpu_freq_threshold_;            // The MHz threshold which will cause
219241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders                                      // the test to fail.
220241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders  int cpu_freq_round_;                // Round the computed frequency to this
221241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders                                      // value.
222241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders
223b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Thread control.
224b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int file_threads_;                  // Threads of file IO.
225b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int net_threads_;                   // Threads of network IO.
226b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int listen_threads_;                // Threads for network IO to connect.
227b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int memory_threads_;                // Threads of memcpy.
228b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int invert_threads_;                // Threads of invert.
229b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int fill_threads_;                  // Threads of memset.
230b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int check_threads_;                 // Threads of strcmp.
231b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int cpu_stress_threads_;            // Threads of CPU stress workload.
232b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int disk_threads_;                  // Threads of disk test.
233b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int random_threads_;                // Number of random disk threads.
234b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int total_threads_;                 // Total threads used.
235b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool error_poll_;                   // Poll for system errors.
236b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
237b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Resources.
238b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  cc_cacheline_data *cc_cacheline_data_;  // The cache line sized datastructure
239b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                          // used by the ccache threads
240b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                          // (in worker.h).
241b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  vector<string> filename_;           // Filenames for file IO.
242b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  vector<string> ipaddrs_;            // Addresses for network IO.
243b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  vector<string> diskfilename_;       // Filename for disk IO device.
244b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Block table for IO device.
245b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  vector<DiskBlockTable*> blocktables_;
246b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
247b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int32 region_mask_;                 // Bitmask of available NUMA regions.
248b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int32 region_count_;                // Count of available NUMA regions.
249b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int32 region_[32];                  // Pagecount per region.
250b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int region_mode_;                   // What to do with NUMA hints?
251b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  static const int kLocalNuma = 1;    // Target local memory.
252b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  static const int kRemoteNuma = 2;   // Target remote memory.
253b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
254b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Results.
255b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 errorcount_;                  // Total hardware incidents seen.
256b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int statuscount_;                   // Total test errors seen.
257b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
258b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Thread type constants and types
259b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  enum ThreadType {
260b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kMemoryType = 0,
261b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kFileIOType = 1,
262b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kNetIOType = 2,
263b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kNetSlaveType = 3,
264b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kCheckType = 4,
265b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kInvertType = 5,
266b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kDiskType = 6,
267b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kRandomDiskType = 7,
268b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kCPUType = 8,
269b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kErrorType = 9,
270241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders    kCCType = 10,
271241f33a3e958842e3db803c03300764bd2ee9c19Nick Sanders    kCPUFreqType = 11,
272b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  };
273b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
274b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Helper functions.
275b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void AcquireWorkerLock();
276b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void ReleaseWorkerLock();
277b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  pthread_mutex_t worker_lock_;  // Lock access to the worker thread structure.
278b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  typedef vector<WorkerThread*> WorkerVector;
279b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  typedef map<int, WorkerVector*> WorkerMap;
280b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Contains all worker threads.
281b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  WorkerMap workers_map_;
282b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Delay between power spikes.
283b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  time_t pause_delay_;
284b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // The duration of each pause (for power spikes).
285b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  time_t pause_duration_;
286b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // For the workers we pause and resume to create power spikes.
287b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  WorkerStatus power_spike_status_;
288b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // For the workers we never pause.
289b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  WorkerStatus continuous_status_;
290b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
291b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  class OsLayer *os_;                   // Os abstraction: put hacks here.
292b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  class PatternList *patternlist_;      // Access to global data patterns.
293b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
294b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // RunAnalysis methods
295b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void AnalysisAllStats();              // Summary of all runs.
296b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void MemoryStats();
297b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void FileStats();
298b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void NetStats();
299b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void CheckStats();
300b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void InvertStats();
301b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void DiskStats();
302b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
303b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void QueueStats();
304b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
305b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Physical page use reporting.
306b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void AddrMapInit();
307b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void AddrMapUpdate(struct page_entry *pe);
308b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void AddrMapPrint();
309b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
310b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // additional memory data from google-specific tests.
311b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void GoogleMemoryStats(float *memcopy_data,
312b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                 float *memcopy_bandwidth);
313b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
314b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void GoogleOsOptions(std::map<std::string, std::string> *options);
315b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
316b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Page queues, only one of (valid_+empty_) or (finelock_q_) will be used
317b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // at a time. A commandline switch controls which queue implementation will
318b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // be used.
319b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  class PageEntryQueue *valid_;        // Page queue structure, valid pages.
320b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  class PageEntryQueue *empty_;        // Page queue structure, free pages.
321b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  class FineLockPEQueue *finelock_q_;  // Page queue with fine-grain locks
322b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  Sat::PageQueueType pe_q_implementation_;   // Queue implementation switch
323b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
324b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  DISALLOW_COPY_AND_ASSIGN(Sat);
325b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson};
326b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
327b0114cb9f332db144f65291211ae65f7f0e814e6Scott AndersonSat *SatFactory();
328b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
329b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#endif  // STRESSAPPTEST_SAT_H_
330