Subversion Repositories HelenOS

Rev

Rev 2265 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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>
  40. #include <ddi/tasklet.h>
  41. #include <synch/spinlock.h>
  42. #include <time/delay.h>
  43. #include <panic.h>
  44. #include <print.h>
  45.  
  46. typedef struct rcu_global
  47. {
  48.     uint32_t current_batch;
  49.     uint32_t completed_batch;
  50.     bool next_batch_waiting;
  51. } rcu_global_t;
  52.  
  53. typedef struct rcu_callback_list
  54. {
  55. struct rcu_callback_list* next;
  56. void (*func)(void*);
  57. void* data;
  58. bool* cpu_mask;
  59. } rcu_callback_list_t;
  60.  
  61.  
  62. typedef struct rcu_percpu
  63. {
  64.     uint32_t current_batch_number;
  65.     uint32_t QS_passed;
  66.     bool QS_pending;
  67.  
  68. rcu_callback_list_t* next_batch, *current_batch, *done_batch;
  69. } rcu_percpu_t;
  70.  
  71. rcu_global_t _rcu_global;
  72. rcu_percpu_t* _rcu_cpu_lists;
  73.  
  74. void rcu_init(void)
  75. {
  76.     _rcu_cpu_lists = malloc(sizeof(rcu_percpu_t)*config.cpu_count,0);
  77.     _rcu_global.completed_batch = -1;
  78.     _rcu_global.current_batch = -1;
  79.     _rcu_global.next_batch_waiting = -1;
  80.  
  81. }
  82.  
  83. void rcu_synchronize(void)
  84. {
  85.     waitq_t wq;
  86.     waitq_initialize(&wq);
  87.     rcu_sync_callback(rcu_synchronize_callback_function, &wq);
  88.     waitq_sleep(&wq);
  89. }
  90.  
  91. void rcu_synchronize_callback_function(void* waitq)
  92. {
  93.     waitq_wakeup(((waitq_t*)waitq), true);
  94. }
  95.  
  96. void rcu_sync_callback(void (*func)(void* data), void* data)
  97. {
  98.     int i;
  99.     rcu_callback_list_t *rd;
  100.     rd = malloc(sizeof(rcu_desc), 0);
  101.     rd->func = func;
  102.     rd->data = data;
  103.     rd->next = NULL;
  104.  
  105.     rd->cpu_mask = malloc (sizeof(bool)*config.cpu_count,0);
  106.     for (i=0;i<config.cpu_count;i++)
  107.         rd->cpu_mask[i]=false;
  108.    
  109.     i = ++(_rcu_global.current_batch);
  110.     _rcu_global.next_batch_waiting = true;
  111.  
  112.     rd->next = _rcu_cpu_lists[0].next_batch;
  113.     for (i=0;i<config.cpu_count;i++)
  114.     {
  115.         _rcu_cpu_lists[i].next_batch = rd;
  116.         _rcu_cpu_lists[i].QS_pending = true;
  117.  
  118.     }
  119.  
  120.     //TODO:tasklet, after_thread_ran, polishing
  121. }
  122.  
  123.