#include <stdlib.h>#include <stdio.h>#include <time.h>#include <assert.h>#include <iostream>#include <fstream>#include <sys/time.h>#include <sys/resource.h>#include "rwlock_tester.h"#include "MutexRWLock.h"#include "classic_rwlock.h"#include "SG_RWLock.h"#include "rwlock.h"#include "SimpleRWLock.h"#include "evg_rwlock.h"#include "evg_rwlock_1.h"#include "baseline_lock.h"Go to the source code of this file.
Defines | |
| #define | PREFIX "Linux_" |
Functions | |
| int | main (int argc, char *argv[]) |
Variables | |
| const int | gThreadsCount [] = { 1,2,4,8,12,16,20,24,32 } |
| const size_t | gThreadsCountLength = sizeof(gThreadsCount)/sizeof(int) |
| #define PREFIX "Linux_" |
| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
Definition at line 39 of file rwlock_test.cc.
References RWLockTester::add_lock_test(), GraphData::add_results(), atomic_add_return(), atomic_cmpexch_return(), atomic_dec(), atomic_dec_return(), atomic_inc(), atomic_inc_return(), RWLockTester::clear_summary(), RWLockTester::get_ostream(), gThreadsCount, gThreadsCountLength, GraphData::init(), kPerformanceLoopsNumber, PREFIX, GraphData::print_read(), GraphData::print_summary(), RWLockTester::print_summary(), GraphData::print_total_time(), GraphData::print_write(), RWLockLoopTest::run_mixed(), RWLockLoopTest::run_r(), RWLockTester::run_test(), RWLockLoopTest::run_w(), and RWLockTester::validate().
00040 { 00041 int a=0, b=1, c=2, d=3, e=4; 00042 00043 a = atomic_inc_return(&b); 00044 assert(a==2); 00045 assert(b==2); 00046 00047 d = atomic_cmpexch_return(&a, 10, 2); 00048 assert(d==2); 00049 assert(a==10); 00050 00051 d = atomic_cmpexch_return(&a, 11, 1); 00052 assert(d==10); 00053 assert(a==10); 00054 00055 b = atomic_dec_return(&a); 00056 assert(a==9); 00057 assert(b==9); 00058 00059 b = atomic_add_return(&a, 3); 00060 assert(a==12); 00061 assert(b==9); 00062 00063 atomic_dec(&e); 00064 assert(e==3); 00065 00066 atomic_inc(&d); 00067 assert(d==11); 00068 00069 RWLockTester tester; 00070 GraphData graph; 00071 00072 tester.add_lock_test(new RWLockLoopTestImpl<MutexRWLock>(tester.get_ostream())); 00073 tester.add_lock_test(new RWLockLoopTestImpl<ClassicRWLock>(tester.get_ostream())); 00074 #ifndef WIN32 00075 #ifdef PTHREAD_RWLOCK_INITIALIZER 00076 tester.add_lock_test(new RWLockLoopTestImpl<PThreadRWLock>(tester.get_ostream())); 00077 #endif 00078 #endif 00079 tester.add_lock_test(new RWLockLoopTestImpl<NonblockingRWLock>(tester.get_ostream())); 00080 tester.add_lock_test(new RWLockLoopTestImpl<SG_RWLock>(tester.get_ostream())); 00081 tester.add_lock_test(new RWLockLoopTestImpl<SimpleRWLock>(tester.get_ostream())); 00082 tester.add_lock_test(new RWLockLoopTestImpl<SharedCounterRWLock>(tester.get_ostream())); 00083 // tester.add_lock_test(new RWLockLoopTestImpl<SharedCounterRWLock2>(tester.get_ostream())); 00084 tester.validate(); 00085 // 00086 // Do not validate BASELINERWLock, it's an empty RW lock shell only used to estimate the test framework overhead 00087 // 00088 tester.add_lock_test(new RWLockLoopTestImpl<BASELINERWLock>(tester.get_ostream(), kPerformanceLoopsNumber, false)); // specify false to not verify the lock 00089 /* 00090 tester.add_lock_test(new RWLockLoopTestImpl<BASELINERWLock>(tester.get_ostream(), kPerformanceLoopsNumber, false)); // specify false to not verify the lock 00091 tester.add_lock_test(new RWLockLoopTestImpl<SharedCounterRWLock2>(tester.get_ostream())); 00092 tester.add_lock_test(new RWLockLoopTestImpl<SharedCounterRWLock>(tester.get_ostream())); 00093 tester.add_lock_test(new RWLockLoopTestImpl<SimpleRWLock>(tester.get_ostream())); 00094 tester.add_lock_test(new RWLockLoopTestImpl<NonblockingRWLock>(tester.get_ostream())); 00095 tester.add_lock_test(new RWLockLoopTestImpl<SG_RWLock>(tester.get_ostream())); 00096 #ifndef WIN32 00097 tester.add_lock_test(new RWLockLoopTestImpl<PThreadRWLock>(tester.get_ostream())); 00098 #endif 00099 tester.add_lock_test(new RWLockLoopTestImpl<ClassicRWLock>(tester.get_ostream())); 00100 */ 00101 // 00102 // Try to increase priority 00103 // 00104 #ifndef WIN32 00105 int setprres = setpriority(PRIO_PROCESS, 0, -20); 00106 if(setprres < 0) 00107 { 00108 cerr << "Set Priority Error: " << setprres << " errno:" << errno << std::endl; 00109 } 00110 #else 00111 if(!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) 00112 { 00113 LPVOID lpMsgBuf = (LPVOID)""; 00114 FormatMessage( 00115 FORMAT_MESSAGE_ALLOCATE_BUFFER | 00116 FORMAT_MESSAGE_FROM_SYSTEM | 00117 FORMAT_MESSAGE_IGNORE_INSERTS, 00118 NULL, 00119 GetLastError(), 00120 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 00121 (LPTSTR) &lpMsgBuf, 00122 0, 00123 NULL ); 00124 cerr << "Set Priority Error: " << (char *)lpMsgBuf << std::endl; 00125 } 00126 #endif 00127 00128 graph.init(tester, gThreadsCount, gThreadsCountLength); 00129 00130 tester.get_ostream() << (char*)"\nStarting Sequential Read test (thread(s) with read loop only...).\n"; 00131 00132 tester.clear_summary(); 00133 00134 // goto mixed_start; 00135 00136 for(int i=0; i<gThreadsCountLength; i++) 00137 { 00138 tester.run_test(gThreadsCount[i], kPerformanceLoopsNumber*2, &RWLockLoopTest::run_r); 00139 graph.add_results(tester, i); 00140 } 00141 tester.print_summary(); 00142 graph.print_read(PREFIX"read_only_read_thread_time.txt"); 00143 graph.print_total_time(PREFIX"read_only_total_time.txt"); 00144 00145 tester.get_ostream() << (char*)"\nStarting Sequential Write test (thread(s) with write loop only...).\n"; 00146 00147 tester.clear_summary(); 00148 00149 for(int i=0; i<gThreadsCountLength; i++) 00150 { 00151 tester.run_test(gThreadsCount[i], kPerformanceLoopsNumber*2, &RWLockLoopTest::run_w); 00152 graph.add_results(tester, i); 00153 } 00154 tester.print_summary(); 00155 graph.print_write(PREFIX"write_only_write_thread_time.txt"); 00156 graph.print_total_time(PREFIX"write_only_total_time.txt"); 00157 00158 tester.get_ostream() << (char*)"\nStarting Sequential Read/Write test (thread(s) with read/write loop executed along with thread(s) with write/read loop...).\n"; 00159 00160 tester.clear_summary(); 00161 00162 for(int i=0; i<gThreadsCountLength; i++) 00163 { 00164 tester.run_test(gThreadsCount[i], kPerformanceLoopsNumber); 00165 graph.add_results(tester, i); 00166 } 00167 tester.print_summary(); 00168 graph.print_read(PREFIX"read_thread_time.txt"); 00169 graph.print_write(PREFIX"write_thread_time.txt"); 00170 graph.print_summary(PREFIX"summary_thread_time.txt"); 00171 graph.print_total_time(PREFIX"total_time.txt"); 00172 00173 mixed_start: 00174 00175 tester.get_ostream() << (char*)"\nStarting Mixed Read/Write test (each thread executes alternating read and write locks...).\n"; 00176 00177 tester.clear_summary(); 00178 for(int i=0; i<gThreadsCountLength; i++) 00179 { 00180 tester.run_test(gThreadsCount[i], kPerformanceLoopsNumber*2, &RWLockLoopTest::run_mixed); 00181 graph.add_results(tester, i); 00182 } 00183 tester.print_summary(); 00184 graph.print_summary(PREFIX"mixed_results.txt"); 00185 graph.print_total_time(PREFIX"mixed_total_time.txt"); 00186 }
| const int gThreadsCount[] = { 1,2,4,8,12,16,20,24,32 } |
| const size_t gThreadsCountLength = sizeof(gThreadsCount)/sizeof(int) |
1.5.5