percpu相关-cpu_number 变量和smp_processor_id

1、cpu_number

是一个 percpu 类型的 int 变量,

arch/arm64/include/asm/smp.h。

34 行,声明 percpu 变量 cpu_number . 在 arch/arm64/kernel/smp.c 中定义。

2、raw_smp_processor_id

43 行,就是读取 当前 运行 CPU 的,cpu_number 。 raw_cpu_ptr(ptr)的信息,参考 https://www.cnblogs.com/zhangzhiwei122/p/16054079.html

  33
  34DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
  35
  36/*
  37 * We don't use this_cpu_read(cpu_number) as that has implicit writes to
  38 * preempt_count, and associated (compiler) barriers, that we'd like to avoid
  39 * the expense of. If we're preemptible, the value can be stale at use anyway.
  40 * And we can't use this_cpu_ptr() either, as that winds up recursing back
  41 * here under CONFIG_DEBUG_PREEMPT=y.
  42 */
  43#define raw_smp_processor_id() (*raw_cpu_ptr(&cpu_number))

 

arch/arm64/kernel/smp.c

  56
  57DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
  58EXPORT_PER_CPU_SYMBOL(cpu_number);
  59

 

3、smp_processor_id

include/linux/smp.h

和raw_smp_processor_id 一样,得到当前cpu的 cpu_number 的值。

上面的 raw_smp_processor_id 是 arch 需要实现的函数,在 arch/arm64/include/asm/smp.h 中。smp_processor_id 则是 linux 平台需要实现的函数,在linux/smp.h 里面。

 228#ifndef __smp_processor_id
 229#define __smp_processor_id(x) raw_smp_processor_id(x)
 230#endif
 231
 232#ifdef CONFIG_DEBUG_PREEMPT
 233  extern unsigned int debug_smp_processor_id(void);
 234# define smp_processor_id() debug_smp_processor_id()
 235#else
 236# define smp_processor_id() __smp_processor_id()
 237#endif

 

posted @ 2022-03-25 12:48  张志伟122  阅读(581)  评论(0编辑  收藏  举报