發表文章

CPU 如何提高吞吐量

圖片
之前我们分析过 CPU 是如何工作的,经过「取指、译码、执行、访存、写回、更新」等几个阶段,说成白话就是: 取指:从内存获取要执行的地址(PC); 译码:拿到 PC 地址后,根据地址提示去哪个寄存器取数据; 执行:取到数据后,执行计算「加减乘除」; 访存:计算完成后,根据地址提示去哪个寄存器写数据; 写回:根据寄存器地址,把结果通过端口输出计算结果; 更新:流程结束后,更新 PC 地址,来执行下一次的操作。 有限循环上面的工作逻辑。 具体流程如图所示: 上面 3 条指令,一条指令完成后,才能开始下一条。也就是说第 1 条指令在执行期间,第 2 条指令只能等待。 我们以每秒十亿条指令为单位来描述吞吐量, 流水线吞吐量的计算公式是: 吞吐量 = 每个阶段处理的指令数 / 流水线的时钟周期。 按上面的指令逻辑来计算:吞吐量为每秒 30 亿条指令,不过, 这样有个很明显的问题,等待时间太长了。 于是聪明人想到了一个好办法:让 CPU 增加流水线作业。 如何做到的呢? 拿江南皮革厂举例: 1染色、2补边、3烘干、4包装,里面的工序分工明确,哪个阶段负责什么作业,各自负责自己的作业。当一只鞋离开当前工序时,另一只新鞋就可以进入了。所以 … 当第一只鞋进入补边阶段,第二只鞋就可以进入染色阶段了。 如下图: 图片来自于普客园(zhangly) 在 CPU 周期里,第一条指令进入译码阶段的时候,指令2就可以进入取指阶段。 这样流水化一套流程下来,吞吐量达到了 80 亿条指令。 那是不是我一直堆硬件,一直增加并行指令的逻辑就可以无限增长了? 流水线 有个重要的特征,它提高了系 统的吞吐量,在单位时间内,提高了执行指令的数量。 不过,会增加一些延迟,也就是一整条指令完成的时间(因为会增加中间流程状态)。 所以 … 流水线也有自己的局限性。 一、不一致的划分 如果处理器的一些硬件单元无法划分成多个较小的单元,那它需要更多的时间来完成作业,而另一些指令完成时间会很快。这样的差异会导致某些阶段时间特别长,难以优化。 木桶原理:整体系统的强弱取决于其中最薄弱的部分,就像一个木桶的容量取决于最短的那块木板一样。 所以,需要尽量将处理器划分成多个任务阶段,每个阶段负责处理特定的任务,尽量保持时间相对一致,来平衡整个处理过程的性能。 将系统设计成具有相同作业的阶段,是一个严峻的挑战。 二、流水线不能过...

Movie Title Generator

This project is called "Movie Title Generator" — a simple online tool that helps you quickly generate titles for short videos. It's built with Next.js and Tailwind CSS , and the title generation is powered by the Deepseek API . Website: https://movietitlegenerator.com/ Using it is super easy: just describe your video content and click "Generate Titles" . The tool will instantly give you 6 title suggestions — perfect for movies, short films, or scripts — great for boosting your video promotion. You can also customize the style of the titles: Want something funny , formal , salesy , or creative ? Just pick the tone you like. Choose the use case : movie, research paper, ad copy, email subject, etc. Pick your genre : action, horror, animation, documentary, and many more. If you like a title, click "More Like This" to dive deeper and get more variations based on that idea. You can repeat this up to 5 layers for more specific results. Give it a ...

Minute Timer Online

Online use of minute timers Introduction: Welcome to our minutetimer.online website! Whether you're counting down to a special event, managing your work sessions, or simply tracking time, our user-friendly platform has got you covered. Key Features: Customizable Timers: Create timers that fit your needs. You can set timers for minutes, seconds, or even hours, and customize them to any duration you desire. Start, Pause, and Reset: Easily start, pause, and reset timers with just a click of a button. Keep track of time effortlessly. Countdown Alerts: When your timer reaches zero, our website will alert you. Get notified through visuals and, if desired, with a pleasant audio signal. Edit and Save: Made a mistake or need to adjust your timer? No problem! Edit your timers and save changes instantly. Use Cases: Productivity: Boost your productivity by breaking your tasks into manageable time blocks with our timers. Fitness: Time your workouts and rest intervals to opti...

Time Tracking Made Simple! timeago.online

It's the time-tracking ninja you never knew you needed. No more guessing or stressing about schedules – this bad boy keeps it real-time and fuss-free. Just hit up https://timeago.online and see for yourself! This thing is all about you, your time, and doing it your way. Whether you're a 30-minutes-ago or 7-hours-ago clock kind of person, timeago.online is down for whatever. Minutes, hours, days – it's your time, your rules. Simple clicks, no tech drama. Instant Updates:      Timeago.Online keeps it real-time. Your schedule stays fresh, no lag! No-Nonsense Interface:      Easy clicks, no fuss. Timeago.Online is sleek and user-friendly. Your Time, Your Rules:      Customize your clock style. 12-hour or 24-hour – your call! Time in Any Flavor:      Minutes, hours, days – Timeago.Online handles it all. Simple time tracking, no sweat. Access Anywhere:      Where you go, we go. Timeago.Online is your pocket-sized tim...