如果没有找到任何内容,sched_find_first_bit的返回值是多少?

时间:2010-04-29 21:58:43

标签: linux

内核是2.4。

另一方面,是否有人知道我可以搜索这类信息的好地方?搜索Google的功能定义令人沮丧。

1 个答案:

答案 0 :(得分:3)

如果您计划花费大量时间搜索或了解Linux内核,我建议您下载副本并使用Cscope

Using Cscope on large projects (example: the Linux kernel)


我在Linux内核2.4.18的副本中找到了以下内容。

关键似乎是下面最后一段代码之前的评论。如果没有设置位,则sched_find_first_bit的返回值似乎未定义。

来自 linux-2.4 / include / linux / sched.h:185


/*
 * The maximum RT priority is configurable.  If the resulting
 * bitmap is 160-bits , we can use a hand-coded routine which
 * is optimal.  Otherwise, we fall back on a generic routine for
 * finding the first set bit from an arbitrarily-sized bitmap.
 */
#if MAX_PRIO  127
#define sched_find_first_bit(map)   _sched_find_first_bit(map)
#else
#define sched_find_first_bit(map)   find_first_bit(map, MAX_PRIO)
#endif

来自 linux-2.4 / include / asm-i386 / bitops.h:303


/**
 * find_first_bit - find the first set bit in a memory region
 * @addr: The address to start the search at
 * @size: The maximum size to search
 *
 * Returns the bit-number of the first set bit, not the number of the byte
 * containing a bit.
 */
static __inline__ int find_first_bit(void * addr, unsigned size)
{
    int d0, d1;
    int res;

    /* This looks at memory. Mark it volatile to tell gcc not to move it around */
    __asm__ __volatile__(
        "xorl %%eax,%%eax\n\t"
        "repe; scasl\n\t"
        "jz 1f\n\t"
        "leal -4(%%edi),%%edi\n\t"
        "bsfl (%%edi),%%eax\n"
        "1:\tsubl %%ebx,%%edi\n\t"
        "shll $3,%%edi\n\t"
        "addl %%edi,%%eax"
        :"=a" (res), "=&c" (d0), "=&D" (d1)
        :"1" ((size + 31) >> 5), "2" (addr), "b" (addr));
    return res;
}

来自 linux-2.4 / include / asm-i386 / bitops.h:425


/*
 * Every architecture must define this function. It's the fastest
 * way of searching a 140-bit bitmap where the first 100 bits are
 * unlikely to be set. It's guaranteed that at least one of the 140
 * bits is cleared.
 */
static inline int _sched_find_first_bit(unsigned long *b)
{
    if (unlikely(b[0]))
        return __ffs(b[0]);
    if (unlikely(b[1]))
        return __ffs(b[1]) + 32;
    if (unlikely(b[2]))
        return __ffs(b[2]) + 64;
    if (b[3])
        return __ffs(b[3]) + 96;
    return __ffs(b[4]) + 128;
}

来自 linux-2.4 / include / asm-i386 / bitops.h:409


/**
 * __ffs - find first bit in word.
 * @word: The word to search
 *
 * Undefined if no bit exists, so code should check against 0 first.
 */
static __inline__ unsigned long __ffs(unsigned long word)
{
    __asm__("bsfl %1,%0"
        :"=r" (word)
        :"rm" (word));
    return word;
}