• Jin Yao's avatar
    perf stat: Fix endless wait for child process · 3902b972
    Jin Yao authored
    [ Upstream commit 8a99255a ]
    
    We hit a 'perf stat' issue by using following script:
    
      #!/bin/bash
    
      sleep 1000 &
      exec perf stat -a -e cycles -I1000 -- sleep 5
    
    Since "perf stat" is launched by exec, the "sleep 1000" would be the
    child process of "perf stat". The wait4() call will not return because
    it's waiting for the child process "sleep 1000" to end. So 'perf stat'
    doesn't return even after 5s passes.
    
    This patch lets 'perf stat' return when the specified child process ends
    (in this case, the specified child process is "sleep 5").
    
    Committer testing:
    
      # cat test.sh
      #!/bin/bash
    
      sleep 10 &
      exec perf stat -a -e cycles -I1000 -- sleep 5
      #
    
    Before:
    
      # time ./test.sh
      #           time             counts unit events
           1.001113090        108,453,351      cycles
           2.002062196        142,075,435      cycles
           3.002896194        164,801,068      cycles
           4.003731666        107,062,140      cycles
           5.002068867        112,241,832      cycles
    
      real	0m10.066s
      user	0m0.016s
      sys	0m0.101s
      #
    
    After:
    
      # time ./test.sh
      #           time             counts unit events
           1.001016096         91,412,027      cycles
           2.002014963        124,063,708      cycles
           3.002883964        125,993,929      cycles
           4.003706470        120,465,734      cycles
           5.002006778        163,560,355      cycles
    
      real	0m5.123s
      user	0m0.014s
      sys	0m0.105s
      #
    Signed-off-by: 's avatarJin Yao <yao.jin@linux.intel.com>
    Reviewed-by: 's avatarJiri Olsa <jolsa@kernel.org>
    Tested-by: 's avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Kan Liang <kan.liang@linux.intel.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: http://lkml.kernel.org/r/1546501245-4512-1-git-send-email-yao.jin@linux.intel.comSigned-off-by: 's avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: 's avatarSasha Levin <sashal@kernel.org>
    3902b972
Name
Last commit
Last update
..
accounting Loading commit data...
arch Loading commit data...
bpf Loading commit data...
build Loading commit data...
cgroup Loading commit data...
crypto Loading commit data...
firewire Loading commit data...
gpio Loading commit data...
hv Loading commit data...
iio Loading commit data...
include Loading commit data...
kvm/kvm_stat Loading commit data...
laptop Loading commit data...
leds Loading commit data...
lib Loading commit data...
memory-model Loading commit data...
nfsd Loading commit data...
objtool Loading commit data...
pci Loading commit data...
pcmcia Loading commit data...
perf Loading commit data...
power Loading commit data...
scripts Loading commit data...
spi Loading commit data...
testing Loading commit data...
thermal/tmon Loading commit data...
time Loading commit data...
usb Loading commit data...
virtio Loading commit data...
vm Loading commit data...
wmi Loading commit data...
Makefile Loading commit data...