From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S262369AbTKRHFL (ORCPT ); Tue, 18 Nov 2003 02:05:11 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S262373AbTKRHFL (ORCPT ); Tue, 18 Nov 2003 02:05:11 -0500 Received: from bluejay.broadware.com ([209.219.63.5]:64214 "EHLO bluejay.broadware.com") by vger.kernel.org with ESMTP id S262369AbTKRHE7 (ORCPT ); Tue, 18 Nov 2003 02:04:59 -0500 Message-ID: <001d01c3ada2$275ba310$0200a8c0@vaiors410> From: "Suman Puthana" To: Cc: "Suman Puthana" Subject: usleep() bug in kernels > 2.4.18? Date: Mon, 17 Nov 2003 23:03:59 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org I'm trying to fix a bug in our application which happens when used with kernels 2.4.19 and thereafter. I've narrowed it down to a problem with the usleep() call. What I have noticed is that the usleep() sleeps within 5-10% accuracy for times > 30 ms in kernels upto 2.4.18 which is good enough.(eg:-32 ms for 30 ms) But in kernels from 2.4.19 onwards - for any value between ( 31-40 ms ), usleep sleeps for 50 ms for any value between ( 41-50 ms ), usleep sleeps for 60 ms for any value between ( 51-60 ms ), usleep sleeps for 70 ms and so on...You can see the trend which is kind of strange. I see that some kind of granularity has been introduced into the newer kernels and I would like to avoid that if possible. Is there an easy way to avoid this? I understand that linux is not an RTOS but something which worked in the previous kernels does not work anymore. I'm just getting into understanding low-level linux kernel stuff...So any input or pointers into understanding this issue would be greatly appreciated. The same system (I've attached the ver_linux output at the end) when booted from a 2.4.18 kernel gives a lot better results for usleep() than when booted from the 2.4.21 kernel ( results as shown above) . I get the same results as shown above with 2.4.19 , 2.4.20, 2.4.21 and 2.4.22 kernels. I've tried this on a few different systems and can reliably reproduce this on the newer kernels. Thanks in Advance, -Suman ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Here's the simple program I used to get these results : #include #include #include #include #define MILLISEC_DIFF(new, old, diff) { \ (diff) = (((new).tv_sec - (old).tv_sec) * 1000L ) + \ (((new).tv_usec - (old).tv_usec) / 1000L ); \ } int main(int args, char ** argv) { int time = 30; struct timeval time1,time2; long elapsed; if(args < 2) { printf("USAGE: sleep