今天在阅读内核源码时,对get_cpu_mask()函数中使用的小技巧颇有感触,在此记录一下。 一、背景知识 get_cpu_mask()函数的作用是依据输入的cpu编号,返回对应的struct cpumask结构体型指针;cpumask是代表了系统中cpu集合的位图,每一bit个代表一个cpu。
MASK_DECLARE_8(48), MASK_DECLARE_8(56),#endif}; staticinlineconststructcpumask *get_cpu_mask(unsignedintcpu) {constunsignedlong*p = cpu_bit_bitmap[1+ cpu %BITS_PER_LONG]; p-= cpu /BITS_PER_LONG;returnto_cpumask(p); } #defineto_cpumask(bitmap) \((structcpumask *)(1?(bitmap...
The getaffinity() system call uses 'cpumask_size()' to decide how big the CPU mask is - so far so good. It is indeed the allocation size of a cpumask. But the code also assumes that the whole allocation is initialized without actually doing so itself. That's wrong, because we might...
const struct cpumask *affinity_mask) { return tags->cpumask; int queue = -1, cpu = 0;set->mq_map = kzalloc_node(sizeof(*set->mq_map) * nr_cpu_ids, GFP_KERNEL, set->numa_node); if (!set->mq_map) return -ENOMEM;if
On success, the rawsched_getaffinity() system call returns the number of bytes placed copied into themaskbuffer; this will be the minimum ofcpusetsizeand the size (in bytes) of thecpumask_tdata type that is used internally by the kernel to represent the CPU set bit mask. ...