
This commit removes all traces of Minix segments (the text/data/stack memory map abstraction in the kernel) and significance of Intel segments (hardware segments like CS, DS that add offsets to all addressing before page table translation). This ultimately simplifies the memory layout and addressing and makes the same layout possible on non-Intel architectures. There are only two types of addresses in the world now: virtual and physical; even the kernel and processes have the same virtual address space. Kernel and user processes can be distinguished at a glance as processes won't use 0xF0000000 and above. No static pre-allocated memory sizes exist any more. Changes to booting: . The pre_init.c leaves the kernel and modules exactly as they were left by the bootloader in physical memory . The kernel starts running using physical addressing, loaded at a fixed location given in its linker script by the bootloader. All code and data in this phase are linked to this fixed low location. . It makes a bootstrap pagetable to map itself to a fixed high location (also in linker script) and jumps to the high address. All code and data then use this high addressing. . All code/data symbols linked at the low addresses is prefixed by an objcopy step with __k_unpaged_*, so that that code cannot reference highly-linked symbols (which aren't valid yet) or vice versa (symbols that aren't valid any more). . The two addressing modes are separated in the linker script by collecting the unpaged_*.o objects and linking them with low addresses, and linking the rest high. Some objects are linked twice, once low and once high. . The bootstrap phase passes a lot of information (e.g. free memory list, physical location of the modules, etc.) using the kinfo struct. . After this bootstrap the low-linked part is freed. . The kernel maps in VM into the bootstrap page table so that VM can begin executing. Its first job is to make page tables for all other boot processes. So VM runs before RS, and RS gets a fully dynamic, VM-managed address space. VM gets its privilege info from RS as usual but that happens after RS starts running. . Both the kernel loading VM and VM organizing boot processes happen using the libexec logic. This removes the last reason for VM to still know much about exec() and vm/exec.c is gone. Further Implementation: . All segments are based at 0 and have a 4 GB limit. . The kernel is mapped in at the top of the virtual address space so as not to constrain the user processes. . Processes do not use segments from the LDT at all; there are no segments in the LDT any more, so no LLDT is needed. . The Minix segments T/D/S are gone and so none of the user-space or in-kernel copy functions use them. The copy functions use a process endpoint of NONE to realize it's a physical address, virtual otherwise. . The umap call only makes sense to translate a virtual address to a physical address now. . Segments-related calls like newmap and alloc_segments are gone. . All segments-related translation in VM is gone (vir2map etc). . Initialization in VM is simpler as no moving around is necessary. . VM and all other boot processes can be linked wherever they wish and will be mapped in at the right location by the kernel and VM respectively. Other changes: . The multiboot code is less special: it does not use mb_print for its diagnostics any more but uses printf() as normal, saving the output into the diagnostics buffer, only printing to the screen using the direct print functions if a panic() occurs. . The multiboot code uses the flexible 'free memory map list' style to receive the list of free memory if available. . The kernel determines the memory layout of the processes to a degree: it tells VM where the kernel starts and ends and where the kernel wants the top of the process to be. VM then uses this entire range, i.e. the stack is right at the top, and mmap()ped bits of memory are placed below that downwards, and the break grows upwards. Other Consequences: . Every process gets its own page table as address spaces can't be separated any more by segments. . As all segments are 0-based, there is no distinction between virtual and linear addresses, nor between userspace and kernel addresses. . Less work is done when context switching, leading to a net performance increase. (8% faster on my machine for 'make servers'.) . The layout and configuration of the GDT makes sysenter and syscall possible.
108 lines
3.4 KiB
C
108 lines
3.4 KiB
C
#ifndef _PROFILE_H
|
|
#define _PROFILE_H
|
|
|
|
#include <minix/type.h>
|
|
|
|
/*
|
|
* Types relating to system profiling. Types are supplied for both
|
|
* statistical profiling and call profiling.
|
|
*/
|
|
|
|
# define PROF_START 0 /* start statistical profiling */
|
|
# define PROF_STOP 1 /* stop statistical profiling */
|
|
|
|
#define PROF_RTC 0 /* RTC based profiling */
|
|
#define PROF_NMI 1 /* NMI based profiling, profiles kernel too */
|
|
|
|
/* Info struct to be copied to from kernel to user program. */
|
|
struct sprof_info_s {
|
|
int mem_used;
|
|
int total_samples;
|
|
int idle_samples;
|
|
int system_samples;
|
|
int user_samples;
|
|
};
|
|
|
|
/* What a profiling sample looks like (used for sizeof()). */
|
|
struct sprof_sample {
|
|
endpoint_t proc;
|
|
void * pc;
|
|
};
|
|
|
|
struct sprof_proc {
|
|
endpoint_t proc;
|
|
char name[PROC_NAME_LEN];
|
|
};
|
|
|
|
#include <minix/types.h>
|
|
|
|
# define PROF_GET 2 /* get call profiling tables */
|
|
# define PROF_RESET 3 /* reset call profiling tables */
|
|
|
|
/* Hash table size in each profiled process is table size + index size.
|
|
*
|
|
* Table size = CPROF_TABLE_SIZE * (CPROF_CPATH_MAX_LEN + 16).
|
|
* Index size = CPROF_INDEX_SIZE * 4;
|
|
*
|
|
* Making CPROF_CPATH_MAX_LEN too small may cause call path overruns.
|
|
* Making CPROF_TABLE_SIZE too small may cause table overruns.
|
|
*
|
|
* There are some restrictions: processes in the boot image are loaded
|
|
* below 16 MB and the kernel is loaded in lower memory (below 640 kB). The
|
|
* latter is reason to use a different size for the kernel table.
|
|
*/
|
|
#define CPROF_TABLE_SIZE_OTHER 3000 /* nr of slots in hash table */
|
|
#define CPROF_TABLE_SIZE_KERNEL 1500 /* kernel has a smaller table */
|
|
#define CPROF_CPATH_MAX_LEN 256 /* len of cpath string field: */
|
|
/* MUST BE MULTIPLE OF WORDSIZE */
|
|
|
|
#define CPROF_INDEX_SIZE (10*1024)/* size of index to hash table */
|
|
#define CPROF_STACK_SIZE 24 /* size of call stack */
|
|
#define CPROF_PROCNAME_LEN 8 /* len of proc name field */
|
|
|
|
#define CPROF_CPATH_OVERRUN 0x1 /* call path overrun */
|
|
#define CPROF_STACK_OVERRUN 0x2 /* call stack overrun */
|
|
#define CPROF_TABLE_OVERRUN 0x4 /* hash table overrun */
|
|
|
|
#define CPROF_ANNOUNCE_OTHER 1 /* processes announce their profiling
|
|
* data on n-th entry of procentry */
|
|
#define CPROF_ACCOUNCE_KERNEL 10000 /* kernel announces not directly */
|
|
|
|
/* Prototype for function called by procentry to get size of table. */
|
|
int profile_get_tbl_size(void);
|
|
/* Prototype for function called by procentry to get announce number. */
|
|
int profile_get_announce(void);
|
|
/* Prototype for function called by procentry to announce control struct
|
|
* and table locations to the kernel. */
|
|
void profile_register(void *ctl_ptr, void *tbl_ptr);
|
|
|
|
/* Info struct to be copied from kernel to user program. */
|
|
struct cprof_info_s {
|
|
int mem_used;
|
|
int err;
|
|
};
|
|
|
|
/* Data structures for control structure and profiling data table in the
|
|
* in the profiled processes.
|
|
*/
|
|
struct cprof_ctl_s {
|
|
int reset; /* kernel sets to have table reset */
|
|
int slots_used; /* proc writes nr slots used in table */
|
|
int err; /* proc writes errors that occurred */
|
|
};
|
|
|
|
struct cprof_tbl_s {
|
|
struct cprof_tbl_s *next; /* next in chain */
|
|
char cpath[CPROF_CPATH_MAX_LEN]; /* string with call path */
|
|
int calls; /* nr of executions of path */
|
|
u64_t cycles; /* execution time of path, in cycles */
|
|
};
|
|
|
|
int sprofile(int action, int size, int freq, int type, void *ctl_ptr,
|
|
void *mem_ptr);
|
|
|
|
int cprofile(int action, int size, void *ctl_ptr, void *mem_ptr);
|
|
|
|
#endif /* PROFILE_H */
|
|
|