From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S261692AbVGNUiF (ORCPT ); Thu, 14 Jul 2005 16:38:05 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S261689AbVGNUiF (ORCPT ); Thu, 14 Jul 2005 16:38:05 -0400 Received: from allen.werkleitz.de ([80.190.251.108]:50821 "EHLO allen.werkleitz.de") by vger.kernel.org with ESMTP id S261692AbVGNUhf (ORCPT ); Thu, 14 Jul 2005 16:37:35 -0400 Date: Thu, 14 Jul 2005 22:38:55 +0200 From: Johannes Stezenbach To: Linus Torvalds Cc: Arjan van de Ven , Vojtech Pavlik , Lee Revell , dean gaudet , Chris Wedgwood , Andrew Morton , "Brown, Len" , dtor_core@ameritech.net, david.lang@digitalinsight.com, davidsen@tmr.com, kernel@kolivas.org, linux-kernel@vger.kernel.org, mbligh@mbligh.org, diegocg@gmail.com, azarah@nosferatu.za.org, christoph@lameter.com Message-ID: <20050714203855.GA6022@linuxtv.org> Mail-Followup-To: Johannes Stezenbach , Linus Torvalds , Arjan van de Ven , Vojtech Pavlik , Lee Revell , dean gaudet , Chris Wedgwood , Andrew Morton , "Brown, Len" , dtor_core@ameritech.net, david.lang@digitalinsight.com, davidsen@tmr.com, kernel@kolivas.org, linux-kernel@vger.kernel.org, mbligh@mbligh.org, diegocg@gmail.com, azarah@nosferatu.za.org, christoph@lameter.com References: <20050714005106.GA16085@taniwha.stupidest.org> <1121304825.4435.126.camel@mindpipe> <1121326938.3967.12.camel@laptopd505.fenrus.org> <20050714121340.GA1072@ucw.cz> <1121360561.3967.55.camel@laptopd505.fenrus.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-SA-Exim-Connect-IP: 84.189.232.111 Subject: Re: [PATCH] i386: Selectable Frequency of the Timer Interrupt X-SA-Exim-Version: 4.2 (built Thu, 03 Mar 2005 10:44:12 +0100) X-SA-Exim-Scanned: Yes (on allen.werkleitz.de) Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 14, 2005 Linus Torvalds wrote: > In other words, the _right_ way to do this is literally > > unsigned long timeout = jiffies + HZ/2; > for (;;) { > if (ready()) > return 0; > if (time_after(timeout, jiffies)) > break; > msleep(10); > } > > which is unquestionably more complex, yes, but it's more complex because > it is CORRECT! Since you emphasised on correctness, your code is actually buggy for the preemptible kernel. It could get preempted after the ready() test, but before the time_after(), for quite a whie if a high priority process keeps the system busy. This code is better: unsigned long timeout = jiffies + HZ/2; int err; for (;;) { err = time_after(timeout, jiffies); if (ready()) return 0; if (err) break; msleep(10); } This way the condition is always re-tested before reporting timeout. Johannes