Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Inaccurate CPU core count & frequency reporting in distro_info.sh on multi-core systems with E & P cores #4522

Open
MicLieg opened this issue Mar 3, 2024 · 0 comments

Comments

@MicLieg
Copy link
Contributor

MicLieg commented Mar 3, 2024

User story

As an admin, I want the distro_info.sh script to accurately report the frequencies and # of all CPU cores, including both E and P cores.

Game

All

Linux distro

Ubuntu 22.04

Command

command: details

Further information

The script distro_info.sh currently has limitations in accurately reporting CPU information for systems with hybrid architectures that include both Efficiency (E-cores) and Performance (P-cores) cores and systems that support Multithreading.

The bugs can be found in the output of ./gameserver details.
Screenshot

CPU Frequency Reporting:

The script uses a method to fetch the CPU frequency that does not account for the differing frequencies of E and P cores. It only captures the frequency of a single core, which can lead to misleading information about the system's capabilities: info_distro.sh#L142

cpufreqency="$(awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]//;s/[ \t]$//')" # e.g 2394.503

This should be updated to reflect a more accurate representation of the system's CPU frequencies, especially for hybrid architectures.

  • A possible solution would be to list the number of cores running at different frequencies:
declare -A freq_count

# Loop through each core and collect frequencies
while IFS=: read -r label cpu_id; do
    cpu_freq=$(awk -v id="$cpu_id" '$1 == "processor" {p=$3} $1 == "cpu" && $2 == "MHz" && p == id {print $4; exit}' /proc/cpuinfo)
    ((freq_count[$cpu_freq]++))
done < <(awk -F: '/processor/ {print $1 ":" $2}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')

# Sort by frequency
for freq in "${!freq_count[@]}"; do
    echo "$freq ${freq_count[$freq]}"
done | sort -rn -k1,1 | awk '{print $2"x " $1 " MHz"}' | paste -sd, - | sed 's/,/, /g'
  • Or use the average frequency of all cores:
# Initialize sum of frequencies and core count
total_freq=0
core_count=0
    
# Loop through each core
for cpu_id in $(awk -F: '/processor/ {print $2}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//'); do
    # Extract the frequency of the current core
    cpu_freq=$(awk -v id="$cpu_id" '$1 == "processor" {p=$3} $1 == "cpu" && $2 == "MHz" && p == id {print $4; exit}' /proc/cpuinfo)
    # Add the frequency to the total
    total_freq=$(echo "$total_freq + $cpu_freq" | bc)
    # Increment the core count
    core_count=$((core_count + 1))
done
    
# Calculate the average frequency
if [ $core_count -gt 0 ]; then
    avg_freq=$(echo "scale=2; $total_freq / $core_count" | bc)
    echo "Average CPU Frequency: $avg_freq MHz"
fi

CPU Core Count Reporting

Additionally, the script inaccurately reports the total number of CPU cores in systems with hybrid architectures. For example, on an Intel i7-13700K, which has 16 physical cores (8 E-cores and 8 P-cores), the script reports a total of 24 cores. This discrepancy arises from the following line: info_distro.sh#141

cpucores="$(awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo)"

This is likely to be an issue of how logical cores are counted versus physical cores, especially in the context of Intel's Thread Director technology, which can present more logical processors to the operating system than the physical core count.

  • The solution is to use the value of cpu cores listed in /proc/cpuinfo:
cpucores="$(awk -F': ' '/cpu cores/ {print $2; exit}' /proc/cpuinfo)"

Relevant log output

No response

Steps to reproduce

These bugs might only arise on bare metal servers

  1. Install any gameserver
  2. Run ./gameserver details
    • Wrong number of cores displayed (if CPU supports Hyperthreading)
    • Only the frequency of a single core is displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🆕 New Issues
Development

No branches or pull requests

1 participant