From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::22f; helo=mail-wr0-x22f.google.com; envelope-from=julien.grall@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x22f.google.com (mail-wr0-x22f.google.com [IPv6:2a00:1450:400c:c0c::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4264B20355234 for ; Wed, 8 Nov 2017 06:31:35 -0800 (PST) Received: by mail-wr0-x22f.google.com with SMTP id o88so2605929wrb.6 for ; Wed, 08 Nov 2017 06:35:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=fSYGzpydW+RF2cs3kO2rG0LghH1EwLL96Nu+w1sxzp0=; b=Muvb3SD9K/hNQklXWsj0AbUixnTh634FoxcuNgECX7urxA/FzLHh8akoTsPvPjX1G+ 9FA2fq5RgBBJaBKsXrd4x249OgqHBwCE+ks/0+EPqoUwJ7kKCDNa/fYf2hEdIMaASvq1 o3kUe3oDwJ7qmtzGqbPaBrsWdHzHRxpb7pr+M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=fSYGzpydW+RF2cs3kO2rG0LghH1EwLL96Nu+w1sxzp0=; b=DVGRyYjUw99KXtQyu0nXvUtMSnbBlaiK5H1cVg9OWNLOFtaHsRcgfMFIHzyGVHfXkY jTM4OG29GFJj5hichUrjPehcPcJt0xPsHP0Nqz2vUNAD1Frw69+7QhCsulsFTEiUvn4i oOJ+Q+THC+GqJYdAiXLdEEoLDmfSKcJi04OTPeukiA2+izcfreWRQgzBwxJ1raf1O0dz 7cvJ9ZCnZiQAiOXOFGYvdse1G2icHnukzhKanVudNjTBefLZ4Sn2ceVTRGCVt0UZdQOg MhfJDdQmfLwtQXnCp03rMFkAHlcDJt19eJFpnNqLAGF65uT+x3RBFfnKXoUg9ampD9g/ DAWg== X-Gm-Message-State: AJaThX4PSkBX1rTR+xfPUJ0iThCX4Y7xjcYrEOb1hBdOs3CaSIN0j4zR awZCgZDqMiBgvMtP2iGDhrk+Tg== X-Google-Smtp-Source: ABhQp+QquymuGS9KVVCp9+sDLuZcJnDm4ogeJweeCs3DKuooqsMVn8tgMR++hOXWPkNbQg2Dp3A84A== X-Received: by 10.223.152.74 with SMTP id v68mr653048wrb.277.1510151733766; Wed, 08 Nov 2017 06:35:33 -0800 (PST) Received: from ?IPv6:::1? ([2001:41d0:1:6c23::1]) by smtp.gmail.com with ESMTPSA id u138sm7406427wmd.17.2017.11.08.06.35.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Nov 2017 06:35:33 -0800 (PST) To: Star Zeng , edk2-devel@lists.01.org Cc: Laszlo Ersek , Ruiyu Ni References: <1510018605-84896-1-git-send-email-star.zeng@intel.com> From: Julien Grall Message-ID: <4fab5c71-d4a9-ee2d-7017-a4c7047713b1@linaro.org> Date: Wed, 8 Nov 2017 14:35:32 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1510018605-84896-1-git-send-email-star.zeng@intel.com> Subject: Re: [PATCH V2] MdeModulePkg SerialDxe: Handle Timeout change more robustly X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Nov 2017 14:31:35 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Hi Star, On 07/11/17 01:36, Star Zeng wrote: > https://lists.01.org/pipermail/edk2-devel/2017-October/016479.html > reported "Xen Console input very slow in recent UEFI" that appears > after 4cf3f37c87ba1f9d58072444bd735e40e4779e70 "MdeModulePkg > SerialDxe: Process timeout consistently in SerialRead". > > Julien did more debugging and find out the following is happening in > TerminalConInTimerHandler (MdeModulePkg/Universal/Console/TerminalDxe) > when a character is received: > 1) GetControl will return EFI_SERIAL_INPUT_BUFFER_EMPTY unset > => Entering in the loop to fetch character from the serial > 2) GetOneKeyFromSerial() > => Return directly with the character read > 3) Looping as the fifo is not full and no error > 4) GetOneKeyFromSerial() -> SerialRead() > => No more character so SerialPortPoll() will return FALSE and loop > until timeout > => Return EFI_TIMEOUT > 5) Exiting the loop from TerminalConInTimerHandler > 6) Characters are printed > > After some investigation, I found it is related to the Timeout value. > > The Timeout is 1000000 (1s) by default to follow UEFI spec. > And the Terminal driver will recalculate and set the Timeout value > based on the properties of UART in TerminalDriverBindingStart()/ > TerminalConInTimerHandler(). > > SerialInTimeOut = 0; > if (Mode->BaudRate != 0) { > // > // According to BAUD rate to calculate the timeout value. > // > SerialInTimeOut = (1 + Mode->DataBits + Mode->StopBits) * > 2 * 1000000 / (UINTN) Mode->BaudRate; > } > > For example, based on the PCD values of PcdUartDefaultBaudRate, > PcdUartDefaultDataBits and PcdUartDefaultStopBits, SerialInTimeOut = > (1 + 8 + 1) * 2 * 1000000 / (UINTN) 115200 = 173 (us). > > When SerialDxe is used, > TerminalDriverBindingStart()/TerminalConInTimerHandler() -> > SerialIo->SetAttributes() -> > SerialSetAttributes() -> > SerialPortSetAttributes() > > Some implementations of SerialPortSetAttributes() could handle the > input parameters and return RETURN_SUCCESS, for example > BaseSerialPortLib16550, then Timeout value will be changed to 173 (us), > no "slow down" will be observed. > But some implementations of SerialPortSetAttributes() just return > RETURN_UNSUPPORTED, for example XenConsoleSerialPortLib, then Timeout > value will be not changed and kept 1000000 (1s), "slow down" will be > observed. > > SerialPortLib instance can be enhanced to > 1. Handle the input parameters and return status accordingly instead of > just returning RETURN_UNSUPPORTED in SerialPortSetAttributes(). > 2. Just return RETURN_SUCCESS instead of RETURN_UNSUPPORTED in > SerialPortSetAttributes() if the instance does not care the input > parameters at all. > > And SerialDxe can also be enhanced like this patch to be more robust > to handle Timeout change. > > Cc: Julien Grall > Cc: Laszlo Ersek > Cc: Ruiyu Ni > Compare against the original parameters > Suggested-by: Laszlo Ersek > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Star Zeng Tested-by: Julien Grall Cheers, -- Julien Grall