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 */