![]() |
|
||||||||||||||
| | 首页 | 新闻 | 文库 | 方案 | 技术 | 独家 | 座谈 | 下载 | 电路图 | 开发套件 | 仿真器 | 邮购 | 帮助 | VIP会员 | 芯片代购 | | ||
|
||
|
|||||
| uclinux2.6(bf561)内核中的current_thread_info | |||||
作者:快乐虾 文章来源:http://blog.csdn.net/lights_joy 点击数: 更新时间:2008-5-14 ![]() |
|||||
|
current_thread_info的定义在include/asm/thread_info.h中:
/* Given a task stack pointer, you can find it's task structure
* just by masking it to the 8K boundary.
*/
static inline struct thread_info *current_thread_info(void)
{
struct thread_info *ti;
__asm__("%0 = sp;": "=&d"(ti):
);
return (struct thread_info *)((long)ti & ~((long)THREAD_SIZE-1));
}
它的作用在于取得运行当前代码的线程的信息,此信息保存在thread_info结构体中。
在上述函数中,THREAD_SIZE定义为:
/*
* Size of kernel stack for each process. This must be a power of 2...
*/
#define THREAD_SIZE 8192 /* 2 pages */
也就是说,上述函数将取SP指针,并将此指针按照8K对齐,即2页对齐,这就是线程信息的指针了。
记得在处理head.s的时候,有一段代码:
/*
* load the current thread pointer and stack
*/
r1.l = _init_thread_union;
r1.h = _init_thread_union;
r2.l = 0x2000; // 8192字节
r2.h = 0x0000;
r1 = r1 + r2;
sp = r1;
usp = sp;
fp = sp;
其中init_thread_union的定义为:
/*
* Initial thread structure.
*
* We need to make sure that this is 8192-byte aligned due to the
* way process stacks are handled. This is done by having a special
* "init_task" linker map entry.
*/
union thread_union init_thread_union
__attribute__ ((__section__(".data.init_task"))) = {
INIT_THREAD_INFO(init_task)};
thread_union的定义在include/linux/shed.h中:
union thread_union {
struct thread_info thread_info;
unsigned long stack[THREAD_SIZE/sizeof(long)];
};
这个union的结构体大小为THREAD_SIZE,也就是8K,在初始化的时候,将FP和SP都指向了初始线程stack的最高位置。
那么这个线程信息是如何保证以8K对齐的呢?答案在.data.init_task这个段,在LDF文件中,有这样的语句:
.data
{
/* make sure the init_task is aligned to the
* kernel thread size so we can locate the kernel
* stack properly and quickly.
*/
__sdata = .;
INPUT_SECTION_ALIGN(8192)
INPUT_SECTIONS($LIBRARIES_CORE_A(.data.init_task))
…
} > MEM_SDRAM
从而保证了init_thread_union是以8192对齐的。
对于一般的线程信息,uclinux内核是如何做到这一点的呢?在thread_info.h中有一个宏定义:
/* thread information allocation */
#define alloc_thread_info(tsk) ((struct thread_info *) \
__get_free_pages(GFP_KERNEL, 1))
#define free_thread_info(ti) free_pages((unsigned long) (ti), 1)
猜测是通过__get_free_pages这个函数来达到目的的,不过目前还没有涉及到内存分配与管理这一块,暂且放一放。
|
|||||
| 文章录入:admin 责任编辑:admin | |||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | |||||
| 最新热点 | 最新推荐 | 相关文章 | ||
| 将LCD接到便携式多媒体应用上 在恶劣环境中调理信号:关于 单片机在机床刀具过载保护与 嵌入式系统的发展趋势 uclinux2.6(bf561)中的bootm uclinux2.6(bf561)中的bootm uclinux2.6(bf561)中的bootm uclinux2.6(bf561)中的bootm 一种基于SoC的高精度电子血压 ADI ADE51xx SOC单相电表方案 |
| 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
| | 本站介绍 | 合作联络 | 欢迎投稿 | 广告业务 | 网站地图 | 设为首页 | 加入收藏 | 友情链接 | 网站公告 | 联系我们 | | |||
|