iOS系列—wakeup in XNU

苹果在iOS13的时候,在内核中退出了一个新的性能掂量指标wakeup,同时因为这个指标而被零碎杀死的利用不可胜数,其中也包含咱们罕用的微信淘宝等。而这个指标齐全是由 XNU 内核统计的,所以咱们很难通过日志等一般伎俩去精确的定位问题,所以这里通过另一种思路去解决这个问题。

为什么要统计 wakeup

要定位这个问题,首先咱们须要晓得这个指标的目标是什么。

XNU 中,对性能的指标有CPU、内存、IO,而wakeup属于 CPU 的性能指标,同时属于 CPU 指标的还有 CPU 使用率,上面是XNU中对其限度的定义。

/*
 * Default parameters for CPU usage monitor.
 *
 * Default setting is 50% over 3 minutes.
 */
#define         DEFAULT_CPUMON_PERCENTAGE 50
#define         DEFAULT_CPUMON_INTERVAL   (3 * 60)
#define TASK_WAKEUPS_MONITOR_DEFAULT_LIMIT              150 /* wakeups per second */
#define TASK_WAKEUPS_MONITOR_DEFAULT_INTERVAL   300 /* in seconds. */

/*
 * Level (in terms of percentage of the limit) at which the wakeups monitor triggers telemetry.
 *
 * (ie when the task's wakeups rate exceeds 70% of the limit, start taking user
 *  stacktraces, aka micro-stackshots)
 */
#define TASK_WAKEUPS_MONITOR_DEFAULT_USTACKSHOTS_TRIGGER        70

总结来说,当 CPU 使用率在3分钟内均值超过50%,就认为适度应用CPU,当wakeup在300秒内均值超过150次,则认为唤起次数过多,同时在阈值的70%水位内核会开启监控。

CPU 使用率咱们很容易了解,使用率越高,电池寿命越低,而且并不是线性减少的。那么wakeup又是如何影响电池寿命的呢?

首先咱们须要看看ARM架构中对于 CPU 功耗问题的形容:

Many ARM systems are mobile devices and powered by batteries. In such systems, optimization of power use, and total energy use, is a key design constraint. Programmers often spend significant amounts of time trying to save battery life in such systems.
因为ARM被大量应用于低功耗设施,而这些设施往往会由电池来作为驱动,所以 ARM 在硬件层面就对功耗这个问题进行了优化设计。

Energy use can be divided into two components:

  • Static
    Static power consumption, also often called leakage, occurs whenever the core logic or RAM blocks have power applied to them. In general terms, the leakage currents are proportional to the total silicon area, meaning that the bigger the chip, the higher the leakage. The proportion of power consumption from leakage gets significantly higher as you move to smaller fabrication geometries.

  • Dynamic
    Dynamic power consumption occurs because of transistor sw

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值