From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9FF6F44850 for ; Fri, 10 Apr 2026 12:19:51 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4fsbTC5pxKz2ynP; Fri, 10 Apr 2026 22:19:27 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2600:3c0a:e001:78e:0:1991:8:25" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1775823567; cv=none; b=S3JcZFPHPeZ7jj0w4L6UQhJoLdWVtHQaljsQJxGpYhjo+WQxM+A0MEzPRjMwYrUNuhJ8CBA0AAN+fLZNCPL31Qnl+ugVDKwD9rDN67O2zsIRvlUjJlaxLF6KrgiZI2z8K5+2bjzcYzPTaS2Uv0buQuXzXy0SQo+soOoJbxDEfxHP+lK4KIrCRG28zQxFcU/jkwKZkayMU5dhT79FfZ5/a9hRbTq65Lv7kdfe3XDVIgqNO1b7K+nGuZ6Zf0nsulTWAKL0glX6mnrDNIBy3isf5zxXIDxI0LP7zaHKkIKDQ+slC4Uy1t9EXDeKk7517AuXiTJD1BroEK+jeftG1Ok75A== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1775823567; c=relaxed/relaxed; bh=95Xzu/wrSKdgPqpES5U3P7913oi5C0HtUtRZ8A2JYug=; h=Date:Message-ID:From:To:Subject:References:MIME-Version: Content-Type:cc; b=L4oFJsQWryRQB5F03BUmerZQS4WNGMtca8Hl4x0gQ6g4PMyhW/hT6cqprWKKs3EFvjxO6EVTXlLs9xjUePml7lDhyLJ5sWnZt1Micv212ZpHTuy/Ff/eRPDY3ZuGcSyN+7dGooXggRvzJxJd6ECCTQMW0OBxYxxSVTkk67Lf+kOPArh1Swg9V0EAuqO/qwFdp6r8in+3SlEe7UxM+RXr2BiuDaDO3jOue2Dca95jqcU/YX49LzAi7UAWDqKQaouUoF5Qj/ABAleAb0WSBg9K7oGXfurDQ07TTq+L9Qwd70FEVxW3LRJMih1HzneSov+2odl5dEBuUKiAejTGxBD5VQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=uunn/bCq; dkim-atps=neutral; spf=pass (client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=tglx@kernel.org; receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=uunn/bCq; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=tglx@kernel.org; receiver=lists.ozlabs.org) Received: from sea.source.kernel.org (sea.source.kernel.org [IPv6:2600:3c0a:e001:78e:0:1991:8:25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4fsbTC105Nz2yhD for ; Fri, 10 Apr 2026 22:19:27 +1000 (AEST) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 5633E444F1; Fri, 10 Apr 2026 12:19:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A057C2BCB3; Fri, 10 Apr 2026 12:19:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775823565; bh=tLIpqPCaUi8Lfeqau43+rfn7UZ8vuvPykTPYNUPuuyU=; h=Date:From:To:Subject:References:cc:From; b=uunn/bCqpDYdqH3aqiI0+2U/qm27AeTQwxnXbKYibcvcv2ZEX2J7abPlER3gpmuTw CBdP5mMh40n2zp7Tno2Q99U//gHXFdOV0IBNQapDNZb3rSYwBD5TySsxa/Td7SLyaZ p+uL6Iv9jGq9ZtmZnt8i06X/J571L31cWnZuiDLMRsOKbpHdih8iJDMdVxjdr+94oH +kfrO2pFRZtB2b/jp8TX3WQWaL7ksYC/uaT6tTAybV37imt1fhiAkDjh2EPTnuViku 1P4aDmEJtrdQSxbhtiFRIYbjrzGEHTE4V2Fb8MxeAUFtdhNoavN7essScQIWwWoRqs j/BFBM5JmmtDw== Date: Fri, 10 Apr 2026 14:19:21 +0200 Message-ID: <20260410120318.320727701@kernel.org> User-Agent: quilt/0.68 From: Thomas Gleixner To: LKML Subject: [patch 11/38] misc: sgi-gru: Remove get_cycles() [ab]use References: <20260410120044.031381086@kernel.org> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 cc: Arnd Bergmann , x86@kernel.org, Lu Baolu , iommu@lists.linux.dev, Michael Grzeschik , netdev@vger.kernel.org, linux-wireless@vger.kernel.org, Herbert Xu , linux-crypto@vger.kernel.org, Vlastimil Babka , linux-mm@kvack.org, David Woodhouse , Bernie Thompson , linux-fbdev@vger.kernel.org, "Theodore Tso" , linux-ext4@vger.kernel.org, Andrew Morton , Uladzislau Rezki , Marco Elver , Dmitry Vyukov , kasan-dev@googlegroups.com, Andrey Ryabinin , Thomas Sailer , linux-hams@vger.kernel.org, "Jason A. Donenfeld" , Richard Henderson , linux-alpha@vger.kernel.org, Russell King , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Huacai Chen , loongarch@lists.linux.dev, Geert Uytterhoeven , linux-m68k@lists.linux-m68k.org, Dinh Nguyen , Jonas Bonn , linux-openrisc@vger.kernel.org, Helge Deller , linux-parisc@vger.kernel.org, Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Paul Walmsley , linux-riscv@lists.infradead.org, Heiko Carstens , linux-s390@vger.kernel.org, "David S. Miller" , sparclinux@vger.kernel.org Calculating a timeout from get_cycles() is a historical leftover without any functional requirement. Use ktime_get() instead. Signed-off-by: Thomas Gleixner --- drivers/misc/sgi-gru/gruhandles.c | 20 ++++++++------------ drivers/misc/sgi-gru/grukservices.c | 3 ++- drivers/misc/sgi-gru/grutlbpurge.c | 5 ++--- 3 files changed, 12 insertions(+), 16 deletions(-) --- a/drivers/misc/sgi-gru/gruhandles.c +++ b/drivers/misc/sgi-gru/gruhandles.c @@ -6,26 +6,22 @@ */ #include +#include #include "gru.h" #include "grulib.h" #include "grutables.h" -/* 10 sec */ #include -#include -#define GRU_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000) -#define CLKS2NSEC(c) ((c) * 1000000 / tsc_khz) + +#define GRU_OPERATION_TIMEOUT_NSEC (((ktime_t)10 * NSEC_PER_SEC)) /* Extract the status field from a kernel handle */ #define GET_MSEG_HANDLE_STATUS(h) (((*(unsigned long *)(h)) >> 16) & 3) struct mcs_op_statistic mcs_op_statistics[mcsop_last]; -static void update_mcs_stats(enum mcs_op op, unsigned long clks) +static void update_mcs_stats(enum mcs_op op, unsigned long nsec) { - unsigned long nsec; - - nsec = CLKS2NSEC(clks); atomic_long_inc(&mcs_op_statistics[op].count); atomic_long_add(nsec, &mcs_op_statistics[op].total); if (mcs_op_statistics[op].max < nsec) @@ -58,21 +54,21 @@ static void report_instruction_timeout(v static int wait_instruction_complete(void *h, enum mcs_op opc) { + ktime_t start_time = ktime_get(); int status; - unsigned long start_time = get_cycles(); while (1) { cpu_relax(); status = GET_MSEG_HANDLE_STATUS(h); if (status != CCHSTATUS_ACTIVE) break; - if (GRU_OPERATION_TIMEOUT < (get_cycles() - start_time)) { + if (GRU_OP_TIMEOUT_NSEC < (ktime_get() - start_time)) { report_instruction_timeout(h); - start_time = get_cycles(); + start_time = ktime_get(); } } if (gru_options & OPT_STATS) - update_mcs_stats(opc, get_cycles() - start_time); + update_mcs_stats(opc, (unsigned long)(ktime_get() - start_time)); return status; } --- a/drivers/misc/sgi-gru/grukservices.c +++ b/drivers/misc/sgi-gru/grukservices.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "gru.h" #include "grulib.h" @@ -1106,7 +1107,7 @@ static int quicktest3(unsigned long arg) int ret = 0; memset(buf2, 0, sizeof(buf2)); - memset(buf1, get_cycles() & 255, sizeof(buf1)); + memset(buf1, get_random_u32() & 255, sizeof(buf1)); gru_copy_gpa(uv_gpa(buf2), uv_gpa(buf1), BUFSIZE); if (memcmp(buf1, buf2, BUFSIZE)) { printk(KERN_DEBUG "GRU:%d quicktest3 error\n", smp_processor_id()); --- a/drivers/misc/sgi-gru/grutlbpurge.c +++ b/drivers/misc/sgi-gru/grutlbpurge.c @@ -22,13 +22,12 @@ #include #include #include +#include #include #include "gru.h" #include "grutables.h" #include -#define gru_random() get_cycles() - /* ---------------------------------- TLB Invalidation functions -------- * get_tgh_handle * @@ -49,7 +48,7 @@ static inline int get_off_blade_tgh(stru int n; n = GRU_NUM_TGH - gru->gs_tgh_first_remote; - n = gru_random() % n; + n = get_random_u32() % n; n += gru->gs_tgh_first_remote; return n; }