-
Notifications
You must be signed in to change notification settings - Fork 0
/
fastpath.c
691 lines (571 loc) · 21.7 KB
/
fastpath.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
/*
* Copyright 2014, General Dynamics C4 Systems
*
* This software may be distributed and modified according to the terms of
* the GNU General Public License version 2. Note that NO WARRANTY is provided.
* See "LICENSE_GPLv2.txt" for details.
*
* @TAG(GD_GPL)
*/
#include <config.h>
#include <fastpath/fastpath.h>
#include <object/reply.h>
#include <object/notification.h>
#ifdef CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES
#include <benchmark/benchmark_track.h>
#endif
#include <benchmark/benchmark_utilisation.h>
void
#ifdef ARCH_X86
NORETURN
#endif
fastpath_call(word_t cptr, word_t msgInfo)
{
seL4_MessageInfo_t info;
cap_t ep_cap;
endpoint_t *ep_ptr;
word_t length;
tcb_t *dest;
word_t badge;
cap_t newVTable;
vspace_root_t *cap_pd;
pde_t stored_hw_asid;
word_t fault_type;
dom_t dom;
/* Get message info, length, and fault type. */
info = messageInfoFromWord_raw(msgInfo);
length = seL4_MessageInfo_get_length(info);
fault_type = seL4_Fault_get_seL4_FaultType(NODE_STATE(ksCurThread)->tcbFault);
/* Check there's no extra caps, the length is ok and there's no
* saved fault. */
if (unlikely(fastpath_mi_check(msgInfo) ||
fault_type != seL4_Fault_NullFault)) {
slowpath(SysCall);
}
/* Lookup the cap */
ep_cap = lookup_fp(TCB_PTR_CTE_PTR(NODE_STATE(ksCurThread), tcbCTable)->cap, cptr);
/* Check it's an endpoint */
if (unlikely(!cap_capType_equals(ep_cap, cap_endpoint_cap) ||
!cap_endpoint_cap_get_capCanSend(ep_cap))) {
slowpath(SysCall);
}
/* Get the endpoint address */
ep_ptr = EP_PTR(cap_endpoint_cap_get_capEPPtr(ep_cap));
/* Get the destination thread, which is only going to be valid
* if the endpoint is valid. */
dest = TCB_PTR(endpoint_ptr_get_epQueue_head(ep_ptr));
/* Check that there's a thread waiting to receive */
if (unlikely(endpoint_ptr_get_state(ep_ptr) != EPState_Recv)) {
slowpath(SysCall);
}
/* ensure we are not single stepping the destination in ia32 */
#if defined(CONFIG_HARDWARE_DEBUG_API) && defined(CONFIG_ARCH_IA32)
if (dest->tcbArch.tcbContext.breakpointState.single_step_enabled) {
slowpath(SysCall);
}
#endif
/* Get destination thread.*/
newVTable = TCB_PTR_CTE_PTR(dest, tcbVTable)->cap;
/* Get vspace root. */
cap_pd = cap_vtable_cap_get_vspace_root_fp(newVTable);
/* Ensure that the destination has a valid VTable. */
if (unlikely(! isValidVTableRoot_fp(newVTable))) {
slowpath(SysCall);
}
#ifdef CONFIG_ARCH_AARCH32
/* Get HW ASID */
stored_hw_asid = cap_pd[PD_ASID_SLOT];
#endif
#ifdef CONFIG_ARCH_X86_64
/* borrow the stored_hw_asid for PCID */
stored_hw_asid.words[0] = cap_pml4_cap_get_capPML4MappedASID_fp(newVTable);
#endif
#ifdef CONFIG_ARCH_AARCH64
stored_hw_asid.words[0] = cap_page_global_directory_cap_get_capPGDMappedASID(newVTable);
#endif
/* let gcc optimise this out for 1 domain */
dom = maxDom ? ksCurDomain : 0;
/* ensure only the idle thread or lower prio threads are present in the scheduler */
if (likely(dest->tcbPriority < NODE_STATE(ksCurThread->tcbPriority)) &&
!isHighestPrio(dom, dest->tcbPriority)) {
slowpath(SysCall);
}
/* Ensure that the endpoint has has grant rights so that we can
* create the reply cap */
if (unlikely(!cap_endpoint_cap_get_capCanGrant(ep_cap))) {
slowpath(SysCall);
}
#ifdef CONFIG_ARCH_AARCH32
if (unlikely(!pde_pde_invalid_get_stored_asid_valid(stored_hw_asid))) {
slowpath(SysCall);
}
#endif
/* Ensure the original caller is in the current domain and can be scheduled directly. */
if (unlikely(dest->tcbDomain != ksCurDomain && maxDom)) {
slowpath(SysCall);
}
if (unlikely(dest->tcbSchedContext != NULL)) {
slowpath(SysCall);
}
reply_t *reply = thread_state_get_replyObject_np(dest->tcbState);
if (unlikely(reply == NULL)) {
slowpath(SysCall);
}
#ifdef ENABLE_SMP_SUPPORT
/* Ensure both threads have the same affinity */
if (unlikely(NODE_STATE(ksCurThread)->tcbSchedContext->scCore != dest->tcbAffinity)) {
/* migration required */
slowpath(SysCall);
}
#endif /* ENABLE_SMP_SUPPORT */
/*
* --- POINT OF NO RETURN ---
*
* At this stage, we have committed to performing the IPC.
*/
#ifdef CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES
ksKernelEntry.is_fastpath = true;
#endif
/* Dequeue the destination. */
endpoint_ptr_set_epQueue_head_np(ep_ptr, TCB_REF(dest->tcbEPNext));
if (unlikely(dest->tcbEPNext)) {
dest->tcbEPNext->tcbEPPrev = NULL;
} else {
endpoint_ptr_mset_epQueue_tail_state(ep_ptr, 0, EPState_Idle);
}
badge = cap_endpoint_cap_get_capEPBadge(ep_cap);
/* Unlink dest <-> reply, link src (cur thread) <-> reply */
thread_state_ptr_set_tsType_np(&NODE_STATE(ksCurThread)->tcbState,
ThreadState_BlockedOnReply);
thread_state_ptr_set_replyObject_np(&dest->tcbState, 0);
thread_state_ptr_set_replyObject_np(&NODE_STATE(ksCurThread)->tcbState, REPLY_REF(reply));
reply->replyTCB = NODE_STATE(ksCurThread);
sched_context_t *sc = NODE_STATE(ksCurThread)->tcbSchedContext;
sc->scTcb = dest;
dest->tcbSchedContext = sc;
NODE_STATE(ksCurThread)->tcbSchedContext = NULL;
reply_t *old_caller = sc->scReply;
reply->replyPrev = call_stack_new(REPLY_REF(sc->scReply), false);
if (unlikely(old_caller)) {
old_caller->replyNext = call_stack_new(REPLY_REF(reply), false);
}
reply->replyNext = call_stack_new(SC_REF(sc), true);
sc->scReply = reply;
fastpath_copy_mrs (length, NODE_STATE(ksCurThread), dest);
/* Dest thread is set Running, but not queued. */
thread_state_ptr_set_tsType_np(&dest->tcbState,
ThreadState_Running);
switchToThread_fp(dest, cap_pd, stored_hw_asid);
msgInfo = wordFromMessageInfo(seL4_MessageInfo_set_capsUnwrapped(info, 0));
fastpath_restore(badge, msgInfo, NODE_STATE(ksCurThread));
}
void
fastpath_reply_recv(word_t cptr, word_t msgInfo, word_t reply)
{
seL4_MessageInfo_t info;
cap_t ep_cap;
endpoint_t *ep_ptr;
word_t length;
tcb_t *caller;
word_t badge;
tcb_t *endpointTail;
word_t fault_type;
cap_t newVTable;
vspace_root_t *cap_pd;
pde_t stored_hw_asid;
dom_t dom;
/* Get message info and length */
info = messageInfoFromWord_raw(msgInfo);
length = seL4_MessageInfo_get_length(info);
fault_type = seL4_Fault_get_seL4_FaultType(NODE_STATE(ksCurThread)->tcbFault);
/* Check there's no extra caps, the length is ok and there's no
* saved fault. */
if (unlikely(fastpath_mi_check(msgInfo) ||
fault_type != seL4_Fault_NullFault)) {
slowpath(SysReplyRecv);
}
/* Lookup the cap */
ep_cap = lookup_fp(TCB_PTR_CTE_PTR(NODE_STATE(ksCurThread), tcbCTable)->cap,
cptr);
/* Check it's an endpoint */
if (unlikely(!cap_capType_equals(ep_cap, cap_endpoint_cap) ||
!cap_endpoint_cap_get_capCanReceive(ep_cap))) {
slowpath(SysReplyRecv);
}
/* lookup the reply object */
cap_t reply_cap = lookup_fp(TCB_PTR_CTE_PTR(NODE_STATE(ksCurThread), tcbCTable)->cap, reply);
/* check it's a reply object */
if (unlikely(!cap_capType_equals(reply_cap, cap_reply_cap))) {
slowpath(SysReplyRecv);
}
/* Check there is nothing waiting on the notification */
if (NODE_STATE(ksCurThread)->tcbBoundNotification &&
notification_ptr_get_state(NODE_STATE(ksCurThread)->tcbBoundNotification) == NtfnState_Active) {
slowpath(SysReplyRecv);
}
/* Get the endpoint address */
ep_ptr = EP_PTR(cap_endpoint_cap_get_capEPPtr(ep_cap));
/* Check that there's not a thread waiting to send */
if (unlikely(endpoint_ptr_get_state(ep_ptr) == EPState_Send)) {
slowpath(SysReplyRecv);
}
/* Get the reply address */
reply_t *reply_ptr = REPLY_PTR(cap_reply_cap_get_capReplyPtr(reply_cap));
/* check that its valid and at the head of the call chain */
if (unlikely(reply_ptr->replyTCB == NULL ||
reply_ptr->replyNext.words[0] == 0)) {
slowpath(SysReplyRecv);
}
/* Determine who the caller is. */
caller = reply_ptr->replyTCB;
/* ensure we are not single stepping the caller in ia32 */
#if defined(CONFIG_HARDWARE_DEBUG_API) && defined(CONFIG_ARCH_IA32)
if (caller->tcbArch.tcbContext.breakpointState.single_step_enabled) {
slowpath(SysReplyRecv);
}
#endif
/* Check that the caller has not faulted, in which case a fault
reply is generated instead. */
fault_type = seL4_Fault_get_seL4_FaultType(caller->tcbFault);
if (unlikely(fault_type != seL4_Fault_NullFault)) {
slowpath(SysReplyRecv);
}
/* Get destination thread.*/
newVTable = TCB_PTR_CTE_PTR(caller, tcbVTable)->cap;
/* Get vspace root. */
cap_pd = cap_vtable_cap_get_vspace_root_fp(newVTable);
/* Ensure that the destination has a valid MMU. */
if (unlikely(! isValidVTableRoot_fp (newVTable))) {
slowpath(SysReplyRecv);
}
#ifdef CONFIG_ARCH_AARCH32
/* Get HWASID. */
stored_hw_asid = cap_pd[PD_ASID_SLOT];
#endif
#ifdef CONFIG_ARCH_X86_64
stored_hw_asid.words[0] = cap_pml4_cap_get_capPML4MappedASID(newVTable);
#endif
#ifdef CONFIG_ARCH_AARCH64
stored_hw_asid.words[0] = cap_page_global_directory_cap_get_capPGDMappedASID(newVTable);
#endif
/* Ensure the original caller can be scheduled directly. */
dom = maxDom ? ksCurDomain : 0;
if (unlikely(!isHighestPrio(dom, caller->tcbPriority))) {
slowpath(SysReplyRecv);
}
#ifdef CONFIG_ARCH_AARCH32
/* Ensure the HWASID is valid. */
if (unlikely(!pde_pde_invalid_get_stored_asid_valid(stored_hw_asid))) {
slowpath(SysReplyRecv);
}
#endif
/* Ensure the original caller is in the current domain and can be scheduled directly. */
if (unlikely(caller->tcbDomain != ksCurDomain && maxDom)) {
slowpath(SysReplyRecv);
}
if (unlikely(caller->tcbSchedContext != NULL)) {
slowpath(SysReplyRecv);
}
#ifdef ENABLE_SMP_SUPPORT
/* Ensure both threads have the same affinity */
if (unlikely(NODE_STATE(ksCurThread)->tcbSchedContext->scCore != caller->tcbAffinity)) {
slowpath(SysReplyRecv);
}
#endif /* ENABLE_SMP_SUPPORT */
/* not possible to set reply object and not be blocked */
assert(thread_state_get_replyObject(NODE_STATE(ksCurThread)->tcbState) == 0);
/*
* --- POINT OF NO RETURN ---
*
* At this stage, we have committed to performing the IPC.
*/
#ifdef CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES
ksKernelEntry.is_fastpath = true;
#endif
/* Set thread state to BlockedOnReceive */
thread_state_ptr_mset_blockingObject_tsType(
&NODE_STATE(ksCurThread)->tcbState, (word_t)ep_ptr, ThreadState_BlockedOnReceive);
/* unlink reply object from caller */
thread_state_ptr_set_replyObject_np(&caller->tcbState, 0);
/* set the reply object */
thread_state_ptr_set_replyObject_np(&NODE_STATE(ksCurThread)->tcbState, REPLY_REF(reply_ptr));
reply_ptr->replyTCB = NODE_STATE(ksCurThread);
/* Place the thread in the endpoint queue */
endpointTail = endpoint_ptr_get_epQueue_tail_fp(ep_ptr);
if (likely(!endpointTail)) {
NODE_STATE(ksCurThread)->tcbEPPrev = NULL;
NODE_STATE(ksCurThread)->tcbEPNext = NULL;
/* Set head/tail of queue and endpoint state. */
endpoint_ptr_set_epQueue_head_np(ep_ptr, TCB_REF(NODE_STATE(ksCurThread)));
endpoint_ptr_mset_epQueue_tail_state(ep_ptr, TCB_REF(NODE_STATE(ksCurThread)),
EPState_Recv);
} else {
/* Update queue. */
tcb_queue_t queue = tcbEPAppend(NODE_STATE(ksCurThread), ep_ptr_get_queue(ep_ptr));
endpoint_ptr_set_epQueue_head_np(ep_ptr, TCB_REF(queue.head));
endpoint_ptr_mset_epQueue_tail_state(ep_ptr, TCB_REF(queue.end), EPState_Recv);
}
/* update call stack */
word_t prev_ptr = call_stack_get_callStackPtr(reply_ptr->replyPrev);
sched_context_t *sc = NODE_STATE(ksCurThread)->tcbSchedContext;
NODE_STATE(ksCurThread)->tcbSchedContext = NULL;
caller->tcbSchedContext = sc;
sc->scTcb = caller;
sc->scReply = REPLY_PTR(prev_ptr);
if (unlikely(REPLY_PTR(prev_ptr) != NULL)) {
sc->scReply->replyNext = reply_ptr->replyNext;
}
/* TODO neccessary? */
reply_ptr->replyPrev.words[0] = 0;
reply_ptr->replyNext.words[0] = 0;
/* I know there's no fault, so straight to the transfer. */
/* Replies don't have a badge. */
badge = 0;
fastpath_copy_mrs (length, NODE_STATE(ksCurThread), caller);
/* Dest thread is set Running, but not queued. */
thread_state_ptr_set_tsType_np(&caller->tcbState,
ThreadState_Running);
switchToThread_fp(caller, cap_pd, stored_hw_asid);
msgInfo = wordFromMessageInfo(seL4_MessageInfo_set_capsUnwrapped(info, 0));
fastpath_restore(badge, msgInfo, NODE_STATE(ksCurThread));
}
static inline void
mask_ack_bail(irq_t irq)
{
maskInterrupt(true, irq);
ackInterrupt(irq);
restore_user_context();
}
void
fastpath_irq(irq_t irq)
{
/* check the irq is valid */
if (unlikely(irq == irqInvalid)) {
if (config_set(CONFIG_IRQ_REPORTING)) {
printf("Spurious interrupt\n");
}
handleSpuriousIRQ();
restore_user_context();
UNREACHABLE();
}
if (unlikely(irq > maxIRQ)) {
mask_ack_bail(irq);
UNREACHABLE();
}
if (unlikely(intStateIRQTable[irq] != IRQSignal)) {
slowpath_irq(irq);
UNREACHABLE();
}
cap_t ntfn_cap = intStateIRQNode[irq].cap;
if (unlikely(cap_get_capType(ntfn_cap) != cap_notification_cap ||
!cap_notification_cap_get_capNtfnCanSend(ntfn_cap))) {
if (config_set(CONFIG_IRQ_REPORTING)) {
printf("Undelivered irq: %d\n", (int) irq);
}
mask_ack_bail(irq);
UNREACHABLE();
}
notification_t *ntfn_ptr = NTFN_PTR(cap_notification_cap_get_capNtfnPtr(ntfn_cap));
notification_state_t ntfn_state = notification_ptr_get_state(ntfn_ptr);
word_t badge = cap_notification_cap_get_capNtfnBadge(ntfn_cap);
tcb_t *dest = NULL;
if (ntfn_state == NtfnState_Waiting) {
dest = TCB_PTR(notification_ptr_get_ntfnQueue_head(ntfn_ptr));
} else if (notification_ptr_get_ntfnBoundTCB(ntfn_ptr)) {
dest = TCB_PTR(notification_ptr_get_ntfnBoundTCB(ntfn_ptr));
#ifdef CONFIG_VTX
if (unlikely(thread_state_ptr_get_tsType(dest->tcbState) == ThreadState_RunningVM)) {
slowpath_irq(irq);
UNREACHABLE();
}
#endif
} else {
ntfn_set_active(ntfn_ptr, badge | notification_ptr_get_ntfnMsgIdentifier(ntfn_ptr));
mask_ack_bail(irq);
UNREACHABLE();
}
/* at this point we know we're going to have to switch threads */
assert(dest != NULL);
/* check dest has a scheduling context */
if (dest->tcbSchedContext == NULL || dest->tcbSchedContext->scRefillMax == 0) {
slowpath_irq(irq);
UNREACHABLE();
}
#ifdef CONFIG_ENABLE_SMP
if (dest->tcbAffinity != getCurrentCPUIndex()) {
slowpath_irq(irq);
UNREACHABLE();
}
#endif
cap_t newVTable = TCB_PTR_CTE_PTR(dest, tcbVTable)->cap;
#ifndef CONFIG_ARCH_AARCH32
vspace_root_t *cap_pd;
#else
pde_t *cap_pd;
#endif
cap_pd = cap_vtable_cap_get_vspace_root_fp(newVTable);
if (unlikely(!isValidVTableRoot_fp(newVTable))) {
slowpath_irq(irq);
UNREACHABLE();
}
pde_t stored_hw_asid;
#ifdef CONFIG_ARCH_X86_64
stored_hw_asid.words[0] = cap_pml4_cap_get_capPML4MappedASID(newVTable);
#endif
#ifdef CONFIG_ARCH_AARCH64
stored_hw_asid.words[0] = cap_page_global_directory_cap_get_capPGDMappedASID(newVTable);
#endif
#ifdef CONFIG_ARCH_AARCH32
/* Get HW ASID */
stored_hw_asid = cap_pd[PD_ASID_SLOT];
if (unlikely(!pde_pde_invalid_get_stored_asid_valid(stored_hw_asid))) {
slowpath_irq(irq);
UNREACHABLE();
}
#endif
/* --- POINT OF NO RETURN -- */
switch (ntfn_state) {
case NtfnState_Active:
case NtfnState_Idle:
if (thread_state_get_tsType(dest->tcbState) == ThreadState_BlockedOnReceive) {
endpoint_t *ep_ptr = EP_PTR(thread_state_get_blockingObject(dest->tcbState));
endpoint_ptr_set_epQueue_head_np(ep_ptr, TCB_REF(dest->tcbEPNext));
if (unlikely(dest->tcbEPNext)) {
dest->tcbEPNext->tcbEPPrev = NULL;
} else {
endpoint_ptr_mset_epQueue_tail_state(ep_ptr, 0, EPState_Idle);
}
setRegister(dest, badgeRegister, badge);
thread_state_ptr_set_tsType_np(&dest->tcbState, ThreadState_Running);
} else {
ntfn_set_active(ntfn_ptr, badge);
mask_ack_bail(irq);
UNREACHABLE();
}
break;
case NtfnState_Waiting:
notification_ptr_set_ntfnQueue_head_np(ntfn_ptr, TCB_REF(dest->tcbEPNext));
if (unlikely(dest->tcbEPNext)) {
dest->tcbEPNext->tcbEPPrev = NULL;
} else {
notification_ptr_mset_ntfnQueue_tail_state(ntfn_ptr, 0, NtfnState_Idle);
}
setRegister(dest, badgeRegister, badge);
thread_state_ptr_set_tsType_np(&dest->tcbState, ThreadState_Running);
break;
}
if (dest->tcbPriority > NODE_STATE(ksCurThread)->tcbPriority) {
/* we're going to switch threads - charge the current thread */
updateTimestamp(false);
ticks_t prev = getNextInterrupt();
/* charge the previous thread */
if (checkBudget()) {
commitTime();
}
if (isSchedulable(NODE_STATE(ksCurThread))) {
SCHED_ENQUEUE_CURRENT_TCB;
}
switchToThread_fp(dest, cap_pd, stored_hw_asid);
/* only set the next irq if we really have to */
ticks_t next = getNextInterrupt();
if (next < prev) {
setDeadline(next - getTimerPrecision());
}
/* update sc */
NODE_STATE(ksCurSC) = NODE_STATE(ksCurThread)->tcbSchedContext;
} else {
assert(isSchedulable(dest));
tcbSchedEnqueue(dest);
}
mask_ack_bail(irq);
UNREACHABLE();
}
void
#ifdef ARCH_X86
NORETURN
#endif
fastpath_signal(word_t cptr)
{
word_t fault_type;
cap_t ntfn_cap;
notification_t *ntfn_ptr;
tcb_t *dest = NULL;
word_t badge;
notification_state_t ntfn_state;
/* get message info and fault type */
fault_type = seL4_Fault_get_seL4_FaultType(NODE_STATE(ksCurThread)->tcbFault);
/* check there's no saved fault */
if (unlikely(fault_type != seL4_Fault_NullFault)) {
slowpath(SysSend);
}
/* lookup the cap */
ntfn_cap = lookup_fp(TCB_PTR_CTE_PTR(NODE_STATE(ksCurThread), tcbCTable)->cap, cptr);
/* check it's a notification object */
if (unlikely(!cap_capType_equals(ntfn_cap, cap_notification_cap))) {
slowpath(SysSend);
}
/* get the address */
ntfn_ptr = NTFN_PTR(cap_notification_cap_get_capNtfnPtr(ntfn_cap));
/* get the state */
ntfn_state = notification_ptr_get_state(ntfn_ptr);
if (ntfn_state == NtfnState_Waiting) {
/* get the destination thread */
dest = TCB_PTR(notification_ptr_get_ntfnQueue_head(ntfn_ptr));
} else {
/* get the bound tcb */
dest = (tcb_t *) notification_ptr_get_ntfnBoundTCB(ntfn_ptr);
}
/* if the target is higher prio we'll need to invoke the scheduler,
* this fastpath only fastpaths signal where we don't change threads */
if (unlikely(dest && dest->tcbPriority > NODE_STATE(ksCurThread)->tcbPriority)) {
slowpath(SysSend);
}
#ifdef ENABLE_SMP_SUPPORT
/* Ensure both threads have the same affinity */
if (unlikely(dest && dest->tcbSchedContext->scCore != getCurrentCPUIndex())) {
slowpath(SysSend);
}
#endif /* ENABLE_SMP_SUPPORT */
/* --- POINT OF NO RETURN -- */
#ifdef CONFIG_BENCHMARK_TRACK_KERNEL_ENTRIES
ksKernelEntry.is_fastpath = true;
#endif
badge = cap_notification_cap_get_capNtfnBadge(ntfn_cap);
switch (ntfn_state) {
case NtfnState_Idle:
if (dest && thread_state_get_tsType(dest->tcbState) == ThreadState_BlockedOnReceive) {
endpoint_t *ep_ptr;
ep_ptr = EP_PTR(thread_state_get_blockingObject(dest->tcbState));
endpoint_ptr_set_epQueue_head_np(ep_ptr, TCB_REF(dest->tcbEPNext));
if (unlikely(dest->tcbEPNext)) {
dest->tcbEPNext->tcbEPPrev = NULL;
} else {
endpoint_ptr_mset_epQueue_tail_state(ep_ptr, 0, EPState_Idle);
}
setRegister(dest, badgeRegister, badge);
thread_state_ptr_set_tsType_np(&dest->tcbState, ThreadState_Running);
tcbSchedEnqueue(dest);
} else {
ntfn_set_active(ntfn_ptr, badge);
}
break;
case NtfnState_Waiting:
/* dequeue the destination */
notification_ptr_set_ntfnQueue_head_np(ntfn_ptr, TCB_REF(dest->tcbEPNext));
if (unlikely(dest->tcbEPNext)) {
dest->tcbEPNext->tcbEPPrev = NULL;
} else {
notification_ptr_mset_ntfnQueue_tail_state(ntfn_ptr, 0, NtfnState_Idle);
}
setRegister(dest, badgeRegister, badge);
thread_state_ptr_set_tsType_np(&dest->tcbState, ThreadState_Running);
tcbSchedEnqueue(dest);
break;
case NtfnState_Active:
ntfn_set_active(ntfn_ptr, badge | notification_ptr_get_ntfnMsgIdentifier(ntfn_ptr));
break;
}
fastpath_restore(getRegister(NODE_STATE(ksCurThread), badgeRegister),
getRegister(NODE_STATE(ksCurThread), msgInfoRegister),
NODE_STATE(ksCurThread));
}