All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kyle Moffett <mrmacman_g4@mac.com>
To: Roman Kononov <kononov195-far@yahoo.com>
Cc: LKML Kernel <linux-kernel@vger.kernel.org>
Subject: Re: C++ pushback
Date: Wed, 26 Apr 2006 23:37:05 -0400	[thread overview]
Message-ID: <4EE8AD21-55B6-4653-AFE9-562AE9958213@mac.com> (raw)
In-Reply-To: <445026EB.8010407@yahoo.com>

On Apr 26, 2006, at 22:05:31, Roman Kononov wrote:
> Kyle Moffett wrote:
>> On Apr 26, 2006, at 19:00:52, Roman Kononov wrote:
>>> Linus Torvalds wrote:
>>>>  - some of the C features we use may or may not be usable from C+ 
>>>> +    (statement expressions?)
>>>
>>> Statement expressions are working fine in g++. The main  
>>> difficulties are:
>>>    - GCC's structure member initialization extensions are syntax
>>>      errors in G++: struct foo_t foo={.member=0};
>>
>> And that breaks a _massive_ amount of kernel code, including such  
>> core functionality like SPIN_LOCK_UNLOCKED and a host of others.   
>> There are all sorts of macros that use member initialization of  
>> that form.
>
> This does not break the code at run time, this breaks the code at  
> compile time, and should be less painful.

So breaking 90% of the source code at compile time is ok?  I think  
not.  The kernel relies really _really_ heavily on such structure  
initializers, and breaking them would effectively break the world as  
far as the kernel is concerned.


>>> G++ compiling heavy C++ is a bit slower than gcc. The g++ front  
>>> end is reliable enough. Do you have a particular bug in mind?
>>
>> A lot of people would consider the "significantly slower" to be a  
>> major bug.  Many people moaned when the kernel stopped supporting  
>> GCC 2.x because that compiler was much faster than modern C  
>> compilers.  I've seen up to a 3x slowdown when compiling the same  
>> files with g++ instead of gcc, and such would be unacceptable to a  
>> _lot_ of people on this list.
>
> I agree, it would be a bad idea to compile the existing C code by g+ 
> +.  The good idea is to be able to produce new C++ modules etc.

No, this is a reason why C++ modules are _not_ a good idea.  If you  
could write the module in C or C++, but in C++ it compiled 100-200%  
slower, then you would write it in C.  Why?  A simple matter of numbers:

Say it takes you 100 hours to write and debug the module in C++, and  
140 to write and debug it in C.  I estimate that at least 200,000  
people would download and compile a single version of the kernel with  
your module (not an unreasonable estimate).  Note that I'm not even  
including the people who do repeated regression testing of versions,  
or people who download and compile multiple versions of the kernel.    
If the source file takes an average of 1.0 seconds to compile in C  
and 2.0 seconds to compile in C++, then:

(2.0 sec - 1.0 sec) * 200,000 = 200,000 seconds = 55.6 hours
140 hours - 100 hours = 40 hours
40 hours < 55.6 hours

So for a single version of the kernel your module, you've already  
wasted 15.6 hours of time across people using it.  Over time that  
number is just going to grow, _especially_ if people start writing  
more and more modules in C++ because they can.  If you want to build C 
++ in the kernel, write a compiler that does not include all the  
problematic C++ features that add so much parsing time (overloaded  
operators, etc).


>>> A lot of C++ features are already supported sanely. You simply  
>>> need to understand them. Especially templates and type checking.
>>
>> First of all, the only way to sanely use templated classes is to  
>> write them completely inline, which causes massive bloat.  Look at  
>> the kernel "struct list_head" and show me the "type-safe C++" way  
>> to do that.  It uses a templated inline class, right?  That  
>> templated inline class gets duplicated for each different type of  
>> object put in a linked list, no?  Think about how many linked  
>> lists we have in the kernel and tell me why that would be a good  
>> thing.
>
> You mentioned a bad example. The struct list_head has [almost?] all  
> "members" inlined. If they were not, one could simply make a base  
> class having [some] members outlined, and which class does not  
> enforce type safety and is for inheritance only.  The template  
> class would then inherit the base one enforcing type safety by  
> having inline members. This technique is well known, trust me. If  
> you need real life examples, tell me.

Ok, help me understand here:  Instead of helping using one sensible  
data structure and generating optimized code for that, the language  
actively _encourages_ you to duplicate classes and interfaces,  
providing even _more_ work for the compiler, making the code harder  
to debug, and probably introducing inefficiencies as well.  If C++  
doesn't work properly for a simple and clean example like struct  
list_head, why should we assume that it's going to work any better  
for more complicated examples in the rest of the kernel?  Whether or  
not some arbitrary function is inlined should be totally orthogonal  
to adding type-checking.

>>> Static constructor issue is trivial.
>>
>> How so?  When do you want the static constructors to be run?   
>> There are many different major stages of kernel-level  
>> initialization; picking one is likely to make them useless for  
>> other code.
>
> For #defines core_initcall() ... late_initcall() I would type  
> something like this:
> 	class foo_t { foo_t(); ~foo_t(); }
> 	static char foo_storage[sizeof(foo_t)];
> 	static foo_t& foo=*reinterpret_cast<foo_t*>(foo_storage);
> 	static void __init foo_init() { new(foo_storage) foo_t; }
> 	core_initcall(foo_init);
>
> This ugly-looking code can be nicely wrapped into a template,  
> which, depending on the type (foo_t in this case), at compile time,  
> picks the proper stage for initialization.

You proved my point.  Static constructors can't work.  You can add  
silly wrapper initcall functions which create objects in static  
memory at various times, but the language-defined static constructors  
are yet another C++ feature that doesn't work by default and has to  
be hacked around.  C++ gives us no advantage over C here either.   
Plus this would break things like static spinlock initialization.   
How would you make this work sanely for this static declaration:

spinlock_t foo_lock = SPIN_LOCK_UNLOCKED;

Under C that turns into (depending on config options):

spinlock_t foo_lock = { .value = 0, .owner = NULL, (...) };

How could that possibly work in C++ given what you've said?  Anything  
that breaks code that simple is an automatic nonstarter for the  
kernel.  Also remember that spinlocks are defined preinitialized at  
the very earliest stages of init.  Of course I probably don't have to  
say that anything that tries to run a function to iterate over all  
statically-allocated spinlocks during init would be rejected out of  
hand.

Cheers,
Kyle Moffett


  reply	other threads:[~2006-04-27  3:37 UTC|newest]

Thread overview: 196+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-24 19:16 Compiling C++ modules Gary Poppitz
2006-04-24 19:27 ` Greg KH
2006-04-24 20:02   ` C++ pushback Gary Poppitz
2006-04-24 20:15     ` Christoph Hellwig
2006-04-24 20:16     ` Greg KH
2006-04-24 20:18     ` Martin Mares
2006-04-24 21:36       ` Jeff V. Merkey
2006-04-24 21:28         ` J.A. Magallon
2006-04-24 21:43           ` Harald Arnesen
2006-04-24 21:52         ` Alan Cox
2006-04-24 22:16           ` J.A. Magallon
2006-04-25  0:05             ` Harald Arnesen
2006-04-25  0:46               ` Diego Calleja
2006-04-25  9:12                 ` Harald Arnesen
2006-04-25  1:30             ` linux-os (Dick Johnson)
2006-04-25  2:58               ` marty fouts
2006-04-27 22:55               ` Bill Davidsen
2006-05-02 15:58                 ` Randy.Dunlap
2006-05-02 20:36                 ` David Schwartz
2006-04-25  8:15             ` Xavier Bestel
2006-04-25  8:42               ` Avi Kivity
2006-04-25  8:52                 ` Martin Mares
2006-04-25  9:00                   ` Avi Kivity
2006-04-25  9:05                     ` Martin Mares
2006-04-25  9:13                       ` Avi Kivity
2006-04-25  9:22                         ` Xavier Bestel
2006-04-25 20:20                           ` J.A. Magallon
2006-04-25 20:31                             ` Barry Kelly
2006-04-25  9:09             ` Nikita Danilov
2006-04-25 20:10               ` J.A. Magallon
2006-04-25 18:02             ` Geert Uytterhoeven
2006-04-27  9:09             ` Alexander E. Patrakov
2006-04-24 22:39           ` Willy Tarreau
2006-04-24 22:57           ` Jeff V. Merkey
2006-04-24 23:02       ` David Schwartz
2006-04-25  8:55         ` Martin Mares
2006-04-25  8:59           ` Jan Engelhardt
2006-04-25 14:37           ` David Schwartz
2006-04-25 19:50             ` Martin Mares
2006-04-26  2:33               ` David Schwartz
2006-04-26  3:42                 ` Matthew Frost
2006-04-26 19:25                   ` David Schwartz
2006-04-26 20:01                     ` Jan-Benedict Glaw
2006-04-26 20:09                       ` Linus Torvalds
2006-04-26 20:19                         ` Al Viro
2006-04-26 21:37                           ` Sam Ravnborg
2006-04-28  9:23                             ` Avi Kivity
2006-04-28 12:00                               ` linux-os (Dick Johnson)
2006-04-28 12:46                                 ` Jan-Benedict Glaw
2006-04-26 20:25                         ` Jan-Benedict Glaw
2006-04-26 20:43                         ` David Schwartz
2006-04-26 23:00                         ` Roman Kononov
2006-04-27  0:38                           ` Kyle Moffett
2006-04-27  2:05                             ` Roman Kononov
2006-04-27  3:37                               ` Kyle Moffett [this message]
2006-04-27  5:37                                 ` Roman Kononov
2006-04-27 13:58                                   ` Michael Buesch
2006-04-27 14:22                                     ` linux-os (Dick Johnson)
2006-04-27  8:07                                 ` Avi Kivity
2006-04-27 13:55                                   ` Denis Vlasenko
2006-04-27 14:27                                     ` Avi Kivity
2006-04-27 14:56                                       ` Denis Vlasenko
2006-04-27 15:54                                         ` Bob Copeland
2006-04-27 16:03                                         ` Avi Kivity
2006-04-27 15:00                                       ` Martin Mares
2006-04-27 15:31                                         ` Avi Kivity
2006-04-27 15:38                                           ` Martin Mares
2006-04-28  8:16                                             ` Avi Kivity
2006-04-28  8:30                                               ` Avi Kivity
2006-04-28 15:47                                               ` Jan Engelhardt
2006-04-28 15:51                                       ` Jan Engelhardt
2006-04-28 16:51                                         ` Avi Kivity
2006-04-27 14:50                                 ` Sam Ravnborg
2006-04-27  8:50                               ` Martin Mares
2006-04-27  3:57                           ` Willy Tarreau
2006-04-27  5:53                             ` Roman Kononov
2006-04-27  7:55                           ` Jan-Benedict Glaw
2006-04-27 17:20                           ` C++ pushback (when does this religious thread end?) Leonard Peterson
2006-04-30 17:48                           ` C++ pushback Jan Harkes
2006-04-30 20:55                             ` David Schwartz
2006-04-26 20:05                     ` linux-os (Dick Johnson)
2006-04-26 20:09                     ` Xavier Bestel
2006-04-26 20:44                       ` Randy.Dunlap
2006-05-02 20:09                         ` C++ pushback + sparse Randy.Dunlap
2006-04-27  7:49                       ` C++ pushback Jiri Kosina
2006-04-26 21:05                     ` Martin Mares
2006-04-25  7:33       ` Avi Kivity
2006-04-25  7:47         ` Nick Piggin
2006-05-13 16:21         ` Esben Nielsen
2006-04-24 20:36     ` Thiago Galesi
2006-04-24 21:38     ` Kurt Wall
2006-04-27 16:17     ` Roman Kononov
2006-04-27 21:59       ` Grant Coady
2006-04-27 22:09     ` Bill Davidsen
2006-04-27 23:19       ` Jan Knutar
2006-04-24 19:30 ` Compiling C++ modules Al Viro
2006-04-24 19:40 ` linux-os (Dick Johnson)
2006-04-24 20:54   ` Geert Uytterhoeven
2006-04-24 19:42 ` Alexey Dobriyan
2006-04-24 20:30 ` Daniel Barkalow
2006-04-24 20:35 ` C++ is in US [Re: Compiling C++ modules] Jiri Slaby
2006-04-24 20:45 ` Compiling C++ modules Alan Cox
2006-04-24 21:03   ` Avi Kivity
2006-04-24 21:23     ` Joshua Hudson
2006-04-24 21:29     ` Kyle Moffett
2006-04-24 21:50       ` marty fouts
2006-04-24 22:09         ` Martin Mares
2006-04-24 22:30           ` Willy Tarreau
2006-04-24 22:32           ` Joshua Hudson
2006-04-24 22:45           ` marty fouts
2006-04-25 15:32         ` Michael Buesch
2006-04-25  7:08       ` Avi Kivity
2006-04-25 10:23         ` James Courtier-Dutton
2006-04-25 15:59         ` Kyle Moffett
2006-04-25 16:46           ` Avi Kivity
2006-04-25 17:10             ` Dmitry Torokhov
2006-04-25 17:19               ` Avi Kivity
2006-04-25 17:28                 ` Dmitry Torokhov
2006-04-25 17:53                   ` Avi Kivity
2006-04-25 18:04                     ` Dmitry Torokhov
2006-04-25 18:08                     ` Valdis.Kletnieks
2006-04-25 18:26                       ` Avi Kivity
2006-04-25 18:38                         ` Avi Kivity
2006-04-25 18:52                           ` Michael Poole
2006-04-25 19:13                             ` Avi Kivity
2006-04-27 15:10                     ` Denis Vlasenko
2006-04-27 20:15                       ` Willy Tarreau
2006-04-27 21:08                         ` Davi Arnaut
2006-04-28  9:33                           ` Avi Kivity
2006-04-28 10:03                             ` Avi Kivity
2006-04-28 11:27                               ` Sergei Organov
2006-04-28 11:03                             ` Martin Mares
2006-04-28 11:30                               ` Avi Kivity
2006-04-28 15:56                                 ` Jan Engelhardt
2006-04-28 17:02                                   ` Avi Kivity
2006-04-28 17:38                                     ` linux-os (Dick Johnson)
2006-04-29  2:50                                       ` Christer Weinigel
2006-05-01 17:46                                       ` Dave Neuer
2006-05-01 20:21                                         ` Jan Engelhardt
2006-05-01 23:53                                         ` David Schwartz
2006-05-02  5:12                                           ` Willy Tarreau
2006-05-02 10:32                                             ` Avi Kivity
2006-05-02 11:15                                               ` Martin Mares
2006-05-02 11:26                                                 ` Avi Kivity
2006-05-02 11:40                                                   ` linux-os (Dick Johnson)
2006-05-02 12:42                                                   ` David Woodhouse
2006-05-02 16:27                                                     ` Christer Weinigel
2006-05-02 12:48                                                   ` Martin Mares
2006-05-02 13:52                                                     ` Avi Kivity
2006-05-02 14:13                                                       ` Al Viro
2006-05-02 14:54                                                         ` Avi Kivity
2006-05-02 16:16                                                   ` Brian Beattie
2006-05-02 16:21                                                     ` Avi Kivity
2006-05-02 13:21                                               ` Willy Tarreau
2006-05-02 14:41                                                 ` Avi Kivity
2006-05-02 22:25                                                   ` Diego Calleja
2006-05-02 13:34                                               ` Al Viro
2006-05-02 14:02                                                 ` Avi Kivity
2006-05-02 14:34                                                   ` Al Viro
2006-05-02 15:04                                                     ` Avi Kivity
2006-05-02 15:15                                                       ` Al Viro
2006-05-02 15:19                                                         ` Avi Kivity
2006-05-02 15:27                                                           ` Kyle Moffett
2006-05-02 15:30                                                             ` Avi Kivity
2006-05-02 15:28                                                           ` Al Viro
2006-05-02 15:51                                                             ` Avi Kivity
2006-05-02 15:24                                                         ` Kyle Moffett
2006-05-03 13:13                                           ` Mark Lord
2006-05-03 20:51                                             ` David Schwartz
2006-04-30 21:15                               ` Eric W. Biederman
2006-04-25 17:54                 ` linux-os (Dick Johnson)
2006-04-26  8:30                   ` Jan Engelhardt
2006-04-26 11:36                     ` linux-os (Dick Johnson)
2006-04-25 19:22             ` Kyle Moffett
2006-04-25 19:54               ` Michael Buesch
2006-04-25 20:24               ` Avi Kivity
2006-04-25 20:11             ` Bongani Hlope
2006-04-25 20:26               ` Avi Kivity
2006-04-25 21:02                 ` Valdis.Kletnieks
2006-04-25 21:15                   ` Avi Kivity
     [not found]                     ` <71a0d6ff0604251646g4fc90b3dr30a03b8606360e7f@mail.gmail.com>
2006-04-26  4:39                       ` Avi Kivity
2006-04-25 17:55           ` Geert Uytterhoeven
2006-04-24 21:58     ` Alan Cox
2006-04-25  7:20       ` Avi Kivity
2006-04-25  9:06         ` Matt Keenan
2006-04-25 20:29           ` Bongani Hlope
2006-04-25 20:37             ` Avi Kivity
2006-04-25 21:08               ` Bongani Hlope
2006-04-25  4:17     ` Martin J. Bligh
2006-04-25  5:30       ` Avi Kivity
2006-04-25  8:58         ` Sam Ravnborg
2006-04-25  7:56     ` Jakob Oestergaard
2006-04-25  9:03     ` Jan Engelhardt
2006-04-24 21:36   ` J.A. Magallon
     [not found] <65Jcu-3js-23@gated-at.bofh.it>
     [not found] ` <665wi-39E-3@gated-at.bofh.it>
     [not found]   ` <669JO-WQ-59@gated-at.bofh.it>
     [not found]     ` <66fcv-Cu-9@gated-at.bofh.it>
2006-04-27 14:23       ` C++ pushback Robert Hancock
2006-04-27 14:41         ` Denis Vlasenko

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=4EE8AD21-55B6-4653-AFE9-562AE9958213@mac.com \
    --to=mrmacman_g4@mac.com \
    --cc=kononov195-far@yahoo.com \
    --cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.