Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp5899304rdb; Mon, 1 Jan 2024 00:45:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyMuAmEGwoXjVpwrcAPLSSchGHEu0ksp/4rtBrL6IrrUVRodoOZpCQv/pSn/DGBNfD+YC3 X-Received: by 2002:a50:c31d:0:b0:556:c70:8266 with SMTP id a29-20020a50c31d000000b005560c708266mr1814060edb.20.1704098720952; Mon, 01 Jan 2024 00:45:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704098720; cv=none; d=google.com; s=arc-20160816; b=fiDBTEp+OZQy+P/Xcop4THO2Qx7VcjOaOkIxDXGUScUcdmy+UAETO0LDQJqSi42ayX cmItXRg+lLK5ln1o9Av/6Dq0x+0R8m24Z0e9hpSvKKg2DrMudSBZhmQFsRyJdJ0gkdSY iIPlOi618iCKfktsTrAjTsSGB8qL3lI1cs/62K+746gkmtS89Y17zy9Iyxbbc42AwWBz lJvipgVGa7TAHHo2FlhP7rlJdJBcCciaF8pupWKb5QC9bWEbfpKf1zg5A7IlrcLT6xbg 6TT7EKJGNTzDNZhK1tzGuhaXwsZ+43b2tn9w3M98MZgoiMTNdamcL2vzdQt/P17p/KJM OVpQ== 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=zMd3337IrmQ0bZURCWuZgY7ObmtziyKnBbbsdShesQA=; fh=eeAwZaHRyXyZSzMLG+kO1wSrO0ZYySLWhKijHy6pPp8=; b=OoTE87dWyZiSrPt1geEdt0K1CbSVh8911HMs0b1aWBZZDu99/Uuo42L0By081UGLaD gM8VE1GRQXmikOzmJcX5jocLO6FAbSx8ytWW1F+L6G0CA0uBhYLYOtsqWOblrj8eiYMY gcA2l8ZY+P8uuUGba5U6OJ2UbrtMw8mZIwCgKP8eQEsPV7AbfbfjgN53an2RnbYnBH+T en+Uc8WSrLvPIKMX1PjXVy7YwEQraPaE89vX6x4BGK3yGrvtBHBGqB9vJLFjDFI+3qt6 LEWSlK7CiDNJglkhL4DPPvW1BJJI4BniF/Ml9apX+6NBF+icFqP9hEoArR6L/IhaeKna 9T3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=P13B6y0L; spf=pass (google.com: domain of linux-kernel+bounces-13840-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13840-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o25-20020a509b19000000b0055326210f0csi10089636edi.637.2024.01.01.00.45.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jan 2024 00:45:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13840-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=P13B6y0L; spf=pass (google.com: domain of linux-kernel+bounces-13840-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13840-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id A31BC1F227B0 for ; Mon, 1 Jan 2024 08:45:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF1E01FA6; Mon, 1 Jan 2024 08:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P13B6y0L" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (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 B80A76107; Mon, 1 Jan 2024 08:45:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-67f911e9ac4so71978356d6.3; Mon, 01 Jan 2024 00:45:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704098706; x=1704703506; 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=zMd3337IrmQ0bZURCWuZgY7ObmtziyKnBbbsdShesQA=; b=P13B6y0L/VLM+WrzGnbvTTHsbtYiNQbkOZp9Qmd50bvisyBta/mdpID43uJL60f7O1 UwsKhBl30I5DkPE3Z4liNcbHYLKeEYB5jdun3naPYQPi0e9lUOKGGWM1RLbUITJ7j/6G X5uyf6yEA9JFqfWSdr/OU5B6Ck2COtkska5RVd/nYyNY5oaDCVwdWcqWsb5bivJ/rUlH 4slAIRo47yNLUy1mpu1JmCs6YeNON0N3yncLoNI7MK2W+kG9rlWIxaWAabJwUHVrNjB3 +elCjSxp0wVaDEHkAlaWOVzPACnon22dATDrh7tcV6ReGHB+bESRzheo+zSzsdnrFMgi t8iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704098706; x=1704703506; 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=zMd3337IrmQ0bZURCWuZgY7ObmtziyKnBbbsdShesQA=; b=OBu5zuLNfVN9LnAzHkqPC2dbm61GAmjRPWn/P9R4hnwFIuBn/y9fSKaRN61w3fVzwN ilEbyarkrLqV7qDQgGZI+wCJLt2q2zBcmlZhXn2rLgkeqn8LYzS4RqEizPJcwWYuIfYS JBllE2yD7VkunfhVomZr4YvazZtIUoUN+A+/F5QPQ9jutqd3VvXrAqyj5ry9scK0GoHn rQz6JOUowo9PmIGZnMA0/lCQmEGDZOTM6UPgSb/b2hiofn3uom/JvL7DddmjZkQ2ivvI /H7+YSc58LB9N1pMdpGtpRZNtrb+cnKdLtMYLPnC4JFwfpTH9PZzQvfnNoNJzHgFa8YB P6Yw== X-Gm-Message-State: AOJu0Yyx3e9nhxIn/A8NTOuS2mqgb+MgwP5vTOvZvvTAUvMSDg+kxePM cgw2jp3qyQpr7ff2f97aA2BHRd4VPF2JzZelMg0= X-Received: by 2002:a0c:ec05:0:b0:67f:b9a4:80e4 with SMTP id y5-20020a0cec05000000b0067fb9a480e4mr16658116qvo.39.1704098706637; Mon, 01 Jan 2024 00:45:06 -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: From: Sagi Maimon Date: Mon, 1 Jan 2024 10:44:55 +0200 Message-ID: Subject: Re: [PATCH v4] posix-timers: add multi_clock_gettime system call To: Andy Lutomirski Cc: richardcochran@gmail.com, 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 11:10=E2=80=AFPM Andy Lutomirski = wrote: > > 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 m= easure > > the offset between multiple clocks, from variety of types: PHC, virtual= PHC > > and various system clocks (CLOCK_REALTIME, CLOCK_MONOTONIC, etc). > > The offset includes the total time that the driver needs to read the cl= ock > > timestamp. Andy Thank you for your notes. > > Knowing this offset sounds quite nice, but... > > > > > New system call allows the reading of a list of clocks - up to PTP_MAX_= CLOCKS. > > 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? > It can be done, but I prefer to leave it generic and consistent with other time system calls. In most cases the offset calculation is done in user space application > > + 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 __kerne= l_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. You are correct, there are some PHCs on the same NIC (each per port) that share the same HW counter/clock. In that case it is slightly better to do the offset calculation in the NIC driver code, but that requires changes in each NIC driver's code. The main thing is that the multi_clock_gettime system call is a generic solution, it covers that case among other cases, for example sync between two PHCs on different NICs.