From patchwork Thu Mar 3 17:29:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 8495061 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@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 AECAEC0554 for ; Thu, 3 Mar 2016 17:29:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EFE5D20268 for ; Thu, 3 Mar 2016 17:29:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1C66020382 for ; Thu, 3 Mar 2016 17:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754510AbcCCR3I (ORCPT ); Thu, 3 Mar 2016 12:29:08 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:54757 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751923AbcCCR3F (ORCPT ); Thu, 3 Mar 2016 12:29:05 -0500 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 4B88260DED; Thu, 3 Mar 2016 17:29:04 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 3AC9D60DCA; Thu, 3 Mar 2016 17:29:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from [10.228.68.148] (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: okaya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 965D260608; Thu, 3 Mar 2016 17:29:02 +0000 (UTC) Subject: Re: [PATCH V2] acpi, pci, irq: account for early penalty assignment To: Bjorn Helgaas References: <1455801582-21595-1-git-send-email-okaya@codeaurora.org> <20160229192420.GC3653@localhost> <56D4A53A.1070708@codeaurora.org> <20160229223453.GA12162@localhost> <56D5E43E.7050406@codeaurora.org> <20160301194340.GA19783@localhost> <56D7317F.7090500@codeaurora.org> <56D7ABFB.3070302@codeaurora.org> <56D84EA9.3080900@codeaurora.org> <20160303151048.GA3290@localhost> <56D8546B.5040908@codeaurora.org> Cc: linux-acpi@vger.kernel.org, timur@codeaurora.org, cov@codeaurora.org, linux-pci@vger.kernel.org, ravikanth.nalla@hpe.com, lenb@kernel.org, harish.k@hpe.com, ashwin.reghunandanan@hpe.com, bhelgaas@google.com, rjw@rjwysocki.net, linux-kernel@vger.kernel.org From: Sinan Kaya Message-ID: <56D8745D.70509@codeaurora.org> Date: Thu, 3 Mar 2016 12:29:01 -0500 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <56D8546B.5040908@codeaurora.org> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 3/3/2016 10:12 AM, Sinan Kaya wrote: > On 3/3/2016 10:10 AM, Bjorn Helgaas wrote: >> That was my idea, but your minimal patch from last night looks awfully >> attractive, and maybe it's not worth moving it to arch/x86. I do think we >> could simplify the code significantly by getting rid of the kzalloc and >> acpi_irq_penalty_list from acpi_irq_set_penalty(). How about pushing on >> that a little bit first, and see what it looks like then? > > OK. Let me go that direction. > How about this? diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c index fa28635..09eea42 100644 --- a/drivers/acpi/pci_link.c +++ b/drivers/acpi/pci_link.c @@ -87,6 +87,7 @@ struct acpi_pci_link { static LIST_HEAD(acpi_link_list); static DEFINE_MUTEX(acpi_link_lock); +static int sci_irq, sci_irq_penalty; /* -------------------------------------------------------------------------- PCI Link Device Management @@ -466,56 +467,71 @@ static int acpi_irq_isa_penalty[ACPI_MAX_ISA_IRQ] = { PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */ }; -struct irq_penalty_info { - int irq; - int penalty; - struct list_head node; -}; +static int acpi_irq_pci_sharing_penalty(int irq) +{ + struct acpi_pci_link *link; + int penalty = 0; + bool found = false; + + list_for_each_entry(link, &acpi_link_list, list) { + /* + * If a link is active, penalize its IRQ heavily + * so we try to choose a different IRQ. + */ + if (link->irq.active && link->irq.active == irq) { + penalty += PIRQ_PENALTY_PCI_USING; + found = true; + } else { + int i; + + /* + * If a link is inactive, penalize the IRQs it + * might, but not as severely. + */ + for (i = 0; i < link->irq.possible_count; i++) { + if (link->irq.possible[i] == irq) { + penalty += PIRQ_PENALTY_PCI_POSSIBLE / + link->irq.possible_count; + found = true; + } + } + } + } -static LIST_HEAD(acpi_irq_penalty_list); + if (found) + return penalty; + + return PIRQ_PENALTY_PCI_AVAILABLE; +} static int acpi_irq_get_penalty(int irq) { - struct irq_penalty_info *irq_info; - if (irq < ACPI_MAX_ISA_IRQ) return acpi_irq_isa_penalty[irq]; - list_for_each_entry(irq_info, &acpi_irq_penalty_list, node) { - if (irq_info->irq == irq) - return irq_info->penalty; - } + if (irq == sci_irq) + return sci_irq_penalty; - return 0; + return acpi_irq_pci_sharing_penalty(irq); } static int acpi_irq_set_penalty(int irq, int new_penalty) { - struct irq_penalty_info *irq_info; - /* see if this is a ISA IRQ */ if (irq < ACPI_MAX_ISA_IRQ) { acpi_irq_isa_penalty[irq] = new_penalty; return 0; } - /* next, try to locate from the dynamic list */ - list_for_each_entry(irq_info, &acpi_irq_penalty_list, node) { - if (irq_info->irq == irq) { - irq_info->penalty = new_penalty; - return 0; - } + if (irq == sci_irq) { + sci_irq_penalty = new_penalty; + return 0; } - /* nope, let's allocate a slot for this IRQ */ - irq_info = kzalloc(sizeof(*irq_info), GFP_KERNEL); - if (!irq_info) - return -ENOMEM; - - irq_info->irq = irq; - irq_info->penalty = new_penalty; - list_add_tail(&irq_info->node, &acpi_irq_penalty_list); - + /* + * This is the remaining PCI IRQs. They are calculated on the + * flight in acpi_irq_get_penalty function. + */ return 0; } @@ -900,6 +916,7 @@ void acpi_penalize_sci_irq(int irq, int trigger, int polarity) if (irq < 0) return; + sci_irq = irq; if (trigger != ACPI_MADT_TRIGGER_LEVEL || polarity != ACPI_MADT_POLARITY_ACTIVE_LOW) penalty = PIRQ_PENALTY_ISA_ALWAYS;