⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 segmgr.h

📁 T-kernel 的extension源代码
💻 H
字号:
/* *---------------------------------------------------------------------- *    T-Kernel / Standard Extension * *    Copyright (C) 2006 by Ken Sakamura. All rights reserved. *    T-Kernel / Standard Extension is distributed  *      under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * *    Version:   1.00.00 *    Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* *	segmgr.h (memory) * *	Segment management (Virtual storage version) */#ifndef _PM_SEGMGR_H_#define _PM_SEGMGR_H_#include <basic.h>#include <tk/tkernel.h>#include <tk/util.h>#include <tk/sysdef.h>#include <extension/sys/segment.h>#include <sys/pinfo.h>#include <sys/imalloc.h>#include <sys/util.h>#include <device/disk.h>#include <extension/errno.h>#include <sys/syslog.h>#include <libstr.h>#include <tstring.h>#include <bzcomp.h>#include <sys/queue.h>#include <sys/debug.h>#include <sys/memdef.h>#include <sys/procdef.h>#include <sys/tkseconf.h>#include "pagedef.h"#include "memaccess.h"/* * Exclusive control lock for segment management *	(*) Note that occurrence of page fault during LockSEG leads to deadlock. */IMPORT	FastLock	SegLock;#define	LockSEG()	Lock(&SegLock)#define	UnlockSEG()	Unlock(&SegLock)/* * Exclusive control lock related to disk map *	(*) Make sure that LockFS is located outside and LockSEG is located inside. */IMPORT	FastLock	FsLock;#define	LockFS()	Lock(&FsLock)#define	UnlockFS()	Unlock(&FsLock)/* * Map-specific information on program on-demand loading *	Value that is not used by file management and not 0. *	Not to be included in disk synchronous processing. */#define	MAP_LOADPROG	(-1)/* ------------------------------------------------------------------------ *//* * Memory area information */typedef struct {	VB*	laddr;		/* First logical address */	UW	nbyte;		/* Number of bytes */} ByteArea;typedef struct {	VP	laddr;		/* First logical address */	UW	npage;		/* Number of pages */} PageArea;/* * Real memory area information */#ifndef N_MEMSECTION#define	N_MEMSECTION	2#endiftypedef struct {	W	n;		/* Number of a */	union {		ByteArea	b;		PageArea	p;	} a[N_MEMSECTION];} RealMemoryInfo;/* * Page frame number *	The maximum size of real memory is 1GB. Therefore, the maximum number of *	page frames is 0x40000 when the page size is 4KB. *	The range of PFN is 1 to MaxPages. Therefore, it needs 19 bits. */typedef	UW	PFN;/* * Logical page */typedef struct LogicalPage {	unsigned int	pn:20;		/* Page number */	unsigned int	lsid:12;	/* Logical space ID */} LP;/* * Disk block number *	id = 0		Corresponds to page file *		no = 0	Page file not allocated *		no > 0	Block number within page file *	id = 1 - 255	Corresponds to disk blocks (disk ID) *		no	First physical block number of the page */typedef struct DiskBlockNumber {	UB	id;	W	no;} DBN;#define	PAGEFILE_ID	0typedef struct MapEntryLink	MEL;/* * Map management information */typedef struct MapEntry {	MEL	*mel;		/* List of page frames being mapped */	MapMode	mode;		/* Map mode */	ID	tid;		/* Mapped task */	unsigned int	mapid:20;	/* Map ID */	unsigned int	mapped:1;	/* UnmapDisk() not executed: TRUE */	unsigned int	alloc:1;	/* Address space is allocated: TRUE */	unsigned int	memmap:1;	/* Directly mapped to memory disk: TRUE */	unsigned int	sync:1;		/* Synchronous mode (writing during unmapping): TRUE */	unsigned int	did:8;		/* Disk ID */	UW	npage;		/* Total number of pages in map */	PhyBlk	pb[1];		/* Disk blocks to be mapped (variable-length) */} ME;#define	MapEntrySize(n)		( sizeof(ME) - sizeof(PhyBlk) \					+ (sizeof(PhyBlk) * (n)) )/* * Map identification information */typedef union MapDescriptor {	MEL	*mel;		/* In the case of disk map */	LP	page;		/* In the case of page file */	UW	w;		/* 0 means unmapped */} MD;/* * Page frame usage state */typedef enum PageFrameState {	PFS_uninit	= 0,	/* Uninitialize */	PFS_free	= 1,	/* Free state with valid content */	PFS_use		= 2,	/* In use (non-resident) */	PFS_lock	= 3	/* In use (resident) */} PFS;/* * Disk block hash */typedef PFN	DBH;/* * Page frame management information */typedef struct PageFrameEntry {	unsigned int	next:20;	/* For queue connection */	unsigned int	etc:12;		/* PFE_ETC information */	unsigned int	prev:20;	/* For queue connection */	unsigned int	reg:1;		/* Already registered in queue: TRUE */	unsigned int	stat:2;		/* Usage state */	unsigned int	rank:3;		/* Usage rank */	unsigned int	upd:1;		/* Already updated: TRUE */	unsigned int	err:1;		/* I/O error occurred: TRUE */	unsigned int	rsv1:4;		/* (Reserved) */	MD	md;		/* Map identification information */	unsigned int	dbh:20;		/* Disk block hash list */	unsigned int	rsv2:4;		/* (Reserved) */	unsigned int	dbn_id:8;	/* DBN.id : Disk blocks to be hashed */	W	dbn_no;		/* DBN.no : Disk blocks to be hashed */} PFE;/* * Area for holding information that is used differently depending on the page usage (up to 12 bits) */typedef union {	/* Disk map (at the time of page-in) */	struct {		unsigned int	ofs:6;		/* Offset block number within page */		unsigned int	len:6;		/* Number of blocks */	} c;	/* Page file */	struct {		unsigned int	lkcnt:8;	/* Number of lock counts */		unsigned int	rsv:4;		/* Not used */	} p;	unsigned int	w:12;} PFE_ETC;/* * Queue for PageFrameEntry connection */typedef struct PageFrameEntryQueue {	PFE	*top;		/* PFE at the start of queue */	UW	diskmap;	/* Number of disk map pages */	UW	other;		/* Number of other pages */} PFE_Q;/* * Map entry connection information */struct MapEntryLink {	MEL	*next_me;	/* List of MEs where pfe are mapped */	MEL	*next_pfe;	/* List of PFs mapped by me */	ME	*me;		/* Back link to me */	PFE	*pfe;		/* Back link to pfe */	UB	lkcnt;		/* Number of lock counts */};#define	MaxLockCount	255	/* Maximum number of lock counts available for a single page *//* * Disk management information */typedef struct DiskEntry {	ID	devid;		/* Device ID (0 is an unused entry) */	DiskInfo info;		/* Disk information */	VP	memadr;		/* First logical address of memory disk				   (when not memory disk, use INVADR) */	UH	blkcnt;		/* Number of physical blocks per page */	UH	lbsz;		/* Logical block size (number of bytes) */	H	pbadj;		/* Adjusted value for logical block alignment */} DE;EXPORT	DE	*DiskEntryTable;	/* DiskEntry table *//* * DiskID <--> DiskEntry interconversion */#define	toDiskID(de)		( ((de) - (DiskEntryTable)) + 1 )#define	toDiskEntry(did)	( &DiskEntryTable[(did) - 1] )/* * Error handler management information */typedef struct ErrorHandlerEntry {	ID	tid;		/* Task with error handler is defined */	FP	errhdr;		/* Error handler*/} EHE;/* * Fixed-length memory pool management information */typedef struct {	QUEUE	q;		/* Queue for page connection */	UW	blksz;		/* Block size (bytes) */	UW	maxblk;		/* Number of blocks per page */} FMB_Pool;/* * Indirect queue */typedef struct {	QUEUE	q;		/* Connection queue */	W	num;		/* Number of entries */} IndQueTop;typedef struct {	QUEUE	q;		/* Connection queue */	VP	ent;		/* Link to body */} IndQue;/* * Disk synchronization option */typedef enum {	NOSYNC		= 0,	/* Do not synchronize */	MARKUPD		= 1,	/* Update mark only */	SYNCONLY	= 2,	/* Synchronization only */	WRITEALL	= 3,	/* Write all */	DISCARD		= 4,	/* Cancel page frame */	FORCEDEL	= 5	/* Cancel page frame, forcedly reset mapping */} SyncOpt;/* * Block number within page *	BLKTOP	First block number of a page that contains blkno block *	BLKOFS	Relative block number of blkno block within the page */Inline W BLKTOP( DE *de, W blkno ){	return (blkno + de->pbadj) / de->blkcnt * de->blkcnt - de->pbadj;}Inline W BLKOFS( DE *de, W blkno ){	return (blkno + de->pbadj) % de->blkcnt;}/* * PFA <--> PFE interconversion */#define	PFAtoPFE(pfa)		( LADRtoPFE(PFAtoLADR(pfa)) )#define	PFEtoPFA(pfe)		( LADRtoPFA(PFEtoLADR(pfe)) )/* * Memory statistical information */typedef struct {	struct {			/* Page frame */		UW	total;		/* All pages */		UW	resident;	/* Number of resident pages */		UW	unresident;	/* Number of non-resident pages*/		UW	diskcache;	/* Number of disk cache pages */	} page_frame;	struct {			/* Page file */		UW	total;		/* Total number of pages */		UW	use;		/* Number of pages in use */	} page_file;	UW	safetymargin;		/* Number of pages to be left as a safety margin */} MemoryInfo;/* ------------------------------------------------------------------------ */#include "import.h"/* ------------------------------------------------------------------------ *//* * Copy-on-write is available: TRUE */Inline BOOL isValidCopyOnWrite( ID did ){#if PT_CopyOnWrite == 0	return FALSE;  /* Always not acceptable because copy-on-write is not supported */#else	return !isMemoryDisk(did);#endif}/* ------------------------------------------------------------------------ */#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -