1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can
5  * be found in the LICENSE file.
6  *
7  */
8 
9 #pragma once
10 
11 //
12 //
13 //
14 
15 #include "types.h"
16 #include "runtime.h"
17 
18 //
19 // The "ring" is a specialized extent designed to accumulate complete
20 // sequences of commands that are constructed by the host and executed
21 // on the device.
22 //
23 // Note that a sequence of commands is considered to be "complete"
24 // once a checkpoint has been invoked.
25 //
26 // Construction of paths and rasters depends on the checkpointing
27 // feature.
28 //
29 // Note that the ring no longer attempts to account for outstanding
30 // refcounts on the ring and its snaps.  Waiting for snaps to complete
31 // is a responsibility best handled elsewhere and up the stack.
32 //
33 
34 struct skc_extent_ring
35 {
36   struct skc_extent_ring_snap * head;
37   struct skc_extent_ring_snap * last;
38 
39   union {
40     skc_uint2                   rw;
41     struct {
42       skc_uint                  reads;  // number of reads
43       skc_uint                  writes; // number of writes
44     };
45   } outer;
46 
47   union {
48     skc_uint2                   rw;
49     struct {
50       skc_uint                  reads;  // number of reads
51       skc_uint                  writes; // number of writes
52     };
53   } inner;
54 
55   struct {
56     skc_uint                    pow2;   // ring size must be pow2
57     skc_uint                    mask;   // modulo is a mask because size is pow2
58     skc_uint                    snap;   // max elements in a snapshot (not req'd to be pow2)
59     skc_uint                    elem;   // size of element in bytes
60   } size;
61 };
62 
63 //
64 //
65 //
66 
67 void
68 skc_extent_ring_init(struct skc_extent_ring * const ring,
69                      skc_uint                 const size_pow2,
70                      skc_uint                 const size_snap,
71                      skc_uint                 const size_elem);
72 
73 //
74 //
75 //
76 
77 skc_bool
78 skc_extent_ring_rem(struct skc_extent_ring const * const ring);
79 
80 skc_bool
81 skc_extent_ring_is_full(struct skc_extent_ring const * const ring);
82 
83 skc_uint
84 skc_extent_ring_wip_count(struct skc_extent_ring const * const ring);
85 
86 skc_uint
87 skc_extent_ring_wip_rem(struct skc_extent_ring const * const ring);
88 
89 skc_bool
90 skc_extent_ring_wip_is_full(struct skc_extent_ring const * const ring);
91 
92 skc_uint
93 skc_extent_ring_wip_index_inc(struct skc_extent_ring * const ring);
94 
95 //
96 //
97 //
98 
99 void
100 skc_extent_ring_checkpoint(struct skc_extent_ring * const ring);
101 
102 //
103 //
104 //
105 
106 struct skc_extent_ring_snap
107 {
108   struct skc_extent_ring      * ring;   // parent ring
109   struct skc_extent_ring_snap * next;   // next snap
110 
111   skc_uint                      reads;  // number of reads
112   skc_uint                      writes; // number of writes
113 
114   skc_bool                      is_free;
115 
116   skc_subbuf_id_t               id;     // id of host temp suballocation
117 };
118 
119 //
120 // For now, all ring snaps allocations occur in "host temporary"
121 // memory.
122 //
123 
124 struct skc_extent_ring_snap *
125 skc_extent_ring_snap_alloc(struct skc_runtime     * const runtime,
126                            struct skc_extent_ring * const ring);
127 
128 void
129 skc_extent_ring_snap_free(struct skc_runtime          * const runtime,
130                           struct skc_extent_ring_snap * const snap);
131 
132 //
133 //
134 //
135 
136 skc_uint
137 skc_extent_ring_snap_count(struct skc_extent_ring_snap const * const snap);
138 
139 skc_uint
140 skc_extent_ring_snap_from(struct skc_extent_ring_snap const * const snap);
141 
142 skc_uint
143 skc_extent_ring_snap_to(struct skc_extent_ring_snap const * const snap);
144 
145 //
146 //
147 //
148 
149