From: Julian Seward Date: Sun, 17 Dec 2006 18:58:55 +0000 (+0000) Subject: A naming-only change: rename VG_(set_running) to VG_(acquire_BigLock) X-Git-Tag: svn/VALGRIND_3_3_0~478 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a96416a3e24d28574b05ef101ac05d841b0e31cd;p=thirdparty%2Fvalgrind.git A naming-only change: rename VG_(set_running) to VG_(acquire_BigLock) and VG_(set_sleeping) to VG_(release_BigLock). And some other minor renamings to the thread locking stuff, to make it easier to follow. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6408 --- diff --git a/coregrind/m_scheduler/priv_sema.h b/coregrind/m_scheduler/priv_sema.h index 658025f8af..5f1732e343 100644 --- a/coregrind/m_scheduler/priv_sema.h +++ b/coregrind/m_scheduler/priv_sema.h @@ -31,11 +31,10 @@ #ifndef __PRIV_SEMA_H #define __PRIV_SEMA_H -/* Not really a semaphore, but use a pipe for a token-passing scheme */ /* Not really a semaphore, but use a pipe for a token-passing scheme */ typedef struct { Int pipe[2]; - Int owner_thread; /* who currently has it */ + Int owner_lwpid; /* who currently has it */ } vg_sema_t; // Nb: this may be OS-specific, but let's not factor it out until we diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c index 98a7e15b41..e439e4994b 100644 --- a/coregrind/m_scheduler/scheduler.c +++ b/coregrind/m_scheduler/scheduler.c @@ -38,13 +38,13 @@ There are no extra threads. The main difference is that Valgrind only allows one client thread - to run at once. This is controlled with the VCPU semaphore, - "run_sema". Any time a thread wants to run client code or + to run at once. This is controlled with the CPU Big Lock, + "the_BigLock". Any time a thread wants to run client code or manipulate any shared state (which is anything other than its own - ThreadState entry), it must hold the run_sema. + ThreadState entry), it must hold the_BigLock. When a thread is about to block in a blocking syscall, it releases - run_sema, and re-takes it when it becomes runnable again (either + the_BigLock, and re-takes it when it becomes runnable again (either because the syscall finished, or we took a signal). VG_(scheduler) therefore runs in each thread. It returns only when @@ -135,7 +135,7 @@ void VG_(print_scheduler_stats)(void) } /* CPU semaphore, so that threads can run exclusively */ -static vg_sema_t run_sema; +static vg_sema_t the_BigLock; /* --------------------------------------------------------------------- @@ -189,14 +189,14 @@ ThreadId VG_(alloc_ThreadState) ( void ) } /* - Mark a thread as Runnable. This will block until the run_sema is + Mark a thread as Runnable. This will block until the_BigLock is available, so that we get exclusive access to all the shared - structures and the CPU. Up until we get the sema, we must not + structures and the CPU. Up until we get the_BigLock, we must not touch any shared state. When this returns, we'll actually be running. */ -void VG_(set_running)(ThreadId tid, HChar* who) +void VG_(acquire_BigLock)(ThreadId tid, HChar* who) { ThreadState *tst; @@ -209,10 +209,10 @@ void VG_(set_running)(ThreadId tid, HChar* who) } #endif - /* First, acquire the lock. We can't do anything else safely prior - to this point. Even doing debug printing prior to this point - is, technically, wrong. */ - ML_(sema_down)(&run_sema); + /* First, acquire the_BigLock. We can't do anything else safely + prior to this point. Even doing debug printing prior to this + point is, technically, wrong. */ + ML_(sema_down)(&the_BigLock); tst = VG_(get_ThreadState)(tid); @@ -246,7 +246,7 @@ void VG_(set_running)(ThreadId tid, HChar* who) but it may mean that we remain in a Runnable state and we're just yielding the CPU to another thread). */ -void VG_(set_sleeping)(ThreadId tid, ThreadStatus sleepstate, HChar* who) +void VG_(release_BigLock)(ThreadId tid, ThreadStatus sleepstate, HChar* who) { ThreadState *tst = VG_(get_ThreadState)(tid); @@ -268,9 +268,9 @@ void VG_(set_sleeping)(ThreadId tid, ThreadStatus sleepstate, HChar* who) print_sched_event(tid, buf); } - /* Release the run_sema; this will reschedule any runnable + /* Release the_BigLock; this will reschedule any runnable thread. */ - ML_(sema_up)(&run_sema); + ML_(sema_up)(&the_BigLock); } /* Clear out the ThreadState and release the semaphore. Leaves the @@ -291,7 +291,7 @@ void VG_(exit_thread)(ThreadId tid) if (VG_(clo_trace_sched)) print_sched_event(tid, "release lock in VG_(exit_thread)"); - ML_(sema_up)(&run_sema); + ML_(sema_up)(&the_BigLock); } /* If 'tid' is blocked in a syscall, send it SIGVGKILL so as to get it @@ -321,14 +321,14 @@ void VG_(vg_yield)(void) vg_assert(tid != VG_INVALID_THREADID); vg_assert(VG_(threads)[tid].os_state.lwpid == VG_(gettid)()); - VG_(set_sleeping)(tid, VgTs_Yielding, "VG_(vg_yield)"); + VG_(release_BigLock)(tid, VgTs_Yielding, "VG_(vg_yield)"); /* Tell the kernel we're yielding. */ VG_(do_syscall0)(__NR_sched_yield); - VG_(set_running)(tid, "VG_(vg_yield)"); + VG_(acquire_BigLock)(tid, "VG_(vg_yield)"); } @@ -413,9 +413,9 @@ void mostly_clear_thread_record ( ThreadId tid ) would be too hard to try to re-number the thread and relocate the thread state down to VG_(threads)[1]. - This function also needs to reinitialize the run_sema, since - otherwise we may end up sharing its state with the parent, which - would be deeply confusing. + This function also needs to reinitialize the_BigLock, since + otherwise we may end up sharing its state with the parent, which + would be deeply confusing. */ static void sched_fork_cleanup(ThreadId me) { @@ -435,9 +435,9 @@ static void sched_fork_cleanup(ThreadId me) } /* re-init and take the sema */ - ML_(sema_deinit)(&run_sema); - ML_(sema_init)(&run_sema); - ML_(sema_down)(&run_sema); + ML_(sema_deinit)(&the_BigLock); + ML_(sema_init)(&the_BigLock); + ML_(sema_down)(&the_BigLock); } @@ -457,7 +457,7 @@ void VG_(scheduler_init) ( Addr clstack_end, SizeT clstack_size ) vg_assert(VG_IS_PAGE_ALIGNED(clstack_end+1)); vg_assert(VG_IS_PAGE_ALIGNED(clstack_size)); - ML_(sema_init)(&run_sema); + ML_(sema_init)(&the_BigLock); for (i = 0 /* NB; not 1 */; i < VG_N_THREADS; i++) { /* Paranoia .. completely zero it out. */ @@ -813,7 +813,7 @@ static UInt/*trc*/ handle_noredir_jump ( ThreadId tid ) /* Run a thread until it wants to exit. - We assume that the caller has already called VG_(set_running) for + We assume that the caller has already called VG_(acquire_BigLock) for us, so we own the VCPU. Also, all signals are blocked. */ VgSchedReturnCode VG_(scheduler) ( ThreadId tid ) @@ -860,8 +860,8 @@ VgSchedReturnCode VG_(scheduler) ( ThreadId tid ) /* 3 Aug 06: doing sys__nsleep works but crashes some apps. sys_yield also helps the problem, whilst not crashing apps. */ - VG_(set_sleeping)(tid, VgTs_Yielding, - "VG_(scheduler):timeslice"); + VG_(release_BigLock)(tid, VgTs_Yielding, + "VG_(scheduler):timeslice"); /* ------------ now we don't have The Lock ------------ */ # if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5) @@ -878,7 +878,7 @@ VgSchedReturnCode VG_(scheduler) ( ThreadId tid ) } # endif - VG_(set_running)(tid, "VG_(scheduler):timeslice"); + VG_(acquire_BigLock)(tid, "VG_(scheduler):timeslice"); /* ------------ now we do have The Lock ------------ */ /* OK, do some relatively expensive housekeeping stuff */ @@ -1387,7 +1387,7 @@ void scheduler_sanity ( ThreadId tid ) if (!VG_(is_running_thread)(tid)) { VG_(message)(Vg_DebugMsg, "Thread %d is supposed to be running, " - "but doesn't own run_sema (owned by %d)\n", + "but doesn't own the_BigLock (owned by %d)\n", tid, VG_(running_tid)); bad = True; } @@ -1399,9 +1399,9 @@ void scheduler_sanity ( ThreadId tid ) bad = True; } - if (lwpid != run_sema.owner_thread) { + if (lwpid != the_BigLock.owner_lwpid) { VG_(message)(Vg_DebugMsg, - "Thread %d doesn't own the run_sema\n", + "Thread (LWPID) %d doesn't own the_BigLock\n", tid); bad = True; } diff --git a/coregrind/m_scheduler/sema.c b/coregrind/m_scheduler/sema.c index b175fa3206..459d2f0754 100644 --- a/coregrind/m_scheduler/sema.c +++ b/coregrind/m_scheduler/sema.c @@ -65,7 +65,7 @@ void ML_(sema_init)(vg_sema_t *sema) sema->pipe[1]); vg_assert(sema->pipe[0] != sema->pipe[1]); - sema->owner_thread = -1; + sema->owner_lwpid = -1; /* create initial token */ sema_char = 'A'; @@ -78,12 +78,12 @@ void ML_(sema_init)(vg_sema_t *sema) void ML_(sema_deinit)(vg_sema_t *sema) { - vg_assert(sema->owner_thread != -1); /* must be initialised */ + vg_assert(sema->owner_lwpid != -1); /* must be initialised */ vg_assert(sema->pipe[0] != sema->pipe[1]); VG_(close)(sema->pipe[0]); VG_(close)(sema->pipe[1]); sema->pipe[0] = sema->pipe[1] = -1; - sema->owner_thread = -1; + sema->owner_lwpid = -1; } /* get a token */ @@ -93,7 +93,7 @@ void ML_(sema_down)(vg_sema_t *sema) Int ret; Int lwpid = VG_(gettid)(); - vg_assert(sema->owner_thread != lwpid); /* can't have it already */ + vg_assert(sema->owner_lwpid != lwpid); /* can't have it already */ vg_assert(sema->pipe[0] != sema->pipe[1]); again: @@ -113,7 +113,7 @@ void ML_(sema_down)(vg_sema_t *sema) if (sema_char == 'Z') sema_char = 'A'; else sema_char++; - sema->owner_thread = lwpid; + sema->owner_lwpid = lwpid; } /* put token back */ @@ -123,11 +123,11 @@ void ML_(sema_up)(vg_sema_t *sema) Char buf[2]; buf[0] = sema_char; buf[1] = 0; - vg_assert(sema->owner_thread != -1); /* must be initialised */ + vg_assert(sema->owner_lwpid != -1); /* must be initialised */ vg_assert(sema->pipe[0] != sema->pipe[1]); - vg_assert(sema->owner_thread == VG_(gettid)()); /* must have it */ + vg_assert(sema->owner_lwpid == VG_(gettid)()); /* must have it */ - sema->owner_thread = 0; + sema->owner_lwpid = 0; ret = VG_(write)(sema->pipe[1], buf, 1); diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c index d46744ecf6..63a85ffa70 100644 --- a/coregrind/m_signals.c +++ b/coregrind/m_signals.c @@ -1589,7 +1589,7 @@ void async_signalhandler ( Int sigNo, vki_siginfo_t *info, struct vki_ucontext * vg_assert(tst->status == VgTs_WaitSys); /* The thread isn't currently running, make it so before going on */ - VG_(set_running)(tid, "async_signalhandler"); + VG_(acquire_BigLock)(tid, "async_signalhandler"); /* Update thread state properly */ VG_(fixup_guest_state_after_syscall_interrupted)( @@ -1915,7 +1915,7 @@ static void sigvgkill_handler(int signo, vki_siginfo_t *si, struct vki_ucontext VG_(message)(Vg_DebugMsg, "sigvgkill for lwp %d tid %d", VG_(gettid)(), tid); - VG_(set_running)(tid, "sigvgkill_handler"); + VG_(acquire_BigLock)(tid, "sigvgkill_handler"); vg_assert(signo == VG_SIGVGKILL); vg_assert(si->si_signo == signo); diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index f4d8504b59..a9c6c200e3 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -71,7 +71,7 @@ static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW) vg_assert(tst->status == VgTs_Init); /* make sure we get the CPU lock before doing anything significant */ - VG_(set_running)(tid, "thread_wrapper(starting new thread)"); + VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)"); if (0) VG_(printf)("thread tid %d started: stack = %p\n", diff --git a/coregrind/m_syswrap/syswrap-main.c b/coregrind/m_syswrap/syswrap-main.c index e259f2644b..1a4f7b7a4f 100644 --- a/coregrind/m_syswrap/syswrap-main.c +++ b/coregrind/m_syswrap/syswrap-main.c @@ -38,7 +38,7 @@ #include "pub_core_libcprint.h" #include "pub_core_libcproc.h" // For VG_(getpid)() #include "pub_core_libcsignal.h" -#include "pub_core_scheduler.h" // For VG_(set_sleeping), VG_(set_running), +#include "pub_core_scheduler.h" // For VG_({acquire,release}_BigLock), // and VG_(vg_yield) #include "pub_core_stacktrace.h" // For VG_(get_and_pp_StackTrace)() #include "pub_core_tooliface.h" @@ -915,7 +915,7 @@ void VG_(client_syscall) ( ThreadId tid ) putSyscallArgsIntoGuestState( &sci->args, &tst->arch.vex ); /* Drop the lock */ - VG_(set_sleeping)(tid, VgTs_WaitSys, "VG_(client_syscall)[async]"); + VG_(release_BigLock)(tid, VgTs_WaitSys, "VG_(client_syscall)[async]"); /* Do the call, which operates directly on the guest state, not on our abstracted copies of the args/result. */ @@ -930,7 +930,7 @@ void VG_(client_syscall) ( ThreadId tid ) to the scheduler. */ /* Reacquire the lock */ - VG_(set_running)(tid, "VG_(client_syscall)[async]"); + VG_(acquire_BigLock)(tid, "VG_(client_syscall)[async]"); /* Even more impedance matching. Extract the syscall status from the guest state. */ diff --git a/coregrind/m_syswrap/syswrap-ppc32-aix5.c b/coregrind/m_syswrap/syswrap-ppc32-aix5.c index c3f9b89476..6e2c202efe 100644 --- a/coregrind/m_syswrap/syswrap-ppc32-aix5.c +++ b/coregrind/m_syswrap/syswrap-ppc32-aix5.c @@ -94,7 +94,7 @@ static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW) vg_assert(tst->status == VgTs_Init); /* make sure we get the CPU lock before doing anything significant */ - VG_(set_running)(tid, "thread_wrapper(starting new thread)"); + VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)"); if (0) VG_(printf)("thread tid %d started: stack = %p\n", diff --git a/coregrind/m_syswrap/syswrap-ppc64-aix5.c b/coregrind/m_syswrap/syswrap-ppc64-aix5.c index 9c95d46a67..74bb11c9c0 100644 --- a/coregrind/m_syswrap/syswrap-ppc64-aix5.c +++ b/coregrind/m_syswrap/syswrap-ppc64-aix5.c @@ -94,7 +94,7 @@ static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW) vg_assert(tst->status == VgTs_Init); /* make sure we get the CPU lock before doing anything significant */ - VG_(set_running)(tid, "thread_wrapper(starting new thread)"); + VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)"); if (0) VG_(printf)("thread tid %d started: stack = %p\n", diff --git a/coregrind/pub_core_scheduler.h b/coregrind/pub_core_scheduler.h index 7e71513b90..8e8df63133 100644 --- a/coregrind/pub_core_scheduler.h +++ b/coregrind/pub_core_scheduler.h @@ -57,7 +57,7 @@ extern void VG_(nuke_all_threads_except) ( ThreadId me, thread state to VgTs_Runnable, and the thread will attempt to take the CPU lock. By the time it returns, tid will be the running thread. */ -extern void VG_(set_running) ( ThreadId tid, HChar* who ); +extern void VG_(acquire_BigLock) ( ThreadId tid, HChar* who ); /* Set a thread into a sleeping state. Before the call, the thread must be runnable, and holding the CPU lock. When this call @@ -67,7 +67,7 @@ extern void VG_(set_running) ( ThreadId tid, HChar* who ); caller must be careful not to touch any shared state. It is also the caller's responsibility to actually block until the thread is ready to run again. */ -extern void VG_(set_sleeping) ( ThreadId tid, ThreadStatus state, HChar* who ); +extern void VG_(release_BigLock) ( ThreadId tid, ThreadStatus state, HChar* who ); /* Yield the CPU for a while */ extern void VG_(vg_yield)(void);