操作系统每秒指令数

发布于 2024-10-06 22:48:23 字数 240 浏览 6 评论 0原文

我是计算机体系结构和设计的新手。我的问题是高级程序指令集在CPU中依次执行。执行这些指令时是否甚至涉及操作系统指令作为开销?例如:如果在 2 GHz 处理器中,有 2*10^9 条指令可以在 2*10^9 时钟周期内执行。那么操作系统总是每秒大约需要执行1*10^9条指令。这种开销是否始终存在,并且只有另外 1*10^9 指令可免费执行以供其他自定义调度程序执行?

这是否意味着操作系统应该始终执行尽可能少的指令,以便可以容纳更多要执行的其他程序?

I am new to Computer Architecture and Design. My question was a high level program Instruction set are executed in CPU one after another. Does it even involve Operating System instructions as overhead when executing these instructions ?. For Example: If in 2 GHz processor there are 2*10^9 instructions that can be executed in 2*10^9 clock cycles. Then the operating system always takes about 1*10^9 instructions to execute per second. Is this overhead always there and only another 1*10^9 instructions are available free for execution for other custom scheduled programs to execute ?

Does that mean operating systems should always have as less instructions to execute as possible so it can accomodate more of other programs to be executed ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦初醒的夏天 2024-10-13 22:48:23

这两个问题都是肯定的,但在一定范围内。

首先,是的,如果操作系统每秒使用 1e9 条指令,则每秒仅剩 1e9 条指令。

其次,是的,您希望尽可能减少这种情况;这就是所谓的“开销”。

“限制”是操作系统确实为您做了好事。例如,考虑一下多任务处理,其中操作系统允许您同时运行多个程序,并在它们之间共享处理器。一方面,涉及到开销。另一方面,如果没有它,当没有程序可以运行时,您要么让机器长时间闲置,要么您必须自己模拟多任务处理——这至少需要与操作系统一样多的指令。

Yes to both questions, within limits.

First, yes, if the OS is using 1e9 instructions/sec, there are only 1e9 instructions/sec left.

Second, yes, you'd like to reduce that as much as possible; it's called "overhead".

The "limits" are that the OS does do good things for you. Consider, for example, miltitasking, where the OS lets you run several programs concurrently, sharing the processor among them. On the one hand, there is overhead involved. On the other hand, without it you'd either leave the machine idle for long stretches when no program could run, or you'd have to simulate multitasking yourself -- which would take at least as many instructinos as the OS would.

恰似旧人归 2024-10-13 22:48:23

稍微扩展一下马丁先生的回应:(注意,这是高度简化的)
操作系统的工作是处理那些程序不想自己做的事情——比如处理 I/O 中断和安排多个任务来共享机器。在运行一个应用程序的机器上的完美世界中,该程序将控制 CPU,直到它需要操作系统为其执行某些操作,例如从磁盘文件中读取下一条记录(这会调用分层“服务”来找出哪个磁盘、哪个文件、哪个记录、哪个字节并计算从磁盘控制器请求哪个磁道上的哪个磁盘块一个典型的“真实”机器还运行一堆后台任务,保持屏幕更新、读取时钟。 、检查新邮件、下载补丁等。这就是优先级发挥作用的地方。某些任务以较低优先级运行,因为我们不关心它们何时完成,例如更新 Windows 中的系统托盘图标以获取新邮件通知。其他任务以高优先级运行,但时间很短,例如在屏幕上跟随鼠标并将其从指针更改为手。
请记住,典型的任务在需要某些操作系统服务并在发生时进入睡眠状态之前只执行几百条指令。大型应用程序可能有数十万条“指令”,但再次花费一些时间等待其他事情,从按钮按下或键盘输入到另一台计算机上的数据库查找的响应。
CPU 密集度最高的应用程序(例如将 Pi 计算到小数点后一百万位)可能会长时间消耗 99.9% 的处理器,但操作系统会定期中断它,只是为了查看是否需要执行其他操作。
回到 DOS 时代(1980 年代),程序实际上可以占用 CPU 一段时间,但如果它需要读取、写入或在屏幕上键入某些内容,则必须通过 BIOS 来执行此操作,除非该程序是编写来执行这些基本操作本身。其中一些是计算机游戏的响应方式,通过执行直接修改屏幕所需的特定操作,并直接从键盘或鼠标设备缓冲区读取,绕过操作系统。
希望我没有让你更加困惑......

To expand a bit on Mr. Martin's response: (beware, this is highly simplified)
The job of the OS is to handle those things which the program doesn't want to odo for itself - like handle I/O interrupts and schedule multiple tasks to share the machine. In a perfect world on a machine running one application program, the program would have control of the CPU until it needed the OS to do something for it, like read the next record from a disk file (which calls layered 'services' to figure out which disk, which file, which record, which byte and calculate which disk block on which track to ask fro from the disk controller. A typical 'real' machine also has a bunch of background tasks running, keeping the screen updated, reading the clock, checking for new mail, downloading patches, etc. This is where priorities come in. some tasks run at lower priority, because we don't care when they're done, like updating the system tray icon in Windows for New Mail notification. Other tasks run at a high priority, but are very short, like following the mouse on the screen and changing it from a pointer to a hand.
Keep in mind that a typical task only does a few hundred instructions before needing some OS service and going to sleep while it happens. Large applications may have hundreds of thousands of 'instructions,' but again spend some of thir time waiting for something else, from a button push or keyboard entry to a response from a database lookup on another machine.
The most CPU intensive applications like calculating Pi to a million decimal places may consume 99.9% of the processor for long periods, but the OS is going to interrupt it periodically just to see if something else needs to be done.
Back in the days of DOS (1980's) the program could actually take the who CPU for awhile, but if it needed to read or write or type something to the screen, it would have to as the BIOS to do that, unless the program was written to do those basic operations itsef. Some of this is how computer games respond, by doing the specific operations needed to modify the screen directly, and read directly from the keyboard or mouse device buffers, bypassing the OS.
Hopefully, I haven't confused you more...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文