Closed
Bug 661596
Opened 13 years ago
Closed 13 years ago
Prevent NSPR from falling back to PR_Atomic functions on Mac when compiler intrinsics are available
Categories
(NSPR :: NSPR, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
4.8.9
People
(Reporter: justin.lebar+bug, Assigned: justin.lebar+bug)
References
Details
Attachments
(1 file, 2 obsolete files)
1.45 KB,
patch
|
wtc
:
review+
|
Details | Diff | Splinter Review |
I was profiling on Mac and I noticed many calls to PR_Atomic{Increment,Decrement}. We'd attempted to get rid of these in bug 592557. It appears that in the js engine (and perhaps elsewhere) DARWIN is not defined. This causes pratom.h to decide that __sync_add_and_fetch isn't defined, and we then fall back to the slow path. Filing under the js component until I can verify that this happens when building other parts of the code too.
Assignee | ||
Comment 1•13 years ago
|
||
This happens outside js, too. Moving to core/general. I think it's Mac and Linux, but I haven't tested Linux yet.
Assignee: general → nobody
Component: JavaScript Engine → General
QA Contact: general → general
Assignee | ||
Updated•13 years ago
|
Hardware: x86 → All
Assignee | ||
Comment 2•13 years ago
|
||
Works on Mac. Need to test on Linux.
Assignee | ||
Comment 3•13 years ago
|
||
To be fair, we're not falling back to the method which uses locks; there's pr/include/md/_darwin.h, which points to an assembly version of atomic increment for darwin. But it's silly -- we should be using the compiler intrinsic, saving a function call, and letting the compiler optimize around the atomic increment.
Assignee | ||
Updated•13 years ago
|
Summary: Prevent NSPR from falling back to slow PR_Atomic functions → Prevent NSPR from falling back to PR_Atomic functions
Assignee | ||
Comment 4•13 years ago
|
||
Linux and Windows seem to work fine as-is. I'll see if I can test Android.
Comment 5•13 years ago
|
||
(In reply to comment #4) > Linux and Windows seem to work fine as-is. I'll see if I can test Android. Android's gcc 4.4 and 4.4.3 don't have __sync_* built-in functions. It is required gcc 4.5.2 (for ARM). If I should write inline assembler for atomic for arm gcc 4.4.x platform, please file a new bug for NSPR.
Assignee | ||
Comment 6•13 years ago
|
||
Looks like the atomics for ARM were done in bug 405992.
Assignee | ||
Updated•13 years ago
|
Summary: Prevent NSPR from falling back to PR_Atomic functions → Prevent NSPR from falling back to PR_Atomic functions on Mac when compiler intrinsics are available
Assignee | ||
Comment 7•13 years ago
|
||
Attachment #537148 -
Flags: review?(ted.mielczarek)
Assignee | ||
Updated•13 years ago
|
Attachment #536952 -
Attachment is obsolete: true
Assignee | ||
Comment 8•13 years ago
|
||
Comment on attachment 537148 [details] [diff] [review] Patch v1 Josh, do you think those #undef DARWINs were there for a reason? We include Cocoa.h plenty of times without undef'ing DARWIN. The only harm of leaving the undefs in is that we'll call the PR_Atomic functions from these files instead of using the macros. If you want to leave them, that's OK with me.
Attachment #537148 -
Flags: review?(joshmoz)
Comment 9•13 years ago
|
||
Comment on attachment 537148 [details] [diff] [review] Patch v1 We should fix the NSPR pratom.h header. NSPR public headers should be self-sufficient and should not require the client to define any macro. We can change pratom.h to test defined(__APPLE__) instead of defined(DARWIN).
Assignee | ||
Comment 10•13 years ago
|
||
We'd similarly want to change LINUX to __LINUX__ in that case.
Assignee | ||
Comment 11•13 years ago
|
||
...actually, you'd probably want to change all of the OS defines, then, right? Maybe we can add a header which defines DARWIN, LINUX, etc. It appears there are many such defines.
Assignee | ||
Comment 12•13 years ago
|
||
Ah, I see; not all of these headers are publicly-consumable. The include/md folder is private? If so, looks like we just need to modify pratom.h.
Assignee | ||
Comment 13•13 years ago
|
||
(In reply to comment #5) > (In reply to comment #4) > > Linux and Windows seem to work fine as-is. I'll see if I can test Android. > > Android's gcc 4.4 and 4.4.3 don't have __sync_* built-in functions. It is > required gcc 4.5.2 (for ARM). So just to check, gcc 4.4.x doesn't define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4? Or does it define it and export a busted __sync_add_and_fetch?
Comment 14•13 years ago
|
||
(In reply to comment #13) > (In reply to comment #5) > > (In reply to comment #4) > > > Linux and Windows seem to work fine as-is. I'll see if I can test Android. > > > > Android's gcc 4.4 and 4.4.3 don't have __sync_* built-in functions. It is > > required gcc 4.5.2 (for ARM). > > So just to check, gcc 4.4.x doesn't define > __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4? Or does it define it and export a > busted __sync_add_and_fetch? gcc 4.4/4.4.3 for *arm* doesn't defined it and doesn't support __sync_* atomic. You can see more details by https://wiki.linaro.org/WorkingGroups/ToolChain/AtomicMemoryOperations. If __sync_* functions are supported by gcc, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_* is defined by cpp. I think that you should use __GCC_HAVE_SYNC_COMPARE_AND_SWAP_* instead of LINUX.
Assignee | ||
Comment 15•13 years ago
|
||
> I think that you should use __GCC_HAVE_SYNC_COMPARE_AND_SWAP_* instead of LINUX.
The problem, AIUI, is that on some architectures GCC defines __GCC_HAVE_SYNC_COMPARE_AND_SWAP_* but exports __sync_* intrinsics which aren't actually threadsafe. So we can only use the intrinsics on architectures where we know they're safe.
Comment 16•13 years ago
|
||
Comment on attachment 537148 [details] [diff] [review] Patch v1 I don't know why those DARWIN undefs are there, I'm fine with getting rid of them.
Attachment #537148 -
Flags: review?(joshmoz) → review+
Assignee | ||
Comment 17•13 years ago
|
||
Attachment #537552 -
Flags: review?(wtc)
Assignee | ||
Updated•13 years ago
|
Attachment #537148 -
Attachment is obsolete: true
Attachment #537148 -
Flags: review?(ted.mielczarek)
Comment 18•13 years ago
|
||
Comment on attachment 537552 [details] [diff] [review] NSPR Patch v1 r=wtc. Note that it is fine to test the LINUX macro because it is defined by NSPR (in mozilla/nsprpub/pr/include/md/_linux.cfg).
Attachment #537552 -
Flags: review?(wtc) → review+
Assignee | ||
Comment 19•13 years ago
|
||
I'm not clear what the process is for making changes to NSPR. Do I check this patch in to m-c, or somewhere else?
Comment 20•13 years ago
|
||
NSPR changes need to land in NSPR CVS. wtc or I can land them for you. Getting them into m-c requires one of us to also tag the NSPR repository, and then someone to update the NSPR snapshot in m-c.
Assignee | ||
Comment 21•13 years ago
|
||
(In reply to comment #20) > NSPR changes need to land in NSPR CVS. wtc or I can land them for you. > Getting them into m-c requires one of us to also tag the NSPR repository, > and then someone to update the NSPR snapshot in m-c. I'll sit tight then. :)
Updated•13 years ago
|
Keywords: checkin-needed
Updated•13 years ago
|
Whiteboard: [needs checkin to NSPR]
Comment 22•13 years ago
|
||
Sorry, I always forget about these bugs: Checking in pr/include/pratom.h; /cvsroot/mozilla/nsprpub/pr/include/pratom.h,v <-- pratom.h new revision: 3.20; previous revision: 3.19 done
Status: NEW → RESOLVED
Closed: 13 years ago
Component: General → NSPR
Keywords: checkin-needed
Product: Core → NSPR
QA Contact: general → nspr
Resolution: --- → FIXED
Whiteboard: [needs checkin to NSPR]
Target Milestone: --- → 4.8.9
Version: unspecified → 4.8.9
You need to log in
before you can comment on or make changes to this bug.
Description
•