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/Auto_Ptr.h"
22 #include "ace/High_Res_Timer.h"
23 #include "ace/Sample_History.h"
24 #include "ace/Basic_Stats.h"
25 #include "ace/Stats.h"
26 #include "ace/Sched_Params.h"
27 #include "ace/Barrier.h"
31 const ACE_TCHAR
*ior
= ACE_TEXT ("file://test.ior");
33 int high_priority_period
= 0;
34 int high_priority_workload
= 0;
35 int low_priority_period
= 0;
36 int low_priority_workload
= 0;
37 int disable_low_priority
= 0;
40 class Roundtrip_Peer
: public Peer_Base
43 Roundtrip_Peer (CORBA::ORB_ptr orb
,
44 RTServer_Setup
&rtserver_setup
,
46 : Peer_Base (orb
, rtserver_setup
)
47 , rt_class_ (&rt_class
)
52 /** @name The Federated_Test::Peer methods
54 virtual Federated_Test::Experiment_Results
*
55 run_experiment (CORBA::Long experiment_id
,
56 CORBA::Long iterations
);
64 parse_args (int argc
, ACE_TCHAR
*argv
[])
66 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:n:l:h:w:v:zr"));
69 while ((c
= get_opts ()) != -1)
73 ior
= get_opts
.opt_arg ();
77 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
81 high_priority_period
= ACE_OS::atoi (get_opts
.opt_arg ());
85 low_priority_period
= ACE_OS::atoi (get_opts
.opt_arg ());
89 high_priority_workload
= ACE_OS::atoi (get_opts
.opt_arg ());
93 low_priority_workload
= ACE_OS::atoi (get_opts
.opt_arg ());
97 disable_low_priority
= 1;
106 ACE_ERROR_RETURN ((LM_ERROR
,
109 "-i iterations (iterations) "
110 "-h high_priority_period (usecs) "
111 "-l low_priority_period (usecs) "
112 "-w high_priority_workload (usecs) "
113 "-v low_priority_workload (usecs) "
114 "-r (enable RT-CORBA) "
115 "-n nthreads (low priority thread) "
116 "-z (disable low priority) "
121 // Indicates successful parsing of the command line
125 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
127 TAO_EC_Default_Factory::init_svcs();
132 ORB_Holder
orb (argc
, argv
, "");
134 if (parse_args (argc
, argv
) != 0)
137 RTServer_Setup
rtserver_setup (use_rt_corba
,
142 PortableServer::POA_var root_poa
=
143 RIR_Narrow
<PortableServer::POA
>::resolve (orb
,
146 PortableServer::POAManager_var poa_manager
=
147 root_poa
->the_POAManager ();
149 poa_manager
->activate ();
151 ACE_DEBUG ((LM_DEBUG
, "Finished ORB and POA configuration\n"));
153 Servant_var
<Roundtrip_Peer
> peer_impl (
154 new Roundtrip_Peer (orb
,
159 Federated_Test::Peer_var peer
=
162 ACE_DEBUG ((LM_DEBUG
, "Finished peer configuration and activation\n"));
164 CORBA::Object_var object
=
165 orb
->string_to_object (ior
);
167 Federated_Test::Control_var control
=
168 Federated_Test::Control::_narrow (object
.in ());
170 control
->join (peer
.in ());
174 catch (const CORBA::Exception
& ex
)
176 ex
._tao_print_exception ("Exception caught:");
183 Federated_Test::Experiment_Results
*
184 Roundtrip_Peer::run_experiment (CORBA::Long experiment_id
,
185 CORBA::Long iterations
)
187 int thread_count
= 1;
189 if (disable_low_priority
== 0)
190 thread_count
+= nthreads
;
193 ACE_Barrier
the_barrier (thread_count
);
195 ACE_DEBUG ((LM_DEBUG
, "Calibrating high res timer ...."));
196 ACE_High_Res_Timer::calibrate ();
198 ACE_High_Res_Timer::global_scale_factor_type gsf
=
199 ACE_High_Res_Timer::global_scale_factor ();
200 ACE_DEBUG ((LM_DEBUG
, "Done (%d)\n", gsf
));
203 Low_Priority_Setup
<Client_Pair
> low_priority_setup (
205 0, // no limit on the number of iterations
206 1, // each client gets its own type
208 ACE_ES_EVENT_UNDEFINED
+ 2,
209 low_priority_workload
,
211 disable_low_priority
? 0 : 1,
212 this->rt_class_
.priority_low (),
213 this->rt_class_
.thr_sched_class (),
217 this->event_channel_
.in (),
221 Client_Pair high_priority_group
;
222 high_priority_group
.init (experiment_id
,
223 ACE_ES_EVENT_UNDEFINED
,
225 high_priority_workload
,
229 high_priority_group
.connect (this->event_channel_
.in ());
230 Auto_Disconnect
<Client_Pair
> high_priority_disconnect (&high_priority_group
);
232 Send_Task high_priority_task
;
233 high_priority_task
.init (iterations
,
234 high_priority_period
,
236 ACE_ES_EVENT_UNDEFINED
,
238 high_priority_group
.supplier (),
241 // Artificial scope to wait for the high priority task...
242 Task_Activator
<Send_Task
> high_priority_act (this->rt_class_
->priority_high (),
243 this->rt_class_
->thr_sched_class (),
245 &high_priority_task
);
248 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - high priority task completed\n"));
251 if (disable_low_priority
== 0)
253 low_priority_setup
.stop_all_threads ();
256 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) client - low priority task(s) stopped\n"));
259 ACE_Sample_History
&history
=
260 high_priority_group
.consumer ()->sample_history ();
262 Federated_Test::Experiment_Results_var
results (
263 new Federated_Test::Experiment_Results (iterations
)
265 results
->length (iterations
);
266 for (CORBA::ULong i
= 0; i
!= results
->length (); ++i
)
268 results
[i
] = history
.get_sample (i
) / gsf
;
271 return results
._retn ();