Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp710906ybz; Wed, 15 Apr 2020 17:15:20 -0700 (PDT) X-Google-Smtp-Source: APiQypKLN6uSUTrnm379KLN3ZOxQsVImURVQ9XOKFbzXjkzKi8KGuFMCGSK/gp0WfEI3YcWxVxBi X-Received: by 2002:a17:906:3b8b:: with SMTP id u11mr7372709ejf.352.1586996120429; Wed, 15 Apr 2020 17:15:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586996120; cv=none; d=google.com; s=arc-20160816; b=hEnngUJwIXTcQQBI7uVQieVh+7IKGBQv58fRE1Awibouzg3hubJ/6j5hFD+RsMsjFL 1bLTiL1jgl434x8z8uuLhgVbI1E1e6vOar6qXuAv1NSjCaAxTVATAXzAH0zUAK2utljB LLh9RfBEHfOsUDIrXMDq0ZYVQN6kJucFwRoHBLqLvXwb5Yjh+RVw/CnbfRaH25SZLm8e w01y1iNHKtg5zJWIUyMRYfDpm9tHUB7jTwgnnckeixWGqZMY9Qhlnir8OOOhE6KSpF72 2zd2G3alu1iT5GqCsR4T+5V1Qh+tIUNfpJNIc+mMDQ/I2lCxLRYI/WaffkQw5P13jNvZ gSow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:bugzilla:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=A8FUkjVdBofT9s7NZzj5Scx0Uhc9mtgjr7nvRsCO88E=; b=hLD5I41A1xYqMdOfllDaM5widO6ZlZ69rNEihKOOfldLi1AQ5lHvmoc5M/wN9TGoEq BuXQuvoCPtDF3BzsRQ8hyiUyg3UO4LKdes0Vtpph3uVbvl/qjzMRT8OSRsikLkjcCUnp t25BX1i9u1EHl9lntSLLRF3YqIg22dye8TeXPNvLtTrx4BaK/ovlY2bJ7hOrKTzT/bho k/lmDmxpvgzHHjfGDr4tql8vEyl5vnosZ+TfzF8qyCHWqrYRdF6y2lf+FTxcOuzGjuuC PiBp4AX6uFsVK/RZ33O22yDACU4ef7CORx37OIU+e59E3/Wb8nqsNM3W+SXTKw0KWTNL +NKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eaRogXqy; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o12si11384478edj.233.2020.04.15.17.14.57; Wed, 15 Apr 2020 17:15:20 -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=@redhat.com header.s=mimecast20190719 header.b=eaRogXqy; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1414783AbgDOPi1 (ORCPT + 99 others); Wed, 15 Apr 2020 11:38:27 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:33139 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728834AbgDOPiR (ORCPT ); Wed, 15 Apr 2020 11:38:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586965096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=A8FUkjVdBofT9s7NZzj5Scx0Uhc9mtgjr7nvRsCO88E=; b=eaRogXqyGDJXdtUpBp5ql1oKEf3o2ho8QGJh3APB3uIwj0P4RZJLHN7EBMPcDlm3pc1kKM y8D3bCDAOz1j6u4ijbecpr5IKkyp26EGhSNLmiYmOdcN/gBLVeIfg1tkZgtQNFe1qPTwQT aP6OU18Jbmbe+lnirBoUnWUx6s4jsFk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-240-y6T9yrGgM4-uzT9WvVQRIA-1; Wed, 15 Apr 2020 11:38:09 -0400 X-MC-Unique: y6T9yrGgM4-uzT9WvVQRIA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A31458018A2; Wed, 15 Apr 2020 15:38:08 +0000 (UTC) Received: from quaco.ghostprotocols.net (unknown [10.3.128.10]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F27A4118DED; Wed, 15 Apr 2020 15:38:07 +0000 (UTC) Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 42B20409A3; Wed, 15 Apr 2020 12:38:03 -0300 (-03) Date: Wed, 15 Apr 2020 12:38:03 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa , Namhyung Kim Cc: Konstantin Kharlamov , Adrian Hunter , Linux Kernel Mailing List , linux-perf-users@vger.kernel.org Subject: [PATCH] perf stat: Honour --timeout for forked workloads Message-ID: <20200415153803.GB20324@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi guys, Please take a look and give this your acks, Tested-by, etc. Thanks, - Arnaldo ---- 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 # Reported-by: Konstantin Kharlamov Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243 Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim 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.25.2