🛠 Premier script Python : santé de la carte

Hardkernel ODROID-XU4 (Samsung Exynos5422) · debutant · Schéma : IMG-odroid-xu4-debutant-3-odroidxu4-premier-script-python.svg — Écran de terminal affichant un script Python listant les 8 cœurs big.LITTLE de l'Exynos5422 et les températures de l'ODROID-XU4

Objectives

Write a first Python script that displays the health of the ODROID-XU4: the 8 cores of the Exynos5422 (4 Cortex-A15 up to 2.0 GHz + 4 Cortex-A7 up to 1.4 GHz, big.LITTLE) and the temperatures of the thermal sensors exposed by the mainline kernel. Python 3 is preinstalled on Armbian.

Hardware

Complete code

#!/usr/bin/env python3
"""sante.py — inventaire CPU big.LITTLE + temperatures sur XU4."""
import glob

def lire(chemin):
    try:
        with open(chemin) as f:
            return f.read.strip
    except OSError:
        return "n/a"

print("== CPUs en ligne ==")
print(lire("/sys/devices/system/cpu/online"))   # attendu: 0-7

print("== Frequences max par cluster (kHz) ==")
for p in sorted(glob.glob("/sys/devices/system/cpu/cpufreq/policy*/cpuinfo_max_freq")):
    print(p.split("/")[5], lire(p))             # 2000000 (A15) / 1400000 (A7)

print("== Temperatures ==")
for z in sorted(glob.glob("/sys/class/thermal/thermal_zone*")):
    t = lire(z + "/type")
    v = lire(z + "/temp")
    if v != "n/a":
        print(f"{t}: {int(v)/1000:.1f} C")

Run: python3 sante.py.

Expected output

The script displays 0-7 (the 8 cores are utilized in HMP under mainline), two frequency policies with maximums of 2000000 kHz (A15 cluster) and 1400000 kHz (A7 cluster), followed by one temperature line per sensor (cpu0 to cpu3 and gpu).

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials