Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp714947ybz; Wed, 15 Apr 2020 17:20:50 -0700 (PDT) X-Google-Smtp-Source: APiQypJvjfvIJWyBZcVtg9aD2/cUCJyduznddg+5EnhNr7T2j9qVAN8/X82VuZ/yLEICTZxY2iRR X-Received: by 2002:a05:6402:1543:: with SMTP id p3mr8588652edx.333.1586996450088; Wed, 15 Apr 2020 17:20:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586996450; cv=none; d=google.com; s=arc-20160816; b=Vh2hfbONM6lodgGFC4SwEwNXSKh8VffMXDJomKcFGTCvCqWR8YcqheN+q8GpAl05Rm OKyzD8BWWo5L9G/w7MgLcc9k+nujALFCHZSm4wDZ5E8w6ObIainIa7zsjNZBkuL0jEzI vS7dlrHqDfnRI4YUT8Z8N+AlIG7YBKkxitcS+7JMHxstlXNMk7csMZ48McpIXpmfCsUM CKsfy5nhDleTj6OPZNqlii7KTMyqJZ1Ibfv1p98VtCla8+dcnn4iVhnMump0QYUqFYwh xOxH1lxDjeM8LDVEkEblgeeA0mKCVTzqSHRimZnpkHqtbjhNfO5pC9TirQ1WZ1drPEZf XL3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=Xpd90H8d2yeXTr/rhsB+k3mtd2C28vWEIlnqEeKiNkU=; b=GPbeWSyAX602w6Bo/h4Ladt08N/0kAXqd94Nv2HUG07e/s8vZJROSchblRSxAzf40h PZnLU09KC/C7YWSHzRCzMpi/0kKGlRLjEdf142VCTOqVVNBwbc0NXm1+qZTuHZ2LM5qx DfiflIfXAjEMo0itsAUhvInDUb1q/mgvcXG2wvmZAynK4HZ370jMl6kgXZriJAE22N4u uVgZ6e/8jc+GNkb8pnXSRrsN0uHeO1ryvBztanoz7Ev0oXvGWsQao2E1J7z2/kMOhkBQ VfRZDJZOPOKsy8IZikpabxYO5sJYLLcIZh7u2uxBg+3iXtxJA9aMoKMPt+5meAkBTyGP Cc/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="TAgdeUO/"; 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 y6si10916540eds.303.2020.04.15.17.20.27; Wed, 15 Apr 2020 17:20:50 -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="TAgdeUO/"; 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 S1415775AbgDOQZj (ORCPT + 99 others); Wed, 15 Apr 2020 12:25:39 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:29819 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1415766AbgDOQZg (ORCPT ); Wed, 15 Apr 2020 12:25:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586967934; 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: in-reply-to:in-reply-to; bh=Xpd90H8d2yeXTr/rhsB+k3mtd2C28vWEIlnqEeKiNkU=; b=TAgdeUO/QivRF79aEmNQq8+TDsHX3hP6KxXEEBV9aDCOnAPD7sk2qIKuo84xIJYgTpjDwD 17gubJITV+461bVwxCEK8BiKV3VqbJnQzi7HrVN7VWsl616CdCAP2f7l8JNm+6ukc11nEl LVNrReQxzCEPWam2//zSM9s8hyeDjsE= 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-176-eRXajeUcNn-oesQ-Sg9xbA-1; Wed, 15 Apr 2020 12:25:29 -0400 X-MC-Unique: eRXajeUcNn-oesQ-Sg9xbA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 78B54107ACC4; Wed, 15 Apr 2020 16:25:26 +0000 (UTC) Received: from krava (ovpn-112-109.ams2.redhat.com [10.36.112.109]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 40ADE99E03; Wed, 15 Apr 2020 16:25:23 +0000 (UTC) Date: Wed, 15 Apr 2020 18:25:19 +0200 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Konstantin Kharlamov , Adrian Hunter , Linux Kernel Mailing List , linux-perf-users@vger.kernel.org, yuzhoujian@didichuxing.com Subject: Re: [PATCH] perf stat: Honour --timeout for forked workloads Message-ID: <20200415162519.GB284534@krava> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200415153803.GB20324@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 15, 2020 at 12:38:03PM -0300, Arnaldo Carvalho de Melo wrote: > 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 Acked/Tested-by: Jiri Olsa cc-ing yuzhoujian, author of the --timeout jirka > --- > 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 >