http://bugs.winehq.org/show_bug.cgi?id=19982
Summary: SetThreadAffinityMask() seems not to work correctly Product: Wine Version: 1.1.29 Platform: PC URL: http://rh-software.com/ OS/Version: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: kernel32 AssignedTo: wine-bugs@winehq.org ReportedBy: ray@pobox.co.uk
Created an attachment (id=23510) --> (http://bugs.winehq.org/attachment.cgi?id=23510) SIV log shouing pseuso random APICs
When my SIV application (http://rh-software.com/) on under Wine the reported processor topography is often incorrect. This is caused by the APIC returned by the CPUID 1 instruction not being the APIC for the CPU I have set affinity to. This makes me believe that SetThreadAffinityMask() is not working correctly. This can easily be shown using me SIV utility with the command line: SIV -SAVE=[processors]=stdout -nodriver | find "CPU-" which when run under Wine typically reports: MPS MCP HTT APIC G N Affinity Speed Processors CPU-0 0 3 0 (core) 0003 0 0 0x00000001 3.00GHz CPU-1 0 3 0 ... 0003 0 1 0x00000002 3.00GHz CPU-2 0 3 0 ... 0003 0 2 0x00000004 3.00GHz CPU-3 0 3 0 ... 0003 0 3 0x00000008 3.00GHz if SetThreadAffinityMask() was woring as expected each CPU would have a different APIC giving a report similar to Processors CPU-0 0 0 0 0000 0 0 0x00000001 3.20GHz CPU-1 0 1 0 (core) 0002 0 1 0x00000002 3.20GHz CPU-2 0 0 1 (logical) 0001 0 2 0x00000004 3.20GHz CPU-3 0 1 1 ... 0003 0 3 0x00000008 3.20GHz this has been seen on at least 2 different systems. Further the APIC returned for a given CPU seems to vary from run-to-run as shown in the siv_apic.txt attachment.
Looking through the bug reports this could also be what is fundamental cause of issue http://bugs.winehq.org/show_bug.cgi?id=11674. If WOW is using SetThreadAffinityMask() it could happen that all the threads end up running on the same CPU because of SetThreadAffinityMask() not working as it should.
The -NODRIVER qualifier is needed with SIV 4.00 and earlier and will not be needed from SIV 4.01 onwards.
http://bugs.winehq.org/show_bug.cgi?id=19982
Boris bstriker@ya.ru changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |bstriker@ya.ru
--- Comment #1 from Boris bstriker@ya.ru 2009-09-08 14:47:20 --- I tried this on my system, so I confirm: $ wine siv -save=[processors]=stdout -nodriver 2> /dev/null | egrep "(CPU-|APIC G)" MPS MCP HTT APIC G N Affinity Speed Processors CPU-0 0 1 0 (core) 0001 0 0 0x00000001 3.17GHz CPU-1 0 1 0 ... 0001 0 1 0x00000002 3.17GHz
http://bugs.winehq.org/show_bug.cgi?id=19982
Vitaliy Margolen vitaliy@kievinfo.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |DUPLICATE
--- Comment #2 from Vitaliy Margolen vitaliy@kievinfo.com 2009-09-08 20:46:12 --- Duplicate
*** This bug has been marked as a duplicate of bug 7768 ***
http://bugs.winehq.org/show_bug.cgi?id=19982
Vitaliy Margolen vitaliy@kievinfo.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #3 from Vitaliy Margolen vitaliy@kievinfo.com 2009-09-08 20:46:55 --- Closing duplicate.
http://bugs.winehq.org/show_bug.cgi?id=19982
Juan Lang juan_lang@yahoo.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|CLOSED |UNCONFIRMED Resolution|DUPLICATE |
--- Comment #4 from Juan Lang juan_lang@yahoo.com 2009-09-08 21:46:03 --- Actually, this isn't a dup. Bug 7768 is about process affinity, and this is about thread affinity. They're related, but separate. This one's probably easier to fix than 7768, because in Linux, the affinity API applies to a thread, so implementing this on top of the Linux API should be relatively straightforward.
http://bugs.winehq.org/show_bug.cgi?id=19982
Juan Lang juan_lang@yahoo.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever Confirmed|0 |1
--- Comment #5 from Juan Lang juan_lang@yahoo.com 2009-09-08 21:47:20 --- Reconfirming per comment 1. (Reopening it didn't give me the option to mark it confirmed.)
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #6 from Juan Lang juan_lang@yahoo.com 2009-09-09 12:39:00 --- Created an attachment (id=23529) --> (http://bugs.winehq.org/attachment.cgi?id=23529) Patch: Use kernel support for thread affinity when available
It turns out I'd already written a patch for thread affinity, but it was rejected along with the process one, probably because the process one needed work. It also doesn't compile on MacOS, but as far as I know there isn't a similar system call there anyway. Does it address the issue for you?
http://bugs.winehq.org/show_bug.cgi?id=19982
Juan Lang juan_lang@yahoo.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |juan_lang@yahoo.com
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #7 from Juan Lang juan_lang@yahoo.com 2009-09-09 12:52:50 --- (In reply to comment #6)
It also doesn't compile on MacOS, but as far as I know there isn't a similar system call there anyway.
Correcting myself: there is a MacOS API for setting thread affinity[1]. Its programming model is rather different than in Windows/Linux, so mapping between the two would be a challenge. Still, I'm curious whether the attached patch works for you (under Linux.)
[1] http://developer.apple.com/mac/library/releasenotes/Performance/RN-AffinityA...
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #8 from red-ray ray@pobox.co.uk 2009-09-10 05:55:46 --- Thank you for this. I confirm that with this patch SIV reportts the correct processor topography. The output from SIV is now:
$ wine siv -save=[processors]=stdout -nodriver 2> /dev/null | egrep "(CPU-|APIC G)" MPS MCP HTT APIC G N Affinity Speed Processors CPU-0 0 0 0 0000 0 0 0x00000001 3.17GHz CPU-1 0 1 0 (core) 0001 0 1 0x00000002 3.17GHz
I hope the patch is accepted this time around. Is there any change it will make 1.1.30 ?
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #9 from Juan Lang juan_lang@yahoo.com 2009-09-10 10:08:40 --- (In reply to comment #8)
I hope the patch is accepted this time around. Is there any change it will make 1.1.30 ?
There's a chance. It depends on my being able to figure out the correct configure magic to make this code be excluded on MacOSX, which has sched.h, but not cpu_set_t nor sched_getaffinity/sched_setaffinity.
http://bugs.winehq.org/show_bug.cgi?id=19982
Juan Lang juan_lang@yahoo.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #10 from Juan Lang juan_lang@yahoo.com 2009-09-11 11:14:42 --- Well, my patch didn't make the latest round of commits. Alexandre tends to be sensitive about changes to the server, so it's not surprising. I don't know the reason why. I'll ask for feedback if it doesn't go in in a day or two.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #11 from Alexandre Julliard julliard@winehq.org 2009-09-11 12:52:51 --- I don't think you can treat thread affinity independently from process affinity. Some test cases would be in order. Also your patch is again fetching the affinity on every thread startup.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #12 from red-ray ray@pobox.co.uk 2009-09-11 14:23:48 --- (In reply to comment #11)
I don't think you can treat thread affinity independently from process affinity. Some test cases would be in order. Also your patch is again fetching the affinity on every thread startup.
Looking at http://msdn.microsoft.com/en-us/library/ms686247(VS.85).aspx the only requirement from the Windows specification is the thread affinity must be a subset of the process affinity.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #13 from Juan Lang juan_lang@yahoo.com 2009-09-11 14:37:24 --- (In reply to comment #12)
Looking at http://msdn.microsoft.com/en-us/library/ms686247(VS.85).aspx the only requirement from the Windows specification is the thread affinity must be a subset of the process affinity.
My patch doesn't do that. Like Alexandre suggested, this needs tests, and since I'm currently without a Windows box, that's a bit of a challenge for me.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #14 from red-ray ray@pobox.co.uk 2009-09-15 08:08:59 --- (In reply to comment #8)
Thank you for this. I confirm that with this patch SIV reportts the correct processor topography. The output from SIV is now: $ wine siv -save=[processors]=stdout -nodriver 2> /dev/null | egrep "(CPU-|APIC G)" MPS MCP HTT APIC G N Affinity Speed Processors CPU-0 0 0 0 0000 0 0 0x00000001 3.17GHz CPU-1 0 1 0 (core) 0001 0 1 0x00000002 3.17GHz I hope the patch is accepted this time around. Is there any change it will make 1.1.30 ?
I have done more testing using the SIV 4.01 [Test APIC] page. The patch improves things but when lots of SetProcessAffinityMask() calls are made the the threads end up on the incorrect CPU. It's possible I did not apply the patch correctly, but I also applied http://bugs.winehq.org/show_bug.cgi?id=19964 which did work, so I am fairly sure it went in correctly.
To run the test download http://rh-software.com/downloads/siz.zip, run SIV.exe, select the [Test APIC] page (Right/Click tray Icon or System Menu->Machine->Test APIC) and then press [Start]. If that does not fail then press [Swap CPU] and it soon will.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #15 from red-ray ray@pobox.co.uk 2009-09-15 09:02:58 --- Oops, should be http://rh-software.com/downloads/siv.zip,
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #16 from Juan Lang juan_lang@yahoo.com 2009-09-28 11:50:34 --- I sent an updated patch series to fix this, starting with this one: http://www.winehq.org/pipermail/wine-patches/2009-September/079014.html
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #17 from ray@pobox.co.uk 2009-09-30 04:43:08 --- Created an attachment (id=23846) --> (http://bugs.winehq.org/attachment.cgi?id=23846) Test Program Binary
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #18 from ray@pobox.co.uk 2009-09-30 04:43:35 --- Created an attachment (id=23847) --> (http://bugs.winehq.org/attachment.cgi?id=23847) Test Program Source
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #19 from ray@pobox.co.uk 2009-09-30 04:57:08 --- (In reply to comment #16)
I sent an updated patch series to fix this, starting with this one: http://www.winehq.org/pipermail/wine-patches/2009-September/079014.html
I have applied these pataches and my ART test program shows a logic error. If the Process Affinity is 0x01 setting a Thread afffinity of 0x02 does not fail and it should do. $ wine art ART - CPU-1 +++ SetThreadAffinityMask( 0x00000002 ) Test Fail - Enabled Mask 0x00000001
Further when I tested with SIV the returned APICs on SIV startup vary from run-to-run and the [Test APIC] page detects incorrect APICs being returned meaning that the threads are still not running on the appropiate processor.
I did these tests on an ubunto linux 2.6.28-15 host system with a two core CPU.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #20 from ray@pobox.co.uk 2009-09-30 05:12:37 --- Created an attachment (id=23848) --> (http://bugs.winehq.org/attachment.cgi?id=23848) Screen Caprure showing the [Test APIC] test failing
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #21 from Juan Lang juan_lang@yahoo.com 2009-09-30 11:11:36 --- (In reply to comment #19)
I have applied these pataches and my ART test program shows a logic error. If the Process Affinity is 0x01 setting a Thread afffinity of 0x02 does not fail and it should do.
Thanks, you're right, I missed that in my tests and implementation.
Further when I tested with SIV the returned APICs on SIV startup vary from run-to-run and the [Test APIC] page detects incorrect APICs being returned meaning that the threads are still not running on the appropiate processor.
Alexandre committed a variant of my patches today. Would you mind retrying with today's git?
If it still doesn't work for you, please check whether HAVE_SCHED_SETAFFINITY is defined in include/config.h. If it isn't defined, configure isn't finding the function on your system. If it is, then the Linux call isn't doing what it's supposed to (and it's a Linux bug rather than a Wine one.)
http://bugs.winehq.org/show_bug.cgi?id=19982
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |download, testcase
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #22 from Juan Lang juan_lang@yahoo.com 2009-09-30 15:00:22 --- (In reply to comment #19)
I have applied these pataches and my ART test program shows a logic error. If the Process Affinity is 0x01 setting a Thread afffinity of 0x02 does not fail and it should do.
I sent a patch for this issue: http://www.winehq.org/pipermail/wine-patches/2009-September/079205.html
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #23 from ray@pobox.co.uk 2009-09-30 15:15:01 --- (In reply to comment #21)
Would you mind retrying with today's git?
I do not know how to actually do this. Is there a patch file ?
When you ran SIV [Test APIC] on your wine system did it pass and how many CPUs does your system have ?
I have just deleted and regenerated include/config.h and when I searched for HAVE_SCHED_SETAFFINITY could not find it at all. there is "#define HAVE_SCHED_H 1". I searched /usr/include/sched.h and found definitions for sched_setaffinity() and sched_getaffinity(). I would expect that if Wine is not able to support SetThreadAffinityMask() I would get an error 50 (ERROR_NOT_SUPPORTED) return which does not seem to be the case.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #24 from ray@pobox.co.uk 2009-09-30 15:26:22 --- (In reply to comment #22)
(In reply to comment #19)
I have applied these pataches and my ART test program shows a logic error. If the Process Affinity is 0x01 setting a Thread afffinity of 0x02 does not fail and it should do.
I sent a patch for this issue: http://www.winehq.org/pipermail/wine-patches/2009-September/079205.html
I have just looked at this patch and reading the code it looks incorrect to me.
void set_thread_affinity( struct thread *thread, affinity_t affinity ) { + if (!(affinity & thread->process->affinity)) + { + set_error( STATUS_INVALID_PARAMETER ); + return; + }
If the process affinity is 0x05 and I try and set a thread affinity of 0x03 this should fail and this will not be the case with the above code.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #25 from Juan Lang juan_lang@yahoo.com 2009-09-30 15:31:18 --- (In reply to comment #24)
If the process affinity is 0x05 and I try and set a thread affinity of 0x03 this should fail and this will not be the case with the above code.
Oh right, okay. Harder for me to test as I only have a 2-core system, but I'll think about it and have another go.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #26 from Juan Lang juan_lang@yahoo.com 2009-09-30 15:34:09 --- (In reply to comment #23)
(In reply to comment #21)
Would you mind retrying with today's git?
I do not know how to actually do this. Is there a patch file ?
Use: git clone git://source.winehq.org/git/wine.git
The most recent source tree will then be in the wine subdirectory of your current directory. See http://wiki.winehq.org/GitWine if you want to learn more about using git with wine.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #27 from Boris bstriker@ya.ru 2009-09-30 15:38:43 --- Created an attachment (id=23856) --> (http://bugs.winehq.org/attachment.cgi?id=23856) Screenshot of Test APIC window on WinXP (Test case 1)
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #28 from Boris bstriker@ya.ru 2009-09-30 15:39:16 --- Created an attachment (id=23857) --> (http://bugs.winehq.org/attachment.cgi?id=23857) Screenshot of Test APIC window on Wine 1.1.30 + 5 patches (Test case 2)
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #29 from Boris bstriker@ya.ru 2009-09-30 15:40:04 --- Created an attachment (id=23858) --> (http://bugs.winehq.org/attachment.cgi?id=23858) Screenshot of Test APIC window on Wine 1.1.30 + patch of comment 19 (Test case 3)
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #30 from Boris bstriker@ya.ru 2009-09-30 15:40:20 --- I performed some tests on a workstation with WinXP at work and on my home computer. Here are the results.
Test cases: 1) WinXP. For reference. 2) Wine 1.1.30 with five patches applied (see comment #16). 3) Wine 1.1.30 from git (downloaded about 1.5 hours ago) + patch from comment #19.
$ grep HAVE_SCHED_SETAFFINITY include/config.h #define HAVE_SCHED_SETAFFINITY 1 This command was executed just after Wine (test case #3) installed with ./tools/wineinstall
Screenshots of 'Test APIC' window of SIV in 3 test cases attached: 1) Reference. 2) Failed. 3) Failed.
'Processors' output of SIV: 1) Reference: Processors CPU-0 0 0 0 0000 0 0 0x00000001 2.67GHz
CPU-1 0 1 0 (core) 0002 0 1 0x00000002 2.67GHz
CPU-2 0 2 0 ... 0004 0 2 0x00000004 2.67GHz
CPU-3 0 3 0 ... 0006 0 3 0x00000008 2.67GHz
CPU-4 0 0 1 (logical) 0001 0 4 0x00000010 2.67GHz
CPU-5 0 1 1 ... 0003 0 5 0x00000020 2.67GHz
CPU-6 0 2 1 ... 0005 0 6 0x00000040 2.67GHz
CPU-7 0 3 1 ... 0007 0 7 0x00000080 2.67GHz 2) Failed: $ wine siv -save=[processors]=stdout -nodriver 2> /dev/null | egrep "(CPU-|APIC G)" MPS MCP HTT APIC G N Affinity Speed Processors CPU-0 0 1 0 (core) 0001 0 0 0x00000001 3.17GHz CPU-1 0 1 0 ... 0001 0 1 0x00000002 3.17GHz 3) Good: $ wine siv -save=[processors]=stdout -nodriver 2> /dev/null | egrep "(CPU-|APIC G)" MPS MCP HTT APIC G N Affinity Speed Processors CPU-0 0 0 0 0000 0 0 0x00000001 3.17GHz CPU-1 0 1 0 (core) 0001 0 1 0x00000002 3.17GHz
ART test: 1) Good. 2) N/A (forget to do it). 3) Good: $ wine art ART - All Tests Passed !
Hope this helps.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #31 from Boris bstriker@ya.ru 2009-09-30 15:44:39 --- My bad, sorry. Test case 3 was with patch from comment #22
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #32 from ray@pobox.co.uk 2009-09-30 15:53:18 --- (In reply to comment #22) I have also just spotted another very obscure bug:
proc_affinity = (1 << si.dwNumberOfProcessors) - 1;
This will typically generate:
00474CBD push 1 00474CBF pop eax 00474CC0 mov ecx,esi 00474CC2 shl eax,cl 00474CC4 dec eax
which for the case of 32 CPUs the after the shl eax,cl EAX will still contain 1 !
If you look in http://www.intel.com/Assets/PDF/manual/253667.pdf you will find:
IA-32 Architecture Compatibility The 8086 does not mask the shift count. However, all other IA-32 processors (starting with the Intel 286 processor) do mask the shift count to 5 bits, resulting in a maximum count of 31. This masking is done in all operating modes (including the virtual-8086 mode) to reduce the maximum execution time of the instructions.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #33 from ray@pobox.co.uk 2009-09-30 15:57:28 --- (In reply to comment #25)
(In reply to comment #24)
If the process affinity is 0x05 and I try and set a thread affinity of 0x03 this should fail and this will not be the case with the above code.
Oh right, okay. Harder for me to test as I only have a 2-core system, but I'll think about it and have another go.
Try Process Affinity 0x01 and set Thread Affinity 0x03 if you only have 2 cores.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #34 from Juan Lang juan_lang@yahoo.com 2009-09-30 16:05:51 --- (In reply to comment #24)
If the process affinity is 0x05 and I try and set a thread affinity of 0x03 this should fail and this will not be the case with the above code.
I sent an improved patch that fixes this: http://www.winehq.org/pipermail/wine-patches/2009-September/079213.html
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #35 from Juan Lang juan_lang@yahoo.com 2009-09-30 16:27:19 --- (In reply to comment #30)
Screenshots of 'Test APIC' window of SIV in 3 test cases attached:
- Reference.
- Failed.
- Failed.
Please explain how they failed. I looked at the screenshots, and I have no idea what they mean. Remember: assume I've never used this program before. (In fact, I haven't.) Explain what I should see, and what I see instead, and how to verify it myself.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #36 from Boris bstriker@ya.ru 2009-09-30 16:51:09 ---
Please explain how they failed
At least, green&red bars in test cases 2 and 3 should have spaces just as green bars. My english is bad, so I attached an image
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #37 from Boris bstriker@ya.ru 2009-09-30 16:51:32 --- Created an attachment (id=23860) --> (http://bugs.winehq.org/attachment.cgi?id=23860) Why tests 2 and 3 failed
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #38 from Boris bstriker@ya.ru 2009-09-30 17:00:27 --- Steps to reproduce: 1) Download SIV: http://rh-software.com/downloads/siv_beta.zip 2) Extract it at any location 3) Run it with 'wine siv' 4) Right click on tray icon \ Machine \ CPU Usage 5) Press 'Test APIC' button at right of buttons row 6) Press 'Start' button 7) Now play with checkboxes at bottom of the window. Each pair of checkboxes should affect corresponding CPU graph only
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #39 from Juan Lang juan_lang@yahoo.com 2009-09-30 17:04:27 --- Okay, that helps, thanks. Ray, how is that time calculated? Are the incorrect values related to bug 19960?
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #40 from Boris bstriker@ya.ru 2009-09-30 17:11:28 ---
I sent an improved patch that fixes this: http://www.winehq.org/pipermail/wine-patches/2009-September/079213.html
I tried it. No changes since 'test case 3'. But I don't know if there are should be any.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #41 from ray@pobox.co.uk 2009-09-30 17:14:20 --- (In reply to comment #38)
Steps to reproduce:
- Download SIV: http://rh-software.com/downloads/siv_beta.zip
- Extract it at any location
- Run it with 'wine siv'
- Right click on tray icon \ Machine \ CPU Usage
- Press 'Test APIC' button at right of buttons row
- Press 'Start' button
- Now play with checkboxes at bottom of the window. Each pair of checkboxes
should affect corresponding CPU graph only
The http://rh-software.com/downloads/siv_beta.zip should not have been posted on this public board. Can it be removed ?
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #42 from ray@pobox.co.uk 2009-09-30 17:17:07 --- (In reply to comment #39)
Okay, that helps, thanks. Ray, how is that time calculated? Are the incorrect values related to bug 19960?
This problem is nothing to do with CPU times. SIV 4.01 and later work around that bug anyway. The problem is that the threads are not being run on the CPU they set affinity to:
What the [Test APIC] page is doing is checking that the APIC of the CPU it had set affinity to is as expected. The actual code is a loop that does:
if( cib->dkc ) // CPU Switching Mode ? { if( ( cpo += 1 ) == smb->cpu + smb->log_cpus ) { cpo = smb->cpu; // cycle round all CPUs }
cpu_ssa_set( cth, cpo->ssa ); // switch to another cpu_ssa_set( cth, cpu->ssa ); // and back to my CPU } else // no, so wait a while { ULONG volatile dly;
for( dly = 0; dly < 3000; dly++ ) {} // so rate is similar }
if( cpu->apic == cpu_get_apic( smb ) ) // APIC correct ? { InterlockedIncrement( &cib->gar ); // Good APIC Rate } else { InterlockedIncrement( &cib->bac ); // Bad APIC Count }
cpu_ssa_set() is a wrapper for SetThreadAffinityMask() cpu_get_apic() reads the APIC of the curent CPU
As soon as the returned APIC is not as expected then FAIL is reported.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #43 from ray@pobox.co.uk 2009-09-30 17:31:07 --- (In reply to comment #40)
I sent an improved patch that fixes this: http://www.winehq.org/pipermail/wine-patches/2009-September/079213.html
I tried it. No changes since 'test case 3'. But I don't know if there are should be any.
The patch is to detect programs trying to set in invalid thread affinity mask. It should have no effect of the operation of SIV as SIV does not do this.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #44 from Juan Lang juan_lang@yahoo.com 2009-09-30 17:40:51 --- That sounds like either the Linux kernel isn't scheduling on the thread you're asking it to, or that the APIC-based CPU identification isn't doing what you want.
I compiled and ran the test program here: http://lkml.org/lkml/2007/5/10/578 and it reported 0, which indicates that after calling sched_setaffinity, sched_getcpu reports the same CPU as sched_setaffinity requested. Thus, either sched_getcpu lying, or sched_setaffinity is doing what I want. If it's lying, it's a Linux kernel bug. Otherwise, the CPU identification is flawed under Wine, and likely a Wine bug.
In either case, _this_ bug will be fixed once my latest patch is committed, except on >= 32 CPU systems.. but I'm willing to leave that one alone until someone actually needs support for those.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #45 from ray@pobox.co.uk 2009-09-30 17:57:04 --- (In reply to comment #44)
That sounds like either the Linux kernel isn't scheduling on the thread you're asking it to, or that the APIC-based CPU identification isn't doing what you want.
The SIV APIC-based CPU identification works on real Windows systems as shown by http://bugs.winehq.org/attachment.cgi?id=23856 but not on Wine. What do I need to do to prove beyond any reasonable doubt that this is a Wine/*nix issue ? Have you run SIV on your system ? Does the failure get shown on your system please ?
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #46 from Juan Lang juan_lang@yahoo.com 2009-09-30 18:04:27 --- (In reply to comment #45)
The SIV APIC-based CPU identification works on real Windows systems as shown by http://bugs.winehq.org/attachment.cgi?id=23856 but not on Wine. What do I need to do to prove beyond any reasonable doubt that this is a Wine/*nix issue ?
You already have. My point is, this is either a Linux kernel bug--we're making the correct call to schedule the thread on a different CPU, and the kernel isn't honoring that request--or the APIC identification is failing under Wine. If the former is true, you'd need to take this up with the Linux folks. If the latter is true, it's a different bug.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #47 from ray@pobox.co.uk 2009-09-30 18:25:53 --- (In reply to comment #46)
the APIC identification is failing under Wine.
I am unclear as to what you mean by this. The APIC is returned in bits 31...24 of EBX after issuing a CPUID 1 instruction. Wine/*nix can not affect the operation of the CPUID instruction, it's just like any other unprivileged x86 instruction.
Have you run SIV on your system ? Does the failure get shown on your system please ? I would like to get an idea if this is just a ubuntu Linux issue. To actually know it works at all with Wine would be a valuable input.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #48 from Juan Lang juan_lang@yahoo.com 2009-09-30 18:32:39 --- (In reply to comment #47)
the APIC identification is failing under Wine.
I am unclear as to what you mean by this. The APIC is returned in bits 31...24 of EBX after issuing a CPUID 1 instruction. Wine/*nix can not affect the operation of the CPUID instruction, it's just like any other unprivileged x86 instruction.
Okay. I didn't remember that that's how you were doing it.
Have you run SIV on your system ? Does the failure get shown on your system please ? I would like to get an idea if this is just a ubuntu Linux issue. To actually know it works at all with Wine would be a valuable input.
Yes, and it fails in the same way here, if I understand the program well enough. (I confess to finding SIV pretty confusing.) Nevertheless, the sched_setaffinity calls succeed. (I instrumented my own wineserver to verify it.) So I'm leaning toward this being a kernel bug. Once we ask the kernel to schedule a thread on a different CPU, and the kernel says, "righto," there's nothing more we can do, is there?
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #49 from ray@pobox.co.uk 2009-09-30 19:40:33 --- (In reply to comment #48)
Yes, and it fails in the same way here, if I understand the program well enough. (I confess to finding SIV pretty confusing.) Nevertheless, the sched_setaffinity calls succeed. (I instrumented my own wineserver to verify it.) So I'm leaning toward this being a kernel bug.
I think having a simple program to test this would be a good move. Looking in the Windows API I would like to use GetCurrentProcessorNumber() which returns the zero based CPU number. It's new in Vista and not in Wine. Having this would be very helpful, what is the best way to get it added to Wine ? Is there a Linux API that will do this ?
Once we ask the kernel to schedule a thread on a different CPU, and the kernel says, "righto," there's nothing more we can do, is there?
If this is a Linux bug then can it we worked around ? I am wondering if doing a sched_yield() or similar after the affinity has been set would trigger a switch to the appropriate CPU.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #50 from Juan Lang juan_lang@yahoo.com 2009-09-30 19:50:27 --- Actually, I take it back. I wrote a test program that runs under Linux that calls sched_setaffinity and cpuid 1 directly, and it does what I expect: after calling sched_setaffinity, the process's CPU, as reported by cpuid 1, changes. I modifed kernel32 to call cpuid 1 also, and after changing the affinity mask, it does not change CPUs. So this remains a Wine bug, not a kernel bug.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #51 from Juan Lang juan_lang@yahoo.com 2009-09-30 20:00:10 --- Now I'm just confused. I added traces to wineserver, and it reports that sched_setaffinity succeeds, and that sched_getaffinity returns the same affinity mask that I set. So perhaps it is a problem with the thread not getting rescheduled.
One difference between the wine environment and my test program is that in wine, the server is a different process than the program who's requesting an affinity change. So maybe an affinity change, while valid, doesn't take effect immediately?
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #52 from Juan Lang juan_lang@yahoo.com 2009-09-30 20:03:58 --- (In reply to comment #49)
I think having a simple program to test this would be a good move. Looking in the Windows API I would like to use GetCurrentProcessorNumber() which returns the zero based CPU number. It's new in Vista and not in Wine. Having this would be very helpful, what is the best way to get it added to Wine ? Is there a Linux API that will do this ?
Implementing it, and sending a patch to wine-patches, is the best way to get it added. You could call sched_getcpu() if it's available.
If this is a Linux bug then can it we worked around ? I am wondering if doing a sched_yield() or similar after the affinity has been set would trigger a switch to the appropriate CPU.
Thanks for the suggestion. I tried that, but no such luck.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #53 from ray@pobox.co.uk 2009-10-01 13:56:02 --- Created an attachment (id=23869) --> (http://bugs.winehq.org/attachment.cgi?id=23869) Test Version of SIV and Test Result files
I have extended SIV to have a have a command line test option to check the APIC is as expected. To run this new test the command is: wine siv -save=[wine-apic]=stdout Within this .ZIP file apic-real.txt shows the output from a real windows system, apic-wine.txt showing the results from my wine system which was built from today's GIT and siv.exe is the test program
The general test loop is run 128K times and it uses SetThreadAffinityMask() to change to a different CPU, read the CPU APIC and check it is as expected. The 1st time uses a work thread and the actual thread handle, the 2nd test also uses a work thread but the Pseudo thread handle (0xFFFFFFFE) and the final test uses the main thread.
When a work thread is used the test currently fails, but passes when the main thread is used.
I hope this is of help and simple enough to use. I feel once this is passing then it would still be a good idea to run the SIV [Test APIC] test as this uses a work thread per CPU and may highlight issues not shown by the [wine-apic] test.
http://bugs.winehq.org/show_bug.cgi?id=19982
Juan Lang juan_lang@yahoo.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords|patch |
--- Comment #54 from Juan Lang juan_lang@yahoo.com 2009-10-03 11:50:45 --- I wonder whether wine should be using pthread_setaffinity_np() instead of sched_setaffinity(). Also, it's possible that I should be setting the affinity directly in ntdll, rather than in wineserver. I'll have another go when I have a chance.
http://bugs.winehq.org/show_bug.cgi?id=19982
Juan Lang juan_lang@yahoo.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #23529|0 |1 is obsolete| |
--- Comment #55 from Juan Lang juan_lang@yahoo.com 2009-10-03 11:51:24 --- (From update of attachment 23529) This was already committed, though it doesn't fix the bug yet.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #56 from ray@pobox.co.uk 2009-10-04 07:30:01 --- (In reply to comment #54)
I wonder whether wine should be using pthread_setaffinity_np() instead of sched_setaffinity().
Looking at http://www.kernel.org/doc/man-pages/online/pages/man2/sched_setaffinity.2.ht... it says:
If you are using the POSIX threads API, then use pthread_setaffinity_np(3) instead of sched_setaffinity().
Does Wine use the "POSIX threads API" ?
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #57 from ray@pobox.co.uk 2009-10-04 08:07:41 --- (In reply to comment #55)
(From update of attachment 23529 [details]) This was already committed, though it doesn't fix the bug yet.
I think currently it fixes SetThreadAffinityMask() for the Main Thread, but not for any additional threads that are created with Windows API call CreateThread().
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #58 from Juan Lang juan_lang@yahoo.com 2009-10-04 11:49:46 --- (In reply to comment #56)
Does Wine use the "POSIX threads API" ?
Yes.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #59 from Juan Lang juan_lang@yahoo.com 2009-10-08 17:12:00 --- I tried fixing this by using the pthread_setaffinity_np function instead, but didn't succeed. There were two issues:
1. It can only be done by the calling process, not by the wineserver, because a pthread_t only has meaning within the current process, not in a separate process. This means it can't work in all cases in which it works in Windows. 2. pthread_setaffinity_np crashed when I tried to use it.
I can attach the patches I wrote if anyone's interested, but I'm currently at a loss with this one, and don't think I'll be putting more time into it.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #60 from Juan Lang juan_lang@yahoo.com 2009-10-12 17:26:55 --- Created an attachment (id=24060) --> (http://bugs.winehq.org/attachment.cgi?id=24060) Patch 1/3: Revert 474b2e4bfb46cf1bb8db0faa6ecfdb3fd157b117
I'm attaching my last attempt at fixing this in case someone else feels like taking it up.
This first patch reverts using sched_setaffinity in wineserver.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #61 from Juan Lang juan_lang@yahoo.com 2009-10-12 17:27:31 --- Created an attachment (id=24061) --> (http://bugs.winehq.org/attachment.cgi?id=24061) Patch 2/3: Use pthread id as thread id on Linux
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #62 from Juan Lang juan_lang@yahoo.com 2009-10-12 17:30:45 --- Created an attachment (id=24062) --> (http://bugs.winehq.org/attachment.cgi?id=24062) Patch 3/3: Use pthread_setaffinity_np to set thread affinity when available
This third patch adds the tid to the reply to the set_thread_info server request. The tid was set to the pthread id in patch 2 of the series. Using it, a process should be able to set the affinity of a thread within the same process as it to the requested affinity. Unfortunately pthread_setaffinity_np crashed for me when I tried to use it, and I don't know the reason.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #63 from Boris bstriker@ya.ru 2009-10-14 13:20:06 --- Thank you for your work, Juan. Should I test your patches on my system? If 'yes', what should I do/run to perform the test, and what feedback do you need?
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #64 from Juan Lang juan_lang@yahoo.com 2009-10-14 13:29:57 --- (In reply to comment #63)
Should I test your patches on my system?
No, don't bother. They don't work for me. I posted them in case they're of use to someone else who wants to take this on. Thanks for the help testing my patches.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #65 from ray@pobox.co.uk 2009-11-23 11:55:05 --- (In reply to comment #64) Hi Juan, It looks like the patces for http://bugs.winehq.org/show_bug.cgi?id=20602 have also fixed this bug.
http://bugs.winehq.org/show_bug.cgi?id=19982
Louis Lenders xerox_xerox2000@yahoo.co.uk changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |xerox_xerox2000@yahoo.co.uk
--- Comment #66 from Louis Lenders xerox_xerox2000@yahoo.co.uk 2009-11-23 12:02:26 --- (In reply to comment #65)
(In reply to comment #64) Hi Juan, It looks like the patces for http://bugs.winehq.org/show_bug.cgi?id=20602 have also fixed this bug.
So can we clode this one , Ray?
http://bugs.winehq.org/show_bug.cgi?id=19982
Dmitry Timoshkov dmitry@codeweavers.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED
--- Comment #67 from Dmitry Timoshkov dmitry@codeweavers.com 2009-11-24 02:14:12 --- Reported fixed.
http://bugs.winehq.org/show_bug.cgi?id=19982
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #68 from Alexandre Julliard julliard@winehq.org 2009-12-04 12:16:19 --- Closing bugs fixed in 1.1.34.
http://bugs.winehq.org/show_bug.cgi?id=19982
ray@pobox.co.uk changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|CLOSED |REOPENED Resolution|FIXED |
--- Comment #69 from ray@pobox.co.uk 2010-07-04 16:28:14 --- This was working in 1.2-rc5 and regressed in 1.2-rc6.
This was logged as http://bugs.winehq.org/show_bug.cgi?id=23509
I can't confirm, so I have re-opened my original bug report.
In addition to inforrect APICs being reported the Menu->Machine->Teat APIC page is also not reporting failure, especially when [Swap CPU] mode is selected.
http://bugs.winehq.org/show_bug.cgi?id=19982
--- Comment #70 from ray@pobox.co.uk 2010-07-04 16:41:57 --- (In reply to comment #69) In addition to inforrect APICs being reported the Menu->Machine->Test APIC page is also now reporting failure, especially when [Swap CPU] mode is selected.
http://bugs.winehq.org/show_bug.cgi?id=19982
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |RESOLVED Resolution| |FIXED
--- Comment #71 from Alexandre Julliard julliard@winehq.org 2010-07-04 17:09:11 --- This was fixed, and there's no reason to believe that the patch no longer works. Please don't reopen. New problems should go into new bugs.
http://bugs.winehq.org/show_bug.cgi?id=19982
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #72 from Alexandre Julliard julliard@winehq.org 2010-07-04 17:09:28 --- Closing.