From nobody Wed Jan 08 23:07:47 2025 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YT3VJ1jB7z5kB0q for ; Wed, 08 Jan 2025 23:07:52 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YT3VH6CsNz4mkb for ; Wed, 8 Jan 2025 23:07:51 +0000 (UTC) (envelope-from markjdb@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-844e55a981dso9927439f.3 for ; Wed, 08 Jan 2025 15:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736377671; x=1736982471; darn=freebsd.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=5CjXydmzIn+pXch1t0g/2W8xP0tvEj8l66Rh/IXCVz4=; b=jcYxQXGFVsAWOUpiZ4vJzyY7BgbhhxIYLHO2c+VMrbRp4gXKivq1o71xuwbUO6tcpM /uNZjXeYUiPpmOqdVk7URM9nn8B9Q89ovPUaJRH8NmD//gjbmQCgaQHDkrQQRQG3hNcb K72I+eIp4AKuCwxuwL1BEVVKk0pZ+BG8263RtRC/itNUIxDIxiFT1I/BFRGD2bObtWQd A8zs3PWk4JKMxqXOiRlpgMDfUtPWb6LBuI2RPbepXYR8pxxSQO8ipJeMr1QFj/JIem4W 4u1w6YRuZEHYpSgPTPVeHhrZ+gwGK7gRIoH3TkiYgajsZEc9kUXPChnQB5lp0aCMpcG6 fRPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736377671; x=1736982471; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5CjXydmzIn+pXch1t0g/2W8xP0tvEj8l66Rh/IXCVz4=; b=iklWBR2Bs02GF4lMz9vMgtF6xatAiVt6oVx3wNMFvt3vteRjAQy+3/w+xCSL1fMq/R vbeNZrFiqUheRvXNzghGo6tUhsCyfaPQW+4N+a6ufiVSJObeqp4n9iVvkkbXfWcmRHVu G05U9W52mDQ6QdrDT6Jh60IWudqztdqck2GdUjtkc4kmNftDBQ/1y5qBGciVf6ZzWJJl 3/NBZyY7OttEvMmR/p+he/ryletv3HT6RvPmf7nalJSINL+Ix1N1gxfgeWdOKyypETs8 PFsY7NEOtJ0MhMN/VouqJ97M0GacOoIUl3kmcZFOBo+DExUR+jewo1ErhelUdpIxRe9v JfmA== X-Gm-Message-State: AOJu0Yz4B/stLX8hRlJ0YIRFmzkhcBrKnxFbs+me2yJVgDLYiLArihwl 1f7AxJofRB5gII9pVxsZc3FeHsxSIDycpq8Jg5ZY/J+ALTbBklOQWHyY1A== X-Gm-Gg: ASbGncvuWO5dGbUeLvVsN1bF/QEjCbppjDho1GTf6jzOU2ipnG6ZCiWLh2WSZhqO29w wF6twCto8/RQ/+uezIzk7qk6mF4H5lGzSZD/YMeJDRtu9B//kBInymIYzm82XiH07V18Lfnvemk oM1RkXousVklvXTXCsSGOJOQEmcNqWFOj9qtoswIPdXZr9O0LAL4olmLqBtM/Th99Vmr1eslKwT 6hFSremOnDzBwOtXrvTwYo0KCJsXquuGlgvHTCLE2sX6zDkNNdNUQ6rnbW60McDNiZR6Ec= X-Google-Smtp-Source: AGHT+IEHQ0otfPvIkyb6ARSaxzCM3PvFFG0kZTrINwXTWoS8/bhG5/bC4MZHT+lkSneWbxB6xRZEIA== X-Received: by 2002:a05:6e02:1787:b0:3ab:4bea:df97 with SMTP id e9e14a558f8ab-3ce3a9d451emr33392605ab.23.1736377670699; Wed, 08 Jan 2025 15:07:50 -0800 (PST) Received: from nuc (192-0-220-237.cpe.teksavvy.com. [192.0.220.237]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ea1b71763asm10703173.103.2025.01.08.15.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 15:07:50 -0800 (PST) Date: Wed, 8 Jan 2025 18:07:47 -0500 From: Mark Johnston To: Konstantin Belousov Cc: freebsd-hackers@freebsd.org Subject: Re: widening ticks Message-ID: References: List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4YT3VH6CsNz4mkb X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] On Thu, Jan 09, 2025 at 12:18:48AM +0200, Konstantin Belousov wrote: > On Wed, Jan 08, 2025 at 04:31:16PM -0500, Mark Johnston wrote: > > The global "ticks" variable counts hardclock ticks, it's widely used in > > the kernel for low-precision timekeeping. The linuxkpi provides a very > > similar variable, "jiffies", but there's an incompatibility: the former > > is a signed int and the latter is an unsigned long. It's not > > particularly easy to paper over this difference, which has been > > responsible for some nasty bugs, and modifying drivers to store the > > jiffies value in a signed int is error-prone and a maintenance burden > > that the linuxkpi is supposed to avoid. > > > > It would be nice to provide a compatible implementation of jiffies. I > > can see a few approaches: > > - Define a 64-bit ticks variable, say ticks64, and make hardclock() > > update both ticks and ticks64. Then #define jiffies ticks64 on 64-bit > > platforms. This is the simplest to implement, but it adds extra work > > to hardclock() and is somewhat ugly. > > - Make ticks an int64_t or a long and convert our native code > > accordingly. This is cleaner but requires a lot of auditing to avoid > > introducing bugs, though perhaps some code could be left unmodified, > > implicitly truncating the value to an int. For example I think > > sched_pctcpu_update() is fine. I've gotten an amd64 kernel to compile > > and boot with this change, but it's hard to be confident in it. This > > approach also has the potential downside of bloating structures that > > store a ticks value, and it can't be MFCed. > > - Introduce a 64-bit ticks variable, ticks64, and > > #define ticks ((int)ticks64). This requires renaming any struct > > fields and local vars named "ticks", of which there's a decent number, > > but that can be done fairly mechanically. > > > > Is there another solution which avoids these pitfalls? If not, should > > we go ahead with one of these approaches? If so, which one? > > You cannot do this in C, but can in asm: > .data > .globl ticksl, ticks > .type ticksl, @object > .type ticks, @object > ticksl: .quad > .size ticksl, 8 > ticks =ticksl /* for little-endian */ > /* ticks =ticksl + 4 for big-endian */ > .size ticks, 4 > > > Then update only ticksl in the hardclock(). I implemented your suggestion here: https://reviews.freebsd.org/D48383