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

bpo-41001: Add os.eventfd()#20930

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
tiran merged 7 commits intopython:masterfromtiran:bpo-41001-eventfd
Nov 13, 2020
Merged

Conversation

tiran
Copy link
Member

@tirantiran commentedJun 17, 2020
edited by bedevere-bot
Loading

aeros reacted with thumbs up emoji
@tirantiran added the type-featureA feature request or enhancement labelJun 17, 2020
@tirantiranforce-pushed thebpo-41001-eventfd branch 2 times, most recently from2891141 to307cf27CompareJune 17, 2020 17:28
@aeros
Copy link
Contributor

Thanks for working on this, Tiran. It seems like it would be worthwhile to add a brief What's New entry for the addition ofos.eventfd().

@@ -3524,6 +3525,48 @@ def test_memfd_create(self):
self.assertFalse(os.get_inheritable(fd2))


@unittest.skipUnless(hasattr(os, 'eventfd'), 'requires os.eventfd')
@support.requires_linux_version(2, 30)
Copy link
Contributor

@aerosaerosJun 18, 2020
edited
Loading

Choose a reason for hiding this comment

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

I think the test class should be ran with Linux 2.27+ (to at least covertest_eventfd_initval) and thentest_eventfd_semaphore (or any future tests that require use of theos.EFD_NONBLOCK flag) can require 2.30+. I'm not sure that it's entirely necessary or the number of devices it would actually be applicable to, but it seems like a better practice to havesome amount of test coverage for 2.27 - 2.29 since the feature will be included in those versions.

Also, would it be worthwhile to add a test that makes use of select (maybe for poll and epoll as well, via mixin), which uses them to check if the file descriptor is ready for reading or writing? I suspect those will be typically used withos.eventfd(), so ensuring that behavior works as expected would make sense to me. I'm just not certain if it makes sense to include those intest_os, or if there might be a better location.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It's actually 2.6.30, not 2.30. I'll fix that with the next commit. Linux Kernel 2.6.30 was released in 2009. It's highly unlikely that somebody is running a Kernel version between 2.6.27 and 2.6.30.

aeros reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

It's actually 2.6.30, not 2.30. I'll fix that with the next commit.

Ah, good catch. I completely didn't notice the missing.6, despite recently reading over the man page foreventfd(). :-)

It's highly unlikely that somebody is running a Kernel version between 2.6.27 and 2.6.30.

Yeah, after looking over the dates for the releases, I'm now in agreement that it would be highly unlikely. If anything, I suspect most on the 2.6.x branch would be using 2.6.39 or 2.6.32.

(Based onhttps://upload.wikimedia.org/wikipedia/en/timeline/40658da696ee210d2be5f221ac12e43b.png.)

@@ -3195,6 +3195,27 @@ features:
.. versionadded:: 3.8


.. function:: eventfd(initval[, flags=os.EFD_CLOEXEC])

Create an event file descriptor
Copy link
Contributor

@aerosaerosJun 18, 2020
edited
Loading

Choose a reason for hiding this comment

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

I think this could be expanded upon a bit, specifically by:

  1. Explicitly mentioning that the file descriptor is returned. I think it helps to make usage a bit more clear, and is done for the abovememfd_create().
  2. Briefly summarize the use for it as a lightweight notifier/waiter for events. Compared to a pipe, it is more resource efficient as an event notifier.

E.g.

Suggested change
Create anevent file descriptor
Createand returnan"eventfd" file descriptor. It can be used as a lightweight
event notifier.
..note::
Compared to a pipe that is exclusively used for event notification,
`eventfd()` can be used as a more resource efficient alternative that
only uses a single file descriptor and has far less overhead.

While I agree with making the low-level OS functions that are thin wrappers to existing OS APIs fairly minimal in terms of documentation details (especially if they're already well documented), I think the existing one could provide a bit more information to the user that explainswhy they might want to use it.

For the full details one can view the man page, but IMO, we at least should summarize the general purpose. Otherwise, I suspect it will significantly deter discoverability of the feature.

@aerosaeros requested a review frompitrouJune 18, 2020 04:31
@tiran
Copy link
MemberAuthor

I have updated the documentation, added a select() test case, and included eventfd_read + eventfd_write helper functions. They are just too useful to omit them.

aeros reacted with thumbs up emoji

Copy link
Member

@pitroupitrou left a comment

Choose a reason for hiding this comment

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

This is nice, though I suspecteventfd_read does a system call even when uncontended?

:func:`eventfd_write` increments the event counter.

*initval* is the initial value of the event counter. It must be an
unsigned integer between 0 and 2\ :sup:`64`\ -\ 2.
Copy link
Member

Choose a reason for hiding this comment

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

According to thisman page, the initialization value is anunsigned int. In any case, I don't think it's useful to document the maximum value.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I have updated the documentation. I think it's useful to document that the initial value is limited toUINT32_MAX while the maximum counter isUINT64_MAX - 1.

doodspav reacted with thumbs up emoji
Provide semaphore-like semantics for reads from a :func:`eventfd` file
descriptor. On read the internal counter is decremented by one.

.. availability:: Linux 2.6.30 or newer
Copy link
Member

Choose a reason for hiding this comment

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

What's the rationale for adding an availability markup for this data member but not the others?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

All other items have same availability aseventfd, semaphore came a bit later.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment:I have made the requested changes; please review again.

@tiran
Copy link
MemberAuthor

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@pitrou: please review the changes made to this pull request.

@tirantiranforce-pushed thebpo-41001-eventfd branch 2 times, most recently from1c504ff to5c9d03eCompareJune 23, 2020 13:35
Copy link
Contributor

@aerosaeros left a comment
edited
Loading

Choose a reason for hiding this comment

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

LGTM (other than a minor suggested change for the whatsnew entry).

As mentioned in a previous review comment, I would prefer to have some mention in the docs of the specific use case foreventfd as a lightweight event notifier/waiter (essentially a brief summary of the "Notes" section from the man page) so that users are aware of its general functionality, even if they may not be already familiar with the system call. Unlike in the earlier years of Python, it's becoming increasingly common for developers to have started with Python before C (which has been my own experience). So, I think it's often quite helpful to at least have a summary of the purpose of the function, instead of assuming the reader is already familiar with it.

But IMO, it's fine to merge as is, that can potentially be considered as a future enhancement to the documentation. The core implementation of the wrapper, helpers, and the tests looks good to me.

(Note that I'm not particularly familiar with the details of implementing a CPython wrapper for a system call, I mainly used the existing members that work with FDs for comparison.)

try:
import select
except ImportError:
select = None
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems all other modules / tests don't guard againstselect not being available. It looks like all platforms should support it (at leastselect.select).

@tirantiranforce-pushed thebpo-41001-eventfd branch 2 times, most recently from50747e8 to54c49fbCompareJune 24, 2020 04:04
@aeros
Copy link
Contributor

aeros commentedJun 25, 2020
edited
Loading

@tiran This is more of a question than it is feedback, but is there a particular reason why we don't link to a specific man page for additional information here? I see that it's not done for other similar members that are effectively just wrappers for system calls, but it seems like it would be quite useful for readers in this case (particularly since our documentation of it is just a brief summary). This could very easily be done using the:manpage: inline sphinx role:

:manpage:`eventfd(2)`

@pablogsal
Copy link
Member

I would suggest also to add a test using poll/epoll if available, but I don't feel strongly about it

@tirantiranforce-pushed thebpo-41001-eventfd branch 2 times, most recently fromfcaa02c to0cf9151CompareNovember 13, 2020 10:26
tiranand others added7 commitsNovember 13, 2020 11:27
The ``eventfd_read`` and ``eventfd_write`` functions are convenientwrappers that perform proper read/write and conversion from/to uint64_t.Signed-off-by: Christian Heimes <christian@python.org>
Signed-off-by: Christian Heimes <christian@python.org>
- initval is a uint32_t- improve documentation- add whatsnewSigned-off-by: Christian Heimes <christian@python.org>
Signed-off-by: Christian Heimes <christian@python.org>
Co-authored-by: Kyle Stanley <aeros167@gmail.com>
@tirantiran merged commitcd9fed6 intopython:masterNov 13, 2020
@bedevere-bot
Copy link

@tiran: Please replace# withGH- in the commit message next time. Thanks!

@tirantiran deleted the bpo-41001-eventfd branchNovember 13, 2020 18:48
adorilson pushed a commit to adorilson/cpython that referenced this pull requestMar 13, 2021
Co-authored-by: Kyle Stanley <aeros167@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@giampaologiampaologiampaolo left review comments

@pablogsalpablogsalpablogsal left review comments

@aerosaerosaeros approved these changes

@pitroupitrouAwaiting requested review from pitrou

@markshannonmarkshannonAwaiting requested review from markshannon

Assignees
No one assigned
Labels
type-featureA feature request or enhancement
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@tiran@aeros@bedevere-bot@pablogsal@giampaolo@pitrou@the-knights-who-say-ni

[8]ページ先頭

©2009-2025 Movatter.jp