Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp124760pxb; Wed, 24 Feb 2021 20:43:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxiFrPF0PGLonmNHAZlMIB7yyDQR4b9fmJdQkDcd5Y5nq225iH7khaw4+6JgHFp/4gvUtMu X-Received: by 2002:a17:907:728b:: with SMTP id dt11mr900920ejc.321.1614228221493; Wed, 24 Feb 2021 20:43:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614228221; cv=none; d=google.com; s=arc-20160816; b=fTUaSpRnd6hG246pjVIlQb49C4+pmDTNe+VBucgx5ISObTesegSePZ/M07Aw7PwmOx cNk7vaByllJ+mBL94YxJG0crYIGMBvM8rw5qe7IkuqDn4P37Clh5qEBpcKRFUiZI3GaY S1obrF8C8JLlLuEEA/jfPmeExVsQd/kJpO9bQNAgQNK1NxB4LE+Co8UeuvG2d5reAebX RT52ffaxjqgEZ31+6G4kHL3kZmBUUP+JtXxuexmkeG5fKGlSBH9htwgzkZjReH+svHs7 1I1Y76F6so9PFJEd9GgNHaACVyMJwwGem5SBP+PsxEtcOMnQ8pzrrnLq4xA/boIMRgWA /QTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=z9NK3k66zAxg617L8ZnboynlZtEiO6YivZtcM5eSd6w=; b=SgrCgbGtJy0kpVIkErtrh39AJTyLv780rHB9dxsuPwx83fhjidPGDAxmKNbVwimaTh ePBasTwKxFMyCZ1IIQSsXJl4fbKbqrLNPLRJYRQePEB9E4BnPxqoLejfW2mpouHRpu6h voYmqUOH8cBi+w4kAAe2OUgEcx0KUFsWrGV2fUjsELg/iiP9MBT4pOfiYm8E1eC2jEaf TFXP93hgaBr6H2MUr0nP8h8SQNa5v1Iwdx0wIeQkeoUH75ZtylZ+yhFqv3xyS/+3kfKo N9CKepoO9Gv1IhRPyOnNhFKZDCO5mDrmpbYW/PKdELxrs8KRYybezsC2Ff4ANQtyGDvu KTNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=jdw2Mlvc; 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=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r1si2506760edt.394.2021.02.24.20.43.18; Wed, 24 Feb 2021 20:43:41 -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=@efficios.com header.s=default header.b=jdw2Mlvc; 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=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233996AbhBXXzG (ORCPT + 99 others); Wed, 24 Feb 2021 18:55:06 -0500 Received: from mail.efficios.com ([167.114.26.124]:57574 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbhBXXzG (ORCPT ); Wed, 24 Feb 2021 18:55:06 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 96EB13180FB; Wed, 24 Feb 2021 18:54:24 -0500 (EST) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id AHULjKWpfXbl; Wed, 24 Feb 2021 18:54:24 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 370723180FA; Wed, 24 Feb 2021 18:54:24 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 370723180FA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1614210864; bh=z9NK3k66zAxg617L8ZnboynlZtEiO6YivZtcM5eSd6w=; h=Date:From:To:Message-ID:MIME-Version; b=jdw2MlvcuxOJb4tpT/iTyUgFd/3pE4P0zc7BZZ2GAO139MjAdyzcupeFMkfRKvRwn R5260vsBqJVfBhwNjHUT7WnjWcCZTP6WIcbmAdd5JdhW8vwO1cQnq04UZ0V1RKPdUF nQuFsJTU8WRmQF7ngrT7ZlrFnmt3wvh97pYLI8NEfTCBfGwFaB1XcudHnx5h26wReR 1Mlm1EVo9JzRArb4EHC2A7g/91x4cKqvkpuEO0NPQ60HFYst++bTBbQMZtA17h5hV7 Qu+eHYZsYdxaheqJ9hsx14G6g1QUWDmExM9LFAUt1NqixmL/oNVA3HZzD9OVX8VefO Yte4gXpyNsuVA== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id vVNDhxZgyVMN; Wed, 24 Feb 2021 18:54:24 -0500 (EST) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id 238D03180F1; Wed, 24 Feb 2021 18:54:24 -0500 (EST) Date: Wed, 24 Feb 2021 18:54:24 -0500 (EST) From: Mathieu Desnoyers To: Mathieu Desnoyers Cc: Michael Jeanson , rostedt , linux-kernel , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , paulmck , Ingo Molnar , acme , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , "Joel Fernandes, Google" , bpf Message-ID: <1593236413.4171.1614210864063.JavaMail.zimbra@efficios.com> In-Reply-To: <915297635.2997.1614185975415.JavaMail.zimbra@efficios.com> References: <20210218222125.46565-1-mjeanson@efficios.com> <20210223211639.670db85c@gandalf.local.home> <083bce0f-bd66-ab83-1211-be9838499b45@efficios.com> <915297635.2997.1614185975415.JavaMail.zimbra@efficios.com> Subject: Re: [RFC PATCH 0/6] [RFC] Faultable tracepoints (v2) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_3996 (zclient/8.8.15_GA_3996) Thread-Topic: Faultable tracepoints (v2) Thread-Index: urvfoX6HX+i7c2KJtiaEM9MhS7PYp0IBUf+l Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- Mathieu Desnoyers wrote: > ----- On Feb 24, 2021, at 11:22 AM, Michael Jeanson mjeanson@efficios.com wrote: > > > [ Adding Mathieu Desnoyers in CC ] > > > > On 2021-02-23 21 h 16, Steven Rostedt wrote: > >> On Thu, 18 Feb 2021 17:21:19 -0500 > >> Michael Jeanson wrote: > >> > >>> This series only implements the tracepoint infrastructure required to > >>> allow tracers to handle page faults. Modifying each tracer to handle > >>> those page faults would be a next step after we all agree on this piece > >>> of instrumentation infrastructure. > >> > >> I started taking a quick look at this, and came up with the question: how > >> do you allow preemption when dealing with per-cpu buffers or storage to > >> record the data? > >> > >> That is, perf, bpf and ftrace are all using some kind of per-cpu data, and > >> this is the reason for the need to disable preemption. What's the solution > >> that LTTng is using for this? I know it has a per cpu buffers too, but does > >> it have some kind of "per task" buffer that is being used to extract the > >> data that can fault? > > As a prototype solution, what I've done currently is to copy the user-space > data into a kmalloc'd buffer in a preparation step before disabling preemption > and copying data over into the per-cpu buffers. It works, but I think we should > be able to do it without the needless copy. > > What I have in mind as an efficient solution (not implemented yet) for the LTTng > kernel tracer goes as follows: > > #define COMMIT_LOCAL 0 > #define COMMIT_REMOTE 1 > > - faultable probe is called from system call tracepoint [ preemption/blocking/migration is allowed ] > - probe code calculate the length which needs to be reserved to store the event > (e.g. user strlen), > > - preempt disable -> [ preemption/blocking/migration is not allowed from here ] > - reserve_cpu = smp_processor_id() > - reserve space in the ring buffer for reserve_cpu > [ from that point on, we have _exclusive_ access to write into the ring buffer "slot" > from any cpu until we commit. ] > - preempt enable -> [ preemption/blocking/migration is allowed from here ] > > - copy data from user-space to the ring buffer "slot", > > - preempt disable -> [ preemption/blocking/migration is not allowed from here ] > commit_cpu = smp_processor_id() > if (commit_cpu == reserve_cpu) > use local_add to increment the buf[commit_cpu].subbuffer[current].commit_count[COMMIT_LOCAL] > else > use atomic_add to increment the buf[commit_cpu].subbuffer[current].commit_count[COMMIT_REMOTE] The line above should increment reserve_cpu's buffer commit count, of course. Thanks, Mathieu > - preempt enable -> [ preemption/blocking/migration is allowed from here ] > > Given that lttng uses per-buffer/per-sub-buffer commit counters as simple free-running > accumulators, the trick here is to use two commit counters rather than single one for each > sub-buffer. Whenever we need to read a commit count value, we always sum the total of the > LOCAL and REMOTE counter. > > This allows dealing with migration between reserve and commit without requiring the overhead > of an atomic operation on the fast-path (LOCAL case). > > I had to design this kind of dual-counter trick in the context of user-space use of restartable > sequences. It looks like it may have a role to play in the kernel as well. :) > > Or am I missing something important that would not survive real-life ? > > Thanks, > > Mathieu > > -- > Mathieu Desnoyers > EfficiOS Inc. > http://www.efficios.com -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com