MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vmbus_txbr_write

Function vmbus_txbr_write

dpdk/drivers/bus/vmbus/vmbus_bufring.c:109–170  ·  view source on GitHub ↗

* Write scattered channel packet to TX bufring. * * The offset of this channel packet is written as a 64bits value * immediately after this channel packet. * * The write goes through three stages: * 1. Reserve space in ring buffer for the new data. * Writer atomically moves priv_write_index. * 2. Copy the new data into the ring. * 3. Update the tail of the ring (visible to host) th

Source from the content-addressed store, hash-verified

107 * next read location. Writer updates write_index
108 */
109int
110vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
111 bool *need_sig)
112{
113 struct vmbus_bufring *vbr = tbr->vbr;
114 uint32_t ring_size = tbr->dsize;
115 uint32_t old_windex, next_windex, windex, total;
116 uint64_t save_windex;
117 int i;
118
119 total = 0;
120 for (i = 0; i < iovlen; i++)
121 total += iov[i].iov_len;
122 total += sizeof(save_windex);
123
124 /* Reserve space in ring */
125 do {
126 uint32_t avail;
127
128 /* Get current free location */
129 old_windex = tbr->windex;
130
131 /* Prevent compiler reordering this with calculation */
132 rte_compiler_barrier();
133
134 avail = vmbus_br_availwrite(tbr, old_windex);
135
136 /* If not enough space in ring, then tell caller. */
137 if (avail <= total)
138 return -EAGAIN;
139
140 next_windex = vmbus_br_idxinc(old_windex, total, ring_size);
141
142 /* Atomic update of next write_index for other threads */
143 } while (!rte_atomic32_cmpset(&tbr->windex, old_windex, next_windex));
144
145 /* Space from old..new is now reserved */
146 windex = old_windex;
147 for (i = 0; i < iovlen; i++) {
148 windex = vmbus_txbr_copyto(tbr, windex,
149 iov[i].iov_base, iov[i].iov_len);
150 }
151
152 /* Set the offset of the current channel packet. */
153 save_windex = ((uint64_t)old_windex) << 32;
154 windex = vmbus_txbr_copyto(tbr, windex, &save_windex,
155 sizeof(save_windex));
156
157 /* The region reserved should match region used */
158 RTE_ASSERT(windex == next_windex);
159
160 /* Ensure that data is available before updating host index */
161 rte_smp_wmb();
162
163 /* Checkin for our reservation. wait for our turn to update host */
164 while (!rte_atomic32_cmpset(&vbr->windex, old_windex, next_windex))
165 rte_pause();
166

Callers 2

rte_vmbus_chan_sendFunction · 0.85

Calls 6

vmbus_br_availwriteFunction · 0.85
vmbus_br_idxincFunction · 0.85
vmbus_txbr_copytoFunction · 0.85
vmbus_txbr_need_signalFunction · 0.85
rte_atomic32_cmpsetFunction · 0.50
rte_pauseFunction · 0.50

Tested by

no test coverage detected