Re: [PATCH 3/8] ntb_perf: Return results by reading the run file

From: Jiang, Dave
Date: Mon Jun 13 2016 - 16:10:15 EST


On Fri, 2016-06-10 at 16:54 -0600, Logan Gunthorpe wrote:
> Instead of having to watch logs, allow the results to be retrieved
> by reading back the run file. This file will return "running" when
> the test is running and nothing if no tests have been run yet.
> It returns 1 line per thread, and will display an error message if
> the
> corresponding thread returns an error.
>
> With the above change, the pr_info calls that returned the results
> are
> then changed to pr_debug calls.
>
> Signed-off-by: Logan Gunthorpe <logang@xxxxxxxxxxxx>
Acked-by: Dave Jiang <dave.jiang@xxxxxxxxx>

> ---
> Âdrivers/ntb/test/ntb_perf.c | 67
> +++++++++++++++++++++++++++++++++++++--------
> Â1 file changed, 55 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/ntb/test/ntb_perf.c
> b/drivers/ntb/test/ntb_perf.c
> index db4dc61..05a8705 100644
> --- a/drivers/ntb/test/ntb_perf.c
> +++ b/drivers/ntb/test/ntb_perf.c
> @@ -123,6 +123,9 @@ struct pthr_ctx {
> Â int src_idx;
> Â void *srcs[MAX_SRCS];
> Â wait_queue_head_tÂÂÂÂÂÂÂ*wq;
> + int status;
> + u64 copied;
> + u64 diff_us;
> Â};
> Â
> Âstruct perf_ctx {
> @@ -305,7 +308,7 @@ static int perf_move_data(struct pthr_ctx *pctx,
> char __iomem *dst, char *src,
> Â }
> Â
> Â if (use_dma) {
> - pr_info("%s: All DMA descriptors submitted\n",
> current->comm);
> + pr_debug("%s: All DMA descriptors submitted\n",
> current->comm);
> Â while (atomic_read(&pctx->dma_sync) != 0) {
> Â if (kthread_should_stop())
> Â break;
> @@ -317,13 +320,16 @@ static int perf_move_data(struct pthr_ctx
> *pctx, char __iomem *dst, char *src,
> Â kdiff = ktime_sub(kstop, kstart);
> Â diff_us = ktime_to_us(kdiff);
> Â
> - pr_info("%s: copied %llu bytes\n", current->comm, copied);
> + pr_debug("%s: copied %llu bytes\n", current->comm, copied);
> Â
> - pr_info("%s: lasted %llu usecs\n", current->comm, diff_us);
> + pr_debug("%s: lasted %llu usecs\n", current->comm, diff_us);
> Â
> Â perf = div64_u64(copied, diff_us);
> Â
> - pr_info("%s: MBytes/s: %llu\n", current->comm, perf);
> + pr_debug("%s: MBytes/s: %llu\n", current->comm, perf);
> +
> + pctx->copied = copied;
> + pctx->diff_us = diff_us;
> Â
> Â return 0;
> Â}
> @@ -345,7 +351,7 @@ static int ntb_perf_thread(void *data)
> Â int rc, node, i;
> Â struct dma_chan *dma_chan = NULL;
> Â
> - pr_info("kthread %s starting...\n", current->comm);
> + pr_debug("kthread %s starting...\n", current->comm);
> Â
> Â node = dev_to_node(&pdev->dev);
> Â
> @@ -575,19 +581,44 @@ static ssize_t debugfs_run_read(struct file
> *filp, char __user *ubuf,
> Â{
> Â struct perf_ctx *perf = filp->private_data;
> Â char *buf;
> - ssize_t ret, out_offset;
> - int running;
> + ssize_t ret, out_off = 0;
> + struct pthr_ctx *pctx;
> + int i;
> + u64 rate;
> Â
> Â if (!perf)
> Â return 0;
> Â
> - buf = kmalloc(64, GFP_KERNEL);
> + buf = kmalloc(1024, GFP_KERNEL);
> Â if (!buf)
> Â return -ENOMEM;
> Â
> - running = mutex_is_locked(&perf->run_mutex);
> - out_offset = snprintf(buf, 64, "%d\n", running);
> - ret = simple_read_from_buffer(ubuf, count, offp, buf,
> out_offset);
> + if (mutex_is_locked(&perf->run_mutex)) {
> + out_off = snprintf(buf, 64, "running\n");
> + goto read_from_buf;
> + }
> +
> + for (i = 0; i < MAX_THREADS; i++) {
> + pctx = &perf->pthr_ctx[i];
> +
> + if (pctx->status == -ENODATA)
> + break;
> +
> + if (pctx->status) {
> + out_off += snprintf(buf + out_off, 1024 -
> out_off,
> + ÂÂÂÂ"%d: error %d\n", i,
> + ÂÂÂÂpctx->status);
> + continue;
> + }
> +
> + rate = div64_u64(pctx->copied, pctx->diff_us);
> + out_off += snprintf(buf + out_off, 1024 - out_off,
> + "%d: copied %llu bytes in %llu usecs, %llu
> MBytes/s\n",
> + i, pctx->copied, pctx->diff_us, rate);
> + }
> +
> +read_from_buf:
> + ret = simple_read_from_buffer(ubuf, count, offp, buf,
> out_off);
> Â kfree(buf);
> Â
> Â return ret;
> @@ -601,12 +632,20 @@ static void threads_cleanup(struct perf_ctx
> *perf)
> Â for (i = 0; i < MAX_THREADS; i++) {
> Â pctx = &perf->pthr_ctx[i];
> Â if (pctx->thread) {
> - kthread_stop(pctx->thread);
> + pctx->status = kthread_stop(pctx->thread);
> Â pctx->thread = NULL;
> Â }
> Â }
> Â}
> Â
> +static void perf_clear_thread_status(struct perf_ctx *perf)
> +{
> + int i;
> +
> + for (i = 0; i < MAX_THREADS; i++)
> + perf->pthr_ctx[i].status = -ENODATA;
> +}
> +
> Âstatic ssize_t debugfs_run_write(struct file *filp, const char
> __user *ubuf,
> Â Âsize_t count, loff_t *offp)
> Â{
> @@ -623,6 +662,8 @@ static ssize_t debugfs_run_write(struct file
> *filp, const char __user *ubuf,
> Â if (!mutex_trylock(&perf->run_mutex))
> Â return -EBUSY;
> Â
> + perf_clear_thread_status(perf);
> +
> Â if (perf->perf_threads > MAX_THREADS) {
> Â perf->perf_threads = MAX_THREADS;
> Â pr_info("Reset total threads to: %u\n",
> MAX_THREADS);
> @@ -757,6 +798,8 @@ static int perf_probe(struct ntb_client *client,
> struct ntb_dev *ntb)
> Â if (rc)
> Â goto err_ctx;
> Â
> + perf_clear_thread_status(perf);
> +
> Â return 0;
> Â
> Âerr_ctx:
> --Â
> 2.1.4
>