@@ -196,25 +196,27 @@ static void calc_min_max_cpu(void)
196196static void help (const char * name )
197197{
198198 puts ("" );
199- printf ("usage: %s [-h] [-u]\n" , name );
199+ printf ("usage: %s [-h] [-u] [-l latency] \n" , name );
200200 printf (" -u: Don't sanity check the number of successful KVM_RUNs\n" );
201+ printf (" -l: Set /dev/cpu_dma_latency to suppress deep sleep states\n" );
201202 puts ("" );
202203 exit (0 );
203204}
204205
205206int main (int argc , char * argv [])
206207{
208+ int r , i , snapshot , opt , fd = -1 , latency = -1 ;
207209 bool skip_sanity_check = false;
208- int r , i , snapshot ;
209210 struct kvm_vm * vm ;
210211 struct kvm_vcpu * vcpu ;
211212 u32 cpu , rseq_cpu ;
212- int opt ;
213213
214- while ((opt = getopt (argc , argv , "hu " )) != -1 ) {
214+ while ((opt = getopt (argc , argv , "hl:u " )) != -1 ) {
215215 switch (opt ) {
216216 case 'u' :
217217 skip_sanity_check = true;
218+ case 'l' :
219+ latency = atoi_paranoid (optarg );
218220 break ;
219221 case 'h' :
220222 default :
@@ -243,6 +245,20 @@ int main(int argc, char *argv[])
243245 pthread_create (& migration_thread , NULL , migration_worker ,
244246 (void * )(unsigned long )syscall (SYS_gettid ));
245247
248+ if (latency >= 0 ) {
249+ /*
250+ * Writes to cpu_dma_latency persist only while the file is
251+ * open, i.e. it allows userspace to provide guaranteed latency
252+ * while running a workload. Keep the file open until the test
253+ * completes, otherwise writing cpu_dma_latency is meaningless.
254+ */
255+ fd = open ("/dev/cpu_dma_latency" , O_RDWR );
256+ TEST_ASSERT (fd >= 0 , __KVM_SYSCALL_ERROR ("open() /dev/cpu_dma_latency" , fd ));
257+
258+ r = write (fd , & latency , 4 );
259+ TEST_ASSERT (r >= 1 , "Error setting /dev/cpu_dma_latency" );
260+ }
261+
246262 for (i = 0 ; !done ; i ++ ) {
247263 vcpu_run (vcpu );
248264 TEST_ASSERT (get_ucall (vcpu , NULL ) == UCALL_SYNC ,
@@ -278,6 +294,9 @@ int main(int argc, char *argv[])
278294 "rseq CPU = %d, sched CPU = %d" , rseq_cpu , cpu );
279295 }
280296
297+ if (fd > 0 )
298+ close (fd );
299+
281300 /*
282301 * Sanity check that the test was able to enter the guest a reasonable
283302 * number of times, e.g. didn't get stalled too often/long waiting for
@@ -293,8 +312,8 @@ int main(int argc, char *argv[])
293312 TEST_ASSERT (skip_sanity_check || i > (NR_TASK_MIGRATIONS / 2 ),
294313 "Only performed %d KVM_RUNs, task stalled too much?\n\n"
295314 " Try disabling deep sleep states to reduce CPU wakeup latency,\n"
296- " e.g. via cpuidle.off=1 or setting /dev/cpu_dma_latency to '0', \n"
297- " or run with -u to disable this sanity check." , i );
315+ " e.g. via cpuidle.off=1 or via -l <latency>, or run with -u to \n"
316+ " disable this sanity check." , i );
298317
299318 pthread_join (migration_thread , NULL );
300319
0 commit comments