27239 HOWTO: FreeBSD with CCACHE - Page 2 - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Miscellaneous > Howtos & FAQs (Moderated)

Howtos & FAQs (Moderated) Would you like to share some of your solutions for certain problems? Tips or tricks? Post here. All new topics are automatically moderated.

Reply
 
Thread Tools Display Modes
  #26  
Old August 9th, 2010, 17:42
camelia camelia is offline
Junior Member
 
Join Date: Aug 2010
Posts: 43
Thanks: 2
Thanked 8 Times in 7 Posts
Default

BTW, I'd suggest using `?=' everywhere. It leaves the chance to override value from environ(7) without touching make.conf.

As for port's gcc there are few pitfalls but libmap.conf addresses only runtime linking problem completely avoiding build linking one (rtld vs. ld). BTW, using CPUTYPE?=native should work for any GCC (newer than gcc3*) and clang. If you're after more portable binaries then you'd want to use -mtune=generic but there is no make(1) macro for it.
Reply With Quote
  #27  
Old September 1st, 2010, 21:18
Seeker's Avatar
Seeker Seeker is offline
Member
 
Join Date: May 2009
Location: Europe/Croatia/Zagreb
Posts: 834
Thanks: 13
Thanked 11 Times in 10 Posts
Default

I have 2 questions:

1) Why exactly, do we have to recompile, devel/libtool22, after we change CC and CXX? What are the consequences, of not doing so?

2) WITH ccache, I did a buildkernel and it took 43 min, to finish. Without ccache it took 39 min, to finish.
Then mistakenly, I've issued a same command again and ONLY then it did compiled in 9 minutes!
So, this means that ccache, speeds up RE-compilation, not a initial compilation, which can be even slower!
Now, as far as I know for myself, after build, I go for install.
I can't imagine, even one scenario, where I would go and build already build thing once again.
Reply With Quote
  #28  
Old September 2nd, 2010, 00:09
wblock@'s Avatar
wblock@ wblock@ is offline
Moderator
 
Join Date: Sep 2009
Location: Milky Way galaxy
Posts: 7,725
Thanks: 432
Thanked 1,762 Times in 1,459 Posts
Default

Quote:
Originally Posted by Seeker View Post
2) WITH ccache, I did a buildkernel and it took 43 min, to finish. Without ccache it took 39 min, to finish.
Then mistakenly, I've issued a same command again and ONLY then it did compiled in 9 minutes!
So, this means that ccache, speeds up RE-compilation, not a initial compilation, which can be even slower!
Same as a browser cache. The first time you go to that page, it's a little slower because it has to cache everything. Second time, it only retrieves the things that have changed, so it's faster. Yes, there's some added overhead in saving the cached files, but it's usually faster than retrieving them again.

Quote:
Now, as far as I know for myself, after build, I go for install.
I can't imagine, even one scenario, where I would go and build already build thing once again.
When you buildworld or kernel, odds are good that a lot of it hasn't changed since the last time it was built, even weeks or months ago. How much has changed depends on how long it's been since you last built world. Next time you buildworld, time it again. If it takes less than 35 minutes (39 minutes normal minus the four already lost to overhead)... you win! After that, anything less than 39 minutes is pure win.
Reply With Quote
  #29  
Old September 2nd, 2010, 00:37
Seeker's Avatar
Seeker Seeker is offline
Member
 
Join Date: May 2009
Location: Europe/Croatia/Zagreb
Posts: 834
Thanks: 13
Thanked 11 Times in 10 Posts
Default

Quote:
Originally Posted by wblock View Post
When you buildworld or kernel, odds are good that a lot of it hasn't changed since the last time it was built, even weeks or months ago. How much has changed depends on how long it's been since you last built world. Next time you buildworld, time it again. If it takes less than 35 minutes (39 minutes normal minus the four already lost to overhead)... you win! After that, anything less than 39 minutes is pure win.
Well I did timed it here and after initial kernel compilation of 43 min, RE-compilation was done in 9 min.
Which is almost, 5 times better, performance boost.

Even few months?!
In that time frame, I would do many, many compilations, of various ports, etc...
Perhaps, a dedicated HDD, just for CCACHE_DIR /var/tmp/ccache, would suffice?
Reply With Quote
  #30  
Old September 2nd, 2010, 06:48
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,193
Thanks: 59
Thanked 633 Times in 349 Posts
Default

@Seeker

These are mine ccache stats after about 12 months of usage:
Code:
% zfs list basefs/var/ccache
NAME                USED  AVAIL  REFER  MOUNTPOINT
basefs/var/ccache   575M   569G   575M  /var/ccache

% ccache -s
cache directory                     /var/ccache
cache hit                          17306
cache miss                         43982
called for link                     5148
multiple source files                  5
compile failed                      3107
preprocessor error                   819
not a C/C++ file                    3423
autoconf compile/link               3957
unsupported compiler option         1221
no input file                       1343
files in cache                     87964
cache size                           1.1 Gbytes
max cache size                       4.0 Gbytes
Also, if You limit it to 1GB in config, then it will STAY 1GB size.
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com
Reply With Quote
  #31  
Old September 4th, 2010, 03:26
ohauer ohauer is offline
Member
 
Join Date: Aug 2009
Posts: 108
Thanks: 1
Thanked 11 Times in 11 Posts
Default

Quote:
Originally Posted by Seeker View Post
I can't imagine, even one scenario, where I would go and build already build thing once again.
Hm, think about you maintain some ports and you will test all different build options
or you patch parts of the source, generate the patchfiles and build again ...

With usage of CCACHE the configure scripts are the main bottleneck for me, and I have similar values like vermaden.
Reply With Quote
  #32  
Old September 4th, 2010, 11:58
Nomacoro Nomacoro is offline
Junior Member
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i cant open the link. what is the matter?
Reply With Quote
  #33  
Old September 4th, 2010, 18:18
camelia camelia is offline
Junior Member
 
Join Date: Aug 2010
Posts: 43
Thanks: 2
Thanked 8 Times in 7 Posts
Default

Quote:
Originally Posted by ohauer View Post
think about you maintain some ports and you will test all different build options
or you patch parts of the source, generate the patchfiles and build again
Most of the time changing configure options affects config.h or CFLAGS that cause cache misses during build.
Reply With Quote
  #34  
Old May 3rd, 2011, 19:22
Beeblebrox's Avatar
Beeblebrox Beeblebrox is offline
Member
 
Join Date: Sep 2010
Posts: 713
Thanks: 39
Thanked 76 Times in 68 Posts
Default ccache with GCC45

I am using gcc45 for ports, native (gcc42) for source. Therefore the conditional statement in make.conf needs to be a little different for my setup. After some debugging, I seem to have found the correct settings for my make.conf
Code:
.if !empty{.CURDIR:M/usr/ports/*}
CC=  /usr/local/libexec/ccache/world/gcc45
CXX= /usr/local/libexec/ccache/world/g++45
CFLAGS+= -mssse3
.else 
CC=  /usr/local/libexec/ccache/world/cc
CXX= /usr/local/libexec/ccache/world/c++
.endif

.if ${.CURDIR:M*/ports/devel/ccache}
  NO_CCACHE= yes
  CC= gcc45
  CXX= g++45
  CPP= cpp45
  CFLAGS+= -mssse3
.endif
Check your /usr/local/libexec/ccache/world/ directory and make sure you have all of the above named files in the folder. These of course, are not files but soft-links to the ccache file in the same folder. If you do not have such links, create them (#ln -s) with the appropriate names specified here (ccache should have created them already though).

Whenever you change (upgrade) ccache versions or add a different compiler (say you switched form 4.5 to 4.6 or such) you must re-build devel/libtool, otherwise you will see "precompiler fails sanity check" messages.
__________________
branch:head - root on zfs - amd64
BLUES, ELWOOD
ILLINOIS LICENSE : B263-1655-2187
CURRENTLY UNDER SUSPENSION
WARRANTS OUTSTANDING : PARKG. 116
MOVING VIOLATIONS : 56
ARREST DRIVER ... IMPOUND VEHICLE

Last edited by Beeblebrox; June 14th, 2011 at 13:14. Reason: corrections to ccache/world
Reply With Quote
  #35  
Old May 6th, 2011, 01:26
qsecofr qsecofr is offline
Member
 
Join Date: Mar 2009
Location: PDX
Posts: 198
Thanks: 27
Thanked 8 Times in 8 Posts
Default

I needed to edit /etc/make.conf as suggested by Beeblebrox:
Code:
CC=  /usr/local/libexec/ccache/world/cc
  CXX= /usr/local/libexec/ccache/world/c++
The original suggestion had dashes instead of forward slashes. Not sure if the original was a typo or worked as intended on author's system. I'm using FreeBSD 8.1-Release.

Also replies suggested building libtool15. I have a more recent version. Not sure if that needs rebuilding, but I did. Was there anything version-specific about that recommendation?

It would have been good if the HOWTO referenced /usr/local/share/doc/ccache/ccache-howto-freebsd.txt and explained any differences.

I agree with Seeker in that a distinction exists between compilation vs. re-compilation. I have no idea how many times I re-compile the same version of the same port. Not by intent anyway - I leave that decision up to portmaster and or make. But I'm hopeful the tool has finer granularity than just overall port version. I'll probably know the next time I upgrade KDE. Maybe.

Last edited by qsecofr; May 6th, 2011 at 01:34. Reason: trying to highlight the slashes
Reply With Quote
  #36  
Old May 6th, 2011, 03:18
wblock@'s Avatar
wblock@ wblock@ is offline
Moderator
 
Join Date: Sep 2009
Location: Milky Way galaxy
Posts: 7,725
Thanks: 432
Thanked 1,762 Times in 1,459 Posts
Default

Quote:
Originally Posted by qsecofr View Post
I agree with Seeker in that a distinction exists between compilation vs. re-compilation. I have no idea how many times I re-compile the same version of the same port. Not by intent anyway - I leave that decision up to portmaster and or make. But I'm hopeful the tool has finer granularity than just overall port version. I'll probably know the next time I upgrade KDE. Maybe.
Benchmark it. Set NO_CCACHE and time a build. Reboot to clear the filesystem cache, leave ccache enabled, and build it again. My guess for port updates is that ccache usually won't have it in the cache and will actually make port builds a little slower.

/usr/src doesn't change all that much from week to week, but there can still be a lot of cache misses caused by small changes.

Last edited by DutchDaemon; May 6th, 2011 at 04:22.
Reply With Quote
  #37  
Old May 6th, 2011, 09:07
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,193
Thanks: 59
Thanked 633 Times in 349 Posts
Default

Quote:
Originally Posted by wblock View Post
My guess for port updates is that ccache usually won't have it in the cache and will actually make port builds a little slower.
CCACHE is useful if you compile something at least TWO TIMES; the first time it's slower because it 'learns', the second and every other compile run is a lot faster. Not the first one.
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com

Last edited by DutchDaemon; May 7th, 2011 at 01:55.
Reply With Quote
  #38  
Old May 6th, 2011, 15:36
wblock@'s Avatar
wblock@ wblock@ is offline
Moderator
 
Join Date: Sep 2009
Location: Milky Way galaxy
Posts: 7,725
Thanks: 432
Thanked 1,762 Times in 1,459 Posts
Default

Quote:
Originally Posted by vermaden View Post
CCACHE is useful if you compile something at least TWO TIMES; the first time it's slower because it 'learns', the second and every other compile run is a lot faster. Not the first one.
Of course. But do you think the cached version of KDE will still be in the cache by the time the next version comes out? And how much of it will be valid because the source hasn't changed? If it's not in the cache or invalid, the overhead of ccache will slow you down, and I suspect that will be the case most of the time with ports. Maybe a really big cache size would help. ccache -s will tell the story.

Last edited by DutchDaemon; May 7th, 2011 at 01:55.
Reply With Quote
  #39  
Old May 6th, 2011, 22:04
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,193
Thanks: 59
Thanked 633 Times in 349 Posts
Default

I would say that if you compile a lot and have a quite large ccache space (4-8G) then the more you compile, the faster it will be, at least I got that impression after longer usage. Currently I only use packages and compile as little as possible, so I do not even bother with setting up CCACHE anymore.
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com

Last edited by DutchDaemon; May 7th, 2011 at 01:56.
Reply With Quote
  #40  
Old November 11th, 2011, 00:33
bbzz bbzz is offline
Member
 
Join Date: Nov 2010
Location: random
Posts: 826
Thanks: 77
Thanked 119 Times in 79 Posts
Default

I have a habit of compiling everything as soon as it's updated. When I'm building as root it works. When I'm building as user using sudo it never uses CCACHE.

The configuration for root is in ~/.cshrc. The configuration for user is in ~/.zshrc. The configuration is identical, minus shell semantics, and both point to same CCACHE location, /var/db/ccache. So the both $PATH are equal.

Since I use sudo with user to update ports and build, CCACHE is never used. What do I need to do to make this work?

p.s. great guide as always.

Last edited by bbzz; November 11th, 2011 at 01:01.
Reply With Quote
  #41  
Old November 11th, 2011, 01:39
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,193
Thanks: 59
Thanked 633 Times in 349 Posts
Default

Edit the /usr/local/etc/sudoers file and add needed variables that should be kept when using sudo(8), for example:
Code:
Defaults        env_keep += "HOME PKG_PATH PKG_DBDIR PKG_TMPDIR TMPDIR PACKAGEROOT PACKAGESITE PACKAGES PKGDIR FTP_PASSIVE_MODE"
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com
Reply With Quote
  #42  
Old November 11th, 2011, 01:59
bbzz bbzz is offline
Member
 
Join Date: Nov 2010
Location: random
Posts: 826
Thanks: 77
Thanked 119 Times in 79 Posts
Default

Tried, but that doesn't help.
There is no update when I check cache with:
# ccache -s
Whereas, when run as root it get updated.

EDIT: I just realized that when using sudo user uses /root/.ccache.
EDIT2: Hence, fixed! Thx.

Last edited by bbzz; November 11th, 2011 at 02:16.
Reply With Quote
  #43  
Old November 11th, 2011, 08:30
graudeejs's Avatar
graudeejs graudeejs is offline
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,525
Thanks: 422
Thanked 607 Times in 475 Posts
Default

That's because If you use shared ccache you'll probably have permissions issues
Reply With Quote
  #44  
Old November 11th, 2011, 15:15
bbzz bbzz is offline
Member
 
Join Date: Nov 2010
Location: random
Posts: 826
Thanks: 77
Thanked 119 Times in 79 Posts
Default

I changed permissions there. For some reason it only works when configuration is defined in both my user's ~/.zshrc AND settings forwarded in visudo.
If it's only configured in ~/.zshrc, but not in visudo (CCACHE_PATH, CCACHE_DIR), it uses default /root/.ccache location. If it's only defined in root's ~/.cshrc and forwarded with visudo, (so nothing defined in user's ~/.zshrc), then it uses user's default location, ~/home/$user/.ccache.
I don't get this, but I got it to work.
Reply With Quote
  #45  
Old May 1st, 2012, 22:59
graudeejs's Avatar
graudeejs graudeejs is offline
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,525
Thanks: 422
Thanked 607 Times in 475 Posts
Default

Quote:
Originally Posted by vermaden View Post
install ccache port or add a package:
Code:
.if !defined(NO_CCACHE)
  CC=  /usr/local/libexec/ccache/world-cc
  CXX= /usr/local/libexec/ccache/world-c++
.endif
This should be updated to

Code:
.if !defined(NO_CCACHE)
  CC=  /usr/local/libexec/ccache/world/cc
  CXX= /usr/local/libexec/ccache/world/c++
.endif
Reply With Quote
  #46  
Old May 1st, 2012, 23:21
wblock@'s Avatar
wblock@ wblock@ is offline
Moderator
 
Join Date: Sep 2009
Location: Milky Way galaxy
Posts: 7,725
Thanks: 432
Thanked 1,762 Times in 1,459 Posts
Default

The port suggests
Code:
.if (!empty(.CURDIR:M/usr/src*) || !empty(.CURDIR:M/usr/obj*))
.if !defined(NOCCACHE)
CC:=${CC:C,^cc,/usr/local/libexec/ccache/world/cc,1}
CXX:=${CXX:C,^c\+\+,/usr/local/libexec/ccache/world/c++,1}
.endif
.endif
Reply With Quote
  #47  
Old May 2nd, 2012, 06:00
graudeejs's Avatar
graudeejs graudeejs is offline
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,525
Thanks: 422
Thanked 607 Times in 475 Posts
Default

Quote:
Originally Posted by wblock@ View Post
The port suggests
Code:
.if (!empty(.CURDIR:M/usr/src*) || !empty(.CURDIR:M/usr/obj*))
.if !defined(NOCCACHE)
CC:=${CC:C,^cc,/usr/local/libexec/ccache/world/cc,1}
CXX:=${CXX:C,^c\+\+,/usr/local/libexec/ccache/world/c++,1}
.endif
.endif
Yes, btw, I use
Code:
WRKDIRPREFIX=/usr/obj
When I used
Code:
if (!empty(.CURDIR:M/usr/src*) || !empty(.CURDIR:M/usr/obj/usr/src*))
...
.endif
it (ccache) didn't work. Any idea why?

Last edited by DutchDaemon; May 2nd, 2012 at 16:40.
Reply With Quote
  #48  
Old May 2nd, 2012, 13:17
wblock@'s Avatar
wblock@ wblock@ is offline
Moderator
 
Join Date: Sep 2009
Location: Milky Way galaxy
Posts: 7,725
Thanks: 432
Thanked 1,762 Times in 1,459 Posts
Default

That line uses ccache only for building the system. That's pretty reasonable, it's rare that ccache will help with building ports.

Last edited by DutchDaemon; May 2nd, 2012 at 16:41.
Reply With Quote
  #49  
Old May 2nd, 2012, 15:48
bbzz bbzz is offline
Member
 
Join Date: Nov 2010
Location: random
Posts: 826
Thanks: 77
Thanked 119 Times in 79 Posts
Default

Code:
.if (!empty(.CURDIR:M/usr/src*) || !empty(.CURDIR:M/usr/obj/usr/src/*))
.if !defined(NOCCACHE)
CC:=${CC:C,^cc,/usr/local/libexec/ccache/world/cc,1}
CXX:=${CXX:C,^c\+\+,/usr/local/libexec/ccache/world/c++,1}
.endif
.endif
So this is the correct way to specify ccache only for world building and not ports? Is there an optimum size for ccache maybe?

Last edited by DutchDaemon; May 2nd, 2012 at 16:41.
Reply With Quote
  #50  
Old May 2nd, 2012, 17:58
wblock@'s Avatar
wblock@ wblock@ is offline
Moderator
 
Join Date: Sep 2009
Location: Milky Way galaxy
Posts: 7,725
Thanks: 432
Thanked 1,762 Times in 1,459 Posts
Default

I've used sizes of 1G to 4G, and more really doesn't help. Either nothing major has changed in the source and it mostly comes from cache, or something major or minor has changed that invalidates all of the cache, and everything has to be rebuilt.
Reply With Quote
Reply

Tags
ccache, kiss

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HOWTO: FreeBSD CPU Scaling and Power Saving vermaden Howtos & FAQs (Moderated) 47 December 30th, 2011 15:25


All times are GMT +1. The time now is 19:34.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0