Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp201224lqb; Thu, 14 Mar 2024 09:00:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVkxzfOfcAbTcpsmqKUSNRvvfA79RhoKRACVO5WiMp1Ua03xbc5u6nujUax48BJ+ztQIwwd4KdzrwFU9Fwr1BI8DJlS/4dRrYOwG+nSFw== X-Google-Smtp-Source: AGHT+IH9cPlOapooWRJvch161tEcUX+CkB6J3Smk9Ee8Ymo3baCwmUc0EevTLWFgTS9O6Ae0aTrV X-Received: by 2002:a17:903:2289:b0:1dd:eba:e744 with SMTP id b9-20020a170903228900b001dd0ebae744mr2847360plh.53.1710432004204; Thu, 14 Mar 2024 09:00:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710432004; cv=pass; d=google.com; s=arc-20160816; b=o9nhgiyh3RhEn8kKRzmcJhQUKcb2ogOB7H/0ExmqyI/vv1TcCkYsmaF0Fys7flF1hM ciP0X7TJmbyZ0HzDAQMK1DcBHOBYZO9WJFPNqSUJqNksnr0LeyyN5zK8mfF6jKZf53HB JLRSMlhYMyqzSZB6IuymxN5hHwHxo3NHASOPIQTw/eD262yTWE/iggkC6JhfBH6dXKjB UL9Ty+DVZS6r3raWaRPHfY/fb9fzQdBpqA1ojDXVfSKxXteJ+UgVZSiWzm6ddX4Eufis cWIvG0CvVy00mbTTzxB6Jzbm9cW+hxcYCSN4T4DrjcsF4QF4E7VnB1pwF+Q2CgFNnLHU m2dQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date; bh=/QFLdRZJf31if+GCi3l4wYzs/yO2UEJfGu8NJqst8GA=; fh=ZntJ/K1YnOVY48KEtYyX03FELBhko+uAvAm4fCoRvWg=; b=Y+WjqKdmYfpzKJS91QojI0DeoirqkCO0zFsme+jVyBtS38dqoDyDvbnh4X27Kjrujl IhrNpMU4Ueru/xy8+DuAZ3/+PkesGUKYLuY9E/a3ZHwrd4c2tYBmxCRKqcPf/bOtLf1F Gq/2/vCEBa+U0JyoHZIPVSeYlKkXytcmK+4OaeX54nfZ25QDkhZCk6A78F2r1lq4OFM3 89Zq4tSbaLssUhCG41dsrXT5NxRmRfEaaKjInOlJ1RPzEw2MWvPZpg1O2O4gCM1nm8nr E5owPszwtpD9mlnQv9Bdv2NVgBQVxTeKbELBd/2ew4y0S72ujurWxfdwBDSqBsm/rKQX 4voA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-103537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103537-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y23-20020a17090264d700b001dda14c445bsi1663378pli.569.2024.03.14.09.00.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 09:00:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-103537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-103537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103537-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DDABF284746 for ; Thu, 14 Mar 2024 16:00:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D669973505; Thu, 14 Mar 2024 15:59:53 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D63116EB74; Thu, 14 Mar 2024 15:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710431993; cv=none; b=fRes4FBxBIt0NkAdOboqNDGwPsOiYzisq+WDKBxVqZIVvKetFsUtsSqXNG4WZ7fk/EVEGiSEmdlBBFe/n1DwFbKZeWrJg1mbuWRsce6HnpZE3Lzyh6oKvrws1kBPfAytnSitliVDkN26W3t7BiSKac/iGgkMR+i75MleB3ep0Mo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710431993; c=relaxed/simple; bh=okaw4O3R57c6tEMT0TJSs1UtnZZCStffxFfDr2xlyHw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aeNHzxxsVnfkXCjyuZrVl9Yz4ZPzdStJRtSAp7dmCJ1Du41C1qBhU6mOltq7qPkTa/O0eJyh8Q6AeHY3mBOTCOUh3ghvnlLSdVXRlMZdXEA0ZLuBFj09hKbZSFheR37EzmMe2h0yZBVIxmPMxTwr7lESVOgnFc4oHEGSbu0jx7M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CCA7E1007; Thu, 14 Mar 2024 09:00:25 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.69.235]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 281FB3F762; Thu, 14 Mar 2024 08:59:45 -0700 (PDT) Date: Thu, 14 Mar 2024 15:59:39 +0000 From: Mark Rutland To: Sagi Maimon Cc: Thomas Gleixner , 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, mszeredi@redhat.com, casey@schaufler-ca.com, reibax@gmail.com, davem@davemloft.net, brauner@kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH v7] posix-timers: add clock_compare system call Message-ID: References: <20240314090540.14091-1-maimon.sagi@gmail.com> <87a5n1m5j1.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Mar 14, 2024 at 02:19:39PM +0200, Sagi Maimon wrote: > On Thu, Mar 14, 2024 at 1:12 PM Thomas Gleixner wrote: > > On Thu, Mar 14 2024 at 11:05, Sagi Maimon wrote: > > > + if (crosstime_support_a) { > > > + ktime_a = ktime_sub(xtstamp_a2.device, xtstamp_a1.device); > > > + ts_offs_err = ktime_divns(ktime_a, 2); > > > + ktime_a = ktime_add_ns(xtstamp_a1.device, (u64)ts_offs_err); > > > + ts_a1 = ktime_to_timespec64(ktime_a); > > > > This is just wrong. > > > > read(a1); > > read(b); > > read(a2); > > > > You _CANNOT_ assume that (a1 + ((a2 - a1) / 2) is anywhere close to the > > point in time where 'b' is read. This code is preemtible and > > interruptible. I explained this to you before. > > > > Your explanation in the comment above the function is just wishful > > thinking. > > > you explained it before, but still it is better then two consecutive > user space calls which are also preemptible > and the userspace to kernel context switch time is added. How much "better" is that in reality? The time for a user<->kernel transition should be trivial relative to the time a task spends not running after having been preempted. Either: (a) Your userspace application can handle the arbitrary delta resulting from a preemption, in which case the trivial cost shouldn't matter. i.e. this patch *is not necessary* to solve your problem. (b) Your userspace application cannot handle the arbitrary delta resulting from a preemption, in which case you need to do something to handle that, which you haven't described at all. i.e. with the information you have provided so far, this patch is *insufficient* to solve your problem. > > > + * In other cases: Read clock_a twice (before, and after reading clock_b) and > > > + * average these times – to be as close as possible to the time we read clock_b. > > > > Can you please sit down and provide a precise technical description of > > the problem you are trying to solve and explain your proposed solution > > at the conceptual level instead of throwing out random implementations > > every few days? 100% agreed. Please, explain the actual problem you are solving here. What *specifically* are you trying to do in userspace with these values? "Synchronization" is too vague a description. Making what is already the best case *marginally better* without handling the common and worst cases is a waste of time. It doesn't actually solve the problem, and it misleads people into thinknig that a problem is solved when it is not. Mark.