BITS_TO_LONGS 宏的作用 [linux-3.0] BITS_TO_LONGS 定义在:include/linux/bitops.h #define BITS_PER_BYTE #define BITS_TO_LONGS(nr) DIV_ROUND_UP 定义在:include/linux/kernel.h (line 58) #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 其目的就是求一个数是几个 long 的...
BITS_TO_LONGS宏的作用 [linux-3.0] BITS_TO_LONGS 定义在:include/linux/bitops.h #define BITS_PER_BYTE ? ? ? ?8 #define BITS_TO_LONGS(nr) ? ?DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) DIV_ROUND_UP 定义在:include/linux/kernel.h (line 58) #define DIV_ROUND_UP(n,d) ((...
宏BITS_TO_LONGS用来实现对应的转换,其定义如下: // file: include/linux/bitops.h#define BITS_TO_LONGS(nr)DIV_ROUND_UP(nr,BITS_PER_BYTE* sizeof(long)) BITS_TO_LONGS中又引用了宏DIV_ROUND_UP和BITS_PER_BYTE。 宏BITS_PER_BYTE扩展为 8,表示每个字节包含 8 个比特位: // file: include/linux...
1156行,evbit,设备支持的事件类型的位图,每一位代表一种事件,比如EV_KEY、EV_REL事件等等。BITS_TO_LONGS(nr)是一个宏,假设long型变量为32位,1位可以表示一种事件,那么这个宏的意思就是nr种事件需要用多少个long型变量来表示。EV_CNT的值为0x1f+1,因此BITS_TO_LONGS(0x1f+1)的值就为1。 1157行,keybit...
typedefstructcpumask{unsignedlongbits[BITS_TO_LONGS(NR_CPUS)];}cpumask_t; 可以看到,结构体cpumask的成员是一个名称为bits拥有NR_CPUS个有效比特位的unsigned long数组。 2.1.2 宏 NR_CPUS 宏NR_CPUS扩展为CONFIG_NR_CPUS,其定义如下: // file: include/linux/threads.h/* Places which use this should...
BITS_TO_LONGS通过DIV_ROUND_UP宏完成。DIV_ROUND_UP根据nr参数计算至少需要几个long型才能满足当前位图的需求。不知道为什么Linux不使用char型,这样不是更节约内存吗?显然DECLARE_BITMAP的引入的根本目的并不是用来节约内存,而是方便对长位图的操作,而通常8位位图的定义并不通过它来定义,而是直接定义位掩码,比如对文...
登录后复制~~structinput_dev {constchar*name;constchar*phys;constchar*uniq;structinput_idid;unsignedlongpropbit[~~BITS_TO_LONGS(INPUT_PROP_CNT)];unsignedlongevbit[BITS_TO_LONGS(EV_CNT)];unsignedlongkeybit[BITS_TO_LONGS(KEY_CNT)];unsignedlongrelbit[BITS_TO_LONGS(REL_CNT)];unsignedlongabsbit...
unsigned long name[BITS_TO_LONGS(bits)] 我们可以看到 DECLARE_BITMAP 宏使用两个参数: name - 位图名称; bits - 位图中位数; 并且只是使用 BITS_TO_LONGS(bits) 元素展开 unsigned long 数组的定义。 BITS_TO_LONGS 宏将一个给定的位数转换为 long 的个数,换言之,就是计算 bits 中有多少个 8 字节元...
unsigend long int name[BITS_TO_LONGS(bits)] DEFINE_BITMAP(name, bits)定义了一个比特位图,name为比特位图的名字,bits为比特位图的大小。 #define BIT(nr) 1UL << (nr) //将1左移 nr位 #define BIT_MASK(nr) 1UL << ( (nr) % BITS_PER_LONG ) //将第nr位置一; ...
unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];//记录支持的按键值 unsigned long relbit[BITS_TO_LONGS(REL_CNT)]; //记录izhic的相对坐标 unsigned long absbit[BITS_TO_LONGS(ABS_CNT)]; //记录支持的绝对坐标 unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)]; ...