跳到主要內容

發表文章

從 EEVDF 看 Linux 核心對端側 AI 延遲敏感度的排程配額優化 / Optimizing Edge AI Latency via Linux EEVDF: Scheduling Quotas and Virtual Deadlines

daily-tech:2026-11-26 從 EEVDF 看 Linux 核心對端側 AI 延遲敏感度的排程配額優化 / Optimizing Edge AI Latency via Linux EEVDF: Scheduling Quotas and Virtual Deadlines 現象: 在 Linux 與 Android 邊緣裝置上部屬端側 AI(例如即時語音辨識、手勢追蹤或端側小型語言模型 SLM Token 生成)時,許多開發團隊在處理高負載背景任務時,常發現 AI 推論會出現不可預期的延遲抖動(Latency Jitter)。即便系統已經透過前篇討論的 DMA-BUF 零拷貝技術消除了大部分的記憶體搬移開銷,但當 AI 執行緒被硬體中斷(如相機新圖框就緒、麥克風音訊緩衝區填滿)喚醒時,往往無法第一時間搶佔 CPU 核心,而是在就緒佇列(Runqueue)中痛苦排隊 5 到 15 毫秒。這類延遲使得即時互動系統的影音同步失效,嚴重傷害端側 AI 的流暢體驗。 Symptom: When deploying on-device AI workloads (such as real-time keyword spotting, gesture tracking, or edge small language model SLM token streaming) on Linux and Android devices under concurrent system loads, developers frequently encounter severe latency jitter. Even after eliminating redundant memory copies using the DMA-BUF zero-copy pipeline analyzed in our previous article, AI threads awakened by hardware interrupts (e.g., camera frame completions or audio buffer fills) often fail to seize CPU cores immediately. Instead, they languish in run...
最近的文章

從 DMA-BUF 到 AHardwareBuffer:拆解 Android 與 Linux 端側 AI 零拷貝管線 / From DMA-BUF to AHardwareBuffer: Deconstructing Zero-Copy Pipelines in Android and Linux Edge AI

daily-tech:2026-11-25 從 DMA-BUF 到 AHardwareBuffer:拆解 Android 與 Linux 端側 AI 零拷貝管線 / From DMA-BUF to AHardwareBuffer: Deconstructing Zero-Copy Pipelines in Android and Linux Edge AI 現象: 在智慧型手機或邊緣嵌入式裝置上執行即時影像 AI(例如物件偵測、語意分割或姿態辨識)時,許多團隊常遇到一種難堪的效能瓶頸:明明選用了輕量化的量化神經網路,推論核心花費的時間僅需 15 毫秒,然而整體管線的端到端延遲卻高達 45 毫秒以上,甚至伴隨著 CPU 使用率飆高與手機發燙。深入分析效能剖析數據後會發現,推論本身很快,耗時全卡在「相機取像後把點陣圖複製給 GPU 前處理」、「GPU 處理完再拷貝成張量陣列交給 NPU」這兩次不必要的記憶體搬移上。 Symptom: When deploying real-time vision AI (such as object detection, semantic segmentation, or pose estimation) on smartphones or edge embedded devices, engineering teams often face an unexpected performance bottleneck: despite choosing an ultra-lightweight quantized neural network whose core inference takes only 15 milliseconds, the end-to-end pipeline latency exceeds 45 milliseconds, accompanied by soaring CPU utilization and device throttling. Profiling reveals that raw inference is swift; the real culprits are redundant memory copies between camera ISP buffers, GPU preproces...

從 LiteRT 與 ExecuTorch 看 Android 端側 AI 記憶體預算:為什麼模型不大卻容易 OOM / On-Device AI Memory Budgeting: Why Models OOM Despite Small Weights

daily-tech:2026-11-24 從 LiteRT 與 ExecuTorch 看 Android 端側 AI 記憶體預算:為什麼模型不大卻容易 OOM / On-Device AI Memory Budgeting: Why Models OOM Despite Small Weights 現象: 在 Android 手機上部署端側 AI 模型時,許多團隊常遇到令人困惑的記憶體崩潰。直覺上,開發者看到量化後的 INT8 或 INT4 權重檔案只有約 1.2GB,心想設備還有超過 2GB 的可用記憶體,應該游刃有餘。然而一旦實際載入並開始接收推論請求,系統卻迅速觸發 Low Memory Killer(LMK),將前台 App 或重要的背景服務強制終止。這並非模型參數本身膨脹,而是推論時伴隨的動態暫存空間與系統底層限制悄悄耗盡了預算。 Symptom: When deploying on-device AI models on Android, developers often face puzzling memory crashes. Intuitively, seeing an INT8 or INT4 quantized weight file of only 1.2 GB makes one assume that 2 GB of available device RAM is more than enough. Yet in practice, as inference begins, the Android Low Memory Killer (LMK) quickly terminates the foreground app or background tasks. The weight parameters do not expand; rather, dynamic runtime buffers and system-level allocations quietly exhaust the available memory budget. 端側 AI 執行期記憶體組成拆解 / On-Device AI Runtime Memory Breakdown 靜態權重參數 Static Model Weights INT8 / INT4 量...

Linux EEVDF 排程:為什麼低延遲不等於永遠優先 / Linux EEVDF Scheduling: Why Low Latency Does Not Mean Always First

Linux EEVDF 排程:為什麼低延遲不等於永遠優先 / Linux EEVDF Scheduling: Why Low Latency Does Not Mean Always First 現象: 同一台 Linux 主機上,終端機輸入偶爾卡頓,AI 推論或編譯工作卻沒有停止。很多人第一個反應是把互動程式設成「最高優先權」,但這可能只是把延遲轉移給別的工作。Linux 近年的公平排程路徑使用 EEVDF(Earliest Eligible Virtual Deadline First)整理可執行工作:它不是承諾某個程式永遠先跑,而是在公平性與回應時間之間計算下一個選擇。 Symptom: On the same Linux host, terminal input can feel sticky while an AI inference or build continues to run. The first reaction is often to give the interactive task the highest priority, but that may only move the latency elsewhere. Recent Linux fair-scheduling work uses EEVDF, or Earliest Eligible Virtual Deadline First, to order runnable tasks. It does not promise that one program always runs first; it computes a next choice between fairness and responsiveness. 圖一|EEVDF 先判斷工作是否 eligible,再比較虛擬截止時間。 / Figure 1 | EEVDF checks eligibility before comparing virtual deadlines. 機制:先理解 eligible,再談 deadline / Mechanism: Eligibility Comes Before the Deadline 公平排程器不只看「誰等最久」。每個工作會在虛擬執行時間軸上累積進度,並依...

Android 端側 AI 為什麼要在 DMA-BUF 停一下?零拷貝不等於零同步 / Android On-Device AI: DMA-BUF Zero-Copy Still Needs Synchronization

daily-tech:2026-11-20 現象:模型沒有變大,畫面卻開始卡 / Symptom: The model is unchanged, but frames stall 手機把相機畫面交給端側 AI 模型時,最直覺的做法是先複製到 CPU,再複製到 GPU 或 NPU。資料量一大,模型本身可能沒有變慢,真正增加的是搬運、等待與格式轉換。共享 buffer 可以減少複製,但若忽略同步,畫面可能讀到未完成的資料,或因等待 producer 而出現尾端延遲。 When a phone sends camera frames to an on-device AI model, the obvious path copies pixels through the CPU and then to the GPU or NPU. With larger frames, transport, waiting, and format conversion can dominate even when the model is unchanged. Shared buffers can reduce copies, but missing synchronization can expose incomplete data or create tail latency. Android AI buffer path Camera / CPU producer AHardwareBuffer shared handle DMA-BUF fd import + fence GPU / NPU consumer cache sync + fence + lifetime still matter 圖 1|共享 buffer 減少搬運,但 cache、fence 與生命週期仍需管理。 / Figure 1 | Shared buffers reduce copies, but cache, fences, and lifetime still need explicit management. 機制:HardwareBuffer 是入口,DMA-BUF 是共享路徑 / Mechanism: HardwareBuffer is the Android entry, DMA-BUF i...

Android 端側 AI 為什麼要在 DMA-BUF 停一下?零拷貝不等於零同步 / Android On-Device AI: DMA-BUF Zero-Copy Still Needs Synchronization

daily-tech:2026-11-19 現象:模型沒有變大,畫面卻開始卡 / Symptom: The model is unchanged, but frames stall 手機把相機畫面交給端側 AI 模型時,最直覺的做法是先複製到 CPU,再複製到 GPU 或 NPU。資料量一大,模型本身可能沒有變慢,真正增加的是搬運、等待與格式轉換。共享 buffer 可以減少複製,但若忽略同步,畫面可能讀到未完成的資料,或因等待 producer 而出現尾端延遲。 When a phone sends camera frames to an on-device AI model, the obvious path copies pixels through the CPU and then to the GPU or NPU. With larger frames, transport, waiting, and format conversion can dominate even when the model is unchanged. Shared buffers can reduce copies, but missing synchronization can expose incomplete data or create tail latency. Android AI buffer path Camera / CPU producer AHardwareBuffer shared handle DMA-BUF fd import + fence GPU / NPU consumer cache sync + fence + lifetime still matter 圖 1|共享 buffer 減少搬運,但 cache、fence 與生命週期仍需管理。 / Figure 1 | Shared buffers reduce copies, but cache, fences, and lifetime still need explicit management. 機制:HardwareBuffer 是入口,DMA-BUF 是共享路徑 / Mechanism: HardwareBuffer is the Android entry, DMA-BUF i...

Android ART 為什麼會突然卡住?看懂 GC、堆積與延遲尖峰 / Android ART GC: Why Short Pauses Become Latency Spikes

daily-tech:2026-11-18 現象:App 沒有崩潰,畫面卻突然停住 / Symptom: The app is alive, but frames suddenly stop Android App 在滑動、開啟相機或載入模型時,可能沒有 Crash,畫面卻短暫停住。很多人先把問題歸咎於 CPU 不夠快,但 ART 的記憶體回收也會讓應用程式執行緒暫停。要找原因,先把配置物件、堆積成長和 GC 暫停分開觀察。 An Android app may not crash, yet briefly freeze while scrolling, opening the camera, or loading a model. CPU speed is an easy suspect, but ART garbage collection can also pause application threads. Separate allocation, heap growth, and GC pauses before changing code or hardware. 機制:ART 如何把垃圾回收放進執行流程 / Mechanism: how ART places GC into execution ART 使用 managed heap 管理 Java 與 Kotlin 物件。程式配置新物件時,堆積會逐步接近成長界線;當回收條件成立,GC 會找出仍被參考的物件,回收不可達空間,並依回收器與階段產生不同程度的工作。背景回收不代表完全沒有停頓:根掃描、執行緒協調與記憶體壓縮仍可能反映在畫面幀時間。 ART manages Java and Kotlin objects in a managed heap. Allocations move the heap toward its growth boundary; when collection is needed, GC identifies reachable objects and reclaims unreachable space. Concurrent work does not mean zero pauses: root scanning, thread coordination, and com...