From: Nick Piggin <npiggin@suse.de>
To: Manfred Spraul <manfred@colorfullife.com>, linux-kernel@vger.kernel.org
Subject: [patch 2/3] ipc: use shifts to extract seq/idx
Date: Thu, 20 May 2010 17:00:04 +1000 [thread overview]
Message-ID: <20100520070004.GH2516@laptop> (raw)
In-Reply-To: <20100520065911.GG2516@laptop>
All the ipc ids and sequences are signed integers, so power of 2
sequence multiplier does not work so well. Convert it to use shifts,
which improves generated code particularly in ipc_lock/ipc_lock_check
fast paths.
Index: linux-2.6/ipc/util.c
===================================================================
--- linux-2.6.orig/ipc/util.c
+++ linux-2.6/ipc/util.c
@@ -123,7 +123,7 @@ void ipc_init_ids(struct ipc_ids *ids)
ids->in_use = 0;
ids->seq = 0;
{
- int seq_limit = INT_MAX/SEQ_MULTIPLIER;
+ int seq_limit = INT_MAX >> SEQ_SHIFT;
if (seq_limit > USHORT_MAX)
ids->seq_max = USHORT_MAX;
else
Index: linux-2.6/ipc/util.h
===================================================================
--- linux-2.6.orig/ipc/util.h
+++ linux-2.6/ipc/util.h
@@ -13,9 +13,11 @@
#include <linux/unistd.h>
#include <linux/err.h>
-#define IPCMNI_MAX 32768 /* <= MAX_INT absolute limit for ipc arrays */
+/* IPCMNI_MAX should be <= MAX_INT, absolute limit for ipc arrays */
+#define IPCMNI_MAX_SHIFT 15
+#define IPCMNI_MAX (1 << IPCMNI_MAX_SHIFT)
-#define SEQ_MULTIPLIER (IPCMNI_MAX)
+#define SEQ_SHIFT IPCMNI_MAX_SHIFT
void sem_init (void);
void msg_init (void);
@@ -93,7 +95,7 @@ void __init ipc_init_proc_interface(cons
#define IPC_MSG_IDS 1
#define IPC_SHM_IDS 2
-#define ipcid_to_idx(id) ((id) % SEQ_MULTIPLIER)
+#define ipcid_to_idx(id) ((id) & ((1UL << SEQ_SHIFT) - 1))
/* must be called with ids->rw_mutex acquired for writing */
int ipc_addid(struct ipc_ids *, struct kern_ipc_perm *, int);
@@ -146,7 +148,7 @@ extern void recompute_msgmni(struct ipc_
static inline int ipc_buildid(int id, int seq)
{
- return SEQ_MULTIPLIER * seq + id;
+ return (seq << SEQ_SHIFT) + id;
}
/*
@@ -154,7 +156,7 @@ static inline int ipc_buildid(int id, in
*/
static inline int ipc_checkid(struct kern_ipc_perm *ipcp, int uid)
{
- if (uid / SEQ_MULTIPLIER != ipcp->seq)
+ if ((uid >> SEQ_SHIFT) != ipcp->seq)
return 1;
return 0;
}
next prev parent reply other threads:[~2010-05-20 7:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-20 6:59 [patch 1/3] ipc: rename IPCMNI to IPCMNI_MAX Nick Piggin
2010-05-20 7:00 ` Nick Piggin [this message]
2010-05-20 18:16 ` [patch 2/3] ipc: use shifts to extract seq/idx Manfred Spraul
2010-05-21 1:33 ` Nick Piggin
2010-05-20 7:07 ` [patch 3/3] ipc: increase IPCMNI_MAX Nick Piggin
2010-05-21 20:31 ` Andrew Morton
2010-05-24 7:43 ` Nick Piggin
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=20100520070004.GH2516@laptop \
--to=npiggin@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
/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;
as well as URLs for NNTP newsgroup(s).