sat.h revision b0114cb9f332db144f65291211ae65f7f0e814e6
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();
137b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
138b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Collect error counts from threads.
139b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 GetTotalErrorCount();
140b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
141b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Command line arguments.
142b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  string cmdline_;
143b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
144b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Memory and test configuration.
145b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int runtime_seconds_;               // Seconds to run.
146b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int page_length_;                   // Length of each memory block.
147b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 pages_;                       // Number of memory blocks.
148b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 size_;                        // Size of memory tested, in bytes.
149b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 size_mb_;                     // Size of memory tested, in MB.
150b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 min_hugepages_mbytes_;        // Minimum hugepages size.
151b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 freepages_;                   // How many invalid pages we need.
152b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int disk_pages_;                    // Number of pages per temp file.
153b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  uint64 paddr_base_;                 // Physical address base.
154b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
155b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Control flags.
156b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  volatile sig_atomic_t user_break_;  // User has signalled early exit.  Used as
157b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // a boolean.
158b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int verbosity_;                     // How much to print.
159b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int strict_;                        // Check results per transaction.
160b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int warm_;                          // FPU warms CPU while coying.
161b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int address_mode_;                  // 32 or 64 bit binary.
162b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool stop_on_error_;                // Exit immendiately on any error.
163b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool findfiles_;                    // Autodetect tempfile locations.
164b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
165b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool error_injection_;              // Simulate errors, for unittests.
166b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool crazy_error_injection_;        // Simulate lots of errors.
167b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  uint64 max_errorcount_;             // Number of errors before forced exit.
168b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int run_on_anything_;               // Ignore unknown machine ereor.
169b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int use_logfile_;                   // Log to a file.
170b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  char logfilename_[255];             // Name of file to log to.
171b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int logfile_;                       // File handle to log to.
172b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
173b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Disk thread options.
174b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int read_block_size_;               // Size of block to read from disk.
175b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int write_block_size_;              // Size of block to write to disk.
176b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 segment_size_;                // Size of segment to split disk into.
177b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int cache_size_;                    // Size of disk cache.
178b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int blocks_per_segment_;            // Number of blocks to test per segment.
179b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int read_threshold_;                // Maximum time (in us) a read should take
180b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // before warning of a slow read.
181b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int write_threshold_;               // Maximum time (in us) a write should
182b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // take before warning of a slow write.
183b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int non_destructive_;               // Whether to use non-destructive mode for
184b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // the disk test.
185b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
186b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Generic Options.
187b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int monitor_mode_;                  // Switch for monitor-only mode SAT.
188b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // This switch trumps most of the other
189b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // argument, as SAT will only run error
190b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // polling threads.
191b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int tag_mode_;                      // Do tagging of memory and strict
192b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // checking for misplaced cachelines.
193b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
194b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool do_page_map_;                  // Should we print a list of used pages?
195b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  unsigned char *page_bitmap_;        // Store bitmap of physical pages seen.
196b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  uint64 page_bitmap_size_;           // Length of physical memory represented.
197b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
198b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Cpu Cache Coherency Options.
199b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool cc_test_;                      // Flag to decide whether to start the
200b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // cache coherency threads.
201b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int cc_cacheline_count_;            // Number of cache line size structures.
202b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int cc_inc_count_;                  // Number of times to increment the shared
203b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                      // cache lines structure members.
204b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
205b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Thread control.
206b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int file_threads_;                  // Threads of file IO.
207b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int net_threads_;                   // Threads of network IO.
208b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int listen_threads_;                // Threads for network IO to connect.
209b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int memory_threads_;                // Threads of memcpy.
210b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int invert_threads_;                // Threads of invert.
211b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int fill_threads_;                  // Threads of memset.
212b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int check_threads_;                 // Threads of strcmp.
213b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int cpu_stress_threads_;            // Threads of CPU stress workload.
214b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int disk_threads_;                  // Threads of disk test.
215b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int random_threads_;                // Number of random disk threads.
216b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int total_threads_;                 // Total threads used.
217b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  bool error_poll_;                   // Poll for system errors.
218b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
219b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Resources.
220b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  cc_cacheline_data *cc_cacheline_data_;  // The cache line sized datastructure
221b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                          // used by the ccache threads
222b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                          // (in worker.h).
223b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  vector<string> filename_;           // Filenames for file IO.
224b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  vector<string> ipaddrs_;            // Addresses for network IO.
225b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  vector<string> diskfilename_;       // Filename for disk IO device.
226b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Block table for IO device.
227b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  vector<DiskBlockTable*> blocktables_;
228b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
229b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int32 region_mask_;                 // Bitmask of available NUMA regions.
230b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int32 region_count_;                // Count of available NUMA regions.
231b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int32 region_[32];                  // Pagecount per region.
232b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int region_mode_;                   // What to do with NUMA hints?
233b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  static const int kLocalNuma = 1;    // Target local memory.
234b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  static const int kRemoteNuma = 2;   // Target remote memory.
235b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
236b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Results.
237b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int64 errorcount_;                  // Total hardware incidents seen.
238b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  int statuscount_;                   // Total test errors seen.
239b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
240b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Thread type constants and types
241b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  enum ThreadType {
242b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kMemoryType = 0,
243b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kFileIOType = 1,
244b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kNetIOType = 2,
245b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kNetSlaveType = 3,
246b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kCheckType = 4,
247b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kInvertType = 5,
248b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kDiskType = 6,
249b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kRandomDiskType = 7,
250b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kCPUType = 8,
251b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kErrorType = 9,
252b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson    kCCType = 10
253b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  };
254b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
255b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Helper functions.
256b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void AcquireWorkerLock();
257b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void ReleaseWorkerLock();
258b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  pthread_mutex_t worker_lock_;  // Lock access to the worker thread structure.
259b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  typedef vector<WorkerThread*> WorkerVector;
260b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  typedef map<int, WorkerVector*> WorkerMap;
261b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Contains all worker threads.
262b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  WorkerMap workers_map_;
263b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Delay between power spikes.
264b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  time_t pause_delay_;
265b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // The duration of each pause (for power spikes).
266b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  time_t pause_duration_;
267b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // For the workers we pause and resume to create power spikes.
268b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  WorkerStatus power_spike_status_;
269b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // For the workers we never pause.
270b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  WorkerStatus continuous_status_;
271b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
272b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  class OsLayer *os_;                   // Os abstraction: put hacks here.
273b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  class PatternList *patternlist_;      // Access to global data patterns.
274b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
275b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // RunAnalysis methods
276b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void AnalysisAllStats();              // Summary of all runs.
277b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void MemoryStats();
278b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void FileStats();
279b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void NetStats();
280b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void CheckStats();
281b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void InvertStats();
282b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void DiskStats();
283b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
284b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void QueueStats();
285b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
286b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Physical page use reporting.
287b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void AddrMapInit();
288b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void AddrMapUpdate(struct page_entry *pe);
289b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  void AddrMapPrint();
290b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
291b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // additional memory data from google-specific tests.
292b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void GoogleMemoryStats(float *memcopy_data,
293b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson                                 float *memcopy_bandwidth);
294b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
295b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  virtual void GoogleOsOptions(std::map<std::string, std::string> *options);
296b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
297b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // Page queues, only one of (valid_+empty_) or (finelock_q_) will be used
298b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // at a time. A commandline switch controls which queue implementation will
299b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  // be used.
300b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  class PageEntryQueue *valid_;        // Page queue structure, valid pages.
301b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  class PageEntryQueue *empty_;        // Page queue structure, free pages.
302b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  class FineLockPEQueue *finelock_q_;  // Page queue with fine-grain locks
303b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  Sat::PageQueueType pe_q_implementation_;   // Queue implementation switch
304b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
305b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson  DISALLOW_COPY_AND_ASSIGN(Sat);
306b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson};
307b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
308b0114cb9f332db144f65291211ae65f7f0e814e6Scott AndersonSat *SatFactory();
309b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson
310b0114cb9f332db144f65291211ae65f7f0e814e6Scott Anderson#endif  // STRESSAPPTEST_SAT_H_
311