Skip to content

fix(power): reschedule idle tasks#94

Open
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:power-idle-restart-timer
Open

fix(power): reschedule idle tasks#94
mhduiy wants to merge 1 commit into
linuxdeepin:masterfrom
mhduiy:power-idle-restart-timer

Conversation

@mhduiy

@mhduiy mhduiy commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
  1. Query the current idle state from IdleWatcher when updating the power save plan.
  2. Recalculate task delays differently when the session is already idle.
  3. Drop the duplicated PowerSavePlan idle state to avoid stale scheduling decisions.

Log: Reschedule power save tasks correctly when the idle state is already active.

fix(power): 修复 idle 任务重排

  1. 更新节能计划时从 IdleWatcher 查询当前 idle 状态。
  2. 会话已处于 idle 状态时按任务自身延迟重新计算定时任务。
  3. 移除 PowerSavePlan 重复维护的 idle 状态,避免使用过期状态调度任务。

Log: 已处于 idle 状态时正确重排节能任务。

1. Query the current idle state from IdleWatcher when updating the power save plan.
2. Recalculate task delays differently when the session is already idle.
3. Drop the duplicated PowerSavePlan idle state to avoid stale scheduling decisions.

Log: Reschedule power save tasks correctly when the idle state is already active.

fix(power): 修复 idle 任务重排

1. 更新节能计划时从 IdleWatcher 查询当前 idle 状态。
2. 会话已处于 idle 状态时按任务自身延迟重新计算定时任务。
3. 移除 PowerSavePlan 重复维护的 idle 状态,避免使用过期状态调度任务。

Log: 已处于 idle 状态时正确重排节能任务。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @mhduiy, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码修复了电源管理中空闲状态判断不同步导致的任务延迟错误,逻辑严谨且无安全风险
代码消除了状态成员变量的隐患,实时获取状态,完全符合规范且无缺陷

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

代码在 PowerSavePlan::Update 函数中移除了对存在同步风险的成员变量 m_isIdle 的依赖,转而通过 m_powerManager->idleWatcher()->isIdle() 实时获取系统真实的空闲状态。针对 isIdle 为 true 的情况,将 t.realDelay 重新计算为 t.delay * 1000,准确实现了在已空闲状态下重排任务的需求,避免了原逻辑中 t.delay - min 导致的倒计时错误延后。同时包含了严谨的空指针保护 m_powerManageriw,语法与逻辑均无瑕疵。
建议:保持当前逻辑,无需额外修改。

  • 2.代码质量(良好)✓

移除冗余的 m_isIdle 成员变量及其在 HandleIdleOnHandleIdleOff 中的赋值操作,遵循了单一数据源原则,大幅降低了状态维护的复杂度和不同步风险。scheduleTask 中的日志级别提升至 qWarning 有助于在发生任务重调度时快速定位问题。
潜在问题:在正常业务流(如用户插拔电源触发重排)中使用 qWarning 可能会导致日志级别滥用,常规信息流通常应使用 qInfoqDebug
建议:考虑将 scheduleTask 中的 qWarning 替换为 qInfo,以区分真正的警告异常与正常的业务调度日志。

  • 3.代码性能(高效)✓

新增的 idleWatcher()->isIdle() 调用通常只是读取一个内部的布尔状态标志,时间复杂度为 O(1),在 Update 函数的调用频率下不会产生任何可感知的性能开销。
建议:无需优化。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码未涉及外部输入处理、命令执行、内存越界等危险操作,且对指针进行了安全校验,不存在安全风险。
建议:继续保持安全的编码习惯。

■ 【改进建议代码示例】

void PowerSavePlan::scheduleTask(const MetaTask &t)
{
    // 使用 qInfo 替代 qWarning,避免正常调度流程污染警告日志
    qInfo(logPowerSession) << "Scheduling task" << t.name << "to run in" << t.realDelay << "ms";
    auto *timer = new QTimer(this);
    timer->setSingleShot(true);
    connect(timer, &QTimer::timeout, this, t.fn);
    // 后续逻辑...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants