Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3538824ybz; Mon, 20 Apr 2020 04:57:03 -0700 (PDT) X-Google-Smtp-Source: APiQypIqXoCq9x2a+iwatIVur5pIqAIZhH7q2IEmdXPg7ZBz22wOR2Ghj05NSbhLGd7FNi72CLOM X-Received: by 2002:a50:e007:: with SMTP id e7mr13902487edl.361.1587383823504; Mon, 20 Apr 2020 04:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587383823; cv=none; d=google.com; s=arc-20160816; b=bFRRELQmSxIH0T3iZCrT3f7bV7pQujn8u5diuRauZNYxqlKEzwJu/7V9ezcnbWaGl9 Rq91KCRxyW4xFWs47GTl2lVXNhHlx3XArFTPARRpy9NFsSykm8B3/Yr/dWU5FO7TXuVx 0sLrY1da24kQZGwpxiPqgdOmcqPFmCuPeFCz13mhfwdBuEi/XzA8yFPbwIaqVrqdh5n+ kn804ytOUQKHCdGC3R91Gk5OycQJjz8xCDf0cBWnzeSq32QNZN2rNCs1wEYd6/lqzxpU xuZ+x+mpj0u1GVvzRG4o/3IQnsbnqi5Ll5AQWrRtvBbiyihegLpe1JY2yfeRW721Huz1 z+wg== 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=lniSvMVvpPy5qzIGREn4C0VpyRhZx5kUl6JqJ5hpSoY=; b=BQ0u+wy6fs5gjznxpMJn1FUnw9S2zuTNKuYOB/Nk+pmyWHAWQFvoqQySJ60fXjd6VA lx8pah9b9LrCEsw7ihM/jUGKPblp0DMCfV0BmBzikzzBB0RW2mnRk4HDrlRVALn3anfD 2wVSImGsK75FU9NmfkitOR4fJq8BKkGkNbD/O9ZNIqVO1ne3P2mthyavETtRNbsyyNM0 +JA+LES8FEvyMWgLcm96EwwUzkTOxzJhgZclNuTONOZXittavxgZIjaR84vS8j/UxR8o XHl1JCw4hupEOb5K6cduRaB7I69287m5mzIfW/9eoV6EKAaQRj6eEB/PXsj4WIXW4aI4 xwLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=W1YRr5UX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id e3si402563ejb.68.2020.04.20.04.56.40; Mon, 20 Apr 2020 04:57:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=W1YRr5UX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726460AbgDTLxd (ORCPT + 99 others); Mon, 20 Apr 2020 07:53:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:36420 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725896AbgDTLx2 (ORCPT ); Mon, 20 Apr 2020 07:53:28 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7F55F218AC; Mon, 20 Apr 2020 11:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383608; bh=C+Ht8Ig+oP2aA02sPboO4LzooPFGVAHYU6P5xjE7qKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W1YRr5UXXWfmtLZPsTTbU3OfaUo6ENOnte7wSj9AnS02mLkw99tln7evXeP5d16q7 7qOQaLVFNvucyEoTZ/YDkgb8so5inE82oTDoQioBFZtWv9iTnJqFllHknC8c89mjYF 2U7WfMPgCNSIqQPk3NG+JVKrIhIj3gDq77dtsxlw= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Konstantin Kharlamov , Adrian Hunter , Jiri Olsa , yuzhoujian Subject: [PATCH 01/60] perf stat: Honour --timeout for forked workloads Date: Mon, 20 Apr 2020 08:52:17 -0300 Message-Id: <20200420115316.18781-2-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200420115316.18781-1-acme@kernel.org> References: <20200420115316.18781-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo When --timeout is used and a workload is specified to be started by 'perf stat', i.e. $ perf stat --timeout 1000 sleep 1h The --timeout wasn't being honoured, i.e. the workload, 'sleep 1h' in the above example, should be terminated after 1000ms, but it wasn't, 'perf stat' was waiting for it to finish. Fix it by sending a SIGTERM when the timeout expires. Now it works: # perf stat -e cycles --timeout 1234 sleep 1h sleep: Terminated Performance counter stats for 'sleep 1h': 1,066,692 cycles 1.234314838 seconds time elapsed 0.000750000 seconds user 0.000000000 seconds sys # Fixes: f1f8ad52f8bf ("perf stat: Add support to print counts after a period of time") Reported-by: Konstantin Kharlamov Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243 Tested-by: Konstantin Kharlamov Cc: Adrian Hunter Acked-by: Jiri Olsa Tested-by: Jiri Olsa Cc: Namhyung Kim Cc: yuzhoujian Link: https://lore.kernel.org/lkml/20200415153803.GB20324@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-stat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index ec053dc1e35c..9207b6c45475 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -686,8 +686,11 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) break; } } - if (child_pid != -1) + if (child_pid != -1) { + if (timeout) + kill(child_pid, SIGTERM); 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.21.1