@@ -126,14 +126,18 @@ int main(int argc, char** argv)
126126
127127 master_vm.remote_connect (storage_vm, false );
128128
129- static uint64_t callback_address = 0x0 ;
129+ static std::map<std::string, uint64_t > callback_address;
130130 master_vm.install_unhandled_syscall_handler (
131131 [] (tinykvm::vCPU& cpu, unsigned sysnum) {
132132 auto & regs = cpu.registers ();
133133 switch (sysnum) {
134- case 0x10001 : // Set callback address
135- callback_address = regs.rdi ;
136- return ;
134+ case 0x10001 : { // Set callback address
135+ auto view = cpu.machine ().string_or_view (regs.rsi , regs.rdx );
136+ const std::string name = view.to_string ();
137+ callback_address[name] = regs.rdi ;
138+ printf (" Set callback '%s' to 0x%llX\n " , name.c_str (), regs.rdi );
139+ return ;
140+ }
137141 default :
138142 printf (" Unhandled master VM syscall: %u\n " , sysnum);
139143 regs.rax = -ENOSYS;
@@ -167,15 +171,29 @@ int main(int argc, char** argv)
167171 assert (vm.is_remote_connected ());
168172
169173 /* Call 'do_calculation' with 21 as argument */
170- if (callback_address == 0 ) {
174+ auto do_it = callback_address.find (" do_nothing" );
175+ if (do_it == callback_address.end ()) {
176+ fprintf (stderr, " Error: no do_nothing() in guest\n " );
177+ exit (1 );
178+ }
179+ auto calc_it = callback_address.find (" do_calculation" );
180+ if (calc_it == callback_address.end ()) {
171181 fprintf (stderr, " Error: no do_calculation() in guest\n " );
172182 exit (1 );
173183 }
174- printf (" Calling do_calculation() @ 0x%lX\n " , callback_address);
175- for (int i = 0 ; i < 100 ; i++)
176- vm.timed_vmcall (callback_address, 5 .0f , 21 );
184+ auto call_overhead = timed_action ([&] {
185+ for (int i = 0 ; i < 100 ; i++)
186+ vm.timed_vmcall (do_it->second , 5 .0f , 21 );
187+ }) / 100.0 ;
188+ printf (" Call overhead: %.2fus\n " , call_overhead * 1e6 );
189+
190+ printf (" Calling do_calculation() @ 0x%lX\n " , calc_it->second );
191+ for (int i = 0 ; i < 10 ; i++)
192+ vm.timed_vmcall (calc_it->second , 5 .0f , 21 );
177193 auto fork_tdiff = timed_action ([&] {
178- vm.timed_vmcall (callback_address, 5 .0f , 21 );
179- });
180- printf (" Fork call time: %.2fus Return value: %ld\n " , fork_tdiff*1e6 , vm.return_value ());
194+ for (int i = 0 ; i < 100 ; i++)
195+ vm.timed_vmcall (calc_it->second , 5 .0f , 21 );
196+ }) / 100.0 ;
197+ fork_tdiff -= call_overhead;
198+ printf (" Remote call time: %.2fus Return value: %ld\n " , fork_tdiff * 1e6 , vm.return_value ());
181199}
0 commit comments