kernel: use monitor/mwait instruction on pc multiprocessor for idlehands

This commit is contained in:
cinap_lenrek 2012-05-04 11:02:11 +02:00
parent 3ce608921a
commit aa015b1c4f
5 changed files with 27 additions and 2 deletions

View file

@ -218,6 +218,7 @@ struct Mach
uvlong cyclefreq; /* Frequency of user readable cycle counter */
uvlong cpuhz;
int cpuidax;
int cpuidcx;
int cpuiddx;
char cpuidid[16];
char* cpuidtype;
@ -277,6 +278,9 @@ struct PCArch
/* cpuid instruction result register bits */
enum {
/* cx */
Monitor = 1<<3,
/* dx */
Fpuonchip = 1<<0,
// Pse = 1<<3, /* page size extensions */

View file

@ -732,8 +732,8 @@ cpuidprint(void)
if(m->cpuidid[0])
i += sprint(buf+i, "%12.12s ", m->cpuidid);
seprint(buf+i, buf + sizeof buf - 1,
"%s (cpuid: AX 0x%4.4uX DX 0x%4.4uX)\n",
m->cpuidtype, m->cpuidax, m->cpuiddx);
"%s (cpuid: AX 0x%4.4uX CX 0x%4.4uX DX 0x%4.4uX)\n",
m->cpuidtype, m->cpuidax, m->cpuidcx, m->cpuiddx);
print(buf);
}
@ -766,6 +766,7 @@ cpuidentify(void)
cpuid(Procsig, regs);
m->cpuidax = regs[0];
m->cpuidcx = regs[2];
m->cpuiddx = regs[3];
if(strncmp(m->cpuidid, "AuthenticAMD", 12) == 0 ||

View file

@ -42,6 +42,7 @@ ulong getcr4(void);
char* getconf(char*);
void guesscpuhz(int);
void halt(void);
void mwait(void*);
int i8042auxcmd(int);
int i8042auxcmds(uchar*, int);
void i8042auxenable(void (*)(int, int));

View file

@ -855,6 +855,21 @@ _nothingready:
HLT
RET
TEXT mwait(SB), $0
MOVL addr+0(FP), AX
MOVL (AX), CX
ORL CX, CX
JNZ _mwaitdone
XORL DX, DX
BYTE $0x0f; BYTE $0x01; BYTE $0xc8 /* MONITOR */
MOVL (AX), CX
ORL CX, CX
JNZ _mwaitdone
XORL AX, AX
BYTE $0x0f; BYTE $0x01; BYTE $0xc9 /* MWAIT */
_mwaitdone:
RET
/*
* Interrupt/exception handling.
* Each entry in the vector table calls either _strayintr or _strayintrx depending

View file

@ -868,6 +868,10 @@ cistrncmp(char *a, char *b, int n)
void
idlehands(void)
{
extern int nrdy;
if(conf.nmach == 1)
halt();
else if(m->cpuidcx & Monitor)
mwait(&nrdy);
}