Fix race by using atomic operation, with this change, both libpthread
and libthr now can run profiling on SMP.
This commit is contained in:
parent
fd94099ec2
commit
0fa2f94316
@ -49,6 +49,7 @@ void btrap(void);
|
|||||||
void eintr(void);
|
void eintr(void);
|
||||||
void user(void);
|
void user(void);
|
||||||
#endif
|
#endif
|
||||||
|
#include <machine/atomic.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mcount is called on entry to each function compiled with the profiling
|
* mcount is called on entry to each function compiled with the profiling
|
||||||
@ -92,7 +93,8 @@ _MCOUNT_DECL(uintfptr_t frompc, uintfptr_t selfpc)
|
|||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
MCOUNT_ENTER(s);
|
MCOUNT_ENTER(s);
|
||||||
#else
|
#else
|
||||||
p->state = GMON_PROF_BUSY;
|
if (!atomic_cmpset_acq_int(&p->state, GMON_PROF_ON, GMON_PROF_BUSY))
|
||||||
|
return;
|
||||||
#endif
|
#endif
|
||||||
frompci = frompc - p->lowpc;
|
frompci = frompc - p->lowpc;
|
||||||
|
|
||||||
@ -260,11 +262,11 @@ done:
|
|||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
MCOUNT_EXIT(s);
|
MCOUNT_EXIT(s);
|
||||||
#else
|
#else
|
||||||
p->state = GMON_PROF_ON;
|
atomic_store_rel_int(&p->state, GMON_PROF_ON);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
overflow:
|
overflow:
|
||||||
p->state = GMON_PROF_ERROR;
|
atomic_store_rel_int(&p->state, GMON_PROF_ERROR);
|
||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
MCOUNT_EXIT(s);
|
MCOUNT_EXIT(s);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user