#!/usr/bin/bash
#
# SPDX-FileCopyrightText: Copyright (c) 2017-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#

if [ ! -r /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq ]; then
  # Cannot access cpufreq driver on BF-1 and BF-2. Use SMBios table instead.
  msg=$(dmidecode -s processor-frequency)    # showing "XXX MHz"
else
  khz=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)
  if ! [[ "$khz" =~ ^[0-9]+$ ]]; then
    echo "Error: Invalid frequency value read: $khz KHz" >&2
    exit 1
  fi
  msg="$((khz/1000)).$((khz%1000)) MHz"
fi
echo "core freq = $msg"
