@@ -249,7 +249,7 @@ static int setup_demand_paging(struct kvm_vm *vm,
249249}
250250
251251static void run_test (enum vm_guest_mode mode , bool use_uffd ,
252- useconds_t uffd_delay , int vcpus )
252+ useconds_t uffd_delay )
253253{
254254 pthread_t * vcpu_threads ;
255255 pthread_t * uffd_handler_threads = NULL ;
@@ -261,7 +261,7 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
261261 int vcpu_id ;
262262 int r ;
263263
264- vm = create_vm (mode , vcpus , guest_percpu_mem_size );
264+ vm = create_vm (mode , nr_vcpus , guest_percpu_mem_size );
265265
266266 perf_test_args .wr_fract = 1 ;
267267
@@ -270,23 +270,23 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
270270 "Failed to allocate buffer for guest data pattern" );
271271 memset (guest_data_prototype , 0xAB , perf_test_args .host_page_size );
272272
273- vcpu_threads = malloc (vcpus * sizeof (* vcpu_threads ));
273+ vcpu_threads = malloc (nr_vcpus * sizeof (* vcpu_threads ));
274274 TEST_ASSERT (vcpu_threads , "Memory allocation failed" );
275275
276- add_vcpus (vm , vcpus , guest_percpu_mem_size );
276+ add_vcpus (vm , nr_vcpus , guest_percpu_mem_size );
277277
278278 if (use_uffd ) {
279279 uffd_handler_threads =
280- malloc (vcpus * sizeof (* uffd_handler_threads ));
280+ malloc (nr_vcpus * sizeof (* uffd_handler_threads ));
281281 TEST_ASSERT (uffd_handler_threads , "Memory allocation failed" );
282282
283- uffd_args = malloc (vcpus * sizeof (* uffd_args ));
283+ uffd_args = malloc (nr_vcpus * sizeof (* uffd_args ));
284284 TEST_ASSERT (uffd_args , "Memory allocation failed" );
285285
286- pipefds = malloc (sizeof (int ) * vcpus * 2 );
286+ pipefds = malloc (sizeof (int ) * nr_vcpus * 2 );
287287 TEST_ASSERT (pipefds , "Unable to allocate memory for pipefd" );
288288
289- for (vcpu_id = 0 ; vcpu_id < vcpus ; vcpu_id ++ ) {
289+ for (vcpu_id = 0 ; vcpu_id < nr_vcpus ; vcpu_id ++ ) {
290290 vm_paddr_t vcpu_gpa ;
291291 void * vcpu_hva ;
292292
@@ -322,15 +322,15 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
322322
323323 clock_gettime (CLOCK_MONOTONIC , & start );
324324
325- for (vcpu_id = 0 ; vcpu_id < vcpus ; vcpu_id ++ ) {
325+ for (vcpu_id = 0 ; vcpu_id < nr_vcpus ; vcpu_id ++ ) {
326326 pthread_create (& vcpu_threads [vcpu_id ], NULL , vcpu_worker ,
327327 & perf_test_args .vcpu_args [vcpu_id ]);
328328 }
329329
330330 pr_info ("Started all vCPUs\n" );
331331
332332 /* Wait for the vcpu threads to quit */
333- for (vcpu_id = 0 ; vcpu_id < vcpus ; vcpu_id ++ ) {
333+ for (vcpu_id = 0 ; vcpu_id < nr_vcpus ; vcpu_id ++ ) {
334334 pthread_join (vcpu_threads [vcpu_id ], NULL );
335335 PER_VCPU_DEBUG ("Joined thread for vCPU %d\n" , vcpu_id );
336336 }
@@ -343,7 +343,7 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
343343 char c ;
344344
345345 /* Tell the user fault fd handler threads to quit */
346- for (vcpu_id = 0 ; vcpu_id < vcpus ; vcpu_id ++ ) {
346+ for (vcpu_id = 0 ; vcpu_id < nr_vcpus ; vcpu_id ++ ) {
347347 r = write (pipefds [vcpu_id * 2 + 1 ], & c , 1 );
348348 TEST_ASSERT (r == 1 , "Unable to write to pipefd" );
349349
@@ -354,7 +354,7 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
354354 pr_info ("Total guest execution time: %ld.%.9lds\n" ,
355355 ts_diff .tv_sec , ts_diff .tv_nsec );
356356 pr_info ("Overall demand paging rate: %f pgs/sec\n" ,
357- perf_test_args .vcpu_args [0 ].pages * vcpus /
357+ perf_test_args .vcpu_args [0 ].pages * nr_vcpus /
358358 ((double )ts_diff .tv_sec + (double )ts_diff .tv_nsec / 100000000.0 ));
359359
360360 ucall_uninit (vm );
@@ -409,8 +409,8 @@ static void help(char *name)
409409
410410int main (int argc , char * argv [])
411411{
412+ int max_vcpus = kvm_check_cap (KVM_CAP_MAX_VCPUS );
412413 bool mode_selected = false;
413- int vcpus = 1 ;
414414 unsigned int mode ;
415415 int opt , i ;
416416 bool use_uffd = false;
@@ -462,12 +462,9 @@ int main(int argc, char *argv[])
462462 guest_percpu_mem_size = parse_size (optarg );
463463 break ;
464464 case 'v' :
465- vcpus = atoi (optarg );
466- TEST_ASSERT (vcpus > 0 ,
467- "Must have a positive number of vCPUs" );
468- TEST_ASSERT (vcpus <= MAX_VCPUS ,
469- "This test does not currently support\n"
470- "more than %d vCPUs." , MAX_VCPUS );
465+ nr_vcpus = atoi (optarg );
466+ TEST_ASSERT (nr_vcpus > 0 && nr_vcpus <= max_vcpus ,
467+ "Invalid number of vcpus, must be between 1 and %d" , max_vcpus );
471468 break ;
472469 case 'h' :
473470 default :
@@ -482,7 +479,7 @@ int main(int argc, char *argv[])
482479 TEST_ASSERT (guest_modes [i ].supported ,
483480 "Guest mode ID %d (%s) not supported." ,
484481 i , vm_guest_mode_string (i ));
485- run_test (i , use_uffd , uffd_delay , vcpus );
482+ run_test (i , use_uffd , uffd_delay );
486483 }
487484
488485 return 0 ;
0 commit comments