This source file includes following definitions.
- i915_globals_shrink
- __i915_globals_park
- i915_global_register
- __i915_globals_cleanup
- i915_globals_init
- i915_globals_park
- i915_globals_unpark
- i915_globals_exit
1
2
3
4
5
6
7 #include <linux/slab.h>
8 #include <linux/workqueue.h>
9
10 #include "i915_active.h"
11 #include "gem/i915_gem_context.h"
12 #include "gem/i915_gem_object.h"
13 #include "i915_globals.h"
14 #include "i915_request.h"
15 #include "i915_scheduler.h"
16 #include "i915_vma.h"
17
18 static LIST_HEAD(globals);
19
20 static atomic_t active;
21 static atomic_t epoch;
22 static struct park_work {
23 struct rcu_work work;
24 int epoch;
25 } park;
26
27 static void i915_globals_shrink(void)
28 {
29 struct i915_global *global;
30
31
32
33
34
35
36 list_for_each_entry(global, &globals, link)
37 global->shrink();
38 }
39
40 static void __i915_globals_park(struct work_struct *work)
41 {
42
43 if (park.epoch == atomic_read(&epoch))
44 i915_globals_shrink();
45 }
46
47 void __init i915_global_register(struct i915_global *global)
48 {
49 GEM_BUG_ON(!global->shrink);
50 GEM_BUG_ON(!global->exit);
51
52 list_add_tail(&global->link, &globals);
53 }
54
55 static void __i915_globals_cleanup(void)
56 {
57 struct i915_global *global, *next;
58
59 list_for_each_entry_safe_reverse(global, next, &globals, link)
60 global->exit();
61 }
62
63 static __initconst int (* const initfn[])(void) = {
64 i915_global_active_init,
65 i915_global_buddy_init,
66 i915_global_context_init,
67 i915_global_gem_context_init,
68 i915_global_objects_init,
69 i915_global_request_init,
70 i915_global_scheduler_init,
71 i915_global_vma_init,
72 };
73
74 int __init i915_globals_init(void)
75 {
76 int i;
77
78 for (i = 0; i < ARRAY_SIZE(initfn); i++) {
79 int err;
80
81 err = initfn[i]();
82 if (err) {
83 __i915_globals_cleanup();
84 return err;
85 }
86 }
87
88 INIT_RCU_WORK(&park.work, __i915_globals_park);
89 return 0;
90 }
91
92 void i915_globals_park(void)
93 {
94
95
96
97
98
99
100
101
102
103 if (!atomic_dec_and_test(&active))
104 return;
105
106 park.epoch = atomic_inc_return(&epoch);
107 queue_rcu_work(system_wq, &park.work);
108 }
109
110 void i915_globals_unpark(void)
111 {
112 atomic_inc(&epoch);
113 atomic_inc(&active);
114 }
115
116 void __exit i915_globals_exit(void)
117 {
118
119 atomic_inc(&epoch);
120 flush_rcu_work(&park.work);
121
122 __i915_globals_cleanup();
123
124
125 rcu_barrier();
126 }