From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH stub] kvm: caching API for interrupts Date: Mon, 30 Jul 2012 08:57:54 +0200 Message-ID: <50163072.6010106@redhat.com> References: <20120729200058.GA13557@redhat.com> <50159721.4000909@redhat.com> <20120729202922.GA13772@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: avi@redhat.com, kvm@vger.kernel.org To: "Michael S. Tsirkin" Return-path: Received: from mail-we0-f174.google.com ([74.125.82.174]:47678 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753801Ab2G3G56 (ORCPT ); Mon, 30 Jul 2012 02:57:58 -0400 Received: by weyx8 with SMTP id x8so3390900wey.19 for ; Sun, 29 Jul 2012 23:57:57 -0700 (PDT) In-Reply-To: <20120729202922.GA13772@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Il 29/07/2012 22:29, Michael S. Tsirkin ha scritto: > On Sun, Jul 29, 2012 at 10:03:45PM +0200, Paolo Bonzini wrote: >> Il 29/07/2012 22:00, Michael S. Tsirkin ha scritto: >>> I've been looking at adding caching for IRQs so that we don't need to >>> scan all VCPUs on each interrupt. One issue I had a problem with, is >>> how the cache structure can be used from both a thread (to fill out the >>> cache) and interrupt (to actually send if cache is valid). >>> >>> For now just added a lock field in the cache so we don't need to worry >>> about this, and with such a lock in place we don't have to worry about >>> RCU as cache can be invalidated simply under this lock. >> >> seqlock? > > AFAIK seqlock only works if uses of stale data have no side-effects, > this is not the case here. We could use an rwlock I think. If you can inject an interrupt using stale data (I think so, that would be a race in the guest between setting the route and getting the interrupt) you can use seqlock to get a consistent copy of the entry: struct kvm_irq_cache ent, *list; rcu_read_lock(); ... do { seq = read_seqcount_begin(&list->cnt); ent = *list; } while (!read_seqcount_retry(&list->cnt, seq)); rcu_read_unlock(); Paolo