tmdgusya / woowa-os-study

이 리포지토리는 우아한 스터디 "그림으로 배우는 리눅스 구조" 예시 코드 및 학습용으로 사용됩니다.
5 stars 4 forks source link

p232 표08-02 처럼 각자의 리눅스 환경의 정보 출력하기 #18

Open SINHOLEE opened 1 month ago

SINHOLEE commented 1 month ago

쥐피티가 도와줬어요

#!/bin/sh

# CPU 개수 확인
cpu_count=$(ls /sys/devices/system/cpu/ | grep -c '^cpu[0-9]\+$')

# 캐시 인덱스 개수 확인 (CPU0 기준)
cache_count=$(ls /sys/devices/system/cpu/cpu0/cache/ | grep -c '^index[0-9]\+$')

# 헤더 파일 리스트 수집
header_files=""
for file in /sys/devices/system/cpu/cpu0/cache/index0/*; do
    if [ -f "$file" ]; then
        header_files="$header_files $(basename "$file")"
    fi
done

# 각 CPU의 캐시 정보 수집 및 출력
i=0
while [ $i -lt $cpu_count ]; do
    echo "CPU $i:"
    j=0
    while [ $j -lt $cache_count ]; do
        echo -n "  Index $j: "
        for header in $header_files; do
            value=$(cat /sys/devices/system/cpu/cpu$i/cache/index$j/$header 2>/dev/null || echo "N/A")
            echo -n "$header=$value "
        done
        echo
        j=$((j+1))
    done
    echo
    i=$((i+1))
done
SINHOLEE commented 1 month ago

결과

CPU 0:
  Index 0: level=1 shared_cpu_list=0 shared_cpu_map=001 type=Data uevent=
  Index 1: level=1 shared_cpu_list=0 shared_cpu_map=001 type=Instruction uevent=
  Index 2: level=2 shared_cpu_list=0-9 shared_cpu_map=3ff type=Unified uevent=

CPU 1:
  Index 0: level=1 shared_cpu_list=1 shared_cpu_map=002 type=Data uevent=
  Index 1: level=1 shared_cpu_list=1 shared_cpu_map=002 type=Instruction uevent=
  Index 2: level=2 shared_cpu_list=0-9 shared_cpu_map=3ff type=Unified uevent=

CPU 2:
  Index 0: level=1 shared_cpu_list=2 shared_cpu_map=004 type=Data uevent=
  Index 1: level=1 shared_cpu_list=2 shared_cpu_map=004 type=Instruction uevent=
  Index 2: level=2 shared_cpu_list=0-9 shared_cpu_map=3ff type=Unified uevent=

CPU 3:
  Index 0: level=1 shared_cpu_list=3 shared_cpu_map=008 type=Data uevent=
  Index 1: level=1 shared_cpu_list=3 shared_cpu_map=008 type=Instruction uevent=
  Index 2: level=2 shared_cpu_list=0-9 shared_cpu_map=3ff type=Unified uevent=

CPU 4:
  Index 0: level=1 shared_cpu_list=4 shared_cpu_map=010 type=Data uevent=
  Index 1: level=1 shared_cpu_list=4 shared_cpu_map=010 type=Instruction uevent=
  Index 2: level=2 shared_cpu_list=0-9 shared_cpu_map=3ff type=Unified uevent=

CPU 5:
  Index 0: level=1 shared_cpu_list=5 shared_cpu_map=020 type=Data uevent=
  Index 1: level=1 shared_cpu_list=5 shared_cpu_map=020 type=Instruction uevent=
  Index 2: level=2 shared_cpu_list=0-9 shared_cpu_map=3ff type=Unified uevent=

CPU 6:
  Index 0: level=1 shared_cpu_list=6 shared_cpu_map=040 type=Data uevent=
  Index 1: level=1 shared_cpu_list=6 shared_cpu_map=040 type=Instruction uevent=
  Index 2: level=2 shared_cpu_list=0-9 shared_cpu_map=3ff type=Unified uevent=

CPU 7:
  Index 0: level=1 shared_cpu_list=7 shared_cpu_map=080 type=Data uevent=
  Index 1: level=1 shared_cpu_list=7 shared_cpu_map=080 type=Instruction uevent=
  Index 2: level=2 shared_cpu_list=0-9 shared_cpu_map=3ff type=Unified uevent=

CPU 8:
  Index 0: level=1 shared_cpu_list=8 shared_cpu_map=100 type=Data uevent=
  Index 1: level=1 shared_cpu_list=8 shared_cpu_map=100 type=Instruction uevent=
  Index 2: level=2 shared_cpu_list=0-9 shared_cpu_map=3ff type=Unified uevent=

CPU 9:
  Index 0: level=1 shared_cpu_list=9 shared_cpu_map=200 type=Data uevent=
  Index 1: level=1 shared_cpu_list=9 shared_cpu_map=200 type=Instruction uevent=
  Index 2: level=2 shared_cpu_list=0-9 shared_cpu_map=3ff type=Unified uevent=

보면 캐시라인 크기와 size를 알 수 없던데,

캐시라인 크기는 getconf LEVEL1_DCACHE_LINESIZE 로 확인할 수 있더라구요