Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an Intel E5620 processor. I have used cat /proc/[pid]/stat to determine what processor the process was last run on (39th field). How can I ensure that a process is dedicated to a processor (I have 8 available) or better yet, how can I dedicate a process to a core (I have 4)?

share|improve this question
6  
Why do you want to do this? The CPU scheduling in most operating systems these days is far superior to a blunt instrument CPU C is only available to process P type of assignment. –  voretaq7 Oct 6 '11 at 17:51
1  
@voretaq7: Because I have a need to do some dedicated processing. I am porting a PowerPC application to linux. Previously it was housed in a VME chassis. –  Brian Oct 6 '11 at 17:53
1  
Do you need to tie the process to a processor (that may be used by other programs too), or do you want to dedicate the processor to a process (so no other processes can get to that CPU)? And again - Why do you want to do this? (what is "dedicated processing"? Why can't it be moved from CPU to CPU?) –  voretaq7 Oct 6 '11 at 18:02
    
@voretaq7: Because I have a process to consume 200MB/s data from PCIe and I need to consume this very fast. I don't want anyone else on that processor. –  Brian Oct 6 '11 at 18:07
    
See my answer below. As @MikeyB noted you should not be trying to outsmart the scheduler - There are proper ways to ensure that you always have CPU cycles when you want them, and they make the scheduler work for you rather than against you. –  voretaq7 Oct 6 '11 at 18:16

5 Answers 5

Based on your comment on MikeyB's answer you're trying to solve this the wrong way IMHO --

Both numactl and taskset will lock your process to a CPU, but they won't keep other processes off that CPU.
If someone else is on that CPU when your process needs it you will have to wait.

A better solution is to set your process' nice value to something that will cause it to aggressively grabt he CPU (something like -20), and if that's still not enough set your process to realtime priority using rtprio, and let the scheduler do what it has to do to make sure that your process always has CPU cycles when it asks for them.

Trying to outsmart the scheduler is, as MikeyB pointed out, generally a Bad Idea. Let it do what it's designed to do, and ask for CPU cycles the RIGHT way (nice values and rtprio).

share|improve this answer
    
nice is a good idea, but I have processes running via rc.local. Not sure how to su to root to ensure that the processes run at the highest value in some instances at startup. I guess I should ask another question regarding that. –  Brian Oct 6 '11 at 18:18
    
I don't see rtprio on my RHEL5.3 install. IS there a RPM for this? –  Brian Oct 6 '11 at 18:23

If you have it installed you can use the taskset command e.g.

taskset -c 2 -p 2345 

to run process 2345 on cpu 2

share|improve this answer

numactl allows you to bind a process to a core or physical CPU as well as forcing a memory allocation policy.

Usually, this is not necessary. Stop trying to outsmart the scheduler.

share|improve this answer
    
I have 200MB/s of data I need to consume through the PCIe slot on a 2.4 GHz processor. I need to be able to consume this very fast and control where the processes are running. –  Brian Oct 6 '11 at 17:59
    
Ah, in this case that's a perfectly sensible use case. Bravo! –  MikeyB Oct 6 '11 at 18:31

read man taskset - it has everything you need

share|improve this answer

To bind a process PID 12345 to the first processor, try this:

# taskset -p 0x00000001 12345
share|improve this answer
    
I'm getting execvp: No such file or directory failed to execute -p –  Brian Oct 6 '11 at 18:00
    
Sorry, I missed the order. Updated. –  quanta Oct 6 '11 at 18:05
    
hmm, this answer here seemed to work : superuser.com/questions/240996/… –  Brian Oct 6 '11 at 18:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.