From patchwork Wed Jun 27 05:23:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Youxin He (youxinhe)" X-Patchwork-Id: 167526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8371BB6F9A for ; Wed, 27 Jun 2012 15:25:37 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SjkjW-0005u3-NN; Wed, 27 Jun 2012 05:24:06 +0000 Received: from masquerade.micron.com ([137.201.242.130]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SjkjS-0005tN-Ix for linux-mtd@lists.infradead.org; Wed, 27 Jun 2012 05:24:03 +0000 Received: from mail.micron.com (ntxboicas03.micron.com [137.201.84.59]) by masquerade.micron.com (8.13.6/8.13.6) with ESMTP id q5R5NmGV006016; Tue, 26 Jun 2012 23:23:48 -0600 Received: from NTXBOIMBX01.micron.com ([fe80::7520:6f5e:51e1:8d75]) by NTXBOICAS03.micron.com ([2002:89c9:543b::89c9:543b]) with mapi id 14.01.0355.002; Tue, 26 Jun 2012 23:23:48 -0600 From: "Youxin He (youxinhe)" To: Artem Bityutskiy , "Changming Chen (changmingche)" Subject: RE: Patch MTD: increase time out value for buffer program Thread-Topic: Patch MTD: increase time out value for buffer program Thread-Index: AQHNSR0lZ8s+XRAdkUex2LPT4m+50ZcNO4YAgADAUgD//7AuIA== Date: Wed, 27 Jun 2012 05:23:48 +0000 Message-ID: <567E14D9F917DD43923114D48B1586363D569F2F@NTXBOIMBX01.micron.com> References: <6ACDE3A4C2F7E94C8DBB6FCC0D06A0873DA88046@NTXBOIMBX05.micron.com> <1340726334.3119.150.camel@sauron.fi.intel.com> <1340767634.2317.1.camel@koala> In-Reply-To: <1340767634.2317.1.camel@koala> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-cr-hashedpuzzle: Ali0 D51P F4sL OBbH QHAU RhQG XZUA awQA bfH9 dgAA e+aH fITt hN15 hdrM kRWl krRM; 3; ZABlAGQAZQBrAGkAbgBkADEAQABnAG0AYQBpAGwALgBjAG8AbQA7AGQAdwBtAHcAMgBAAGkAbgBmAHIAYQBkAGUAYQBkAC4AbwByAGcAOwBsAGkAbgB1AHgALQBtAHQAZABAAGwAaQBzAHQAcwAuAGkAbgBmAHIAYQBkAGUAYQBkAC4AbwByAGcA; Sosha1_v1; 7; {CBB99353-391A-48BD-814D-615A2D80287B}; eQBvAHUAeABpAG4AaABlAEAAbQBpAGMAcgBvAG4ALgBjAG8AbQA=; Wed, 27 Jun 2012 05:23:35 GMT; UgBFADoAIABQAGEAdABjAGgAIABNAFQARAA6ACAAaQBuAGMAcgBlAGEAcwBlACAAdABpAG0AZQAgAG8AdQB0ACAAdgBhAGwAdQBlACAAZgBvAHIAIABiAHUAZgBmAGUAcgAgAHAAcgBvAGcAcgBhAG0A x-cr-puzzleid: {CBB99353-391A-48BD-814D-615A2D80287B} x-originating-ip: [137.201.88.182] x-tm-as-product-ver: SMEX-10.0.0.4152-7.000.1014-19000.003 x-tm-as-result: No--67.951900-0.000000-31 x-tm-as-user-approved-sender: Yes x-tm-as-user-blocked-sender: No x-mt-checkinternalsenderrule: True MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.62 on mail-srv4 on 137.201.82.105 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [137.201.242.130 listed in list.dnswl.org] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: "linux-mtd@lists.infradead.org" , "dwmw2@infradead.org" , "Frank Liu \(frankliu\)" X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Hi Artem, How about just change HZ/1000 stuff to msecs_to_jiffies()? Schedule_timeout() is a good idea but I don't see it is necessary to use schedule_timeout() to replace schedule(). The code you add below is just for suspend case, normal case will not go to schedule(), but normal case you should check for timeout otherwise infinite loop in case a program failure occur. + #define WRITE_TIEMEOUT 4 ....... - unsigned long uWriteTimeout = ( HZ / 1000 ) + 1; + unsigned long uWriteTimeout = msecs_to_jiffies(WRITE_TIEMEOUT); ....... Thanks. Best regards, Youxin He -----Original Message----- From: Artem Bityutskiy [mailto:dedekind1@gmail.com] Sent: Wednesday, June 27, 2012 11:27 AM To: Changming Chen (changmingche) Cc: dwmw2@infradead.org; linux-mtd@lists.infradead.org; Youxin He (youxinhe); Frank Liu (frankliu) Subject: Re: Patch MTD: increase time out value for buffer program On Tue, 2012-06-26 at 18:58 +0300, Artem Bityutskiy wrote: > On Wed, 2012-06-13 at 04:29 +0000, Changming Chen (changmingche) wrote: > > The time out value(1ms:typical HZ defined smaller than 1000) defined for function "do_write_buffer" in "cfi_cmdset_0002.c" is not enough. Because the enlargement of buffer size, much time will cost for buffer program. It's has risk that time out will be triggered before buffer program finished and make misjudge for buffer program. we suggest that 4ms is more appropriate compare to 1ms. This change has no impact of program performance. > > > > diff --git a/a/drivers/mtd/chips/cfi_cmdset_0002.c > > b/b/drivers/mtd/chips/cfi_cmd index 9d93c45..7da8fca 100755 > > --- a/a/drivers/mtd/chips/cfi_cmdset_0002.c > > +++ b/b/drivers/mtd/chips/cfi_cmdset_0002.c > > @@ -1312,7 +1312,7 @@ static int __xipram do_write_buffer(struct map_info *map, > > struct cfi_private *cfi = map->fldrv_priv; > > unsigned long timeo = jiffies + HZ; > > /* see comments in do_write_oneword() regarding uWriteTimeo. */ > > - unsigned long uWriteTimeout = ( HZ / 1000 ) + 1; > > + unsigned long uWriteTimeout = ( HZ / 1000 ) + 4; > > No, sorry, this is not a fix, this is a band-aid. The whole HZ/1000 > thing is broken. You should not use HZ at all. For this driver it > looks like you should use ' schedule_timeout()' with the right timout > instead of 'schedule()' and get rid of all the HZ and jiffies stuff. What I meant is something like this (not tested, not even compiled), which should also be done in many other places in this file: map_word oldd; int retry_cnt = 0; @@ -1197,8 +1189,6 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, adr, map_bankwidth(map), chip->word_write_time); - /* See comment above for timeout value. */ - timeo = jiffies + uWriteTimeout; for (;;) { if (chip->state != FL_WRITING) { /* Someone's suspended the write. Sleep */ @@ -1207,20 +1197,18 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); mutex_unlock(&chip->mutex); - schedule(); + ret = schedule_timeout(msecs_to_jiffies(WRITE_TIEMEOUT)); remove_wait_queue(&chip->wq, &wait); - timeo = jiffies + (HZ / 2); /* FIXME */ mutex_lock(&chip->mutex); + if (!ret) { + xip_enable(map, chip, adr); + printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); + xip_disable(map, chip, adr); + break; + } continue; } - if (time_after(jiffies, timeo) && !chip_ready(map, adr)){ - xip_enable(map, chip, adr); - printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); - xip_disable(map, chip, adr); - break; - } - if (chip_ready(map, adr)) break; --- Best Regards, Artem Bityutskiy diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index 22d0493..8ce3b44 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -48,6 +48,9 @@ #define SST49LF008A 0x005a #define AT49BV6416 0x00d6 +/* Write operation timeout, ms */ +#define WRITE_TIEMEOUT 2 + static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); static int cfi_amdstd_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); @@ -1143,17 +1146,6 @@ static int cfi_amdstd_secsi_read (struct mtd_info *mtd, loff_t from, size_t len, static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, map_word datum) { struct cfi_private *cfi = map->fldrv_priv; - unsigned long timeo = jiffies + HZ; - /* - * We use a 1ms + 1 jiffies generic timeout for writes (most devices - * have a max write time of a few hundreds usec). However, we should - * use the maximum timeout value given by the chip at probe time - * instead. Unfortunately, struct flchip does have a field for - * maximum timeout, only for typical which can be far too short - * depending of the conditions. The ' + 1' is to avoid having a - * timeout of 0 jiffies if HZ is smaller than 1000. - */ - unsigned long uWriteTimeout = ( HZ / 1000 ) + 1; int ret = 0;