Subversion Repositories HelenOS

Rev

Rev 2260 | Rev 2309 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2260 hudecek 1
/*
2
 * Copyright (c) 2007 Jan Hudecek
3
 * Copyright (c) 2006 Jakub Jermar
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
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
16
 *   derived from this software without specific prior written permission.
17
 *
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
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
29
/** @addtogroup sync
30
 * @{
31
 */
32
/** @file
33
 */
34
 
35
#include <synch/rcu.h>
36
#include <synch/waitq.h>
37
#include <arch.h>
38
#include <config.h>
39
#include <arch/types.h>
2265 hudecek 40
#include <proc/tasklet.h>
2260 hudecek 41
#include <synch/spinlock.h>
42
#include <time/delay.h>
43
#include <panic.h>
44
#include <print.h>
45
 
2265 hudecek 46
typedef struct  {
2260 hudecek 47
    uint32_t current_batch;
48
    uint32_t completed_batch;
49
    bool next_batch_waiting;
50
} rcu_global_t;
51
 
2265 hudecek 52
typedef struct rcu_callback_list {
53
    struct rcu_callback_list* next;
54
    void (*func)(void*);
55
    void* data;
56
    bool* cpu_mask;
2260 hudecek 57
} rcu_callback_list_t;
58
 
59
 
2265 hudecek 60
typedef struct {
2260 hudecek 61
    uint32_t current_batch_number;
62
    uint32_t QS_passed;
63
    bool QS_pending;
2265 hudecek 64
    rcu_callback_list_t* next_batch, *current_batch, *done_batch;
2260 hudecek 65
} rcu_percpu_t;
66
 
67
rcu_global_t _rcu_global;
68
rcu_percpu_t* _rcu_cpu_lists;
69
 
2265 hudecek 70
void rcu_init(void)
2260 hudecek 71
{
72
    _rcu_cpu_lists = malloc(sizeof(rcu_percpu_t)*config.cpu_count,0);
73
    _rcu_global.completed_batch = -1;
74
    _rcu_global.current_batch = -1;
75
    _rcu_global.next_batch_waiting = -1;
76
}
77
 
78
void rcu_synchronize(void)
79
{
80
    waitq_t wq;
81
    waitq_initialize(&wq);
82
    rcu_sync_callback(rcu_synchronize_callback_function, &wq);
83
    waitq_sleep(&wq);
84
}
85
 
86
void rcu_synchronize_callback_function(void* waitq)
87
{
88
    waitq_wakeup(((waitq_t*)waitq), true);
89
}
90
 
91
void rcu_sync_callback(void (*func)(void* data), void* data)
92
{
93
    int i;
94
    rcu_callback_list_t *rd;
2265 hudecek 95
    rd = malloc(sizeof(rcu_callback_list_t), 0);
2260 hudecek 96
    rd->func = func;
97
    rd->data = data;
98
    rd->next = NULL;
99
 
100
    rd->cpu_mask = malloc (sizeof(bool)*config.cpu_count,0);
101
    for (i=0;i<config.cpu_count;i++)
102
        rd->cpu_mask[i]=false;
103
 
104
    i = ++(_rcu_global.current_batch);
105
    _rcu_global.next_batch_waiting = true;
106
 
107
    rd->next = _rcu_cpu_lists[0].next_batch;
2265 hudecek 108
    for (i=0;i<config.cpu_count;i++) {
2260 hudecek 109
        _rcu_cpu_lists[i].next_batch = rd;
110
        _rcu_cpu_lists[i].QS_pending = true;
111
    }
112
 
113
    //TODO:tasklet, after_thread_ran, polishing
114
}
115