아래 코드 부분 분석 중 cpu_bit_bitmap에 대해 궁금증이 생겨 질문드립니다.
include/linux/cpumask.h
static inline const struct cpumask *get_cpu_mask(unsigned int cpu) //cpu = 99
{
const unsigned long *p = cpu_bit_bitmap[1 + cpu % BITS_PER_LONG];
p -= cpu / BITS_PER_LONG;
return to_cpumask(p);
}
cpu_bit_bitmap 초기화 부분 : kernel/cpu.c
const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {[1
MASK_DECLARE_8(0), MASK_DECLARE_8(8),
MASK_DECLARE_8(16), MASK_DECLARE_8(24),
#if BITS_PER_LONG > 32
MASK_DECLARE_8(32), MASK_DECLARE_8(40),
MASK_DECLARE_8(48), MASK_DECLARE_8(56),
#endif
};
EXPORT_SYMBOL_GPL(cpu_bit_bitmap);
전체 CPU 수가 64*3개 있다고 가정할 때,
cpu가 0일 때는, cpu_bit_bitmap[1][0] 부터 192 bit (struct cpumask 크기, sizeof(long)*3 )를 읽습니다. 즉,
cpu_bit_bitmap[1][0] = 0x1
cpu_bit_bitmap[1][1] = 0x0
cpu_bit_bitmap[1][2] = 0x0
를 읽게 됩니다.
cpu가 64일때는, cpu_bit_bitmap[0][2] 부터 읽어,
cpu_bit_bitmap[0][2] = 0x0
cpu_bit_bitmap[1][0] = 0x1
cpu_bit_bitmap[1][1] = 0x0
을 읽게 됩니다.
표로 표현하면 다음과 같습니다.
이는 little endian으로 읽을 경우, cpu 0일 때 0번째 bit이 1이고, cpu 64일 때 64번째 bit이 1로 읽힐 것으로 보이는데요,
만약 big endian의 경우는 어떻게 되는지요?
.
안녕하세요? 문c 블로그(http://jake.dothome.co.kr)의 문영일입니다.
위의 내용 잘 분석하셨습니다..
답변 내용이 길어져 get_cpu_mask() 함수와 cpu_bit_bitmap 배열 관계를 제 블로그에 설명해두었습니다.
CPU 비트맵 (API) | 문c - http://jake.dothome.co.kr/cpu-api
감사합니다.