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

lib: remove select(), allow pthreads to poke poll() #555

Closed
wants to merge 2 commits into from

Conversation

qlyoung
Copy link
Member

@qlyoung qlyoung commented May 16, 2017

When scheduling a task onto a thread master owned by another pthread, we
need to lock the thread master's mutex. However, if the pthread which
owns that thread master is in poll(), we could be stuck waiting for a
very long time. To solve this, we copy all data poll() needs and unlock
during poll(). To break the target pthread out of poll(), thread_master
has gained a pipe whose reading end is passed into poll(). After an event
that requires immediate action by the target pthread, a byte is written
into the pipe in order to wake it up.

This commit also removes select(), as poll() is present on every supported
platform and does not have an upper limit on file descriptors.

Signed-off-by: Quentin Young qlyoung@cumulusnetworks.com

@NetDEF-CI
Copy link
Collaborator

Continous Integration Result: SUCCESSFUL

Congratulations, this patch passed basic tests

Tested-by: NetDEF / OpenSourceRouting.org CI System

CI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-727/

This is a comment from an EXPERIMENTAL automated CI system.
For questions and feedback in regards to this CI system, please feel free to email
Martin Winter - mwinter (at) opensourcerouting.org.

lib/thread.c Outdated
@@ -378,13 +384,14 @@ thread_master_create (void)
rv->timer->update = rv->background->update = thread_timer_update;
rv->spin = true;
rv->handle_signals = true;
pipe (rv->io_pipe);
fcntl (rv->io_pipe[0], F_SETFL, fcntl(rv->io_pipe[0], F_GETFL, 0) | O_NONBLOCK);
Copy link
Member

Choose a reason for hiding this comment

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

There's a function in lib/network.c called set_nonblocking for that, maybe you want to use it.

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea, changed

When scheduling a task onto a thread master owned by another pthread, we
need to lock the thread master's mutex. However, if the pthread which
owns that thread master is in poll(), we could be stuck waiting for a
very long time. To solve this, we copy all data poll() needs and unlock
during poll(). To break the target pthread out of poll(), thread_master
has gained a pipe whose reading end is passed into poll(). After an event
that requires immediate action by the target pthread, a byte is written
into the pipe in order to wake it up.

This commit also removes select(), as poll() is present on every supported
platform and does not have an upper limit on file descriptors.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
@NetDEF-CI
Copy link
Collaborator

Continous Integration Result: SUCCESSFUL

Congratulations, this patch passed basic tests

Tested-by: NetDEF / OpenSourceRouting.org CI System

CI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-737/

This is a comment from an EXPERIMENTAL automated CI system.
For questions and feedback in regards to this CI system, please feel free to email
Martin Winter - mwinter (at) opensourcerouting.org.

@@ -40,6 +41,12 @@ DEFINE_MTYPE_STATIC(LIB, THREAD_STATS, "Thread stats")
#include <mach/mach_time.h>
#endif

#define AWAKEN(m) \
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't used anywhere ... is this patch actually complete?

(Would've been better to put the select() removal in a separate patch, very confusing to review like this...)

Copy link
Member Author

@qlyoung qlyoung May 18, 2017

Choose a reason for hiding this comment

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

It is used in multiple places, but looks like it snuck out of funcname_thread_add_read_write in a force push somewhere...and yes, but the pipe poke related changes are actually quite small, just the bits in fd_poll and thread_master_create.

@@ -878,6 +779,8 @@ funcname_thread_add_timer_timeval (struct thread_master *m,
          }
      }
      pthread_mutex_unlock (&thread->mtx);
 +
 +    AWAKEN (m);
    }
    pthread_mutex_unlock (&m->mtx);

and funcname_thread_add_event as well, one moment and I'll add it back to rw

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
@NetDEF-CI
Copy link
Collaborator

Continous Integration Result: SUCCESSFUL

Congratulations, this patch passed basic tests

Tested-by: NetDEF / OpenSourceRouting.org CI System

CI System Testrun URL: https://ci1.netdef.org/browse/FRR-FRRPULLREQ-766/

This is a comment from an EXPERIMENTAL automated CI system.
For questions and feedback in regards to this CI system, please feel free to email
Martin Winter - mwinter (at) opensourcerouting.org.


CLANG Static Analyzer Summary

  • Github Pull Request 555, comparing to Git base SHA 934ec54

Bug comparison statistics:

  • Fixed bugs: 0
  • New bugs: 0

143 Static Analyzer issues remaining.

See details at
https://ci1.netdef.org/browse/FRR-FRRPULLREQ-766/artifact/shared/static_analysis/index.html

@donaldsharp
Copy link
Member

@eqvinox needs to relook

@eqvinox
Copy link
Contributor

eqvinox commented May 30, 2017

replaced by #633

@eqvinox eqvinox closed this May 30, 2017
@qlyoung qlyoung deleted the wake-poll2 branch June 16, 2017 19:22
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.

5 participants