gpt4 book ai didi

linux - 如果找不到任何东西,sched_find_first_bit 的返回值是多少?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:01:33 26 4
gpt4 key购买 nike

内核是2.4。

附带说明一下,有人知道我可以搜索此类信息的好地方吗?在 Google 上搜索函数定义令人沮丧。

最佳答案

如果您计划花大量时间搜索或了解 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;
}

关于linux - 如果找不到任何东西,sched_find_first_bit 的返回值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2741065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com