public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH][2.6.8-rc1-mm1] drivers/scsi/sg.c gcc341 inlining fix
@ 2004-07-15  9:46 Mikael Pettersson
  2004-07-15 13:09 ` Jeff Garzik
  2004-07-15 14:36 ` William Lee Irwin III
  0 siblings, 2 replies; 29+ messages in thread
From: Mikael Pettersson @ 2004-07-15  9:46 UTC (permalink / raw)
  To: axboe, wli
  Cc: B.Zolnierkiewicz, akpm, dgilbert, jgarzik, linux-kernel,
	linux-scsi, mikpe

On Wed, 14 Jul 2004 23:12:54 -0700, William Lee Irwin III wrote:
>Jeff Garzik <jgarzik@pobox.com> wrote:
>>>> Or you could just call it "gcc is dumb" rather than a compiler bug.
>
>On Wed, Jul 14 2004, Andrew Morton wrote:
>[... code snippet ...]
>>> is pretty dumb too.  I don't see any harm if this compiler feature/problem
>>> pushes us to fix the above in the obvious way.
>
>On Thu, Jul 15, 2004 at 07:56:56AM +0200, Jens Axboe wrote:
>> Excuse my ignorance, but why on earth would that be dumb? Looks
>> perfectly legit to me, and I have to agree with Jeff that the compiler
>> is exceedingly dumb if it fails to inline that case.
>
>Enter gcc...
>
>Maybe "the obvious way" is sending a someone off to whip gcc into shape,
>or possibly reporting it as a gcc problem.

It shows you guys aren't compiler writers.

Compilers for top-down (define-before-use) languages like C
have traditionally also worked in a top-down fashion, processing
one top-level declaration at a time. Forward references are
either errors, or are (when a proper declaration is in scope)
left to the linker to resolve.

Processing an entire compilation-unit (e.g. whole C file)
as a single unit is typically _only_ done when either the
language semantics requires it (not C, but e.g. Haskell),
or when very high optimisation levels are requested.

In the case of gcc-3.4.1 failing to inline, you are asking
gcc to do something (peeking forward) which it never has
promised to do. And with the kernel using -fno-unit-at-a-time
for stack conservation reasons, gcc is actually being _told_
not to do global compilation.

This is not a gcc bug, nor is it being "exceedingly dumb".

/Mikael

^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: [PATCH][2.6.8-rc1-mm1] drivers/scsi/sg.c gcc341 inlining fix
@ 2004-07-14 17:51 Mikael Pettersson
  2004-07-14 18:36 ` Jeff Garzik
  0 siblings, 1 reply; 29+ messages in thread
From: Mikael Pettersson @ 2004-07-14 17:51 UTC (permalink / raw)
  To: B.Zolnierkiewicz, jgarzik; +Cc: akpm, dgilbert, linux-kernel, linux-scsi, mikpe

On Wed, 14 Jul 2004 11:59:01 -0400, Jeff Garzik wrote:
>Bartlomiej Zolnierkiewicz wrote:
>> Hi,
>> 
>> On Wednesday 14 of July 2004 14:16, Mikael Pettersson wrote:
>> 
>>>gcc-3.4.1 errors out in 2.6.8-rc1-mm1 at drivers/scsi/sg.c:
>>>
>>>drivers/scsi/sg.c: In function `sg_ioctl':
>>>drivers/scsi/sg.c:209: sorry, unimplemented: inlining failed in call to
>>>'sg_jif_to_ms': function body not available drivers/scsi/sg.c:930: sorry,
>>>unimplemented: called from here
>>>make[2]: *** [drivers/scsi/sg.o] Error 1
>>>make[1]: *** [drivers/scsi] Error 2
>>>make: *** [drivers] Error 2
>>>
>>>sg_jif_to_ms() is marked inline but used defore its function
>>>body is available. Moving it nearer the top of sg.c (together
>>>with sg_ms_to_jif() for consistency) fixes the problem.
>> 
>> 
>> While your patch is perfectly fine I think we can do better.
>> I think that we may try converting sg.c to use jiffies_to_msecs()
>> and msecs_to_jiffies() from <linux/time.h>.
>
>
>_Look_ at the patch.  It just moves code around for no reason.  Using 
>static inline prototypes should work just fine.  This patch isn't needed.

It's needed, and no it's not a compiler bug.

2.6.8-rc1-mm1 changed <linux/compiler-gcc3.h> to attach
__attribute__((always_inline)) to inline-declarations.
gcc-3.4, in turn, honors this literally: if it fails to
inline because the function body isn't visible at the
call site, then it generates a compiler error, exactly
as the kernel asked it to.

(And placing 'static inline' on a forward-declared function
is utterly pointless: if its body isn't visible it won't
be inlined, and if it is visible, the forward declaration
itself served no purpose.)

Now maybe Andrew shouldn't have merged that change, but
at least it shows us where inlining doesn't occur, allowing
us to fix the code or remove unnecessary inlines.

/Mikael

^ permalink raw reply	[flat|nested] 29+ messages in thread
* [PATCH][2.6.8-rc1-mm1] drivers/scsi/sg.c gcc341 inlining fix
@ 2004-07-14 12:16 Mikael Pettersson
  2004-07-14 15:52 ` Jeff Garzik
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Mikael Pettersson @ 2004-07-14 12:16 UTC (permalink / raw)
  To: akpm; +Cc: dgilbert, linux-kernel, linux-scsi

gcc-3.4.1 errors out in 2.6.8-rc1-mm1 at drivers/scsi/sg.c:

drivers/scsi/sg.c: In function `sg_ioctl':
drivers/scsi/sg.c:209: sorry, unimplemented: inlining failed in call to 'sg_jif_to_ms': function body not available
drivers/scsi/sg.c:930: sorry, unimplemented: called from here
make[2]: *** [drivers/scsi/sg.o] Error 1
make[1]: *** [drivers/scsi] Error 2
make: *** [drivers] Error 2

sg_jif_to_ms() is marked inline but used defore its function
body is available. Moving it nearer the top of sg.c (together
with sg_ms_to_jif() for consistency) fixes the problem.

Signed-off-by: Mikael Pettersson <mikpe@csd.uu.se>

--- linux-2.6.8-rc1-mm1/drivers/scsi/sg.c.~1~	2004-07-14 12:58:34.000000000 +0200
+++ linux-2.6.8-rc1-mm1/drivers/scsi/sg.c	2004-07-14 13:45:26.000000000 +0200
@@ -225,6 +225,30 @@
 #define SZ_SG_REQ_INFO sizeof(sg_req_info_t)
 
 static int
+sg_ms_to_jif(unsigned int msecs)
+{
+	if ((UINT_MAX / 2U) < msecs)
+		return INT_MAX;	/* special case, set largest possible */
+	else
+		return ((int) msecs <
+			(INT_MAX / 1000)) ? (((int) msecs * HZ) / 1000)
+		    : (((int) msecs / 1000) * HZ);
+}
+
+static inline unsigned
+sg_jif_to_ms(int jifs)
+{
+	if (jifs <= 0)
+		return 0U;
+	else {
+		unsigned int j = (unsigned int) jifs;
+		return (j <
+			(UINT_MAX / 1000)) ? ((j * 1000) / HZ) : ((j / HZ) *
+								  1000);
+	}
+}
+
+static int
 sg_open(struct inode *inode, struct file *filp)
 {
 	int dev = iminor(inode);
@@ -2575,30 +2599,6 @@
 	free_pages((unsigned long) buff, order);
 }
 
-static int
-sg_ms_to_jif(unsigned int msecs)
-{
-	if ((UINT_MAX / 2U) < msecs)
-		return INT_MAX;	/* special case, set largest possible */
-	else
-		return ((int) msecs <
-			(INT_MAX / 1000)) ? (((int) msecs * HZ) / 1000)
-		    : (((int) msecs / 1000) * HZ);
-}
-
-static inline unsigned
-sg_jif_to_ms(int jifs)
-{
-	if (jifs <= 0)
-		return 0U;
-	else {
-		unsigned int j = (unsigned int) jifs;
-		return (j <
-			(UINT_MAX / 1000)) ? ((j * 1000) / HZ) : ((j / HZ) *
-								  1000);
-	}
-}
-
 static unsigned char allow_ops[] = { TEST_UNIT_READY, REQUEST_SENSE,
 	INQUIRY, READ_CAPACITY, READ_BUFFER, READ_6, READ_10, READ_12,
 	MODE_SENSE, MODE_SENSE_10, LOG_SENSE

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2004-07-26 22:12 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-15  9:46 [PATCH][2.6.8-rc1-mm1] drivers/scsi/sg.c gcc341 inlining fix Mikael Pettersson
2004-07-15 13:09 ` Jeff Garzik
2004-07-15 15:58   ` Matthew Wilcox
2004-07-15 14:36 ` William Lee Irwin III
  -- strict thread matches above, loose matches on Subject: below --
2004-07-14 17:51 Mikael Pettersson
2004-07-14 18:36 ` Jeff Garzik
2004-07-14 19:05   ` Adrian Bunk
2004-07-14 21:35   ` Andrew Morton
2004-07-14 23:39     ` Jeff Garzik
2004-07-14 22:39       ` Andrew Morton
2004-07-15  0:19       ` Matthew Wilcox
2004-07-15  5:56     ` Jens Axboe
2004-07-15  6:12       ` William Lee Irwin III
2004-07-15 15:42     ` Douglas Gilbert
2004-07-14 12:16 Mikael Pettersson
2004-07-14 15:52 ` Jeff Garzik
2004-07-14 16:42   ` Adrian Bunk
2004-07-14 16:44     ` Jeff Garzik
2004-07-14 16:54       ` Adrian Bunk
2004-07-14 17:31         ` Bartlomiej Zolnierkiewicz
2004-07-14 18:33           ` Adrian Bunk
2004-07-14 18:44             ` Jeff Garzik
2004-07-14 19:06             ` Douglas Gilbert
2004-07-26 22:09             ` Andrew Morton
2004-07-14 18:34           ` Jeff Garzik
2004-07-14 18:31         ` Jeff Garzik
2004-07-14 15:57 ` Bartlomiej Zolnierkiewicz
2004-07-14 15:59   ` Jeff Garzik
2004-07-26 21:53 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox