From patchwork Thu Dec 8 22:12:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 31516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp457591wrr; Thu, 8 Dec 2022 14:39:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf4RNTczwe3ZCw+7BvhEhkVz+q4e6qjUcwIZeivEpHUfTf6y5Z47zDdJVqwv9G+fgmCkTEzH X-Received: by 2002:a17:906:9705:b0:7c0:fd1e:972e with SMTP id k5-20020a170906970500b007c0fd1e972emr2800281ejx.46.1670539180961; Thu, 08 Dec 2022 14:39:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670539180; cv=none; d=google.com; s=arc-20160816; b=La/yawub54HIbFSPix8JLWGGg/0nUQ4lDexiLDWEivsB5CUGmb1Twa0lJoLGs9eT2G 0Oi8zYShmphvBhThJ2bfFjFv24m66zk+Ffe3+EUUa8nD7AlP0ysC9fb15mrVe2CySXE3 sSJHLXmSTYrbXN1IdRhgZ3jBFkXvXV0J4wrz5749ZmkMx6kePlnOWRlucgv9d7/yphwW S81xBL3TQsc7myjPWaMkMxcaEy4sTWeBh3RjqsDgt4H9GILc45gUS2gwjOZgqVpQGgv8 gIoUrR/T6yHN7XY/7HdvpFdE2zCA0eWySwVojInv2/2sblzYmEp737eshFXeuz3Z4Pk2 YnAw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=ofafQVLNRP+tT6wQKp30O09XbJPTUTpdSmZSfMnZHZ4=; b=BTOiTD//BjJ46VqlSFfsT4P17MD3li/FAK23uINUDTJ/1XJ0uwbKd3tSVSiapH2HiJ BOR+fyiQG+NAI7bbv8STWkh89fCZIhsYjCGUNLlXT5xyWhTHgzgXZzCujrqoWJL9sIa9 guzZs9lRbg9zyAI5nVpnjwWhhLAylgr6aDJ8uUEalknfJjs/kabUMKPMDBO29serKJk/ XFprQmf+a9gFL30jpZY6V9bju4iQmR+YPZcgNT3FMO1ACGQ7ORxsuLs38vmoVAGg5QFF z5gL9j0uqEaVxD3yyPY5xUPtay3ckLIcJMvSWPMHUuPBnymjR/rvK1LZVDJr10aj2Mrm vjuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Yy0XwLfC; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd17-20020a1709069b9100b007c0cb833625si14888161ejc.478.2022.12.08.14.39.17; Thu, 08 Dec 2022 14:39:40 -0800 (PST) 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=@intel.com header.s=Intel header.b=Yy0XwLfC; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229760AbiLHWMO (ORCPT + 99 others); Thu, 8 Dec 2022 17:12:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbiLHWMC (ORCPT ); Thu, 8 Dec 2022 17:12:02 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEA4B63A2; Thu, 8 Dec 2022 14:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670537519; x=1702073519; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=fT9SC06qYKXjgX1+neHHzXyWOTyqrcFvQQcpAYrJp80=; b=Yy0XwLfCQb+8JabfVdvKKykzMimJkBKgaOM7fSGck+IN3nSQfPupa6YE v9/5JFzVZcgHrW2krsSQDtdMs10ezIa0/f6ZC1dJJNqbiCYB9Hdp+l+X6 oogk+Aqs2TxE/InZzQDePDU8Q53SVzfJg2NB744kFnM7AEFDddNPDPfWs 9H4FJPloRH3gJ1vbUNLsiaVXhH8mCDKq4hHTGqcmyIsMhskuk8yJ5u415 4z/7NsSIkOJy55OMF7oNL0dgUQuGZFtXRFJv4ZwTHk8rs13kZc/UzB3SM gihe0UH46PKT6HuGsHFVBsEVIEiCgW+o5ifzQb1Jug+6fHE69u50k+FFC A==; X-IronPort-AV: E=McAfee;i="6500,9779,10555"; a="300735866" X-IronPort-AV: E=Sophos;i="5.96,228,1665471600"; d="scan'208";a="300735866" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2022 14:11:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10555"; a="649335504" X-IronPort-AV: E=Sophos;i="5.96,228,1665471600"; d="scan'208";a="649335504" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 08 Dec 2022 14:11:55 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id D63CC179; Fri, 9 Dec 2022 00:12:23 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Hans de Goede , platform-driver-x86@vger.kernel.org Subject: [PATCH v1 1/2] efi/earlycon: Replace open coded strnchrnul() Date: Fri, 9 Dec 2022 00:12:16 +0200 Message-Id: <20221208221217.56354-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751687292112492857?= X-GMAIL-MSGID: =?utf-8?q?1751687292112492857?= strnchrnul() can be called in the early stages. Replace open coded variant in the EFI early console driver. Signed-off-by: Andy Shevchenko --- drivers/firmware/efi/earlycon.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/efi/earlycon.c b/drivers/firmware/efi/earlycon.c index 4d6c5327471a..be7c83b6cd10 100644 --- a/drivers/firmware/efi/earlycon.c +++ b/drivers/firmware/efi/earlycon.c @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -143,16 +144,10 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num) len = si->lfb_linelength; while (num) { - unsigned int linemax; - unsigned int h, count = 0; + unsigned int linemax = (si->lfb_width - efi_x) / font->width; + unsigned int h, count; - for (s = str; *s && *s != '\n'; s++) { - if (count == num) - break; - count++; - } - - linemax = (si->lfb_width - efi_x) / font->width; + count = strnchrnul(str, num, '\n') - str; if (count > linemax) count = linemax; From patchwork Thu Dec 8 22:12:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 31515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp457034wrr; Thu, 8 Dec 2022 14:38:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf7xbGZ3gR8QpM/wQq4p2FVubcdf+LW4pMuL1F6DGt8+/uevfDe0I48I+apf86J1aegZfqjE X-Received: by 2002:a17:906:ca18:b0:7c0:a181:90c5 with SMTP id jt24-20020a170906ca1800b007c0a18190c5mr2850436ejb.1.1670539086052; Thu, 08 Dec 2022 14:38:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670539086; cv=none; d=google.com; s=arc-20160816; b=AX5GtaJGriMBu3hdv2qwVuMFa/HAG2O4UNCNtl09wGQmTbwGuNS4UUs1wAyEQ0NLn2 fNi6VNUvDKgAvSBuG0ZG1epHgJHIJNeyrEEeuGjvDCYphbOYgyyEnKD3GONngaEfhyiD ouAD25Im+CRjMQC6TDWSCPId79ub5G5q728auzjEAe5dP8tFC+ea14/uhyVLnqNej/LW XkgJlHw7Q7A8hV08iwIYk0qvrMKCiP/CN3jD3eMtmbgQgt6M1m3iapBSf/Fltbo/sCGL s7bx5fikyEgAScpseZw/sItumEK9ax9wusdpLSphX9u5CnSe+ZENFP8XfVkdeP+POB51 /YIg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YSF4X3tc5EdanfFhpPh5s4P613IpcQLldjdS+O8MKA4=; b=vK1CZgc/DqcAQzw99T6m5Rg+nwAbW5ySxj7JqEfHXSHydAXZIlzP3tcCbL93UERJ/Q OSYGR9qjJiatc+2eSVPWGzZ2NuhIvcfq8HUvPJC3gWTpRr6rTkfjBK1YiCmH70pWRj1g Glj/fuRNxQqMdAlnCykfC7Abav4ADJneZDSSrQDHS8JqpLN7Hh2ouzjEWCPiY6DTmgW4 Zsi69u6qGC/znEttrp2SrVtVKQCwAoGs3inVBpui+xYO3YW8wYQbIa8zFL9iQCJusPFj QRV6Um00VMlO9wPCSRvN5cVHdw6+rtlqEERFI7kaImSwJ5fcPgjvATtBvwwYR7bjVo/L uVGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="ae/SWJ3Y"; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa41-20020a17090786a900b007c07ac26356si20234389ejc.513.2022.12.08.14.37.41; Thu, 08 Dec 2022 14:38:06 -0800 (PST) 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=@intel.com header.s=Intel header.b="ae/SWJ3Y"; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229810AbiLHWMS (ORCPT + 99 others); Thu, 8 Dec 2022 17:12:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230043AbiLHWMD (ORCPT ); Thu, 8 Dec 2022 17:12:03 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E2DB27DE5; Thu, 8 Dec 2022 14:12:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670537522; x=1702073522; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vvU4PeGKvcYxDi2SGTd4kcVlxgzXOYX6SRbtggkIuPw=; b=ae/SWJ3Y2JnS7cvEQi/jUCcnM9H3ovnCOnSuo5XnjS2ZTOdnis1B91md FMdKCzIpvlogbG/vPfNg+1wHILv+6ct98S+mtFwUrvHYGcpywy0HKsBDa G8aQ9yLza194DmtqYwdWXYURLvxY0xXrx4ot03b9bV83VRHpYRbnzfQzw I3ioZFJwGG81Ku7RtDzuN476HFzBMksfGHNLpTPHMxHAH0ooxZLGlQDux ir7dLf+qXBRcXqzvK/dHNkMzId+VkmuhDcDacfr1oJcymsBg96dJJ4uew dzYVfnSh1XjW8QiOkktGkjbzjzghgOVbKNBQX89S0k10EPu6NLFBJHm11 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10555"; a="300735872" X-IronPort-AV: E=Sophos;i="5.96,228,1665471600"; d="scan'208";a="300735872" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2022 14:11:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10555"; a="649335508" X-IronPort-AV: E=Sophos;i="5.96,228,1665471600"; d="scan'208";a="649335508" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 08 Dec 2022 14:11:56 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id C3423433; Fri, 9 Dec 2022 00:12:24 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Hans de Goede , platform-driver-x86@vger.kernel.org Subject: [PATCH v1 2/2] efi/earlycon: Speed up scrolling by skiping moving empty space Date: Fri, 9 Dec 2022 00:12:17 +0200 Message-Id: <20221208221217.56354-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221208221217.56354-1-andriy.shevchenko@linux.intel.com> References: <20221208221217.56354-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751687192808194680?= X-GMAIL-MSGID: =?utf-8?q?1751687192808194680?= Currently the scroll copies the full screen which is slow on the hi-resolution displays. At the same time most of the screen is an empty space which has no need to be copied over and over. Optimize the scrolling algorithm by caching the x coordinates of the last printed lines and scroll in accordance with the maximum x in that cache. On my Microsoft Surface Book (the first version) this produces a significant speedup of the console 90 seconds vs. 168 seconds with the kernel command line having ignore_loglevel earlycon=efifb keep_bootcon Signed-off-by: Andy Shevchenko --- drivers/firmware/efi/earlycon.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/earlycon.c b/drivers/firmware/efi/earlycon.c index be7c83b6cd10..f54e6fdf08e2 100644 --- a/drivers/firmware/efi/earlycon.c +++ b/drivers/firmware/efi/earlycon.c @@ -16,6 +16,8 @@ static const struct console *earlycon_console __initdata; static const struct font_desc *font; +static u16 cur_line_y, max_line_y; +static u32 efi_x_array[1024]; static u32 efi_x, efi_y; static u64 fb_base; static bool fb_wb; @@ -86,9 +88,17 @@ static void efi_earlycon_clear_scanline(unsigned int y) static void efi_earlycon_scroll_up(void) { unsigned long *dst, *src; + u16 maxlen = 0; u16 len; u32 i, height; + /* Find the cached maximum x coordinate */ + for (i = 0; i < max_line_y; i++) { + if (efi_x_array[i] > maxlen) + maxlen = efi_x_array[i]; + } + maxlen *= 4; + len = screen_info.lfb_linelength; height = screen_info.lfb_height; @@ -103,7 +113,7 @@ static void efi_earlycon_scroll_up(void) return; } - memmove(dst, src, len); + memmove(dst, src, maxlen); efi_earlycon_unmap(src, len); efi_earlycon_unmap(dst, len); @@ -136,6 +146,7 @@ static void efi_earlycon_write(struct console *con, const char *str, unsigned int num) { struct screen_info *si; + u32 cur_efi_x = efi_x; unsigned int len; const char *s; void *dst; @@ -176,6 +187,7 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num) str += count; if (num > 0 && *s == '\n') { + cur_efi_x = efi_x; efi_x = 0; efi_y += font->height; str++; @@ -183,6 +195,7 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num) } if (efi_x + font->width > si->lfb_width) { + cur_efi_x = efi_x; efi_x = 0; efi_y += font->height; } @@ -190,6 +203,9 @@ efi_earlycon_write(struct console *con, const char *str, unsigned int num) if (efi_y + font->height > si->lfb_height) { u32 i; + efi_x_array[cur_line_y] = cur_efi_x; + cur_line_y = (cur_line_y + 1) % max_line_y; + efi_y -= font->height; efi_earlycon_scroll_up(); @@ -230,7 +246,15 @@ static int __init efi_earlycon_setup(struct earlycon_device *device, if (!font) return -ENODEV; - efi_y = rounddown(yres, font->height) - font->height; + /* Fill the cache with maximum possible value of x coordinate */ + memset32(efi_x_array, rounddown(xres, font->width), ARRAY_SIZE(efi_x_array)); + efi_y = rounddown(yres, font->height); + + /* Make sure we have cache for the x coordinate for the full screen */ + max_line_y = efi_y / font->height + 1; + cur_line_y = 0; + + efi_y -= font->height; for (i = 0; i < (yres - efi_y) / font->height; i++) efi_earlycon_scroll_up();