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 // sat.h : sat stress test object interface and data structures
17 #ifndef STRESSAPPTEST_SAT_H_
18 #define STRESSAPPTEST_SAT_H_
26 // This file must work with autoconf on its public version,
27 // so these includes are correct.
28 #include "finelock_queue.h"
34 // SAT stress test class.
37 // Enum for page queue implementation switch.
38 enum PageQueueType { SAT_ONELOCK, SAT_FINELOCK };
43 // Read configuration from arguments. Called first.
44 bool ParseArgs(int argc, char **argv);
45 virtual bool CheckGoogleSpecificArgs(int argc, char **argv, int *i);
46 // Initialize data structures, subclasses, and resources,
47 // based on command line args.
48 // Called after ParseArgs().
51 // Execute the test. Initialize() and ParseArgs() must be called first.
52 // This must be called from a single-threaded program.
55 // Pretty print result summary.
56 // Called after Run().
57 // Return value is success or failure of the SAT run, *not* of this function!
60 // Pretty print version info.
64 virtual void PrintHelp();
66 // Clean up allocations and resources.
70 // Abort Run(). Only for use by Run()-installed signal handlers.
71 void Break() { user_break_ = true; }
73 // Fetch and return empty and full pages into the empty and full pools.
74 bool GetValid(struct page_entry *pe);
75 bool PutValid(struct page_entry *pe);
76 bool GetEmpty(struct page_entry *pe);
77 bool PutEmpty(struct page_entry *pe);
79 bool GetValid(struct page_entry *pe, int32 tag);
80 bool GetEmpty(struct page_entry *pe, int32 tag);
82 // Accessor functions.
83 int verbosity() const { return verbosity_; }
84 int logfile() const { return logfile_; }
85 int page_length() const { return page_length_; }
86 int disk_pages() const { return disk_pages_; }
87 int strict() const { return strict_; }
88 int tag_mode() const { return tag_mode_; }
89 int status() const { return statuscount_; }
90 void bad_status() { statuscount_++; }
91 int errors() const { return errorcount_; }
92 int warm() const { return warm_; }
93 bool stop_on_error() const { return stop_on_error_; }
94 int32 region_mask() const { return region_mask_; }
95 // Semi-accessor to find the "nth" region to avoid replicated bit searching..
96 int32 region_find(int32 num) const {
97 for (int i = 0; i < 32; i++) {
98 if ((1 << i) & region_mask_) {
107 // Causes false errors for unittesting.
108 // Setting to "true" causes errors to be injected.
109 void set_error_injection(bool errors) { error_injection_ = errors; }
110 bool error_injection() const { return error_injection_; }
113 // Opens log file for writing. Returns 0 on failure.
114 bool InitializeLogfile();
115 // Checks for supported environment. Returns 0 on failure.
116 bool CheckEnvironment();
117 // Allocates size_ bytes of test memory.
118 bool AllocateMemory();
119 // Initializes datapattern reference structures.
120 bool InitializePatterns();
121 // Initializes test memory with datapatterns.
122 bool InitializePages();
124 // Start up worker threads.
125 virtual void InitializeThreads();
126 // Spawn worker threads.
128 // Reap worker threads.
130 // Run bandwidth and error analysis.
131 virtual void RunAnalysis();
132 // Delete worker threads.
133 void DeleteThreads();
135 // Return the number of cpus in the system.
138 // Collect error counts from threads.
139 int64 GetTotalErrorCount();
141 // Command line arguments.
144 // Memory and test configuration.
145 int runtime_seconds_; // Seconds to run.
146 int page_length_; // Length of each memory block.
147 int64 pages_; // Number of memory blocks.
148 int64 size_; // Size of memory tested, in bytes.
149 int64 size_mb_; // Size of memory tested, in MB.
150 int64 min_hugepages_mbytes_; // Minimum hugepages size.
151 int64 freepages_; // How many invalid pages we need.
152 int disk_pages_; // Number of pages per temp file.
153 uint64 paddr_base_; // Physical address base.
154 vector< vector<string> > modules_; // Memory module names per channel.
155 int interleave_size_; // Channel interleaving chunk size in bytes.
156 // Usually cacheline sized.
157 int channel_width_; // Channel width in bits.
160 volatile sig_atomic_t user_break_; // User has signalled early exit. Used as
162 int verbosity_; // How much to print.
163 int strict_; // Check results per transaction.
164 int warm_; // FPU warms CPU while coying.
165 int address_mode_; // 32 or 64 bit binary.
166 bool stop_on_error_; // Exit immendiately on any error.
167 bool findfiles_; // Autodetect tempfile locations.
169 bool error_injection_; // Simulate errors, for unittests.
170 bool crazy_error_injection_; // Simulate lots of errors.
171 uint64 max_errorcount_; // Number of errors before forced exit.
172 int run_on_anything_; // Ignore unknown machine ereor.
173 int use_logfile_; // Log to a file.
174 char logfilename_[255]; // Name of file to log to.
175 int logfile_; // File handle to log to.
177 // Disk thread options.
178 int read_block_size_; // Size of block to read from disk.
179 int write_block_size_; // Size of block to write to disk.
180 int64 segment_size_; // Size of segment to split disk into.
181 int cache_size_; // Size of disk cache.
182 int blocks_per_segment_; // Number of blocks to test per segment.
183 int read_threshold_; // Maximum time (in us) a read should take
184 // before warning of a slow read.
185 int write_threshold_; // Maximum time (in us) a write should
186 // take before warning of a slow write.
187 int non_destructive_; // Whether to use non-destructive mode for
191 int monitor_mode_; // Switch for monitor-only mode SAT.
192 // This switch trumps most of the other
193 // argument, as SAT will only run error
195 int tag_mode_; // Do tagging of memory and strict
196 // checking for misplaced cachelines.
198 bool do_page_map_; // Should we print a list of used pages?
199 unsigned char *page_bitmap_; // Store bitmap of physical pages seen.
200 uint64 page_bitmap_size_; // Length of physical memory represented.
202 // Cpu Cache Coherency Options.
203 bool cc_test_; // Flag to decide whether to start the
204 // cache coherency threads.
205 int cc_cacheline_count_; // Number of cache line size structures.
206 int cc_inc_count_; // Number of times to increment the shared
207 // cache lines structure members.
210 int file_threads_; // Threads of file IO.
211 int net_threads_; // Threads of network IO.
212 int listen_threads_; // Threads for network IO to connect.
213 int memory_threads_; // Threads of memcpy.
214 int invert_threads_; // Threads of invert.
215 int fill_threads_; // Threads of memset.
216 int check_threads_; // Threads of strcmp.
217 int cpu_stress_threads_; // Threads of CPU stress workload.
218 int disk_threads_; // Threads of disk test.
219 int random_threads_; // Number of random disk threads.
220 int total_threads_; // Total threads used.
221 bool error_poll_; // Poll for system errors.
224 cc_cacheline_data *cc_cacheline_data_; // The cache line sized datastructure
225 // used by the ccache threads
227 vector<string> filename_; // Filenames for file IO.
228 vector<string> ipaddrs_; // Addresses for network IO.
229 vector<string> diskfilename_; // Filename for disk IO device.
230 // Block table for IO device.
231 vector<DiskBlockTable*> blocktables_;
233 int32 region_mask_; // Bitmask of available NUMA regions.
234 int32 region_count_; // Count of available NUMA regions.
235 int32 region_[32]; // Pagecount per region.
236 int region_mode_; // What to do with NUMA hints?
237 static const int kLocalNuma = 1; // Target local memory.
238 static const int kRemoteNuma = 2; // Target remote memory.
241 int64 errorcount_; // Total hardware incidents seen.
242 int statuscount_; // Total test errors seen.
244 // Thread type constants and types
260 virtual void AcquireWorkerLock();
261 virtual void ReleaseWorkerLock();
262 pthread_mutex_t worker_lock_; // Lock access to the worker thread structure.
263 typedef vector<WorkerThread*> WorkerVector;
264 typedef map<int, WorkerVector*> WorkerMap;
265 // Contains all worker threads.
266 WorkerMap workers_map_;
267 // Delay between power spikes.
269 // The duration of each pause (for power spikes).
270 time_t pause_duration_;
271 // For the workers we pause and resume to create power spikes.
272 WorkerStatus power_spike_status_;
273 // For the workers we never pause.
274 WorkerStatus continuous_status_;
276 class OsLayer *os_; // Os abstraction: put hacks here.
277 class PatternList *patternlist_; // Access to global data patterns.
279 // RunAnalysis methods
280 void AnalysisAllStats(); // Summary of all runs.
290 // Physical page use reporting.
292 void AddrMapUpdate(struct page_entry *pe);
295 // additional memory data from google-specific tests.
296 virtual void GoogleMemoryStats(float *memcopy_data,
297 float *memcopy_bandwidth);
299 virtual void GoogleOsOptions(std::map<std::string, std::string> *options);
301 // Page queues, only one of (valid_+empty_) or (finelock_q_) will be used
302 // at a time. A commandline switch controls which queue implementation will
304 class PageEntryQueue *valid_; // Page queue structure, valid pages.
305 class PageEntryQueue *empty_; // Page queue structure, free pages.
306 class FineLockPEQueue *finelock_q_; // Page queue with fine-grain locks
307 Sat::PageQueueType pe_q_implementation_; // Queue implementation switch
309 DISALLOW_COPY_AND_ASSIGN(Sat);
314 #endif // STRESSAPPTEST_SAT_H_