Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WT-12331 API review #10562

Closed
wants to merge 8 commits into from
Closed

WT-12331 API review #10562

wants to merge 8 commits into from

Conversation

marcbutler
Copy link
Contributor

Add the header only for API review.

  • For API design review ONLY.
  • Not in WT normal style: will be changed once API design is agreed.

*
* \retval -EINVAL Not a futex, or pointer to [val] is null.
*/
int __wt_fetch(struct __wt_futex *ftx, uint32_t *val);
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason not to call this __wt_futex_fetch? I'm trying to figure out if fetch/store consciously skip the futex prefix.

I'm not that familiar with futexes, but the interface seems sensible to me as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No: entirely inadvertent. Fixed -- thanks.

@marcbutler marcbutler marked this pull request as draft May 7, 2024 03:42
Copy link
Contributor

@pmacko86 pmacko86 left a comment

Choose a reason for hiding this comment

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

Nice proposal—thanks for putting it together! I added several comments with questions about clarifying some of the behaviors, which may be worth addressing in the comments.

/*
* Get the value associated with the futex.
*
* \retval -EINVAL Not a futex, or pointer to [val] is null.
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 WT normally returns positive, not negative error codes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to change, this is an old device driver habit. My experience has been so far that the majority of WT calls set errno and return -1. Happy to bring it into expectations.

/*
* Wait on a futex.
*
* \param expected Expected current value of futex.
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the expected return value if the current value of futex is not the same as the expected value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is treated as a wakeup.

* \param expected Expected current value of futex.
*
* \retval -EINVAL Not a futex, or [timeout_us] <= 0.
* \retval -ETIMEDOUT Timeout expired before being awoken.
Copy link
Contributor

Choose a reason for hiding this comment

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

What would this function do if the system call gets interrupted and fails with EINTR? In that case, would the function wait again, or would it fail - and if so, with which return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the futex call is interrupted, a new timeout is calculated and it goes back to waiting.

*
* \retval -EINVAL Not a futex.
*/
int __wt_futex_store(struct __wt_futex *ftx, uint32_t val);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you expect a need to add atomic operations on futexes in the future, such as increment, decrement, or compare-and-swap? If so, is it worth defining them now, or we'd just add them as needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here originally was to provide some kind of wrapper for a basic use: with the idea of trying to create a usable abstract mechanism. However you raise a good point: this is a low-level mechanism and we will likely want to vary how we modify the associated 32-bit value. So I have pared the API to a portable "futex ops" API.

Copy link
Contributor

@keitharnoldsmith keitharnoldsmith left a comment

Choose a reason for hiding this comment

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

I started a review, got interrupted, ate lunch, came back... and found that Peter had stolen my comment about negative error returns! :-)

I'm not sure whether the header name is intended to be part of the API up for review here, but I'd call this os_futex.h since it's abstracting functionality across multiple operating systems, or possibly just place this content in os.h.

I'll LGTM and follow along on Peter's comments.

Rather than try to abstract out the futex, provide a minimal porting
interface as originally envisaged.

Reformat in the WT style.
This is and should be a very thin wrapper around OS implementations.
Higher level constructs can utilze session context as appropriate.

Cast to volatile in the parameter.
Adds unit test.
Copy link

Test coverage is too low, this change probably shouldn't be merged as-is.

Metric (for added/changed code) Coverage
Line coverage 0% (0/15)
Branch coverage 0% (0/4)

@marcbutler marcbutler closed this May 20, 2024
@marcbutler marcbutler deleted the wt-12331-futex branch May 20, 2024 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants