netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Fwd: [PATCH] [TIPC]: Enhancements to msg_set_bits() routine]
@ 2007-04-24 18:56 Jon Paul Maloy
  2007-04-25 16:39 ` Ingo Oeser
  0 siblings, 1 reply; 3+ messages in thread
From: Jon Paul Maloy @ 2007-04-24 18:56 UTC (permalink / raw)
  To: davem, netdev, Jon Paul Maloy, Per Liden, Stephens, Allan

[-- Attachment #1: Type: text/plain, Size: 813 bytes --]

This patch makes two enhancements to msg_set_bits():

1) It now ignores any bits of the new field value that are not
   covered by the mask being used.  (Previously, if the new value
   exceeded the size of the mask the extra bits could corrupt
   other fields in the message header word being updated.)

2) The code has been optimized to minimize the number of run-time
   endianness conversion operations by leveraging the fact that the
   mask (and, in some cases, the value as well) is constant and the
   necessary conversion can be performed by the compiler.

Apply the attached patch, or pull from:

 git://tipc.cslab.ericsson.net/pub/git/tipc.git

 (rebased on linux/kernel/git/davem/net-2.6.git)

Summary:

 net/tipc/msg.h |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)


///Jon




[-- Attachment #2: 0001-TIPC-Enhancements-to-msg_set_bits-routine.patch --]
[-- Type: text/x-patch, Size: 1894 bytes --]

>From 1c3c79c4c79aa8a665ddf41c08b4363cbb946950 Mon Sep 17 00:00:00 2001
From: Jon Paul Maloy <jon.maloy@ericsson.com>
Date: Mon, 23 Apr 2007 11:49:07 -0400
Subject: [PATCH 1/1] [TIPC]: Enhancements to msg_set_bits() routine

This patch makes two enhancements to msg_set_bits():

1) It now ignores any bits of the new field value that are not
   covered by the mask being used.  (Previously, if the new value
   exceeded the size of the mask the extra bits could corrupt
   other fields in the message header word being updated.)

2) The code has been optimized to minimize the number of run-time
   endianness conversion operations by leveraging the fact that the
   mask (and, in some cases, the value as well) is constant and the
   necessary conversion can be performed by the compiler.

Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Jon Paul Maloy <jon.maloy@ericsson.com>
---
 net/tipc/msg.h |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/tipc/msg.h b/net/tipc/msg.h
index 62d5490..5c64e55 100644
--- a/net/tipc/msg.h
+++ b/net/tipc/msg.h
@@ -1,8 +1,8 @@
 /*
  * net/tipc/msg.h: Include file for TIPC message header routines
  *
- * Copyright (c) 2000-2006, Ericsson AB
- * Copyright (c) 2005, Wind River Systems
+ * Copyright (c) 2000-2007, Ericsson AB
+ * Copyright (c) 2005-2007, Wind River Systems
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -71,8 +71,11 @@ static inline void msg_set_word(struct tipc_msg *m, u32 w, u32 val)
 static inline void msg_set_bits(struct tipc_msg *m, u32 w,
 				u32 pos, u32 mask, u32 val)
 {
-	u32 word = msg_word(m,w) & ~(mask << pos);
-	msg_set_word(m, w, (word |= (val << pos)));
+	val = (val & mask) << pos;
+	val = htonl(val);
+	mask = htonl(mask << pos);
+	m->hdr[w] &= ~mask;
+	m->hdr[w] |= val;
 }
 
 /*
-- 
1.5.0.5



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

* Re: [Fwd: [PATCH] [TIPC]: Enhancements to msg_set_bits() routine]
  2007-04-24 18:56 [Fwd: [PATCH] [TIPC]: Enhancements to msg_set_bits() routine] Jon Paul Maloy
@ 2007-04-25 16:39 ` Ingo Oeser
       [not found]   ` <462FBADA.2060701@ericsson.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Oeser @ 2007-04-25 16:39 UTC (permalink / raw)
  To: Jon Paul Maloy; +Cc: davem, netdev, Per Liden, Stephens, Allan

Hi Jon,

Jon Paul Maloy schrieb:
> 2) The code has been optimized to minimize the number of run-time
>    endianness conversion operations by leveraging the fact that the
>    mask (and, in some cases, the value as well) is constant and the
>    necessary conversion can be performed by the compiler.

3) It can be checked by sparse, if you use proper types.
 
> diff --git a/net/tipc/msg.h b/net/tipc/msg.h
> index 62d5490..5c64e55 100644
> --- a/net/tipc/msg.h
> +++ b/net/tipc/msg.h
> @@ -71,8 +71,11 @@ static inline void msg_set_word(struct tipc_msg *m, u32
> w, u32 val) static inline void msg_set_bits(struct tipc_msg *m, u32 w,
>  				u32 pos, u32 mask, u32 val)

static inlinevoid msg_set_bits(struct tipc_msg *m, u32 w,
  				u32 pos, __be32 mask, __be32 val)


Care to resubmit?


Best Regards

Ingo Oeser

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

* Re: [Fwd: [PATCH] [TIPC]: Enhancements to msg_set_bits() routine]
       [not found]   ` <462FBADA.2060701@ericsson.com>
@ 2007-04-27 11:06     ` Ingo Oeser
  0 siblings, 0 replies; 3+ messages in thread
From: Ingo Oeser @ 2007-04-27 11:06 UTC (permalink / raw)
  To: Jon Paul Maloy; +Cc: davem, netdev, Jon Paul Maloy, Per Liden, Stephens, Allan

Hi Jon,

Jon Paul Maloy schrieb:
> Ingo Oeser wrote:
> > static inlinevoid msg_set_bits(struct tipc_msg *m, u32 w,
> >   				u32 pos, __be32 mask, __be32 val)
> >
> >
> > Care to resubmit?

> I don't mind at all, but I would first like to understand better
> what this means. 
> If I understand it correctly __be32 literally means "big-endian
> 32-bit integer", but the way it is used doesn't seem to imply this,
> since both input and output to htonl() often is of that type.

Yes, you are right! I mixed up htonl and ntohl :-)
Sorry for the confusion!

Best Regards

Ingo Oeser

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

end of thread, other threads:[~2007-04-27 11:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-24 18:56 [Fwd: [PATCH] [TIPC]: Enhancements to msg_set_bits() routine] Jon Paul Maloy
2007-04-25 16:39 ` Ingo Oeser
     [not found]   ` <462FBADA.2060701@ericsson.com>
2007-04-27 11:06     ` Ingo Oeser

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).