Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6030130iog; Thu, 23 Jun 2022 09:54:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v7tKgYVqCbbVOmF2eZygK9nZmkGXIG1d+fJgUB00zCr8VOEf0TjeIdxfpA7LgqsxRfQK6D X-Received: by 2002:a05:6402:5206:b0:42e:1279:cc8b with SMTP id s6-20020a056402520600b0042e1279cc8bmr12100959edd.186.1656003276389; Thu, 23 Jun 2022 09:54:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656003276; cv=none; d=google.com; s=arc-20160816; b=nKKCr4/m1OlO5yeWYKSrx8CnNvBM2JYmQP47gUju0nvc7XpthBNbQZd8cDzSWX5PDH ClIhGB3P0vowdtohlVoptUYkJwcwTz9glXHjL2/CT6UMF9mxuTd29PO6VG5hOqrRsgri EbZcqj0R6vKlcEeiP76xUWWgrmhEqkTUTamQwoAngliw+zKpti9ALRTPxRi6d3RTMt7z NAcESimfY4eYzBIJ9UN5sTlLeJa/5cyrQQEWovBGZrFWt7GhQ5a+3vBzoHrTvGATxGqO NJrDSAbXi62+emOGJdH6YQYiZOcsT/Ot/CPNViq2QZBQlB18X9zcCSZUu2AWwapPOFJi fYYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Zh4ZacDRkCsfNEnX+4yCG5YKa8Zx47i4hZJ3exRE4M4=; b=qiabmBQcN6MfOneUwAYPpn5RJq/F2TQSRck5C3IWtVo5PjLaXLvjSsm5aQRgOzUTOn lpN9s6ZUqlJdJx2VkQDW8unKO0l/+iUE6t4tHJOCOEGtlQPCUURGbm5wxZFDqNCmYyTI DKW8iP4DZrHMYhPUHFw8PkwSZd9p+0qEpfSvi6ChOyIkvUIp7tfnYz5W5ozNpn/7EJ2x K/vqVCsWTAUZrGSwhtrJcvKCULVNY9l/9s8fEXbU4fsyN2HIdT81JuRo0OdC1Y2gYncI ddUqu+IachSJU9wxrcf7OUQJC16FAtsKb3oZ8YmrmxcQ9lg3emUtzAB2VdAZlFuLPTev svZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K5l73IYF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb5-20020a170907960500b006f3be13d016si10647712ejc.37.2022.06.23.09.54.07; Thu, 23 Jun 2022 09:54:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K5l73IYF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232380AbiFWQrT (ORCPT + 99 others); Thu, 23 Jun 2022 12:47:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232456AbiFWQqo (ORCPT ); Thu, 23 Jun 2022 12:46:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C168A49B75; Thu, 23 Jun 2022 09:46:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 22ED561F85; Thu, 23 Jun 2022 16:46:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A30AC3411B; Thu, 23 Jun 2022 16:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656002795; bh=Yv8CjKqydAz/Fpz5QLw4VQmmWsQMsONZHOvoeqnMo4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K5l73IYFCRb09bdatV14rHGYNzG6TB4mAMpCsUuAin5U+GcrbT0zIIWRVQ+shuc4W QQXrwwp4K7LBWP3VNFKlmunuqw8aVa5vtCPZSkgpj8xItIXHFILoIci1uPX8fu0gyD y0CMt2Tp66NVSlT3mXpXtySXg5+9V59N6jBc7RXk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andi Kleen , Theodore Tso , "Jason A. Donenfeld" Subject: [PATCH 4.9 028/264] random: optimize add_interrupt_randomness Date: Thu, 23 Jun 2022 18:40:21 +0200 Message-Id: <20220623164344.866224048@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen commit e8e8a2e47db6bb85bb0cb21e77b5c6aaedf864b4 upstream. add_interrupt_randomess always wakes up code blocking on /dev/random. This wake up is done unconditionally. Unfortunately this means all interrupts take the wait queue spinlock, which can be rather expensive on large systems processing lots of interrupts. We saw 1% cpu time spinning on this on a large macro workload running on a large system. I believe it's a recent regression (?) Always check if there is a waiter on the wait queue before waking up. This check can be done without taking a spinlock. 1.06% 10460 [kernel.vmlinux] [k] native_queued_spin_lock_slowpath | ---native_queued_spin_lock_slowpath | --0.57%--_raw_spin_lock_irqsave | --0.56%--__wake_up_common_lock credit_entropy_bits add_interrupt_randomness handle_irq_event_percpu handle_irq_event handle_edge_irq handle_irq do_IRQ common_interrupt Signed-off-by: Andi Kleen Signed-off-by: Theodore Ts'o Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -722,7 +722,8 @@ retry: } /* should we wake readers? */ - if (entropy_bits >= random_read_wakeup_bits) { + if (entropy_bits >= random_read_wakeup_bits && + wq_has_sleeper(&random_read_wait)) { wake_up_interruptible(&random_read_wait); kill_fasync(&fasync, SIGIO, POLL_IN); }