开发者

Dedicating all processor power to a task

Let's say we have a very processor-intensive task at hand which could be effectively parallelized. How can we dedicate all or almost all available processor power to performing开发者_如何学Python that task?

The task could be a variety of things, and iterative Fibonacci number generation that saves recorded numbers would be just one example.


You have probably provided too few details about your target environment.

Typically when using an RTOS you can either disable interrupts so that neither the scheduler nor interrupt service routines will run, or you can apply a task lock so that the scheduler will not run, but ISR's will continue to run. You can achieve the same effect as a task lock by boosting the priority of the task to the highest priority.

If you are not using and RTOS (or no OS) you typically do not have that much control of scheduling, but if your thread runs without yielding (i.e. calling a function that causes the thread to wait), and other threads and processes do not need many cycles, your thread will get pretty much all of the CPU. For example a busy loop in Windows will most of the time show up as 100% usage of one core in the task monitor, if you are not running other processor intensive tasks. If your processor has multiple cores, you'll have to parallelize the task somehow to make it use all of them.

I/O calls typically cause thread blocking, so your requirement to 'save' the results may cause an issue. The solution is to buffer the results in memory (directly or as a queue or write-cache), and defer output until completion of all calculations.


The operating system handles CPU dedication. Most of the time, if your program needs more power, it'll get it, but higher-priority ("nice" in Linux) processes will be higher in the queue for CPU time requests.


Well, it heavily depend on the context of your projet, and what are the other tasks running on the processor.

Consider these two examples :

1/ The processor is only doing some low priority jobs, let's say as communication on USB, CAN, SPI or whatever you have, that you don't care during the computation (processort intensive task), for example because commnication layer waits for the output of this task. Then, you can assign (statically or dynamically, depending on the operating system you have) this task a very high priority. You may also stop other tasks by whatever synchronization avaibale to you (messages, task pause ...)

2/ The processor is doing high priority jobs, even smalls one (watchdog, regulation, measurements), so you can assign your task a lower priority as it will take the residual microprocessor power, and that can be enough !

So, maybe you will have questions about HOW TO assign priority to task ... but it all depends on the your firmware architecture and the choice you made between a Operating system or a big 'main' by hand !

Give us more details if you need precise answers.


Remove all unnecessary processes.

Turn off every disk access and other blocking IO caused by this or other process. If you have to do this, do it late, batch it. Using multiple cores in parallel threads and setting CPU-to-process or core-to-process affinity could help - the last one will be probably OS-specific.

Set the process high priority so it gets larger share.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜