-- CreateTestFilePageMgrImpl.mesa -- Last edited by -- Kolling on November 14, 1983 2:23 pm DIRECTORY AlpineEnvironment USING[FileID, nullFileID, PageCount, VolumeID], AlpineInternal USING[FileHandle], File USING[EraseVolume, FindVolumeFromName, GetVolumeID, Volume, VolumeID], FileMap USING[Handle, Initialize, Register], FilePageMgr USING[Create, Delete, ForceOutEverything, InitializeFilePageMgr, NoSuchFile, RestoreCacheToCleanState], FS USING[StreamOpen], IO USING[card, Close, GetCard, int, PutF, PutRope, rope, STREAM], MyPerfStats USING[CreateTimer, DestroyTimer, Initialize, InitializeTimer, Print, Start, Stop, Timer], RandomCard USING[Choose, Init], Rope USING[ROPE], SafeStorage USING[IsCollectorActive, WaitForCollectorDone], SystemVersion USING[machineType]; CreateTestFilePageMgrImpl: CEDAR PROGRAM IMPORTS File, FileMap, FPM: FilePageMgr, FS, IO, MyPerfStats, RandomCard, SafeStorage, SystemVersion = BEGIN OPEN AI: AlpineInternal, AE: AlpineEnvironment; GetParams: PROCEDURE = BEGIN paramStreamHandle: IO.STREAM _ FS.StreamOpen["AnomaliesCreateFile.Params", $read]; IF (NFiles _ paramStreamHandle.GetCard[]) = 0 THEN ERROR; IF NFiles > 999 THEN ERROR; IF (NNormalChunksInCache _ paramStreamHandle.GetCard[]) = 0 THEN ERROR; IF (NLogChunksInCache _ paramStreamHandle.GetCard[]) = 0 THEN ERROR; IF (NLeaderChunksInCache _ paramStreamHandle.GetCard[]) = 0 THEN ERROR; paramStreamHandle.Close[]; resultsStreamHandle.PutF["\nNFiles: %g\n\nNNormalChunksInCache: %g NLogChunksInCache: %g NLeaderChunksInCache: %g\n\n", IO.card[NFiles], IO.card[NNormalChunksInCache], IO.card[NLogChunksInCache], IO.card[NLeaderChunksInCache]]; END; SetUpFileData: PROCEDURE = BEGIN files _ NEW[Files[NFiles]]; FOR index: CARDINAL IN [0..NFiles) DO files[index] _ [fileID: AE.nullFileID, inUse: FALSE, exists: FALSE, size: 0]; ENDLOOP; END; DeleteAllFiles: PROCEDURE = BEGIN FOR index: CARDINAL IN [0..NFiles) DO fileHandle: FileMap.Handle _ FileMap.Register[volumeID, files[index].fileID]; FPM.Delete[fileHandle ! FPM.NoSuchFile => CONTINUE]; fileHandle _ NIL; ENDLOOP; resultsStreamHandle.PutRope[" All files deleted. "]; END; CleanCache: PROCEDURE = BEGIN FPM.ForceOutEverything[]; FPM.RestoreCacheToCleanState[]; resultsStreamHandle.PutRope["Cache cleaned. "]; END; Shell: PROCEDURE[proc: PROCEDURE[fileIndex: CARDINAL, timer: MyPerfStats.Timer, fileInterval: FileInterval], timerName: Rope.ROPE, fileIndex: CARDINAL, fileInterval: FileInterval] = BEGIN timer: MyPerfStats.Timer _ MyPerfStats.CreateTimer[timerName]; proc[fileIndex, timer, fileInterval]; MyPerfStats.Print[ , resultsStreamHandle, FALSE]; MyPerfStats.DestroyTimer[timer]; END; -- varies size of file. CreateFile: PROCEDURE[fileIndex: CARDINAL, timer: MyPerfStats.Timer, fileInterval: FileInterval] = BEGIN FileIDProc: PROCEDURE[fileID: AE.FileID] = BEGIN files[fileIndex].fileID _ fileID; END; fileHandle: FileMap.Handle; active: BOOLEAN; prevCollectorIncarnation, endingPrevCollectorIncarnation: CARDINAL; attempts: CARDINAL _ 5; files[fileIndex].exists _ TRUE; files[fileIndex].size _ (WITH fileInt: fileInterval SELECT FROM allFixed => fileInt.nPagesEachTime, allRandom => RandomCard.Choose[min: 0, max: MaxFileSize], ENDCASE => ERROR); DO [active, prevCollectorIncarnation] _ SafeStorage.IsCollectorActive[]; IF active THEN [prevCollectorIncarnation, , , ] _ SafeStorage.WaitForCollectorDone[]; MyPerfStats.Start[timer]; FPM.Create[volumeID, files[fileIndex].size, FileIDProc]; MyPerfStats.Stop[timer]; [active, endingPrevCollectorIncarnation] _ SafeStorage.IsCollectorActive[]; IF ((active) OR (endingPrevCollectorIncarnation # prevCollectorIncarnation)) THEN BEGIN resultsStreamHandle.PutRope[ "CreateFile interrupted by garbage collection "]; IF (attempts _ attempts - 1) > 0 THEN BEGIN resultsStreamHandle.PutRope["retrying "]; fileHandle _ FileMap.Register[volumeID, files[fileIndex].fileID]; FPM.Delete[fileHandle]; fileHandle _ NIL; CleanCache[]; MyPerfStats.InitializeTimer[timer]; [] _ SafeStorage.WaitForCollectorDone[]; LOOP; END ELSE resultsStreamHandle.PutF["giving up\n"]; EXIT; END; resultsStreamHandle.PutF["CreateFile file: %g size: %3g ", IO.card[fileIndex], IO.int[files[fileIndex].size]]; EXIT; ENDLOOP; END; -- varies AllSomeOrSomeRandom: TYPE = {allFixed, allRandom, someFixed, someRandom}; FileInterval: TYPE = RECORD[SELECT allOrSomeRandom: AllSomeOrSomeRandom FROM allFixed => [nPagesEachTime: CARDINAL], allRandom => NULL, someFixed => [firstPage, lastPage, nPagesEachTime: CARDINAL], someRandom => NULL, ENDCASE]; Main: PROCEDURE = BEGIN -- set up to call from CoPilot for debugging. foo: CARDINAL _ 0; increment: CARDINAL _ 150; fileSize: CARDINAL; BEGIN ENABLE ANY => foo _ foo + 1; -- protect us from the tempcedarexec. MyPerfStats.Initialize[]; File.EraseVolume[volume]; resultsStreamHandle _ FS.StreamOpen["AnomaliesCreateFile.Results", $append]; resultsStreamHandle.PutRope[" Nucleus"]; resultsStreamHandle.PutF["\nMachine type: %g\n\n", IO.rope[SELECT SystemVersion.machineType FROM dolphin => "Dolphin", dorado => "Dorado", dandelion => "Dandelion", dicentra => "Dicentra", ENDCASE => "unknown"]]; [] _ RandomCard.Init[0]; GetParams[]; FileMap.Initialize[numHashSlotsDesired: 43, fQLength: 60]; FPM.InitializeFilePageMgr[nNormalChunksInCache: NNormalChunksInCache, nLogChunksInCache: NLogChunksInCache, nLeaderChunksInCache: NLeaderChunksInCache]; SetUpFileData[]; THROUGH [0..5) DO fileSize _ 1; DeleteAllFiles[]; FOR fileIndex: CARDINAL IN [0..NFiles) DO CleanCache[]; Shell[proc: CreateFile, timerName: "CreateFile", fileIndex: fileIndex, fileInterval: [allFixed[fileSize]]]; fileSize _ fileSize + increment; ENDLOOP; ENDLOOP; CleanCache[]; THROUGH [0..5) DO fileSize _ ((NFiles-1)*increment) + 1; DeleteAllFiles[]; FOR fileIndex: CARDINAL IN [0..NFiles) DO CleanCache[]; Shell[proc: CreateFile, timerName: "CreateFile", fileIndex: fileIndex, fileInterval: [allFixed[fileSize]]]; fileSize _ fileSize - increment; ENDLOOP; ENDLOOP; CleanCache[]; DeleteAllFiles[]; resultsStreamHandle.Close[]; END; END; -- main line code: MaxFileSize: CARDINAL _ 150; resultsStreamHandle: IO.STREAM; NFiles: CARDINAL; files: REF Files; Files: TYPE = RECORD[SEQUENCE nFiles: [0..LAST[CARDINAL]] OF FileModel]; FileModel: TYPE = RECORD[fileID: AE.FileID, inUse: BOOLEAN, exists: BOOLEAN, size: CARDINAL]; NNormalChunksInCache: CARDINAL; NLogChunksInCache: CARDINAL; NLeaderChunksInCache: CARDINAL; volume: File.Volume _ File.FindVolumeFromName["Gentian"]; volumeID: AE.VolumeID _ LOOPHOLE[File.GetVolumeID[volume]]; END. Edit Log Initial: Kolling: 19-Apr-82 12:22:00: test for FilePageManager.