Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Expose aLock type in preview mode#87672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kouvel merged 17 commits intodotnet:mainfromkouvel:Lock
Oct 30, 2023
Merged

Expose aLock type in preview mode#87672

kouvel merged 17 commits intodotnet:mainfromkouvel:Lock
Oct 30, 2023

Conversation

@kouvel
Copy link
Contributor

@kouvelkouvel commentedJun 16, 2023
edited
Loading

  • For now, theLock type requires preview features to be enabled
  • Ported CoreCLR's AwareLock implementation to C# with a bit of refactoring, folded in a couple of ideas from NativeAOT's previousLock implementation, and fixed a couple of issues.
  • Added an adaptive spin strategy to reduce CPU time from spin-waiting when spin-waits are not effective
  • This implementation replaces NativeAOT'sLock implementation. The performance of acquiring a lock under contention is improved in NativeAOT.

API review:#34812
Tracking issue:#87673

En3Tho and ArminShoeibi reacted with thumbs up emojifilipnavara, AustinWise, and SupinePandora43 reacted with eyes emoji
@ghost
Copy link

Note regarding thenew-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

Tagging subscribers to this area:@mangod9
See info inarea-owners.md if you want to be subscribed.

Issue Details
  • For now, theLock type requires preview features to be enabled
  • Ported CoreCLR's AwareLock implementation to C# with a bit of refactoring, folded in a couple of ideas from NativeAOT's previousLock implementation, and fixed a couple of issues.
  • Added an adaptive spin strategy to reduce CPU time from spin-waiting when spin-waits are not effective
  • This implementation replaces NativeAOT'sLock implementation. The performance of acquiring a lock under contention is improved in NativeAOT.

API review:#34812

Author:kouvel
Assignees:kouvel
Labels:

area-System.Threading

Milestone:8.0.0

@kouvelkouvel mentioned this pull requestJun 16, 2023
8 tasks
@vargaz
Copy link
Contributor

The mono changes look ok.

kouvel reacted with thumbs up emoji

@kouvel
Copy link
ContributorAuthor

kouvel commentedJun 16, 2023
edited
Loading

Here are some perf numbers on NativeAOT. I used a test that has multiple threads enter a lock, perform a short delay, exit the lock, and perform another short delay. Throughput is the number of enter+delay+exit+delay rounds performed per ms. The delay is a recursive calculation of a random Fibonacci number between 4 and 9. The numbers are from my Intel x64 6-core 12-thread machine on Windows.

UsingMonitor:

ThreadsThroughput beforeCPU usage before (%)Throughput afterCPU usage after (%)
168009.368009.1
2570016.9570016.3
3510023.8530023.5
6390044.9540027.5
12250056.3530024.5
24260064.8530024.9

UsingLock:

ThreadsThroughputCPU usage (%)
168008.4
2640016.0
3580023.9
6550028.5
12550026.1
24550024.8
hez2010 reacted with rocket emoji

returntrue;
}

thrownewLockRecursionException(SR.Lock_Enter_LockRecursionException);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't think I'm following how this gets thrown. It would mean _recursionCount was -1. I don't see a test in LockTests for LockRecursionException.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh - you're using 32 bit overflowlike Native AOT .. since this is a new type, how about picking something smaller that is still always going to mean a bug in the app, but small enough that it won't cause a hang in the app (and also becomes feasibly unit testable). Eg., 65K

kouvel reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

in fact that's what the comment suggests "is expected to be high enough that it would typically not be reached when the lock is used properly."

@kouvel
Copy link
ContributorAuthor

Rebased to fix conflicts

@VSadov
Copy link
Member

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kouvel
Copy link
ContributorAuthor

Trying a rebase due to some unrelated build failures.

@kouvel
Copy link
ContributorAuthor

The remaining issues in the CI appear to be unrelated.

@radical
Copy link
Member

This was merged on Red and broke Wasm.Build.Tests onmain.#94212

@radical
Copy link
Member

Also one of thefailures is:

Unhandled exception. System.InvalidOperationException: There is no currently active test.   at Xunit.Sdk.TestOutputHelper.QueueTestOutput(String output) in /_/src/xunit.execution/Sdk/Frameworks/TestOutputHelper.cs:line 60   at System.Diagnostics.AsyncStreamReader.FlushMessageQueue(Boolean rethrowInNewThread)--- End of stack trace from previous location ---   at System.Threading.ThreadPoolWorkQueue.Dispatch()   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()./RunTests.sh: line 105:    83 Aborted                 (core dumped) dotnet exec xunit.console.dll Wasm.Build.Tests.dll -xml $XHARNESS_OUT/testResults.xml $HELIX_XUNIT_ARGS -nocolor -verbose -notrait category=IgnoreForCI -notrait category=failing $XUnitTraitArg $RSP_FILE

Could this be related to the change here? I have never seen this happen on the tests before.

cc@lewing

@jkotas
Copy link
Member

Also introduced#94227

@kouvel
Copy link
ContributorAuthor

This was merged on Red and broke Wasm.Build.Tests on main.#94212
Could this be related to the change here? I have never seen this happen on the tests before.

I have no idea how this PR could cause those failures, apologies if there was a mishap. There are only a few lines of code in this PR that would affect wasm, do you see anything that could be relevant? I'll see if I can get a repro, but otherwise I don't see any link between the failure and this PR.

Also introduced#94227

#94241 should fix the issue.

@kouvel
Copy link
ContributorAuthor

kouvel commentedOct 31, 2023
edited
Loading

Could this be related to the change here? I have never seen this happen on the tests before.

Only thing I can think of at the moment is that there is a pragma warning disable for using preview features when we should probably be enabling preview features for the corelib project. I don't know what kind of effect that would have, but I think that's something that was missed after local testing and unaddressed, so I'll fix that anyway.

kouvel added a commit that referenced this pull requestNov 2, 2023
* Small cleanup for Lock in Mono- Enable preview features in shared CoreLib project instead of disabling the compiler warning. Probably a bit cleaner, and would enable using Lock in other libraries to try it out.- Undid an unnecessary change from#87672
@ghostghost locked asresolvedand limited conversation to collaboratorsDec 1, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@danmoseleydanmoseleydanmoseley left review comments

@jkotasjkotasjkotas left review comments

@VSadovVSadovVSadov approved these changes

@mangod9mangod9Awaiting requested review from mangod9

@BrzVladBrzVladAwaiting requested review from BrzVladBrzVlad is a code owner

@vargazvargazAwaiting requested review from vargaz

@lambdageeklambdageekAwaiting requested review from lambdageek

@thaystgthaystgAwaiting requested review from thaystgthaystg is a code owner

@marek-safarmarek-safarAwaiting requested review from marek-safar

@MichalStrehovskyMichalStrehovskyAwaiting requested review from MichalStrehovskyMichalStrehovsky is a code owner

+1 more reviewer

@gfoidlgfoidlgfoidl left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

@kouvelkouvel

Projects

None yet

Milestone

9.0.0

Development

Successfully merging this pull request may close these issues.

7 participants

@kouvel@vargaz@VSadov@radical@jkotas@gfoidl@danmoseley

[8]ページ先頭

©2009-2025 Movatter.jp