linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc: use string library
@ 2012-01-27 14:24 Akinobu Mita
  2012-01-27 14:24 ` [PATCH] mtd/nand: " Akinobu Mita
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Akinobu Mita @ 2012-01-27 14:24 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: Akinobu Mita, Benjamin Herrenschmidt, linuxppc-dev

- Use memchr_inv to check if the data contains all 0xFF bytes.
  It is faster than looping for each byte.

- Use memcmp to compare memory areas

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
 arch/powerpc/platforms/powermac/nvram.c |   42 ++++++++++++++-----------------
 1 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/platforms/powermac/nvram.c b/arch/powerpc/platforms/powermac/nvram.c
index 54d2271..da18b26 100644
--- a/arch/powerpc/platforms/powermac/nvram.c
+++ b/arch/powerpc/platforms/powermac/nvram.c
@@ -279,7 +279,7 @@ static u32 core99_check(u8* datas)
 
 static int sm_erase_bank(int bank)
 {
-	int stat, i;
+	int stat;
 	unsigned long timeout;
 
 	u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
@@ -301,11 +301,10 @@ static int sm_erase_bank(int bank)
 	out_8(base, SM_FLASH_CMD_CLEAR_STATUS);
 	out_8(base, SM_FLASH_CMD_RESET);
 
-	for (i=0; i<NVRAM_SIZE; i++)
-		if (base[i] != 0xff) {
-			printk(KERN_ERR "nvram: Sharp/Micron flash erase failed !\n");
-			return -ENXIO;
-		}
+	if (memchr_inv(base, 0xff, NVRAM_SIZE)) {
+		printk(KERN_ERR "nvram: Sharp/Micron flash erase failed !\n");
+		return -ENXIO;
+	}
 	return 0;
 }
 
@@ -336,17 +335,16 @@ static int sm_write_bank(int bank, u8* datas)
 	}
 	out_8(base, SM_FLASH_CMD_CLEAR_STATUS);
 	out_8(base, SM_FLASH_CMD_RESET);
-	for (i=0; i<NVRAM_SIZE; i++)
-		if (base[i] != datas[i]) {
-			printk(KERN_ERR "nvram: Sharp/Micron flash write failed !\n");
-			return -ENXIO;
-		}
+	if (memcmp(base, datas, NVRAM_SIZE)) {
+		printk(KERN_ERR "nvram: Sharp/Micron flash write failed !\n");
+		return -ENXIO;
+	}
 	return 0;
 }
 
 static int amd_erase_bank(int bank)
 {
-	int i, stat = 0;
+	int stat = 0;
 	unsigned long timeout;
 
 	u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE;
@@ -382,12 +380,11 @@ static int amd_erase_bank(int bank)
 	/* Reset */
 	out_8(base, 0xf0);
 	udelay(1);
-	
-	for (i=0; i<NVRAM_SIZE; i++)
-		if (base[i] != 0xff) {
-			printk(KERN_ERR "nvram: AMD flash erase failed !\n");
-			return -ENXIO;
-		}
+
+	if (memchr_inv(base, 0xff, NVRAM_SIZE)) {
+		printk(KERN_ERR "nvram: AMD flash erase failed !\n");
+		return -ENXIO;
+	}
 	return 0;
 }
 
@@ -429,11 +426,10 @@ static int amd_write_bank(int bank, u8* datas)
 	out_8(base, 0xf0);
 	udelay(1);
 
-	for (i=0; i<NVRAM_SIZE; i++)
-		if (base[i] != datas[i]) {
-			printk(KERN_ERR "nvram: AMD flash write failed !\n");
-			return -ENXIO;
-		}
+	if (memcmp(base, datas, NVRAM_SIZE)) {
+		printk(KERN_ERR "nvram: AMD flash write failed !\n");
+		return -ENXIO;
+	}
 	return 0;
 }
 
-- 
1.7.4.4


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] mtd/nand: use string library
  2012-01-27 14:24 [PATCH] powerpc: use string library Akinobu Mita
@ 2012-01-27 14:24 ` Akinobu Mita
  2012-01-27 17:16   ` Joe Perches
  2012-01-27 14:24 ` [PATCH] mtd/onenand: " Akinobu Mita
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Akinobu Mita @ 2012-01-27 14:24 UTC (permalink / raw)
  To: linux-kernel, akpm
  Cc: Akinobu Mita, Jiandong Zheng, Scott Branden, David Woodhouse, linux-mtd

- Use memchr_inv to check if the data contains all 0xFF bytes.
  It is faster than looping for each byte.

- Use memcmp to compare memory areas

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jiandong Zheng <jdzheng@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
 drivers/mtd/nand/davinci_nand.c |    7 +++----
 drivers/mtd/nand/denali.c       |    7 +++----
 drivers/mtd/nand/diskonchip.c   |   18 +++---------------
 drivers/mtd/nand/nand_bbt.c     |   16 +++++-----------
 drivers/mtd/nand/nand_bcm_umi.c |   10 +++-------
 5 files changed, 17 insertions(+), 41 deletions(-)

diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index 6e56615..423a7cc 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -315,10 +315,9 @@ static int nand_davinci_correct_4bit(struct mtd_info *mtd,
 	unsigned long timeo;
 
 	/* All bytes 0xff?  It's an erased page; ignore its ECC. */
-	for (i = 0; i < 10; i++) {
-		if (ecc_code[i] != 0xff)
-			goto compare;
-	}
+	if (memchr_inv(ecc_code, 0xff, 10))
+		goto compare;
+
 	return 0;
 
 compare:
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 3984d48..a87e3a4 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -908,10 +908,9 @@ static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
  */
 bool is_erased(uint8_t *buf, int len)
 {
-	int i = 0;
-	for (i = 0; i < len; i++)
-		if (buf[i] != 0xFF)
-			return false;
+	if (memchr_inv(buf, 0xFF, len))
+		return false;
+
 	return true;
 }
 #define ECC_SECTOR_SIZE 512
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index df921e7..bf0602e 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -945,12 +945,8 @@ static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, unsign
 		/* Note: this somewhat expensive test should not be triggered
 		   often.  It could be optimized away by examining the data in
 		   the writebuf routine, and remembering the result. */
-		for (i = 0; i < 512; i++) {
-			if (dat[i] == 0xff)
-				continue;
+		if (memchr_inv(dat, 0xff, 512))
 			emptymatch = 0;
-			break;
-		}
 	}
 	/* If emptymatch still =1, we do have an all-0xff data buffer.
 	   Return all-0xff ecc value instead of the computed one, so
@@ -1000,24 +996,16 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat,
 		/* If emptymatch=1, the read syndrome is consistent with an
 		   all-0xff data and stored ecc block.  Check the stored ecc. */
 		if (emptymatch) {
-			for (i = 0; i < 6; i++) {
-				if (read_ecc[i] == 0xff)
-					continue;
+			if (memchr_inv(read_ecc, 0xff, 6))
 				emptymatch = 0;
-				break;
-			}
 		}
 		/* If emptymatch still =1, check the data block. */
 		if (emptymatch) {
 			/* Note: this somewhat expensive test should not be triggered
 			   often.  It could be optimized away by examining the data in
 			   the readbuf routine, and remembering the result. */
-			for (i = 0; i < 512; i++) {
-				if (dat[i] == 0xff)
-					continue;
+			if (memchr_inv(dat, 0xff, 512))
 				emptymatch = 0;
-				break;
-			}
 		}
 		/* If emptymatch still =1, this is almost certainly a freshly-
 		   erased block, in which case the ECC will not come out right.
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 20a112f..a1b2dd5 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -100,10 +100,8 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc
 
 	end = paglen + td->offs;
 	if (td->options & NAND_BBT_SCANEMPTY) {
-		for (i = 0; i < end; i++) {
-			if (p[i] != 0xff)
-				return -1;
-		}
+		if (memchr_inv(p, 0xff, end))
+			return -1;
 	}
 	p += end;
 
@@ -133,14 +131,10 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc
  */
 static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td)
 {
-	int i;
-	uint8_t *p = buf;
-
 	/* Compare the pattern */
-	for (i = 0; i < td->len; i++) {
-		if (p[td->offs + i] != td->pattern[i])
-			return -1;
-	}
+	if (memcmp(buf + td->offs, td->pattern, td->len))
+		return -1;
+
 	return 0;
 }
 
diff --git a/drivers/mtd/nand/nand_bcm_umi.c b/drivers/mtd/nand/nand_bcm_umi.c
index 46a6bc9..ad51dad 100644
--- a/drivers/mtd/nand/nand_bcm_umi.c
+++ b/drivers/mtd/nand/nand_bcm_umi.c
@@ -109,13 +109,9 @@ int nand_bcm_umi_bch_correct_page(uint8_t *datap, uint8_t *readEccData,
 	 * see if errors are correctible
 	 */
 	if ((regValue & REG_UMI_BCH_CTRL_STATUS_UNCORR_ERR) > 0) {
-		int i;
-
-		for (i = 0; i < numEccBytes; i++) {
-			if (readEccData[i] != 0xff) {
-				/* errors cannot be fixed, return -1 */
-				return -1;
-			}
+		if (memchr_inv(readEccData, 0xff, numEccBytes)) {
+			/* errors cannot be fixed, return -1 */
+			return -1;
 		}
 		/* If ECC is unprogrammed then we can't correct,
 		 * assume everything OK */
-- 
1.7.4.4


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] mtd/onenand: use string library
  2012-01-27 14:24 [PATCH] powerpc: use string library Akinobu Mita
  2012-01-27 14:24 ` [PATCH] mtd/nand: " Akinobu Mita
@ 2012-01-27 14:24 ` Akinobu Mita
  2012-01-27 14:24 ` [PATCH] mtd/ubi: use memchr_inv Akinobu Mita
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Akinobu Mita @ 2012-01-27 14:24 UTC (permalink / raw)
  To: linux-kernel, akpm
  Cc: Akinobu Mita, David Woodhouse, Kyungmin Park, linux-mtd

- Use memchr_inv to check if the data contains all 0xFF bytes.
  It is faster than looping for each byte.

- Use memcmp to compare memory areas

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: linux-mtd@lists.infradead.org
---
 drivers/mtd/onenand/onenand_base.c |    8 ++------
 drivers/mtd/onenand/onenand_bbt.c  |   10 +++-------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index a061bc1..374605f 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -3673,7 +3673,7 @@ static void flexonenand_get_size(struct mtd_info *mtd)
 static int flexonenand_check_blocks_erased(struct mtd_info *mtd, int start, int end)
 {
 	struct onenand_chip *this = mtd->priv;
-	int i, ret;
+	int ret;
 	int block;
 	struct mtd_oob_ops ops = {
 		.mode = MTD_OPS_PLACE_OOB,
@@ -3699,11 +3699,7 @@ static int flexonenand_check_blocks_erased(struct mtd_info *mtd, int start, int
 		if (ret)
 			return ret;
 
-		for (i = 0; i < mtd->oobsize; i++)
-			if (this->oob_buf[i] != 0xff)
-				break;
-
-		if (i != mtd->oobsize) {
+		if (memchr_inv(this->oob_buf, 0xff, mtd->oobsize)) {
 			printk(KERN_WARNING "%s: Block %d not erased.\n",
 				__func__, block);
 			return 1;
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index 66fe3b7..8b1277b 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -32,14 +32,10 @@
  */
 static int check_short_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
 {
-	int i;
-	uint8_t *p = buf;
-
 	/* Compare the pattern */
-	for (i = 0; i < td->len; i++) {
-		if (p[i] != td->pattern[i])
-			return -1;
-	}
+	if (memcmp(buf, td->pattern, td->len))
+		return -1;
+
         return 0;
 }
 
-- 
1.7.4.4


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] mtd/ubi: use memchr_inv
  2012-01-27 14:24 [PATCH] powerpc: use string library Akinobu Mita
  2012-01-27 14:24 ` [PATCH] mtd/nand: " Akinobu Mita
  2012-01-27 14:24 ` [PATCH] mtd/onenand: " Akinobu Mita
@ 2012-01-27 14:24 ` Akinobu Mita
  2012-01-27 14:24 ` [PATCH] mtd/inftlmount: " Akinobu Mita
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Akinobu Mita @ 2012-01-27 14:24 UTC (permalink / raw)
  To: linux-kernel, akpm
  Cc: Akinobu Mita, Artem Bityutskiy, David Woodhouse, linux-mtd

Use memchr_inv to check if the data contains all 0xFF bytes.  It is
faster than looping for each byte.
This also removes ubi_check_pattern which is no longer used.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
 drivers/mtd/ubi/io.c   |   14 +++++---------
 drivers/mtd/ubi/misc.c |   19 -------------------
 drivers/mtd/ubi/scan.c |    2 +-
 drivers/mtd/ubi/ubi.h  |    1 -
 4 files changed, 6 insertions(+), 30 deletions(-)

diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 5cde4e5..9fc27d3 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -435,8 +435,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
 		if (err)
 			goto out;
 
-		err = ubi_check_pattern(ubi->peb_buf1, 0xFF, ubi->peb_size);
-		if (err == 0) {
+		if (memchr_inv(ubi->peb_buf1, 0xFF, ubi->peb_size)) {
 			ubi_err("erased PEB %d, but a non-0xFF byte found",
 				pnum);
 			err = -EIO;
@@ -454,9 +453,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum)
 		if (err)
 			goto out;
 
-		err = ubi_check_pattern(ubi->peb_buf1, patterns[i],
-					ubi->peb_size);
-		if (err == 0) {
+		if (memchr_inv(ubi->peb_buf1, patterns[i], ubi->peb_size)) {
 			ubi_err("pattern %x checking failed for PEB %d",
 				patterns[i], pnum);
 			err = -EIO;
@@ -783,7 +780,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
 		 * 0xFF. If yes, this physical eraseblock is assumed to be
 		 * empty.
 		 */
-		if (ubi_check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) {
+		if (!memchr_inv(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) {
 			/* The physical eraseblock is supposedly empty */
 			if (verbose)
 				ubi_warn("no EC header found at PEB %d, "
@@ -1039,7 +1036,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
 		if (mtd_is_eccerr(read_err))
 			return UBI_IO_BAD_HDR_EBADMSG;
 
-		if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
+		if (!memchr_inv(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
 			if (verbose)
 				ubi_warn("no VID header found at PEB %d, "
 					 "only 0xFF bytes", pnum);
@@ -1427,8 +1424,7 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
 		goto error;
 	}
 
-	err = ubi_check_pattern(buf, 0xFF, len);
-	if (err == 0) {
+	if (memchr_inv(buf, 0xFF, len)) {
 		ubi_err("flash region at PEB %d:%d, length %d does not "
 			"contain all 0xFF bytes", pnum, offset, len);
 		goto fail;
diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c
index f6a7d7a..0e4b9a2 100644
--- a/drivers/mtd/ubi/misc.c
+++ b/drivers/mtd/ubi/misc.c
@@ -103,22 +103,3 @@ void ubi_calculate_reserved(struct ubi_device *ubi)
 	if (ubi->beb_rsvd_level < MIN_RESEVED_PEBS)
 		ubi->beb_rsvd_level = MIN_RESEVED_PEBS;
 }
-
-/**
- * ubi_check_pattern - check if buffer contains only a certain byte pattern.
- * @buf: buffer to check
- * @patt: the pattern to check
- * @size: buffer size in bytes
- *
- * This function returns %1 in there are only @patt bytes in @buf, and %0 if
- * something else was also found.
- */
-int ubi_check_pattern(const void *buf, uint8_t patt, int size)
-{
-	int i;
-
-	for (i = 0; i < size; i++)
-		if (((const uint8_t *)buf)[i] != patt)
-			return 0;
-	return 1;
-}
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 0cb17d9..54a56acc 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -808,7 +808,7 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr,
 	if (err)
 		goto out_unlock;
 
-	if (ubi_check_pattern(ubi->peb_buf1, 0xFF, ubi->leb_size))
+	if (!memchr_inv(ubi->peb_buf1, 0xFF, ubi->leb_size))
 		goto out_unlock;
 
 	ubi_err("PEB %d contains corrupted VID header, and the data does not "
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index d51d75d..2ff1eb6 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -519,7 +519,6 @@ int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf,
 		      int length);
 int ubi_check_volume(struct ubi_device *ubi, int vol_id);
 void ubi_calculate_reserved(struct ubi_device *ubi);
-int ubi_check_pattern(const void *buf, uint8_t patt, int size);
 
 /* eba.c */
 int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
-- 
1.7.4.4


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] mtd/inftlmount: use memchr_inv
  2012-01-27 14:24 [PATCH] powerpc: use string library Akinobu Mita
                   ` (2 preceding siblings ...)
  2012-01-27 14:24 ` [PATCH] mtd/ubi: use memchr_inv Akinobu Mita
@ 2012-01-27 14:24 ` Akinobu Mita
  2012-01-27 14:24 ` [PATCH] mtd/nftlmount: " Akinobu Mita
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Akinobu Mita @ 2012-01-27 14:24 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: Akinobu Mita, David Woodhouse, linux-mtd

Use memchr_inv to check if the data contains all 0xFF bytes.  It is
faster than looping for each byte.
This also removes memcmpb which is no longer used.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
 drivers/mtd/inftlmount.c |   14 ++------------
 1 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
index 4adc037..419b1c9 100644
--- a/drivers/mtd/inftlmount.c
+++ b/drivers/mtd/inftlmount.c
@@ -320,16 +320,6 @@ static int find_boot_record(struct INFTLrecord *inftl)
 	return -1;
 }
 
-static int memcmpb(void *a, int c, int n)
-{
-	int i;
-	for (i = 0; i < n; i++) {
-		if (c != ((unsigned char *)a)[i])
-			return 1;
-	}
-	return 0;
-}
-
 /*
  * check_free_sector: check if a free sector is actually FREE,
  *	i.e. All 0xff in data and oob area.
@@ -345,14 +335,14 @@ static int check_free_sectors(struct INFTLrecord *inftl, unsigned int address,
 	for (i = 0; i < len; i += SECTORSIZE) {
 		if (mtd_read(mtd, address, SECTORSIZE, &retlen, buf))
 			return -1;
-		if (memcmpb(buf, 0xff, SECTORSIZE) != 0)
+		if (memchr_inv(buf, 0xff, SECTORSIZE))
 			return -1;
 
 		if (check_oob) {
 			if(inftl_read_oob(mtd, address, mtd->oobsize,
 					  &retlen, &buf[SECTORSIZE]) < 0)
 				return -1;
-			if (memcmpb(buf + SECTORSIZE, 0xff, mtd->oobsize) != 0)
+			if (memchr_inv(buf + SECTORSIZE, 0xff, mtd->oobsize))
 				return -1;
 		}
 		address += SECTORSIZE;
-- 
1.7.4.4


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] mtd/nftlmount: use memchr_inv
  2012-01-27 14:24 [PATCH] powerpc: use string library Akinobu Mita
                   ` (3 preceding siblings ...)
  2012-01-27 14:24 ` [PATCH] mtd/inftlmount: " Akinobu Mita
@ 2012-01-27 14:24 ` Akinobu Mita
  2012-01-27 14:24 ` [PATCH] mtd/tests: " Akinobu Mita
  2012-01-27 14:24 ` [PATCH] mISDN: " Akinobu Mita
  6 siblings, 0 replies; 14+ messages in thread
From: Akinobu Mita @ 2012-01-27 14:24 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: Akinobu Mita, David Woodhouse, linux-mtd

Use memchr_inv to check if the data contains all 0xFF bytes.  It is
faster than looping for each byte.
This also removes memcmpb which is no longer used.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
 drivers/mtd/nftlmount.c |   20 +++++---------------
 1 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
index 51b9d6a..a96bdb4 100644
--- a/drivers/mtd/nftlmount.c
+++ b/drivers/mtd/nftlmount.c
@@ -255,16 +255,6 @@ The new DiskOnChip driver already scanned the bad block table.  Just query it.
 	return boot_record_count?0:-1;
 }
 
-static int memcmpb(void *a, int c, int n)
-{
-	int i;
-	for (i = 0; i < n; i++) {
-		if (c != ((unsigned char *)a)[i])
-			return 1;
-	}
-	return 0;
-}
-
 /* check_free_sector: check if a free sector is actually FREE, i.e. All 0xff in data and oob area */
 static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int len,
 			      int check_oob)
@@ -277,14 +267,14 @@ static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int
 	for (i = 0; i < len; i += SECTORSIZE) {
 		if (mtd_read(mtd, address, SECTORSIZE, &retlen, buf))
 			return -1;
-		if (memcmpb(buf, 0xff, SECTORSIZE) != 0)
+		if (memchr_inv(buf, 0xff, SECTORSIZE))
 			return -1;
 
 		if (check_oob) {
 			if(nftl_read_oob(mtd, address, mtd->oobsize,
 					 &retlen, &buf[SECTORSIZE]) < 0)
 				return -1;
-			if (memcmpb(buf + SECTORSIZE, 0xff, mtd->oobsize) != 0)
+			if (memchr_inv(buf + SECTORSIZE, 0xff, mtd->oobsize))
 				return -1;
 		}
 		address += SECTORSIZE;
@@ -392,7 +382,7 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b
 			case SECTOR_FREE:
 				/* verify that the sector is really free. If not, mark
 				   as ignore */
-				if (memcmpb(&bci, 0xff, 8) != 0 ||
+				if (memchr_inv(&bci, 0xff, 8) ||
 				    check_free_sectors(nftl, block * nftl->EraseSize + i * SECTORSIZE,
 						       SECTORSIZE, 0) != 0) {
 					printk("Incorrect free sector %d in block %d: "
@@ -529,10 +519,10 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
 				return -1;
 			if (i == SECTORSIZE) {
 				/* skip erase mark */
-				if (memcmpb(buf, 0xff, 8))
+				if (memchr_inv(buf, 0xff, 8))
 					return -1;
 			} else {
-				if (memcmpb(buf, 0xff, 16))
+				if (memchr_inv(buf, 0xff, 16))
 					return -1;
 			}
 		}
-- 
1.7.4.4


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] mtd/tests: use memchr_inv
  2012-01-27 14:24 [PATCH] powerpc: use string library Akinobu Mita
                   ` (4 preceding siblings ...)
  2012-01-27 14:24 ` [PATCH] mtd/nftlmount: " Akinobu Mita
@ 2012-01-27 14:24 ` Akinobu Mita
  2012-01-27 14:24 ` [PATCH] mISDN: " Akinobu Mita
  6 siblings, 0 replies; 14+ messages in thread
From: Akinobu Mita @ 2012-01-27 14:24 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: Akinobu Mita, David Woodhouse, linux-mtd

Use memchr_inv to check if the data contains all 0xFF bytes.  It is
faster than looping for each byte.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
---
 drivers/mtd/tests/mtd_pagetest.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index 252ddb0..08847cf 100644
--- a/drivers/mtd/tests/mtd_pagetest.c
+++ b/drivers/mtd/tests/mtd_pagetest.c
@@ -401,6 +401,7 @@ static int erasetest(void)
 	size_t read, written;
 	int err = 0, i, ebnum, ok = 1;
 	loff_t addr0;
+	unsigned char *p;
 
 	printk(PRINT_PREF "erasetest\n");
 
@@ -442,14 +443,13 @@ static int erasetest(void)
 
 	printk(PRINT_PREF "verifying 1st page of block %d is all 0xff\n",
 	       ebnum);
-	for (i = 0; i < pgsize; ++i)
-		if (twopages[i] != 0xff) {
-			printk(PRINT_PREF "verifying all 0xff failed at %d\n",
-			       i);
-			errcnt += 1;
-			ok = 0;
-			break;
-		}
+	p = memchr_inv(twopages, 0xff, pgsize);
+	if (p) {
+		printk(PRINT_PREF "verifying all 0xff failed at %d\n",
+			       p - twopages);
+		errcnt += 1;
+		ok = 0;
+	}
 
 	if (ok && !err)
 		printk(PRINT_PREF "erasetest ok\n");
-- 
1.7.4.4


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH] mISDN: use memchr_inv
  2012-01-27 14:24 [PATCH] powerpc: use string library Akinobu Mita
                   ` (5 preceding siblings ...)
  2012-01-27 14:24 ` [PATCH] mtd/tests: " Akinobu Mita
@ 2012-01-27 14:24 ` Akinobu Mita
  2012-02-01 19:15   ` David Miller
  6 siblings, 1 reply; 14+ messages in thread
From: Akinobu Mita @ 2012-01-27 14:24 UTC (permalink / raw)
  To: linux-kernel, akpm; +Cc: Akinobu Mita, Karsten Keil, netdev

Use memchr_inv to check if the data contains all same bytes.  It is
faster than looping for each byte.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: netdev@vger.kernel.org
---
 drivers/isdn/mISDN/l1oip_core.c |   16 +++-------------
 1 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/isdn/mISDN/l1oip_core.c b/drivers/isdn/mISDN/l1oip_core.c
index 22f8ec8..04f115a 100644
--- a/drivers/isdn/mISDN/l1oip_core.c
+++ b/drivers/isdn/mISDN/l1oip_core.c
@@ -1112,7 +1112,7 @@ handle_bmsg(struct mISDNchannel *ch, struct sk_buff *skb)
 	struct l1oip			*hc = bch->hw;
 	int			ret = -EINVAL;
 	struct mISDNhead	*hh = mISDN_HEAD_P(skb);
-	int			l, ll, i;
+	int			l, ll;
 	unsigned char		*p;
 
 	switch (hh->prim) {
@@ -1128,13 +1128,8 @@ handle_bmsg(struct mISDNchannel *ch, struct sk_buff *skb)
 			break;
 		}
 		/* check for AIS / ulaw-silence */
-		p = skb->data;
 		l = skb->len;
-		for (i = 0; i < l; i++) {
-			if (*p++ != 0xff)
-				break;
-		}
-		if (i == l) {
+		if (!memchr_inv(skb->data, 0xff, l)) {
 			if (debug & DEBUG_L1OIP_MSG)
 				printk(KERN_DEBUG "%s: got AIS, not sending, "
 					"but counting\n", __func__);
@@ -1144,13 +1139,8 @@ handle_bmsg(struct mISDNchannel *ch, struct sk_buff *skb)
 			return 0;
 		}
 		/* check for silence */
-		p = skb->data;
 		l = skb->len;
-		for (i = 0; i < l; i++) {
-			if (*p++ != 0x2a)
-				break;
-		}
-		if (i == l) {
+		if (!memchr_inv(skb->data, 0x2a, l)) {
 			if (debug & DEBUG_L1OIP_MSG)
 				printk(KERN_DEBUG "%s: got silence, not sending"
 					", but counting\n", __func__);
-- 
1.7.4.4


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd/nand: use string library
  2012-01-27 14:24 ` [PATCH] mtd/nand: " Akinobu Mita
@ 2012-01-27 17:16   ` Joe Perches
  2012-01-27 18:52     ` Brian Norris
  0 siblings, 1 reply; 14+ messages in thread
From: Joe Perches @ 2012-01-27 17:16 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-kernel, akpm, Jiandong Zheng, Scott Branden,
	David Woodhouse, linux-mtd

On Fri, 2012-01-27 at 23:24 +0900, Akinobu Mita wrote:
> - Use memchr_inv to check if the data contains all 0xFF bytes.
>   It is faster than looping for each byte.

Stupid question:

Are there any mtd devices modified that are slower
at 64 bit accesses than repeated 8 bit accesses?


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd/nand: use string library
  2012-01-27 17:16   ` Joe Perches
@ 2012-01-27 18:52     ` Brian Norris
  2012-01-27 23:52       ` Akinobu Mita
  0 siblings, 1 reply; 14+ messages in thread
From: Brian Norris @ 2012-01-27 18:52 UTC (permalink / raw)
  To: Joe Perches
  Cc: Akinobu Mita, Scott Branden, linux-kernel, linux-mtd,
	Jiandong Zheng, akpm, David Woodhouse

On Fri, Jan 27, 2012 at 9:16 AM, Joe Perches <joe@perches.com> wrote:
> On Fri, 2012-01-27 at 23:24 +0900, Akinobu Mita wrote:
>> - Use memchr_inv to check if the data contains all 0xFF bytes.
>>   It is faster than looping for each byte.
>
> Stupid question:
>
> Are there any mtd devices modified that are slower
> at 64 bit accesses than repeated 8 bit accesses?

I believe this patch deals with kernel buffers, not any kind of direct
access to the MTD, so the question (which is not stupid IMO) should be
regarding CPU architectures. And my educated guess is that 64-bit
access should not be any slower. I do know that 8-bit access *is*
slower for some relevant architectures.

Brian

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd/nand: use string library
  2012-01-27 18:52     ` Brian Norris
@ 2012-01-27 23:52       ` Akinobu Mita
  2012-01-31 17:57         ` Brian Norris
  0 siblings, 1 reply; 14+ messages in thread
From: Akinobu Mita @ 2012-01-27 23:52 UTC (permalink / raw)
  To: Brian Norris
  Cc: Joe Perches, Scott Branden, linux-kernel, linux-mtd,
	Jiandong Zheng, akpm, David Woodhouse, eric.dumazet

2012/1/28 Brian Norris <computersforpeace@gmail.com>:
> On Fri, Jan 27, 2012 at 9:16 AM, Joe Perches <joe@perches.com> wrote:
>> On Fri, 2012-01-27 at 23:24 +0900, Akinobu Mita wrote:
>>> - Use memchr_inv to check if the data contains all 0xFF bytes.
>>>   It is faster than looping for each byte.
>>
>> Stupid question:
>>
>> Are there any mtd devices modified that are slower
>> at 64 bit accesses than repeated 8 bit accesses?
>
> I believe this patch deals with kernel buffers, not any kind of direct
> access to the MTD, so the question (which is not stupid IMO) should be
> regarding CPU architectures. And my educated guess is that 64-bit
> access should not be any slower. I do know that 8-bit access *is*
> slower for some relevant architectures.

It could be slower when the number of bytes scanned is very small
(found a unmatched character immediately, or the size of the area
is very small), because memchr_inv() needs to generate a 64bit pattern
to compare before starting the loop.  I recalled that Eric Dumazet
pointed out it could generate the 64bit pattern more efficiently.
(https://lkml.org/lkml/2011/8/8/480)

Even if that small scanning is slower, this change can be assumed cleanup
patch that simplifies the code.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd/nand: use string library
  2012-01-27 23:52       ` Akinobu Mita
@ 2012-01-31 17:57         ` Brian Norris
  2012-02-01 13:11           ` Akinobu Mita
  0 siblings, 1 reply; 14+ messages in thread
From: Brian Norris @ 2012-01-31 17:57 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: Joe Perches, Scott Branden, linux-kernel, linux-mtd,
	Jiandong Zheng, akpm, David Woodhouse, eric.dumazet

On Fri, Jan 27, 2012 at 3:52 PM, Akinobu Mita <akinobu.mita@gmail.com> wrote:
> 2012/1/28 Brian Norris <computersforpeace@gmail.com>:
>> On Fri, Jan 27, 2012 at 9:16 AM, Joe Perches <joe@perches.com> wrote:
>>> On Fri, 2012-01-27 at 23:24 +0900, Akinobu Mita wrote:
>>>> - Use memchr_inv to check if the data contains all 0xFF bytes.
>>>>   It is faster than looping for each byte.
>>>
>>> Stupid question:
>>>
>>> Are there any mtd devices modified that are slower
>>> at 64 bit accesses than repeated 8 bit accesses?
>>
>> I believe this patch deals with kernel buffers, not any kind of direct
>> access to the MTD, so the question (which is not stupid IMO) should be
>> regarding CPU architectures. And my educated guess is that 64-bit
>> access should not be any slower. I do know that 8-bit access *is*
>> slower for some relevant architectures.
>
> It could be slower when the number of bytes scanned is very small
> (found a unmatched character immediately, or the size of the area
> is very small), because memchr_inv() needs to generate a 64bit pattern
> to compare before starting the loop.  I recalled that Eric Dumazet
> pointed out it could generate the 64bit pattern more efficiently.
> (https://lkml.org/lkml/2011/8/8/480)
>
> Even if that small scanning is slower, this change can be assumed cleanup
> patch that simplifies the code.

Well, I agree that it qualifies as cleanup as well, but we should at
least make an attempt not to cause performance regression...

So by my understanding, the use of memchr_inv() is on buffers of
minimum length of 10 in this patch, so we're likely to have decent
results. And memcmp() usage looks fine to me.

So unless other concerns arise:

Acked-by: Brian Norris <computersforpeace@gmail.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mtd/nand: use string library
  2012-01-31 17:57         ` Brian Norris
@ 2012-02-01 13:11           ` Akinobu Mita
  0 siblings, 0 replies; 14+ messages in thread
From: Akinobu Mita @ 2012-02-01 13:11 UTC (permalink / raw)
  To: Brian Norris
  Cc: Joe Perches, Scott Branden, linux-kernel, linux-mtd,
	Jiandong Zheng, akpm, David Woodhouse, eric.dumazet

2012/2/1 Brian Norris <computersforpeace@gmail.com>:
> On Fri, Jan 27, 2012 at 3:52 PM, Akinobu Mita <akinobu.mita@gmail.com> wrote:
>> 2012/1/28 Brian Norris <computersforpeace@gmail.com>:
>>> On Fri, Jan 27, 2012 at 9:16 AM, Joe Perches <joe@perches.com> wrote:
>>>> On Fri, 2012-01-27 at 23:24 +0900, Akinobu Mita wrote:
>>>>> - Use memchr_inv to check if the data contains all 0xFF bytes.
>>>>>   It is faster than looping for each byte.
>>>>
>>>> Stupid question:
>>>>
>>>> Are there any mtd devices modified that are slower
>>>> at 64 bit accesses than repeated 8 bit accesses?
>>>
>>> I believe this patch deals with kernel buffers, not any kind of direct
>>> access to the MTD, so the question (which is not stupid IMO) should be
>>> regarding CPU architectures. And my educated guess is that 64-bit
>>> access should not be any slower. I do know that 8-bit access *is*
>>> slower for some relevant architectures.
>>
>> It could be slower when the number of bytes scanned is very small
>> (found a unmatched character immediately, or the size of the area
>> is very small), because memchr_inv() needs to generate a 64bit pattern
>> to compare before starting the loop.  I recalled that Eric Dumazet
>> pointed out it could generate the 64bit pattern more efficiently.
>> (https://lkml.org/lkml/2011/8/8/480)
>>
>> Even if that small scanning is slower, this change can be assumed cleanup
>> patch that simplifies the code.
>
> Well, I agree that it qualifies as cleanup as well, but we should at
> least make an attempt not to cause performance regression...
>
> So by my understanding, the use of memchr_inv() is on buffers of
> minimum length of 10 in this patch, so we're likely to have decent
> results. And memcmp() usage looks fine to me.

Sorry, I answered without checking memchr_inv() carefully.  If the size
of buffer is less than 16 bytes, memchr_inv() scans for each byte as the
original code did.  So it is unlikely to be slower in the most cases.

But I mentioned in the previous email, there are some problems in
memchr_inv().  I'll send the patch in a few days.

> So unless other concerns arise:
>
> Acked-by: Brian Norris <computersforpeace@gmail.com>

Thanks.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] mISDN: use memchr_inv
  2012-01-27 14:24 ` [PATCH] mISDN: " Akinobu Mita
@ 2012-02-01 19:15   ` David Miller
  0 siblings, 0 replies; 14+ messages in thread
From: David Miller @ 2012-02-01 19:15 UTC (permalink / raw)
  To: akinobu.mita; +Cc: linux-kernel, akpm, isdn, netdev

From: Akinobu Mita <akinobu.mita@gmail.com>
Date: Fri, 27 Jan 2012 23:24:55 +0900

> Use memchr_inv to check if the data contains all same bytes.  It is
> faster than looping for each byte.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-02-01 19:16 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-27 14:24 [PATCH] powerpc: use string library Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/nand: " Akinobu Mita
2012-01-27 17:16   ` Joe Perches
2012-01-27 18:52     ` Brian Norris
2012-01-27 23:52       ` Akinobu Mita
2012-01-31 17:57         ` Brian Norris
2012-02-01 13:11           ` Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/onenand: " Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/ubi: use memchr_inv Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/inftlmount: " Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/nftlmount: " Akinobu Mita
2012-01-27 14:24 ` [PATCH] mtd/tests: " Akinobu Mita
2012-01-27 14:24 ` [PATCH] mISDN: " Akinobu Mita
2012-02-01 19:15   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).