From patchwork Sun Mar 6 01:57:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 8512141 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A1A15C0553 for ; Sun, 6 Mar 2016 02:02:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 87E4A201EC for ; Sun, 6 Mar 2016 02:02:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 85FC62010C for ; Sun, 6 Mar 2016 02:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751082AbcCFCBo (ORCPT ); Sat, 5 Mar 2016 21:01:44 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:33647 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751031AbcCFCBm (ORCPT ); Sat, 5 Mar 2016 21:01:42 -0500 Received: by mail-pf0-f174.google.com with SMTP id 124so58623651pfg.0 for ; Sat, 05 Mar 2016 18:01:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=ZY/M2zK9SxghpRix15w+QfMP2DR+O1wg/KSGOrIhRAs=; b=X6idyoI0oAdT2lxAIB9rJCsg6Z5rYb/6VJwZQEp9gJRYjfV7fs0P3mUFFsVOVYrWyW 8bnIuMopuwc1JqxkkDQnNwQtr/AbYiQYPGRfvHx3VtbZb3O3GNUBMo5WSkl1jDTB7lIC sfb/G+LBPb3cy71sKbAFnOwC0G7t+fmoEksv60TmfXyRxFuYcC9rvb8DQLRV0jWIIGfg FKgJnuJAFdRkU3dsDa55jO8A1HDA1zoA6Tc7/XYUoEa2z3vTauxAisVXd2lEysmdqCX+ vK7hFsgtikLRR0shtACT5oIVfeAn1TDdwgOvEFUUyQdFH3nQgxK19EISQKDlihe4AU9Q N0Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ZY/M2zK9SxghpRix15w+QfMP2DR+O1wg/KSGOrIhRAs=; b=PUyworXlEU3Dc3knkJ3kkjqCPBrbKHSPqZFCrIi0DFPkd+jE9T9JLegbBRqr5GkrHt TjXa3HTi0E+bPYY2WHKAgGXo1PI1FSojJm1aqpvgLS8DvmBlx1n0drf95UPy+fagvUBd mDUFLujxTU1RTHwDXA8vpIjf9jQsJwKU12NfY0pLWSeJh0XVNEWtDEN+iupgV9cPQmKj sWepkqNDP9pJVsdIaFcq8cLaX3ot90XAkZUdQU/DGqv78ibSHeLm30A1U7li43oI2s7W ND1lucLy28bMM6TC5q1Ml7roS31V8neccHFyg8j6K1UYo1M+VsiHPp0cvGWbg2eLE+rT 5oUg== X-Gm-Message-State: AD7BkJJ1DFlXiwMqr5/+RePf9ULSYZfFE0YMEwNoInQz73K0ZS42N8aUjDLAS+oSMZswnA== X-Received: by 10.98.93.155 with SMTP id n27mr23368890pfj.88.1457229701767; Sat, 05 Mar 2016 18:01:41 -0800 (PST) Received: from localhost ([45.32.44.20]) by smtp.gmail.com with ESMTPSA id ux2sm14942830pac.46.2016.03.05.18.01.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Mar 2016 18:01:41 -0800 (PST) From: Wei Yang To: jan.kiszka@siemens.com, pbonzini@redhat.com Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org, Wei Yang Subject: [PATCH] kvm/irqchip: use bitmap utility for gsi tracking Date: Sun, 6 Mar 2016 01:57:25 +0000 Message-Id: <1457229445-25954-1-git-send-email-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.5.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP By using utilities in bitops and bitmap, this patch tries to make it more friendly to audience. No functional change. Signed-off-by: Wei Yang --- kvm-all.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index bd9e764..ed3f4a2 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -90,7 +90,7 @@ struct KVMState #ifdef KVM_CAP_IRQ_ROUTING struct kvm_irq_routing *irq_routes; int nr_allocated_irq_routes; - uint32_t *used_gsi_bitmap; + unsigned long *used_gsi_bitmap; unsigned int gsi_count; QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE]; #endif @@ -951,12 +951,12 @@ typedef struct KVMMSIRoute { static void set_gsi(KVMState *s, unsigned int gsi) { - s->used_gsi_bitmap[gsi / 32] |= 1U << (gsi % 32); + set_bit(gsi, s->used_gsi_bitmap); } static void clear_gsi(KVMState *s, unsigned int gsi) { - s->used_gsi_bitmap[gsi / 32] &= ~(1U << (gsi % 32)); + clear_bit(gsi, s->used_gsi_bitmap); } void kvm_init_irq_routing(KVMState *s) @@ -965,17 +965,9 @@ void kvm_init_irq_routing(KVMState *s) gsi_count = kvm_check_extension(s, KVM_CAP_IRQ_ROUTING) - 1; if (gsi_count > 0) { - unsigned int gsi_bits, i; - /* Round up so we can search ints using ffs */ - gsi_bits = ALIGN(gsi_count, 32); - s->used_gsi_bitmap = g_malloc0(gsi_bits / 8); + s->used_gsi_bitmap = bitmap_new(gsi_count); s->gsi_count = gsi_count; - - /* Mark any over-allocated bits as already in use */ - for (i = gsi_count; i < gsi_bits; i++) { - set_gsi(s, i); - } } s->irq_routes = g_malloc0(sizeof(*s->irq_routes)); @@ -1105,9 +1097,7 @@ static void kvm_flush_dynamic_msi_routes(KVMState *s) static int kvm_irqchip_get_virq(KVMState *s) { - uint32_t *word = s->used_gsi_bitmap; - int max_words = ALIGN(s->gsi_count, 32) / 32; - int i, zeroes; + int next_virq; /* * PIC and IOAPIC share the first 16 GSI numbers, thus the available @@ -1120,16 +1110,12 @@ static int kvm_irqchip_get_virq(KVMState *s) } /* Return the lowest unused GSI in the bitmap */ - for (i = 0; i < max_words; i++) { - zeroes = ctz32(~word[i]); - if (zeroes == 32) { - continue; - } - - return zeroes + i * 32; + next_virq = find_first_zero_bit(s->used_gsi_bitmap, s->gsi_count); + if (next_virq >= s->gsi_count) { + return -ENOSPC; + } else { + return next_virq; } - return -ENOSPC; - } static KVMMSIRoute *kvm_lookup_msi_route(KVMState *s, MSIMessage msg)