Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp12852464pxu; Sat, 2 Jan 2021 14:10:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKoH7bJglYguRvWXfr4lNt3NVB/2jnCecp1kA4SuwVC/EoIsfFFeWSG45vlLSu73kdX/AH X-Received: by 2002:a17:906:d101:: with SMTP id b1mr43059456ejz.80.1609625437355; Sat, 02 Jan 2021 14:10:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609625437; cv=none; d=google.com; s=arc-20160816; b=eSbaEPMQJNOuxxcuDUIcts1xb08dZWYpq2XZKauSiX+QNPTHdLI/zJbftrEueNGmJE ONQu5jAl9ddFrwaE0IoZFmW8/lYh4Ca6saE9Vm7LqW4l/hQ0s5+gqTmjW/kCGbhm7yU9 lzKtglOOdMElLzvVsrupl/7FVCo2Mqg+D/nhRTMnrqdsqEzTCxROg+cvdaMsy7rzouWg TJOHA2VvYPEAJQRIh8ifeihLwXiqKYAnQYGAThxfA9H1jCNSFdWBBCNPXcxePvlwIloX 1RLc7SQQWqZ09lKq+PbWLrJxNz8Xp5QFWW3RRQpiXJfO2xwQMOR/RAAgVdhLt3PA0U04 41gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9mLL/HOM0OOf6st8CCnk7Keb6zn1LJXLxmx1YNNo8TY=; b=EwLdT+y17TYu34zV5bfcjOothOWLmuYigCJgKHXS67+TBNp7TycbxpuDcISXx3ENbL iJ4l5TJ/7508R8RyJ846XOAp97UrFkWOLSbCy/ajqSxMbLo+nmpmFghrCaf2D3HO2+Sy h6GK0lTmqsZyTT7sQrIfvMn1QPuN/OOLnzo5oZODOJrPnPPb2g+MC6+hnNZOy9jI3bFt 5CG0+htaHoBmnBFIokSD2s7JIGYoprfx4VGwI5bnbypxoD5ofiXLpGg234IfVxGdOCCH 3hc6uXGEJfd4sItI6hq+f/+kk5Chf3wM4AgSj5LxYbnGCUQOmZMa6+vuuVyayxJqKlLG JKrA== ARC-Authentication-Results: i=1; mx.google.com; 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 op28si25905921ejb.30.2021.01.02.14.10.14; Sat, 02 Jan 2021 14:10:37 -0800 (PST) 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; 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 S1727412AbhABWGf convert rfc822-to-8bit (ORCPT + 99 others); Sat, 2 Jan 2021 17:06:35 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:21874 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727390AbhABWGe (ORCPT ); Sat, 2 Jan 2021 17:06:34 -0500 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-296-GDyyDExqNUCLI6mU2s9Syw-1; Sat, 02 Jan 2021 17:05:37 -0500 X-MC-Unique: GDyyDExqNUCLI6mU2s9Syw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8EF49800D62; Sat, 2 Jan 2021 22:05:35 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id C725B19727; Sat, 2 Jan 2021 22:05:32 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov Subject: [PATCH 15/22] perf daemon: Use control to stop session Date: Sat, 2 Jan 2021 23:04:34 +0100 Message-Id: <20210102220441.794923-16-jolsa@kernel.org> In-Reply-To: <20210102220441.794923-1-jolsa@kernel.org> References: <20210102220441.794923-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using 'stop' control command to stop perf record session. If that fails, falling back to current SIGTERM/SIGKILL pair. Signed-off-by: Jiri Olsa --- tools/perf/builtin-daemon.c | 56 ++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c index 260bcffd9ae8..e45a1acaad18 100644 --- a/tools/perf/builtin-daemon.c +++ b/tools/perf/builtin-daemon.c @@ -502,11 +502,33 @@ session__control(struct session *session, const char *msg, bool do_ack) static void session__kill(struct session *session, struct daemon *daemon) { - session__signal(session, SIGTERM); - if (session__wait(session, daemon, 10)) { - session__signal(session, SIGKILL); - session__wait(session, daemon, 10); - } + int how = 0; + + do { + switch (how) { + case 0: + session__control(session, "stop", false); + break; + case 1: + session__signal(session, SIGTERM); + break; + case 2: + session__signal(session, SIGKILL); + break; + default: + break; + } + how++; + + } while (session__wait(session, daemon, 10)); +} + +static void daemon__stop(struct daemon *daemon) +{ + struct session *session; + + list_for_each_entry(session, &daemon->sessions, list) + session__control(session, "stop", false); } static int daemon__reconfig(struct daemon *daemon) @@ -545,11 +567,25 @@ static int daemon__reconfig(struct daemon *daemon) static void daemon__kill(struct daemon *daemon) { - daemon__signal(daemon, SIGTERM); - if (daemon__wait(daemon, 10)) { - daemon__signal(daemon, SIGKILL); - daemon__wait(daemon, 10); - } + int how = 0; + + do { + switch (how) { + case 0: + daemon__stop(daemon); + break; + case 1: + daemon__signal(daemon, SIGTERM); + break; + case 2: + daemon__signal(daemon, SIGKILL); + break; + default: + break; + } + how++; + + } while (daemon__wait(daemon, 10)); } static void daemon__free(struct daemon *daemon) -- 2.26.2