发信人: wenbobo()
整理人: wenbobo(2003-01-09 23:23:19), 站内信件
|
AMD K6 WriteBack Optimizations(AMD K6的回写优化)
AMD K6 反写(技术)最佳化(wenbobo: 回写优化)
This source code uses GCC inline assembler (AT&T syntax).
该源程序需用内嵌AT&T语法汇编器的GCC来编译.
(wenbobo: 该源程序使用了GCC的内嵌AT&T汇编.)
I wrote and tested this on my own K6 (k6-200) and it works ok, but I was unable to find anyone with a K6-2 (CXT core) or K6-3 since there is two different methods for enabling writeback mode. It _should_ work fine on k6-2 CXT and K6-3 processors.
这是我写的代码,并且在我自己的K6(K6-200)上运行良好。但是自启用两种不同反写方法后,我就不能正常运行于K6-2(CXT内核)或K6-3了.它跑在K6-2 CXT和K6-3处理器上是最佳的。
(wenbobo: 这是我写的代码,在我自己的K6(K6-200)上测试了,运行良好。但是我没能找到有K6-2(CXT内核)或者K6-3的人,而激活回写模式是有两种不同的方法的。这段代码在K6-2 CXT和K6-3上应该也能很好的工作。)
With some tweaking, can be put into anyone's OS.
作适应修改后,它可以移值到任何操作系统。
(wenbobo: 作适当修改后,它可以放入任何人的操作系统。)
You call AMD_K6_writeback with the CPUID results family, model and stepping, only when you are sure you have an AMD cpu.
你可以用AMD-K6反写技术获得CPU系列的识别符,型号和级别,最关键是你必须确定你有一个AMD处理器.
(wenbobo: 你可以使用CPUID指令返回的family,model和stepping作为参数来调用AMD_K6_writeback,只是你得先确定你用的是AMD cpu.)
void AMD_K6_writeback(int family, int model, int stepping)
{
/* mem_end == top of memory in bytes */
/* mem_end == 字节为单位的最大内存 */
int mem=(mem_end>>20)/4; /* turn into 4mb aligned pages (wenbobo: 转成4MB对其的页)*/
int c;
union REGS regs;
if(family==5)
{
c=model;
/* model 8 stepping 0-7 use old style, 8-F use new style */
/* (wenbobo: model 8以前0-7型号的CPU使用旧的风格,8-F版的用新风格代码) */
if(model==8)
{
if(stepping<8)
c=7;
else
c=9;
}
switch(c)
{
/* old style write back (wenbobo: 旧式风格的回写)*/
case 6:
case 7:
AMD_K6_read_msr(0xC0000082, & regs);
if(((regs.x.eax>>1)&0x7F)==0)
kprintf("AMD K6 : WriteBack currently disabled\n");
else
kprintf("AMD K6 : WriteBack currently enabled (%luMB)\n",
((regs.x.eax>>1)&0x7F)*4);
kprintf("AMD K6 : Enabling WriteBack to %luMB\n", mem*4);
AMD_K6_write_msr(0xC0000082, ((mem<<1)&0x7F), 0, & regs);
break;
/* new style write back (wenbobo: 新式风格的回写)*/
case 9:
AMD_K6_read_msr(0xC0000082, & regs);
if(((regs.x.eax>>22)&0x3FF)==0)
kprintf("AMD K6 : WriteBack Disabled\n");
else
kprintf("AMD K6 : WriteBack Enabled (%luMB)\n",
((regs.x.eax>>22)&0x3FF)*4);
kprintf("AMD K6 : Enabled WriteBack (%luMB)\n", mem*4);
AMD_K6_write_msr(0xC0000082, ((mem<<22)&0x3FF), 0, & regs);
break;
default: /* dont set it on Unknowns + k5's (wenbobo: 别设在未知的CPU和K5上了)*/
break;
}
}
}
void AMD_K6_write_msr(ULONG msr, ULONG v1, ULONG v2, union REGS *regs)
{
asm __volatile__ (
"pushfl\n"
"cli\n"
"wbinvd\n"
"wrmsr\n"
"popfl\n"
: "=a" (regs->x.eax),
"=b" (regs->x.ebx),
"=c" (regs->x.ecx),
"=d" (regs->x.edx)
: "a" (v1),
"d" (v2),
"c" (msr)
: "eax",
"ecx",
"edx",
"ebx",
"memory"); /* wenbobo: 参考我前面的解释*/
}
void AMD_K6_read_msr(ULONG msr, union REGS *regs)
{
asm __volatile__ (
"pushfl\n"
"cli\n"
"wbinvd\n"
"xorl %%eax, %%eax\n"
"xorl %%edx, %%edx\n"
"rdmsr\n"
"popfl\n"
: "=a" (regs->x.eax),
"=b" (regs->x.ebx),
"=c" (regs->x.ecx),
"=d" (regs->x.edx)
: "c" (msr)
: "eax",
"ecx",
"edx",
"ebx",
"memory");
}
---- 掬水月在手
弄花香满身 |
|