Commit a2a67cd5 authored by Simon Marlow's avatar Simon Marlow

RTS tidyup sweep, first phase

The first phase of this tidyup is focussed on the header files, and in
particular making sure we are exposinng publicly exactly what we need
to, and no more.

 - Rts.h now includes everything that the RTS exposes publicly,
   rather than a random subset of it.

 - Most of the public header files have moved into subdirectories, and
   many of them have been renamed.  But clients should not need to
   include any of the other headers directly, just #include the main
   public headers: Rts.h, HsFFI.h, RtsAPI.h.

 - All the headers needed for via-C compilation have moved into the
   stg subdirectory, which is self-contained.  Most of the headers for
   the rest of the RTS APIs have moved into the rts subdirectory.

 - I left MachDeps.h where it is, because it is so widely used in
   Haskell code.
 
 - I left a deprecated stub for RtsFlags.h in place.  The flag
   structures are now exposed by Rts.h.

 - Various internal APIs are no longer exposed by public header files.

 - Various bits of dead code and declarations have been removed

 - More gcc warnings are turned on, and the RTS code is more
   warning-clean.

 - More source files #include "PosixSource.h", and hence only use
   standard POSIX (1003.1c-1995) interfaces.

There is a lot more tidying up still to do, this is just the first
pass.  I also intend to standardise the names for external RTS APIs
(e.g use the rts_ prefix consistently), and declare the internal APIs
as hidden for shared libraries.
parent 5d379cbe
......@@ -58,7 +58,7 @@ cmmToRawCmm cmm = do
-- <normal forward rest of StgInfoTable>
-- <forward variable part>
--
-- See includes/InfoTables.h
-- See includes/rts/storage/InfoTables.h
--
-- For return-points these are as follows
--
......
......@@ -56,7 +56,7 @@ import Data.Maybe
-- Temp Jan08
import SMRep
import ClosureInfo
#include "../includes/StgFun.h"
#include "../includes/rts/storage/FunTypes.h"
pprCmms :: (Outputable info, Outputable g) => [GenCmm CmmStatic info g] -> SDoc
......
......@@ -64,7 +64,7 @@ import Data.Bits
-------------------------------------------------------------------------
-- bring in ARG_P, ARG_N, etc.
#include "../includes/StgFun.h"
#include "../includes/rts/storage/FunTypes.h"
-------------------------
argDescrType :: ArgDescr -> StgHalfWord
......
......@@ -24,9 +24,9 @@ module CgProf (
) where
#include "HsVersions.h"
#include "MachDeps.h"
#include "../includes/MachDeps.h"
-- For WORD_SIZE_IN_BITS only.
#include "../includes/Constants.h"
#include "../includes/rts/Constants.h"
-- For LDV_CREATE_MASK, LDV_STATE_USE
-- which are StgWords
#include "../includes/DerivedConstants.h"
......
......@@ -50,7 +50,7 @@ module CgUtils (
) where
#include "HsVersions.h"
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
import BlockId
import CgMonad
......
......@@ -246,7 +246,7 @@ data SMRep
| BlackHoleRep
data ClosureType -- Corresponds 1-1 with the varieties of closures
-- implemented by the RTS. Compare with ghc/includes/ClosureTypes.h
-- implemented by the RTS. Compare with includes/rts/storage/ClosureTypes.h
= Constr
| ConstrNoCaf
| Fun
......@@ -284,7 +284,7 @@ isStaticRep BlackHoleRep = False
\end{code}
\begin{code}
#include "../includes/ClosureTypes.h"
#include "../includes/rts/storage/ClosureTypes.h"
-- Defines CONSTR, CONSTR_1_0 etc
-- krc: only called by tickyDynAlloc in CgTicky; return
......
......@@ -313,7 +313,7 @@ mkVirtHeapOffsets is_thunk things
-------------------------------------------------------------------------
-- bring in ARG_P, ARG_N, etc.
#include "../includes/StgFun.h"
#include "../includes/rts/storage/FunTypes.h"
-------------------------
-- argDescrType :: ArgDescr -> StgHalfWord
......
......@@ -25,9 +25,9 @@ module StgCmmProf (
) where
#include "HsVersions.h"
#include "MachDeps.h"
#include "../includes/MachDeps.h"
-- For WORD_SIZE_IN_BITS only.
#include "../includes/Constants.h"
#include "../includes/rts/Constants.h"
-- For LDV_CREATE_MASK, LDV_STATE_USE
-- which are StgWords
#include "../includes/DerivedConstants.h"
......
......@@ -44,7 +44,7 @@ module StgCmmUtils (
) where
#include "HsVersions.h"
#include "MachRegs.h"
#include "../includes/stg/MachRegs.h"
import StgCmmMonad
import StgCmmClosure
......
......@@ -208,7 +208,7 @@ sizeSS16 :: SizedSeq a -> Word16
sizeSS16 (SizedSeq n _) = fromIntegral n
-- Bring in all the bci_ bytecode constants.
#include "Bytecodes.h"
#include "rts/Bytecodes.h"
largeArgInstr :: Word16 -> Word16
largeArgInstr bci = bci_FLAG_LARGE_ARGS .|. bci
......
......@@ -84,7 +84,7 @@ mkITbl tc
dcs = tyConDataCons tc
n = tyConFamilySize tc
#include "../includes/ClosureTypes.h"
#include "../includes/rts/storage/ClosureTypes.h"
cONSTR :: Int -- Defined in ClosureTypes.h
cONSTR = CONSTR
......@@ -151,7 +151,7 @@ ptrToInt (Ptr a#) = I# (addr2Int# a#)
#if sparc_TARGET_ARCH
-- After some consideration, we'll try this, where
-- 0x55555555 stands in for the address to jump to.
-- According to ghc/includes/MachRegs.h, %g3 is very
-- According to includes/rts/MachRegs.h, %g3 is very
-- likely indeed to be baggable.
--
-- 0000 07155555 sethi %hi(0x55555555), %g3
......
......@@ -165,7 +165,7 @@ data Closure = Closure { tipe :: ClosureType
instance Outputable ClosureType where
ppr = text . show
#include "../includes/ClosureTypes.h"
#include "../includes/rts/storage/ClosureTypes.h"
aP_CODE, pAP_CODE :: Int
aP_CODE = AP
......
......@@ -206,7 +206,7 @@ initBinMemSize :: Int
initBinMemSize = 1024 * 1024
-- The *host* architecture version:
#include "MachDeps.h"
#include "../includes/MachDeps.h"
binaryInterfaceMagic :: Word32
#if WORD_SIZE_IN_BITS == 32
......
......@@ -14,8 +14,8 @@ import Data.Bits (shiftL)
-- be in trouble.
#include "HsVersions.h"
#include "../includes/MachRegs.h"
#include "../includes/Constants.h"
#include "../includes/stg/MachRegs.h"
#include "../includes/rts/Constants.h"
#include "../includes/MachDeps.h"
#include "../includes/DerivedConstants.h"
......
......@@ -275,7 +275,7 @@ opt_Unregisterised = lookUp (fsLit "-funregisterised")
-- Derived, not a real option. Determines whether we will be compiling
-- info tables that reside just before the entry code, or with an
-- indirection to the entry code. See TABLES_NEXT_TO_CODE in
-- includes/InfoTables.h.
-- includes/rts/storage/InfoTables.h.
tablesNextToCode :: Bool
tablesNextToCode = not opt_Unregisterised
&& cGhcEnableTablesNextToCode == "YES"
......
......@@ -21,7 +21,7 @@ where
{-
#include "nativeGen/NCG.h"
#include "HsVersions.h"
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
import RegsBase
......
......@@ -22,7 +22,7 @@ where
#include "HsVersions.h"
#include "nativeGen/NCG.h"
#include "MachDeps.h"
#include "../includes/MachDeps.h"
-- NCG stuff:
import PPC.Instr
......
......@@ -49,7 +49,7 @@ where
#include "nativeGen/NCG.h"
#include "HsVersions.h"
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
import Reg
import RegClass
......
......@@ -43,7 +43,7 @@ import FastTypes
-- There is an allocatableRegsInClass :: RegClass -> Int, but doing the unboxing
-- is too slow for us here.
--
-- Look at includes/MachRegs.h to get these numbers.
-- Look at includes/stg/MachRegs.h to get these numbers.
--
#if i386_TARGET_ARCH
......
......@@ -115,7 +115,7 @@ import Data.Maybe
import Data.List
import Control.Monad
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
-- -----------------------------------------------------------------------------
......
......@@ -15,7 +15,7 @@ where
#include "HsVersions.h"
#include "nativeGen/NCG.h"
#include "MachDeps.h"
#include "../includes/MachDeps.h"
-- NCG stuff:
import SPARC.CodeGen.Sanity
......
......@@ -93,7 +93,7 @@ import FastBool
#define f31 63
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
-- | Check whether a machine register is free for allocation.
freeReg :: RegNo -> FastBool
......
......@@ -54,7 +54,7 @@ import FastBool
prepared for any eventuality.
The whole fp-register pairing thing on sparcs is a huge nuisance. See
fptools/ghc/includes/MachRegs.h for a description of what's going on
includes/stg/MachRegs.h for a description of what's going on
here.
-}
......@@ -290,11 +290,13 @@ regDotColor reg
-- Hard coded freeReg / globalRegMaybe -----------------------------------------
-- This isn't being used at the moment because we're generating
-- these functions from the information in includes/MachRegs.hs via RegPlate.hs
-- these functions from the information in
-- includes/stg/MachRegs.hs via RegPlate.hs
-- | Check whether a machine register is free for allocation.
-- This needs to match the info in includes/MachRegs.h otherwise modules
-- compiled with the NCG won't be compatible with via-C ones.
-- This needs to match the info in includes/stg/MachRegs.h
-- otherwise modules compiled with the NCG won't be compatible
-- with via-C ones.
--
{-
freeReg :: RegNo -> FastBool
......
......@@ -27,7 +27,7 @@ where
#include "HsVersions.h"
#include "nativeGen/NCG.h"
#include "MachDeps.h"
#include "../includes/MachDeps.h"
-- NCG stuff:
import X86.Instr
......
......@@ -466,7 +466,7 @@ pprDataItem lit
-- all such offsets will fit into 32 bits, so we have to stick
-- to 32-bit offset fields and modify the RTS appropriately
--
-- See Note [x86-64-relative] in includes/InfoTables.h
-- See Note [x86-64-relative] in includes/rts/storage/InfoTables.h
--
ppr_item II64 x
| isRelativeReloc x =
......
......@@ -54,7 +54,7 @@ where
-- HACK: go for the max
#endif
#include "../includes/MachRegs.h"
#include "../includes/stg/MachRegs.h"
import Reg
import RegClass
......
......@@ -4,7 +4,9 @@ places in the GHC library.
*/
#include "Rts.h"
#if __GLASGOW_HASKELL__ <= 610
#include "RtsFlags.h"
#endif
#include "HsFFI.h"
......@@ -20,19 +22,19 @@ and causes gcc to require too many registers on x84
*/
HsInt
ghc_strlen( HsAddr a )
ghc_strlen( HsPtr a )
{
return (strlen((char *)a));
}
HsInt
ghc_memcmp( HsAddr a1, HsAddr a2, HsInt len )
ghc_memcmp( HsPtr a1, HsPtr a2, HsInt len )
{
return (memcmp((char *)a1, a2, len));
}
HsInt
ghc_memcmp_off( HsAddr a1, HsInt i, HsAddr a2, HsInt len )
ghc_memcmp_off( HsPtr a1, HsInt i, HsPtr a2, HsInt len )
{
return (memcmp((char *)a1 + i, a2, len));
}
......
......@@ -59,7 +59,7 @@ module Binary
#include "HsVersions.h"
-- The *host* architecture version:
#include "MachDeps.h"
#include "../includes/MachDeps.h"
import {-# SOURCE #-} Name (Name)
import FastString
......
......@@ -19,7 +19,7 @@ module FastMutInt(
#ifdef __GLASGOW_HASKELL__
#include "MachDeps.h"
#include "../includes/MachDeps.h"
#ifndef SIZEOF_HSINT
#define SIZEOF_HSINT INT_SIZE_IN_BYTES
#endif
......
......@@ -66,7 +66,6 @@
#define CMINUSMINUS 1
#include "ghcconfig.h"
#include "RtsConfig.h"
/* -----------------------------------------------------------------------------
Types
......@@ -144,6 +143,18 @@
name : bits8[] str; \
} \
#ifdef TABLES_NEXT_TO_CODE
#define RET_LBL(f) f##_info
#else
#define RET_LBL(f) f##_ret
#endif
#ifdef TABLES_NEXT_TO_CODE
#define ENTRY_LBL(f) f##_info
#else
#define ENTRY_LBL(f) f##_entry
#endif
/* -----------------------------------------------------------------------------
Byte/word macros
......@@ -320,26 +331,26 @@
Constants.
-------------------------------------------------------------------------- */
#include "Constants.h"
#include "rts/Constants.h"
#include "DerivedConstants.h"
#include "ClosureTypes.h"
#include "StgFun.h"
#include "OSThreads.h"
#include "SMPClosureOps.h"
#include "rts/storage/ClosureTypes.h"
#include "rts/storage/FunTypes.h"
#include "rts/storage/SMPClosureOps.h"
#include "rts/OSThreads.h"
/*
* Need MachRegs, because some of the RTS code is conditionally
* compiled based on REG_R1, REG_R2, etc.
*/
#define STOLEN_X86_REGS 4
#include "MachRegs.h"
#include "stg/MachRegs.h"
#include "Liveness.h"
#include "StgLdvProf.h"
#include "rts/storage/Liveness.h"
#include "rts/prof/LDV.h"
#undef BLOCK_SIZE
#undef MBLOCK_SIZE
#include "Block.h" /* For Bdescr() */
#include "rts/storage/Block.h" /* For Bdescr() */
#define MyCapability() (BaseReg - OFFSET_Capability_r)
......
/*
Headers for GranSim specific objects.
Note that in GranSim we have one run-queue and blocking-queue for each
processor. Therefore, this header file redefines variables like
run_queue_hd to be relative to CurrentProc. The main arrays of runnable
and blocking queues are defined in Schedule.c. The important STG-called
GranSim macros (e.g. for fetching nodes) are at the end of this
file. Usually they are just wrappers to proper C functions in GranSim.c.
*/
#ifndef GRANSIM_H
#define GRANSIM_H
#if !defined(GRAN)
/* Dummy definitions for basic GranSim macros called from STG land */
#define DO_GRAN_ALLOCATE(n) /* nothing */
#define DO_GRAN_UNALLOCATE(n) /* nothing */
#define DO_GRAN_FETCH(node) /* nothing */
#define DO_GRAN_EXEC(arith,branch,load,store,floats) /* nothing */
#define GRAN_FETCH_AND_RESCHEDULE(liveness_mask,reenter) /* nothing */
#define GRAN_RESCHEDULE(liveness_mask,reenter) /* nothing */
#endif
#if defined(GRAN) /* whole file */
extern StgTSO *CurrentTSO;
/*
* @node Headers for GranSim specific objects, , ,
* @section Headers for GranSim specific objects
*
* @menu
* * Externs and prototypes::
* * Run and blocking queues::
* * Spark queues::
* * Processor related stuff::
* * GranSim costs::
* * STG called GranSim functions::
* * STG-called routines::
* @end menu
*
* @node Externs and prototypes, Run and blocking queues, Includes, Headers for GranSim specific objects
* @subsection Externs and prototypes
*/
/* Global constants */
extern char *gran_event_names[];
extern char *proc_status_names[];
extern char *event_names[];
/* Vars checked from within STG land */
extern rtsBool NeedToReSchedule, IgnoreEvents, IgnoreYields;
;
extern rtsTime TimeOfNextEvent, TimeOfLastEvent, EndOfTimeSlice;
/* costs for basic operations (copied from RTS flags) */
extern nat gran_arith_cost, gran_branch_cost, gran_load_cost, gran_store_cost, gran_float_cost;
extern nat SparksAvail; /* How many sparks are available */
extern nat SurplusThreads; /* How many excess threads are there */
extern nat sparksIgnored, sparksCreated;
/*
* @node Run and blocking queues, Spark queues, Externs and prototypes, Headers for GranSim specific objects
* @subsection Run and blocking queues
*/
/* declared in Schedule.c */
extern StgTSO *run_queue_hds[], *run_queue_tls[];
extern StgTSO *blocked_queue_hds[], *blocked_queue_tls[];
extern StgTSO *ccalling_threadss[];
#define run_queue_hd run_queue_hds[CurrentProc]
#define run_queue_tl run_queue_tls[CurrentProc]
#define blocked_queue_hd blocked_queue_hds[CurrentProc]
#define blocked_queue_tl blocked_queue_tls[CurrentProc]
#define pending_sparks_hd pending_sparks_hds[CurrentProc]
#define pending_sparks_tl pending_sparks_tls[CurrentProc]
#define ccalling_threads ccalling_threadss[CurrentProc]
/*
* @node Spark queues, Processor related stuff, Run and blocking queues, Headers for GranSim specific objects
* @subsection Spark queues
*/
/*
In GranSim we use a double linked list to represent spark queues.
This is more flexible, but slower, than the array of pointers
representation used in GUM. We use the flexibility to define new fields in
the rtsSpark structure, representing e.g. granularity info (see HWL's PhD
thesis), or info about the parent of a spark.
*/
/* Sparks and spark queues */
typedef struct rtsSpark_
{
StgClosure *node;
nat name, global;
nat gran_info; /* for granularity improvement mechanisms */
PEs creator; /* PE that created this spark (unused) */
struct rtsSpark_ *prev, *next;
} rtsSpark;
typedef rtsSpark *rtsSparkQ;
/* The spark queues, proper */
/* In GranSim this is a globally visible array of spark queues */
extern rtsSparkQ pending_sparks_hds[];
extern rtsSparkQ pending_sparks_tls[];
/* Prototypes of those spark routines visible to compiler generated .hc */
/* Routines only used inside the RTS are defined in rts/parallel GranSimRts.h */
rtsSpark *newSpark(StgClosure *node,
nat name, nat gran_info, nat size_info,
nat par_info, nat local);
/* void add_to_spark_queue(rtsSpark *spark); */
/*
* @node Processor related stuff, GranSim costs, Spark queues, Headers for GranSim specific objects
* @subsection Processor related stuff
*/
extern PEs CurrentProc;
extern rtsTime CurrentTime[];
/* Maximum number of PEs that can be simulated */
#define MAX_PROC 32 /* (BITS_IN(StgWord)) */ /* ToDo: fix this!! */
/*
#if MAX_PROC==16
#else
#error MAX_PROC should be 32 on this architecture
#endif
*/
/* #define CurrentTSO CurrentTSOs[CurrentProc] */
/* Processor numbers to bitmasks and vice-versa */
#define MainProc 0 /* Id of main processor */
#define NO_PRI 0 /* dummy priority */
#define MAX_PRI 10000 /* max possible priority */
#define MAIN_PRI MAX_PRI /* priority of main thread */
/* GrAnSim uses IdleProcs as bitmask to indicate which procs are idle */
#define PE_NUMBER(n) (1l << (long)n)
#define ThisPE PE_NUMBER(CurrentProc)
#define MainPE PE_NUMBER(MainProc)
#define Everywhere (~0l)
#define Nowhere (0l)
#define Now CurrentTime[CurrentProc]
#define IS_LOCAL_TO(ga,proc) ((1l << (PEs) proc) & ga)
#define GRAN_TIME_SLICE 1000 /* max time between 2 ReSchedules */
/*
* @node GranSim costs, STG called GranSim functions, Processor related stuff, Headers for GranSim specific objects
* @subsection GranSim costs
*/
/* Default constants for communication (see RtsFlags on how to change them) */
#define LATENCY 1000 /* Latency for single packet */
#define ADDITIONAL_LATENCY 100 /* Latency for additional packets */
#define BASICBLOCKTIME 10
#define FETCHTIME (LATENCY*2+MSGUNPACKTIME)
#define LOCALUNBLOCKTIME 10
#define GLOBALUNBLOCKTIME (LATENCY+MSGUNPACKTIME)
#define MSGPACKTIME 0 /* Cost of creating a packet */
#define MSGUNPACKTIME 0 /* Cost of receiving a packet */
#define MSGTIDYTIME 0 /* Cost of cleaning up after send */
/* How much to increase GrAnSims internal packet size if an overflow