More apple madness

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

zullil
Posts: 6442
Joined: Tue Jan 09, 2007 12:31 am
Location: PA USA
Full name: Louis Zulli

Re: More apple madness

Post by zullil »

Max wrote:As you have Xcode installed on your Mac, you could use the Instruments.app.

Google found this description:
https://www.logicprohelp.com/forum/view ... =5&t=88835

turning off hyperthreading from os x (lion and mountain lion

Postby jamiethemorris » Sun Oct 28, 2012 6:28 am

If you're processor supports hyperthreading, it can be helpful for audio work, but if you're getting the notorious single core overload, you are actually overloading half of a core. It is possible to toggle this function on and off in os x depending on which works better for the particular project you're working on. This requires xcode to be installed.

1. Open the instruments app, which is located in /Applications/Xcode/Contents/Applications. To get there you can right click on the xcode app and choose "show package contents." You can create an alias of this for your applications folder or drag it to the dock if you like.
2. You should get a pop-up window, just click cancel. Go to preferences, and you should see a checkbox at the bottom to disable hyperthreading.
3. Restart logic, and you can now use the full frequency of each core. You can use the instruments app to toggle hyperthreading on and off as needed.

I hope this helps anyone having overloads with a fast processor. find I find it to be more reliable than logic's built in function, and much more convenient than disabling it in the bios. This helped me tremendously, i was getting overloads even on a 4.5 ghz quad core.
-Max
Can be opened from Xcode (Version 4.6.3 (4H1503)) from the Xcode menu: Open Developer Tool-->Instruments

In the Instruments Preferences (General), I see "Hardware Multi-Threading" checked and also grayed out, so I cannot change the setting. Looks like all I can do is move a slider that will adjust the number of active cores (physical cores).

This is on a 2007 Macbook running Lion.

Apple seems focused on gadgets now. I got a 16 core Dell workstation and am happily running Linux.
Max
Posts: 247
Joined: Tue Apr 13, 2010 10:41 am

Re: More apple madness

Post by Max »

zullil wrote:In the Instruments Preferences (General), I see "Hardware Multi-Threading" checked and also grayed out, so I cannot change the setting. Looks like all I can do is move a slider that will adjust the number of active cores (physical cores).

This is on a 2007 Macbook running Lion.
Are you sure, that your cpu from 2007 supports hyperthreading?

-Max
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: More apple madness

Post by bob »

Max wrote:As you have Xcode installed on your Mac, you could use the Instruments.app.

Google found this description:
https://www.logicprohelp.com/forum/view ... =5&t=88835

turning off hyperthreading from os x (lion and mountain lion

Postby jamiethemorris » Sun Oct 28, 2012 6:28 am

If you're processor supports hyperthreading, it can be helpful for audio work, but if you're getting the notorious single core overload, you are actually overloading half of a core. It is possible to toggle this function on and off in os x depending on which works better for the particular project you're working on. This requires xcode to be installed.

1. Open the instruments app, which is located in /Applications/Xcode/Contents/Applications. To get there you can right click on the xcode app and choose "show package contents." You can create an alias of this for your applications folder or drag it to the dock if you like.
2. You should get a pop-up window, just click cancel. Go to preferences, and you should see a checkbox at the bottom to disable hyperthreading.
3. Restart logic, and you can now use the full frequency of each core. You can use the instruments app to toggle hyperthreading on and off as needed.

I hope this helps anyone having overloads with a fast processor. find I find it to be more reliable than logic's built in function, and much more convenient than disabling it in the bios. This helped me tremendously, i was getting overloads even on a 4.5 ghz quad core.
-Max
It comes RIGHT BACK on after a resume, a reboot, etc. On machines with a real BIOS, it is trivial to fix. On linux, a kernel boot option turns it off. Not apple.
wgarvin
Posts: 838
Joined: Thu Jul 05, 2007 5:03 pm
Location: British Columbia, Canada

Re: More apple madness

Post by wgarvin »

My first thought when I saw this thread, was that you could just work around the problem by setting your thread affinity masks to contain even-numbered bits only.

A little googling later, it was apparent that OSX doesn't even expose APIs for setting thread affinity. Apparently scheduling is the kernel's job and applications are not supposed to know or tamper how it works (or in this case, doesn't work).

I don't really see how any modern games could be ported to OSX without this; working around scheduler bullshit is sort of par for the course with Windows, and all of the game engines I've worked with like to create one thread per core and then do their own scheduling of chunks of work to those threads. In a situation like that, the OS moving the threads around is nothing but harmful. I guess the same is true of an SMP searcher; you want one thread per real core, and unless a core gets hijacked by the OS to use for something else, you don't really want it moving your threads around at all. But there's no APIs to find out if its happening or force it not to do that. Weaksauce. :lol:
zullil
Posts: 6442
Joined: Tue Jan 09, 2007 12:31 am
Location: PA USA
Full name: Louis Zulli

Re: More apple madness

Post by zullil »

Max wrote:
zullil wrote:In the Instruments Preferences (General), I see "Hardware Multi-Threading" checked and also grayed out, so I cannot change the setting. Looks like all I can do is move a slider that will adjust the number of active cores (physical cores).

This is on a 2007 Macbook running Lion.
Are you sure, that your cpu from 2007 supports hyperthreading?

-Max
Good point. It doesn't. My iMac does, but that's still running 10.6
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: More apple madness

Post by bob »

wgarvin wrote:My first thought when I saw this thread, was that you could just work around the problem by setting your thread affinity masks to contain even-numbered bits only.

A little googling later, it was apparent that OSX doesn't even expose APIs for setting thread affinity. Apparently scheduling is the kernel's job and applications are not supposed to know or tamper how it works (or in this case, doesn't work).

I don't really see how any modern games could be ported to OSX without this; working around scheduler bullshit is sort of par for the course with Windows, and all of the game engines I've worked with like to create one thread per core and then do their own scheduling of chunks of work to those threads. In a situation like that, the OS moving the threads around is nothing but harmful. I guess the same is true of an SMP searcher; you want one thread per real core, and unless a core gets hijacked by the OS to use for something else, you don't really want it moving your threads around at all. But there's no APIs to find out if its happening or force it not to do that. Weaksauce. :lol:
Yes. And the real issue is (a) the hyperthreading bug has been known for years, yet apple has not fixed it (2 real cores 4 logical cores, it will run a two thread program with nothing else running and STILL schedule both threads on one real core, something linux gets right). People have been complaining and asking about (1) processor affinity and (2) a way to disable hyperthreading. But they don't seem to listen to what users want...
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: More apple madness

Post by michiguel »

bob wrote:
wgarvin wrote:My first thought when I saw this thread, was that you could just work around the problem by setting your thread affinity masks to contain even-numbered bits only.

A little googling later, it was apparent that OSX doesn't even expose APIs for setting thread affinity. Apparently scheduling is the kernel's job and applications are not supposed to know or tamper how it works (or in this case, doesn't work).

I don't really see how any modern games could be ported to OSX without this; working around scheduler bullshit is sort of par for the course with Windows, and all of the game engines I've worked with like to create one thread per core and then do their own scheduling of chunks of work to those threads. In a situation like that, the OS moving the threads around is nothing but harmful. I guess the same is true of an SMP searcher; you want one thread per real core, and unless a core gets hijacked by the OS to use for something else, you don't really want it moving your threads around at all. But there's no APIs to find out if its happening or force it not to do that. Weaksauce. :lol:
Yes. And the real issue is (a) the hyperthreading bug has been known for years, yet apple has not fixed it (2 real cores 4 logical cores, it will run a two thread program with nothing else running and STILL schedule both threads on one real core, something linux gets right). People have been complaining and asking about (1) processor affinity and (2) a way to disable hyperthreading. But they don't seem to listen to what users want...
Totally out of curiosity, how is it done in FreeBSD and the likes? (OS X is a closer relative of those).

One problem I recently faced porting is that OS X does not support unnamed semaphores. So, in order to say OS X is POSIX compliant, they have the function, but it just returns an error :shock:. My point is, be careful with POSIX functions. I ended up implementing my own version of semaphores based on condition variables, which they support. To me, it sounds they do not like people using them. Maybe they are encouraging people to use multiprocessing rather than multithreading, hence the named semaphores support? It is not that difficult to implement. Since even I can do it, I am sure there is not technical issue behind it.

Miguel
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: More apple madness

Post by bob »

michiguel wrote:
bob wrote:
wgarvin wrote:My first thought when I saw this thread, was that you could just work around the problem by setting your thread affinity masks to contain even-numbered bits only.

A little googling later, it was apparent that OSX doesn't even expose APIs for setting thread affinity. Apparently scheduling is the kernel's job and applications are not supposed to know or tamper how it works (or in this case, doesn't work).

I don't really see how any modern games could be ported to OSX without this; working around scheduler bullshit is sort of par for the course with Windows, and all of the game engines I've worked with like to create one thread per core and then do their own scheduling of chunks of work to those threads. In a situation like that, the OS moving the threads around is nothing but harmful. I guess the same is true of an SMP searcher; you want one thread per real core, and unless a core gets hijacked by the OS to use for something else, you don't really want it moving your threads around at all. But there's no APIs to find out if its happening or force it not to do that. Weaksauce. :lol:
Yes. And the real issue is (a) the hyperthreading bug has been known for years, yet apple has not fixed it (2 real cores 4 logical cores, it will run a two thread program with nothing else running and STILL schedule both threads on one real core, something linux gets right). People have been complaining and asking about (1) processor affinity and (2) a way to disable hyperthreading. But they don't seem to listen to what users want...
Totally out of curiosity, how is it done in FreeBSD and the likes? (OS X is a closer relative of those).

One problem I recently faced porting is that OS X does not support unnamed semaphores. So, in order to say OS X is POSIX compliant, they have the function, but it just returns an error :shock:. My point is, be careful with POSIX functions. I ended up implementing my own version of semaphores based on condition variables, which they support. To me, it sounds they do not like people using them. Maybe they are encouraging people to use multiprocessing rather than multithreading, hence the named semaphores support? It is not that difficult to implement. Since even I can do it, I am sure there is not technical issue behind it.

Miguel
I don't use any BSD-based systems, in Linux just add the kernel boot option "noht" to the boot options and you are done. Sometimes when doing a demo in my O/S class, where I prefer to have just one CPU, you can boot with "nosmp" and only have one core, period.

Funny thing is, mavericks has a kernel boot option "cpus=n" but it is broken. On my 2 physical core mac, with 4 logical cores, "cpus=2" gives me one physical, two logical cores, which defies logic.

The CPU affinity stuff has been on every box I have tried over the past 20 years, EXCEPT for mac os x. The process scheduler makes it very difficult to do any sort of performance measuring or testing since it doesn't understand the simple idea of one thread per physical core unless there are more threads than physical cores.

I've been working on my parallel search quite a bit. For the last CCT event using my 4-year old 2x6 core 2.66ghz box, I was seeing speeds of over 30M nodes per second. I have pushed that to here so far, and am still working:

time=2:23(90%) n=7371856373 fh1=0.91% nps=51.5M


That 90% means that 90% of 12 cores were 100% busy, but that leaves 1.2 cores MIA. I am working on getting those back as well. We have some sort of 24 core box that should be up within a week, which is why I am trying to see how hard I can push this 12 core box first...

Unfortunately I can barely test on my macbook when fiddling with threads. And even when not using threads I see a single thread bouncing back and forth among the cores, which is nonsensical.
Max
Posts: 247
Joined: Tue Apr 13, 2010 10:41 am

Re: More apple madness

Post by Max »

bob wrote:It comes RIGHT BACK on after a resume, a reboot, etc. On machines with a real BIOS, it is trivial to fix. On linux, a kernel boot option turns it off. Not apple.
You could use this tiny kext "Turbo Boost Disabler for Mac OS X" source code and change the msr register responsible for hyperthreading. There is a link to the Intel Architectures Software Developer Manual too.

-Max
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: More apple madness

Post by bob »

Max wrote:
bob wrote:It comes RIGHT BACK on after a resume, a reboot, etc. On machines with a real BIOS, it is trivial to fix. On linux, a kernel boot option turns it off. Not apple.
You could use this tiny kext "Turbo Boost Disabler for Mac OS X" source code and change the msr register responsible for hyperthreading. There is a link to the Intel Architectures Software Developer Manual too.

-Max
I am not sure what the kernel is going to do if a processor that is supposed to be present is suddenly "MIA". I'd expect a deadlock somewhere.

I did a quick check and that code is over 2 years old, which means likely not compatible with Mavericks. There have been all sorts of incompatibilities between Mavericks and previous versions (lion, mountain lion).