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

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 |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
index 1e003c9..c19faaf 100644
--- a/kernel/cobalt/posix/nsem.c
+++ b/kernel/cobalt/posix/nsem.c
@@ -25,6 +25,7 @@
 
 static struct hlist_head *nsem_hash;
 DEFINE_XNLOCK(nsem_lock);
+static unsigned mm_mult, mm_shift, nsem_hash_size;
 
 struct nsem {
        struct cobalt_sem *sem;
@@ -38,8 +39,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 +135,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 +292,17 @@ 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]);
+
+       i = int_sqrt(nsem_hash_size);
+       mm_shift = 32 - fls(i);
+       mm_mult = (i << mm_shift) / sizeof(struct mm_struct);
        
        return 0;
 }


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

Reply via email to