From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [PATCH] IO: Intelligent device lookup on bus Date: Wed, 20 Jul 2011 16:41:49 -0300 Message-ID: <20110720194149.GA21379@amt.cnet> References: <1311163918-14334-1-git-send-email-levinsasha928@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, Avi Kivity To: Sasha Levin Return-path: Received: from mx1.redhat.com ([209.132.183.28]:17243 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752460Ab1GTTl7 (ORCPT ); Wed, 20 Jul 2011 15:41:59 -0400 Content-Disposition: inline In-Reply-To: <1311163918-14334-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Jul 20, 2011 at 03:11:58PM +0300, Sasha Levin wrote: > Currently the method of dealing with an IO operation on a bus (PIO/MMIO) > is to call the read or write callback for each device registered > on the bus until we find a device which handles it. > > Since the number of devices on a bus can be significant due to ioeventfds > and coalesced MMIO zones, this leads to a lot of overhead on each IO > operation. > > Instead of registering devices, we now register ranges which points to > a device. Lookup is done using an efficient bsearch instead of a linear > search. > > This should speed up all IO operations generated by the guest. Some numbers, please. > +int kvm_io_bus_find_closest_dev_idx(struct kvm_io_bus *bus, > + gpa_t addr, int len) > +{ > + int start = 0, end = bus->dev_count - 1; > + > + if (bus->dev_count == 0) > + return -1; > + > + while (start <= end) { > + int mid = (start + end) / 2; > + struct kvm_io_range *range = &bus->range[mid]; > + > + if (addr > range->addr) > + start = mid + 1; > + else if (addr < range->addr) > + end = mid - 1; If mid is zero, this assigns end = -1?