Rev 2260 | Rev 2315 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2260 | Rev 2265 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2007 Jan Hudecek |
2 | * Copyright (c) 2007 Jan Hudecek |
3 | * Copyright (c) 2006 Jakub Jermar |
3 | * Copyright (c) 2006 Jakub Jermar |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | /** @addtogroup sync |
29 | /** @addtogroup sync |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <synch/rcu.h> |
35 | #include <synch/rcu.h> |
36 | #include <synch/waitq.h> |
36 | #include <synch/waitq.h> |
37 | #include <arch.h> |
37 | #include <arch.h> |
38 | #include <config.h> |
38 | #include <config.h> |
39 | #include <arch/types.h> |
39 | #include <arch/types.h> |
40 | #include <ddi/tasklet.h> |
40 | #include <proc/tasklet.h> |
41 | #include <synch/spinlock.h> |
41 | #include <synch/spinlock.h> |
42 | #include <time/delay.h> |
42 | #include <time/delay.h> |
43 | #include <panic.h> |
43 | #include <panic.h> |
44 | #include <print.h> |
44 | #include <print.h> |
45 | 45 | ||
46 | typedef struct rcu_global |
46 | typedef struct { |
47 | { |
- | |
48 | uint32_t current_batch; |
47 | uint32_t current_batch; |
49 | uint32_t completed_batch; |
48 | uint32_t completed_batch; |
50 | bool next_batch_waiting; |
49 | bool next_batch_waiting; |
51 | } rcu_global_t; |
50 | } rcu_global_t; |
52 | 51 | ||
53 | typedef struct rcu_callback_list |
52 | typedef struct rcu_callback_list { |
54 | { |
- | |
55 | struct rcu_callback_list* next; |
53 | struct rcu_callback_list* next; |
56 | void (*func)(void*); |
54 | void (*func)(void*); |
57 | void* data; |
55 | void* data; |
58 | bool* cpu_mask; |
56 | bool* cpu_mask; |
59 | } rcu_callback_list_t; |
57 | } rcu_callback_list_t; |
60 | 58 | ||
61 | 59 | ||
62 | typedef struct rcu_percpu |
60 | typedef struct { |
63 | { |
- | |
64 | uint32_t current_batch_number; |
61 | uint32_t current_batch_number; |
65 | uint32_t QS_passed; |
62 | uint32_t QS_passed; |
66 | bool QS_pending; |
63 | bool QS_pending; |
67 | - | ||
68 | rcu_callback_list_t* next_batch, *current_batch, *done_batch; |
64 | rcu_callback_list_t* next_batch, *current_batch, *done_batch; |
69 | } rcu_percpu_t; |
65 | } rcu_percpu_t; |
70 | 66 | ||
71 | rcu_global_t _rcu_global; |
67 | rcu_global_t _rcu_global; |
72 | rcu_percpu_t* _rcu_cpu_lists; |
68 | rcu_percpu_t* _rcu_cpu_lists; |
73 | 69 | ||
74 | void rcu_init(void) |
70 | void rcu_init(void) |
75 | { |
71 | { |
76 | _rcu_cpu_lists = malloc(sizeof(rcu_percpu_t)*config.cpu_count,0); |
72 | _rcu_cpu_lists = malloc(sizeof(rcu_percpu_t)*config.cpu_count,0); |
77 | _rcu_global.completed_batch = -1; |
73 | _rcu_global.completed_batch = -1; |
78 | _rcu_global.current_batch = -1; |
74 | _rcu_global.current_batch = -1; |
79 | _rcu_global.next_batch_waiting = -1; |
75 | _rcu_global.next_batch_waiting = -1; |
80 | - | ||
81 | } |
76 | } |
82 | 77 | ||
83 | void rcu_synchronize(void) |
78 | void rcu_synchronize(void) |
84 | { |
79 | { |
85 | waitq_t wq; |
80 | waitq_t wq; |
86 | waitq_initialize(&wq); |
81 | waitq_initialize(&wq); |
87 | rcu_sync_callback(rcu_synchronize_callback_function, &wq); |
82 | rcu_sync_callback(rcu_synchronize_callback_function, &wq); |
88 | waitq_sleep(&wq); |
83 | waitq_sleep(&wq); |
89 | } |
84 | } |
90 | 85 | ||
91 | void rcu_synchronize_callback_function(void* waitq) |
86 | void rcu_synchronize_callback_function(void* waitq) |
92 | { |
87 | { |
93 | waitq_wakeup(((waitq_t*)waitq), true); |
88 | waitq_wakeup(((waitq_t*)waitq), true); |
94 | } |
89 | } |
95 | 90 | ||
96 | void rcu_sync_callback(void (*func)(void* data), void* data) |
91 | void rcu_sync_callback(void (*func)(void* data), void* data) |
97 | { |
92 | { |
98 | int i; |
93 | int i; |
99 | rcu_callback_list_t *rd; |
94 | rcu_callback_list_t *rd; |
100 | rd = malloc(sizeof(rcu_desc), 0); |
95 | rd = malloc(sizeof(rcu_callback_list_t), 0); |
101 | rd->func = func; |
96 | rd->func = func; |
102 | rd->data = data; |
97 | rd->data = data; |
103 | rd->next = NULL; |
98 | rd->next = NULL; |
104 | 99 | ||
105 | rd->cpu_mask = malloc (sizeof(bool)*config.cpu_count,0); |
100 | rd->cpu_mask = malloc (sizeof(bool)*config.cpu_count,0); |
106 | for (i=0;i<config.cpu_count;i++) |
101 | for (i=0;i<config.cpu_count;i++) |
107 | rd->cpu_mask[i]=false; |
102 | rd->cpu_mask[i]=false; |
108 | 103 | ||
109 | i = ++(_rcu_global.current_batch); |
104 | i = ++(_rcu_global.current_batch); |
110 | _rcu_global.next_batch_waiting = true; |
105 | _rcu_global.next_batch_waiting = true; |
111 | 106 | ||
112 | rd->next = _rcu_cpu_lists[0].next_batch; |
107 | rd->next = _rcu_cpu_lists[0].next_batch; |
113 | for (i=0;i<config.cpu_count;i++) |
108 | for (i=0;i<config.cpu_count;i++) { |
114 | { |
- | |
115 | _rcu_cpu_lists[i].next_batch = rd; |
109 | _rcu_cpu_lists[i].next_batch = rd; |
116 | _rcu_cpu_lists[i].QS_pending = true; |
110 | _rcu_cpu_lists[i].QS_pending = true; |
117 | - | ||
118 | } |
111 | } |
119 | 112 | ||
120 | //TODO:tasklet, after_thread_ran, polishing |
113 | //TODO:tasklet, after_thread_ran, polishing |
121 | } |
114 | } |
122 | 115 | ||
123 | 116 |