Allow ev_qs to not have INDIR throttling (XCC)
[akaros.git] / kern / include / ros / event.h
1 /* Copyright (c) 2010-2011 The Regents of the University of California
2  * Barret Rhoden <brho@cs.berkeley.edu>
3  * See LICENSE for details.
4  *
5  * Kernel interface for event/notification delivery and preemption. */
6
7 #ifndef ROS_INC_EVENT_H
8 #define ROS_INC_EVENT_H
9
10 #include <ros/common.h>
11 #include <ros/atomic.h>
12 #include <ros/arch/trapframe.h>
13 /* #include <ros/ucq.h> included below */
14
15 /* Event Delivery Flags from the process to the kernel */
16 #define EVENT_IPI                               0x001   /* IPI the vcore (usually with INDIR) */
17 #define EVENT_INDIR                             0x002   /* send an indirection event to vcore */
18 #define EVENT_FALLBACK                  0x004   /* pick another vcore if it's offline */
19 #define EVENT_NOMSG                             0x008   /* just send the bit, not the msg */
20 #define EVENT_ROUNDROBIN                0x010   /* pick a vcore, RR style */
21 #define EVENT_VCORE_APPRO               0x020   /* send to where the kernel wants */
22 #define EVENT_NOTHROTTLE                0x040   /* send all alerts (no throttling) */
23 /* Flags from the program to the 2LS */
24 #define EVENT_JUSTHANDLEIT              0x100   /* 2LS should handle the ev_q */
25 #define EVENT_THREAD                    0x200   /* spawn thread to handle ev_q */
26
27 /* Event Message Types */
28 #define EV_NONE                                  0
29 #define EV_PREEMPT_PENDING               1
30 #define EV_GANG_PREMPT_PENDING   2
31 #define EV_VCORE_REVOKE                  3
32 #define EV_GANG_RETURN                   4
33 #define EV_USER_IPI                              5
34 #define EV_PAGE_FAULT                    6
35 #define EV_ALARM                                 7
36 #define EV_EVENT                                 8
37 #define EV_FREE_APPLE_PIE                9
38 #define EV_SYSCALL                              10
39 #define NR_EVENT_TYPES                  11 /* keep me last */
40
41 /* Will probably have dynamic notifications later */
42 #define MAX_NR_DYN_EVENT                25
43 #define MAX_NR_EVENT                    (NR_EVENT_TYPES + MAX_NR_DYN_EVENT)
44
45 /* Want to keep this small and generic, but add items as you need them.  One
46  * item some will need is an expiration time, which ought to be put in the 64
47  * bit arg.  Will need tweaking / thought as we come up with events.  These are
48  * what get put on the per-core queue in procdata. */
49 struct event_msg {
50         uint16_t                                        ev_type;
51         uint16_t                                        ev_arg1;
52         uint32_t                                        ev_arg2;
53         void                                            *ev_arg3;
54         uint64_t                                        ev_arg4;
55 };
56
57 /* Including here since ucq.h needs to know about struct event_msg */
58 #include <ros/ucq.h>
59
60 /* Structure for storing / receiving event messages.  An overflow causes the
61  * bit of the event to get set in the bitmap.  You can also have just the bit
62  * sent (and no message). */
63 struct event_mbox {
64         struct ucq                                      ev_msgs;
65         uint8_t                                         ev_bitmap[(MAX_NR_EVENT - 1) / 8 + 1];
66 };
67
68 /* The kernel sends messages to this structure, which describes how and where
69  * to receive messages, including optional IPIs. */
70 struct event_queue {
71         struct event_mbox                       *ev_mbox;
72         int                                                     ev_flags;
73         bool                                            ev_alert_pending;
74         uint32_t                                        ev_vcore;
75         void                                            (*ev_handler)(struct event_queue *);
76 };
77
78 /* Big version, contains storage space for the ev_mbox.  Never access the
79  * internal mbox directly. */
80 struct event_queue_big {
81         struct event_mbox                       *ev_mbox;
82         int                                                     ev_flags;
83         uint32_t                                        ev_vcore;
84         void                                            (*ev_handler)(struct event_queue *);
85         struct event_mbox                       ev_imbox;
86 };
87
88 /* Per-core data about preemptions and notifications */
89 struct preempt_data {
90         struct user_trapframe           preempt_tf;
91         struct ancillary_state          preempt_anc;
92         struct user_trapframe           notif_tf;
93         uintptr_t                                       transition_stack;       /* advertised by the user */
94         bool                                            notif_enabled;          /* vcore willing to recv */
95         bool                                            notif_pending;          /* notif k_msg on the way */
96         bool                                            can_rcv_msg;            /* can receive FALLBACK */
97         seq_ctr_t                                       preempt_tf_valid;
98         struct event_mbox                       ev_mbox;
99 };
100
101 #endif /* ROS_INC_EVENT_H */