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

poll: Minimize overhead when polling single event #1396

Closed
wants to merge 2 commits into from

Conversation

Vudentz
Copy link
Contributor

@Vudentz Vudentz commented Sep 7, 2017

This attempts to minimize as much as possible when polling a single event which is what k_queue_get does when CONFIG_POLL is enabled.

Jira: 2593

@pfalcon
Copy link
Contributor

pfalcon commented Sep 7, 2017

@Vudentz : Thanks much for looking into this! Unfortunately, it doesn't seem to have any noticeable effect on #1378 :

(on 100 requests)

  50%     20
  66%     22
  75%     23
  80%     24
  90%   1020
  95%   1024
  98%   1040
  99%   1042
 100%   1042 (longest request)

kernel/poll.c Outdated
@@ -197,6 +231,10 @@ int k_poll(struct k_poll_event *events, int num_events, s32_t timeout)
int last_registered = -1, rc;
unsigned int key;

if (num_events == 1) {
return poll_1(events, timeout);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not just a goto to a label on line 241? I am not sure introducing poll_1() optimize that much the path.

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

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

Not loving it, unless you can convince me this is a real world performance win.

kernel/poll.c Outdated
@@ -246,7 +246,7 @@ int k_poll(struct k_poll_event *events, int num_events, s32_t timeout)

_pend_current_thread(&wait_q, timeout);

int swap_rc = _Swap(key);
rc = _Swap(key);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? This surely doesn't affect the generated code at all (and if so only spuriously by e.g. changing register assignments), and honestly IMHO it was clearer with one specific/named register per use. Mutable variables are a bad thing when not 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.

I always thought this would require another register, isn't that a common practice not to introduce new variable if you can reuse them. Perhaps this depends on the compiler and if it can detect there is no overlapping of rc and swap_rc, but depending on the compiler to do the right thing sometimes can backfire.

kernel/poll.c Outdated
@@ -197,6 +231,10 @@ int k_poll(struct k_poll_event *events, int num_events, s32_t timeout)
int last_registered = -1, rc;
unsigned int key;

if (num_events == 1) {
return poll_1(events, timeout);
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you benchmarked this? The net effect here is a fairly significant increase in code size, and what you gain is AFAICT that the loop exit test in the needs to be executed only once (i.e. if(num_events == 1) is basically the same test) instead of twice, and the final irq_unlock/lock pair gets to be elided.

That's just a tiny handful of cycles. I'm sure it's faster, but I doubt it's much faster and I'd say we really need to see numbers before adding this.

Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that this patch was an attempt to address https://jira.zephyrproject.org/browse/ZEP-2593 , but per my comment above, it doesn't help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I was coming from the point that IRQ should be locked as little as possible since this is now used for by buffer polls this is a very heavy dependency on this code path.

nagineni pushed a commit to nagineni/zephyr that referenced this pull request Nov 20, 2017
…ect-rtos#1396)

Configure will now call the helper method to set both modes instead of
writing directory to the register, this fixed an issue where app
cannot reconfigure classification mode once it is set.

Fixes zephyrproject-rtos#1254

Signed-off-by: Jimmy Huang <[email protected]>
It is now possible to poll event if there is another thread polling.

Signed-off-by: Luiz Augusto von Dentz <[email protected]>
In case K_POLL_STATE_NOT_READY is set the return will be set to -EINTR
indicating that the poll was interrupted.

Fixes zephyrproject-rtos#5026

Signed-off-by: Luiz Augusto von Dentz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants