Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SRCS = $(wildcard $(SRCDIR)/*.c)
OBJS = $(patsubst $(SRCDIR)/%.c,$(BUILDDIR)/%.o,$(SRCS))
TARGET = $(BUILDDIR)/nvfd

.PHONY: all clean install uninstall
.PHONY: all clean install uninstall install-utils uninstall-utils

all: $(TARGET)

Expand All @@ -47,7 +47,15 @@ install: $(TARGET)
install -d $(DESTDIR)$(UNITDIR)
install -m 644 systemd/nvfd.service $(DESTDIR)$(UNITDIR)/nvfd.service

uninstall:
install-utils:
install -m 755 utils/nvfd-fan-control.sh $(DESTDIR)$(BINDIR)/
install -m 644 utils/nvfd-fan-control.service $(DESTDIR)$(UNITDIR)/

uninstall: uninstall-utils
rm -f $(DESTDIR)$(BINDIR)/nvfd
rm -f $(DESTDIR)$(UNITDIR)/nvfd.service
@echo "Config files preserved in $(CONFDIR). Remove manually if desired."

uninstall-utils:
rm -f $(DESTDIR)$(BINDIR)/nvfd-fan-control.sh
rm -f $(DESTDIR)$(UNITDIR)/nvfd-fan-control.service
111 changes: 99 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ NVFD is an open-source NVIDIA GPU fan control daemon for Linux. It uses the NVML
- Fixed fan speed mode
- True auto mode (returns control to NVIDIA driver)
- Multi-GPU support with per-GPU or all-GPU control, adaptive full/tabbed display
- Per-GPU mode switching via CLI (`nvfd 0 auto`, `nvfd 1 curve`, etc.)
- Real-time temperature, utilization, memory, and power monitoring
- Systemd service with automatic fan reset on shutdown
- Config hot-reload via SIGHUP
Expand Down Expand Up @@ -75,6 +76,13 @@ The install script will:
- Set up the systemd service
- Migrate any existing config from v1.x

**Optional:** Install with utility scripts:
```bash
sudo scripts/install.sh --with-utils
```

See [Advanced Usage](#advanced-usage) for details on utility scripts.

### Manual build

```bash
Expand All @@ -83,6 +91,11 @@ sudo make install
sudo systemctl enable --now nvfd.service
```

**Optional: Install utilities**
```bash
sudo make install-utils
```

## Uninstallation

```bash
Expand All @@ -101,18 +114,21 @@ Config files in `/etc/nvfd/` are preserved. Remove manually if desired.
## Usage

```
nvfd Interactive TUI dashboard (on TTY)
nvfd auto Return fan control to NVIDIA driver
nvfd curve Enable custom fan curve for all GPUs
nvfd curve <temp> <speed> Edit fan curve point (e.g., nvfd curve 60 70)
nvfd curve show Show current fan curve
nvfd curve edit Interactive curve editor (ncurses)
nvfd curve reset Reset fan curve to default
nvfd <speed> Set fixed fan speed for all GPUs (30-100)
nvfd <gpu_index> <speed> Set fixed fan speed for specific GPU
nvfd list List all GPUs and their indices
nvfd status Show current status
nvfd -h Show help
nvfd Interactive TUI dashboard (on TTY)
nvfd auto Return fan control to NVIDIA driver
nvfd curve Enable custom fan curve for all GPUs
nvfd curve <temp> <speed> Edit fan curve point (e.g., nvfd curve 60 70)
nvfd curve show Show current fan curve
nvfd curve edit Interactive curve editor (ncurses)
nvfd curve reset Reset fan curve to default
nvfd <speed> Set fixed fan speed for all GPUs (30-100)
nvfd <gpu_index> <speed> Set fixed fan speed for specific GPU
nvfd <gpu_index> auto Set specific GPU to auto mode
nvfd <gpu_index> curve Set specific GPU to curve mode
nvfd <gpu_index> manual <sp> Set specific GPU to fixed speed
nvfd list List all GPUs and their indices
nvfd status Show current status
nvfd -h Show help
```

When run with no arguments on a TTY, `nvfd` launches the interactive TUI dashboard.
Expand Down Expand Up @@ -169,6 +185,11 @@ nvfd 0 60
# Return all fans to driver control
nvfd auto

# Per-GPU mode control
nvfd 0 auto # Set GPU 0 to auto mode
nvfd 1 curve # Set GPU 1 to curve mode
nvfd 0 manual 70 # Set GPU 0 to manual mode at 70%

# Use custom fan curve
nvfd curve
nvfd curve show
Expand Down Expand Up @@ -215,6 +236,72 @@ sudo systemctl status nvfd # Check status

The daemon resets all fans to driver-controlled auto mode on shutdown.

## Advanced Usage

### Temperature-Aware Fan Control

The `nvfd-fan-control.sh` utility provides automatic per-GPU fan mode switching based on temperature thresholds with hysteresis:

```bash
# Run with default thresholds (up: 45°C, down: 35°C)
sudo nvfd-fan-control.sh

# Custom thresholds with hysteresis
sudo nvfd-fan-control.sh --threshold-up 50 --threshold-down 40

# Verbose logging
sudo nvfd-fan-control.sh -v
```

**Hysteresis explained:**
- `--threshold-up 45`: Switch to **curve mode** when temperature **rises above 45°C**
- `--threshold-down 35`: Switch to **auto mode** when temperature **falls below 35°C**
- Between 35-45°C: **Keep current mode** (prevents thrashing)

The script monitors GPU temperatures and automatically switches each GPU between:
- **Auto mode** (quiet) when temperature falls below threshold-down
- **Curve mode** (cooled) when temperature rises above threshold-up

### Monitoring Mode Switches

You can monitor mode switches in real-time using the **nvfd dashboard**:

```bash
nvfd
```

The dashboard shows the current mode (Auto/Manual/Curve) for each GPU. When `nvfd-fan-control.sh` switches a GPU mode, the dashboard updates within 5 seconds.

**Important notes:**
- **Polling interval:** The script checks GPU temperatures every **10 seconds**
- **Mode change latency:** A mode switch may take up to 10 seconds after temperature crosses the threshold
- **Dashboard update:** The nvfd daemon reads config every 5 seconds
- **Total latency:** 5-15 seconds from temperature crossing threshold to dashboard showing new mode

#### Systemd Service

When installed with `--with-utils`, the service unit is installed but **not enabled by default**. To enable:

```bash
sudo systemctl enable --now nvfd-fan-control.service
```

The service depends on `nvfd.service` and automatically detects config changes within 5 seconds.

**Customizing thresholds:** Edit `/etc/systemd/system/nvfd-fan-control.service` and modify the `ExecStart` line:
```ini
ExecStart=/usr/local/bin/nvfd-fan-control.sh --threshold-up 50 --threshold-down 40
```
Then reload and restart: `sudo systemctl daemon-reload && sudo systemctl restart nvfd-fan-control.service`

### Dependencies

The utility script requires:
- `nvidia-smi` (included with NVIDIA drivers)
- `nvfd` binary (installed via this package)

No CUDA toolkit required for runtime.

## Migration from v1.x

NVFD automatically migrates old configuration:
Expand Down
111 changes: 99 additions & 12 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ NVFD 是一款開源的 Linux NVIDIA GPU 風扇控制守護程式。透過 NVML
- 固定轉速模式
- 自動模式(將控制權交還 NVIDIA 驅動程式)
- 多 GPU 支援,單卡或全卡控制,自適應全顯/分頁顯示
- 透過 CLI 實現每張 GPU 的模式切換 (`nvfd 0 auto`, `nvfd 1 curve` 等)
- 即時溫度、使用率、記憶體、功耗監控
- Systemd 服務,關機時自動重設風扇
- 透過 SIGHUP 熱載入設定
Expand Down Expand Up @@ -75,6 +76,13 @@ sudo scripts/install.sh
- 設定 systemd 服務
- 自動遷移 v1.x 舊設定

**可選:** 安裝實用工具腳本:
```bash
sudo scripts/install.sh --with-utils
```

詳見 [進階用法](#進階用法) 了解實用工具腳本的詳細資訊。

### 手動編譯

```bash
Expand All @@ -83,6 +91,11 @@ sudo make install
sudo systemctl enable --now nvfd.service
```

**可選:安裝實用工具**
```bash
sudo make install-utils
```

## 解除安裝

```bash
Expand All @@ -101,18 +114,21 @@ sudo make uninstall
## 使用方式

```
nvfd 互動式 TUI 儀表板(需在終端機執行)
nvfd auto 將風扇控制權交還 NVIDIA 驅動程式
nvfd curve 啟用自訂風扇曲線
nvfd curve <溫度> <轉速> 編輯風扇曲線控制點(例:nvfd curve 60 70)
nvfd curve show 顯示目前風扇曲線
nvfd curve edit 互動式曲線編輯器(ncurses)
nvfd curve reset 重設風扇曲線為預設值
nvfd <轉速> 設定所有 GPU 固定轉速(30-100)
nvfd <GPU編號> <轉速> 設定指定 GPU 固定轉速
nvfd list 列出所有 GPU
nvfd status 顯示目前狀態
nvfd -h 顯示說明
nvfd 互動式 TUI 儀表板(需在終端機執行)
nvfd auto 將風扇控制權交還 NVIDIA 驅動程式
nvfd curve 啟用自訂風扇曲線
nvfd curve <溫度> <轉速> 編輯風扇曲線控制點(例:nvfd curve 60 70)
nvfd curve show 顯示目前風扇曲線
nvfd curve edit 互動式曲線編輯器(ncurses)
nvfd curve reset 重設風扇曲線為預設值
nvfd <轉速> 設定所有 GPU 固定轉速(30-100)
nvfd <GPU 編號> <轉速> 設定指定 GPU 固定轉速
nvfd <GPU 編號> auto 設定指定 GPU 為自動模式
nvfd <GPU 編號> curve 設定指定 GPU 為曲線模式
nvfd <GPU 編號> manual <轉速> 設定指定 GPU 為固定轉速
nvfd list 列出所有 GPU
nvfd status 顯示目前狀態
nvfd -h 顯示說明
```

在終端機中不帶參數執行 `nvfd` 會啟動互動式 TUI 儀表板。
Expand Down Expand Up @@ -169,6 +185,11 @@ nvfd 0 60
# 所有風扇交還驅動程式控制
nvfd auto

# 每張 GPU 的模式控制
nvfd 0 auto # 設定 GPU 0 為自動模式
nvfd 1 curve # 設定 GPU 1 為曲線模式
nvfd 0 manual 70 # 設定 GPU 0 為手動模式 70%

# 使用自訂風扇曲線
nvfd curve
nvfd curve show
Expand Down Expand Up @@ -215,6 +236,72 @@ sudo systemctl status nvfd # 查看狀態

守護程式關閉時會自動將所有風扇重設為驅動程式控制的自動模式。

## 進階用法

### 溫度感知風扇控制

`nvfd-fan-control.sh` 實用工具可根據溫度閾值(帶遲滯)自動切換每張 GPU 的風扇模式:

```bash
# 使用預設閾值(up: 45°C, down: 35°C)運行
sudo nvfd-fan-control.sh

# 自訂閾值(帶遲滯)
sudo nvfd-fan-control.sh --threshold-up 50 --threshold-down 40

# 啟用詳細日誌
sudo nvfd-fan-control.sh -v
```

**遲滯說明:**
- `--threshold-up 45`:溫度**上升至 45°C 以上**時切換到**曲線模式**
- `--threshold-down 35`:溫度**下降至 35°C 以下**時切換到**自動模式**
- 在 35-45°C 之間:**保持當前模式**(防止頻繁切換)

該腳本會監控 GPU 溫度,並自動在以下模式之間切換每張 GPU:
- **自動模式**(安靜):溫度低於 threshold-down 時
- **曲線模式**(散熱):溫度高於 threshold-up 時

### 監控模式切換

您可以使用 **nvfd 儀表板** 即時監控模式切換:

```bash
nvfd
```

儀表板會顯示每張 GPU 的當前模式(Auto/Manual/Curve)。當 `nvfd-fan-control.sh` 切換 GPU 模式時,儀表板會在 5 秒內更新。

**重要說明:**
- **輪詢間隔:** 腳本每 **10 秒** 檢查一次 GPU 溫度
- **模式切換延遲:** 溫度超過閾值後,模式切換可能需要最多 10 秒
- **儀表板更新:** nvfd 守護程式每 5 秒讀取配置
- **總延遲:** 從溫度超過閾值到儀表板顯示新模式,總共需要 5-15 秒

#### Systemd 服務

使用 `--with-utils` 安裝後,服務單元已安裝但**預設未啟用**。啟用方法:

```bash
sudo systemctl enable --now nvfd-fan-control.service
```

該服務依賴於 `nvfd.service`,並會在 5 秒內自動偵測到配置變更。

**自訂閾值:** 編輯 `/etc/systemd/system/nvfd-fan-control.service` 並修改 `ExecStart` 行:
```ini
ExecStart=/usr/local/bin/nvfd-fan-control.sh --threshold-up 50 --threshold-down 40
```
然後重新載入並重啟:`sudo systemctl daemon-reload && sudo systemctl restart nvfd-fan-control.service`

### 依賴項

實用工具腳本需要:
- `nvidia-smi`(包含在 NVIDIA 驅動中)
- `nvfd` 二进制文件(通過此套件安裝)

運行時不需要 CUDA toolkit。

## 從 v1.x 遷移

NVFD 會自動遷移舊版設定:
Expand Down
1 change: 1 addition & 0 deletions include/curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ int curve_write(const FanCurve *curve);
void curve_edit(int temp, int speed);
void curve_reset(void);
int curve_interpolate(int temp, const FanCurve *curve);
int curve_apply_to_gpu(unsigned int gpu_index);

/* Default built-in curve interpolation (fallback when no curve file exists) */
int curve_default_interpolate(int temp);
Expand Down
Loading