diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-03-31 15:26:07 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-03-31 15:26:07 +0000 |
commit | 8fbe8a2f4c32e613e9ebcfd42f34f564a7d93c7a (patch) | |
tree | 48f6e86e10d6bf70ca1d0778d956498c5a707fb3 /performance-tests | |
parent | c6916096d95937bf2b0cfd61b6f9fd1d0288bb5c (diff) | |
download | ATCD-8fbe8a2f4c32e613e9ebcfd42f34f564a7d93c7a.tar.gz |
this test no longer worked; so, reverted to revision 4.5, plus minimum changes necessary to support build on platforms without threads
Diffstat (limited to 'performance-tests')
-rw-r--r-- | performance-tests/Misc/context_switch_time.cpp | 370 |
1 files changed, 205 insertions, 165 deletions
diff --git a/performance-tests/Misc/context_switch_time.cpp b/performance-tests/Misc/context_switch_time.cpp index 7f61f9b6100..bb21e7247bd 100644 --- a/performance-tests/Misc/context_switch_time.cpp +++ b/performance-tests/Misc/context_switch_time.cpp @@ -1,5 +1,5 @@ // $Id$ - +// // ============================================================================ // // = LIBRARY @@ -59,11 +59,10 @@ // // ============================================================================ -static const char usage [] = - "[-? |\n" - " [-c <repeat count, 0 means forever>]\n" - " [-n to spawn a new LWP with each thread]\n" - " [<iterations>]]"; +static const char usage [] = "[-? |\n" + " [-c <repeat count, 0 means forever>]\n" + " [-n to spawn a new LWP with each thread\n" + "[<iterations>]]"; #include "ace/Sched_Params.h" #include "ace/ACE.h" @@ -79,62 +78,78 @@ static const char usage [] = #define DEBUG 0 #endif /* DEBUG */ -// global test configuration parameters. -static u_long count = 1; -static u_long num_iterations = 1000; -static u_int new_lwp = 0; +#if defined (__sun) +/* Solaris priority values range from low to high with increasing priority */ +static const unsigned int LOW_PRIORITY = 1; +static const unsigned int HIGH_PRIORITY = 2; +#else +/* VxWorks and Win32 priority values range from high to low with + increasing priority */ +static const unsigned int LOW_PRIORITY = 2; +static const unsigned int HIGH_PRIORITY = 1; +#endif + + +// global test configuration parameters +static unsigned long count = 1; +static unsigned long num_iterations = 1000; +static unsigned int new_lwp = 0; +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// class Low_Priority_Null_Task +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + class Low_Priority_Null_Task : public ACE_Task<ACE_MT_SYNCH> { public: - Low_Priority_Null_Task (const int priority); - virtual ~Low_Priority_Null_Task (void); + Low_Priority_Null_Task (); + virtual ~Low_Priority_Null_Task (); - virtual int svc (void); + virtual int svc (); // called by other task: it returns when this task is ready to // continue - void ready (void) { initialized_.acquire (); } - - void done (void); + void ready () { initialized_.acquire (); } - ACE_hthread_t thread_id (void) const { return thread_id_; } + void done (); + ACE_hthread_t thread_id () const { return thread_id_; } private: ACE_hthread_t thread_id_; ACE_Semaphore initialized_; // blocks until thread_id_ is assigned ACE_Semaphore blocked_semaphore_; // force proper construction of independent instances - Low_Priority_Null_Task (void); Low_Priority_Null_Task (const Low_Priority_Null_Task &); Low_Priority_Null_Task &operator= (const Low_Priority_Null_Task &); }; inline -Low_Priority_Null_Task::Low_Priority_Null_Task (const int priority) - : ACE_Task<ACE_MT_SYNCH> (ACE_Service_Config::thr_mgr ()), - initialized_ (0), // initialize to locked, then unlock when ready - blocked_semaphore_ (0) +Low_Priority_Null_Task::Low_Priority_Null_Task() : + ACE_Task<ACE_MT_SYNCH> (ACE_Service_Config::thr_mgr ()), + initialized_ (0), // initialize to locked, then unlock when ready + blocked_semaphore_ (0) { #if DEBUG > 0 cout << "Low_Priority_Null_Task ctor" << endl; #endif /* DEBUG */ - this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, priority); + this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, LOW_PRIORITY); #if DEBUG > 0 cout << "Low_Priority_Null_Task ctor, activated" << endl; #endif /* DEBUG */ } -Low_Priority_Null_Task::~Low_Priority_Null_Task (void) +Low_Priority_Null_Task::~Low_Priority_Null_Task() { } int -Low_Priority_Null_Task::svc (void) +Low_Priority_Null_Task::svc () { #if DEBUG > 0 cout << "Low_Priority_Null_Task::svc (), entering" << ::flush; @@ -159,25 +174,29 @@ Low_Priority_Null_Task::svc (void) } void -Low_Priority_Null_Task::done (void) +Low_Priority_Null_Task::done () { blocked_semaphore_.release (); } +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// class Suspend_Resume_Test +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + class Suspend_Resume_Test : public ACE_Task<ACE_MT_SYNCH> { public: - Suspend_Resume_Test (const u_long iterations, - const int low_priority, - const int high_priority); - virtual ~Suspend_Resume_Test (void); + Suspend_Resume_Test (const unsigned long iterations); + virtual ~Suspend_Resume_Test (); - virtual int svc (void); + virtual int svc (); - ACE_hrtime_t elapsed_time (void) const { return elapsed_time_; } + ACE_hrtime_t elapsed_time () const { return elapsed_time_; } private: - const u_long iterations_; + const unsigned long iterations_; Low_Priority_Null_Task low_; @@ -186,30 +205,30 @@ private: ACE_hrtime_t elapsed_time_; // force proper construction of independent instances - Suspend_Resume_Test (void); + Suspend_Resume_Test (); Suspend_Resume_Test (const Suspend_Resume_Test &); Suspend_Resume_Test &operator= (const Suspend_Resume_Test &); }; -Suspend_Resume_Test::Suspend_Resume_Test (const u_long iterations, - const int low_priority, - const int high_priority) - : iterations_ (iterations), - low_ (low_priority) +Suspend_Resume_Test::Suspend_Resume_Test (const unsigned long iterations) : + ACE_Task<ACE_MT_SYNCH> (), + iterations_ (iterations), + low_ (), + timer_ () { #if DEBUG > 0 cout << "Suspend_Resume_Test ctor" << endl; #endif /* DEBUG */ - this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, high_priority); + this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, HIGH_PRIORITY); } -Suspend_Resume_Test::~Suspend_Resume_Test (void) +Suspend_Resume_Test::~Suspend_Resume_Test() { } int -Suspend_Resume_Test::svc (void) +Suspend_Resume_Test::svc () { #if DEBUG > 0 ACE_hthread_t thread_id; @@ -226,7 +245,7 @@ Suspend_Resume_Test::svc (void) timer_.start (); - for (u_long i = 0; i < iterations_; ++i) + for (unsigned long i = 0; i < iterations_; ++i) { #if DEBUG > 0 if (i % (iterations_ >= 10 ? iterations_ / 10 : 1) == 0) @@ -253,57 +272,63 @@ Suspend_Resume_Test::svc (void) } +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// class High_Priority_Simple_Task +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + class High_Priority_Simple_Task : public ACE_Task<ACE_MT_SYNCH> { public: - High_Priority_Simple_Task (const int priority); - virtual ~High_Priority_Simple_Task (void); + High_Priority_Simple_Task (); + virtual ~High_Priority_Simple_Task (); - virtual int svc (void); + virtual int svc (); // called by other task: it returns when this task is ready to // continue - void ready (void) { initialized_.acquire (); } + void ready () { initialized_.acquire (); } - void done (void); + void done (); - ACE_hthread_t thread_id (void) const { return thread_id_; } - u_long iterations (void) const { return iterations_; } + ACE_hthread_t thread_id () const { return thread_id_; } + unsigned long iterations () const { return iterations_; } private: ACE_hthread_t thread_id_; ACE_Semaphore initialized_; // block until thread_id_ is assigned int terminate_; - u_long iterations_; + unsigned long iterations_; // force proper construction of independent instances - High_Priority_Simple_Task (void); High_Priority_Simple_Task (const High_Priority_Simple_Task &); High_Priority_Simple_Task &operator= (const High_Priority_Simple_Task &); }; inline -High_Priority_Simple_Task::High_Priority_Simple_Task (const int priority) - : initialized_ (0), // initialize to locked, then unlock when ready - terminate_ (0), - iterations_ (0) +High_Priority_Simple_Task::High_Priority_Simple_Task() : + ACE_Task<ACE_MT_SYNCH> (ACE_Service_Config::thr_mgr ()), + initialized_ (0), // initialize to locked, then unlock when ready + terminate_ (0), + iterations_ (0) { #if DEBUG > 0 cout << "High_Priority_Simple_Task ctor" << endl; #endif /* DEBUG */ - this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, priority); + this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, HIGH_PRIORITY); #if DEBUG > 0 cout << "High_Priority_Simple_Task ctor, activated" << endl; #endif /* DEBUG */ } -High_Priority_Simple_Task::~High_Priority_Simple_Task (void) +High_Priority_Simple_Task::~High_Priority_Simple_Task() { } int -High_Priority_Simple_Task::svc (void) +High_Priority_Simple_Task::svc () { #if DEBUG > 0 cout << "High_Priority_Simple_Task::svc (), entering" << ::flush; @@ -341,26 +366,31 @@ High_Priority_Simple_Task::svc (void) return 0; } -inline void -High_Priority_Simple_Task::done (void) +inline +void +High_Priority_Simple_Task::done () { terminate_ = 1; } +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// class Ping_Suspend_Resume_Test +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + class Ping_Suspend_Resume_Test : public ACE_Task<ACE_MT_SYNCH> { public: - Ping_Suspend_Resume_Test (const u_long iterations, - const int low_priority, - const int high_priority); - virtual ~Ping_Suspend_Resume_Test (void); + Ping_Suspend_Resume_Test (const unsigned long iterations); + virtual ~Ping_Suspend_Resume_Test (); - virtual int svc (void); + virtual int svc (); - ACE_hrtime_t elapsed_time (void) const { return elapsed_time_; } + ACE_hrtime_t elapsed_time () const { return elapsed_time_; } private: - const u_long iterations_; + const unsigned long iterations_; High_Priority_Simple_Task high_; @@ -369,31 +399,31 @@ private: ACE_hrtime_t elapsed_time_; // force proper construction of independent instances - Ping_Suspend_Resume_Test (void); + Ping_Suspend_Resume_Test (); Ping_Suspend_Resume_Test (const Ping_Suspend_Resume_Test &); Ping_Suspend_Resume_Test &operator= (const Ping_Suspend_Resume_Test &); }; -Ping_Suspend_Resume_Test::Ping_Suspend_Resume_Test (const u_long iterations, - const int low_priority, - const int high_priority) - : iterations_ (iterations), - high_ (high_priority), - timer_ () +Ping_Suspend_Resume_Test::Ping_Suspend_Resume_Test (const unsigned long + iterations) : + ACE_Task<ACE_MT_SYNCH> (), + iterations_ (iterations), + high_ (), + timer_ () { #if DEBUG > 0 cout << "Ping_Suspend_Resume_Test ctor" << endl; #endif /* DEBUG */ - this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, low_priority); + this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, LOW_PRIORITY); } -Ping_Suspend_Resume_Test::~Ping_Suspend_Resume_Test (void) +Ping_Suspend_Resume_Test::~Ping_Suspend_Resume_Test() { } int -Ping_Suspend_Resume_Test::svc (void) +Ping_Suspend_Resume_Test::svc () { #if DEBUG > 0 cout << "Ping_Suspend_Resume_Test::svc (), entering" << ::flush; @@ -421,7 +451,7 @@ Ping_Suspend_Resume_Test::svc (void) timer_.start (); - for (u_long i = 0; i < iterations_; ++i) + for (unsigned long i = 0; i < iterations_; ++i) { #if DEBUG > 0 if (i % (iterations_ >= 10 ? iterations_ / 10 : 1) == 0) @@ -464,46 +494,52 @@ Ping_Suspend_Resume_Test::svc (void) } +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// class Yield_Test +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + class Yield_Test : public ACE_Task<ACE_MT_SYNCH> { public: - Yield_Test (const u_long iterations, - const int priority); - virtual ~Yield_Test (void); + Yield_Test (const unsigned long iterations); + virtual ~Yield_Test (); - virtual int svc (void); + virtual int svc (); - ACE_hrtime_t elapsed_time (void) const { return elapsed_time_; } + ACE_hrtime_t elapsed_time () const { return elapsed_time_; } private: - const u_long iterations_; + const unsigned long iterations_; ACE_High_Res_Timer timer_; ACE_hrtime_t elapsed_time_; // force proper construction of independent instances - Yield_Test (void); + Yield_Test (); Yield_Test (const Yield_Test &); Yield_Test &operator= (const Yield_Test &); }; -Yield_Test::Yield_Test (const u_long iterations, - const int priority) - : iterations_ (iterations) +Yield_Test::Yield_Test (const unsigned long iterations) : + ACE_Task<ACE_MT_SYNCH> (), + iterations_ (iterations), + timer_ () { #if DEBUG > 0 cout << "Yield_Test ctor" << endl; #endif /* DEBUG */ - this->activate (THR_BOUND | THR_DETACHED | new_lwp, 2, 0, priority); + this->activate (THR_BOUND | THR_DETACHED | new_lwp, 2, 0, LOW_PRIORITY); } -Yield_Test::~Yield_Test (void) +Yield_Test::~Yield_Test() { } int -Yield_Test::svc (void) +Yield_Test::svc () { #if DEBUG > 0 cout << "Yield_Test::svc (), entering" << ::flush; @@ -520,7 +556,7 @@ Yield_Test::svc (void) timer_.start (); - for (u_long i = 0; i < iterations_; ++i) + for (unsigned long i = 0; i < iterations_; ++i) { #if DEBUG > 0 if (i % (iterations_ >= 10 ? iterations_ / 10 : 1) == 0) @@ -542,72 +578,85 @@ Yield_Test::svc (void) return 0; } -static u_int -parse_args (int argc, char *argv []) + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// function get_options +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +static +unsigned int +get_options (int argc, char *argv []) { ACE_Get_Opt get_opt (argc, argv, "c:n?"); int opt; - - while ((opt = get_opt ()) != EOF) - { - switch (opt) - { - case 'c': - if (ACE_OS::atoi (get_opt.optarg) >= 0) - count = ACE_OS::atoi (get_opt.optarg); - else - { - cerr << argv [0] << ": count must be >= 0" << endl; - return 1; - } - break; - case 'n': - new_lwp = THR_NEW_LWP; - break; - case '?': - cout << "usage: " << argv [0] << " " << usage << endl; - ACE_OS::exit (0); - break; - default: - cerr << argv [0] << ": unknown arg, " << (char) opt << endl; - cerr << "usage: " << argv [0] << " " << usage << endl; - return 1; - } - } - - switch (argc - get_opt.optind) - { - case 0: - // use default number of iterations - break; - case 1: - if (ACE_OS::atoi (argv [get_opt.optind]) > 0) - num_iterations = ACE_OS::atoi (argv [get_opt.optind]); + while ((opt = get_opt ()) != EOF) { + switch (opt) { + case 'c': + if (ACE_OS::atoi (get_opt.optarg) >= 0) + { + count = ACE_OS::atoi (get_opt.optarg); + } else - { - cerr << argv [0] << ": iterations must be > 0" << endl; - return 1; - } + { + cerr << argv [0] << ": count must be >= 0" << endl; + return 1; + } + break; + case 'n': + new_lwp = THR_NEW_LWP; + break; + case '?': + cout << "usage: " << argv [0] << " " << usage << endl; + ACE_OS::exit (0); break; default: - cerr << argv [0] << ": too many arguments" << endl; + cerr << argv [0] << ": unknown arg, " << (char) opt << endl; cerr << "usage: " << argv [0] << " " << usage << endl; return 1; } + } + + switch (argc - get_opt.optind) { + case 0: + // use default number of iterations + break; + case 1: + if (ACE_OS::atoi (argv [get_opt.optind]) > 0) + { + num_iterations = ACE_OS::atoi (argv [get_opt.optind]); + } + else + { + cerr << argv [0] << ": iterations must be > 0" << endl; + return 1; + } + break; + default: + cerr << argv [0] << ": too many arguments" << endl; + cerr << "usage: " << argv [0] << " " << usage << endl; + return 1; + } return 0; } +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// function main +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// int main (int argc, char *argv []) { if (ACE_High_Res_Timer::supported () == 0) - ACE_OS::fprintf (stderr, "%s: high-resolution time is not supported " - "by ACE on this platform.\n", argv[0]); + { + ACE_OS::fprintf (stderr, "%s: high-resolution time is not supported " + "by ACE on this platform.\n", argv[0]); + } - if (parse_args (argc, argv)) - ACE_OS::exit (-1); + if (get_options (argc, argv)) ACE_OS::exit (-1); if (ACE_OS::sched_params ( ACE_Sched_Params ( @@ -616,8 +665,10 @@ main (int argc, char *argv []) ACE_SCOPE_PROCESS)) != 0) { if (ACE_OS::last_error () == EPERM) - ACE_OS::fprintf (stderr, "%s: user is not superuser, so remain in " - "time-sharing class\n", argv[0]); + { + ACE_OS::fprintf (stderr, "%s: user is not superuser, so remain in " + "time-sharing class\n", argv[0]); + } else { ACE_OS::perror (argv[0]); @@ -625,36 +676,22 @@ main (int argc, char *argv []) } } - static const int LOW_PRIORITY = ACE_Sched_Params::priority_min ( - ACE_SCHED_FIFO, - ACE_SCOPE_PROCESS); - static const int HIGH_PRIORITY = ACE_Sched_Params::next_priority ( - ACE_SCHED_FIFO, - LOW_PRIORITY, - ACE_SCOPE_PROCESS); - int forever = count == 0; - while (forever || count-- > 0) + while (forever || count-- > 0) { - // Run suspend/resume test first . . . - Suspend_Resume_Test suspend_resume_test (num_iterations, - LOW_PRIORITY, - HIGH_PRIORITY); - + // run suspend/resume test first . . . + Suspend_Resume_Test suspend_resume_test (num_iterations); // Wait for all tasks to exit. ACE_Service_Config::thr_mgr ()->wait (); - // Then Ping Suspend/Resume test. - Ping_Suspend_Resume_Test ping_suspend_resume_test (num_iterations, - LOW_PRIORITY, - HIGH_PRIORITY); - + // then Ping Suspend/Resume test + Ping_Suspend_Resume_Test ping_suspend_resume_test (num_iterations); // Wait for all tasks to exit. ACE_Service_Config::thr_mgr ()->wait (); if (ping_suspend_resume_test.elapsed_time () > - suspend_resume_test.elapsed_time ()) + suspend_resume_test.elapsed_time ()) { cout << "context switch time is (" << setw (9) @@ -680,9 +717,8 @@ main (int argc, char *argv []) << endl; } - // Then Yield test. - Yield_Test yield_test (num_iterations, LOW_PRIORITY); - + // then Yield test + Yield_Test yield_test (num_iterations); // Wait for all tasks to exit. ACE_Service_Config::thr_mgr ()->wait (); @@ -691,6 +727,7 @@ main (int argc, char *argv []) << " microseconds" << endl; } + return 0; } #else @@ -701,3 +738,6 @@ main (int, char *[]) return 0; } #endif /* ACE_HAS_THREADS */ + + +// EOF |