Page 1 of 1

Anzahl der Prozessorkerne ermitteln

Posted: 12. Aug 2008 6:08
by pagasi
Ein Programm das ich gerade anfange zu schreiben, soll sowohl die
Anzahl der Prozessoren, wie auch die Anzahl der Prozessorkerne
eines Rechners ermittteln.

Wie macht man das ?

Ein Codeschnipsel (Sprache egal) wäre hilfreich.

Danke

Posted: 12. Aug 2008 9:19
by Janka
Bitteschön: "cat /proc/cpuinfo"
Das einlesen, parsen (total simpel), fertig.

Janka

Posted: 12. Aug 2008 10:53
by hjb
Hi!

Besser noch wäre wahrscheinlich /sys/devices/system/cpu, wo es auch Info über Topologie und Cache-Zuordnung gibt.

Zu den meisten /proc-Dateien gibt es mittlerweile ein besseres und stabileres Pendant in /sys.

Grüße,
hjb

Posted: 12. Aug 2008 11:27
by pagasi
Das werde ich heute abend gleich mal ausprobieren.

Und danke für die prompten Antworten.

Posted: 12. Aug 2008 19:50
by Janka
hjb wrote:Hi!
Besser noch wäre wahrscheinlich /sys/devices/system/cpu, wo es auch Info über Topologie und Cache-Zuordnung gibt.

Code: Select all

$ find /sys/devices/system/cpu
/sys/devices/system/cpu/
/sys/devices/system/cpu/cpu0
/sys/devices/system/cpu/cpu0/crash_notes
/sys/devices/system/cpu/cpu0/cache
/sys/devices/system/cpu/cpu0/cache/index0
/sys/devices/system/cpu/cpu0/cache/index0/type
/sys/devices/system/cpu/cpu0/cache/index0/level
/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size
/sys/devices/system/cpu/cpu0/cache/index0/physical_line_partition
/sys/devices/system/cpu/cpu0/cache/index0/ways_of_associativity
/sys/devices/system/cpu/cpu0/cache/index0/number_of_sets
/sys/devices/system/cpu/cpu0/cache/index0/size
/sys/devices/system/cpu/cpu0/cache/index0/shared_cpu_map
/sys/devices/system/cpu/cpu0/cache/index1
/sys/devices/system/cpu/cpu0/cache/index1/type
/sys/devices/system/cpu/cpu0/cache/index1/level
/sys/devices/system/cpu/cpu0/cache/index1/coherency_line_size
/sys/devices/system/cpu/cpu0/cache/index1/physical_line_partition
/sys/devices/system/cpu/cpu0/cache/index1/ways_of_associativity
/sys/devices/system/cpu/cpu0/cache/index1/number_of_sets
/sys/devices/system/cpu/cpu0/cache/index1/size
/sys/devices/system/cpu/cpu0/cache/index1/shared_cpu_map
/sys/devices/system/cpu/cpu0/cache/index2
/sys/devices/system/cpu/cpu0/cache/index2/type
/sys/devices/system/cpu/cpu0/cache/index2/level
/sys/devices/system/cpu/cpu0/cache/index2/coherency_line_size
/sys/devices/system/cpu/cpu0/cache/index2/physical_line_partition
/sys/devices/system/cpu/cpu0/cache/index2/ways_of_associativity
/sys/devices/system/cpu/cpu0/cache/index2/number_of_sets
/sys/devices/system/cpu/cpu0/cache/index2/size
/sys/devices/system/cpu/cpu0/cache/index2/shared_cpu_map
Ok, ich bekomme da andere Informationen. Ob bessere, wag ich mal zu bezweifeln.

Janka

Posted: 13. Aug 2008 5:56
by pagasi
Ich habe mich jetzt für diese Methode entschieden, die mir für meine
Zwecke am sinnvollsten erscheint.

ls /sys/devices/system/cpu/cpu? -dw1|wc -l>cores


btw.
Bei mir steht dort cpu0 bis cpu3 drin.
Was bei eiiner Quadcore-CPU (die mein Rechner hat) auch richtig wäre.
Wenn man unterstellt, dass jedes dieser Verzeichnisse cpu(x) einen
Prozessorkern repräsentiert.

übermorgen

Posted: 13. Aug 2008 17:57
by haha
Moin,

aber bei 10 Prozessoren geht dies dann nicht mehr ;-)

Aber damit:
ls -1 /sys/devices/system/cpu|grep [0-9]|wc -l


bye

Posted: 27. Aug 2008 7:38
by jochen
Schau mal in diesen RH-Knowledgebase-Artikel hier: -> http://kbase.redhat.com/faq/FAQ_46_10715.shtm
Der erläutert m.E. sehr schön, wie der Kernel zwischen Hyperthreading, Cores und Prozessoren (als physische Einheit/Baustein) unterscheidet. Mit den dortigen Infos kann man exakt unterscheiden, ob man beispielsweise 2 Cores in einem Prozessorgehäuse oder 2 Prozessorgehäuse mit jeweils einem Core hat.

Viel Spass beim Auseinanderfitzeln der Daten,
Jochen