ktest: Add minor fixes for kernel tests
[akaros.git] / kern / include / rcu.h
1 /* Copyright (c) 2018 Google Inc
2  * Barret Rhoden <brho@cs.berkeley.edu>
3  * See LICENSE for details.
4  *
5  * RCU.  See rcu.c for notes.
6  */
7
8 #pragma once
9
10 #include <arch/membar.h>
11 #include <arch/topology.h>
12 #include <percpu.h>
13 #include <list.h>
14
15 struct rcu_head;
16 typedef void (*rcu_callback_t)(struct rcu_head *head);
17 typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func);
18
19 struct rcu_head {
20         struct list_head                        link;
21         rcu_callback_t                          func;
22         unsigned long                           gpnum;
23 };
24
25 #include <rcupdate.h>
26
27 /* This is a little nasty.  We can't undef it, since NUM_RCU_NODES is used in a
28  * few places.  We could get this from Kconfig, like Linux does. */
29 #define NR_CPUS 4096
30
31 #include <rcu_helper.h>
32 #include <rculist.h>
33 #include <rendez.h>
34
35 struct rcu_node {
36         struct rcu_node                         *parent;
37         unsigned long                           qsmask; /* cores that need to check in */
38         unsigned long                           qsmaskinit;
39         unsigned int                            level;
40         unsigned int                            grplo;  /* lowest nr CPU here */
41         unsigned int                            grphi;  /* highest nr CPU here */
42         unsigned int                            grpnum; /* our number in our parent */
43         unsigned long                           grpmask;/* our bit in our parent */
44 };
45
46 struct rcu_state {
47         struct rcu_node                         node[NUM_RCU_NODES];
48         struct rcu_node                         *level[RCU_NUM_LVLS];
49
50         /* These are read by everyone but only written by the GP kthread */
51         unsigned long                           gpnum;
52         unsigned long                           completed;
53
54         /* These are written by anyone trying to wake the gp kthread, which can be
55          * any core whose CB list is long or does an rcu_barrier() */
56         /* TODO: make a ktask struct and use a read-only pointer. */
57         struct rendez                           gp_ktask_rv;
58         int                                                     gp_ktask_ctl;
59 };
60
61 struct rcu_pcpui {
62         struct rcu_state                        *rsp;
63         struct rcu_node                         *my_node;
64         int                                                     coreid;
65         unsigned int                            grpnum;
66         unsigned long                           grpmask;
67         bool                                            booted;
68
69         spinlock_t                                      lock;
70         struct list_head                        cbs;
71         unsigned int                            nr_cbs;
72         unsigned long                           gp_acked;
73
74         struct rendez                           mgmt_ktask_rv;
75         int                                                     mgmt_ktask_ctl;
76 };
77 DECLARE_PERCPU(struct rcu_pcpui, rcu_pcpui);
78
79 void rcu_init(void);
80 void rcu_report_qs(void);
81 void rcu_barrier(void);
82 void rcu_force_quiescent_state(void);
83 unsigned long get_state_synchronize_rcu(void);
84 void cond_synchronize_rcu(unsigned long oldstate);
85 void kfree_call_rcu(struct rcu_head *head, rcu_callback_t off);
86
87 /* Internal Helpers (rcu.c) */
88 void rcu_init_pcpui(struct rcu_state *rsp, struct rcu_pcpui *rpi, int coreid);
89
90 /* Internal Helpers (rcu_tree_helper.c) */
91 void rcu_init_one(struct rcu_state *rsp);
92 void rcu_init_geometry(void);
93 void rcu_dump_rcu_node_tree(struct rcu_state *rsp);