Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp5705107rdb; Sun, 31 Dec 2023 13:10:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IEB0bH2vtKFsgo8tx2V69UMLV6DJxGIq3Q5McAB1HmQEVqZq3TMlTcgeYyM1zRYbAi0aG8N X-Received: by 2002:a05:6e02:1baf:b0:35f:f11a:4655 with SMTP id n15-20020a056e021baf00b0035ff11a4655mr23330913ili.71.1704057035103; Sun, 31 Dec 2023 13:10:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704057035; cv=none; d=google.com; s=arc-20160816; b=hThs0iCi3PWwugGBahryMrOzoi2/xY1JGoK8NGdTbDS6xr8jniug7rjIC4uJIYiMv/ p54fNDlE+e0RJlN3Lzr4PKIe+7CjAh3O4phpGnDPl5GygRWK/jAh7HU4Tw0SdpRJOC3H Iz70vsLDRaxGPsAqTeVPae/K6zfcqh4y2MsbQT2ljftWPL6c0dyXdYs9ajgzJQOLlaq8 2NG5bp5T68P/z65RacZTMiUF8fCDCqLlrglv67lihgxFfP+wu4pCgHzRYHt5M1gn8JBy IYHaqw6uM5H+bdxCNKf4Wf+JkYxYjL33i3koyI4AeiDSm0jDRkDG+OMzut/cmiexeI1N aX5g== ARC-Message-Signature: i=1; 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=xATRtJexAbxItw8WxWagC6vdDtpGQ0/if3EPbxquzf4=; fh=6fgsl4qVp1Z51Ni3Kn+SftD8I97XcFZ4kKBN+QJQaGs=; b=MI/Hp2FiWY93MDPTawuWieKC87M+s+Q/oI0oyR8TbPZ0eJsqUK+l+k1/h9rRTfvZV+ p4c1sjO6qZWcu+za+xK3uToeMlnuCDp5lQWNjamPVi6lF6ETJPMJ7McG7NMYcZs7hmUu dWtfw+32nzy8vwIi2ChfEjxUO8+DbSxFn9NPv6ebTKd32wSX9CAJVuDP0I9Y0xXKyIfK lIdCVS3KZ3733i2XUx4tRcGhnn+56izfIxcXyv8dcL+qBJmyQcaDjZOFyUrsPNgHkDmu 2RVNUpd9zzZDafO/jDFm1o6xFcIYe8eWdjAkq8G30ApbASlQrIW07t3qqC0MChxKRBMI 8Zvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="N/BGgOp4"; spf=pass (google.com: domain of linux-kernel+bounces-13786-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id v10-20020a056a00148a00b006d09bca867fsi12747618pfu.121.2023.12.31.13.10.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 13:10:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13786-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="N/BGgOp4"; spf=pass (google.com: domain of linux-kernel+bounces-13786-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 985EC28175F for ; Sun, 31 Dec 2023 21:10:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA348BE66; Sun, 31 Dec 2023 21:10:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N/BGgOp4" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 008CEBA3F for ; Sun, 31 Dec 2023 21:10:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC09FC433CB for ; Sun, 31 Dec 2023 21:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704057025; bh=ADVGoneIdstsKr16ibvhATBX2Jiv5nuTwiT5ZmAB7uc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=N/BGgOp4vDBtl27a9MFf6vjYvackawX9UlBVzXl3vwd1QN11AGKDCuHGmXLOKieRn 74VnzoVMBf/PnMD7ihBGeqqSNVQ1y/ylz0gQjlVB3ewREmn0iG11g1OYRGljxKqdxm RaVSfODio6dKCw/krph7VRIwBZQM3KuAZIOEU5bO25DuQcGFYFsyEdUzp4LAhxKb6Y +kPCflFBjflxbfe4TEr4umM/gH+0cMvkPPU8KJ3d/CoCCZkQ5uyp6VQ/QOa/sFdNVU E270JNpdb8/1hktYU6K6/hLXFIKufZwxcvBTDFNFPsV/1zisy2iXmJwMK+L8cSoC5s qnZHsQPycTJgg== Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6808c3938afso19440496d6.1 for ; Sun, 31 Dec 2023 13:10:25 -0800 (PST) X-Gm-Message-State: AOJu0YyvZKPCi+dygGdWNiXguH2ANtdarwwWx6NpS5iZ7AS3EPyuocdP Fo0p9XG4Mb1lHAjwEHa+uCX41HRY8TUXy73Rp6lp5M/9bgD1 X-Received: by 2002:a05:620a:22d:b0:781:e26:a513 with SMTP id u13-20020a05620a022d00b007810e26a513mr17770518qkm.14.1704057004460; Sun, 31 Dec 2023 13:10:04 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231231170721.3381-1-maimon.sagi@gmail.com> In-Reply-To: <20231231170721.3381-1-maimon.sagi@gmail.com> From: Andy Lutomirski Date: Sun, 31 Dec 2023 13:09:52 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4] posix-timers: add multi_clock_gettime system call To: Sagi Maimon Cc: richardcochran@gmail.com, luto@kernel.org, datglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, arnd@arndb.de, geert@linux-m68k.org, peterz@infradead.org, hannes@cmpxchg.org, sohil.mehta@intel.com, rick.p.edgecombe@intel.com, nphamcs@gmail.com, palmer@sifive.com, keescook@chromium.org, legion@kernel.org, mark.rutland@arm.com, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Dec 31, 2023 at 9:07=E2=80=AFAM Sagi Maimon = wrote: > > Some user space applications need to read some clocks. > Each read requires moving from user space to kernel space. > The syscall overhead causes unpredictable delay between N clocks reads > Removing this delay causes better synchronization between N clocks. > > Introduce a new system call multi_clock_gettime, which can be used to mea= sure > the offset between multiple clocks, from variety of types: PHC, virtual P= HC > and various system clocks (CLOCK_REALTIME, CLOCK_MONOTONIC, etc). > The offset includes the total time that the driver needs to read the cloc= k > timestamp. Knowing this offset sounds quite nice, but... > > New system call allows the reading of a list of clocks - up to PTP_MAX_CL= OCKS. > Supported clocks IDs: PHC, virtual PHC and various system clocks. > Up to PTP_MAX_SAMPLES times (per clock) in a single system call read. > The system call returns n_clocks timestamps for each measurement: > - clock 0 timestamp > - ... > - clock n timestamp Could this instead be arranged to read the actual, exact offset? > + kernel_tp =3D kernel_tp_base; > + for (j =3D 0; j < n_samples; j++) { > + for (i =3D 0; i < n_clocks; i++) { > + if (put_timespec64(kernel_tp++, (struct __kernel_= timespec __user *) > + &ptp_multi_clk_get->ts[j][i])) { > + error =3D -EFAULT; > + goto out; > + } > + } > + } There are several pairs of clocks that tick at precisely same rate (and use the same underlying hardware clock), and the offset could be computed exactly instead of doing this noisy loop that is merely somewhat less bad than what user code could do all by itself.