CPU周期的限制装配执行数 [英] Limiting assembly execution number of cpu cycles

查看:110
本文介绍了CPU周期的限制装配执行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,动态加载在未知的组件实现指定接口。我不知道大会的内容和目的,其他比它实现我的接口。

I have a project that dynamically loads in unknown assemblies implementing a specified interface. I don't know the contents or purposes of the assembly, other than it implementing my interface.

我需要以某种方式限制的处理能力提供给这些组件的数量。处理器优先级是不是我要找的。我不能用秒表并分配一定的时间装配运行的服务器可能是任意忙。

I need to somehow restrict the amount of processing power available to these assemblies. Processor priority is not what I'm looking for. I can't use a stopwatch and assign a certain amount of time for the assembly to run as the server might be arbitrarily busy.

最理想的,我想指定一些完全加载CPU占用独立的措施。如果需要的话我可以运行的程序集在自己的进程。

Optimally I'd like to specify some completely load independent measure of CPU usage. I can run the assemblies in their own process if necessary.

有没有办法以某种方式衡量一个给定线程的总数超过时间的CPU使用率(或过程,虽然线程将是最佳的)?

Is there any way to somehow measure the total over-time CPU usage of a given thread (or process, though thread would be the optimal)?

可能我在使用过程中性能计数器,或者他们,因为我怀疑,太不可靠?虽然我不需要的非周期的准确性,我需要相当高精确度来限制分配给每个组件执行的计算能力

Might I use the process performance counters, or are they, as I suspect, too unreliable? While I don't need to-the-cycle accuracy, I would need rather high accuracy to limit the computing power allocated to each assembly execution.


要推断了一下我的情况。我不是在寻找的过程中优先级的原因是,我不害怕耗尽我的资源,我只是需要确保我可以衡量多少的资源给定的程序集使用 - 因此我的观点有关服务器被任意忙碌着。

To extrapolate a bit on my situation. The reason I'm not looking for prioritization of the processes is that I'm not afraid of exhausting my resources, I just need to ensure I can measure "how many" resources a given assembly uses - thus my point about the server being arbitrarily busy.

想象示例场景中,你有两个组件X和Y他们每个人实现一个给定的算法,我想做一个原始的测试,装配干得最快的工作。我运行的每个组件并让它运行,直到它的使用Z的资源,在这一点上,我评估其组装做了最好的工作。在这种情况下,我不介意,如果一个组件运行在100%的CPU三秒钟,而另外一个在5分钟内运行了2%的CPU - 这是总的资源使用情况是重要的。

Imagine the example scenario where you have two assemblies X and Y. Each of them implement a given algorithm and I want to do a primitive test of which assembly gets the job done quickest. I run each assembly and let it run until it's used "Z" resources, at which point I evaluate which assembly did the best job. In this case, I don't mind if one assembly runs at 100% CPU for three seconds, while the other one runs for 2% CPU over 5 minutes - it's the total resource usage that's important.

我想我也许可以使用的CPU时间perfcounter做粗限制。侏儒每个组件在一个新的线程,并让它运行,直到它的使用一定量的CPU时间,在这一点上,我会杀了过程和评估结果。我只是怕这是不够准确的。

I'm thinking I might be able to use the CPU time perfcounter to do a crude limitation. Runt each assembly in a new thread and let it run until it's used a given amount of CPU time, at which point I'll kill the process and evaluate the results. I'm just afraid it won't be accurate enough.

推荐答案

像大多数x86操作系统的工作就是使用preemptive线程调度。操作系统初始化主板上一个计时器,将发送一个处理器中断每个,说100毫秒。 (这是一个执行分片。好行为计算密集型程序通常应启动等待的东西把他们在等待队列前,此限制)。当处理器得到中断,切换执行到操作系统内核。

The way most X86 operating systems work is to use preemptive thread scheduling. The OS initializes a timer on the mother board that will send an interrupt to the processor every, say 100ms. (This is an execution slice. Well behaving computationally intensive programs should typically start to wait for something putting them in wait queue before this limit.) When the processor gets the interrupt, it switches execution to the OS kernel.

因此​​,它应该是技术上无法限制线程上执行的单核系统的东西比这个计时器更精细。

Thus it should be technically impossible to limit thread execution on a single core system to something more granular than this timer.

使用公平的计划,你可以有一个旋转的管理者(因为你不感兴趣的节能),着眼于各自的线程的执行时间,如果他们已经太久执行终止它们。

With "fair" scheduling, you could have a spinning manager (since you're not interested in saving power) that looks at execution time of the respective threads and terminates them if they've executed for too long.

这篇关于CPU周期的限制装配执行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆