Skip to content

Commit 6b7c005

Browse files
committed
simx86: stk16 and stk32 in cpatch don't need to lock e_invalidate()
Instead call prejit_sync() like in m_munprotect, and also do that in the other cpatch write functions. SPEC_PREJIT is about ~40% slower in my tests than non-prejit.
1 parent 004d3e1 commit 6b7c005

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

src/base/emu-i386/simx86/cpatch.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int CpatchInvalidates;
5353
/*
5454
* Return address of the stub function is passed into eip
5555
*/
56-
void m_munprotect(unsigned int addr, unsigned int len, unsigned char *eip)
56+
static void m_munprotect(unsigned int addr, unsigned int len, unsigned char *eip)
5757
{
5858
/* Shut down prejitter before invalidating, or it may crash.
5959
* Also since mprot API currently lacks mutex, shut down prejitter
@@ -241,7 +241,8 @@ void rep_movs_stos(struct rep_stack *stack)
241241

242242
void stk_16(dosaddr_t addr, Bit16u value)
243243
{
244-
e_invalidate(addr, 2);
244+
prejit_sync();
245+
e_invalidate_unlocked(addr, 2);
245246
WRITE_WORD(addr, value);
246247
#if PROFILE
247248
CpatchStkWrites++;
@@ -250,7 +251,8 @@ void stk_16(dosaddr_t addr, Bit16u value)
250251

251252
void stk_32(dosaddr_t addr, Bit32u value)
252253
{
253-
e_invalidate(addr, 4);
254+
prejit_sync();
255+
e_invalidate_unlocked(addr, 4);
254256
WRITE_DWORD(addr, value);
255257
#if PROFILE
256258
CpatchStkWrites++;
@@ -325,6 +327,7 @@ void wri_8(dosaddr_t addr, Bit8u value, unsigned char *rip)
325327
#if PROFILE
326328
CpatchWrites++;
327329
#endif
330+
prejit_sync();
328331
if (e_querymprot(addr)) {
329332
wri8_slow(addr, value, eip);
330333
return;
@@ -354,6 +357,7 @@ void wri_16(dosaddr_t addr, Bit16u value, unsigned char *rip)
354357
#if PROFILE
355358
CpatchWrites++;
356359
#endif
360+
prejit_sync();
357361
if (e_querymprotrange(addr, 2)) {
358362
wri16_slow(addr, value, eip);
359363
return;
@@ -383,6 +387,7 @@ void wri_32(dosaddr_t addr, Bit32u value, unsigned char *rip)
383387
#if PROFILE
384388
CpatchWrites++;
385389
#endif
390+
prejit_sync();
386391
if (e_querymprotrange(addr, 4)) {
387392
wri32_slow(addr, value, eip);
388393
return;

src/base/emu-i386/simx86/emu86.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ int e_querymprotrange(unsigned int addr, size_t len);
748748
int e_querymprotrange_full(unsigned int addr, size_t len);
749749
int e_markpage(unsigned int addr, size_t len);
750750
int e_unmarkpage(unsigned int addr, size_t len);
751-
void m_munprotect(unsigned int addr, unsigned int len, unsigned char *eip);
752751

753752
void InitGenCodeBuf(void);
754753
void EndGenCodeBuf(void);
@@ -773,7 +772,11 @@ int64_t m_findnode(unsigned int addr, size_t len);
773772
int64_t m_findnodestart(unsigned int addr);
774773
void mprot_init(void);
775774
void mprot_end(void);
775+
#if SPEC_PREJIT
776776
void prejit_sync(void);
777+
#else
778+
#define prejit_sync()
779+
#endif
777780
void init_emu_npu(void);
778781

779782
unsigned int Sim_helper(unsigned int mem_ref, unsigned int data, int mode,

src/base/emu-i386/simx86/interp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,15 +2809,15 @@ static void prejit_run(TNode *G)
28092809
}
28102810
#endif
28112811

2812+
#if SPEC_PREJIT
28122813
void prejit_sync(void)
28132814
{
2814-
#if SPEC_PREJIT
28152815
pthread_mutex_lock(&run_mtx);
28162816
while (prejit_running)
28172817
cond_wait(&run_cnd, &run_mtx);
28182818
pthread_mutex_unlock(&run_mtx);
2819-
#endif
28202819
}
2820+
#endif
28212821

28222822
void prejit_init(void)
28232823
{

src/base/emu-i386/simx86/trees.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ static void do_invalidate(unsigned data, int cnt)
13981398
InvalidateNodeRange(data, cnt, NULL);
13991399
}
14001400

1401-
static void _e_invalidate(unsigned data, int cnt)
1401+
void e_invalidate_unlocked(unsigned data, int cnt)
14021402
{
14031403
/* nothing to invalidate if there are no page protections */
14041404
if (!e_querymprotrange(data, cnt))
@@ -1413,7 +1413,7 @@ static void _e_invalidate(unsigned data, int cnt)
14131413
void e_invalidate(unsigned data, int cnt)
14141414
{
14151415
prejit_lock();
1416-
_e_invalidate(data, cnt);
1416+
e_invalidate_unlocked(data, cnt);
14171417
prejit_unlock();
14181418
}
14191419

src/include/cpu-emu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ char *e_scp_disasm(cpuctx_t *scp, int pmode);
6464

6565
/* called from mfs.c, fatfs.c and some places that memcpy */
6666
void e_invalidate(unsigned data, int cnt);
67+
void e_invalidate_unlocked(unsigned data, int cnt);
6768
void e_invalidate_full(unsigned data, int cnt);
6869
void e_invalidate_full_pa(unsigned data, int cnt);
6970
int e_invalidate_page_full(unsigned data);

0 commit comments

Comments
 (0)