Signals were not a good choice of IPC to implement the poll function for several reasons: In order to handle the asynchrnous poll-related event, a substantial amount of state information is needed. Signals are only capable of passing minimal amounts of data. There are also complexities with performing kernel space signal handlers in kernel space code that is better to avoid. So, instead of signals, the equivalent logic was converted to run via a callback that executes on the high-priority work queue.

Squashed commit of the following:

    Fix up some final compile isses.

    net/netdev:  Convert the network down notification logic to use the new wqueue-based notification factility.

    net/udp:  Convert the UDP readahead notification logic to use the new wqueue-based notification factility.

    net/tcp:  Convert the TCP readahead notification logic to use the new wqueue-based notification factility.

    mm/iob:  Convert the IOB notification logic to use the new wqueue-based notification factility.

    sched/wqueue:  Signals are not good IPCs to support the target poll functionality for several reasons including the amount of data that can be passed with a signal and in the fact that in protected and kernel modes, user threads executing signal handlers in protected, kernel memory is problematic.  Instead, convert the same logic to perform the notifications via function callback on the high priority work queue.
This commit is contained in:
Gregory Nutt
2018-09-09 15:01:44 -06:00
parent 20814acad2
commit 9d3148406c
23 changed files with 570 additions and 448 deletions
+2 -3
View File
@@ -39,10 +39,9 @@ config NETDEV_IFINDEX
config NETDOWN_NOTIFIER
bool "Support network down notifications"
default n
select SIG_NOTIFIER
depends on !DISABLE_SIGNALS
depends on SCHED_HPWORK
---help---
Enable building of logic that will send a signal to a kernel
Enable building of logic that will execute on the high priority work
thread when the network is taken down. This is is a general purpose
notifier, but was developed specifically to support SIGHUP poll()
logic.
+18 -18
View File
@@ -47,6 +47,10 @@
#include <nuttx/net/ip.h>
#ifdef CONFIG_NETDOWN_NOTIFIER
# include <nuttx/wqueue.h>
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -464,24 +468,24 @@ int netdev_ipv6_ifconf(FAR struct lifconf *lifc);
*
****************************************************************************/
#ifdef CONFIG_NETDOWN_NOTIFIER
int netdev_dev_lladdrsize(FAR struct net_driver_s *dev);
#endif
/****************************************************************************
* Name: netdown_notifier_setup
*
* Description:
* Set up to notify the specified PID with the provided signal number.
*
* NOTE: To avoid race conditions, the caller should set the sigprocmask
* to block signal delivery. The signal will be delivered once the
* signal is removed from the sigprocmask.
* Set up to perform a callback to the worker function the network goes
* down. The worker function will execute on the high priority worker
* thread.
*
* Input Parameters:
* pid - The PID to be notified. If a zero value is provided, then the
* PID of the calling thread will be used.
* signo - The signal number to use with the notification.
* worker - The worker function to execute on the high priority work
* queue when data is available in the UDP readahead buffer.
* dev - The network driver to be monitored
*
* arg - A user-defined argument that will be available to the worker
* function when it runs.
* Returned Value:
* > 0 - The signal notification is in place. The returned value is a
* key that may be used later in a call to
@@ -495,14 +499,15 @@ int netdev_dev_lladdrsize(FAR struct net_driver_s *dev);
****************************************************************************/
#ifdef CONFIG_NETDOWN_NOTIFIER
int netdown_notifier_setup(int pid, int signo, FAR struct net_driver_s *dev);
int netdown_notifier_setup(worker_t worker, FAR struct net_driver_s *dev,
FAR void *arg);
#endif
/****************************************************************************
* Name: netdown_notifier_teardown
*
* Description:
* Eliminate a TCP read-ahead notification previously setup by
* Eliminate a network down notification previously setup by
* netdown_notifier_setup(). This function should only be called if the
* notification should be aborted prior to the notification. The
* notification will automatically be torn down after the signal is sent.
@@ -525,13 +530,8 @@ int netdown_notifier_teardown(int key);
* Name: netdown_notifier_signal
*
* Description:
* Read-ahead data has been buffered. Signal all threads waiting for
* read-ahead data to become available.
*
* When the read-ahead data becomes available, *all* of the waiters in
* this thread will be signaled. If there are multiple waiters then only
* the highest priority thread will get the data. Lower priority threads
* will need to call netdown_notifier_setup() once again.
* A network has gone down has been buffered. Execute worker thread
* functions for all threads monitoring the state of the device.
*
* Input Parameters:
* dev - The TCP connection where read-ahead data was just buffered.
+29 -25
View File
@@ -40,8 +40,9 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <assert.h>
#include <nuttx/signal.h>
#include <nuttx/wqueue.h>
#include <nuttx/mm/iob.h>
#include <nuttx/net/netdev.h>
@@ -57,18 +58,16 @@
* Name: netdown_notifier_setup
*
* Description:
* Set up to notify the specified PID with the provided signal number.
*
* NOTE: To avoid race conditions, the caller should set the sigprocmask
* to block signal delivery. The signal will be delivered once the
* signal is removed from the sigprocmask.
* Set up to perform a callback to the worker function the network goes
* down. The worker function will execute on the high priority worker
* thread.
*
* Input Parameters:
* pid - The PID to be notified. If a zero value is provided, then the
* PID of the calling thread will be used.
* signo - The signal number to use with the notification.
* worker - The worker function to execute on the high priority work
* queue when data is available in the UDP readahead buffer.
* dev - The network driver to be monitored
*
* arg - A user-defined argument that will be available to the worker
* function when it runs.
* Returned Value:
* > 0 - The signal notification is in place. The returned value is a
* key that may be used later in a call to
@@ -81,8 +80,13 @@
*
****************************************************************************/
int netdown_notifier_setup(int pid, int signo, FAR struct net_driver_s *dev)
int netdown_notifier_setup(worker_t worker, FAR struct net_driver_s *dev,
FAR void *arg)
{
struct work_notifier_s info;
DEBUGASSERT(worker != NULL);
/* If network driver is already down, then return zero without setting up
* the notification.
*/
@@ -92,16 +96,21 @@ int netdown_notifier_setup(int pid, int signo, FAR struct net_driver_s *dev)
return 0;
}
/* Otherwise, this is just a simple wrapper around nxsig_notifer_setup(). */
/* Otherwise, this is just a simple wrapper around work_notifer_setup(). */
return nxsig_notifier_setup(pid, signo, NXSIG_NET_DOWN, dev);
info.evtype = WORK_NET_DOWN;
info.qualifier = dev;
info.arg = arg;
info.worker = worker;
return work_notifier_setup(&info);
}
/****************************************************************************
* Name: netdown_notifier_teardown
*
* Description:
* Eliminate a TCP read-ahead notification previously setup by
* Eliminate a network down notification previously setup by
* netdown_notifier_setup(). This function should only be called if the
* notification should be aborted prior to the notification. The
* notification will automatically be torn down after the signal is sent.
@@ -118,22 +127,17 @@ int netdown_notifier_setup(int pid, int signo, FAR struct net_driver_s *dev)
int netdown_notifier_teardown(int key)
{
/* This is just a simple wrapper around nxsig_notifier_teardown(). */
/* This is just a simple wrapper around work_notifier_teardown(). */
return nxsig_notifier_teardown(key);
return work_notifier_teardown(key);
}
/****************************************************************************
* Name: netdown_notifier_signal
*
* Description:
* Read-ahead data has been buffered. Signal all threads waiting for
* read-ahead data to become available.
*
* When the read-ahead data becomes available, *all* of the waiters in
* this thread will be signaled. If there are multiple waiters then only
* the highest priority thread will get the data. Lower priority threads
* will need to call netdown_notifier_setup() once again.
* A network has gone down has been buffered. Execute worker thread
* functions for all threads monitoring the state of the device.
*
* Input Parameters:
* dev - The TCP connection where read-ahead data was just buffered.
@@ -145,9 +149,9 @@ int netdown_notifier_teardown(int key)
void netdown_notifier_signal(FAR struct net_driver_s *dev)
{
/* This is just a simple wrapper around nxsig_notifier_signal(). */
/* This is just a simple wrapper around work_notifier_signal(). */
return nxsig_notifier_signal(NXSIG_NET_DOWN, dev);
return work_notifier_signal(WORK_NET_DOWN, dev);
}
#endif /* CONFIG_NETDOWN_NOTIFIER */
+6 -7
View File
@@ -69,14 +69,13 @@ config NET_TCP_READAHEAD
config TCP_READAHEAD_NOTIFIER
bool "Support TCP read-ahead notifications"
default n
select SIG_NOTIFIER
depends on NET_TCP_READAHEAD && !DISABLE_SIGNALS
depends on NET_TCP_READAHEAD && SCHED_HPWORK
---help---
Enable building of TCP read-ahead notifier logic that will send a
signal to a kernel thread when an TCP read-ahead data has been
buffered. This is is a general purpose notifier, but was developed
specifically to support TCP poll() logic where the poll must wait
for incoming TCP data to be buffered.
Enable building of TCP read-ahead notifier logic that will execute a
worker function on the high priority work queue when read-ahead data
is available. This is is a general purpose notifier, but was
developed specifically to support poll() logic where the poll must
wait for read-ahead data to become available.
config NET_TCP_WRITE_BUFFERS
bool "Enable TCP/IP write buffering"
+17 -21
View File
@@ -49,6 +49,10 @@
#include <nuttx/mm/iob.h>
#include <nuttx/net/ip.h>
#ifdef CONFIG_TCP_READAHEAD_NOTIFIER
# include <nuttx/wqueue.h>
#endif
#if defined(CONFIG_NET_TCP) && !defined(CONFIG_NET_TCP_NO_STACK)
/****************************************************************************
@@ -1546,21 +1550,16 @@ int tcp_pollteardown(FAR struct socket *psock, FAR struct pollfd *fds);
* Name: tcp_notifier_setup
*
* Description:
* Set up to notify the specified PID with the provided signal number.
*
* NOTE: To avoid race conditions, the caller should set the sigprocmask
* to block signal delivery. The signal will be delivered once the
* signal is removed from the sigprocmask.
*
* NOTE: If sigwaitinfo() or sigtimedwait() are used to catch the signal
* then then TCP connection structure pointer may be recovered in the
* sival_ptr value of the struct siginfo instance.
* Set up to perform a callback to the worker function when an TCP data
* is added to the read-ahead buffer. The worker function will execute
* on the high priority worker thread.
*
* Input Parameters:
* pid - The PID to be notified. If a zero value is provided, then the
* PID of the calling thread will be used.
* signo - The signal number to use with the notification.
* worker - The worker function to execute on the high priority work
* queue when data is available in the TCP readahead buffer.
* conn - The TCP connection where read-ahead data is needed.
* arg - A user-defined argument that will be available to the worker
* function when it runs.
*
* Returned Value:
* > 0 - The signal notification is in place. The returned value is a
@@ -1575,7 +1574,8 @@ int tcp_pollteardown(FAR struct socket *psock, FAR struct pollfd *fds);
****************************************************************************/
#ifdef CONFIG_TCP_READAHEAD_NOTIFIER
int tcp_notifier_setup(int pid, int signo, FAR struct tcp_conn_s *conn);
int tcp_notifier_setup(worker_t worker, FAR struct tcp_conn_s *conn,
FAR void *arg);
#endif
/****************************************************************************
@@ -1608,14 +1608,10 @@ int tcp_notifier_teardown(int key);
* Read-ahead data has been buffered. Signal all threads waiting for
* read-ahead data to become available.
*
* When the read-ahead data becomes available, *all* of the waiters in
* this thread will be signaled. If there are multiple waiters then only
* the highest priority thread will get the data. Lower priority threads
* will need to call tcp_notifier_setup() once again.
*
* NOTE: If sigwaitinfo() or sigtimedwait() are used to catch the signal
* then then TCP connection structure pointer may be obtained in the
* sival_ptr value of the struct siginfo instance.
* When read-ahead data becomes available, *all* of the workers waiting
* for read-ahead data will be executed. If there are multiple workers
* waiting for read-ahead data then only the first to execute will get the
* data. Others will need to call tcp_notifier_setup() once again.
*
* Input Parameters:
* conn - The TCP connection where read-ahead data was just buffered.
+30 -28
View File
@@ -40,8 +40,9 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <assert.h>
#include <nuttx/signal.h>
#include <nuttx/wqueue.h>
#include <nuttx/mm/iob.h>
#include "tcp/tcp.h"
@@ -56,21 +57,16 @@
* Name: tcp_notifier_setup
*
* Description:
* Set up to notify the specified PID with the provided signal number.
*
* NOTE: To avoid race conditions, the caller should set the sigprocmask
* to block signal delivery. The signal will be delivered once the
* signal is removed from the sigprocmask.
*
* NOTE: If sigwaitinfo() or sigtimedwait() are used to catch the signal
* then then TCP connection structure pointer may be recovered in the
* sival_ptr value of the struct siginfo instance.
* Set up to perform a callback to the worker function when an TCP data
* is added to the read-ahead buffer. The worker function will execute
* on the high priority worker thread.
*
* Input Parameters:
* pid - The PID to be notified. If a zero value is provided, then the
* PID of the calling thread will be used.
* signo - The signal number to use with the notification.
* worker - The worker function to execute on the high priority work
* queue when data is available in the TCP readahead buffer.
* conn - The TCP connection where read-ahead data is needed.
* arg - A user-defined argument that will be available to the worker
* function when it runs.
*
* Returned Value:
* > 0 - The signal notification is in place. The returned value is a
@@ -84,8 +80,13 @@
*
****************************************************************************/
int tcp_notifier_setup(int pid, int signo, FAR struct tcp_conn_s *conn)
int tcp_notifier_setup(worker_t worker, FAR struct tcp_conn_s *conn,
FAR void *arg)
{
struct work_notifier_s info;
DEBUGASSERT(worker != NULL);
/* If there is already buffered read-ahead data, then return zero without
* setting up the notification.
*/
@@ -95,9 +96,14 @@ int tcp_notifier_setup(int pid, int signo, FAR struct tcp_conn_s *conn)
return 0;
}
/* Otherwise, this is just a simple wrapper around nxsig_notifer_setup(). */
/* Otherwise, this is just a simple wrapper around work_notifer_setup(). */
return nxsig_notifier_setup(pid, signo, NXSIG_TCP_READAHEAD, conn);
info.evtype = WORK_TCP_READAHEAD;
info.qualifier = conn;
info.arg = arg;
info.worker = worker;
return work_notifier_setup(&info);
}
/****************************************************************************
@@ -121,9 +127,9 @@ int tcp_notifier_setup(int pid, int signo, FAR struct tcp_conn_s *conn)
int tcp_notifier_teardown(int key)
{
/* This is just a simple wrapper around nxsig_notifier_teardown(). */
/* This is just a simple wrapper around work_notifier_teardown(). */
return nxsig_notifier_teardown(key);
return work_notifier_teardown(key);
}
/****************************************************************************
@@ -133,14 +139,10 @@ int tcp_notifier_teardown(int key)
* Read-ahead data has been buffered. Signal all threads waiting for
* read-ahead data to become available.
*
* When the read-ahead data becomes available, *all* of the waiters in
* this thread will be signaled. If there are multiple waiters then only
* the highest priority thread will get the data. Lower priority threads
* will need to call tcp_notifier_setup() once again.
*
* NOTE: If sigwaitinfo() or sigtimedwait() are used to catch the signal
* then then TCP connection structure pointer may be obtained in the
* sival_ptr value of the struct siginfo instance.
* When read-ahead data becomes available, *all* of the workers waiting
* for read-ahead data will be executed. If there are multiple workers
* waiting for read-ahead data then only the first to execute will get the
* data. Others will need to call tcp_notifier_setup() once again.
*
* Input Parameters:
* conn - The TCP connection where read-ahead data was just buffered.
@@ -152,9 +154,9 @@ int tcp_notifier_teardown(int key)
void tcp_notifier_signal(FAR struct tcp_conn_s *conn)
{
/* This is just a simple wrapper around nxsig_notifier_signal(). */
/* This is just a simple wrapper around work_notifier_signal(). */
return nxsig_notifier_signal(NXSIG_TCP_READAHEAD, conn);
return work_notifier_signal(WORK_TCP_READAHEAD, conn);
}
#endif /* CONFIG_TCP_READAHEAD_NOTIFIER */
+6 -7
View File
@@ -60,14 +60,13 @@ config NET_UDP_READAHEAD
config UDP_READAHEAD_NOTIFIER
bool "Support UDP read-ahead notifications"
default n
select SIG_NOTIFIER
depends on NET_UDP_READAHEAD && !DISABLE_SIGNALS
depends on NET_UDP_READAHEAD && SCHED_HPWORK
---help---
Enable building of UDP read-ahead notifier logic that will send a
signal to a kernel thread when an UDP read-ahead data has been
buffered. This is is a general purpose notifier, but was developed
specifically to support UDP poll() logic where the poll must wait
for incoming UDP data to be buffered.
Enable building of UDP read-ahead notifier logic that will execute a
worker function on the high priority work queue when read-ahead data
is available. This is is a general purpose notifier, but was
developed specifically to support poll() logic where the poll must
wait for read-ahead data to become available.
config NET_UDP_WRITE_BUFFERS
bool "Enable UDP/IP write buffering"
+17 -21
View File
@@ -53,6 +53,10 @@
# include <nuttx/mm/iob.h>
#endif
#ifdef CONFIG_UDP_READAHEAD_NOTIFIER
# include <nuttx/wqueue.h>
#endif
#if defined(CONFIG_NET_UDP) && !defined(CONFIG_NET_UDP_NO_STACK)
/****************************************************************************
@@ -647,21 +651,16 @@ int udp_pollteardown(FAR struct socket *psock, FAR struct pollfd *fds);
* Name: udp_notifier_setup
*
* Description:
* Set up to notify the specified PID with the provided signal number.
*
* NOTE: To avoid race conditions, the caller should set the sigprocmask
* to block signal delivery. The signal will be delivered once the
* signal is removed from the sigprocmask.
*
* NOTE: If sigwaitinfo() or sigtimedwait() are used to catch the signal
* then then UDP connection structure pointer may be recovered in the
* sival_ptr value of the struct siginfo instance.
* Set up to perform a callback to the worker function when an UDP data
* is added to the read-ahead buffer. The worker function will execute
* on the high priority worker thread.
*
* Input Parameters:
* pid - The PID to be notified. If a zero value is provided, then the
* PID of the calling thread will be used.
* signo - The signal number to use with the notification.
* worker - The worker function to execute on the high priority work
* queue when data is available in the UDP readahead buffer.
* conn - The UDP connection where read-ahead data is needed.
* arg - A user-defined argument that will be available to the worker
* function when it runs.
*
* Returned Value:
* > 0 - The signal notification is in place. The returned value is a
@@ -676,7 +675,8 @@ int udp_pollteardown(FAR struct socket *psock, FAR struct pollfd *fds);
****************************************************************************/
#ifdef CONFIG_UDP_READAHEAD_NOTIFIER
int udp_notifier_setup(int pid, int signo, FAR struct udp_conn_s *conn);
int udp_notifier_setup(worker_t worker, FAR struct udp_conn_s *conn,
FAR void *arg);
#endif
/****************************************************************************
@@ -709,14 +709,10 @@ int udp_notifier_teardown(int key);
* Read-ahead data has been buffered. Signal all threads waiting for
* read-ahead data to become available.
*
* When the read-ahead data becomes available, *all* of the waiters in
* this thread will be signaled. If there are multiple waiters then only
* the highest priority thread will get the data. Lower priority threads
* will need to call udp_notifier_setup() once again.
*
* NOTE: If sigwaitinfo() or sigtimedwait() are used to catch the signal
* then then UDP connection structure pointer may be obtained in the
* sival_ptr value of the struct siginfo instance.
* When read-ahead data becomes available, *all* of the workers waiting
* for read-ahead data will be executed. If there are multiple workers
* waiting for read-ahead data then only the first to execute will get the
* data. Others will need to call udp_notifier_setup() once again.
*
* Input Parameters:
* conn - The UDP connection where read-ahead data was just buffered.
+30 -28
View File
@@ -40,8 +40,9 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <assert.h>
#include <nuttx/signal.h>
#include <nuttx/wqueue.h>
#include <nuttx/mm/iob.h>
#include "udp/udp.h"
@@ -56,21 +57,16 @@
* Name: udp_notifier_setup
*
* Description:
* Set up to notify the specified PID with the provided signal number.
*
* NOTE: To avoid race conditions, the caller should set the sigprocmask
* to block signal delivery. The signal will be delivered once the
* signal is removed from the sigprocmask.
*
* NOTE: If sigwaitinfo() or sigtimedwait() are used to catch the signal
* then then UDP connection structure pointer may be recovered in the
* sival_ptr value of the struct siginfo instance.
* Set up to perform a callback to the worker function when an UDP data
* is added to the read-ahead buffer. The worker function will execute
* on the high priority worker thread.
*
* Input Parameters:
* pid - The PID to be notified. If a zero value is provided, then the
* PID of the calling thread will be used.
* signo - The signal number to use with the notification.
* worker - The worker function to execute on the high priority work
* queue when data is available in the UDP readahead buffer.
* conn - The UDP connection where read-ahead data is needed.
* arg - A user-defined argument that will be available to the worker
* function when it runs.
*
* Returned Value:
* > 0 - The signal notification is in place. The returned value is a
@@ -84,8 +80,13 @@
*
****************************************************************************/
int udp_notifier_setup(int pid, int signo, FAR struct udp_conn_s *conn)
int udp_notifier_setup(worker_t worker, FAR struct udp_conn_s *conn,
FAR void *arg)
{
struct work_notifier_s info;
DEBUGASSERT(worker != NULL);
/* If there is already buffered read-ahead data, then return zero without
* setting up the notification.
*/
@@ -95,9 +96,14 @@ int udp_notifier_setup(int pid, int signo, FAR struct udp_conn_s *conn)
return 0;
}
/* Otherwise, this is just a simple wrapper around nxsig_notifer_setup(). */
/* Otherwise, this is just a simple wrapper around work_notifer_setup(). */
return nxsig_notifier_setup(pid, signo, NXSIG_UDP_READAHEAD, conn);
info.evtype = WORK_UDP_READAHEAD;
info.qualifier = conn;
info.arg = arg;
info.worker = worker;
return work_notifier_setup(&info);
}
/****************************************************************************
@@ -121,9 +127,9 @@ int udp_notifier_setup(int pid, int signo, FAR struct udp_conn_s *conn)
int udp_notifier_teardown(int key)
{
/* This is just a simple wrapper around nxsig_notifier_teardown(). */
/* This is just a simple wrapper around work_notifier_teardown(). */
return nxsig_notifier_teardown(key);
return work_notifier_teardown(key);
}
/****************************************************************************
@@ -133,14 +139,10 @@ int udp_notifier_teardown(int key)
* Read-ahead data has been buffered. Signal all threads waiting for
* read-ahead data to become available.
*
* When the read-ahead data becomes available, *all* of the waiters in
* this thread will be signaled. If there are multiple waiters then only
* the highest priority thread will get the data. Lower priority threads
* will need to call udp_notifier_setup() once again.
*
* NOTE: If sigwaitinfo() or sigtimedwait() are used to catch the signal
* then then UDP connection structure pointer may be obtained in the
* sival_ptr value of the struct siginfo instance.
* When read-ahead data becomes available, *all* of the workers waiting
* for read-ahead data will be executed. If there are multiple workers
* waiting for read-ahead data then only the first to execute will get the
* data. Others will need to call udp_notifier_setup() once again.
*
* Input Parameters:
* conn - The UDP connection where read-ahead data was just buffered.
@@ -152,9 +154,9 @@ int udp_notifier_teardown(int key)
void udp_notifier_signal(FAR struct udp_conn_s *conn)
{
/* This is just a simple wrapper around nxsig_notifier_signal(). */
/* This is just a simple wrapper around work_notifier_signal(). */
return nxsig_notifier_signal(NXSIG_UDP_READAHEAD, conn);
return work_notifier_signal(WORK_UDP_READAHEAD, conn);
}
#endif /* CONFIG_UDP_READAHEAD_NOTIFIER */