[1] | 1 | /* |
---|
| 2 | * kern/event.h - Per-CPU Events-Manager |
---|
| 3 | * |
---|
| 4 | * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless |
---|
| 5 | * Copyright (c) 2011,2012 UPMC Sorbonne Universites |
---|
| 6 | * |
---|
| 7 | * This file is part of ALMOS-kernel. |
---|
| 8 | * |
---|
| 9 | * ALMOS-kernel is free software; you can redistribute it and/or modify it |
---|
| 10 | * under the terms of the GNU General Public License as published by |
---|
| 11 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 12 | * |
---|
| 13 | * ALMOS-kernel is distributed in the hope that it will be useful, but |
---|
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 16 | * General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, |
---|
| 20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #ifndef _EVENT_H_ |
---|
| 24 | #define _EVENT_H_ |
---|
| 25 | |
---|
| 26 | #include <types.h> |
---|
| 27 | #include <list.h> |
---|
| 28 | |
---|
| 29 | struct cpu_s; |
---|
| 30 | |
---|
| 31 | /** Private event flags */ |
---|
| 32 | #define EVENT_PENDING 1 |
---|
| 33 | |
---|
| 34 | ////////////////////////////////////////////////// |
---|
| 35 | // Public Section // |
---|
| 36 | ////////////////////////////////////////////////// |
---|
| 37 | |
---|
| 38 | /** Local Events Priorities */ |
---|
| 39 | typedef enum |
---|
| 40 | { |
---|
| 41 | E_CLK = 0, /* Fixed Priority */ |
---|
| 42 | E_TLB, |
---|
| 43 | E_CHR, |
---|
| 44 | E_BLK, |
---|
| 45 | E_MIGRATE, |
---|
| 46 | E_CREATE, |
---|
| 47 | E_FORK, |
---|
| 48 | E_EXEC, |
---|
| 49 | E_FUNC, |
---|
| 50 | E_PRIO_NR |
---|
| 51 | }event_prio_t; |
---|
| 52 | |
---|
| 53 | typedef enum |
---|
| 54 | { |
---|
| 55 | EL_LOCAL, |
---|
| 56 | EL_REMOTE |
---|
| 57 | }event_listner_type_t; |
---|
| 58 | |
---|
| 59 | /** Opaque event structure */ |
---|
| 60 | struct event_s; |
---|
| 61 | |
---|
| 62 | /** Opaque events listner structure */ |
---|
| 63 | struct event_listner_s; |
---|
| 64 | |
---|
| 65 | /** Get CPU of given listner */ |
---|
| 66 | #define event_listner_get_cpu(el,name) |
---|
| 67 | |
---|
| 68 | /** Event handler type definition */ |
---|
| 69 | #define EVENT_HANDLER(n) sint_t (n)(struct event_s *event) |
---|
| 70 | typedef EVENT_HANDLER(event_handler_t); |
---|
| 71 | |
---|
| 72 | /** Set event's priority */ |
---|
| 73 | #define event_set_priority(e, _prio) |
---|
| 74 | |
---|
| 75 | /** Set event's sender id */ |
---|
| 76 | #define event_set_senderId(e,_id) |
---|
| 77 | |
---|
| 78 | /** Set event's handler */ |
---|
| 79 | #define event_set_handler(e,_handler) |
---|
| 80 | |
---|
| 81 | /** Set event handler's argument */ |
---|
| 82 | #define event_set_argument(e,_arg) |
---|
| 83 | |
---|
| 84 | /** Set handler execution error code */ |
---|
| 85 | #define event_set_error(e,_error) |
---|
| 86 | |
---|
| 87 | /** Get event's priority */ |
---|
| 88 | #define event_get_priority(e) |
---|
| 89 | |
---|
| 90 | /** Get event's sender id */ |
---|
| 91 | #define event_get_senderId(e) |
---|
| 92 | |
---|
| 93 | /** Get event's handler */ |
---|
| 94 | #define event_get_handler(e) |
---|
| 95 | |
---|
| 96 | /** Get handler's argument */ |
---|
| 97 | #define event_get_argument(e) |
---|
| 98 | |
---|
| 99 | /** Get handler execution error code */ |
---|
| 100 | #define event_get_error(e) |
---|
| 101 | |
---|
| 102 | /** True if event manager has a pending event */ |
---|
| 103 | #define event_is_pending(el) |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | /** Initialize event */ |
---|
| 107 | error_t event_init(struct event_s *event); |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | /** Destroy event */ |
---|
| 111 | void event_destroy(struct event_s *event); |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | /** |
---|
| 115 | * Send an event to local event listner |
---|
| 116 | * must be called with interrupts disabled |
---|
| 117 | * Doing the same for a remote event listner |
---|
| 118 | * is not required |
---|
| 119 | */ |
---|
| 120 | void event_send(struct event_s *event, uint_t cpu_gid); |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | /** |
---|
| 124 | * Notify about all recived events, |
---|
| 125 | * must be called with interrupts disabled |
---|
| 126 | */ |
---|
| 127 | void event_listner_notify(struct event_listner_s *el); |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | /** Initialize event listner */ |
---|
| 131 | error_t event_listner_init(struct event_listner_s *el); |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | /** Destroy event listner */ |
---|
| 135 | void event_listner_destroy(struct event_listner_s *el); |
---|
| 136 | |
---|
| 137 | /** Events Manager thread */ |
---|
| 138 | void* thread_event_manager(void *arg); |
---|
| 139 | |
---|
| 140 | ////////////////////////////////////////////////// |
---|
| 141 | // Private Section // |
---|
| 142 | ////////////////////////////////////////////////// |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | /** |
---|
| 146 | * Private events list based database |
---|
| 147 | **/ |
---|
| 148 | struct event_list_s |
---|
| 149 | { |
---|
| 150 | volatile uint_t count; |
---|
| 151 | struct list_entry root; |
---|
| 152 | }; |
---|
| 153 | |
---|
| 154 | /** opaque events listner */ |
---|
| 155 | struct event_listner_s |
---|
| 156 | { |
---|
| 157 | uint_t count; |
---|
| 158 | volatile uint_t flags; |
---|
| 159 | volatile uint_t prio CACHELINE; |
---|
| 160 | struct event_list_s tbl[E_PRIO_NR]; |
---|
| 161 | |
---|
| 162 | }; |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | /** internal event info structure */ |
---|
| 166 | typedef struct |
---|
| 167 | { |
---|
| 168 | /* event type */ |
---|
| 169 | uint_t prio; |
---|
| 170 | |
---|
| 171 | /* event handler */ |
---|
| 172 | event_handler_t *handler; |
---|
| 173 | |
---|
| 174 | /* event argument */ |
---|
| 175 | void *arg; |
---|
| 176 | |
---|
| 177 | /* event sender id */ |
---|
| 178 | void *id; |
---|
| 179 | |
---|
| 180 | /* event error code */ |
---|
| 181 | error_t err; |
---|
| 182 | }event_info_t; |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | /** Event opaque structure */ |
---|
| 186 | struct event_s |
---|
| 187 | { |
---|
| 188 | /* Event Primary Info */ |
---|
| 189 | event_info_t e_info; |
---|
| 190 | |
---|
| 191 | /* Event List Chain */ |
---|
| 192 | struct list_entry e_list; |
---|
| 193 | |
---|
| 194 | /* Event Backup Info */ |
---|
| 195 | event_info_t e_bckp; |
---|
| 196 | |
---|
| 197 | /* Event Private Data */ |
---|
| 198 | void *data; |
---|
| 199 | }; |
---|
| 200 | |
---|
| 201 | #define event_backup(e) \ |
---|
| 202 | do{ \ |
---|
| 203 | (e)->e_bckp.prio = (e)->e_info.prio; \ |
---|
| 204 | (e)->e_bckp.handler = (e)->e_info.handler; \ |
---|
| 205 | (e)->e_bckp.arg = (e)->e_info.arg; \ |
---|
| 206 | (e)->e_bckp.id = (e)->e_info.id; \ |
---|
| 207 | (e)->e_bckp.err = (e)->e_info.err; \ |
---|
| 208 | }while(0) |
---|
| 209 | |
---|
| 210 | #define event_restore(e) \ |
---|
| 211 | do{ \ |
---|
| 212 | (e)->e_info.prio = (e)->e_bckp.prio; \ |
---|
| 213 | (e)->e_info.handler = (e)->e_bckp.handler; \ |
---|
| 214 | (e)->e_info.arg = (e)->e_bckp.arg; \ |
---|
| 215 | (e)->e_info.id = (e)->e_bckp.id; \ |
---|
| 216 | (e)->e_info.err = (e)->e_bckp.err; \ |
---|
| 217 | }while(0) |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | #undef event_listner_get_cpu |
---|
| 221 | #define event_listner_get_cpu(_el,_name) \ |
---|
| 222 | list_container((_el), struct cpu_s, _name) |
---|
| 223 | |
---|
| 224 | #undef event_set_priority |
---|
| 225 | #define event_set_priority(e, _prio) do{(e)->e_info.prio = (_prio);}while(0) |
---|
| 226 | |
---|
| 227 | #undef event_set_senderId |
---|
| 228 | #define event_set_senderId(e,_id) do{(e)->e_info.id = (_id);}while(0) |
---|
| 229 | |
---|
| 230 | #undef event_set_handler |
---|
| 231 | #define event_set_handler(e,_handler) do{(e)->e_info.handler = (_handler);}while(0) |
---|
| 232 | |
---|
| 233 | #undef event_set_argument |
---|
| 234 | #define event_set_argument(e,_arg) do{(e)->e_info.arg = (_arg);}while(0) |
---|
| 235 | |
---|
| 236 | #undef event_set_error |
---|
| 237 | #define event_set_error(e,_error) do{(e)->e_info.err = (_error);}while(0) |
---|
| 238 | |
---|
| 239 | #undef event_get_priority |
---|
| 240 | #define event_get_priority(e) ((e)->e_info.prio) |
---|
| 241 | |
---|
| 242 | #undef event_get_senderId |
---|
| 243 | #define event_get_senderId(e) ((e)->e_info.id) |
---|
| 244 | |
---|
| 245 | #undef event_get_handler |
---|
| 246 | #define event_get_handler(e) ((e)->e_info.handler) |
---|
| 247 | |
---|
| 248 | #undef event_get_argument |
---|
| 249 | #define event_get_argument(e) ((e)->e_info.arg) |
---|
| 250 | |
---|
| 251 | #undef event_get_error |
---|
| 252 | #define event_get_error(e) ((e)->e_info.err) |
---|
| 253 | |
---|
| 254 | #undef event_is_pending |
---|
| 255 | #define event_is_pending(el) ((el)->flags & EVENT_PENDING) |
---|
| 256 | |
---|
| 257 | #endif /* _EVENT_H_ */ |
---|