<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Rust on KK的博客</title><link>https://spin6lock.github.io/tags/rust/</link><description>Recent content in Rust on KK的博客</description><generator>Hugo</generator><language>zh-CN</language><lastBuildDate>Sun, 12 Sep 2021 00:00:00 +0800</lastBuildDate><atom:link href="https://spin6lock.github.io/tags/rust/feed.xml" rel="self" type="application/rss+xml"/><item><title>CPU 画正弦曲线</title><link>https://spin6lock.github.io/2021/09/12/CPU%E7%94%BB%E6%AD%A3%E5%BC%A6%E6%9B%B2%E7%BA%BF.html</link><pubDate>Sun, 12 Sep 2021 00:00:00 +0800</pubDate><guid>https://spin6lock.github.io/2021/09/12/CPU%E7%94%BB%E6%AD%A3%E5%BC%A6%E6%9B%B2%E7%BA%BF.html</guid><description>&lt;img class="td-image" src="https://spin6lock.github.io/assets/images/cpu_sin_curve.png" alt="image" loading="lazy" decoding="async"&gt;&lt;p&gt;周末终于有时间尝试在树莓派上写代码，好久没写 Rust，&lt;a href="https://github.com/spin6lock/cpu_sin_curve"&gt; 写了个正弦曲线玩玩 &lt;/a&gt; :)&lt;/p&gt;&#10;&lt;p&gt;大致思路就是先定好取样点数量，以 300 毫秒为一个单位，算好 2*PI 周期的正弦曲线值，CPU 需要忙多少毫秒，闲多少毫秒，然后死循环跑就行。通过 while 循环不断检测经过的时间是否满足条件，满足后直接 sleep 过去。这里还需要用到一个第三方的库 core_affinity，将线程锁在第 2 个 CPU 核心上（第一个核心应该是 Linux 调度器所在的核心，避免影响它）&lt;/p&gt;</description></item></channel></rss>