기용이의 실험실 개인 지식관리 시스템

51/120

javadoc 으로 API문서 생성하기

Posted by admin

javadoc -author -version  -encoding euc-kr -charset euc-kr -docencoding euc-kr -d ./javadoc  directory/*.java

41/120

리눅스에서 CPU갯수 및 CORE얻기

Posted by admin

CHIP_COUNT=`cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l`; CHIP_CORES=`cat /proc/cpuinfo | grep "siblings" | tail -1 | cut -d: -f2`; echo "CPU: $CHIP_COUNT chips x $CHIP_CORES cores"

CPU: 2 chips x  4 cores

OS에서 물리적 CPU, 코어수, HT 알아내기.

갑자기 회사엔지니어 한분이 사무실 들오오셔서 이슈화 시켰다...

물리적 CPU 개수와 코어 수를 알고싶다는 고객이 있다는것...

/proc/cpuinfo 에대한 분석을 얘기했으나,

믿을 수 있는 방법이나 정확한 항목이 필요했다...

엔지니어들마다 의견이 분분하고, 서로가 서로의 말을 헛가려서 해대고....

한참 뒤 몇대의 서버들을 살펴 본 결과 나온 결론..

physical_id 값은 물리적 CPU 에 고유하다. 즉 id값 당 CPU 1개 이다.

sibling 값은 CPU 에들어가는 Logical CPU 값이다.

cpu_core 는 물리적 CPU 의 코어 개수이다.

HT 는 sibling 값을 cpu_core 로 나눠 1이면 Non -HT,

2의 배수 면 HT 인 것이다.

몇가지 예를 들자면,

Single CPU, Single Core, Non-HT 일 경우,
 -> Processor : 0
     Physical_id : 8
 대략 이렇게 sibling 과 코어값이 없다. 결과는 1 CPU 1Core

Single CPU, Single Core, HT 일 경우,
 -> Processor : 0 1
    Physical_id: 0 0
    sibling :      2 2
    core_id :     0 0
    cpu_cores:  1 1

Single CPU, Dual Core, Non-HT 일 경우,
 -> Processor : 0  1
     physical_id: 0  1
     sibling :     2  2
     core_id:     0  1
     cpu_cores:  2  2

Dual CPUs, Single Core, HT
 -> Processor: 0  1  2  3
   physical_id: 0  0  1  1
   sibling  :     2  2  2  2
   core_id  :   0  0  0   0
   cpu_cores:  1  1  1   1

Dual CPUs, Dual-Core, Non-HT
 -> Processor : 0   1   2   3   4   5   6   7
    physical_id: 0   0   0   0   1   1    1   1
    sibling      : 2   2   2   2   2  2   2   2
    core_id     :  0   0   1   1   2  2   3    3
    cpu_cores :  2   2   2   2   2  2   2  2

뭐 대략 이런식이니까 대강 보면 이해 가실것이다...

참고로 간단한 스크립트...

접기

#!/bin/bash
#
# Counting of Physical CPU and Core, HT
#
#
#        2009. 4. 13
#        Made by Mirr (mirr81\at(@)\gmail.com)

Info="/proc/cpuinfo"

    echo "####################################"
    echo "#### Counting of Physical CPUs ####"
    echo "####################################"

    PName=$(grep name $Info | sort -u | awk -F: '{print $2}')
    ProcNum=$(grep processor $Info | sort -u | wc -l)
    PhysCPUs=$(grep physical $Info | sort -u | wc -l)
    echo "Processor Nums : $ProcNum"

    CoreNum=$(grep cores $Info | sort -u | awk -F: '{print $2}')
    echo "Core per Processor : $CoreNum"

    sibling=$(grep "sibling" $Info | sort -u | awk -F: '{print $2}')
    echo "sibling (Logical CPUs) : $sibling"

    HT=$(expr $sibling / $CoreNum)
   
    if [ "$HT" -eq 1 ]
    then
        echo "Hyperthreding : No"
    else
        echo "Hyperthreding : Yes"
    fi

    echo "=================================="

    echo " Product Name : $PName"
    echo " Total Physical Cpus : $PhysCPUs "
    echo " Core Nums(per Processor) : $CoreNum "
exit