https://hrubos.tech/blogy/content/images/20260707202712-Snímka obrazovky 2026-07-07 o 20.26.51.png ^^^
Rytieri od Panny Márie, pripravte sa na boj proti čiernym, naša Kráľovná bude stáť pri nás!
S láskou white hats :)

Základná myšlienka pre Linux by bola:
#!/usr/bin/env python3
import os
import subprocess
import shutil
OLLAMA_PROCESS = "ollama"
def run(cmd):
print("\n>", " ".join(cmd))
subprocess.run(cmd)
def find_pids():
try:
out = subprocess.check_output(
["pgrep", "-f", OLLAMA_PROCESS],
text=True
)
return out.split()
except subprocess.CalledProcessError:
return []
# -----------------------------------
# 1 CPU CORES
# -----------------------------------
def limit_cpu():
pids = find_pids()
if not pids:
print("Ollama nebeží.")
return
cores = input("Koľko jadier ponechať? (napr. 2): ")
cpu_list = ",".join(str(i) for i in range(int(cores)))
for pid in pids:
run([
"taskset",
"-pc",
cpu_list,
pid
])
# -----------------------------------
# 2 NICE + IONICE
# -----------------------------------
def limit_priority():
pids = find_pids()
if not pids:
print("Ollama nebeží.")
return
for pid in pids:
run([
"renice",
"19",
"-p",
pid
])
run([
"ionice",
"-c3",
"-p",
pid
])
print("Priorita znížená.")
# -----------------------------------
# 3 NVIDIA
# -----------------------------------
def nvidia_low_power():
if shutil.which("nvidia-smi") is None:
print("nvidia-smi nebolo nájdené.")
return
watt = input("Power limit vo W (napr. 40): ")
run(["sudo", "nvidia-smi", "-pm", "1"])
run(["sudo", "nvidia-smi", "-pl", watt])
print("Hotovo.")
# -----------------------------------
# 4 AMD
# -----------------------------------
def amd_low_power():
path = "/sys/class/drm/card0/device/power_dpm_force_performance_level"
if not os.path.exists(path):
print("AMDGPU nepodporuje tento parameter.")
return
run([
"sudo",
"sh",
"-c",
f'echo low > {path}'
])
print("AMD GPU prepnutá na LOW.")
# -----------------------------------
# MENU
# -----------------------------------
while True:
print("\n============================")
print(" OLLAMA POWER MANAGER")
print("============================")
print("1. Obmedziť CPU jadrá")
print("2. Znížiť NICE + IONICE")
print("3. NVIDIA LOW POWER")
print("4. AMD LOW POWER")
print("0. Koniec")
c = input("\nVýber: ")
if c == "1":
limit_cpu()
elif c == "2":
limit_priority()
elif c == "3":
nvidia_low_power()
elif c == "4":
amd_low_power()
elif c == "0":
break
else:
print("Neplatná voľba.")
Niečo iné:
#!/usr/bin/env python3
"""
Ollama Power Manager (simplified single-file edition)
NOTE:
- Intended for Ubuntu/Debian/Linux Mint.
- Some operations require sudo.
- NVIDIA/AMD features depend on driver support.
"""
import os, shutil, subprocess, platform
def run(cmd):
print(">", " ".join(cmd))
subprocess.run(cmd)
def install():
if shutil.which("apt"):
pkgs=["python3-psutil","python3-rich","util-linux","cpufrequtils","pciutils","lm-sensors"]
run(["sudo","apt","update"])
run(["sudo","apt","install","-y",*pkgs])
def detect_cpu():
model=""
vendor=""
with open("/proc/cpuinfo") as f:
for line in f:
if line.startswith("model name") and not model:
model=line.split(":",1)[1].strip()
if line.startswith("vendor_id") and not vendor:
vendor=line.split(":",1)[1].strip()
return vendor,model
def detect_gpu():
try:
out=subprocess.check_output(["lspci"],text=True)
except Exception:
return "Unknown"
g=[]
for l in out.splitlines():
if "VGA" in l or "3D" in l:
g.append(l)
return "\n".join(g) if g else "None"
def profile(name):
if name=="eco":
run(["sudo","cpupower","frequency-set","-g","powersave"])
print("Set nice/ionice manually on running ollama:")
print(" renice 19 -p $(pgrep ollama)")
print(" ionice -c3 -p $(pgrep ollama)")
if shutil.which("nvidia-smi"):
run(["sudo","nvidia-smi","-pm","1"])
run(["sudo","nvidia-smi","-pl","40"])
elif name=="balanced":
run(["sudo","cpupower","frequency-set","-g","schedutil"])
elif name=="max":
run(["sudo","cpupower","frequency-set","-g","performance"])
def main():
while True:
print("\n=== Ollama Power Manager ===")
print("1 Install dependencies")
print("2 Detect hardware")
print("3 Max Performance")
print("4 Balanced")
print("5 Power Saver")
print("0 Exit")
c=input("> ")
if c=="1": install()
elif c=="2":
print(platform.platform())
print(detect_cpu())
print(detect_gpu())
elif c=="3": profile("max")
elif c=="4": profile("balanced")
elif c=="5": profile("eco")
elif c=="0": break
if __name__=="__main__":
main()
Príkazy ako vždy pre GPT, díky AI za vypľutý kódik ^^^

Comments “Komentár: Povolali k1 proti ra-ica a dali mu 5 minút na riešenie v linux mint:”