per cpu变量相关函数和宏
DEFINE_PER_CPU_SHARED_ALIGNED(type,
name):静态分配per_cpu数组,数组名为
name,结构类型为type
DEFINE_PER_CPU(type,
name) : 静态分配per_cpu数组,数组名为
name,结构类型为type
per_cpu(
name,cpu) : 为CPU选择一个每CPU数组元素,CPU由参数cpu指定,数组名称为
name
__get_cpu_var(
name) :选择per_cpu数组
name的本地CPU元素
get_cpu_var(
name) : 先禁用内核内核抢占,然后在per_cpu数组
name中,为本地CPU选择元素
put_cpu_var(
name) :启用内核抢占(不使用
name)
alloc_percpu(type):动态分配type类型数据结构的per_cpu数组,并返回它的地址
free_percpu(pointer):释放被动态分配的per_cpu数组,pointer指示其地址
per_cpu_ptr(pointer,cpu):返回per_cpu数组中参数cpu对应的CPU元素地址,参数pointer给出数组地址
查找per cpu变量地址
static DEFINE_PER_CPU_SHARED_ALIGNED(
struct msm_spm_device, msm_cpu_spm_device);
比如用上面DEFINE_PER_CPU_SHARED_ALIGNED宏声明的一个变量msm_spm_device,在某一个时刻用T32查看其地址为0xC0D037C0。这个地址其实是对应CPU0的地址,如果想要看CPU1的地址怎么办? 因为每个per cpu变量对应的偏移地址,根据CPU核数,保存在__per_cpu_offset[]数组中。 比如想看msm_spm_device对应的CPU1的地址的话,就在CPU0对应的地址0xC0D037C0基础上加上__per_cpu_offset[1]的值0x02F8D000。也就是 0xC0D037C0+0x2F8D000 = 0xC3C907C0。 然后 v.v (struct msm_spm_device*)0xC3C907C0, 这样就可以看到CPU1对应的数据结构的内容了。
转载请注明原文地址: https://ju.6miu.com/read-660531.html