Commit b9420e1c authored by David Laight's avatar David Laight Committed by David S. Miller

net: sctp: Optimise the way 'sctp_arg_t' values are initialised.

Even if memset() is inlined (as on x86) using it to zero the union
generates a memory word write of zero, followed by a write of the
smaller field, and then a read of the word.
As well as being a lot of instructions the sequence is unlikely to
be optimised by the store-load forward hardware so will be slow.

Instead allocate a field of the union that is the same size as the
entire union and write a zero value to it. The compiler will then
generate the required value in a register.

Zeroing the union shouldn't be necessary, but this patch series isn't
intended to have a behavioural change.
Signed-off-by: default avatarDavid Laight <david.laight@aculab.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent be1f4f48
...@@ -118,6 +118,7 @@ typedef enum { ...@@ -118,6 +118,7 @@ typedef enum {
#define SCTP_MAX_NUM_COMMANDS 14 #define SCTP_MAX_NUM_COMMANDS 14
typedef union { typedef union {
void *zero_all; /* Set to NULL to clear the entire union */
__s32 i32; __s32 i32;
__u32 u32; __u32 u32;
__be32 be32; __be32 be32;
...@@ -154,7 +155,7 @@ typedef union { ...@@ -154,7 +155,7 @@ typedef union {
static inline sctp_arg_t \ static inline sctp_arg_t \
SCTP_## name (type arg) \ SCTP_## name (type arg) \
{ sctp_arg_t retval;\ { sctp_arg_t retval;\
memset(&retval, 0, sizeof(sctp_arg_t));\ retval.zero_all = NULL;\
retval.elt = arg;\ retval.elt = arg;\
return retval;\ return retval;\
} }
...@@ -191,7 +192,7 @@ static inline sctp_arg_t SCTP_NOFORCE(void) ...@@ -191,7 +192,7 @@ static inline sctp_arg_t SCTP_NOFORCE(void)
static inline sctp_arg_t SCTP_NULL(void) static inline sctp_arg_t SCTP_NULL(void)
{ {
sctp_arg_t retval; sctp_arg_t retval;
memset(&retval, 0, sizeof(sctp_arg_t)); retval.zero_all = NULL;
return retval; return retval;
} }
...@@ -212,7 +213,8 @@ typedef struct { ...@@ -212,7 +213,8 @@ typedef struct {
*/ */
static inline int sctp_init_cmd_seq(sctp_cmd_seq_t *seq) static inline int sctp_init_cmd_seq(sctp_cmd_seq_t *seq)
{ {
memset(seq, 0, sizeof(sctp_cmd_seq_t)); seq->next_free_slot = 0;
seq->next_cmd = 0;
return 1; /* We always succeed. */ return 1; /* We always succeed. */
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment