exdata
驱动牛犊
驱动牛犊
  • 注册日期2002-11-11
  • 最后登录2007-07-16
  • 粉丝0
  • 关注0
  • 积分30分
  • 威望3点
  • 贡献值0点
  • 好评度3点
  • 原创分0分
  • 专家分0分
阅读:1455回复:4

讨论超线程(Hyper-Threading)对驱动的编写要求:

楼主#
更多 发布于:2004-04-02 11:36
引用:
Hyper-Threading为何物?:

当今的处理器发展普遍向着提高处理器指令平铺速率的方向迈进,但由于所使用的处理器资源会有冲突,因此性能提升的效果并不理想。而通过Hyper-Threading技术,通过在一枚处理器上整合两个逻辑处理器(注:是处理器而不是运算单元)单元,使得具有这种技术的新型CPU具有能同时执行多个线程的能力,而这是现有其它微处理器都不能做到的。

简单的说,Hyper Threading是一种同步多执行绪(SMT,simultaneous Multi-threading)技术,它的原理很简单,就是把一颗CPU当成两颗来用,将一颗具Hyper-Threading功能的“实体”处理器变成两个“逻辑”处理器而逻辑处理器对于操作系统来说跟实体处理器并没什么两样,因此操作系统会把工作线程分派给这“两颗”处理器去执行,让多种应用程序或单一应用程序的多个执行绪(thread),能够同时在同一颗处理器上执行;不过两个逻辑处理器是共享这颗CPU的所有执行资源。




通过整合这一技术,具有Hyper-Threading技术的CPU能在同一物理处理器资源下同时执行两个程序,或者是一个程序的两个线程,从而使物理处理器资源利用率至少提升40%。Intel将在未来使用NetBurtst架构的全线处理器中引入这一技术!

Hyper-Threading技术将如何工作?:

Hyper-Threading做法是复制一颗处理器的架构指挥中心(architectural state)变成两个,使得Windows操作系统认为是在与两颗处理器沟通,但这两个架构指挥中心共享该处理器的工作资源(execution resources)。架构指挥中心追踪每个程序或执行绪的执行状况;工作资源指的则是“处理器用来进行加、乘、加载等工作的单元(execution unit)”。如此一来,操作系统把工作线程安排好以后,就分派给这两个逻辑上的处理器执行,而这颗CPU的每个执行单元等于在同样的时间内要服务两个“指令处理中心”,当然它的效率就高多了,操作系统就把一颗实体的处理器认定为两个逻辑处理器作工作指派,当然整体工作效能就比没有具备Hyper-Threading 的处理器高出许多,性价比自然高出许多。
 

在网上逛了一回,除了SpinLock的一些说明似乎有点参考意义之外没有找到多少超线程与驱动编程相关的资料,假想有两个逻辑CPU存在,突然想道下面的情况,迷惑中,由于没有硬件条件无法验证,恳请前辈们指教。

ThreadFunction() //内核线程函数
{
while(1)
{
event.wait();
spinlock.lock();
DoSomething1(); //当前运行于逻辑CPU1
//系统在此时刻发生了调度,这是不可避免的
DoSomethink2(); //当系统在此调度使ThreadFunction运行时
//究竟是那一个逻辑CPU在运行ThreadFunction?
//CPU1?CPU2?会不会CPU2呢,那样对Spinlock的
//作用如何解析?
spinlock.unlock();
}
} :)
hong
驱动小牛
驱动小牛
  • 注册日期2001-09-19
  • 最后登录2005-12-16
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2004-04-06 00:08
answer:
运行于逻辑CPU1.
this is the function of spinlock.lock();
exdata
驱动牛犊
驱动牛犊
  • 注册日期2002-11-11
  • 最后登录2007-07-16
  • 粉丝0
  • 关注0
  • 积分30分
  • 威望3点
  • 贡献值0点
  • 好评度3点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2004-04-06 09:12
answer:
运行于逻辑CPU1.
this is the function of spinlock.lock();
 


线程应该还是运行于CPU1,但是并不是spinlock的作用,这里的lock并没有对函数-CPU起到什么关联作用,最多只能保护locked状态时侯数据访问引起的冲突;

在找到的一些资料中提及multiprocessor systems中线程和逻辑CPU有亲缘属性affinity,该属性关联线程到指定的逻辑CPU,以我的理解线程在系统调度时不会被不同的逻辑CPU瓜分。
arthurtu
驱动巨牛
驱动巨牛
  • 注册日期2001-11-08
  • 最后登录2020-12-19
  • 粉丝0
  • 关注0
  • 积分26分
  • 威望161点
  • 贡献值0点
  • 好评度35点
  • 原创分0分
  • 专家分0分
  • 社区居民
地板#
发布于:2004-04-06 10:02
Choosing a Processor for a Ready Thread
When a thread becomes ready to run, Windows 2000 first tries to schedule the thread to run on an idle processor. If there is a choice of idle processors, preference is given first to the thread's ideal processor, then to the thread's last processor, and then to the currently executing processor (that is, the CPU on which the scheduling code is running). If none of these CPUs are idle, Windows 2000 picks the first available idle processor by scanning the idle processor mask from highest to lowest CPU number.

If all processors are currently busy and a thread becomes ready, Windows 2000 looks to see whether it can preempt a thread in the running or standby state on one of the CPUs. Which CPU is examined? The first choice is the thread's ideal processor, and the second choice is the thread's last processor. If neither of those CPUs are in the thread's affinity mask, Windows 2000 selects the highest processor in the active processor mask that the thread can run on.

If the processor selected already has a thread selected to run next (waiting in the standby state to be scheduled) and that thread's priority is less than the priority of the thread being readied for execution, the new thread preempts that first thread out of the standby state and becomes the next thread for that CPU. If there is already a thread running on that CPU, Windows 2000 checks whether the priority of the currently running thread is less than the thread being readied for execution. If so, the currently running thread is marked to be preempted and Windows 2000 queues an interprocessor interrupt to kick off the currently running thread in favor of this new thread.


.
 :D
hong
驱动小牛
驱动小牛
  • 注册日期2001-09-19
  • 最后登录2005-12-16
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2004-04-06 22:49
Arthurtu is correct!

here the main point is spinLock().
once spinlock() returns that means the following code will be garanteed to execute on the same CPU.
游客

返回顶部