From patchwork Tue Apr 1 22:44:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 3925941 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 52A6ABF540 for ; Tue, 1 Apr 2014 22:47:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3153A2024D for ; Tue, 1 Apr 2014 22:47:10 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 36F7F20240 for ; Tue, 1 Apr 2014 22:47:09 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WV7SH-0007ZD-Sq; Tue, 01 Apr 2014 22:46:54 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WV7SF-0007vw-Fb; Tue, 01 Apr 2014 22:46:51 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WV7SC-0007vb-HY for linux-arm-kernel@lists.infradead.org; Tue, 01 Apr 2014 22:46:49 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s31MkJ8O030465; Tue, 1 Apr 2014 17:46:19 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s31MkJ08002356; Tue, 1 Apr 2014 17:46:19 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Tue, 1 Apr 2014 17:46:18 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s31MkI1S005570; Tue, 1 Apr 2014 17:46:18 -0500 From: Felipe Balbi To: , Subject: [PATCH] irq: crossbar: improve allocate_free_irq() complexity Date: Tue, 1 Apr 2014 17:44:19 -0500 Message-ID: <1396392259-27437-1-git-send-email-balbi@ti.com> X-Mailer: git-send-email 1.9.1.286.g5172cb3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140401_184648_658626_11AA22FB X-CRM114-Status: GOOD ( 14.28 ) X-Spam-Score: -7.5 (-------) Cc: Linux Kernel Mailing List , Felipe Balbi , Darren Etheridge , santosh.shilimkar@ti.com, galak@codeaurora.org, Linux OMAP Mailing List , Linux ARM Kernel Mailing List X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 current algorithm in allocate_free_irq() is O(n), by just keeping track of last allocated IRQ with a simple unsigned integer, we can find a free IRQ in O(1). Signed-off-by: Felipe Balbi --- compile-tested only as J6 DTS is currently missing crossbar altogether :-( There's a drawback with this patch which I'm not sure if we should care a lot because I couldn't entirely grasp when is domain->xlate() called and if we will map/unmap IRQs in runtime or will this *always* be done only during boot. If we're talking about runtime IRQ remapping, then this, clearly, won't work. But if this will be done only during boot up, then we avoid iterating over the irq_map array each time we try to translate a new IRQ prior to mapping it. Comments are highly welcome as I'll probably learn something new about the IRQ subsystem ;-) drivers/irqchip/irq-crossbar.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/irqchip/irq-crossbar.c b/drivers/irqchip/irq-crossbar.c index fc817d2..1c4da5a 100644 --- a/drivers/irqchip/irq-crossbar.c +++ b/drivers/irqchip/irq-crossbar.c @@ -31,6 +31,7 @@ struct crossbar_device { void __iomem *crossbar_base; int *register_offsets; void (*write) (int, int); + unsigned int current_irq; }; static struct crossbar_device *cb; @@ -52,16 +53,15 @@ static inline void crossbar_writeb(int irq_no, int cb_no) static inline int allocate_free_irq(int cb_no) { - int i; + int current_irq; - for (i = 0; i < cb->int_max; i++) { - if (cb->irq_map[i] == IRQ_FREE) { - cb->irq_map[i] = cb_no; - return i; - } - } + if (cb->current_irq == cb->int_max) + return -ENODEV; + + current_irq = cb->current_irq++; + cb->irq_map[current_irq++] = cb_no; - return -ENODEV; + return current_irq; } static int crossbar_domain_map(struct irq_domain *d, unsigned int irq,