Is there a way to set processor affinity?

In other OS's like Windows and Linux you can set an application to a single core instead of having it shift to all the (in my case) 4 CPU's that my Macbook Pro has to offer. And I was wondering if it was possible to do the same on Mac OS, as far as I've looked into it, even on High Sierra 10.13.4 this function is not available. I also spoke to an Apple Tech Support Executive and he confirmed that there's no official way of doing this, and he was unaware if any 3rd party applications could make this happen. I wonder why such a function does not exist on this OS. Maybe Apple could include such a function in the Activity Monitor, maybe after right clicking the process? Similar to how one could do it on Windows Task Manager.


If anyone is wondering why I would want to do such a thing as having an application use only a single core, the answer to that question is, older applications don't benefit from the multi-core processors, and work more efficiently on a single core processor. I've been trying to work with an older Java based application, and to an extent disabling hardware acceleration with the help of JDK through terminal helped, but it still does not make the application run on a single core. And also, some newer games also benefit from single-core rendering.


So if anyone has a way of doing this, do let me know.

Thank you.

Have you already looked at the low level Mach APIs? I haven't tried out, but there seems to be at least:


kern_return_t processor_assign

(

processor_t processor,

processor_set_t new_set,

boolean_t wait

);


http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/processor_assign.html


Using the low level Mach APIs is however not trivial. You should have a decent knowledge about i.e. Mach ports etc. in order to work with those.


However somehow I am bit sceptical about the performance benefit of your approach. I mean, restricting a process to a specific core might yield in a performance benefit if a) the most commonly executed code and b) accessed data of your app is quite small such that you can leverage the benefits of 1st and 2nd level cache tied to one core. As soon as you have to access the shared 3rd level cache you should probably get the same access times on any core. And the disadvantage of tying your process to one core is that your process is less likely to get execution slices by the scheduler. To counter the latter you might increase the scheduling priority, but still I have my doubts, especially since you say your intention is not running a very thin native app, but rather a full Java VM and who knows what running on top of that.

Is there a way to set processor affinity?
 
 
Q