]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - src_frescan/frescan_data.h
add the infraestructure for storing the negotiated contracts and performing the analy...
[frescor/fna.git] / src_frescan / frescan_data.h
1 /*!
2  * @file frescan_data.h
3  *
4  * @brief global data used from different modules in frescan
5  *
6  * @version 0.01
7  *
8  * @date 12-Mar-2008
9  *
10  * @author
11  *      Daniel Sangorrin
12  *
13  * @comments
14  *
15  * In order to simplify we have a single module, frescan_data, to store the
16  * main internal structures and global data of the FRESCAN protocol.
17  *
18  * @license
19  *
20  * See MaRTE OS license
21  *
22  */
23
24 #ifndef _MARTE_FRESCAN_DATA_H_
25 #define _MARTE_FRESCAN_DATA_H_
26
27 #include <stdint.h>    // uint32_t
28 #include <semaphore.h> // sem_t
29 #include <time.h>      // struct timespec, timer_t
30 #include "fosa_threads_and_signals.h"   // fosa_thread_id_t
31
32 #include <misc/linux_list.h> // struct list_head
33 #include <misc/freelist.h>   // freelist_t
34
35 #include "frescan.h"         // frescan_node_t, _prio_t, _budget_t
36 #include "frescan_config.h"  // FRESCAN_MLOCK_T, FRESCAN_MX_XXX
37 #include "frescan_packets.h" // frescan_packet_t
38
39 /**
40  * frescan_repl_op_t - a replenishment operation
41  *
42  * @when: when the replenishment operation is programmed at
43  * @amount: number of frames to add to the current_budget
44  * @repl_list: to chain the replenishments for a certain sporadic server
45  * @pool_pos: to know how to free it from the replenishment pool
46  */
47
48 typedef struct {
49         struct timespec when;
50         frescan_budget_t amount;
51         struct list_head repl_list;
52         int pool_pos;
53 } frescan_repl_op_t;
54
55 /**
56  * frescan_server_params_t - server parameters
57  *
58  * @budget: the budget in CAN 8-byte frames
59  * @period: the replenishment period for the server
60  * @prio: the priority for the server TODO: this should be a return value
61  */
62
63 typedef struct {
64         frescan_budget_t budget;
65         struct timespec  period;
66 } frescan_budget_period_t;
67
68 typedef struct {
69         frescan_budget_period_t values;
70         frescan_prio_t prio;
71 } frescan_server_params_t;
72
73 /**
74  * frescan_server_data_t - server data
75  *
76  * @params: the fixed parameters (budget, period and priority)
77  * @current_budget: the current available capacity
78  * @current_priority: the current priority (0=background)
79  * @repl_list: the list of pending replenishment operations
80  * @repl_timer: the timer for the replenishments associated to this server
81  *     NOTE: we could use a single timer for all but for now this is simpler
82  * @act_time: the last activation time for the server
83  * @packet_list: the packets enqueued on this server
84  * @servers_list: the list of servers
85  */
86
87 typedef struct {
88         frescan_server_params_t params;
89         frescan_network_t net;
90         frescan_ss_t      id;
91         frescan_budget_t  current_budget;
92         frescan_prio_t    current_priority;
93         frescan_budget_t  pending_packets;
94         frescan_repl_op_t replenishments;
95         timer_t           repl_timer;
96         struct timespec   act_time;
97         frescan_packet_t  packet_list;
98         struct list_head  servers_list;
99 } frescan_server_data_t;
100
101 /**
102  * the_servers_pool - pool of servers structure
103  */
104
105 extern frescan_server_data_t the_servers_pool[FRESCAN_MX_NETWORKS][FRESCAN_MX_IDS];
106 extern freelist_t the_servers_pool_freelist[FRESCAN_MX_NETWORKS];
107 extern frescan_server_data_t the_active_servers[FRESCAN_MX_NETWORKS];
108
109 /**
110  * frescan_contract_t
111  */
112
113 typedef struct {
114         frescan_budget_period_t min_values;
115         frescan_budget_period_t max_values;
116         frescan_prio_t prio;
117 } frescan_contract_t;
118
119 /**
120  * frescan_sa_xxx scheduling analysis types
121  */
122
123 typedef struct {
124         frescan_prio_t server_prio;
125 } frescan_sa_final_values_t;
126
127 typedef struct {
128         frescan_contract_t        contract;
129         frescan_node_t            node;
130         frescan_ss_t              ss;
131         frescan_sa_final_values_t final_values;
132         struct list_head          list;
133 } frescan_sa_contract_t;
134
135 typedef struct {
136         frescan_prio_t    max_prio;
137         frescan_prio_t    min_prio;
138 } frescan_sa_init_params_t;
139
140 typedef struct {
141         frescan_sa_contract_t contracts[FRESCAN_MX_NODES][FRESCAN_MX_IDS];
142         frescan_sa_contract_t contracts_head;
143         frescan_sa_init_params_t init_params;
144 } frescan_sa_scenario_t;
145
146 /**
147  * frescan_prio_queue_t - priority queue
148  *
149  * FRESCAN priority queues are implemented as an array of one 'fifo_queue' for
150  * each priority. Where the 'fifo_queues' are implemented using the
151  * 'struct list_head fifo_list;' field of each packet structure (Linux lists).
152  *
153  * So far mutual exclusion is achieved by disabling interrupts and
154  * synchronization is done using a semaphore. This is because the queues
155  * are accesed concurrently from user threads and the IRQ handler.
156  *
157  * @net: the network this priority queue belongs to (mainly for locking)
158  * @fifo_queues: an array of packets for each priority where each packet
159  *               is just the head of a fifo_list. The array is allocated
160  *               from the heap, using malloc, at initialization with range
161  *               0..max_prio-1
162  * @max_prio: defines the number of priorities as (0 .. max_prio - 1)
163  * @sem: semaphore used for synchronization
164  */
165
166 typedef struct {
167         frescan_network_t net;
168         frescan_packet_t *fifo_queues;
169         uint32_t max_prio;
170         sem_t sem;
171 } frescan_prio_queue_t;
172
173 /**
174  * frescan_queues_t - the set of FRESCAN queues for each instance of a protocol
175  *
176  * @tx_fp_queue: priority queue for the fixed priority packets
177  * @rx_channel_queues: a priority queue for each receiving channel
178  *
179  * TODO: add here the sporadic server queues...
180  */
181
182 typedef struct {
183         frescan_prio_queue_t *tx_fp_queue;
184         frescan_prio_queue_t **rx_channel_queues;
185         uint32_t num_rx_channels;
186 } frescan_queues_t;
187
188 /**
189  * frescan_network_data_t - data for each network instance
190  *
191  * @local_node: the local node id for that network. The implementation does not
192  * support several interfaces for the same network.
193  * @fd: file descriptor associated to /dev/canXX
194  * @repl_thread_id: replenishment thread id
195  * @manager_thread_id: manager thread id
196  * @acceptor_thread_id: acceptor thread id
197  * @neg_messages_ss_id: sporadic server for negotiation messages
198  * @queues: the queues of this network instance
199  * @last_packet: pointer to the last packet from which a frame was inserted
200  *               in the chip and its transmission is not complete.
201  * @last_packet_prio: prio of the packet in the buffer
202  * @id_queues: queues to store received packets while the whole message is
203  *             not complete (fragmentation). (id = 0 .. FRESCAN_MX_IDS - 1)
204  * @id_fp_queues: the same as id_queues but for fp messages, which have
205  *                id=FRESCAN_MX_IDS and are distinguised through their
206  *                priorities.
207  * @scenario: the scheduling analysis scenario for the network
208  *
209  * the implementation can handle several FRESCAN networks at the same time
210  * in the same node, so we need a place to store its internal data. The data
211  * is allocated as an array where the index is the MINOR number (which also
212  * identifies the /dev/canx device for that network)
213  */
214
215 typedef struct {
216         FRESCAN_MLOCK_T lock;
217         frescan_node_t local_node;
218         int fd;
219         fosa_thread_id_t repl_thread_id;
220         fosa_thread_id_t manager_thread_id;
221         fosa_thread_id_t acceptor_thread_id;
222         frescan_ss_t neg_messages_ss_id;
223         frescan_queues_t queues;
224         frescan_packet_t *last_packet;
225         frescan_prio_t last_packet_prio;
226         frescan_packet_t *id_queues[FRESCAN_MX_IDS];      // TODO: alloc at init
227         frescan_packet_t *id_fp_queues[FRESCAN_MX_PRIOS]; // TODO: alloc at init
228         frescan_sa_scenario_t scenario;
229 } frescan_network_data_t;
230
231 extern frescan_network_data_t the_networks[FRESCAN_MX_NETWORKS];
232
233 /**
234  * frescan_data_init() - init the data global variables
235  *
236  */
237
238 extern int frescan_data_init(int fd, frescan_init_params_t *params);
239
240 #endif // _MARTE_FRESCAN_DATA_H_