Module: xenomai-gch
Branch: for-forge
Commit: 79ba7c08c3ac6c0acc8bc4c8ab243e1e90ce7e54
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=79ba7c08c3ac6c0acc8bc4c8ab243e1e90ce7e54

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Fri Dec 20 00:33:49 2013 +0100

to be merged with sem commit: less naive hash function

---

 kernel/cobalt/posix/nsem.c |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
index 1e003c9..58ef5e9 100644
--- a/kernel/cobalt/posix/nsem.c
+++ b/kernel/cobalt/posix/nsem.c
@@ -25,6 +25,8 @@
 
 static struct hlist_head *nsem_hash;
 DEFINE_XNLOCK(nsem_lock);
+static unsigned mm_mult, nsem_hash_size;
+#define MM_SHIFT 20
 
 struct nsem {
        struct cobalt_sem *sem;
@@ -38,8 +40,9 @@ struct nsem {
 static unsigned __attribute__((pure)) 
 nsem_hash_crunch(xnhandle_t handle, struct mm_struct *mm)
 {
-       unsigned hash = handle + (unsigned long)mm / sizeof(struct mm_struct);
-       return hash % CONFIG_XENO_OPT_REGISTRY_NRSLOTS;
+       unsigned long hash = (unsigned long)mm;
+       hash = handle + (((unsigned long long)hash * mm_mult) >> MM_SHIFT);
+       return hash % nsem_hash_size;
 }
 
 static struct nsem *
@@ -133,6 +136,7 @@ nsem_open(struct __shadow_sem __user *ushadow, const char 
*name,
                        return ERR_PTR(-EFAULT);
                }
                handle = shadow.handle;
+               break;
 
        default:
                return ERR_PTR(rc);
@@ -289,13 +293,18 @@ int cobalt_nsem_pkg_init(void)
 {
        unsigned i;
        
-       nsem_hash = kmalloc(CONFIG_XENO_OPT_REGISTRY_NRSLOTS *
-                       sizeof(*nsem_hash), GFP_KERNEL);
+       nsem_hash_size = xnregistry_hash_size();
+       nsem_hash = kmalloc(nsem_hash_size * sizeof(*nsem_hash), GFP_KERNEL);
        if (nsem_hash == NULL)
                return -ENOMEM;
        
-       for (i = 0; i < CONFIG_XENO_OPT_REGISTRY_NRSLOTS; i++)
+       for (i = 0; i < nsem_hash_size; i++)
                INIT_HLIST_HEAD(&nsem_hash[i]);
+
+       mm_mult = (int_sqrt(nsem_hash_size) << MM_SHIFT) 
+               / sizeof(struct mm_struct);
+       if (mm_mult == 0)
+               mm_mult = 5;
        
        return 0;
 }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to