Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp470014lqt; Thu, 6 Jun 2024 08:47:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXuvZLnavJB6U3Duy7eigtsxUC+oBrKsy8gmxnL+gRuZ3AWKKFLha6Y6IC+6La5r9JNzQZld1m4URUp4AGbcPZmlKu7WZThq2GC4rPx/g== X-Google-Smtp-Source: AGHT+IFx7LMfI/gH1t24ySJhMGD2DUQalp4xNs4nXpG2huH1ZvcN/wMCkvxwXknzxS5tQzRnliuV X-Received: by 2002:ac8:7f8f:0:b0:43d:f71d:98cf with SMTP id d75a77b69052e-44041b4e991mr296781cf.11.1717688853506; Thu, 06 Jun 2024 08:47:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717688853; cv=pass; d=google.com; s=arc-20160816; b=SLnPB9Xw81x1f43xdNzHtThgAEwdCZcwElPPRm0bw26N+TPNVE7ZmpGfxj76+mNugk Rxg6OKPcY2K4FInRFXNpeqnu8plR3HRFN4r6n2mgCNZRC0m1pwA3EJJ4g4yeN+hcHWmN vnsgvzVfYs8DAqvrSr8Gx4URU7m0xyvS+jDfRruRrAwwNU3Macm6iAwwryS0FQjTgO9L HqstpZoeWWf7kpIUZRjGJEJAJsv34pLF65Rkw8qUZbY31vGkNlAuLizXk0UaKS9yhCNo 8b0QJzwwlFpRcITbAdK2mfTBJjIBZkQKevoqgNaRQHDwMm2/4YF/SE8s23cUdheW0rBh RYlQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=hKe52NGpfUxlQvWE5siBYeg/W5fcruKXW0Q1K5Wl+lE=; fh=UUOfeybJeA7TYLpWdQoIV2IrjHCb5LRmwGUcdvmKVvk=; b=xLHw7wThVQxbkbvBMC7m6Yo4jEYWeeaR51zvYmQeh6BoImrk3COHDK5bnJ8nSUIUYX bL1y44C3VnTLyIDGJBk+anmaAsupiWHj4fXO5BdIXpUVUCnpjqyWSjdTybSJmZdrkDRz jIgC9ji8ciY/krcuBgN3roHO5U3AuG7cNq/K4bExM0RV4z7sADgjvEZ3pYIuJCDeITNT 3TbOxoNyc6mM+2n9x10nvkL/cT2Q4yFbF/XUQc2eClYc4TuT/NHCCX3bMpfWuNfajs7X pQAmHW610ZmAekbDPQlSK9Ux0x9k/ZOsqQ9xLSj6Rt/QkHQ4YEsZ6Ol82RydHQke9aJ8 YmBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="OZNx6c2/"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-204602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204602-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-44038b162ecsi18295871cf.390.2024.06.06.08.47.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 08:47:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="OZNx6c2/"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-204602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204602-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2DD231C235C8 for ; Thu, 6 Jun 2024 15:47:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7563196C7B; Thu, 6 Jun 2024 15:47:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OZNx6c2/" Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E7BB197543 for ; Thu, 6 Jun 2024 15:47:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717688831; cv=none; b=ozZ8jiphXUUscyluzI1BznrHU5vw3iiyZ40f7gtd6xVzhmWUz8wQA7GIdwPM/pv8chAD5EVcSu+youLBOS3cJ/mmHo+Myh+Pwpxun8yZnHKojU64VQcQ1zFfHpVy42HdYupuqnU8lQrXcsE6sSy4Dwq3so/AUMQrV1w++Oz+YBY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717688831; c=relaxed/simple; bh=hKe52NGpfUxlQvWE5siBYeg/W5fcruKXW0Q1K5Wl+lE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=tIZfICA4g4gPcmLxAeIVsYrgsnVWVRamlHSNzUd1loMXM2hR9yjJh5O16g7MfLJQHbw3yRzP+Wb9aNGVwVUwGOKGij0L9MLEA445RPE+6iY0hinkoOUEtyYo+94+FzH67Fhc74/Bzjxg1ad6yDA1bq3screKpZw/cHAUsDQ/WQ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OZNx6c2/; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-35e5c6600f0so930841f8f.3 for ; Thu, 06 Jun 2024 08:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717688828; x=1718293628; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=hKe52NGpfUxlQvWE5siBYeg/W5fcruKXW0Q1K5Wl+lE=; b=OZNx6c2/IKmqQJcxrj0tQNl2zPD5oIkhrhQGFsoBiwvg0uKo0JcRyiJyw+KzMdVdeu Td+E+VwRLrrt3V9uWxkPdw1WOkQy1W+hovlj5if+8p7WjWHFkYnBaCrdgqTjO0wC1xU7 va9+oTOj5z20OS3AtlP3Nqnbxm1BHWI/eYgOaRCEbDtdRUixsdylUnBmGbhpqcSoeuYX 4/9J7WfunmnqKXh4KUmT5aeghIPTjsFeLAg+x0pp7r+7NqkAfkEgds6it/TZviqje9/1 1IfaAUuGG0cky3yhJyFPJkC2jUzdBvSxbFHLAzsCP44/0TIQCfmNq5qUpvdLO4np4A7K lZJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717688828; x=1718293628; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hKe52NGpfUxlQvWE5siBYeg/W5fcruKXW0Q1K5Wl+lE=; b=eSzp7frJK6VOCMAnNzh/35CzWbO9evBtralhL0rIslViv11yBoDcIyxIOQkNzIR4+B 15gg/a5wNC9QfjoYEtv9aRtsjDyOdDjfScrdtsTq8AbbmdjWuX1owFWIj7WKTsegdfOk mbtjKCLGDSrpJ6fKCinRbLKXpYDmf8cAHphgCZi0sQaPx64oysFqkM5eZeEAesV7qMLV 8yFKaAVYJ4fjTvja+GPSqEpua5LhIHmTCBgCqn226nnsiXoajFSxWt6JyGmpv6F1XRFF +Je6ZU6f8PRPidU2a+0rhe2R3Xq8pf63ug17VAZrN3R15R/QmiHILsE5gSPcz2ZXqpQy YIgQ== X-Forwarded-Encrypted: i=1; AJvYcCWBsmNuXxdFKZS6FMO5gRGUEufdfZwv6QsAW4GNuyILpY0ZUIllwtBCEghW2D0YZJN4waEEI+Dnz85pyT3HpY7RvuVGGLJAV7Z/BeG6 X-Gm-Message-State: AOJu0Ywufb3GlUJ4b5eh8lLJQKJBCuJa7pTmak2m1CFcX7OmsEx/pI24 wZ6daWF6mrIWB1cUdKWvYomSTsiu8M/xKowy/3tJBrHKWZgjmsx2KjGhnfmse5qWKWx3Syspo3a XJg3jcvsPPNWkVUSRHwlGBPm71eKi/D8Xt+B3 X-Received: by 2002:a5d:6ac6:0:b0:35e:8333:28f4 with SMTP id ffacd0b85a97d-35e8ef7f346mr4448223f8f.60.1717688828366; Thu, 06 Jun 2024 08:47:08 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240606-tracepoint-v1-0-6551627bf51b@google.com> In-Reply-To: From: Alice Ryhl Date: Thu, 6 Jun 2024 17:46:55 +0200 Message-ID: Subject: Re: [PATCH 0/3] Tracepoints and static branch/call in Rust To: Mathieu Desnoyers Cc: Steven Rostedt , Masami Hiramatsu , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Ard Biesheuvel , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , linux-trace-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 6, 2024 at 5:25=E2=80=AFPM Mathieu Desnoyers wrote: > > On 2024-06-06 11:05, Alice Ryhl wrote: > > This implementation implements support for static keys in Rust so that > > the actual static branch will end up in the Rust object file. However, > > it would also be possible to just wrap the trace_##name generated by > > __DECLARE_TRACE in an extern C function and then call that from Rust. > > This will simplify the Rust code by removing the need for static > > branches and calls, but it places the static branch behind an external > > call, which has performance implications. > > The tracepoints try very hard to minimize overhead of dormant tracepoints > so it is not frowned-upon to have them built into production binaries. > This is needed to make sure distribution vendors keep those tracepoints > in the kernel binaries that reach end-users. > > Adding a function call before evaluation of the static branch goes agains= t > this major goal. > > > > > A possible middle ground would be to place just the __DO_TRACE body in > > an extern C function and to implement the Rust wrapper by doing the > > static branch in Rust, and then calling into C the code that contains > > __DO_TRACE when the tracepoint is active. However, this would need some > > changes to include/linux/tracepoint.h to generate and export a function > > containing the body of __DO_TRACE when the tracepoint should be callabl= e > > from Rust. > > This tradeoff is more acceptable than having a function call before > evaluation of the static branch, but I wonder what is the upside of > this tradeoff compared to inlining the whole __DO_TRACE in Rust ? > > > So in general, there is a tradeoff between placing parts of the > > tracepoint (which is perf sensitive) behind an external call, and havin= g > > code duplicated in both C and Rust (which must be kept in sync when > > changes are made). This is an important point that I would like feedbac= k > > on from the C maintainers. > > I don't see how the duplication happens there: __DO_TRACE is meant to be > inlined into each C tracepoint caller site, so the code is already meant > to be duplicated. Having an explicit function wrapping the tracepoint > for Rust would just create an extra instance of __DO_TRACE if it happens > to be also inlined into C code. > > Or do you meant you would like to prevent having to duplicate the > implementation of __DO_TRACE in both C and Rust ? > > I'm not sure if you mean to prevent source code duplication between > C and Rust or duplication of binary code (instructions). It's a question of maintenance burden. If you change how __DO_TRACE is implemented, then those changes must also be reflected in the Rust version. There's no issue in the binary code. Alice