Dual-core CPUs and Multi-threading [modified]
-
When you have a dual core CPU, does a multi-threaded app "just know" that it can use the 2nd core, or can/must you set cpu affinity on a thread-by-thread basis in order to take advantage of the 2nd core? Now that I have a dual-core CPU, I was thinking about writing an app to compare the speed of using just one core versus using both cores to run a calculation-intensive thread. (It's fun to play with ne hardware.) -- modified at 8:33 Friday 4th August, 2006 (for spelling errors)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
When you have a dual core CPU, does a multi-threaded app "just know" that it can use the 2nd core, or can/must you set cpu affinity on a thread-by-thread basis in order to take advantage of the 2nd core? Now that I have a dual-core CPU, I was thinking about writing an app to compare the speed of using just one core versus using both cores to run a calculation-intensive thread. (It's fun to play with ne hardware.) -- modified at 8:33 Friday 4th August, 2006 (for spelling errors)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001You do not have to specify affinity, windows 'should' do this for you and you application should make use of all of the available CPUs based on your processes default affinity. Typeically you only set affinity if you need to limit the process/thread to a single or specific CPU. -- modified at 8:12 Friday 4th August, 2006
Darka [Xanya] "When you're taught to love everyone, to love your enemies, then what value does that place on love?"
-
When you have a dual core CPU, does a multi-threaded app "just know" that it can use the 2nd core, or can/must you set cpu affinity on a thread-by-thread basis in order to take advantage of the 2nd core? Now that I have a dual-core CPU, I was thinking about writing an app to compare the speed of using just one core versus using both cores to run a calculation-intensive thread. (It's fun to play with ne hardware.) -- modified at 8:33 Friday 4th August, 2006 (for spelling errors)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001John Simmons / outlaw programmer wrote:
It's fun to play with ne hardware.
It always is.
Abhishek
-
When you have a dual core CPU, does a multi-threaded app "just know" that it can use the 2nd core, or can/must you set cpu affinity on a thread-by-thread basis in order to take advantage of the 2nd core? Now that I have a dual-core CPU, I was thinking about writing an app to compare the speed of using just one core versus using both cores to run a calculation-intensive thread. (It's fun to play with ne hardware.) -- modified at 8:33 Friday 4th August, 2006 (for spelling errors)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
When you have a dual core CPU, does a multi-threaded app "just know" that it can use the 2nd core, or can/must you set cpu affinity on a thread-by-thread basis in order to take advantage of the 2nd core? Now that I have a dual-core CPU, I was thinking about writing an app to compare the speed of using just one core versus using both cores to run a calculation-intensive thread. (It's fun to play with ne hardware.) -- modified at 8:33 Friday 4th August, 2006 (for spelling errors)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001John Simmons / outlaw programmer wrote:
It's fun to play with new hardware
<voice_of_envy> And to brag about it :-D. </voice_of_envy>
Software Zen:
delete this;
-
When you have a dual core CPU, does a multi-threaded app "just know" that it can use the 2nd core, or can/must you set cpu affinity on a thread-by-thread basis in order to take advantage of the 2nd core? Now that I have a dual-core CPU, I was thinking about writing an app to compare the speed of using just one core versus using both cores to run a calculation-intensive thread. (It's fun to play with ne hardware.) -- modified at 8:33 Friday 4th August, 2006 (for spelling errors)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001The OS allocates threads to logical processors, if they're runnable (not blocked or suspended), in order of priority. A thread will run for up to its quantum on any CPU on which it's allowed to run (you can set affinity to restrict a thread to specific logical processors) unless it's pre-empted by a higher priority thread. Windows boosts foreground apps by giving their threads a longer quantum than background apps. To take advantage of cache locality, Windows remembers which logical processor (logical HT core, physical core, physical processor) a thread last ran on, and a preferred logical processor for that thread. Each new thread in a process gets a different preferred processor from the previous one, rotating across the logical processors. If possible, it runs the thread on the last processor, or if that is not available, on the preferred processor. If neither are available it tries a nearby processor - another logical HT processor on the same core, another core in the same package, then other cores in the same memory domain (for Non-Uniform Memory Access [NUMA] systems), then finally any available core. The full details are in 'Windows Internals, 4th Edition' by Mark Russinovich and David Solomon. I'm hoping that Mark's SysInternals' acquisition by Microsoft doesn't get in the way of him updating this book!
Stability. What an interesting concept. -- Chris Maunder
-
The OS allocates threads to logical processors, if they're runnable (not blocked or suspended), in order of priority. A thread will run for up to its quantum on any CPU on which it's allowed to run (you can set affinity to restrict a thread to specific logical processors) unless it's pre-empted by a higher priority thread. Windows boosts foreground apps by giving their threads a longer quantum than background apps. To take advantage of cache locality, Windows remembers which logical processor (logical HT core, physical core, physical processor) a thread last ran on, and a preferred logical processor for that thread. Each new thread in a process gets a different preferred processor from the previous one, rotating across the logical processors. If possible, it runs the thread on the last processor, or if that is not available, on the preferred processor. If neither are available it tries a nearby processor - another logical HT processor on the same core, another core in the same package, then other cores in the same memory domain (for Non-Uniform Memory Access [NUMA] systems), then finally any available core. The full details are in 'Windows Internals, 4th Edition' by Mark Russinovich and David Solomon. I'm hoping that Mark's SysInternals' acquisition by Microsoft doesn't get in the way of him updating this book!
Stability. What an interesting concept. -- Chris Maunder
Mike Dimmick wrote:
I'm hoping that Mark's SysInternals' acquisition by Microsoft doesn't get in the way of him updating this book
It is a great book, just over halfway through it.
Darka [Xanya] "When you're taught to love everyone, to love your enemies, then what value does that place on love?"
-
John Simmons / outlaw programmer wrote:
It's fun to play with new hardware
<voice_of_envy> And to brag about it :-D. </voice_of_envy>
Software Zen:
delete this;
Don't get too envious yet. Apparently there are "issues" with multiple cores under Windows with several apps (mostly games, but I don't own any of the ones I've seen mentioned), and this is such a problem that AMD has issued a new driver, and MS has issued a patch to address it. I'm running Win2K on the system in question, and I haven't noticed any problems (yet), but if I do, I haven't found anything about whether or not the driver/patch combo will work on Win2K. I'm not sure what I need to do about it yet, either. -- modified at 8:31 Friday 4th August, 2006
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Don't get too envious yet. Apparently there are "issues" with multiple cores under Windows with several apps (mostly games, but I don't own any of the ones I've seen mentioned), and this is such a problem that AMD has issued a new driver, and MS has issued a patch to address it. I'm running Win2K on the system in question, and I haven't noticed any problems (yet), but if I do, I haven't found anything about whether or not the driver/patch combo will work on Win2K. I'm not sure what I need to do about it yet, either. -- modified at 8:31 Friday 4th August, 2006
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001John Simmons / outlaw programmer wrote:
Apparently there are "issues" with multiple cores under Windows with several apps
oh yes there are, it took ages to get Command & Conquer Generals working, but it did in the end. Not come across anything that didn't work straight away though, been multi-core for a couple of months now, wouldn't move back (2 Gb ram helps too!).
Darka [Xanya] "When you're taught to love everyone, to love your enemies, then what value does that place on love?"
-
When you have a dual core CPU, does a multi-threaded app "just know" that it can use the 2nd core, or can/must you set cpu affinity on a thread-by-thread basis in order to take advantage of the 2nd core? Now that I have a dual-core CPU, I was thinking about writing an app to compare the speed of using just one core versus using both cores to run a calculation-intensive thread. (It's fun to play with ne hardware.) -- modified at 8:33 Friday 4th August, 2006 (for spelling errors)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001As Darka and Mike have said, you don't have to do anything; Windows will do it for you. You can, however, limit which processors your threads will run on using the CPU affinity is you wish. If you have two threads sharing the same data that can be cached, then it makes sense to run them on the same processor, or different HT cores of the same CPU, so that they can use the same cache.
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
The OS allocates threads to logical processors, if they're runnable (not blocked or suspended), in order of priority. A thread will run for up to its quantum on any CPU on which it's allowed to run (you can set affinity to restrict a thread to specific logical processors) unless it's pre-empted by a higher priority thread. Windows boosts foreground apps by giving their threads a longer quantum than background apps. To take advantage of cache locality, Windows remembers which logical processor (logical HT core, physical core, physical processor) a thread last ran on, and a preferred logical processor for that thread. Each new thread in a process gets a different preferred processor from the previous one, rotating across the logical processors. If possible, it runs the thread on the last processor, or if that is not available, on the preferred processor. If neither are available it tries a nearby processor - another logical HT processor on the same core, another core in the same package, then other cores in the same memory domain (for Non-Uniform Memory Access [NUMA] systems), then finally any available core. The full details are in 'Windows Internals, 4th Edition' by Mark Russinovich and David Solomon. I'm hoping that Mark's SysInternals' acquisition by Microsoft doesn't get in the way of him updating this book!
Stability. What an interesting concept. -- Chris Maunder
A colleague told me the other day that he had tried to run one of our applications on a specified core (after your explanation I reckon that he set the affinity to a specified core) and that it actually slowed the application down. Is this because the thread restricted to a specific logical processor might be blocked by other threads, whilst if it wasn't restricted then it would be free to take up time on another logical processor? Graham My signature is not black, just a very, very dark blue
-
Don't get too envious yet. Apparently there are "issues" with multiple cores under Windows with several apps (mostly games, but I don't own any of the ones I've seen mentioned), and this is such a problem that AMD has issued a new driver, and MS has issued a patch to address it. I'm running Win2K on the system in question, and I haven't noticed any problems (yet), but if I do, I haven't found anything about whether or not the driver/patch combo will work on Win2K. I'm not sure what I need to do about it yet, either. -- modified at 8:31 Friday 4th August, 2006
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Based on comments from the device driver guy in my group, I wouldn't be surprised to see a lot of driver updates. Apparently it's pretty easy for a driver to assume a single processor environment and fail to take into account multiprocessor issues. This causes everything from performance problems to random BSOD's.
John Simmons / outlaw programmer wrote:
I'm running Win2K on the system in question
I didn't think Win2K supported multiple processors out of the box. Or are you running a server version?
Software Zen:
delete this;
-
The OS allocates threads to logical processors, if they're runnable (not blocked or suspended), in order of priority. A thread will run for up to its quantum on any CPU on which it's allowed to run (you can set affinity to restrict a thread to specific logical processors) unless it's pre-empted by a higher priority thread. Windows boosts foreground apps by giving their threads a longer quantum than background apps. To take advantage of cache locality, Windows remembers which logical processor (logical HT core, physical core, physical processor) a thread last ran on, and a preferred logical processor for that thread. Each new thread in a process gets a different preferred processor from the previous one, rotating across the logical processors. If possible, it runs the thread on the last processor, or if that is not available, on the preferred processor. If neither are available it tries a nearby processor - another logical HT processor on the same core, another core in the same package, then other cores in the same memory domain (for Non-Uniform Memory Access [NUMA] systems), then finally any available core. The full details are in 'Windows Internals, 4th Edition' by Mark Russinovich and David Solomon. I'm hoping that Mark's SysInternals' acquisition by Microsoft doesn't get in the way of him updating this book!
Stability. What an interesting concept. -- Chris Maunder
Mark is the man alright. I've got a lot of respect for him since the first time I used DebugView. Man, it was a real god send. And we use it really heavily now. I just hope he gets a Vista version going soon.
Truth is the subjection of reality to an individuals perception
-
When you have a dual core CPU, does a multi-threaded app "just know" that it can use the 2nd core, or can/must you set cpu affinity on a thread-by-thread basis in order to take advantage of the 2nd core? Now that I have a dual-core CPU, I was thinking about writing an app to compare the speed of using just one core versus using both cores to run a calculation-intensive thread. (It's fun to play with ne hardware.) -- modified at 8:33 Friday 4th August, 2006 (for spelling errors)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001John Simmons / outlaw programmer wrote:
Now that I have a dual-core CPU, I was thinking about writing an app to compare the speed of using just one core versus using both cores to run a calculation-intensive thread. (It's fun to play with ne hardware.)
If your calculation is not mutlithreaded the result is the dual core will probably be slower considering that it is probably clocked slower than the processor it replaces.
John
-
Don't get too envious yet. Apparently there are "issues" with multiple cores under Windows with several apps (mostly games, but I don't own any of the ones I've seen mentioned), and this is such a problem that AMD has issued a new driver, and MS has issued a patch to address it. I'm running Win2K on the system in question, and I haven't noticed any problems (yet), but if I do, I haven't found anything about whether or not the driver/patch combo will work on Win2K. I'm not sure what I need to do about it yet, either. -- modified at 8:31 Friday 4th August, 2006
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Don't get too envious yet. Apparently there are "issues" with multiple cores under Windows with several apps (mostly games, but I don't own any of the ones I've seen mentioned), and this is such a problem that AMD has issued a new driver, and MS has issued a patch to address it. I'm running Win2K on the system in question, and I haven't noticed any problems (yet), but if I do, I haven't found anything about whether or not the driver/patch combo will work on Win2K. I'm not sure what I need to do about it yet, either. -- modified at 8:31 Friday 4th August, 2006
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001> Apparently there are "issues" with multiple cores under Windows with several apps (mostly games The only problem I've seen with a game when I swapped my Athlon64 3200 with a 4800 was GTA San Andreas. The timing was *way* off, eg, the in-game clock and traffic moved as fast as the machine could make it (which was interesting in its own right) :-D My quick solution was to reinstall the game on top of itself (fortunately the installer was smart enough to realize it didn't actually have to transfer any files back from the media on the hard drive), so that took less than 30 seconds. I haven't encountered any other problem whatsoever, and I simply dropped the new CPU in without reinstalling anything. At some later point I stumbled upon AMD's newer driver and installed it, but I can't even comment whether that made any difference or not...
-
Mark is the man alright. I've got a lot of respect for him since the first time I used DebugView. Man, it was a real god send. And we use it really heavily now. I just hope he gets a Vista version going soon.
Truth is the subjection of reality to an individuals perception
-
> Apparently there are "issues" with multiple cores under Windows with several apps (mostly games The only problem I've seen with a game when I swapped my Athlon64 3200 with a 4800 was GTA San Andreas. The timing was *way* off, eg, the in-game clock and traffic moved as fast as the machine could make it (which was interesting in its own right) :-D My quick solution was to reinstall the game on top of itself (fortunately the installer was smart enough to realize it didn't actually have to transfer any files back from the media on the hard drive), so that took less than 30 seconds. I haven't encountered any other problem whatsoever, and I simply dropped the new CPU in without reinstalling anything. At some later point I stumbled upon AMD's newer driver and installed it, but I can't even comment whether that made any difference or not...
-
Based on comments from the device driver guy in my group, I wouldn't be surprised to see a lot of driver updates. Apparently it's pretty easy for a driver to assume a single processor environment and fail to take into account multiprocessor issues. This causes everything from performance problems to random BSOD's.
John Simmons / outlaw programmer wrote:
I'm running Win2K on the system in question
I didn't think Win2K supported multiple processors out of the box. Or are you running a server version?
Software Zen:
delete this;
Gary R. Wheeler wrote:
I didn't think Win2K supported multiple processors out of the box. Or are you running a server version?
I'm using Win2k Pro. If you go into device manager, expand the tree item "Computer", double-click the sub item, and click the 2nd tab, you'll see two items listed - Single CPU, and Mulitple CPU. All I had to do was click the multiple CPU option, and reboot.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Never had any problems with dual P3 config I had, but that was years ago. In any case, you can manually force affinity to one of the cores through task manager, shouldn't that fix the problem?
Yeah, but that's a pain. :)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001