Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp926548imj; Sat, 9 Feb 2019 10:58:59 -0800 (PST) X-Google-Smtp-Source: AHgI3IZbF44E9V3KF0Mqd6JE7ceuV9ZjKDoD3dlNvKJCi0RzsETFJO4kUlTl2AZ62A+LJMydL3ZM X-Received: by 2002:a62:7792:: with SMTP id s140mr28737561pfc.26.1549738738959; Sat, 09 Feb 2019 10:58:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549738738; cv=none; d=google.com; s=arc-20160816; b=j1XXWSHRVjZykHNMPaEmgseVDGwN/Blmlpkwt1M26ToWl+oFcVs1Lmsz/Au+E+whjp Xg6Tyrg5lttOCqC3DykUR0I1GUlWKBmrkxglLgH9RJRkIN6XRCsXKDXq0iRodGYmaya5 61xLw8LRm/Lt2kpIoId1mznwBq6t5LSSyzIvBAStjTLM1fd5BY3ASj325fiHVabmFgSi r1ambH0hb8oUVCNOYDkQNx4tm0QkR1+tbSPETFOOQRiuli+fPmjizCIEcOjahBFSGzqb MqGij/ungDUkIVGV0vX8OxiMKJ8CsCySwqA+Kp2K3IxQbwpQgEczgN/D1E2wEB9O9s4U dr0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pf626K7IkLZJxUgX80kplE8Se10ICMTa4r2WuU7uc8I=; b=loeRLPJxJsjIU0eusP9za5xbRrodg7S1DNZcIIjuS4d70PMLzA3fpooP6MjQv9OsV5 6z0Hhr9G6EQS8BY2KUfZzy+L1FhDuqZK9uTmGOfrFd4/H4T+8e/n7RNH7vwnUzfc2m0d 39Fxww+McPN03KNvFICMQkc1BgfrcV98G7ssK7LW6d6qrjZoeGAOpVKlbdrkw+VFvsyh q5Njmm9emz8z5IM5OytaPLCkxXATooAocMtUvR57QDnNdSdXr2YCDgIcUXUpN+CcbLBo W8/qAhxWpJ3BNqy/EKyXNKrYLJ1TJbRO5tumKr/pa8qorTlK/HpaYnLHxXd4E/+CaCX1 pytQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PNOHV+pm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n4si5767483pgd.10.2019.02.09.10.58.43; Sat, 09 Feb 2019 10:58:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PNOHV+pm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727828AbfBIS54 (ORCPT + 99 others); Sat, 9 Feb 2019 13:57:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:60118 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727013AbfBISrk (ORCPT ); Sat, 9 Feb 2019 13:47:40 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E0E5221929; Sat, 9 Feb 2019 18:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549738058; bh=glGdR8CXpXwmO8Nu3AWnJURVXH8pepIrWJjf/OxNOMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PNOHV+pmWSDfNyMWjC8KYYMV5xRrzzXo/AzWm/0ftSpCklxUtyaPtsPywiNz2duXJ Ot54TG2KlDds3ErFrhd21MzE0yFm0jWQhmhDuglaKjVvOmIzLsH4KyQNr0Ju/URgDY FrhlwgHmxH5kJp0K9sKuBC/fgGrXSFGxFzqBryso= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jin Yao , Alexander Shishkin , Andi Kleen , Kan Liang , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 4.20 03/42] perf stat: Fix endless wait for child process Date: Sat, 9 Feb 2019 13:46:55 -0500 Message-Id: <20190209184734.125935-3-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190209184734.125935-1-sashal@kernel.org> References: <20190209184734.125935-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jin Yao [ Upstream commit 8a99255a50c0b4c2a449b96fd8d45fcc8d72c701 ] 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: Jin Yao Reviewed-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Andi Kleen Cc: Kan Liang Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1546501245-4512-1-git-send-email-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/builtin-stat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 1410d66192f7..63a3afc7f32b 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -561,7 +561,8 @@ try_again: break; } } - wait4(child_pid, &status, 0, &stat_config.ru_data); + if (child_pid != -1) + wait4(child_pid, &status, 0, &stat_config.ru_data); if (workload_exec_errno) { const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg)); -- 2.19.1