Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
[linux-2.6-microblaze.git] / include / linux / sbitmap.h
index c65ba88..2713e68 100644 (file)
@@ -324,7 +324,7 @@ static inline void sbitmap_put(struct sbitmap *sb, unsigned int bitnr)
        sbitmap_deferred_clear_bit(sb, bitnr);
 
        if (likely(sb->alloc_hint && !sb->round_robin && bitnr < sb->depth))
-               *this_cpu_ptr(sb->alloc_hint) = bitnr;
+               *raw_cpu_ptr(sb->alloc_hint) = bitnr;
 }
 
 static inline int sbitmap_test_bit(struct sbitmap *sb, unsigned int bitnr)
@@ -332,6 +332,24 @@ static inline int sbitmap_test_bit(struct sbitmap *sb, unsigned int bitnr)
        return test_bit(SB_NR_TO_BIT(sb, bitnr), __sbitmap_word(sb, bitnr));
 }
 
+static inline int sbitmap_calculate_shift(unsigned int depth)
+{
+       int     shift = ilog2(BITS_PER_LONG);
+
+       /*
+        * If the bitmap is small, shrink the number of bits per word so
+        * we spread over a few cachelines, at least. If less than 4
+        * bits, just forget about it, it's not going to work optimally
+        * anyway.
+        */
+       if (depth >= 4) {
+               while ((4U << shift) > depth)
+                       shift--;
+       }
+
+       return shift;
+}
+
 /**
  * sbitmap_show() - Dump &struct sbitmap information to a &struct seq_file.
  * @sb: Bitmap to show.