r/linux • • Nov 07 '18

Fluff Lines of code in the Linux kernel

Post image
1.2k Upvotes

169 comments sorted by

View all comments

225

u/saitilkE Nov 07 '18

That's a lot of drivers.

Thanks for this, quite interesting!

167

u/equeim Nov 07 '18

Compiling the kernel with Ubuntu's or Fedora's config (which includes most driver) take ~1.5 hours on a modern machine. Compiling the kernel with drivers only for your hardware takes ~1.5 minutes.

54

u/aes_gcm Nov 07 '18

How does one compile it for only the current hardware?

105

u/[deleted] Nov 07 '18

You can run make localmodconfig in the kernel to build with only what is currently loaded (and you probably want to enable a few more on top of that for removable devices, etc).

19

u/[deleted] Nov 07 '18

How long has that been around?

31

u/dbbo Nov 07 '18

I remember using it on Debian Lenny, so probably about decade at least.

→ More replies (1)

2

u/[deleted] Nov 11 '18

Can be tedious to manually pick needed modules, so it can be useful to collect any loaded modules from a running kernel using something like this, i whipped that up quite a few years back and have been using it to track what modules my hardware needs ever since.

eg; if you get a new piece of hardware, boot into your distros kernel, run that script whilst relevant modules had been autoloaded by that kernel, then recompile your localmodconfig kernel, which will then have the relevant new modules.

Saves so much time not waiting for hundreds of modules that you'll never need.

→ More replies (4)

22

u/Shok3001 Nov 07 '18

A few years ago I tried compiling the kernel on an old PowerPC mac that I installed linux on. It took all day. Should have done this!

→ More replies (1)

10

u/geppetto123 Nov 07 '18

So how do Linux kernel programmers do their test? Sounds like debugging take ages if you have to try different approaches...

29

u/jms87 Nov 07 '18

Linux kernel programmers would already have most of it compiled. Only changed files and their dependencies would be compiled every time.

3

u/bigbadsubaru Dec 28 '18

I test Linux kernel drivers, and one of my test boxes has four 8 core Xeons (64 total logical cores) building the kernel, even if I do a "make allmodconfig" (builds everything as a loadable module) if I tell make to use all cores (make -j65) it builds the whole thing in 5 minutes or so.

2

u/Guy1524 Apr 13 '19

Jesus christ, that's a lot of threads.

11

u/[deleted] Nov 07 '18

Like all large c / c++ projects. There is an initial first build time and a rebuild time. Then there is also ccache which speeds things up massively.

For kernel specific stuff normally you do something like a network pxe boot. So when the compile is complete you just press the reset button on the other machine.

Debugging the kernel is hard. But... When your doing that stuff you mostly know what your doing so normally your debugging something awkward like hardware that does not behave as documented (this is very common!)

→ More replies (3)

7

u/coder111 Nov 07 '18

Well, on a decent 64 core machine, you can build it in under a minute...

See Phoronix for benchmarks.

→ More replies (2)
→ More replies (1)

6

u/buttux Nov 08 '18

Maybe single threaded, but a modern machine has more than a few CPUs. Add -j with 2x your cpu count to your 'make' for a more reasonable build time. My dev box has 64 threads, an allconfig 'make' is maybe 5 minutes.

3

u/Twirrim Nov 07 '18

Why on earth does it take 1.5 hours? Even on 4 core VMs I've been compiling full upstream kernels faster than that (while using Ubuntu's kernel config file)

6

u/newhacker1746 Nov 07 '18

For me on Ubuntu 18.04 compiling a 4.20-rc1 kernel with ubuntu’s .config, on an e5645 hex core OC’d to 3.21ghz, make -j 12 bindeb-pkg takes about 15 minutes.

3

u/equeim Nov 07 '18

Hmm, I may have confused it with 0.5h, I didn't compile kernel with full config for a long time.

3

u/throwawayPzaFm Nov 07 '18

Or maybe you forgot -j

→ More replies (4)

7

u/udoprog Nov 07 '18

Thank you!

7

u/TomahawkChopped Nov 07 '18

Or most driver code could be monstrous piles of complexity with tons of tech debt

Edit: I'm not saying this is true, just commenting on the signal loss from just counting lines of code

16

u/[deleted] Nov 07 '18

It actually tons of other people's tech debt for workaround's for hardware that does not work correctly or behaves in strange ways.

Other than that its actually quite clean. I actually prefer working with most of the kernel code cause it written by people who mostly know what they are doing.

→ More replies (1)