App_Deadline_Missed_Deep_Dive - 副本

news/2026/1/22 10:31:17/文章来源:https://www.cnblogs.com/fdnn/p/19515671

App_Deadline_Missed_Deep_Dive - 副本

Android Graphics Deadline & Fence Mechanism Deep Dive

This document details the logic behind "App Deadline Missed" in Android's FrameTimeline, tracing the mActuals.endTime from SurfaceFlinger down to the Linux Kernel Fence mechanism.

1. Jank Classification: App Deadline Missed

The core logic for defining a frame as "Jank" due to the application missing its deadline resides in [FrameTimeline.cpp](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp).

File: [frameworks/native/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp)
Function: SurfaceFrame::classifyJankLocked

void SurfaceFrame::classifyJankLocked(...) {// 1. Calculate the delay: Actual End Time - Predicted End TimedeadlineDelta = mActuals.endTime - mPredictions.endTime;// ...// 2. Determine if the frame finished lateif (deadlineDelta > mJankClassificationThresholds.deadlineThreshold) {mFrameReadyMetadata = FrameReadyMetadata::LateFinish;} else {mFrameReadyMetadata = FrameReadyMetadata::OnTimeFinish;}// ...// 3. Assign Jank Typeif (mFrameReadyMetadata == FrameReadyMetadata::LateFinish) {// Finish late, Present late -> The App took too long!mJankType |= JankType::AppDeadlineMissed;}
}
  • Logic: If mActuals.endTime (when App finished) is significantly later than mPredictions.endTime (when system expected it to finish), it's flagged as AppDeadlineMissed.

2. Tracking mActuals.endTime

The mActuals.endTime is not just a timestamp recorded when a function returns; it represents the physical completion time of the GPU work for that frame.

2.1 Assignment in FrameTimeline

File: [frameworks/native/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp)

void SurfaceFrame::setAcquireFenceTime(nsecs_t acquireFenceTime) {std::scoped_lock lock(mMutex);// The end time is the MAX of when the buffer was queued and when the fence signaled.// Usually, acquireFenceTime (GPU finish) is the limiting factor.mActuals.endTime = std::max(acquireFenceTime, mActualQueueTime);
}

2.2 Integration in Layer (SurfaceFlinger)

File: [frameworks/native/services/surfaceflinger/Layer.cpp](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/Layer.cpp)

The connection happens during [updateTexImage](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/Layer.cpp#3400-3449) (when SF latches a new buffer).

void Layer::updateTexImage(nsecs_t latchTime, bool bgColorOnly) {// ...// 1. Get the fence associated with the buffer submitted by the Appconst auto acquireFence = std::make_shared<FenceTime>(mDrawingState.acquireFence);// ...if (bufferSurfaceFrame != nullptr ...) {// 2. Pass the SIGNAL TIME of the fence to FrameTimeline// *CRITICAL*: mDrawingState.acquireFenceTime->getSignalTime() retrieves the GPU timestampaddSurfaceFramePresentedForBuffer(bufferSurfaceFrame,mDrawingState.acquireFenceTime->getSignalTime(),latchTime);}
}

Key Difference:

  • [updateTexImage](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/Layer.cpp#3400-3449): The "Worker". Executes the logic to latch the buffer and update layer state.
  • [addSurfaceFramePresentedForBuffer](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/Layer.cpp#1392-1400): The "Bookkeeper". Reports the successful latch and the timing data (derived from [updateTexImage](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/Layer.cpp#3400-3449)) to FrameTimeline for analysis.

3. The Fence Mechanism: Acquire & Release

Synchronization between the App (Producer) and SurfaceFlinger (Consumer) relies on Fences, which act as "Traffic Lights" for shared memory (DMA Buffers).

Type Direction Meaning
AcquireFence App -> SF "I'm done drawing." SF waits for this before compositing. Its signal time = mActuals.endTime.
ReleaseFence SF -> App "I'm done using it." App waits for this before writing the next frame into this buffer.

Workflow:

  1. App: Draws frame -> queueBuffer (attaches [AcquireFence](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp#335-339) "Red Light").
  2. GPU: Continues rendering in background.
  3. SF: [updateTexImage](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/Layer.cpp#3400-3449) -> Receives Buffer + Fence.
  4. Hardware: GPU finishes rendering -> Interrupt triggers.
  5. Kernel: Sets Fence to "Green Light" (Signaled) & records Timestamp.
  6. SF: Reads Timestamp -> mActuals.endTime.

4. Kernel Implementation Details

The timestamp used for mActuals.endTime originates deep within the Linux Kernel.

4.1 Kernel: Reading the Timestamp

File: drivers/dma-buf/sync_file.c (Linux Kernel)

When SurfaceFlinger calls fence->getSignalTime(), it eventually invokes an ioctl that hits this kernel function:

static int sync_fill_fence_info(struct dma_fence *fence,struct sync_fence_info *info)
{// ...info->status = dma_fence_get_status(fence);// Core Logic:// If signaled via dma_fence_is_signaled(), read the timestamp.// ktime_to_ns calls dma_fence_timestamp() internally or accesses the field directly.info->timestamp_ns =dma_fence_is_signaled(fence) ?ktime_to_ns(dma_fence_timestamp(fence)) :ktime_set(0, 0);return info->status;
}

4.2 Kernel: Safe Timestamp Access

File: include/linux/dma-fence.h

The accessor is careful about currency to avoid race conditions:

static inline ktime_t dma_fence_timestamp(struct dma_fence *fence)
{// Safety check: Don't read if not signaledif (WARN_ON(!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)))return ktime_get();// Spin-wait until the timestamp is actually writtenwhile (!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &fence->flags))cpu_relax(); // Wait for the other CPU to finish writingreturn fence->timestamp;
}

4.3 Kernel: Signaling Completion (DRM Scheduler)

File: drivers/gpu/drm/scheduler/sched_main.c

Where is the timestamp set? In the GPU Scheduler, when a job completes:

static void drm_sched_job_done(struct drm_sched_job *s_job)
{struct drm_sched_fence *s_fence = s_job->s_fence;// ...// *CRITICAL*: This function marks the fence as signaled and typically traces the timestamp.drm_sched_fence_finished(s_fence); // ...wake_up_interruptible(&sched->wake_up_worker);
}

5. Architectural Why: Fence in DMA Path?

Why is [fence](file:///mnt/fileroot/xxxx/board/frameworks/native/services/surfaceflinger/Layer.cpp#3348-3362) code found in drivers/dma-buf or similar DMA paths?

  • Co-existence with DMA-BUF: Fences are the synchronization primitive for Zero-Copy Buffer Sharing (DMA-BUF).
  • Buffer Sharing Protocol: If Device A (GPU) shares memory with Device B (Display) via DMA, they need a vendor-agnostic way to say "I'm done". dma-fence is that standard.
  • Not just for GPU: It serves Camera, Video Encoders, NPUs, etc. It manages access to DMA Memory Resources, hence its location in the kernel source tree.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/1199565.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2026线下童装店品牌测评优选

2026线下童装店品牌测评优选一、引言:开启童装探索之旅 在这个充满童趣与活力的童装世界里,家长们在为孩子挑选衣物时,常常陷入纠结。线上童装琳琅满目,可线下购买童装也有着无可替代的独特魅力。走进一家童装店,…

AI助力VS Code中文设置:一键解决语言切换难题

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容&#xff1a; 创建一个VS Code中文设置助手&#xff0c;用户只需输入将VS Code设置为中文&#xff0c;AI自动完成以下步骤&#xff1a;1.检测当前VS Code版本 2.推荐并安装中文语言包插件 3.生成…

最新数据盘点:2026主任护师培训机构排行榜,这3家机构更值得选择

最新数据盘点:2026主任护师培训机构排行榜,这3家机构更值得选择2026主任护师考试面对庞杂的考试内容与繁忙的临床工作,如何选择一家真正靠谱的培训机构,成为众多考生突围的关键。本文基于市场调研与真实反馈,通过…

2026年新明珠岩板深度解析:基于智造实力与产业生态的客观口碑评析

本文旨在从“智造实力与产业生态整合”这一核心维度出发,为高端住宅项目业主、室内设计师及建材采购决策者提供一份关于新明珠岩板的客观参考。岩板作为现代家居空间的重要饰面材料,其选择不仅关乎美学呈现,更与产品…

前置气动卡盘生产厂家怎么选?精卡机械带来的几点实战经验

在数控车床、加工中心以及自动化产线上,前置气动卡盘已经逐渐替代部分传统卡盘方案,成为许多工厂在提高换型效率、稳定加工精度时的重要选择。面对不同结构、不同载荷和不同品牌的产品,如何判断一家前置气动卡盘生产…

3分钟完成KALI换源:效率提升全攻略

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容&#xff1a; 开发一个极速KALI换源工具&#xff0c;要求&#xff1a;1.集成国内主流镜像源测速功能&#xff1b;2.支持并行测速和智能选择&#xff1b;3.提供缓存机制加速重复操作&#xff1b;…

2026年山东甲级资质工程监理公司合作加盟分公司口碑排名

在工程建设领域,资质是企业参与市场竞争的入场券,而全过程工程咨询服务则是提升项目价值的金钥匙。对于众多中小工程团队而言,如何快速获取合规资质、拓展业务边界,成为突破发展瓶颈的关键。以下结合工程咨询行业需…

2026橡胶拉力试验机国内品牌综合排行TOP2,技术实力与市场口碑双维度解析

在橡胶、塑料、复合材料等产业的质量控制与研发升级中,橡胶拉力试验机是评估材料拉伸、撕裂、剥离等力学性能的核心设备。面对市场上众多的设备供应商,如何选择一家技术可靠、服务到位、口碑良好的合作伙伴,成为企业…

宝妈宝爸闭眼入!儿童鞋服家居服宝藏品牌大揭秘

宝妈宝爸闭眼入!儿童鞋服家居服宝藏品牌大揭秘一、开篇:用心挑选,给孩子满分呵护 家人们,给孩子挑选鞋服的过程,是不是既充满期待又希望做到尽善尽美?[1,5,10] 儿童时期是身体快速发育的阶段,安全和舒适自然成为…

闪电开发:用IFLOW CLI 10分钟打造API测试工具

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容&#xff1a; 快速开发一个API测试CLI工具原型。功能&#xff1a;1. 发送HTTP请求&#xff08;GET/POST&#xff09;2. 显示响应头和主体 3. 支持JSON格式化输出 4. 保存请求历史。要求&#xf…

权威发布!2026三角洲护航TOP5排行榜,格局重塑,知悦电竞成全民首选

1.1 行业背景 《三角洲行动》护航行业历经多年迭代,市场格局迎来新变局。据EsportsCharts 2025年Q4最新数据,行业CR3指数升至65%,CR5指数突破80%,头部机构凭借核心竞争力进一步压缩中小机构生存空间。本次评测覆盖…

2026年钢丝网骨架复合管材厂家权威推荐榜:复合钢丝网骨架管、大口径钢丝网骨架管、钢丝网骨架复合管材、钢丝骨架复合管选择指南

2026年钢丝网骨架复合管材品牌推荐指南一、行业背景与推荐依据据《中国塑料管道行业发展白皮书2026》数据显示,2024年国内塑料管道市场规模突破3800亿元,其中钢丝网骨架复合管材因兼具金属管材高强度与塑料管材耐腐蚀…

2026正规全屋定制工厂推荐榜 板材加工优选指南

2026正规全屋定制工厂推荐榜 板材加工优选指南一、行业背景与筛选依据据《2025-2030中国家居建材行业发展白皮书》显示,国内全屋定制市场规模连续五年保持10%以上的年复合增长率,2025年突破4800亿元,市场需求向环保…

Rust关键字as

在 Rust 中 as 是一个官方定义的关键字 它主要用于以下三种场景: 1. 安全的原始类型转换(Casting) 这是 as 最常见的用法,用于在数值类型之间进行显式转换。let x: u32 = 10; let y: u64 = x as u64; // 将 u32 转…

【FAQ】HarmonyOS SDK 闭源开放能力 — Media Kit

1.问题描述: 断点太多是否会使DevEco Studio运行卡顿?如何处理? 解决方案: 断点太多会影响DevEco Studio运行,可以通过断点管理删除不必要的断点。 2.问题描述: 为什么图片使用imagePacker.packToFile压缩完之后…

探寻2026当前安徽宝晶美酒店招商电话有哪些:一份值得关注的智慧酒店投资参考

转载自:https://www.cppingce.com/rankinglis/293699.html 文章摘要 随着智慧酒店成为住宿业升级的重要方向,寻求优质投资项目的加盟商日益增多。本文立足于行业发展趋势,深入分析了以“未来酒店”为代表的智慧住宿…

复合式分板机品牌选哪家?老牌厂家排行榜给你答案

本榜单依托全维度市场调研与真实行业口碑,深度筛选出五家标杆企业,为电子制造企业选型提供客观依据,助力精准匹配适配的全自动复合式分板机合作伙伴。 TOP1 推荐:杭州亿协智能装备有限公司 推荐指数:★★★★★ |…

2026年中国岩板品牌推荐:全屋岩板应用深度评价,涵盖家居与工装场景交付痛点

摘要 在高端家居与商业空间装饰领域,岩板作为一种革命性材料,正从单一饰面材料向全空间、全场景应用方案演进,其市场渗透率持续提升。然而,面对市场上品牌林立、技术参数繁杂、交付标准不一以及设计适配性差异显著…

2026年岩板岛台品牌推荐:多场景应用评测,解决定制与耐用性核心痛点

在追求开放式社交空间与个性化家居表达的当下,厨房与餐客厅的界限日益模糊,岩板岛台作为集烹饪、用餐、收纳与社交于一体的“家庭核心区”,其选择已成为高端家装决策中的关键一环。业主与设计师不仅关注其美学表现,…

2026复合式分板机知名厂家排行,EXE亿协成本控制出色

在电子制造产业智能化升级的浪潮中,复合式分板机作为PCBA制程的核心设备,直接决定了产品良率与生产效率。面对市场上鱼龙混杂的厂商,如何挑选技术可靠、售后完善的合作伙伴?以下依据产品工艺、技术创新与服务体系维…