Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp641221rdb; Thu, 19 Oct 2023 15:01:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSM3RUJnUkUeR5wW7rf+YlfrB7ZzEduKmRVvPbNdu+lTh9k4meJRqMsFPTTo0fT71Dbb3t X-Received: by 2002:a17:903:186:b0:1b6:bced:1dc2 with SMTP id z6-20020a170903018600b001b6bced1dc2mr201138plg.0.1697752867923; Thu, 19 Oct 2023 15:01:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697752867; cv=none; d=google.com; s=arc-20160816; b=ZsSbgOkZcBuKx5Y59o4GjpzB9nLPAUsdE00jyIoknJ4E4zlxRynz6PQ5KsaUK+iEvK bo4UOjibv13nFeLj4k6JLMCFzqnaKUEjcKuSPUbdykS2WasR996GkMJ63CtUbyI6fsqS yI6YOW+aG19hssF545XLQlsFCMOtoDqUywK6GphI30NqsIviGXDlWRq9enkVddlBTMfP /4wrOOxj04qvyjqOjP8yq2G4yICPD3WsGxFd2w573uRhZRHAmZTaDSbriHQLPZII5hHg mSdzW/mZmdN9QeB+/PEy5TF9krIzV7UvAssIj6lTF81Dhma5z2IBJ1Ckpt4cm/2tMRzC ceBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:in-reply-to:subject :cc:to:dkim-signature:dkim-signature:from; bh=o2kQGRnjkpW8NV5UEGIjy6i2Lw5zLDk1wI9xtQ0It5Y=; fh=U6hFu4jo67iO/mhEHIVGLbUOJwOKGVYIFxoNnrG3cgQ=; b=BpYnw03jVBApyaEYTI/eLqwa0H+ui2Hm/fvbINDv/kdEaJfqIfIaU5lnLlv1/zB/Kv j6UE6M6TrefD73RxnL6UDzvNAwBF64l4h/hqZDF4Lxv+dvPbXgzZlru9xP2IUOlupAOo qAZh+E9jUR8ICFWJewQO6O0G1HRXmYEMd/DMcFDhla5imm04m2ayWEeXkaLJ/rshdnnN 6Zl73u3O2nAltrkHYl6VazKTN2YAUHH0UIdIcEn7kkiGWYHOfBpt2dATLbPDX9/uchYd uUuf00RJPwRRnCX1Zthvm+C8JLqT0ux/Aqy9ubsFfR9cOZ6g09c8ZRmQeLm20kFc/LIR 0I7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OFtLhVmd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=WY4r1ywq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id j16-20020a170902759000b001c6223e5675si383263pll.188.2023.10.19.15.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 15:01:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OFtLhVmd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=WY4r1ywq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3210C819D734; Thu, 19 Oct 2023 15:01:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346610AbjJSWAv (ORCPT + 99 others); Thu, 19 Oct 2023 18:00:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235556AbjJSWAt (ORCPT ); Thu, 19 Oct 2023 18:00:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D683115; Thu, 19 Oct 2023 15:00:46 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697752844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=o2kQGRnjkpW8NV5UEGIjy6i2Lw5zLDk1wI9xtQ0It5Y=; b=OFtLhVmdGAGajfdsQU77o4un/tVAdYcM7cfwt20W9su0nN9zUiglcL5C4pDEb4q88MJzLO x5HDKpnT1/1lsSU8vKySCq1RLS7VJye3ei4+VMtw0uCD0w7qgUgZRlBSUcaicBnbHq4OQM mqC4nMnW3ootEGH3Z7j1ETk8ZUrXdgmgAMC4DzuoxhllzQY4nnoXxM5gbzdAXXNXSWD5Sa lHnIfI/VC1YvapORPfXS8oxP8OeBmd70rwTvUJoTfYU3S+x3sfwVydywAwIgsgZgP0p9N5 3FVR3vXv1ON8t+fn6QllxjFsOKixj4rzsRVi/dN/W6MmEfKFJhO4iRcGMvCxFA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697752844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=o2kQGRnjkpW8NV5UEGIjy6i2Lw5zLDk1wI9xtQ0It5Y=; b=WY4r1ywqpIX7pjSgKhtd/YMTG9q7nuDraudwOpgvLzXDgf0mNyLuwtbpuWmgdtYAMHYJV3 PfofEjkkaGKIMBCg== To: Jeff Layton , Linus Torvalds , Alexander Viro , Christian Brauner , John Stultz , Stephen Boyd , Chandan Babu R , "Darrick J. Wong" , Dave Chinner , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Amir Goldstein , Jan Kara , David Howells Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, Jeff Layton Subject: Re: [PATCH RFC 2/9] timekeeping: new interfaces for multigrain timestamp handing In-Reply-To: <20231018-mgtime-v1-2-4a7a97b1f482@kernel.org> Date: Fri, 20 Oct 2023 00:00:43 +0200 Message-ID: <87o7gu2rxw.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 15:01:04 -0700 (PDT) Jeff! On Wed, Oct 18 2023 at 13:41, Jeff Layton wrote: > +void ktime_get_mg_fine_ts64(struct timespec64 *ts) > +{ > + struct timekeeper *tk = &tk_core.timekeeper; > + unsigned long flags; > + u32 nsecs; > + > + WARN_ON(timekeeping_suspended); > + > + raw_spin_lock_irqsave(&timekeeper_lock, flags); > + write_seqcount_begin(&tk_core.seq); Depending on the usage scenario, this will end up as a scalability issue which affects _all_ of timekeeping. The usage of timekeeper_lock and the sequence count has been carefully crafted to be as non-contended as possible. We went a great length to optimize that because the ktime_get*() functions are really hotpath all over the place. Exposing such an interface which wreckages that is a recipe for disaster down the road. It might be a non-issue today, but once we hit the bottleneck of that global lock, we are up the creek without a paddle. Well not really, but all we can do then is fall back to ktime_get_real(). So let me ask the obvious question: Why don't we do that right away? Many moons ago when we added ktime_get_real_coarse() the main reason was that reading the time from the underlying hardware was insanely expensive. Many moons later this is not true anymore, except for the stupid case where the BIOS wreckaged the TSC, but that's a hopeless case for performance no matter what. Optimizing for that would be beyond stupid. I'm well aware that ktime_get_real_coarse() is still faster than ktime_get_real() in micro-benchmarks, i.e. 5ns vs. 15ns on the four years old laptop I'm writing this. Many moons ago it was in the ballpark of 40ns vs. 5us due to TSC being useless and even TSC read was way more expensive (factor 8-10x IIRC) in comparison. That really mattered for FS, but does todays overhead still make a difference in the real FS use case scenario? I'm not in the position of running meaningful FS benchmarks to analyze that, but I think the delta between ktime_get_real_coarse() and ktime_get_real() on contemporary hardware is small enough that it justifies this question. The point is that both functions have pretty much the same D-cache pattern because they access the same data in the very same cacheline. The only difference is the actual TSC read and the extra conversion, but that's it. The TSC read has been massively optimized by the CPU vendors. I know that the ARM64 counter has been optimized too, though I have no idea about PPC64 and S390, but I would be truly surprised if they didn't optimize the hell out of it because time read is really used heavily both in kernel and user space. Does anyone have numbers on contemporary hardware to shed some light on that in the context of FS and the problem at hand? Thanks, tglx