DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
To: Jakub Grajciar <jgrajcia@cisco.com>, dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH v2] eal_interrupts: add option for pending callback unregister
Date: Fri, 7 Dec 2018 14:47:23 +0000	[thread overview]
Message-ID: <327df61b-0ce5-492b-87b9-28fcdc035ec3@intel.com> (raw)
In-Reply-To: <20181207114048.2324-1-jgrajcia@cisco.com>

On 07-Dec-18 11:40 AM, Jakub Grajciar wrote:
> use case: if callback is used to receive message form socket,
> and the message received is disconnect/error, this callback needs
> to be unregistered, but cannot because it is still active.
> 
> With this patch it is possible to mark the callback to be
> unregistered once the interrupt process is done with this
> interrupt source.
> 
> Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
> ---
>   .../common/include/rte_interrupts.h           | 30 +++++++
>   lib/librte_eal/linuxapp/eal/eal_interrupts.c  | 83 ++++++++++++++++++-
>   2 files changed, 111 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/librte_eal/common/include/rte_interrupts.h b/lib/librte_eal/common/include/rte_interrupts.h
> index d751a6378..3946742ad 100644
> --- a/lib/librte_eal/common/include/rte_interrupts.h
> +++ b/lib/librte_eal/common/include/rte_interrupts.h
> @@ -24,6 +24,13 @@ struct rte_intr_handle;
>   /** Function to be registered for the specific interrupt */
>   typedef void (*rte_intr_callback_fn)(void *cb_arg);
>   
> +/**
> + * Function to call after a callback is unregistered.
> + * Can be used to close fd and free cb_arg.
> + */
> +typedef void (*rte_intr_unregister_callback_fn)(struct rte_intr_handle *intr_handle,
> +						void *cb_arg);
> +
>   #include "rte_eal_interrupts.h"
>   
>   /**
> @@ -61,6 +68,29 @@ int rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
>   int rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle,
>   				rte_intr_callback_fn cb, void *cb_arg);
>   
> +/**
> + * It unregisters the callback according to the specified interrupt handle,
> + * after it's no longer acive. Failes if source is not active.
> + *
> + * @param intr_handle
> + *  pointer to the interrupt handle.
> + * @param cb
> + *  callback address.
> + * @param cb_arg
> + *  address of parameter for callback, (void *)-1 means to remove all
> + *  registered which has the same callback address.
> + * @param ucb_fn
> + *  callback to call before cb is unregistered (optional).
> + *  can be used to close fd and free cb_arg.
> + *
> + * @return
> + *  - On success, return the number of callback entities marked for remove.
> + *  - On failure, a negative value.
> + */
> +int rte_intr_callback_unregister_pending(const struct rte_intr_handle *intr_handle,
> +				rte_intr_callback_fn cb_fn, void *cb_arg,
> +				rte_intr_unregister_callback_fn ucb_fn);
> +
>   /**
>    * It enables the interrupt for the specified handle.
>    *
> diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
> index cbac451e1..144ac4c22 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
> @@ -76,6 +76,8 @@ struct rte_intr_callback {
>   	TAILQ_ENTRY(rte_intr_callback) next;
>   	rte_intr_callback_fn cb_fn;  /**< callback address */
>   	void *cb_arg;                /**< parameter for callback */
> +	uint8_t pending_delete;      /**< delete after callback is called */
> +	rte_intr_unregister_callback_fn ucb_fn; /**< fn to call before cb is deleted */
>   };
>   
>   struct rte_intr_source {
> @@ -472,6 +474,8 @@ rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
>   	}
>   	callback->cb_fn = cb;
>   	callback->cb_arg = cb_arg;
> +	callback->pending_delete = 0;
> +	callback->ucb_fn = NULL;
>   
>   	rte_spinlock_lock(&intr_lock);
>   
> @@ -518,6 +522,57 @@ rte_intr_callback_register(const struct rte_intr_handle *intr_handle,
>   	return ret;
>   }
>   
> +int
> +rte_intr_callback_unregister_pending(const struct rte_intr_handle *intr_handle,
> +				rte_intr_callback_fn cb_fn, void *cb_arg,
> +				rte_intr_unregister_callback_fn ucb_fn)
> +{
> +	int ret;
> +	struct rte_intr_source *src;
> +	struct rte_intr_callback *cb, *next;
> +
> +	/* do parameter checking first */
> +	if (intr_handle == NULL || intr_handle->fd < 0) {
> +		RTE_LOG(ERR, EAL,
> +		"Unregistering with invalid input parameter\n");
> +		return -EINVAL;
> +	}
> +
> +	rte_spinlock_lock(&intr_lock);
> +
> +	/* check if the insterrupt source for the fd is existent */
> +	TAILQ_FOREACH(src, &intr_sources, next)
> +		if (src->intr_handle.fd == intr_handle->fd)
> +			break;
> +
> +	/* No interrupt source registered for the fd */
> +	if (src == NULL) {
> +		ret = -ENOENT;
> +
> +	/* only usable if the source is active */
> +	} else if (src->active == 0) {
> +		return -EAGAIN;

Forgot unlock?

> +
> +	} else {
> +		ret = 0;
> +
> +		/* walk through the callbacks and mark all that match. */
> +		for (cb = TAILQ_FIRST(&src->callbacks); cb != NULL; cb = next) {
> +			next = TAILQ_NEXT(cb, next);
> +			if (cb->cb_fn == cb_fn && (cb_arg == (void *)-1 ||
> +					cb->cb_arg == cb_arg)) {
> +				cb->pending_delete = 1;
> +				cb->ucb_fn = ucb_fn;
> +				ret++;
> +			}
> +		}
> +	}
> +
> +	rte_spinlock_unlock(&intr_lock);
> +
> +	return ret;
> +}
> +
>   int
>   rte_intr_callback_unregister(const struct rte_intr_handle *intr_handle,
>   			rte_intr_callback_fn cb_fn, void *cb_arg)
> @@ -698,7 +753,7 @@ static int
>   eal_intr_process_interrupts(struct epoll_event *events, int nfds)
>   {
>   	bool call = false;
> -	int n, bytes_read;
> +	int n, bytes_read, rv;
>   	struct rte_intr_source *src;
>   	struct rte_intr_callback *cb, *next;
>   	union rte_intr_read_buffer buf;
> @@ -823,9 +878,33 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
>   				rte_spinlock_lock(&intr_lock);
>   			}
>   		}
> -
>   		/* we done with that interrupt source, release it. */
>   		src->active = 0;
> +
> +		rv = 0;
> +
> +		/* check if any callback are supposed to be removed */
> +		for (cb = TAILQ_FIRST(&src->callbacks); cb != NULL; cb = next) {
> +			next = TAILQ_NEXT(cb, next);
> +			if (cb->pending_delete) {
> +				TAILQ_REMOVE(&src->callbacks, cb, next);
> +				if (cb->ucb_fn)
> +					cb->ucb_fn(&src->intr_handle, cb->cb_arg);
> +				free(cb);
> +				rv++;
> +			}
> +		}
> +
> +		/* all callbacks for that source are removed. */
> +		if (TAILQ_EMPTY(&src->callbacks)) {
> +			TAILQ_REMOVE(&intr_sources, src, next);
> +			free(src);
> +		}
> +
> +		/* notify the pipe fd waited by epoll_wait to rebuild the wait list */
> +		if (rv >= 0 && write(intr_pipe.writefd, "1", 1) < 0)
> +			return -EPIPE;

Forgot unlock?

> +
>   		rte_spinlock_unlock(&intr_lock);
>   	}
>   
> 


-- 
Thanks,
Anatoly

      reply	other threads:[~2018-12-07 14:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-07 11:40 Jakub Grajciar
2018-12-07 14:47 ` Burakov, Anatoly [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=327df61b-0ce5-492b-87b9-28fcdc035ec3@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=jgrajcia@cisco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).