Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2330868pxb; Thu, 11 Feb 2021 09:38:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBgGNj8iKvorRkT0E/obcdoiEzmiolyfbbtswVsLWzxnvJeiwuQAoUllCTlPTfDW3ysPsw X-Received: by 2002:a05:6402:2553:: with SMTP id l19mr9303441edb.326.1613065128150; Thu, 11 Feb 2021 09:38:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613065128; cv=none; d=google.com; s=arc-20160816; b=vMWDLbqlAubvwJVc3JOWVtgF/UzvGVpFDA3OLmDu7LZ7grXx2aQ9mJNQZ/Yi4CJ1kH TyTd0LkeSIMiyV3kee2c6gIE62stdIG0IagqOfkDVqqhLLV7sjOFjLlbAT5kRxv6aLUn 2lrzq8adR9tF/EfGyD57AWfBOTu7Gj5DTLcjsMQWV2tnX8N5IEyxY3CY+H1aXS2hNpX8 9FK33GMIfILde8O8J/afZQxdS6ds8khnNLJD4Csuvn78XhLDsSpJLNaUYRG78QAysuXg uSiIJwt1XRY1OQkNEJXPFtry40gQCEYswLOaZZKhFQb3xz5QpJBfEaCKQYy5qomEzFOF mZ7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8772P6vmNybTNfCUnNYCC7Sd7vQziPC/FvJiYq/mKF0=; b=Yc1bn+bmLr3P54m2WwYitmOpcc+dDRHF3vBZ81rtIE7fmDPaY0j1gFCvQHatI2epth 6HeVUYdmrxdlt+df7bU6D9kHcioNyRstLKeacFNdK5o4CH5Mr6rkWhkiJlPjqcgHho9t RCfqoG3bW0yk5f2GVJPES3DykfmTnTHPZSCDWpjnGiBPqE0tfkF12JIYnQT7AMaP0ITQ x8GhtAi/GwqKVBzOIug7YEw8DISVAONjYETE38dDXHsbKWaLDvsqJYkUScjuuWhzgnU/ A0kx36NfW/fNx2TfcVxARkXL7a2vXVtXJDq3kEnGw1VGr5XPkja6KNd/cVhVX/DdkXWi or7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OIAt1EI0; 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 g12si4440778edk.115.2021.02.11.09.38.19; Thu, 11 Feb 2021 09:38:48 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OIAt1EI0; 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 S232377AbhBKRgY (ORCPT + 99 others); Thu, 11 Feb 2021 12:36:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27885 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbhBKQh0 (ORCPT ); Thu, 11 Feb 2021 11:37:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613061358; 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:references:references; bh=8772P6vmNybTNfCUnNYCC7Sd7vQziPC/FvJiYq/mKF0=; b=OIAt1EI0H+fD7pfveKBJCaX72Av/D+cFAH7OW9OWLE6OEwYVSmavQiWZOULOLrjri2HH+/ T4v0YhXaMKmzpqHwZFqWA11/qvyLbfSbT57wT3Q4760JhvJoEqABzA4JW0WylIZBnHulJk AXic1E0sIpgXDP3i5Q8EtAhIa+9CFEI= 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-122-MhuDq2VTMEisZjcwKw9DnA-1; Thu, 11 Feb 2021 11:35:56 -0500 X-MC-Unique: MhuDq2VTMEisZjcwKw9DnA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 09AE910066F0; Thu, 11 Feb 2021 16:35:55 +0000 (UTC) Received: from krava (unknown [10.40.192.105]) by smtp.corp.redhat.com (Postfix) with SMTP id C71A360BF1; Thu, 11 Feb 2021 16:35:52 +0000 (UTC) Date: Thu, 11 Feb 2021 17:35:51 +0100 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , Alexei Budankov Subject: Re: [PATCH 13/24] perf daemon: Allow only one daemon over base directory Message-ID: References: <20210208200908.1019149-1-jolsa@kernel.org> <20210208200908.1019149-14-jolsa@kernel.org> <20210211132018.GE1131885@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210211132018.GE1131885@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 11, 2021 at 10:20:18AM -0300, Arnaldo Carvalho de Melo wrote: > Em Mon, Feb 08, 2021 at 09:08:57PM +0100, Jiri Olsa escreveu: > > Add 'lock' file under daemon base and flock it, so only one > > perf daemon can run on top of it. > > > > Each daemon tries to create and lock BASE/lock file, if it's > > successful we are sure we're the only daemon running over > > the BASE. > > > > Once daemon is finished, file descriptor to lock file is > > closed and lock is released. > > > > Example: > > > > # cat ~/.perfconfig > > [daemon] > > base=/opt/perfdata > > > > [session-cycles] > > run = -m 10M -e cycles --overwrite --switch-output -a > > > > [session-sched] > > run = -m 20M -e sched:* --overwrite --switch-output -a > > > > Starting the daemon: > > > > # perf daemon start > > > > And try once more: > > > > # perf daemon start > > failed: another perf daemon (pid 775594) owns /opt/perfdata > > > > will end up with an error, because there's already one running > > on top of /opt/perfdata. > > Had to add this: > > Committer notes: > > Provide lockf(F_TLOCK) when not available, i.e. transform: > > lockf(fd, F_TLOCK, 0); > > into: > > flock(fd, LOCK_EX | LOCK_NB); > > Which should be equivalent. > > Noticed when cross building to some odd Android NDK. > > ------ > > Patch: > > [acme@five perf]$ git diff > diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c > index 1c17c9e10ca6a656..2890573540f7d027 100644 > --- a/tools/perf/builtin-daemon.c > +++ b/tools/perf/builtin-daemon.c > @@ -914,6 +914,20 @@ static int setup_config(struct daemon *daemon) > return daemon->config_real ? 0 : -1; > } > > +#ifndef F_TLOCK > +#define F_TLOCK 2 > + > +#include > + > +static int lockf(int fd, int cmd, off_t len) > +{ > + if (cmd != F_TLOCK || len != 0) > + return -1; > + > + return flock(fd, LOCK_EX | LOCK_NB); > +} > +#endif // F_TLOCK > + > /* > * Each daemon tries to create and lock BASE/lock file, > * if it's successful we are sure we're the only daemon > [acme@five perf]$ > nice, thanks jirka