Re: [PATCH bpf-next v2 3/5] nbd: add tracepoints for send/receive timing

From: Josef Bacik
Date: Sat Apr 06 2019 - 20:14:03 EST


On Fri, Apr 05, 2019 at 04:55:04PM -0700, Matt Mullins wrote:
> From: Andrew Hall <hall@xxxxxx>
>
> This adds four tracepoints to nbd, enabling separate tracing of payload
> and header sending/receipt.
>
> In the send path for headers that have already been sent, we also
> explicitly initialize the handle so it can be referenced by the later
> tracepoint.
>
> Signed-off-by: Andrew Hall <hall@xxxxxx>
> Signed-off-by: Matt Mullins <mmullins@xxxxxx>
> ---
> drivers/block/nbd.c | 8 ++++
> include/trace/events/nbd.h | 92 ++++++++++++++++++++++++++++++++++++++
> 2 files changed, 100 insertions(+)
>
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index 7393d04d255c..d3d914620f66 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -513,6 +513,10 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
> if (sent) {
> if (sent >= sizeof(request)) {
> skip = sent - sizeof(request);
> +
> + // initialize handle for tracing purposes
> + handle = nbd_cmd_handle(cmd);
> +

Don't use c++ style commenting.

> goto send_pages;
> }
> iov_iter_advance(&from, sent);
> @@ -536,6 +540,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
> (unsigned long long)blk_rq_pos(req) << 9, blk_rq_bytes(req));
> result = sock_xmit(nbd, index, 1, &from,
> (type == NBD_CMD_WRITE) ? MSG_MORE : 0, &sent);
> + trace_nbd_header_sent(req, handle);
> if (result <= 0) {
> if (was_interrupted(result)) {
> /* If we havne't sent anything we can just return BUSY,
> @@ -608,6 +613,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
> bio = next;
> }
> out:
> + trace_nbd_payload_sent(req, handle);
> nsock->pending = NULL;
> nsock->sent = 0;
> return 0;
> @@ -655,6 +661,7 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index)
> tag, req);
> return ERR_PTR(-ENOENT);
> }
> + trace_nbd_header_received(req, handle);
> cmd = blk_mq_rq_to_pdu(req);
>
> mutex_lock(&cmd->lock);
> @@ -708,6 +715,7 @@ static struct nbd_cmd *nbd_read_stat(struct nbd_device *nbd, int index)
> }
> }
> out:
> + trace_nbd_payload_received(req, handle);
> mutex_unlock(&cmd->lock);
> return ret ? ERR_PTR(ret) : cmd;
> }
> diff --git a/include/trace/events/nbd.h b/include/trace/events/nbd.h
> index 5928255ed02e..eef476fef95a 100644
> --- a/include/trace/events/nbd.h
> +++ b/include/trace/events/nbd.h
> @@ -7,6 +7,98 @@
>
> #include <linux/tracepoint.h>
>
> +TRACE_EVENT(nbd_header_sent,
> +
> + TP_PROTO(struct request *req, u64 handle),
> +
> + TP_ARGS(req, handle),
> +
> + TP_STRUCT__entry(
> + __field(struct request *, req)
> + __field(u64, handle)
> + ),
> +
> + TP_fast_assign(
> + __entry->req = req;
> + __entry->handle = handle;
> + ),
> +
> + TP_printk(
> + "nbd header sent: request %p, handle 0x%016llx",
> + __entry->req,
> + __entry->handle
> + )
> +);
> +

These are all the same, use DECLARE_EVENT_CLASS() and then just DEFINE_EVENT()
for each individual event. Also no pointers, we don't want to leak pointers to
userspace for stuff. Thanks,

Josef