From patchwork Fri Dec 8 18:46:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Steffen X-Patchwork-Id: 10103169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6BFD7602A0 for ; Fri, 8 Dec 2017 18:54:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C5A228697 for ; Fri, 8 Dec 2017 18:54:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 513DF28E40; Fri, 8 Dec 2017 18:54:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D021428697 for ; Fri, 8 Dec 2017 18:54:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752522AbdLHSy2 (ORCPT ); Fri, 8 Dec 2017 13:54:28 -0500 Received: from smtp2.infineon.com ([217.10.52.18]:50613 "EHLO smtp2.infineon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752003AbdLHSy2 (ORCPT ); Fri, 8 Dec 2017 13:54:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infineon.com; i=@infineon.com; q=dns/txt; s=IFXMAIL; t=1512759267; x=1544295267; h=from:to:subject:date:message-id:in-reply-to:references: mime-version; bh=Cy5UUpjIveIraBf+VBAPci8W4Kim7KtW4vLNSUToSE4=; b=OVBLzpPlb44BLEGBku4f75HsScu6QnF2Rc6p1hi36G0sO1hCciYGQG2R Sy/glbjvwSwZPEnegaVouOd/aC/5/kimibI81Yviw8atCbLFC12/b/a8s gyMVjVWCzO2R9twp2l7QoUVrmMQNmqASWLs0ZOwU7jjhOWa4z0gApxO4W A=; X-SBRS: None Received: from unknown (HELO mucxv001.muc.infineon.com) ([172.23.11.16]) by smtp2.infineon.com with ESMTP/TLS/AES256-GCM-SHA384; 08 Dec 2017 19:54:26 +0100 Received: from MUCSE708.infineon.com (mucse708.infineon.com [172.23.7.82]) by mucxv001.muc.infineon.com (Postfix) with ESMTPS; Fri, 8 Dec 2017 19:54:26 +0100 (CET) Received: from ABGN5CG4522MQD.eu.infineon.com (172.23.8.247) by MUCSE708.infineon.com (172.23.7.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.669.32; Fri, 8 Dec 2017 19:54:26 +0100 From: Alexander Steffen To: , , , Subject: [RFC][PATCH 9/9] tpm: ignore burstcount to improve tpm_tis send() performance Date: Fri, 8 Dec 2017 19:46:58 +0100 Message-ID: <20171208184658.9588-10-Alexander.Steffen@infineon.com> X-Mailer: git-send-email 2.11.1.windows.1 In-Reply-To: <20171208184658.9588-1-Alexander.Steffen@infineon.com> References: <20171208184658.9588-1-Alexander.Steffen@infineon.com> MIME-Version: 1.0 X-Originating-IP: [172.23.8.247] X-ClientProxiedBy: MUCSE706.infineon.com (172.23.7.80) To MUCSE708.infineon.com (172.23.7.82) Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Nayna Jain The TPM burstcount status indicates the number of bytes that can be sent to the TPM without causing bus wait states. Effectively, it is the number of empty bytes in the command FIFO. This patch optimizes the tpm_tis_send_data() function by checking the burstcount only once. And if the burstcount is valid, it writes all the bytes at once, permitting wait state. After this change, performance on a TPM 1.2 with an 8 byte burstcount for 1000 extends improved from ~41sec to ~14sec. Suggested-by: Ken Goldman in conjunction with the TPM Device Driver work group. Signed-off-by: Nayna Jain Acked-by: Mimi Zohar Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 7240ee4..7979b06 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -320,7 +320,6 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int rc, status, burstcnt; - size_t count = 0; status = tpm_tis_status(chip); if ((status & TPM_STS_COMMAND_READY) == 0) { @@ -333,23 +332,23 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) } } - while (count < len) { - burstcnt = get_burstcount(chip); - if (burstcnt < 0) { - dev_err(&chip->dev, "Unable to read burstcount\n"); - rc = burstcnt; - goto out_err; - } - burstcnt = min_t(int, burstcnt, len - count); - rc = tpm_tis_write_bytes(priv, ADD_LOCALITY(priv->fifo_address, - priv->locality), - burstcnt, buf + count); - if (rc < 0) - goto out_err; - - count += burstcnt; + /* + * Get the initial burstcount to ensure TPM is ready to + * accept data. + */ + burstcnt = get_burstcount(chip); + if (burstcnt < 0) { + dev_err(&chip->dev, "Unable to read burstcount\n"); + rc = burstcnt; + goto out_err; } + rc = tpm_tis_write_bytes(priv, ADD_LOCALITY(priv->fifo_address, + priv->locality), + len, buf); + if (rc < 0) + goto out_err; + if (!(priv->flags & TPM_TIS_ITPM_WORKAROUND) && wait_for_tpm_stat(chip, TPM_STS_DATA_EXPECT | TPM_STS_VALID, TPM_STS_VALID, chip->timeout_c, &priv->int_queue,