Unify process_alloc() and process_realloc() with PROCESS_ALLOC_MODE_REALLOC bit
[moveable_pool.git] / process.h
1 #ifndef _PROCESS_H
2 #define _PROCESS_H 1
3
4 #define PARA_SHIFT 8
5 #define BLOCK_SHIFT 9
6 //#define PAGE_SHIFT 12
7
8 #define BLOCK_PARAS_SHIFT (BLOCK_SHIFT - PARA_SHIFT)
9 #define BLOCK_PARAS (1 << BLOCK_PARAS_SHIFT)
10
11 //#define PAGE_PARAS_SHIFT (PAGE_SHIFT - PARA_SHIFT)
12 //#define PAGE_PARAS (1 << PAGE_PARAS_SHIFT)
13
14 //#define PAGE_BLOCKS_SHIFT (PAGE_SHIFT - BLOCK_SHIFT)
15 //#define PAGE_BLOCKS (1 << PAGE_BLOCKS_SHIFT)
16
17 #include "pool.h"
18 #include "core.h" // TEMPORARY, JUST TO GET INDIRECT_CORE SETTING
19
20 struct lru_item {
21   struct lru_item *prev;
22   struct lru_item *next;
23 };
24
25 #define PROCESS_FLAGS_ACTIVE 1
26 #ifndef INDIRECT_CORE
27 #define PROCESS_FLAGS_CORE_ITEM 2
28 #endif
29
30 struct process {
31   int flags;
32   struct lru_item lru_item;
33   struct pool_item core_item;
34   struct pool_item swap_item;
35   int para_base;
36   int para_limit;
37 #ifdef INDIRECT_CORE
38   int in_core_block;
39 #endif
40 };
41
42 // derived variables, not stored in process to save space
43 struct process_calc {
44   int block_base;
45   int block_limit;
46   int core_origin;
47   int swap_origin;
48   int in_core_block;
49 };
50
51 extern struct process *processes;
52 extern int n_processes;
53
54 extern int process_avail;
55
56 extern struct lru_item lru_head, *victim;
57
58 #define PROCESS_ALLOC_MODE_REALLOC 1 // must = POOL_ALLOC_MODE_REALLOC
59 #define PROCESS_ALLOC_MODE_LAST_FIT 2 // must = POOL_ALLOC_MODE_LAST_FIT
60
61 void process_init(int n, int spare);
62 bool process_alloc(
63   struct process *process,
64   int para_base,
65   int para_limit,
66   int mode
67 );
68 void process_run(struct process *process);
69 void process_free(struct process *process);
70 void process_calc(struct process *process, struct process_calc *calc);
71  
72 // abstract
73 void swap_read_write(int core_block, int swap_block, int blocks, bool dir);
74
75 #endif