qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 3/9] event poll: make epoll work for normal fd


From: mdroth
Subject: Re: [Qemu-devel] [PATCH 3/9] event poll: make epoll work for normal fd
Date: Thu, 21 Feb 2013 14:19:31 -0600
User-agent: Mutt/1.5.21 (2010-09-15)

On Thu, Feb 21, 2013 at 08:54:47PM +0800, Liu Ping Fan wrote:
> From: Liu Ping Fan <address@hidden>
> 
> When event poll can work with normal fd, we can port them
> onto the event loop.
> 
> Signed-off-by: Liu Ping Fan <address@hidden>
> ---
>  hw/dataplane/event-poll.c |   36 ++++++++++++++++++++++++++++++++++++
>  hw/dataplane/event-poll.h |    8 ++++++++
>  2 files changed, 44 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/dataplane/event-poll.c b/hw/dataplane/event-poll.c
> index 2b55c6e..b7dea53 100644
> --- a/hw/dataplane/event-poll.c
> +++ b/hw/dataplane/event-poll.c
> @@ -32,6 +32,42 @@ void event_poll_add(EventPoll *poll, EventHandler *handler,
>      }
>  }
> 
> +void event_poll_add_fd(EventPoll *poll, int fd, uint32_t type,
> +    EventHandler *handler)
> +{
> +    struct epoll_event event = {
> +        .events = type,
> +        .data.ptr = handler,
> +    };
> +
> +    if (epoll_ctl(poll->epoll_fd, EPOLL_CTL_ADD, fd, &event) != 0) {
> +        fprintf(stderr, "failed to add event fd handler to epoll: %m\n");
> +        exit(1);
> +    }
> +
> +}

An alternative to adding these interfaces would be initializing an
EventNotifier using event_notifier_init_fd() and then passing that in to
event_poll_add()

I think doing it this way would be applicable on top of Paolo's
patches to switch dataplane to using AioContext as well.

> +void event_poll_del_fd(EventPoll *poll, int fd)
> +{
> +    if (epoll_ctl(poll->epoll_fd, EPOLL_CTL_DEL, fd, NULL) != 0) {
> +        fprintf(stderr, "failed to del event handler to epoll: %m\n");
> +        exit(1);
> +    }
> +}
> +
> +
> +void event_poll_modify_fd(EventPoll *poll, int fd, uint32_t type,
> +    EventHandler *handler)
> +{
> +    struct epoll_event event = {
> +        .events = type,
> +        .data.ptr = handler,
> +    };
> +    if (epoll_ctl(poll->epoll_fd, EPOLL_CTL_MOD, fd, &event) != 0) {
> +        fprintf(stderr, "failed to modify event handler to epoll: %m\n");
> +        exit(1);
> +    }
> +}
> +
>  /* Event callback for stopping event_poll() */
>  static void handle_stop(EventHandler *handler)
>  {
> diff --git a/hw/dataplane/event-poll.h b/hw/dataplane/event-poll.h
> index 3e8d3ec..606138c 100644
> --- a/hw/dataplane/event-poll.h
> +++ b/hw/dataplane/event-poll.h
> @@ -22,6 +22,8 @@ typedef void EventCallback(EventHandler *handler);
>  struct EventHandler {
>      EventNotifier *notifier;        /* eventfd */
>      EventCallback *callback;        /* callback function */
> +    void *opaque;
> +    int fd;                         /* normal fd*/
>  };
> 
>  typedef struct {
> @@ -32,6 +34,12 @@ typedef struct {
> 
>  void event_poll_add(EventPoll *poll, EventHandler *handler,
>                      EventNotifier *notifier, EventCallback *callback);
> +void event_poll_add_fd(EventPoll *poll, int fd, uint32_t type,
> +                    EventHandler *handler);
> +void event_poll_del_fd(EventPoll *poll, int fd);
> +void event_poll_modify_fd(EventPoll *poll, int fd, uint32_t type,
> +                    EventHandler *handler);
> +
>  void event_poll_init(EventPoll *poll);
>  void event_poll_cleanup(EventPoll *poll);
>  void event_poll(EventPoll *poll);
> -- 
> 1.7.4.4
> 
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]