Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
how to know how many cpu core?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
concord
Apprentice
Apprentice


Joined: 02 Oct 2005
Posts: 193

PostPosted: Fri Jun 06, 2008 2:41 pm    Post subject: how to know how many cpu core? Reply with quote

Dear friends:

I have installed a gentoo on usb hard disk and I have used it on PIII, P4, amd and multi-cpu/core computer. When compile system or program, I aways re-nano MAKEOPTS in make.conf. So, I want to know, how can I compose the make.conf to adjust the "-j*" automatically? I mean let gentoo know the cpu # and change "-j*" itself. Thanks in advance!
_________________
AMD64 Desktop
Pentium4 Laptop
Pentium3 Server
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54317
Location: 56N 3W

PostPosted: Fri Jun 06, 2008 3:30 pm    Post subject: Reply with quote

concord,

Have a file say /etc/make.template with no MAKEOPTS which you copy to /etc/make.conf every boot
Parse /proc/cpuinfo in a script to discover how many CPUs you seem to have (they count from 0)
based on that, add a suitable MAKEOPTS to /etc/make.conf

Put the script into /etc/conf.d/local.start, or call it from there.

Your kernel needs SMP support for the maximum number of cores you will ever want to use.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
HyperQuantum
Tux's lil' helper
Tux's lil' helper


Joined: 27 Sep 2005
Posts: 88

PostPosted: Fri Jun 06, 2008 3:34 pm    Post subject: Reply with quote

NeddySeagoon wrote:

Parse /proc/cpuinfo in a script to discover how many CPUs you seem to have (they count from 0)


Something like this?
Code:
cat /proc/cpuinfo | grep '^processor' | wc -l

Correctly returns the number 2 on my laptop.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9691
Location: almost Mile High in the USA

PostPosted: Fri Jun 06, 2008 8:42 pm    Post subject: Reply with quote

The script will need to carefully parse /proc/cpuinfo, a simple grep won't work to separate multithread processors properly.

A simple grep for "processor" will report that my hyperthread P4 to have two cores, which is not the case - it can run two threads but only has one core (hyperthreading).

It'd be even worse for multisocket machines that have asymmetric parts in the machine (what if it were possible to put a P4-multithread and a Q6600 in the same machine?) /proc/cpuinfo would be really weird...
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6051
Location: Removed by Neddy

PostPosted: Fri Jun 06, 2008 8:52 pm    Post subject: Reply with quote

HyperQuantum wrote:
NeddySeagoon wrote:

Parse /proc/cpuinfo in a script to discover how many CPUs you seem to have (they count from 0)


Something like this?
Code:
cat /proc/cpuinfo | grep '^processor' | wc -l

Correctly returns the number 2 on my laptop.


1) don't use cat like that, cat is for joining files
2) don't use grep like that, grep can accept a file as an input:
Code:
cat /proc/cpuinfo | grep '^processor' | wc -l


and as stated false-positive occur

Code:
grep "Initializing CPU" <(dmesg) | wc -l

should be better
_________________
Quote:
Removed by Chiitoo
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Fri Jun 06, 2008 11:09 pm    Post subject: Reply with quote

Naib wrote:
Code:
grep "Initializing CPU" <(dmesg) | wc -l

the wc -l is dispensable, better use
Code:
grep -c "Initializing CPU" <(dmesg)

_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
concord
Apprentice
Apprentice


Joined: 02 Oct 2005
Posts: 193

PostPosted: Sat Jun 07, 2008 6:23 pm    Post subject: Reply with quote

Thanks very much for your help. parse dmesg is a good idea.
_________________
AMD64 Desktop
Pentium4 Laptop
Pentium3 Server
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum