Isolate processor to run only my program

Asked

Viewed 141 times

1

It has as I isolate the processor to run only my program in C?

It’s more of a didactic and scholarly question that my I.A teacher passed on to me.

He asked us to perform millions of operations to sum up real numbers, and take the time it took the processor to execute them. Then split, and find the average that the processor takes to perform 1 sum operation.

And do this with other operations of subtraction, multiplication and comparison.

How do I completely isolate the processor, and it only execute my code? He left it free to do in any language, but I believe that C is the most viable, can be Assembly also.

If it is possible for Windows to stop all the processes to do just that calculation, won’t the OS quit? And how do I do this?

  • 2

    How about starting with [Process Escalation](https://pt.wikipedia.org/wiki/Escalonamento_de_processos "Process Escalation"). and then something more practical like: [Nice on Unix](https://en.wikipedia.org/wiki/Nice_(Unix) "Nice")

  • 1

    Have any answers solved what was in doubt? Do you need something else to be improved? Do you think it is possible to accept it now?

3 answers

3

This is not possible in "normal" operating systems, the operating system controls this. What you can do is ask for high priority for the operating system, which will deliver as it wants. You can determine affinity and try to make your process only run on one of the processors, but this is OS discretion.

So you can do it in any language you think best, the only question is to call the OS API that defines process scheduling.

  • 1

    In Unix systems, this priority is defined by nice program. The less cool, the more priority. I forgot what name given to it in Windows

  • Not even if I do it in Assembly ? Since it will be manipulating directly in the registers ?

  • 2

    Nothing can pass over the operating system. It is not the registrar that controls process priority, it is the operating system.

  • @Bruno you can even get one flop higher direct with Assembly using only registers, but usually this becomes irrelevant because higher-level uses (such as matrix multiplication) require using a lot of floating-point memory. Usually more until the number of registers

3

This all depends on your OS. In modern OS you have Apis that allow you to take processor usage statistics from the program. That is, how much CPU time was spent exclusively to run your program, how much time it took to run in the kernel, how much time he spent in total, and so on.

Thus, although vc has no exclusive use of the CPU, with these statistics, vc can account for the use of the CPU, as if it were totally of the program.

In the UNIX world, you can use getrusage. In the case of Windows, you can use Getprocesstimes

3


Regarding GNU/Linux operating systems, there are ways to do this yes, basically Voce will have to use the cpuset.

Example:

$ mkdir /cpuset 
$ mount -t cpuset none /cpuset/
$ cd /cpuset

$ mkdir sys                               # cria um cpuset para o sistema operacional
$ /bin/echo 0-2 > sys/cpuset.cpus         # atribui os cpu cores 0-2
$ /bin/echo 1 > sys/cpuset.cpu_exclusive
$ /bin/echo 0 > sys/cpuset.mems     

$ mkdir rt                                 # cria cpuset para o teu processo
$ /bin/echo 3 > rt/cpuset.cpus             # atribui o cpu core 3

$ /bin/echo 1 > rt/cpuset.cpu_exclusive
$ /bin/echo 0 > rt/cpuset.mems
$ /bin/echo 0 > rt/cpuset.sched_load_balance
$ /bin/echo 1 > rt/cpuset.mem_hardwall

# direciona todos os processos do cpuset default para o cpuset sys
$ for T in `cat tasks`; do echo "Moving " $T; /bin/echo $T > sys/tasks; done

After this setup step start your process (program) and direct to the dedicated cpuset newly created.

$ /bin/echo $PID > /cpuset/rt/tasks

Consult more man cpuset.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.