public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frank Seidel <fseidel@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Jiri Slaby <jirislaby@gmail.com>, Adrian Bunk <bunk@kernel.org>
Subject: Re: [RFC 13/13] Char: nozomi, cleanup read and write
Date: Sun, 11 Nov 2007 17:02:51 +0100	[thread overview]
Message-ID: <200711111702.53191.fseidel@suse.de> (raw)
In-Reply-To: <200711110337.29831.fseidel@suse.de>

On Sonntag 11 November 2007 03:37:28, you (Frank Seidel) wrote:
> While in the read_mem32 the unlikekly really seems to be of no use at all (the
> switch-case ahead seems to be hit nearly always), the unlikely in the 
> write_mem32 seems to be fine.
> I compared after each 30 seconds and got median ratio of 1381:1 (for the
> likely path) after about 20 minutes, i see a range between 1046:1 and
> 3511:1. So i wouldn't call it a bad guess from my beginners point of view.

I even did some more tracking which pathes get used in there with what
size_bytes values for write_mem32. To what i could see i get about
50% of the calls with size_bytes == 4 (what gets handled in the
switch-case shortcut), about 30% of the calls with size_bytes == 1 (
so i also added a shortcut for this which was just one line) and the
remaining calls (not handled in the switch-case ahead) still reach
a ratio of about 800:1 for the 4-byte-case to the (unlikely) 2-byte-
case.

So i did a rework of that patch which is nearly as nice as Jiris,
but works here without problems and has the size_bytes 1 shortcut,
plus the "unlikely" for the remaining 2-bytes path.

I know the format of the patch isn't fully correct, but i'll integrate
it into the complete patch und polish it there before posting that
again.

Thanks a lot,
Frank
---
Index: linux/drivers/char/nozomi.c
===================================================================
--- linux.orig/drivers/char/nozomi.c
+++ linux/drivers/char/nozomi.c
@@ -104,6 +104,7 @@
 #include <linux/list.h>
 #include <linux/uaccess.h>
 #include <asm/atomic.h>
+#include <asm/byteorder.h>
 
 #include <linux/delay.h>
 
@@ -265,7 +266,7 @@ enum port_type {
 	PORT_ERROR	= -1,
 };
 
-#ifdef __ARMEB__
+#ifdef __BIG_ENDIAN
 /* Big endian */
 
 struct toggles {
@@ -547,11 +548,7 @@ static void read_mem32(u32 *buf, const v
 			u32 size_bytes)
 {
 	u32 i = 0;
-#ifdef __ARMEB__
-	const u32 *ptr = (u32 *) mem_addr_start;
-#else
 	const u32 *ptr = (__force u32 *) mem_addr_start;
-#endif
 	u16 *buf16;
 
 	if (unlikely(!ptr || !buf))
@@ -561,19 +558,11 @@ static void read_mem32(u32 *buf, const v
 	switch (size_bytes) {
 	case 2:	/* 2 bytes */
 		buf16 = (u16 *) buf;
-#ifdef __ARMEB__
-		*buf16 = __le16_to_cpu(readw(ptr));
-#else
-		*buf16 = readw((void __iomem *)ptr);
-#endif
+		*buf16 = __le16_to_cpu(readw((void __iomem *)ptr));
 		goto out;
 		break;
 	case 4:	/* 4 bytes */
-#ifdef __ARMEB__
-		*(buf) = __le32_to_cpu(readl(ptr));
-#else
-		*(buf) = readl((void __iomem *)ptr);
-#endif
+		*(buf) = __le32_to_cpu(readl((void __iomem *)ptr));
 		goto out;
 		break;
 	}
@@ -582,19 +571,11 @@ static void read_mem32(u32 *buf, const v
 		if (size_bytes - i == 2) {
 			/* Handle 2 bytes in the end */
 			buf16 = (u16 *) buf;
-#ifdef __ARMEB__
-			*(buf16) = __le16_to_cpu(readw(ptr));
-#else
-			*(buf16) = readw((void __iomem *)ptr);
-#endif
+			*(buf16) = __le16_to_cpu(readw((void __iomem *)ptr));
 			i += 2;
 		} else {
 			/* Read 4 bytes */
-#ifdef __ARMEB__
-			*(buf) = __le32_to_cpu(readl(ptr));
-#else
-			*(buf) = readl((void __iomem *)ptr);
-#endif
+			*(buf) = __le32_to_cpu(readl((void __iomem *)ptr));
 			i += 4;
 		}
 		buf++;
@@ -613,11 +594,7 @@ static u32 write_mem32(void __iomem *mem
 			u32 size_bytes)
 {
 	u32 i = 0;
-#ifdef __ARMEB__
-	u32 *ptr = (u32 *) mem_addr_start;
-#else
 	u32 *ptr = (__force u32 *) mem_addr_start;
-#endif
 	u16 *buf16;
 
 	if (unlikely(!ptr || !buf))
@@ -627,40 +604,28 @@ static u32 write_mem32(void __iomem *mem
 	switch (size_bytes) {
 	case 2:	/* 2 bytes */
 		buf16 = (u16 *) buf;
-#ifdef __ARMEB__
-		writew(__le16_to_cpu(*buf16), ptr);
-#else
-		writew(*buf16, (void __iomem *)ptr);
-#endif
+		writew(__cpu_to_le16(*buf16), (void __iomem *)ptr);
 		return 2;
 		break;
+	case 1:
+		/* also need to write 4 bytes in this case
+		 * so falling through..
+		 */
 	case 4: /* 4 bytes */
-#ifdef __ARMEB__
-		writel(__cpu_to_le32(*buf), ptr);
-#else
-		writel(*buf, (void __iomem *)ptr);
-#endif
+		writel(__cpu_to_le32(*buf), (void __iomem *)ptr);
 		return 4;
 		break;
 	}
 
 	while (i < size_bytes) {
-		if (size_bytes - i == 2) {
+		if (unlikely(size_bytes - i == 2)) {
 			/* 2 bytes */
 			buf16 = (u16 *) buf;
-#ifdef __ARMEB__
-			writew(__le16_to_cpu(*buf16), ptr);
-#else
-			writew(*buf16, (void __iomem *)ptr);
-#endif
+			writew(__cpu_to_le16(*buf16), (void __iomem *)ptr);
 			i += 2;
 		} else {
 			/* 4 bytes */
-#ifdef __ARMEB__
-			writel(__cpu_to_le32(*buf), ptr);
-#else
-			writel(*buf, (void __iomem *)ptr);
-#endif
+			writel(__cpu_to_le32(*buf), (void __iomem *)ptr);
 			i += 4;
 		}
 		buf++;

  reply	other threads:[~2007-11-11 16:03 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-09 23:43 [RFC 1/13] Char: nozomi, remove unneded stuff Jiri Slaby
2007-11-09 23:44 ` [RFC 2/13] Char: nozomi, expand some functions Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-09 23:44 ` [RFC 3/13] Char: nozomi, fix fail paths Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-09 23:45 ` [RFC 4/13] Char: nozomi, tty index cleanup Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-10 15:50     ` Jiri Slaby
2007-11-09 23:46 ` [RFC 5/13] Char: nozomi, ioctls cleanup Jiri Slaby
2007-11-10 15:41   ` Frank Seidel
2007-11-09 23:46 ` [RFC 6/13] Char: nozomi, reorder and cleanup probe, remove Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-09 23:47 ` [RFC 7/13] Char: nozomi, remove struct irq Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-12 15:11   ` Frank Seidel
2007-11-09 23:48 ` [RFC 8/13] Char: nozomi, tty cleanup Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-12 18:43   ` Frank Seidel
2007-11-09 23:48 ` [RFC 9/13] Char: nozomi, lock cleanup Jiri Slaby
2007-11-10 15:42   ` Frank Seidel
2007-11-09 23:49 ` [RFC! 10/13] Char: nozomi, fix tty_flip_buffer_push Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-09 23:50 ` [RFC 11/13] Char: nozomi, remove unused includes Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-09 23:50 ` [RFC 12/13] Char: nozomi, remove void acc char2 char3 more mp mp.c mp.yy m1 nozomi2 proto rej slock1 casts Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-09 23:51 ` [RFC 13/13] Char: nozomi, cleanup read and write Jiri Slaby
2007-11-10 15:43   ` Frank Seidel
2007-11-10 16:15   ` Adrian Bunk
2007-11-10 22:04     ` Jiri Slaby
2007-11-11  2:37       ` Frank Seidel
2007-11-11 16:02         ` Frank Seidel [this message]
2007-11-12  7:54       ` Adrian Bunk
2007-11-12  9:43         ` Frank Seidel
2007-11-10 15:41 ` [RFC 1/13] Char: nozomi, remove unneded stuff Frank Seidel
2007-11-10 15:55   ` Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200711111702.53191.fseidel@suse.de \
    --to=fseidel@suse.de \
    --cc=bunk@kernel.org \
    --cc=jirislaby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox