Каково возвращаемое значение sched_find_first_bit, если он ничего не находит? - PullRequest
1 голос
/ 30 апреля 2010

ядро ​​2.4.

Кстати, кто-нибудь знает хорошее место, где я могу искать такую ​​информацию? Поиск в Google по определениям функций разочаровывает.

1 Ответ

3 голосов
/ 30 апреля 2010

Если вы планируете потратить какое-то значительное время на поиск или понимание ядра Linux, я рекомендую загрузить копию и использовать Cscope .

Использование Cscope в больших проектах (например, ядро ​​Linux)


Я нашел следующее в копии ядра 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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...