From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796459291; b=a+Xkbc69q5lUBUHCusVNW6Dal6WCnevHuUuQ7K8/t76EaIr1CXb93+DylOeeMYYS4re4 hvpNZGvyXjlUJW8BSemH56cWj3TpKesMKd5IWEfvqGCkxn1DHTyFq1/gbiiE/IDq6bS86 YztnifUrxXWe5OXUqJv0Wv1FFBVqtiAxXXC5qZIyD4VALoKBnHmUOuyF1B3WJXZ6tviYy e2jukaxjLKjsLWQ2TGE22dg27h/KVNlmCgIUkAzg/ERoUWjNeF1PefQsbbUelZ3i6ati+ 9LhXpixpUv//+BSPlY2MEAz8DdJbTHWXH65Gr44WcDYOLKQ44OJ3tRzEl6IcyoAFknw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459291; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=3oaSbQgCCtqKXVobDZoKmn+644A7z+sfQjThpL1iEWQ=; b=BNt1alF1EDM1xMLAq0mxrd2ig0xp42rh34qjH5Lhj7wXWpU2in7pbin+K2oUbj9r8odg JibEmdfYl4yGc6UcOxHTVJmviNItlYiUbQflfwuCDF7kntm51/ESxLEjAseQXRXFGy5kU EG6NS9stkSqjCTQHK9erPl2yf5+iMkKsOWs7tsz/NnKo8BwuYgCGkwg7RKzoUASJA5SA4 AUyWmQsR3oShk/h9TMQMf5GAGqAOW3jUYdb1njOkwcmZlD2Hk9F4fjfW9+AEsa0oZkOMS HRY6UTJK5AgBJ38OxEgBl66ZQM1m/ztpgSzvqPtVjZIeYmV7Ma52DfG4XP1tELoognQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=r27W+ktj; arc=none smtp.remote-ip=209.85.128.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8B12606A322 for ; Sat, 5 Dec 2026 08:28:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E8B12606A322 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=r27W+ktj Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4ba013938d7so14146285e9.2 for ; Sat, 05 Dec 2026 00:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796459289; x=1797064089; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3oaSbQgCCtqKXVobDZoKmn+644A7z+sfQjThpL1iEWQ=; b=r27W+ktjHHAA1Op17Kj6Upijz596FPlx2kR6WGT7PQ3yZ6swOLZlpoPTh5efVxXAcD yQrBpz3C3wYeMcSWfmS2Ior06qRPyJ7G6jCLnFAYvG84kXOB73w+pbzX8/Ipkjtnhhpg ZOT8jpuRkeyyWeu0WL4gIZolK0xQZh9EXJN1u1C+1n4E+TQoP4YU6gPOiv4AfhqKTkKB bgGJ/OZAyhjF6WrKs6TLDActf7FIr2KuNYmODCvSmfEl7vcMw7+kKvnw+ms9O/RvkZlj XbRsoJaRGGb4nKSWrzWV/zlNuOkfGkbqUmlQa9LRVFulbMzgkknKPZsTZIBNuV58bVko x3IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796459289; x=1797064089; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=3oaSbQgCCtqKXVobDZoKmn+644A7z+sfQjThpL1iEWQ=; b=O+WhgWMjlR7fRDKV/zsCrLYwiJJsZ6wE/QFFOw4ySyBF58Kxh9kGEwEYsLiO4zCIe1 +ljhRG1vqFuEl3vpjb7Xxrts2V1U9qvshPTkOlCcA8qXr8OOCqpteGYa17R7Iy7pGZQy 4a8hUEDVi9PU4EObG/77F60//Wp5vYRqsun3u13USjFbQiVtuNPRA0gES6T+uKn1NnjS s0trz8E8vTPlWBs4YBIwJzd496chVlGjw2S2XufV/iGEOFYrCk5J8DPPHkXnPkXu6NZ5 EDe7dE3ioG5EKFwuKtX2+PFqd9rmgbB7s8r6WrBr1TiUVWZtOd0r4iLcZorFDqY26IrF wbTw== X-Forwarded-Encrypted: i=1; AL+hErFOsJ8jYWKwXpmFYP22ElkbCdt++pa8PRbo7bVCOnV9Ou2yTGcjQx7DxOJ9vg+lYdbXajRlWvnZ5GL4Nc8=@vger.kernel.org X-Gm-Message-State: APuU4Z8k6SShMbTRpEbjYCnma2MOnbNRi8W/Zj+ZFnKchlFpuJLLhPDH AXKPaxJWu7sQnYXl0E7IFroesLzKvJh6YPGecAq3dPwkcqBkQoPzFSmd X-Gm-Gg: AZFdTZf+4jM9M6+/7aG0N3fKoGXXkmMTAJqCwuRpBBtYyIzYYdN5Xt9yWQJ5M+Pcd3n 3xRg7lklrWA1AWnxs9oLsP2Ja6wBsgxUqjBJgvrzhfs1qn/4F5wA8cr+Dj2/RJfwPtzsa4IMThR LR4Xj+tCS67Uu4AcGkPt4UtQtmAvrBK8SSLFNkLo/rxMMOc2CPs6mHxKw32mMLwUqEd5Z2p5fuJ dIaA6rwY/sbki+RhJfVLTAA1Bn1JOCSM7zDB2eNhpH8b0muq2O1cR3D3MXbJHWH6Sy6rrfNL3IY Y6o5s443Z2g4tcBqmem8R6I0wlYNY3uUyAT+L1BsYkikhJRHAh7Sl8wfZPqjifObCuEvw7hRQ0X LkQk1+zskvaG5v0LMmowK2RoDPLxYDJT43dJ35YzUtmaJcFdKEdnxpB5xqVLKGJUu0zEGb+D878 Aa99QNqWMj5TWW8tYKcoxMl6TPXI+eTKBt3i5TF+o8Scj4AyMBqF7V4mLN9oxnfl8UgiZo95ssq MElpHEL/jMjmLwNe+Ht+ALiKyMjisrLa3N6aCT73m1bClTBEhmq0LRF3tbYzJfc7S8u7QapwUoW 7QtE8UH5AzB4EweM80d2nBcmHaI6aIgMtcxHXNh3gyi7/kpmM1AhrywCMKITe+nO7XlsFKWJKFz 9SvCR7Tp2xCdoIlPMn6LMIij3eCWay6l7Z7UrU0tz9gznsdE4M4LxEmPc0M5P X-Received: by 2002:a05:600c:a48:b0:4a1:da58:1ee with SMTP id 5b1f17b1804b1-4bbeb8ef5ebmr91576055e9.31.1796459289150; Sat, 05 Dec 2026 00:28:09 -0800 (PST) Received: from beelink0 (host86-181-68-246.range86-181.btcentralplus.com. [86.181.68.246]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbf172107bsm17731535e9.1.2026.12.05.00.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 00:28:08 -0800 (PST) From: Graeme Harker To: geert@linux-m68k.org Cc: Finn Thain , linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] m68k: delay: Fix rounding of short udelay() and ndelay() Date: Sat, 5 Dec 2026 08:28:07 +0000 Message-ID: <20261205082807.1348564-1-graeme.harker@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <31cf41a9-a2c2-6ae6-b12e-50e54875d0d1@linux-m68k.org> References: <31cf41a9-a2c2-6ae6-b12e-50e54875d0d1@linux-m68k.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi Geert, Finn has measured the patch on his LC 630 (thanks again, Finn) and has left the remaining choice to you, so here is what I would like to send as v2, if you are happy with it. His numbers bear out the udelay() half: every udelay() is longer than before and close to what was asked, the remaining 2% shortfall with interrupts off being calibrate_delay(), which this patch does not touch. For ndelay(), the patch is faster than the old code from 100 ns to 4 us (1.17 against 2.49 us at 100 ns, 5.63 against 6.07 us at 4 us), and never short, but it has one real flaw: the constant 5 that I copied from x86 is 16.4% more than 2^32 / 10^9, so long ndelay()s run about 16% long (46.9 against 39.2 us at 40 us). With his loops_per_jiffy of 107776 the patch's formula predicts 46.6 us there. For v2 I would keep udelay() as it is and change only the ndelay() constant, using shifts so that it adds no multiply: static inline void ndelay(unsigned long nsec) { /* 4 + 1/4 + 1/32 + 1/64 = 4.296875, close to 2^32 / 10^9 */ __xdelay(nsec * 4 + (nsec >> 2) + (nsec >> 5) + (nsec >> 6)); } That is 0.044% over 2^32 / 10^9 rather than 16.4%. The shifts truncate, so a very short ndelay() can ask for a fraction of a loop less than the exact figure, under a nanosecond; __delay()'s extra loop covers that. I have checked the loop counts on the host against the exact figure for loops_per_jiffy of 17792 (my 68030), 107776 (Finn's LC040) and 170000000. As before, ndelay() is good up to about 250 ms, where xloops * 4 overflows. Short ndelay()s still pay for the 64-bit multiply in __xdelay(): on the LC040 ndelay(20) went from 0.40 to 0.61 us. If you would rather avoid that, the other choice is to drop the ndelay() change altogether and send v2 as a udelay() fix only. Would you like v2 with the shift form, or udelay() only? I'll wait for your answer before sending either. Graeme