How to set CPU affinity (taskset)?

JGFoster

Registered
I understand that Leopard has more sophisticated processor affinity capabilities and I am wondering if there is a way to get to that from a C-level API (and from the command line).

The reason I want this is to limit the functionality of a free version of a product (e.g., Oracle Express Edition and and Microsoft SQL Server Express Edition) so that it runs on only one CPU, no matter how many are on the machine. This way we can let developers use the real product for development and small projects, but we can charge when scaling is needed.

James
 
As far as I know, Microsoft SQL Server Express Edition does not run on Mac OS X.

Are you running Mac OS X or Windows on your Mac computer?
 
I am not trying to run SQL Server on Mac OSX. I am trying to set CPU affinity using a C API for a competing product that has a similar licensing model but runs on Macintosh OSX 10.5.
 
The release notes were helpful and come close to what I need. Thread affinity (as opposed to process affinity) would be fine. The only problem I see is in the notes where it says "Threads with affinity tags will tend to remain in place" (emphasis added). Since my goal is actually performance degradation(!), I wonder if the OS will move threads if my preferred CPU is busy.
 
It's possible, but I don't know enough about Mac OS X's thread/processor management to say one way or the other.

I know what you're talking about on the Windows-side, though -- with the ability to "tell" a certain process to only use Core 1, or Processor 2, or the like. I think since Mac OS X is a much more heavily threaded operating system with a different way of managing processes that the kind of control you're looking for may not exist, or may be managed in a completely different way, without control over specific processors or cores.
 
Would it be possible to have the limited version of your program only use one thread? If you did, it would effectively limit the program to one core, since OS X can't split a single thread across two cores.
 
Would it be possible to have the limited version of your program only use one thread?

No. The application (an enterprise object database) at a minimum runs a dozen processes, each of which can have multiple threads. The idea is to run the exact same software that is used by existing customers (who currently run thousands of processes across hundreds of machines). We can set CPU affinity on Linux, so have an easy way to license a free version with confidence that customers will contact us when they need to scale their application.
 
You might want to take a look at this VERY old thread and see if it can point you in the right direction. The last post mentioned something about XGrid.

However, in most of the hits I found on Google from various forums and mailing lists, it seems that Mac OS X's kernel is able to manage processor affinity efficiently through its algorithms (or at least Apple says sounder "Multicore Optimized" :p) so that there would be no need for manual configuration of processor affinity. Of course, Leopard (or Leopard Server) might have the tools built in for doing this manually of need be.
 
Back
Top