我们可以优化代码来降低功耗吗?
有没有什么技术可以优化代码以确保更低的功耗。架构是ARM。语言是C
Are there any techniques to optimize code in order to ensure lesser power consumption.Architecture is ARM.language is C
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
来自 ARM 技术参考网站:
根据这些信息,我想说处理器为您做了很多工作来节省电量。任何电力浪费都来自于编写得不好的代码,这些代码执行了不必要的处理,无论如何您都不希望这样做。如果您希望节省电量,应用程序的整体设计将会产生更大的效果。网络访问、屏幕渲染等高耗电操作将是功耗比较受关注的。
From the ARM technical reference site:
Based on this information, I'd say that the processor does a lot of work for you to save power. Any power wastage would come from poorly written code that does more processing than necessary, which you wouldn't want anyway. If you're looking to save power, the overall design of your application will have more effect. Network access, screen rendering, and other power-hungry operations will be of more concern for power consumption.
实际上,优化代码以使用更少的功耗只是优化代码。无论您的动机是金钱、社会、政治还是类似的,更少的 CPU 周期 = 更少的能源消耗。我想说的是,我认为你可以用“执行时间”代替“功耗”,因为它们本质上是成正比的——因此,当你不用“吓跑”人们时,你可能会取得更大的成功。与电源相关的问题。不过,我可能会纠正:)
Optimizing code to use less power is, effectively, just optimizing code. Regardless of whether your motives are monetary, social, politital or the like, fewer CPU cycles = less energy used. What I'm trying to say is I think you can probably replace "power consumption" with "execution time", as they would, essentially, be directly proportional - and you therefore may have more success when not "scaring" people off with a power-related question. I may, however, stand corrected :)
是的。使用 分析器 并查看哪些例程使用了大部分 CPU。在 ARM 上,您可以使用一些 JTAG 连接器(如果可用)(我使用了 Lauterbach 用于调试和分析)。主要问题通常是让处理器在空闲时处于低功耗状态(深度睡眠)。如果您无法大幅降低 CPU 使用百分比(例如从 80% 降低到 50%),则不会产生太大影响。根据您运行的操作系统,选项可能会有所不同。
Yes. Use a profiler and see what routines are using most of the CPU. On ARM you can use some JTAG connectors, if available (I used Lauterbach both for debugging and for profiling). The main problem is generally to put your processor, when in idle, in a low-consumption state (deep sleep). If you cannot reduce the CPU percentage used by much (for example from 80% to 50%) it won't make a big difference. Depending on what operating systems you are running the options may vary.
2010 年 7 月版的ACM 通讯有一篇关于节能算法的文章,您可能会感兴趣。我还没有读过它,所以无法传授它的任何智慧。
The July 2010 edition of the Communications of the ACM has an article on energy-efficient algorithms which might interest you. I haven't read it yet so cannot impart any of its wisdom.
尝试保留在片上内存(高速缓存)中进行空闲循环,将 I/O 保持在最低限度,将总线上的位翻转保持在最低限度。像 proms 和闪存这样的 NV 存储器在存储 0 时消耗的电量比存储 1 多(这就是为什么它们会擦除为 1,它实际上是 0,但在您看到它之前,传输器会反转该位,0 存储为 1,1 存储为零,这也是它们在失败时降级为 1 的原因),我不知道易失性存储器,dram 使用的晶体管数量是 sram 的一半,但必须刷新。
为了使所有这些变得重要,您需要从较低功率的系统开始,因为上述情况可能并不明显。例如,不要使用英特尔的任何产品。
Try to stay in on chip memory (cache) for idle loops, keep I/O to a minimum, keep bit flipping to a minimum on busses. NV memory like proms and flash consume more power to store zeros than ones (which is why they erase to ones, it is actually a zero but the transitor(s) invert the bit before you see it, zeros stored as ones, ones stored as zeros, this is also why they degrade to ones when they fail), I dont know about volatile memories, dram uses half as many transistors as sram, but has to be refreshed.
For all of this to matter though you need to start with a lower power system as the above may not be noticeable. dont use anything from intel for example.
如果您没有运行 Windows XP+ 或较新版本的 Linux,则可以运行一个后台线程,该线程除了 HLT 之外不执行任何操作。
这就是 CPUIdle 等程序降低功耗/热量的方式。
If you are not running Windows XP+ or a newer version of Linux, you could run a background thread which does nothing but HLT.
This is how programs like CPUIdle reduce power consumption/heat.
如果处理器被调整为在需要更少的周期时使用更少的功率,那么简单地让代码运行更高效就是解决方案。否则,除非操作系统公开某种电源管理功能,否则您无能为力。
If the processor is tuned to use less power when it needs less cycles, then simply making your code run more efficiently is the solution. Else, there's not much you can do unless the operating system exposes some sort of power management functionality.
将 IO 保持在最低限度。
Keep IO to a minimum.
在某些 ARM 处理器上,可以通过将稳压器置于待机模式来降低功耗。
On some ARM processors it's possible to reduce power consumption by putting the voltage regulator in standby mode.