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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77B8CC04A68 for ; Thu, 28 Jul 2022 10:31:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235679AbiG1Kah (ORCPT ); Thu, 28 Jul 2022 06:30:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233296AbiG1Kaf (ORCPT ); Thu, 28 Jul 2022 06:30:35 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2AE7643C; Thu, 28 Jul 2022 03:30:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=U3nI+Dk03TsFhKliasBzCqNdnQznxo+muaRKiNshSuY=; b=DoknfXSTWH6Zj0VygdQvr0QmiU n3MBGvZvhPEFAiDYNcsplITEjAUg8GjB0EjIdovXr9DMAWKceqzB1X00wpuAfOPT0rd14gfho5lej Cea7D/u12vnurMUcIqiJUIVdZ7fxAY2iHbUkSlC4ghl7mLfwL+46das3fo0EemF3c0MCYQaDOoWE/ Gpdw7ThlFbzXOJYPg1N8thEeDwUQ/0eOakgSxbfT1lF340nCCBAc1+Oo9XL+StraJ1EeOTvqvwj+S w2bhehT6r2x+aMyEKKmGn2cive6opClxIfPNulf55c6iZfVzSev7RjV84AJaerI1G3Na5uq2NqbC6 C7gY0xbA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oH0mM-003kPI-If; Thu, 28 Jul 2022 10:30:06 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 09FD998040A; Thu, 28 Jul 2022 12:30:05 +0200 (CEST) Date: Thu, 28 Jul 2022 12:30:04 +0200 From: Peter Zijlstra To: Yu Zhe Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, liqiong@nfschina.com Subject: Re: [PATCH] x86/aperfmperf: use time_is_before_jiffies(a + b) to replace "jiffies - a > b" Message-ID: References: <20220727031405.26892-1-yuzhe@nfschina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 28, 2022 at 10:55:51AM +0800, Yu Zhe wrote: > 在 2022年07月28日 00:00, Peter Zijlstra 写道: > > > On Wed, Jul 27, 2022 at 11:14:05AM +0800, Yu Zhe wrote: > > > time_is_before_jiffies deals with timer wrapping correctly. > > Please explain how the current code does not. > > 1. If the timer wrap changes in the future you won't have to alter your code. > > 2. unsigned long ut; > > ut = ULONG_MAX + 4; > > printf("time_after(ut, ULONG_MAX), ut:%d, %d --> %d\n", ut, > time_after(ut, ULONG_MAX), (ULONG_MAX - ut) < 0); > > > In this case, time_after returns true, it's correct. Now try the same with the existing code...