2 #include "ORB_Holder.h"
3 #include "Servant_var.h"
4 #include "RIR_Narrow.h"
5 #include "RTServer_Setup.h"
7 #include "Auto_Disconnect.h"
9 #include "Task_Activator.h"
10 #include "Client_Pair.h"
12 #include "orbsvcs/Event_Service_Constants.h"
13 #include "orbsvcs/Event/EC_Default_Factory.h"
15 #include "tao/Messaging/Messaging.h"
16 #include "tao/Strategies/advanced_resource.h"
17 #include "tao/RTCORBA/Priority_Mapping_Manager.h"
18 #include "tao/RTCORBA/Continuous_Priority_Mapping.h"
19 #include "tao/RTPortableServer/RTPortableServer.h"
20 #include "ace/Get_Opt.h"
21 #include "ace/High_Res_Timer.h"
22 #include "ace/Sample_History.h"
23 #include "ace/Basic_Stats.h"
24 #include "ace/Stats.h"
25 #include "ace/Sched_Params.h"
26 #include "ace/Barrier.h"
29 const ACE_TCHAR
*ior
= ACE_TEXT ("file://test.ior");
31 int high_priority_period
= 0;
32 int high_priority_workload
= 0;
33 int low_priority_period
= 0;
34 int low_priority_workload
= 0;
35 int disable_low_priority
= 0;
38 class Roundtrip_Peer
: public Peer_Base
41 Roundtrip_Peer (CORBA::ORB_ptr orb
,
42 RTServer_Setup
&rtserver_setup
,
44 : Peer_Base (orb
, rtserver_setup
)
45 , rt_class_ (&rt_class
)
50 /** @name The Federated_Test::Peer methods
52 virtual Federated_Test::Experiment_Results
*
53 run_experiment (CORBA::Long experiment_id
,
54 CORBA::Long iterations
);
62 parse_args (int argc
, ACE_TCHAR
*argv
[])
64 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:n:l:h:w:v:zr"));
67 while ((c
= get_opts ()) != -1)
71 ior
= get_opts
.opt_arg ();
75 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
79 high_priority_period
= ACE_OS::atoi (get_opts
.opt_arg ());
83 low_priority_period
= ACE_OS::atoi (get_opts
.opt_arg ());
87 high_priority_workload
= ACE_OS::atoi (get_opts
.opt_arg ());
91 low_priority_workload
= ACE_OS::atoi (get_opts
.opt_arg ());
95 disable_low_priority
= 1;
104 ACE_ERROR_RETURN ((LM_ERROR
,
107 "-i iterations (iterations) "
108 "-h high_priority_period (usecs) "
109 "-l low_priority_period (usecs) "
110 "-w high_priority_workload (usecs) "
111 "-v low_priority_workload (usecs) "
112 "-r (enable RT-CORBA) "
113 "-n nthreads (low priority thread) "
114 "-z (disable low priority) "
119 // Indicates successful parsing of the command line
123 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
125 TAO_EC_Default_Factory::init_svcs();
130 ORB_Holder
orb (argc
, argv
, "");
132 if (parse_args (argc
, argv
) != 0)
135 RTServer_Setup
rtserver_setup (use_rt_corba
,
140 PortableServer::POA_var root_poa
=
141 RIR_Narrow
<PortableServer::POA
>::resolve (orb
,
144 PortableServer::POAManager_var poa_manager
=
145 root_poa
->the_POAManager ();
147 poa_manager
->activate ();
149 ACE_DEBUG ((LM_DEBUG
, "Finished ORB and POA configuration\n"));
151 Servant_var
<Roundtrip_Peer
> peer_impl (
152 new Roundtrip_Peer (orb
,
157 Federated_Test::Peer_var peer
=
160 ACE_DEBUG ((LM_DEBUG
, "Finished peer configuration and activation\n"));
162 CORBA::Object_var object
=
163 orb
->string_to_object (ior
);
165 Federated_Test::Control_var control
=
166 Federated_Test::Control::_narrow (object
.in ());
168 control
->join (peer
.in ());
172 catch (const CORBA::Exception
& ex
)
174 ex
._tao_print_exception ("Exception caught:");
181 Federated_Test::Experiment_Results
*
182 Roundtrip_Peer::run_experiment (CORBA::Long experiment_id
,
183 CORBA::Long iterations
)
185 int thread_count
= 1;
187 if (disable_low_priority
== 0)
188 thread_count
+= nthreads
;
191 ACE_Barrier
the_barrier (thread_count
);
193 ACE_DEBUG ((LM_DEBUG
, "Calibrating high res timer ...."));
194 ACE_High_Res_Timer::calibrate ();
196 ACE_High_Res_Timer::global_scale_factor_type gsf
=
197 ACE_High_Res_Timer::global_scale_factor ();
198 ACE_DEBUG ((LM_DEBUG
, "Done (%d)\n", gsf
));
201 Low_Priority_Setup
<Client_Pair
> low_priority_setup (
203 0, // no limit on the number of iterations
204 1, // each client gets its own type
206 ACE_ES_EVENT_UNDEFINED
+ 2,
207 low_priority_workload
,
209 disable_low_priority
? 0 : 1,
210 this->rt_class_
.priority_low (),
211 this->rt_class_
.thr_sched_class (),
215 this->event_channel_
.in (),
219 Client_Pair high_priority_group
;
220 high_priority_group
.init (experiment_id
,
221 ACE_ES_EVENT_UNDEFINED
,
223 high_priority_workload
,
227 high_priority_group
.connect (this->event_channel_
.in ());
228 Auto_Disconnect
<Client_Pair
> high_priority_disconnect (&high_priority_group
);
230 Send_Task high_priority_task
;
231 high_priority_task
.init (iterations
,
232 high_priority_period
,
234 ACE_ES_EVENT_UNDEFINED
,
236 high_priority_group
.supplier (),
239 // Artificial scope to wait for the high priority task...
240 Task_Activator
<Send_Task
> high_priority_act (this->rt_class_
->priority_high (),
241 this->rt_class_
->thr_sched_class (),
243 &high_priority_task
);
246 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - high priority task completed\n"));
249 if (disable_low_priority
== 0)
251 low_priority_setup
.stop_all_threads ();
254 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - low priority task(s) stopped\n"));
257 ACE_Sample_History
&history
=
258 high_priority_group
.consumer ()->sample_history ();
260 Federated_Test::Experiment_Results_var
results (
261 new Federated_Test::Experiment_Results (iterations
)
263 results
->length (iterations
);
264 for (CORBA::ULong i
= 0; i
!= results
->length (); ++i
)
266 results
[i
] = history
.get_sample (i
) / gsf
;
269 return results
._retn ();