uclinux-2008R1-RC8(bf561)到VDSP5的移植(26):smp_processor_id

本文探讨了Linux内核中的smp_processor_id宏及其底层实现raw_smp_processor_id,并介绍了ADI平台上的adi_core_id函数。这些函数用于确定当前执行核心的标识。
 
  
smp_processor_id是在include/linux/smp.h中定义的一个宏:
# define smp_processor_id() raw_smp_processor_id()
在此之前还有一段说明:
 
/*
 * smp_processor_id(): get the current CPU ID.
 *
 * if DEBUG_PREEMPT is enabled the we check whether it is
 * used in a preemption-safe way. (smp_processor_id() is safe
 * if it's used in a preemption-off critical section, or in
 * a thread that is bound to the current CPU.)
 *
 * NOTE: raw_smp_processor_id() is for internal use only
 * (smp_processor_id() is the preferred variant), but in rare
 * instances it might also be used to turn off false positives
 * (i.e. smp_processor_id() use that the debugging code reports but
 * which use for some reason is legal). Don't use this to hack around
 * the warning message, as your code might not work under PREEMPT.
 */
那么raw_smp_processor_id又是何方神圣?从定义和注释可以认为这个宏应该用于取得当前运行代码的CPU序号,查了下linux-2.6.19的代码,在asm/smp.h中可以验证这一点,而VDSP5提供了一个叫adi_core_id的函数:
adi_core_id

Identify caller’s core
Synopsis
#include <ccblkfn.h>
int adi_core_id(void);
Description
The adi_core_id function returns a numeric value indicating which processor core is executing the call to the function. This function is most useful on multi-core processors, when the caller is a function shared between both cores, but which needs to perform different actions (or access different data) depending on the core executing it.
The function returns a zero value when executed by Core A, and a value of one when executed on Core B.
Error Conditions
The adi_core_id function does not return an error condition.
Example
#include <ccblkfn.h>
const char *core_name(void)
{
      if (adi_core_id() == 0)
         return "Core A";
      else
         return "Core B";
}
因此我们在asm/smp.h中添加如下定义:
 
/*
 * This function is needed by all SMP systems. It must _always_ be valid
 * from the initial startup. We map APIC_BASE very early in page_setup(),
 * so this is correct in the x86 case.
 */
#define raw_smp_processor_id() (adi_core_id())
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌云阁主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值