ftrace: Use fls() to get the bits for dup_hash()
authorWei Yang <richard.weiyang@linux.alibaba.com>
Mon, 31 Aug 2020 03:11:00 +0000 (11:11 +0800)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Thu, 8 Oct 2020 19:29:06 +0000 (15:29 -0400)
The effect here is to get the number of bits, lets use fls() to do
this job.

Link: https://lkml.kernel.org/r/20200831031104.23322-3-richard.weiyang@linux.alibaba.com
Signed-off-by: Wei Yang <richard.weiyang@linux.alibaba.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
kernel/trace/ftrace.c

index 123d520b92612a2d6d9a75ce0d6bd732bea8dcf5..5633d37d880659b9b189a58ad55506bff040c6d2 100644 (file)
@@ -1370,8 +1370,9 @@ static struct ftrace_hash *dup_hash(struct ftrace_hash *src, int size)
        /*
         * Make the hash size about 1/2 the # found
         */
-       for (size /= 2; size; size >>= 1)
-               bits++;
+       bits = fls(size);
+       if (bits)
+               bits--;
 
        /* Don't allocate too much */
        if (bits > FTRACE_HASH_MAX_BITS)