Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/hyperv/vmbus/hv_ring_buffer.c
Show All 24 Lines | |||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/types.h> | |||||
#include <sys/sysctl.h> | |||||
#include "hv_vmbus_priv.h" | #include "hv_vmbus_priv.h" | ||||
/* Amount of space to write to */ | /* Amount of space to write to */ | ||||
#define HV_BYTES_AVAIL_TO_WRITE(r, w, z) ((w) >= (r))? \ | #define HV_BYTES_AVAIL_TO_WRITE(r, w, z) ((w) >= (r))? \ | ||||
((z) - ((w) - (r))):((r) - (w)) | ((z) - ((w) - (r))):((r) - (w)) | ||||
SYSCTL_DECL(_hw_hyperv); | |||||
static char rbi_stats[256]; | |||||
sepherosa_gmail.com: You could declare it on the rbi_sysctl_stats() stack, i think 128B should be enough. Use a… | |||||
static int | |||||
rbi_sysctl_stats(SYSCTL_HANDLER_ARGS) | |||||
{ | |||||
hv_vmbus_ring_buffer_info* rbi; | |||||
uint32_t read_index, write_index, interrupt_mask, sz; | |||||
uint32_t read_avail, write_avail; | |||||
rbi = (hv_vmbus_ring_buffer_info*)arg1; | |||||
read_index = rbi->ring_buffer->read_index; | |||||
write_index = rbi->ring_buffer->write_index; | |||||
interrupt_mask = rbi->ring_buffer->interrupt_mask; | |||||
sz = rbi->ring_data_size; | |||||
howard0su_gmail.comUnsubmitted Not Done Inline Actionsdo you consider to acquire lock here to get a stable snapshot? howard0su_gmail.com: do you consider to acquire lock here to get a stable snapshot? | |||||
honzhan_microsoft.comAuthorUnsubmitted Not Done Inline ActionsI do not want to hurt any performance in current stage since we are tuning. If we require it in the future, we can add code to acquire lock here. honzhan_microsoft.com: I do not want to hurt any performance in current stage since we are tuning. If we require it in… | |||||
sepherosa_gmail.comUnsubmitted Not Done Inline ActionsIt's fine, they are just for debugging, _once_ there are issues. sepherosa_gmail.com: It's fine, they are just for debugging, _once_ there are issues. | |||||
write_avail = HV_BYTES_AVAIL_TO_WRITE(read_index, | |||||
write_index, sz); | |||||
read_avail = sz - write_avail; | |||||
snprintf(rbi_stats, sizeof(rbi_stats), | |||||
"r_idx: %d " | |||||
sepherosa_gmail.comUnsubmitted Not Done Inline ActionsI'd suggest to strip the white space between : and %d, so it will look like: So they are much easier to parse in scripts or using other programmatic way. sepherosa_gmail.com: I'd suggest to strip the white space between : and %d, so it will look like:
r_idx:XXX w_idx… | |||||
Not Done Inline ActionsOk. honzhan_microsoft.com: Ok. | |||||
"w_idx: %d " | |||||
"int_mask: %d " | |||||
"r_avail: %d " | |||||
"w_avail: %d", | |||||
read_index, write_index, interrupt_mask, | |||||
read_avail, write_avail); | |||||
return (sysctl_handle_string(oidp, rbi_stats, | |||||
sizeof(rbi_stats), req)); | |||||
} | |||||
#define RBI_SYSCTL_STAT(rbi, ctx, desc, parent, oid) \ | |||||
SYSCTL_ADD_PROC(ctx, parent, OID_AUTO, oid, \ | |||||
CTLTYPE_STRING|CTLFLAG_RD, rbi, 0, \ | |||||
rbi_sysctl_stats, "A", desc) | |||||
void | |||||
ring_buffer_stat(struct sysctl_ctx_list *ctx, | |||||
const char* devname, | |||||
int unit, hv_vmbus_channel* channel) | |||||
{ | |||||
struct sysctl_oid *dev_sysctl, *devunit_sysctl, *devch_sysctl; | |||||
struct sysctl_oid *devch_id_sysctl; | |||||
struct sysctl_oid *devch_id_out_sysctl, *devch_id_in_sysctl; | |||||
char name[16]; | |||||
/* This creates hw.hyperv.DEVNAME tree */ | |||||
dev_sysctl = SYSCTL_ADD_NODE(ctx, SYSCTL_STATIC_CHILDREN(_hw_hyperv), | |||||
OID_AUTO, devname, CTLFLAG_RD, 0, ""); | |||||
/* This creates hw.hyperv.DEVNAME.DEVUNIT tree */ | |||||
snprintf(name, sizeof(name), "%d", unit); | |||||
devunit_sysctl = SYSCTL_ADD_NODE(ctx, | |||||
SYSCTL_CHILDREN(dev_sysctl), | |||||
OID_AUTO, name, CTLFLAG_RD, 0, ""); | |||||
/* This creates hw.hyperv.DEVNAME.DEVUNIT.channel tree */ | |||||
devch_sysctl = SYSCTL_ADD_NODE(ctx, | |||||
SYSCTL_CHILDREN(devunit_sysctl), | |||||
OID_AUTO, "channel", CTLFLAG_RD, 0, ""); | |||||
/* This creates hw.hyperv.DEVNAME.DEVUNIT.channel.CHANID tree */ | |||||
snprintf(name, sizeof(name), "%d", channel->offer_msg.child_rel_id); | |||||
devch_id_sysctl = SYSCTL_ADD_NODE(ctx, | |||||
SYSCTL_CHILDREN(devch_sysctl), | |||||
OID_AUTO, name, CTLFLAG_RD, 0, ""); | |||||
devch_id_out_sysctl = SYSCTL_ADD_NODE(ctx, | |||||
SYSCTL_CHILDREN(devch_id_sysctl), | |||||
OID_AUTO, "out", CTLFLAG_RD, 0, ""); | |||||
devch_id_in_sysctl = SYSCTL_ADD_NODE(ctx, | |||||
SYSCTL_CHILDREN(devch_id_sysctl), | |||||
OID_AUTO, "in", CTLFLAG_RD, 0, ""); | |||||
RBI_SYSCTL_STAT(&(channel->outbound), ctx, | |||||
"outbound ring buffer stats", | |||||
SYSCTL_CHILDREN(devch_id_out_sysctl), | |||||
"ring_buffer_stats"); | |||||
RBI_SYSCTL_STAT(&(channel->inbound), ctx, | |||||
"inbound ring buffer stats", | |||||
SYSCTL_CHILDREN(devch_id_in_sysctl), | |||||
"ring_buffer_stats"); | |||||
} | |||||
/** | /** | ||||
* @brief Get number of bytes available to read and to write to | * @brief Get number of bytes available to read and to write to | ||||
* for the specified ring buffer | * for the specified ring buffer | ||||
*/ | */ | ||||
static inline void | static inline void | ||||
get_ring_buffer_avail_bytes( | get_ring_buffer_avail_bytes( | ||||
hv_vmbus_ring_buffer_info* rbi, | hv_vmbus_ring_buffer_info* rbi, | ||||
▲ Show 20 Lines • Show All 464 Lines • Show Last 20 Lines |
You could declare it on the rbi_sysctl_stats() stack, i think 128B should be enough. Use a global variable like this is calling for trouble later.