3 * \brief Kernel control block declarations.
7 * Copyright (c) 2013, 2014, ETH Zurich.
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
19 #include <capabilities.h>
21 #include <mdb/mdb_tree.h>
32 * this is the memory layout of ObjType_KernelControlBlock
33 * this struct should contain all the persistent state that belongs to a
37 bool is_valid; ///< kcb has been initialized by a kernel before
39 /// kcb scheduling ring.
40 /// These fields point to the next and previous kcb that should be
41 /// scheduled when we're running multiple kcbs on the same kernel.
42 /// invariant: next == NULL --> prev == NULL
43 /// invariant: next is the next kcb in the ring and prev is the previous
45 struct kcb *next, *prev;
49 // XXX: need memory for a rootcn here because we can't have it static in
50 // the kernel data section anymore
51 struct cte init_rootcn;
53 /// which scheduler state is valid
54 enum sched_state sched;
55 /// RR scheduler state
56 struct dcb *ring_current;
57 /// RBED scheduler state
58 struct dcb *queue_head, *queue_tail;
59 unsigned int u_hrt, u_srt, w_be, n_be;
60 /// current time since kernel start in timeslices. This is necessary to
61 /// make the scheduler work correctly
63 struct dcb *wakeup_queue_head;
64 /// last value of kernel_now before shutdown/migration
65 //needs to be signed because it's possible to migrate a kcb onto a cpu
66 //driver whose kernel_now > this kcb's kernel_off.
69 struct cte * irq_dest_caps[NDISPATCH];
70 // TODO: maybe add a shared part which can replace struct core_data?
73 ///< The kernel control block
74 extern struct kcb *kcb_current;
75 ///< flag that indicates whether kcb scheduling should happen
76 extern bool kcb_sched_suspended;
78 static inline void print_kcb(void)
80 printk(LOG_DEBUG, "kcb contents:\n");
81 printk(LOG_DEBUG, " next = %p, prev = %p\n",
82 kcb_current->next, kcb_current->prev);
83 printk(LOG_DEBUG, " mdb_root = 0x%"PRIxLVADDR"\n", kcb_current->mdb_root);
84 printk(LOG_DEBUG, " queue_head = %p\n", kcb_current->queue_head);
85 printk(LOG_DEBUG, " queue_tail = %p\n", kcb_current->queue_tail);
86 printk(LOG_DEBUG, " wakeup_queue_head = %p\n", kcb_current->wakeup_queue_head);
87 printk(LOG_DEBUG, " u_hrt = %u, u_srt = %u, w_be = %u, n_be = %u\n",
88 kcb_current->u_hrt, kcb_current->u_srt, kcb_current->w_be,
90 // TODO interrupt state
93 // XXX: this is from RBED, don't know how to properly have this here -SG
94 extern struct dcb *queue_tail;
95 static inline void switch_kcb(struct kcb *next)
97 assert (next != NULL);
99 mdb_init(kcb_current);
100 // update queue tail to make associated assembly not choke
101 queue_tail = kcb_current->queue_tail;
104 void kcb_add(struct kcb* new_kcb);
105 errval_t kcb_remove(struct kcb *to_remove);
106 void kcb_update_core_id(struct kcb *kcb);