Re: [PATCH 2/2] kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD

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

 



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

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@xxxxxxxxxx>

> ---
>  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");
>  }

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux