mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Jiri Hladky <hladky.jiri@googlemail.com>
Cc: linux-kernel@vger.kernel.org, Martin Mares <mj@ucw.cz>,
	the arch/x86 maintainers <x86@kernel.org>
Subject: Re: Bug in arch/i386/lib/delay.c file, delay_loop function
Date: Tue, 17 Jun 2008 11:03:30 +0200	[thread overview]
Message-ID: <20080617090330.GB18127@elte.hu> (raw)
In-Reply-To: <900048340806020300pf0db974k8318162a442968a2@mail.gmail.com>


* Jiri Hladky <hladky.jiri@googlemail.com> wrote:

> Hi Ingo, hi Martin!
> 
> As Martin correctly pointed out, my code will fail when loops=0. So I 
> have added a fix for this.

applied to tip/x86/delay, thanks Jiri! If it passes testing it will show 
up in the v2.6.27 kernel.

[ A few small patch format nits: the first hunk of the patch didnt 
  apply, it was whitespace-damaged - i hand-merged that. The assembly 
  had non-standard formatting - nowadays we try to format the assembly
  so that it looks nice in the .c file, not i the .s file. I fixed that 
  too. Also, the best way is to send fixes in the format below, with a 
  nice commit description, followed by a signed-off-by line. I fixed 
  that as well. ]

please double-check the end result. You can pick up tip/master via:

  http://people.redhat.com/mingo/tip.git/README

do "git-log -1 e01b70ef" or "git-log arch/x86/lib/delay_32.c" to see 
your commit.

	Ingo

------------->
commit e01b70ef3eb3080fecc35e15f68cd274c0a48163
Author: Jiri Hladky <hladky.jiri@googlemail.com>
Date:   Mon Jun 2 12:00:19 2008 +0200

    x86: fix bug in arch/i386/lib/delay.c file, delay_loop function
    
    when trying to understand how Bogomips are implemented I have found a
    bug in arch/i386/lib/delay.c file, delay_loop function.
    
    The function fails for loops > 2^31+1. It because SF is set when dec
    returns numbers > 2^31.
    
    The fix is to use jnz instruction instead of jns (and add one decl
    instruction to the end to have exactly the same number of loops as in
    original version).
    
    Martin Mares observed:
    
    > It is a long time since I have hacked that file, but you should definitely
    > make sure that the function is never called with a zero argument. In such
    > case, the original version made just a single pass, but your version
    > makes 2^32 of them.
    
    fixed that.
    
    Signed-off-by: Ingo Molnar <mingo@elte.hu>

diff --git a/arch/x86/lib/delay_32.c b/arch/x86/lib/delay_32.c
index d710f2d..ef69131 100644
--- a/arch/x86/lib/delay_32.c
+++ b/arch/x86/lib/delay_32.c
@@ -3,6 +3,7 @@
  *
  *	Copyright (C) 1993 Linus Torvalds
  *	Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ *	Copyright (C) 2008 Jiri Hladky <hladky _dot_ jiri _at_ gmail _dot_ com>
  *
  *	The __delay function must _NOT_ be inlined as its execution time
  *	depends wildly on alignment on many x86 processors. The additional
@@ -28,16 +29,22 @@
 /* simple loop based delay: */
 static void delay_loop(unsigned long loops)
 {
-	int d0;
-
 	__asm__ __volatile__(
-		"\tjmp 1f\n"
-		".align 16\n"
-		"1:\tjmp 2f\n"
-		".align 16\n"
-		"2:\tdecl %0\n\tjns 2b"
-		:"=&a" (d0)
-		:"0" (loops));
+		"	test %0,%0	\n"
+		"	jz 3f		\n"
+		"	jmp 1f		\n"
+
+		".align 16		\n"
+		"1:	jmp 2f		\n"
+
+		".align 16		\n"
+		"2:	decl %0		\n"
+		"	jnz 2b		\n"
+		"3:	decl %0		\n"
+
+		: /* we don't need output */
+		:"a" (loops)
+	);
 }
 
 /* TSC based delay: */

      reply	other threads:[~2008-06-17  9:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-30 15:15 Jiri Hladky
2008-05-31 16:39 ` Ingo Molnar
2008-06-01 17:05 ` Martin Mares
2008-06-02 10:00   ` Jiri Hladky
2008-06-17  9:03     ` Ingo Molnar [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080617090330.GB18127@elte.hu \
    --to=mingo@elte.hu \
    --cc=hladky.jiri@googlemail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mj@ucw.cz \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®