Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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
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

[Core][aDAG] Remove busy waiting semaphore acquire in linux#47322

Open
rkooo567 wants to merge6 commits intoray-project:master
base:master
Choose a base branch
Loading
fromrkooo567:remove-unnecessary-busy-waiting

Conversation

rkooo567
Copy link
Contributor

Why are these changes needed?

In linux, we can simply use timedwait without busy-waiting which has performance penalty. I think the implementation complexity is low, and the aDAG should be as performance sensitive as possible, so we should avoid busy waiting if possible

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e.,git commit -s) in this PR.
  • I've runscripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed forhttps://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it indoc/source/tune/api/ under the
      corresponding.rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures athttps://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@rkooo567
Copy link
ContributorAuthor

Comment on lines +104 to +107
if (*timeout_point <= now) {
// If the timeout is already passed, try once and return
got_sem = sem_trywait(sem) == 0;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be unified withsem_timedwait:

If the timeout has already expired by the time of the call, and the semaphore could not be locked immediately, then sem_timedwait() fails with a timeout error (errno set to ETIMEDOUT).If the operation can be performed immediately, then sem_timedwait() never fails with a timeout error, regardless of the value of abs_timeout. Furthermore, the validity of abs_timeout is not checked in this case.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

will fix

auto secs = std::chrono::duration_cast<std::chrono::seconds>(duration);
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration - secs);

timespec ts;
Copy link
Member

Choose a reason for hiding this comment

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

nit:

timespec ts;clock_gettime(CLOCK_REALTIME, &ts);// get current timens = ns.count()// Handle the case where nanoseconds overflowauto one_sec_in_ns =1000000000L;ts.tv_sec += secs.count() + ns / one_sec_in_ns;ts.tv_nsec += ns % one_sec_in_ns;

auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration - secs);

timespec ts;
clock_gettime(CLOCK_REALTIME, &ts); // get current time
Copy link
Member

Choose a reason for hiding this comment

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

can we derivetimespec fromauto now = std::chrono::steady_clock::now();?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Also, should be CLOCK_MONOTONIC rather than CLOCK_REALTIME

@@ -93,6 +96,38 @@ Status PlasmaObjectHeader::TryToAcquireSemaphore(
break;
}
} while (std::chrono::steady_clock::now() < *timeout_point);

#else // defined(__Linux__)
Copy link
Member

Choose a reason for hiding this comment

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

Use#elif instead

@@ -16,6 +16,8 @@

#if defined(__APPLE__) || defined(__linux__)
#include <semaphore.h>

#include <ctime>
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to includectime? In addition, is it used by both APPLE and LINUX?

auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration - secs);

timespec ts;
clock_gettime(CLOCK_REALTIME, &ts); // get current time
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Also, should be CLOCK_MONOTONIC rather than CLOCK_REALTIME


#else // defined(__Linux__)

// Calculate the relative time to wait
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you extract this to a private util method?

@staleStale
Copy link

stalebot commentedFeb 25, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

  • If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@stalestalebot added the staleThe issue is stale. It will be closed within 7 days unless there are further conversation labelFeb 25, 2025
@hainesmichaelchainesmichaelc added the community-contributionContributed by the community labelApr 4, 2025
@stalestalebot removed the staleThe issue is stale. It will be closed within 7 days unless there are further conversation labelApr 4, 2025
@hainesmichaelchainesmichaelc removed the community-contributionContributed by the community labelApr 4, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@kevin85421kevin85421kevin85421 left review comments

@ruisearch42ruisearch42ruisearch42 left review comments

At least 1 approving review is required to merge this pull request.

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@rkooo567@kevin85421@ruisearch42@hainesmichaelc

[8]ページ先頭

©2009-2025 Movatter.jp