From patchwork Thu May 5 06:13:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikunj A Dadhania X-Patchwork-Id: 618852 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r0lGz31Wvz9t5V for ; Thu, 5 May 2016 16:23:55 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3r0lGz2FfGzDqB3 for ; Thu, 5 May 2016 16:23:55 +1000 (AEST) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Received: from e28smtp03.in.ibm.com (e28smtp03.in.ibm.com [125.16.236.3]) (using TLSv1.2 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3r0lGv1XpTzDq5y for ; Thu, 5 May 2016 16:23:51 +1000 (AEST) Received: from localhost by e28smtp03.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 5 May 2016 11:43:48 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp03.in.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 5 May 2016 11:43:45 +0530 X-IBM-Helo: d28dlp01.in.ibm.com X-IBM-MailFrom: nikunj@linux.vnet.ibm.com X-IBM-RcptTo: slof@lists.ozlabs.org Received: from d28relay06.in.ibm.com (d28relay06.in.ibm.com [9.184.220.150]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id CA285E005F for ; Thu, 5 May 2016 11:46:43 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay06.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u456Dg9D51249160 for ; Thu, 5 May 2016 11:43:42 +0530 Received: from d28av01.in.ibm.com (localhost [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u456DfjF000384 for ; Thu, 5 May 2016 11:43:42 +0530 Received: from abhimanyu.in.ibm.com ([9.79.199.183]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u456Dfn5000371; Thu, 5 May 2016 11:43:41 +0530 From: Nikunj A Dadhania To: slof@lists.ozlabs.org Date: Thu, 5 May 2016 11:43:39 +0530 Message-Id: <1462428819-11150-1-git-send-email-nikunj@linux.vnet.ibm.com> X-Mailer: git-send-email 2.5.5 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16050506-0009-0000-0000-00000C9DAD22 Subject: [SLOF] [PATCH] rtas-nvram: optimize erase X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" As this was done at byte granularity, erasing complete nvram(64K default) took a lot of time. To reduce the number of rtas call per byte write which is expensive, the erase is done in a block of 1024. After this patch there is ~450msec improvement during boot. Default qemu booting does not provide file backed nvram, so every boot there would be full erase of 64K. Before this patch: real 0m2.214s user 0m0.015s sys 0m0.006s real 0m2.222s user 0m0.014s sys 0m0.005s real 0m2.201s user 0m0.010s sys 0m0.005s After this patch: real 0m1.762s user 0m0.014s sys 0m0.006s real 0m1.773s user 0m0.011s sys 0m0.004s real 0m1.754s user 0m0.013s sys 0m0.005s Signed-off-by: Nikunj A Dadhania --- lib/libnvram/nvram.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/libnvram/nvram.c b/lib/libnvram/nvram.c index 473814e..5a895ee 100644 --- a/lib/libnvram/nvram.c +++ b/lib/libnvram/nvram.c @@ -80,6 +80,8 @@ static volatile uint8_t nvram[NVRAM_LENGTH]; /* FAKE */ #elif defined(RTAS_NVRAM) +#define RTAS_ERASE_BUF_SZ 1024 +unsigned char erase_buf[RTAS_ERASE_BUF_SZ] = {0}; static inline void nvram_fetch(unsigned int offset, void *buf, unsigned int len) { struct hv_rtas_call rtas = { @@ -372,9 +374,18 @@ partition_t get_partition_fs(char *name, int namelen) void erase_nvram(int offset, int len) { int i; +#ifdef RTAS_NVRAM + int chunk; + memset(erase_buf, 0, RTAS_ERASE_BUF_SZ); + for (i = len; i > 0; i -= RTAS_ERASE_BUF_SZ, offset += RTAS_ERASE_BUF_SZ) { + chunk = (i > RTAS_ERASE_BUF_SZ)? RTAS_ERASE_BUF_SZ : i; + nvram_store(offset, erase_buf, chunk); + } +#else for (i=offset; i