Skip to content

Commit 8cd023c

Browse files
author
Axel Heider
committed
vm_arm: add priority in vm config struct
- Cleanup the definitions. - Set a default base value for the attribute. - Derive the other priorities in the config params template. - Do sanity check during template processing. Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
1 parent 8d7cd52 commit 8cd023c

5 files changed

Lines changed: 41 additions & 13 deletions

File tree

components/VM_Arm/configurations/vm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
emits HaveNotification notification_ready_connector; \
6464
maybe uses VMDTBPassthrough dtb_self; \
6565
provides VMDTBPassthrough dtb; \
66-
attribute int base_prio; \
66+
attribute int base_prio = 100; \
6767
attribute int num_vcpus = 1; \
6868
attribute int num_extra_frame_caps; \
6969
attribute int extra_frame_map_address; \

components/VM_Arm/src/main.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ seL4_CPtr camkes_alloc(seL4_ObjectType type, size_t size, unsigned flags);
7777
extern void *fs_buf;
7878
int start_extra_frame_caps;
7979

80-
int VM_PRIO = 100;
8180
int NUM_VCPUS = 1;
8281

83-
#define IRQSERVER_PRIO (VM_PRIO + 1)
8482
#define IRQ_MESSAGE_LABEL 0xCAFE
8583

8684
#define DMA_VSTART 0x40000000
@@ -558,7 +556,7 @@ static int vmm_init(const vm_config_t *vm_config)
558556
assert(!err);
559557

560558
/* Create an IRQ server */
561-
_irq_server = irq_server_new(vspace, vka, IRQSERVER_PRIO,
559+
_irq_server = irq_server_new(vspace, vka, vm_config->priority.irqserver,
562560
simple, simple_get_cnode(simple), fault_ep_obj.cptr,
563561
IRQ_MESSAGE_LABEL, 256, &_io_ops.malloc_ops);
564562
assert(_irq_server);
@@ -1259,7 +1257,7 @@ static int main_continued(void)
12591257

12601258
/* Create CPUs and DTB node */
12611259
for (int i = 0; i < NUM_VCPUS; i++) {
1262-
vm_vcpu_t *new_vcpu = create_vmm_plat_vcpu(&vm, VM_PRIO - 1);
1260+
vm_vcpu_t *new_vcpu = create_vmm_plat_vcpu(&vm, vm_config.priority.vcpu);
12631261
assert(new_vcpu);
12641262
}
12651263
if (vm_config.generate_dtb) {
@@ -1317,15 +1315,10 @@ static int main_continued(void)
13171315
}
13181316

13191317
/* base_prio and num_vcpus are optional attributes of the VM component. */
1320-
extern const int __attribute__((weak)) base_prio;
13211318
extern const int __attribute__((weak)) num_vcpus;
13221319

13231320
int run(void)
13241321
{
1325-
/* if the base_prio attribute is set, use it */
1326-
if (&base_prio != NULL) {
1327-
VM_PRIO = base_prio;
1328-
}
13291322
/* if the num_vcpus attribute is set, try to use it */
13301323
if (&num_vcpus != NULL) {
13311324
if (num_vcpus > CONFIG_MAX_NUM_NODES) {

components/VM_Arm/vm_common.camkes

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ assembly {
3030
vm.cnode_size_bits = 23;
3131
vm.simple_untyped24_pool = 12;
3232

33-
vm.base_prio = 100;
34-
35-
vm._priority = 101;
33+
vm._priority = 101; /* priority of VM component's main thread */
3634
vm.sem_value = 0;
3735

3836
}

templates/seL4VMParameters.template.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,37 @@
2424

2525
const vm_config_t vm_config = {
2626

27+
.priority = {
28+
/*#
29+
* The CAmkES attribute '_priority' define the control thread's
30+
* priority, which is the thread that does the VMM setup and executes
31+
* the VMM even loop eventually.
32+
* The VMM attribute 'base_prio' defines the priorities to be used
33+
* - interrupt server thread: base_prio + 1
34+
* - vmm thread: base_prio
35+
* - vcpu thread(s): base_prio - 1
36+
* but these can never exceed the component priority. Furthermore these
37+
* constrains apply:
38+
* - the vcpu thread can't have a higher priority than the VMM's event
39+
* loop, otherwise it can't be preempted when an even arrives. It may
40+
* have equal priority, in this case events like IRQ injection get
41+
* delayed until the vcpu thread was preempted or yielded.
42+
* - the VMM thread can have a higher priority than the interrupt
43+
* server thread. They may have equal priority, but this also
44+
* increases e.g. interrupt latency.
45+
#*/
46+
/*- set comp_prio = config.get('_priority') -*/
47+
/*- set base_prio = config.get('base_prio') -*/
48+
/*- set irqserver_prio = min(comp_prio, base_prio + 1) -*/
49+
/*- set vcpu_prio = min(comp_prio, base_prio - 1) -*/
50+
/*- if ((vcpu_prio > base_prio) or (base_prio > irqserver_prio)) -*/
51+
/*? raise(Exception('Invalid priority configuration: vcpu/'+str(vcpu_prio)+' > base/'+str(base_prio)+' > irqserver/'+str(irqserver_prio))) ?*/
52+
/*- endif -*/
53+
.irqserver = /*? irqserver_prio ?*/,
54+
.vmm = /*? base_prio ?*/,
55+
.vcpu = /*? vcpu_prio ?*/,
56+
},
57+
2758
/*- if vm_address_config -*/
2859

2960
.ram = {

templates/seL4VMParameters.template.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
typedef struct {
1515

16+
struct {
17+
uint8_t vmm;
18+
uint8_t irqserver;
19+
uint8_t vcpu;
20+
} priority;
21+
1622
struct {
1723
uintptr_t phys_base;
1824
uintptr_t base;

0 commit comments

Comments
 (0)