Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6479087rdb; Tue, 2 Jan 2024 03:30:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/amG+7N/ZB3eGu+oPF8JfQ4cBvPZuxhexQcdlsc6dViekpm5zeyWwcit1O+wn25lQGC0K X-Received: by 2002:a05:6870:a188:b0:203:ec89:de1e with SMTP id a8-20020a056870a18800b00203ec89de1emr22277095oaf.58.1704195043016; Tue, 02 Jan 2024 03:30:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704195042; cv=none; d=google.com; s=arc-20160816; b=Gh4BmYqUpMC87o7iSkkK9BfQX/Kbx2dl4QGHn/WAAPg4STk31YY112iFVsHzCvtEQY I8iTenpeKTtb1XSbbdcjoIDM6QyUFvw5zVlTfWJDV2Z22IOradCxqcMSDZX/vFvJ7kRS g31uJAGsiKqo9tEyUe72coWIWW+RGjG3XVEBVwcG9xV2f7mc/4yZUdZM7zVG/nG7jFqq 6qczYgQdGxpOXWsBxqWSHHcL9cOI9WMAJUiHMt9Zddo8HQ5uFSDmN1YHm5FxyvG5qClA 52znlgu2LfUob/1PekiKaT/CydN6G/X1mpQBPCKPgd06HY+DndRyfjvVZUOVl9AMg1Rt ql7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:subject:cc:to:from:date:references :in-reply-to:message-id:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:user-agent:feedback-id:dkim-signature :dkim-signature; bh=h3JvgInG7Ve5RiimZ8l2qqQlcPTAgW2uluafkfImiMg=; fh=yV+A7dg0vSgHLNxdwugiPzc12vqWtsckNirADCaIHt0=; b=FHmicL3BMh51XKv1p4JRZmddhbrRcb/5jZ8CqsXB6xt9o8HbhTotOLYfo+V/DXd/oh XTFRRi9M8mBrHmctCur9phLTdIbXqAKtU87gP0hhovHEN6BwMpLtIc8uebzvj7IaYl4/ bwMLfD/h8TpUASJ54XXy5NPLZr/W7qPZFECdmInzBZYL6Y+DD/VZaquzPrtljQA9x2d8 7bN8PFbGxcNSFv0dscUFOrJuNgt+CddafzHUPG2h2XU9+Eg1g9F/FK/d1xmpxxOtqAAM nFnemvitrPZZlqdOBSjnWaM+luEcZIWoZsCH3oZPr2wWkZxaL7v6QdU2bSnh7fowva87 lq9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm1 header.b=J0ZzP+oE; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=kG2JZIXk; spf=pass (google.com: domain of linux-kernel+bounces-14292-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h33-20020a63f921000000b005cdc5c9d6a2si20065673pgi.576.2024.01.02.03.30.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 03:30:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14292-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@arndb.de header.s=fm1 header.b=J0ZzP+oE; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=kG2JZIXk; spf=pass (google.com: domain of linux-kernel+bounces-14292-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id BCF5BB20D9D for ; Tue, 2 Jan 2024 11:30:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 014EDEAE5; Tue, 2 Jan 2024 11:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b="J0ZzP+oE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kG2JZIXk" X-Original-To: linux-kernel@vger.kernel.org Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F6A1E555; Tue, 2 Jan 2024 11:30:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arndb.de Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 890A93200AD5; Tue, 2 Jan 2024 06:30:21 -0500 (EST) Received: from imap51 ([10.202.2.101]) by compute5.internal (MEProxy); Tue, 02 Jan 2024 06:30:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1704195021; x=1704281421; bh=h3JvgInG7Ve5RiimZ8l2qqQlcPTAgW2uluafkfImiMg=; b= J0ZzP+oENC5diPXzLG51ke/34Q4eGEG/BZdJpS2ydH8WJEaBlzGtV/fF2DFmQcM1 zFeZLkK3EnU26TOYyIIrE1PcDocj1PX7tLakPL++r2nsa9YZK0CuMfPM05VZev5p PwnHw3+SpjQkdLsx4kZnNesNS+xZ7MlJQeRrhxvXtv39q+Sgtxvrf4fc8B1YNh3H 9eXlnMj6CygiRY4Vpb105G1kDzQ2U2vPgUH4rt8iMzEbYCS67H+NguMLOexH80+y Am/+o+vqC6whc99P6hC+lFBFK6/oglggTWUDxW17eRPtmLjmDf7OFhfYXIdNEiAs Bi6OgB3KwcVWqEhXLLvH8g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1704195021; x= 1704281421; bh=h3JvgInG7Ve5RiimZ8l2qqQlcPTAgW2uluafkfImiMg=; b=k G2JZIXkFwCe70RI3PcafnLr3j8GF7AFn3rI2Re525QhVWVQBhtTnh5+bq4BU1Rox 2yHZaPE7w+NO79R6NB9AV84egZjUFHEKbkCBErjw9Tv6+zql9ImL//LBu7GVHmFA NtLGRyuqIcPYO6mq1iqHw3o+/SucXcsWcHi3snwlHJWpf1pRl68BeVUxWbNJAZqg P4ZspZysFW/TCn3o9hMiS/Fd92IGdqiFa8SY6CgZHmHcm25DoOzH/5LmtAkCkImx tK0ydany5PLkP+OQJvA+vUIQU+R74CZQVww2wKQrzz3vIV72/DtLyxGa5lHTOkaJ QmPQlmfQcgtZSRCdoxJXw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdegvddgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtgfesthhqredtreerjeenucfhrhhomhepfdet rhhnugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugesrghrnhgusgdruggvqeenucggtffrrg htthgvrhhnpeegfeejhedvledvffeijeeijeeivddvhfeliedvleevheejleetgedukedt gfejveenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grrhhnugesrghrnhgusgdruggv X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id F1587B6008D; Tue, 2 Jan 2024 06:30:19 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-1364-ga51d5fd3b7-fm-20231219.001-ga51d5fd3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <84d8e9d7-09ce-4781-8dfa-a74bb0955ae8@app.fastmail.com> In-Reply-To: References: <20231228122411.3189-1-maimon.sagi@gmail.com> Date: Tue, 02 Jan 2024 12:29:59 +0100 From: "Arnd Bergmann" To: "Sagi Maimon" Cc: "Richard Cochran" , "Andy Lutomirski" , datglx@linutronix.de, "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "H. Peter Anvin" , "Geert Uytterhoeven" , "Peter Zijlstra" , "Johannes Weiner" , "Sohil Mehta" , "Rick Edgecombe" , "Nhat Pham" , "Palmer Dabbelt" , "Kees Cook" , "Alexey Gladkov" , "Mark Rutland" , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Linux-Arch , Netdev Subject: Re: [PATCH v3] posix-timers: add multi_clock_gettime system call Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sun, Dec 31, 2023, at 17:00, Sagi Maimon wrote: > On Fri, Dec 29, 2023 at 5:27=E2=80=AFPM Arnd Bergmann = wrote: >> > +struct __ptp_multi_clock_get { >> > + unsigned int n_clocks; /* Desired number of clocks. */ >> > + unsigned int n_samples; /* Desired number of measurements per= clock. */ >> > + clockid_t clkid_arr[MULTI_PTP_MAX_CLOCKS]; /* list of clock I= Ds */ >> > + /* >> > + * Array of list of n_clocks clocks time samples n_samples ti= mes. >> > + */ >> > + struct __kernel_timespec ts[MULTI_PTP_MAX_SAMPLES][MULTI_PTP= _MAX_CLOCKS]; >> > +}; >> >> The fixed size arrays here seem to be an unnecessary limitation, >> both MULTI_PTP_MAX_SAMPLES and MULTI_PTP_MAX_CLOCKS are small >> enough that one can come up with scenarios where you would want >> a higher number, but at the same time the structure is already >> 808 bytes long, which is more than you'd normally want to put >> on the kernel stack, and which may take a significant time to >> copy to and from userspace. >> >> Since n_clocks and n_samples are always inputs to the syscall, >> you can just pass them as register arguments and use a dynamically >> sized array instead. >> > Both MULTI_PTP_MAX_SAMPLES and MULTI_PTP_MAX_CLOCKS are enough of any > usage we can think of, > But I think you are right, it is better to use a dynamically sized > array for future use, plus to use less stack memory. > On patch v4 a dynamically sized array will be used . > I leaving both MULTI_PTP_MAX_SAMPLES and MULTI_PTP_MAX_CLOCKS but > increasing their values, since there should be some limitation. I think having an implementation specific limit in the kernel is fine, but it would be nice to hardcode that limit in the API. If both clkidarr[] and ts[] are passed as pointer arguments in registers, they can be arbitrarily long in the API and still have a documented maximum that we can extend in the future without changing the interface. >> It's not clear to me what you gain from having the n_samples >> argument over just calling the syscall repeatedly. Does >> this offer a benefit for accuracy or is this just meant to >> avoid syscall overhead. > It is mainly to avoid syscall overhead which also slightly > improve the accuracy. This is not a big deal as far as I'm concerned, but it would be nice to back this up with some numbers if you think it's worthwhile, as my impression is that the effect is barely measurable: my guess would be that the syscall overhead is always much less than the cost for the hardware access. >> On the other hand, this will still give less accuracy than the >> getcrosststamp() callback with ioctl(PTP_SYS_OFFSET_PRECISE), >> so either the last bit of accuracy isn't all that important, >> or you need to refine the interface to actually be an >> improvement over the chardev. >> > I don't understand this comment, please explain. > The ioctl(PTP_SYS_OFFSET_PRECISE) is one specific case that can be > done by multi_clock_gettime syscall (which cover many more cases) > Plus the ioctl(PTP_SYS_OFFSET_PRECISE) works only on drivers that > support this feature. My point here is that on drivers that do support PTP_SYS_OFFSET_PRECISE, the extra accuracy should be maintained by the new interface, ideally in a way that does not have any other downsides. I think Andy's suggestion of exposing time offsets instead of absolute times would actually achieve that: If the interface is changed to return the offset against CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW or CLOCK_BOOTTIME (not sure what is best here), then the new syscall can use getcrosststamp() where supported for the best results or fall back to gettimex64() or gettime64() otherwise to provide a consistent user interface. Returning an offset would also allow easily calculating an average over multiple calls in the kernel, instead of returning a two-dimensional array. Arnd