kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matt Evans <matt@ozlabs.org>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: penberg@kernel.org, mingo@elte.hu, gorcunov@gmail.com,
	asias.hejun@gmail.com, kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD
Date: Thu, 15 Dec 2011 11:52:38 +1100	[thread overview]
Message-ID: <4EE944D6.8020105@ozlabs.org> (raw)
In-Reply-To: <1323844646-14156-2-git-send-email-levinsasha928@gmail.com>

On 14/12/11 17:37, Sasha Levin wrote:
> Check KVM_CAP_IOEVENTFD before using ioeventfds.
> 
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>

A much nicer solution than my "[PATCH V2 2/2] kvm tools: Make virtio-pci's
ioeventfd__add_event() fall back gracefully if ioeventfds unavailable".

 matt.nastyhacks--;

Acked-by: Matt Evans <matt@ozlabs.org>

> ---
>  tools/kvm/builtin-run.c           |    2 +-
>  tools/kvm/include/kvm/ioeventfd.h |    2 +-
>  tools/kvm/ioeventfd.c             |   16 +++++++++++++++-
>  3 files changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
> index 76f1a8c..47e4ea8 100644
> --- a/tools/kvm/builtin-run.c
> +++ b/tools/kvm/builtin-run.c
> @@ -932,7 +932,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
>  
>  	kvm->single_step = single_step;
>  
> -	ioeventfd__init();
> +	ioeventfd__init(kvm);
>  
>  	max_cpus = kvm__max_cpus(kvm);
>  	recommended_cpus = kvm__recommended_cpus(kvm);
> diff --git a/tools/kvm/include/kvm/ioeventfd.h b/tools/kvm/include/kvm/ioeventfd.h
> index df01750..3a95788 100644
> --- a/tools/kvm/include/kvm/ioeventfd.h
> +++ b/tools/kvm/include/kvm/ioeventfd.h
> @@ -19,7 +19,7 @@ struct ioevent {
>  	struct list_head	list;
>  };
>  
> -void ioeventfd__init(void);
> +void ioeventfd__init(struct kvm *kvm);
>  void ioeventfd__start(void);
>  void ioeventfd__add_event(struct ioevent *ioevent);
>  void ioeventfd__del_event(u64 addr, u64 datamatch);
> diff --git a/tools/kvm/ioeventfd.c b/tools/kvm/ioeventfd.c
> index 3a240e4..75dd3f2 100644
> --- a/tools/kvm/ioeventfd.c
> +++ b/tools/kvm/ioeventfd.c
> @@ -18,9 +18,14 @@
>  static struct	epoll_event events[IOEVENTFD_MAX_EVENTS];
>  static int	epoll_fd;
>  static LIST_HEAD(used_ioevents);
> +static bool	ioeventfd_avail;
>  
> -void ioeventfd__init(void)
> +void ioeventfd__init(struct kvm *kvm)
>  {
> +	ioeventfd_avail = kvm__has_cap(kvm, KVM_CAP_IOEVENTFD);
> +	if (!ioeventfd_avail)
> +		return;
> +
>  	epoll_fd = epoll_create(IOEVENTFD_MAX_EVENTS);
>  	if (epoll_fd < 0)
>  		die("Failed creating epoll fd");
> @@ -33,6 +38,9 @@ void ioeventfd__add_event(struct ioevent *ioevent)
>  	struct ioevent *new_ioevent;
>  	int event;
>  
> +	if (!ioeventfd_avail)
> +		return;
> +
>  	new_ioevent = malloc(sizeof(*new_ioevent));
>  	if (new_ioevent == NULL)
>  		die("Failed allocating memory for new ioevent");
> @@ -68,6 +76,9 @@ void ioeventfd__del_event(u64 addr, u64 datamatch)
>  	struct ioevent *ioevent;
>  	u8 found = 0;
>  
> +	if (!ioeventfd_avail)
> +		return;
> +
>  	list_for_each_entry(ioevent, &used_ioevents, list) {
>  		if (ioevent->io_addr == addr) {
>  			found = 1;
> @@ -123,6 +134,9 @@ void ioeventfd__start(void)
>  {
>  	pthread_t thread;
>  
> +	if (!ioeventfd_avail)
> +		return;
> +
>  	if (pthread_create(&thread, NULL, ioeventfd__thread, NULL) != 0)
>  		die("Failed starting ioeventfd thread");
>  }


  reply	other threads:[~2011-12-15  0:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-14  6:37 [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host Sasha Levin
2011-12-14  6:37 ` [PATCH 2/2] kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD Sasha Levin
2011-12-15  0:52   ` Matt Evans [this message]
2011-12-15  4:25 ` [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host Matt Evans

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=4EE944D6.8020105@ozlabs.org \
    --to=matt@ozlabs.org \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    /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).