歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

uclinux-2008R1-RC8(bf561)到VDSP5的移植(26):smp_processor_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())

Copyright © Linux教程網 All Rights Reserved