The ring buffer's information, including read_index, write_index, interrupt_mask, read available, and write available is important for debugging, especially on Azure environment. In order to fill the gap, here use sysctl to print those information.
Some notes about why I choose this implementation:
(1) This implementation considers stats for ring buffers in both channels and sub channels.
(2) Here I used SYSCTL_ADD_PROC instead of SYSCTL_ADD_INT, because read/write available needs calculation dynamically. That cannot be achieved through SYSCTL_ADD_INT.
(3) The values of read_index and write_index change dynamically, so both of them should be captured at the same time in order to avoid getting inconsistent values. That is why I used CTLTYPE_STRING instead of CTLTYPE_INT. Thus, all of those inforamation related to a ring buffer can be captured and print out at a special point.
(4) There is no lock to guarantee 100 percent consistent for read_index and write_index. It is possible to get inconsistent values under high pressure. There is no high accurate requirement on statistic. We just use it to detect whether the communication between VM and host is still working.
The output of sysctl is like:
dev.hn.0.channel.14.out.ring_buffer_stats: r_idx:46600 w_idx:46600 int_mask:0 r_avail:0 w_avail:520192 dev.hn.0.channel.14.in.ring_buffer_stats: r_idx:57744 w_idx:57744 int_mask:0 r_avail:0 w_avail:520192 dev.hvkvp.0.channel.1.out.ring_buffer_stats: r_idx:4456 w_idx:4456 int_mask:0 r_avail:0 w_avail:12288 dev.hvkvp.0.channel.1.in.ring_buffer_stats: r_idx:4456 w_idx:4456 int_mask:0 r_avail:0 w_avail:12288 dev.hvtimesync.0.channel.11.out.ring_buffer_stats: r_idx:4000 w_idx:4000 int_mask:0 r_avail:0 w_avail:12288 dev.hvtimesync.0.channel.11.in.ring_buffer_stats: r_idx:4000 w_idx:4000 int_mask:0 r_avail:0 w_avail:12288 dev.hvshutdown.0.channel.10.out.ring_buffer_stats: r_idx:80 w_idx:80 int_mask:0 r_avail:0 w_avail:12288 dev.hvshutdown.0.channel.10.in.ring_buffer_stats: r_idx:80 w_idx:80 int_mask:0 r_avail:0 w_avail:12288 dev.hvheartbeat.0.channel.8.out.ring_buffer_stats: r_idx:4400 w_idx:4400 int_mask:0 r_avail:0 w_avail:12288 dev.hvheartbeat.0.channel.8.in.ring_buffer_stats: r_idx:4400 w_idx:4400 int_mask:0 r_avail:0 w_avail:12288 dev.storvsc.1.channel.15.sub.1.out.ring_buffer_stats: r_idx:0 w_idx:0 int_mask:0 r_avail:0 w_avail:77824 dev.storvsc.1.channel.15.sub.1.in.ring_buffer_stats: r_idx:0 w_idx:0 int_mask:0 r_avail:0 w_avail:77824 dev.storvsc.1.channel.15.out.ring_buffer_stats: r_idx:664 w_idx:664 int_mask:0 r_avail:0 w_avail:77824 dev.storvsc.1.channel.15.in.ring_buffer_stats: r_idx:616 w_idx:616 int_mask:0 r_avail:0 w_avail:77824 dev.storvsc.0.channel.2.out.ring_buffer_stats: r_idx:15128 w_idx:15128 int_mask:0 r_avail:0 w_avail:77824 dev.storvsc.0.channel.2.in.ring_buffer_stats: r_idx:29800 w_idx:29800 int_mask:0 r_avail:0 w_avail:77824
Submitted by: Hongjiang Zhang <honzhan microsoft com>