From a683ecf9f32b4b7d8fa9aece4e13e7cc3c592069 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 26 Mar 2014 23:19:04 +0000 Subject: [PATCH] Add and document new configuration options config_thread_single and config_protection_none. Copied from Perforce Change: 185037 ServerID: perforce.ravenbrook.com --- mps/code/config.h | 29 +++++++++++++++++++++++++++-- mps/code/lock.h | 13 ++----------- mps/code/lockix.c | 24 ++++++++++++------------ mps/code/lockli.c | 24 ++++++++++++------------ mps/code/lockw3.c | 24 ++++++++++++------------ mps/design/config.txt | 39 +++++++++++++++++++++++++++++++++++++-- 6 files changed, 102 insertions(+), 51 deletions(-) diff --git a/mps/code/config.h b/mps/code/config.h index bf056d2dc0d..a1ebc2e688a 100644 --- a/mps/code/config.h +++ b/mps/code/config.h @@ -164,6 +164,33 @@ #endif +/* CONFIG_THREAD_SINGLE -- support single-threaded execution only + * + * This symbol causes the MPS to be built for single-threaded + * execution only, where locks are not needed and so lock operations + * can be defined as no-ops by lock.h. + */ + +#if defined(CONFIG_THREAD_SINGLE) +#define THREAD_SINGLE +#else +#define THREAD_MULTI +#endif + +/* CONFIG_PROTECTION_NONE -- no support for memory protection + * + * This symbol causes the MPS to built for an environment where there + * is no memory protection, and so segment summaries cannot be + * maintained by seg.c. + */ + +#if defined(CONFIG_PROTECTION_NONE) +#define PROTECTION_NONE +#else +#define PROTECTION +#endif + + #define MPS_VARIETY_STRING \ MPS_ASSERT_STRING "." MPS_LOG_STRING "." MPS_STATS_STRING @@ -517,8 +544,6 @@ #define MPS_PROD_STRING "mps" #define MPS_PROD_MPS -#define THREAD_MULTI -#define PROTECTION #define PROD_CHECKLEVEL_INITIAL CheckLevelSHALLOW /* TODO: This should be proportional to the memory usage of the MPS, not diff --git a/mps/code/lock.h b/mps/code/lock.h index 1431bbacd85..5faddfa05b8 100644 --- a/mps/code/lock.h +++ b/mps/code/lock.h @@ -85,9 +85,6 @@ #define LockSig ((Sig)0x51970CC9) /* SIGnature LOCK */ -#if defined(THREAD_MULTI) - - /* LockSize -- Return the size of a LockStruct * * Supports allocation of locks. @@ -198,8 +195,7 @@ extern void LockClaimGlobal(void); extern void LockReleaseGlobal(void); -#elif defined(THREAD_SINGLE) - +#ifdef THREAD_SINGLE #define LockSize() MPS_PF_ALIGN #define LockInit(lock) UNUSED(lock) @@ -214,12 +210,7 @@ extern void LockReleaseGlobal(void); #define LockClaimGlobal() #define LockReleaseGlobal() - -#else - -#error "No threading defined." - -#endif +#endif /* THREAD_SINGLE */ #endif /* lock_h */ diff --git a/mps/code/lockix.c b/mps/code/lockix.c index c32361e8560..2afd294246e 100644 --- a/mps/code/lockix.c +++ b/mps/code/lockix.c @@ -58,7 +58,7 @@ typedef struct LockStruct { /* LockSize -- size of a LockStruct */ -size_t LockSize(void) +size_t (LockSize)(void) { return sizeof(LockStruct); } @@ -66,7 +66,7 @@ size_t LockSize(void) /* LockCheck -- check a lock */ -Bool LockCheck(Lock lock) +Bool (LockCheck)(Lock lock) { CHECKS(Lock, lock); /* While claims can't be very large, I don't dare to put a limit on it. */ @@ -77,7 +77,7 @@ Bool LockCheck(Lock lock) /* LockInit -- initialize a lock */ -void LockInit(Lock lock) +void (LockInit)(Lock lock) { pthread_mutexattr_t attr; int res; @@ -99,7 +99,7 @@ void LockInit(Lock lock) /* LockFinish -- finish a lock */ -void LockFinish(Lock lock) +void (LockFinish)(Lock lock) { int res; @@ -114,7 +114,7 @@ void LockFinish(Lock lock) /* LockClaim -- claim a lock (non-recursive) */ -void LockClaim(Lock lock) +void (LockClaim)(Lock lock) { int res; @@ -133,7 +133,7 @@ void LockClaim(Lock lock) /* LockReleaseMPM -- release a lock (non-recursive) */ -void LockReleaseMPM(Lock lock) +void (LockReleaseMPM)(Lock lock) { int res; @@ -148,7 +148,7 @@ void LockReleaseMPM(Lock lock) /* LockClaimRecursive -- claim a lock (recursive) */ -void LockClaimRecursive(Lock lock) +void (LockClaimRecursive)(Lock lock) { int res; @@ -168,7 +168,7 @@ void LockClaimRecursive(Lock lock) /* LockReleaseRecursive -- release a lock (recursive) */ -void LockReleaseRecursive(Lock lock) +void (LockReleaseRecursive)(Lock lock) { int res; @@ -203,7 +203,7 @@ static void globalLockInit(void) /* LockClaimGlobalRecursive -- claim the global recursive lock */ -void LockClaimGlobalRecursive(void) +void (LockClaimGlobalRecursive)(void) { int res; @@ -216,7 +216,7 @@ void LockClaimGlobalRecursive(void) /* LockReleaseGlobalRecursive -- release the global recursive lock */ -void LockReleaseGlobalRecursive(void) +void (LockReleaseGlobalRecursive)(void) { LockReleaseRecursive(globalRecLock); } @@ -224,7 +224,7 @@ void LockReleaseGlobalRecursive(void) /* LockClaimGlobal -- claim the global non-recursive lock */ -void LockClaimGlobal(void) +void (LockClaimGlobal)(void) { int res; @@ -237,7 +237,7 @@ void LockClaimGlobal(void) /* LockReleaseGlobal -- release the global non-recursive lock */ -void LockReleaseGlobal(void) +void (LockReleaseGlobal)(void) { LockReleaseMPM(globalLock); } diff --git a/mps/code/lockli.c b/mps/code/lockli.c index 06437b5b531..5e63e15d291 100644 --- a/mps/code/lockli.c +++ b/mps/code/lockli.c @@ -72,7 +72,7 @@ typedef struct LockStruct { /* LockSize -- size of a LockStruct */ -size_t LockSize(void) +size_t (LockSize)(void) { return sizeof(LockStruct); } @@ -80,7 +80,7 @@ size_t LockSize(void) /* LockCheck -- check a lock */ -Bool LockCheck(Lock lock) +Bool (LockCheck)(Lock lock) { CHECKS(Lock, lock); /* While claims can't be very large, I don't dare to put a limit on it. */ @@ -91,7 +91,7 @@ Bool LockCheck(Lock lock) /* LockInit -- initialize a lock */ -void LockInit(Lock lock) +void (LockInit)(Lock lock) { pthread_mutexattr_t attr; int res; @@ -113,7 +113,7 @@ void LockInit(Lock lock) /* LockFinish -- finish a lock */ -void LockFinish(Lock lock) +void (LockFinish)(Lock lock) { int res; @@ -128,7 +128,7 @@ void LockFinish(Lock lock) /* LockClaim -- claim a lock (non-recursive) */ -void LockClaim(Lock lock) +void (LockClaim)(Lock lock) { int res; @@ -147,7 +147,7 @@ void LockClaim(Lock lock) /* LockReleaseMPM -- release a lock (non-recursive) */ -void LockReleaseMPM(Lock lock) +void (LockReleaseMPM)(Lock lock) { int res; @@ -162,7 +162,7 @@ void LockReleaseMPM(Lock lock) /* LockClaimRecursive -- claim a lock (recursive) */ -void LockClaimRecursive(Lock lock) +void L(ockClaimRecursive)(Lock lock) { int res; @@ -182,7 +182,7 @@ void LockClaimRecursive(Lock lock) /* LockReleaseRecursive -- release a lock (recursive) */ -void LockReleaseRecursive(Lock lock) +void (LockReleaseRecursive)(Lock lock) { int res; @@ -217,7 +217,7 @@ static void globalLockInit(void) /* LockClaimGlobalRecursive -- claim the global recursive lock */ -void LockClaimGlobalRecursive(void) +void (LockClaimGlobalRecursive)(void) { int res; @@ -230,7 +230,7 @@ void LockClaimGlobalRecursive(void) /* LockReleaseGlobalRecursive -- release the global recursive lock */ -void LockReleaseGlobalRecursive(void) +void (LockReleaseGlobalRecursive)(void) { LockReleaseRecursive(globalRecLock); } @@ -238,7 +238,7 @@ void LockReleaseGlobalRecursive(void) /* LockClaimGlobal -- claim the global non-recursive lock */ -void LockClaimGlobal(void) +void (LockClaimGlobal)(void) { int res; @@ -251,7 +251,7 @@ void LockClaimGlobal(void) /* LockReleaseGlobal -- release the global non-recursive lock */ -void LockReleaseGlobal(void) +void (LockReleaseGlobal)(void) { LockReleaseMPM(globalLock); } diff --git a/mps/code/lockw3.c b/mps/code/lockw3.c index 258b31bff44..2fdc2800032 100644 --- a/mps/code/lockw3.c +++ b/mps/code/lockw3.c @@ -40,18 +40,18 @@ typedef struct LockStruct { } LockStruct; -size_t LockSize(void) +size_t (LockSize)(void) { return sizeof(LockStruct); } -Bool LockCheck(Lock lock) +Bool (LockCheck)(Lock lock) { CHECKS(Lock, lock); return TRUE; } -void LockInit(Lock lock) +void (LockInit)(Lock lock) { AVER(lock != NULL); lock->claims = 0; @@ -60,7 +60,7 @@ void LockInit(Lock lock) AVERT(Lock, lock); } -void LockFinish(Lock lock) +void (LockFinish)(Lock lock) { AVERT(Lock, lock); /* Lock should not be finished while held */ @@ -69,7 +69,7 @@ void LockFinish(Lock lock) lock->sig = SigInvalid; } -void LockClaim(Lock lock) +void (LockClaim)(Lock lock) { AVERT(Lock, lock); EnterCriticalSection(&lock->cs); @@ -79,7 +79,7 @@ void LockClaim(Lock lock) lock->claims = 1; } -void LockReleaseMPM(Lock lock) +void (LockReleaseMPM)(Lock lock) { AVERT(Lock, lock); AVER(lock->claims == 1); /* The lock should only be held once */ @@ -87,7 +87,7 @@ void LockReleaseMPM(Lock lock) LeaveCriticalSection(&lock->cs); } -void LockClaimRecursive(Lock lock) +void (LockClaimRecursive)(Lock lock) { AVERT(Lock, lock); EnterCriticalSection(&lock->cs); @@ -95,7 +95,7 @@ void LockClaimRecursive(Lock lock) AVER(lock->claims > 0); } -void LockReleaseRecursive(Lock lock) +void (LockReleaseRecursive)(Lock lock) { AVERT(Lock, lock); AVER(lock->claims > 0); @@ -129,27 +129,27 @@ static void lockEnsureGlobalLock(void) } } -void LockClaimGlobalRecursive(void) +void (LockClaimGlobalRecursive)(void) { lockEnsureGlobalLock(); AVER(globalLockInit); LockClaimRecursive(globalRecLock); } -void LockReleaseGlobalRecursive(void) +void (LockReleaseGlobalRecursive)(void) { AVER(globalLockInit); LockReleaseRecursive(globalRecLock); } -void LockClaimGlobal(void) +void (LockClaimGlobal)(void) { lockEnsureGlobalLock(); AVER(globalLockInit); LockClaim(globalLock); } -void LockReleaseGlobal(void) +void (LockReleaseGlobal)(void) { AVER(globalLockInit); LockReleaseMPM(globalLock); diff --git a/mps/design/config.txt b/mps/design/config.txt index 03bfec5109a..c7184ab31ee 100644 --- a/mps/design/config.txt +++ b/mps/design/config.txt @@ -97,6 +97,10 @@ as a dimension of configuration since `.req.prod`_ has been retired. _`.def.target`: The *target* is the result of the build. +_`.def.option`: An *option* is a feature of the MPS that is not +selected via the *platform* and *variety*. See `.opt`_. + + Overview -------- @@ -150,7 +154,7 @@ _`.build.cc`: A consequence of this approach is that it should always be possible to build a complete target with a single UNIX command line calling the compiler driver (usually "cc" or "gcc"), for example:: - cc -o main -DCONFIG_VAR_DF foo.c bar.c baz.s -lz + cc -o main -DCONFIG_VAR_COOL foo.c bar.c baz.s -lz _`.build.defs`: The "defs" are the set of preprocessor macros which are to be predefined when compiling the module sources:: @@ -319,12 +323,14 @@ _`.pf.form`: This file consists of sets of directives of the form:: #elif #define MPS_PF_ + #define MPS_PF_STRING "" #define MPS_OS_ #define MPS_ARCH_ #define MPS_BUILD_ #define MPS_T_WORD #define MPS_T_ULONGEST - #define MPS_WORD_SHIFT + #define MPS_WORD_WIDTH + #define MPS_WORD_SHIFT #define MPS_PF_ALIGN _`.pf.detect`: The conjunction of builder predefinitions is a constant @@ -513,6 +519,35 @@ For example, this sort of thing:: This violates `.no-spaghetti`_. +Configuration options +--------------------- + +_`.opt`: Options select features of the MPS that are not selected by the *platform* and the *variety*. + +_`.opt.support`: The features selected by options are not supported or +documented in the public interface. This is to keep the complexity of +the MPS manageable: at present the number of supported configuration +is *platforms* × *varieties* (at time of writing, 9 × 3 = 27). Each +supported option would double (or worse) the number of supported +configurations. + +_`.opt.ansi`: ``CONFIG_PF_ANSI`` tells ``mps.c`` to exclude the +sources for the auto-detected platform, and use the generic ("ANSI") +platform instead. + +_`.opt.thread`: ``CONFIG_THREAD_SINGLE`` causes the MPS to be built +for single-threaded execution only, where locks are not needed and so +lock operations can be defined as no-ops by ``lock.h``. + +_`.opt.prot`: ``CONFIG_PROTECTION_NONE`` causes the MPS to be built +for an environment where there is no memory protection, and so segment summaries cannot be maintained by ``seg.c``. + +_`.opt.prot.thread`: If both ``CONFIG_THREAD_SINGLE`` and +``CONFIG_PROTECTION_NONE`` are defined, then the shield is not needed +and so shield operations can be defined as no-ops by ``mpm.h``. + + + To document ----------- - What about constants in config.h?