|
From: Jeremy F. <je...@go...> - 2003-12-18 09:06:42
|
CVS commit by fitzhardinge:
Make rep; nop (pause) yield the thread. Based on a patch by Tom Hughes;
I added a test case and cleaned up vg_dispatch.S while I was about it.
CCMAIL: 695...@bu...
M +1 -0 coregrind/vg_constants.h 1.14
M +2 -21 coregrind/vg_dispatch.S 1.13
M +3 -0 coregrind/vg_from_ucode.c 1.69
M +10 -0 coregrind/vg_scheduler.c 1.134
M +5 -1 coregrind/vg_to_ucode.c 1.116
M +1 -0 coregrind/vg_translate.c 1.64
M +2 -1 include/vg_skin.h.base 1.4
M +5 -2 none/tests/Makefile.am 1.17
--- valgrind/coregrind/vg_constants.h #1.13:1.14
@@ -49,4 +49,5 @@
#define VG_TRC_EBP_JMP_SYSCALL 19 /* EBP and TRC */
#define VG_TRC_EBP_JMP_CLIENTREQ 23 /* EBP and TRC */
+#define VG_TRC_EBP_JMP_YIELD 27 /* EBP and TRC */
#define VG_TRC_INNER_FASTMISS 31 /* TRC only; means fast-cache miss. */
--- valgrind/coregrind/vg_dispatch.S #1.12:1.13
@@ -170,30 +170,11 @@
dispatch_exceptional:
/* this is jumped to only, not fallen-through from above */
- cmpl $VG_TRC_EBP_JMP_SYSCALL, %ebp
- jz dispatch_syscall
- cmpl $VG_TRC_EBP_JMP_CLIENTREQ, %ebp
- jz dispatch_clientreq
cmpl $VG_TRC_INNER_COUNTERZERO, %ebp
jz counter_is_zero
-
- /* ebp has an invalid value ... crap out. */
- pushl $panic_msg_ebp
- call VG_(core_panic)
- /* (never returns) */
-dispatch_syscall:
- /* save %eax in %EIP and defer to sched */
- movl $VG_(baseBlock), %ebp
- movl VGOFF_(m_eip), %esi
- movl %eax, (%ebp, %esi, 4)
- movl $VG_TRC_EBP_JMP_SYSCALL, %eax
- jmp run_innerloop_exit
-
-dispatch_clientreq:
/* save %eax in %EIP and defer to sched */
- movl $VG_(baseBlock), %ebp
movl VGOFF_(m_eip), %esi
- movl %eax, (%ebp, %esi, 4)
- movl $VG_TRC_EBP_JMP_CLIENTREQ, %eax
+ movl %eax, VG_(baseBlock)(,%esi, 4)
+ movl %ebp, %eax
jmp run_innerloop_exit
--- valgrind/coregrind/vg_from_ucode.c #1.68:1.69
@@ -2550,4 +2550,7 @@ static void load_ebp_from_JmpKind ( JmpK
VG_(emit_movv_lit_reg) ( 4, VG_TRC_EBP_JMP_CLIENTREQ, R_EBP );
break;
+ case JmpYield:
+ VG_(emit_movv_lit_reg) ( 4, VG_TRC_EBP_JMP_YIELD, R_EBP );
+ break;
default:
VG_(core_panic)("load_ebp_from_JmpKind");
--- valgrind/coregrind/vg_scheduler.c #1.133:1.134
@@ -248,4 +248,5 @@ Char* name_of_sched_event ( UInt event )
case VG_TRC_EBP_JMP_SYSCALL: return "SYSCALL";
case VG_TRC_EBP_JMP_CLIENTREQ: return "CLIENTREQ";
+ case VG_TRC_EBP_JMP_YIELD: return "YIELD";
case VG_TRC_INNER_COUNTERZERO: return "COUNTERZERO";
case VG_TRC_INNER_FASTMISS: return "FASTMISS";
@@ -1187,4 +1188,13 @@ VgSchedReturnCode VG_(scheduler) ( void
switch (trc) {
+ case VG_TRC_EBP_JMP_YIELD:
+ /* Explicit yield. Let a new thread be scheduled,
+ simply by doing nothing, causing us to arrive back at
+ Phase 1. */
+ if (VG_(bbs_to_go) == 0) {
+ goto debug_stop;
+ }
+ break;
+
case VG_TRC_INNER_COUNTERZERO:
/* Timeslice is out. Let a new thread be scheduled,
--- valgrind/coregrind/vg_to_ucode.c #1.115:1.116
@@ -5556,5 +5556,9 @@ static Addr disInstr ( UCodeBlock* cb, A
if (abyte == 0x90) { /* REP NOP (PAUSE) */
if (dis) VG_(printf)("rep nop (P4 pause)\n");
- /* do nothing; apparently a hint to the P4 re spin-wait loop */
+ uInstr1(cb, JMP, 0, Literal, 0);
+ uLiteral(cb, eip);
+ uCond(cb, CondAlways);
+ LAST_UINSTR(cb).jmpkind = JmpYield;
+ *isEnd = True;
}
else {
--- valgrind/coregrind/vg_translate.c #1.63:1.64
@@ -1134,4 +1134,5 @@ void pp_UInstrWorker ( Int instrNo, UIns
case JmpSyscall: VG_(printf)("-sys"); break;
case JmpClientReq: VG_(printf)("-cli"); break;
+ case JmpYield: VG_(printf)("-yld"); break;
default: break;
}
--- valgrind/include/vg_skin.h.base #1.3:1.4
@@ -877,5 +877,6 @@
JmpRet=2, /* jump due to an x86 ret insn */
JmpSyscall=3, /* do a system call, then jump */
- JmpClientReq=4 /* do a client request, then jump */
+ JmpClientReq=4,/* do a client request, then jump */
+ JmpYield=5 /* do a yield, then jump */
}
JmpKind;
--- valgrind/none/tests/Makefile.am #1.16:1.17
@@ -36,5 +36,6 @@
shortpush.stderr.exp shortpush.vgtest \
shorts.stderr.exp shorts.vgtest \
- smc1.stderr.exp smc1.stdout.exp smc1.vgtest
+ smc1.stderr.exp smc1.stdout.exp smc1.vgtest \
+ yield.stdout.exp yield.vgtest
check_PROGRAMS = \
@@ -44,5 +45,5 @@
rcrl readline1 resolv seg_override sha1_test shortpush shorts smc1 \
pth_blockedsig \
- coolo_sigaction gxx304
+ coolo_sigaction gxx304 yield
AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -g -I$(top_srcdir)/include
@@ -73,4 +74,6 @@
shortpush_SOURCES = shortpush.c
shorts_SOURCES = shorts.c
+yield_SOURCES = yield.c
+yield_LDADD = -lpthread
# pthread C ones
|