DPDK patches and discussions
 help / color / mirror / Atom feed
From: Olivier Matz <olivier.matz@6wind.com>
To: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Cc: dev@dpdk.org, Keith Wiles <keith.wiles@intel.com>,
	Jingjing Wu <jingjing.wu@intel.com>,
	Thomas Monjalon <thomas@monjalon.net>,
	Ferruh Yigit <ferruh.yigit@intel.com>,
	Jim Thompson <jim@netgate.com>,
	Anatoly Burakov <anatoly.burakov@intel.com>
Subject: Re: [dpdk-dev] [PATCH v2] cmdline: rework as a wrapper to libedit
Date: Tue, 26 Jun 2018 15:21:21 +0200	[thread overview]
Message-ID: <20180626132121.6qm3m3mx2ubkxyn3@platinum> (raw)
In-Reply-To: <20180419151155.5680-1-adrien.mazarguil@6wind.com>

Hi Adrien,

Better late than never, please find below some comments
about your patch.

On Thu, Apr 19, 2018 at 05:13:53PM +0200, Adrien Mazarguil wrote:
> Disclaimer: this patch must not be confused with the CLI library [1]
> (work in progress) that will eventually supersede librte_cmdline itself
> with a different API.
> 
> Rather, it modifies librte_cmdline to delegate all the heavy lifting
> (terminal and history handling), strips unused features and re-implements
> what remains of its public API as a wrapper to the editline library (also
> known as libedit) [2], a well-known, BSD-licensed and widely available
> library used by many projects which does everything needed and more [3].
> 
> This approach was chosen because converting librte_cmdline as a wrapper to
> a more capable library was easier and faster than addressing its
> shortcomings and results in much less code to maintain in DPDK.
> 
> It also provides a drop-in solution for applications that rely on
> librte_cmdline. They benefit from greatly improved command line handling
> without a meaningful impact on their code base.
> 
> The main motivation behind this patch is testpmd's flow (rte_flow) command,
> which requires support for dynamic tokens and very long lines that must be
> broken down when displayed. This is not supported by librte_cmdline's
> limited terminal handling capabilities, resulting in a rather frustrating
> user experience.
> 
> It had to be addressed given the importance of testpmd as one of the
> primary tool used by PMD developers.
> 
> This rework results in the following changes:
> 
> - Removed circular buffer management interface for command history
>   (cmdline_cirbuf.c), command history being handled by libedit.
> - Removed raw command-line interpreter (cmdline_rdline.c).
> - Removed raw terminal handler (cmdline_vt100.c).
> - Removed all test/example code for the above.
> - Re-implemented high level interactive and non-interactive command-line
>   handlers (cmdline.c and cmdline_socket.c) on top of libedit using its
>   native interface, not its readline compatibility layer.
> - Made struct cmdline opaque so that applications relying on librte_cmdline
>   do not need to include any libedit headers.
> - Applications do not need to include cmdline_rdline.h anymore.
> - Terminal resizing is now automatically handled.
> - New external dependency for applications relying on librte_cmdline.
> - Major version bump due to the ABI impact of these changes.
> 
> [1] http://dpdk.org/browse/draft/dpdk-draft-cli/
> [2] http://thrysoee.dk/editline/
> [3] http://netbsd.gw.com/cgi-bin/man-cgi?editline++NetBSD-current
> 
> Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> Cc: Olivier Matz <olivier.matz@6wind.com>
> Cc: Keith Wiles <keith.wiles@intel.com>
> Cc: Jingjing Wu <jingjing.wu@intel.com>
> Cc: Thomas Monjalon <thomas@monjalon.net>
> Cc: Ferruh Yigit <ferruh.yigit@intel.com>
> Cc: Jim Thompson <jim@netgate.com>
> Cc: Anatoly Burakov <anatoly.burakov@intel.com>
> 
> --
> 
> v2 changes:
> 
> - Replaced an instance of snprintf() with rte_strlcpy() [5].
> - Rebased patch.
> 
> [5] http://dpdk.org/ml/archives/dev/2018-April/097721.html
> 
> v1 changes:
> 
> No fundamental change since the original RFC [4], except it's been rebased
> several times and Meson build support was added in the meantime. Commit log
> was also shortened a bit.
> 
> I'm re-sending this because I think it's useful, at least to me (duh). As
> the maintainer of rte_flow, I spend most of my time typing flow commands in
> testpmd and libedit makes that a pleasant experience.
> 
> Try it out! And don't hesitate to send your acked-by line to get this in
> time for 18.05 :)
> 
> [4] http://dpdk.org/ml/archives/dev/2017-November/081605.html

Re-saying what I said the first time: I think this is a very good
improvement, removing lots of dpdk code that is better implemented in
well-known libraries.


The compilation with shared libraries fail. Please try for instance:
./devtools/test-build.sh -j4 x86_64-native-linuxapp-clang+shared+debug

I suggest to add in lib/librte_cmdline/Makefile:

  LDLIBS += $(shell pkg-config --libs libedit)


I also think something should be added in
/doc/guides/linux_gsg/sys_reqs.rst to highlight the new build
dependency.


I noticed a bad behavior change (in addition to many good ones):
ctrl-c now quits the application, and this was not the case before.
I often use ctrl-c to delete the line I'm currently editing. Please
see at the end a proposition to restore this feature.


Finally, the patch removes some functions, so it should be announced
with a deprecation notice.


[...]

> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index 0b442c3a6..6b4d9dbfd 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -48,7 +48,6 @@
>  #include <rte_flow.h>
>  #include <rte_gro.h>
>  
> -#include <cmdline_rdline.h>
>  #include <cmdline_parse.h>
>  #include <cmdline_parse_num.h>
>  #include <cmdline_parse_string.h>

FYI, after rebase, same hunk is also required in
examples/vhost_crypto/main.c

[...]

> diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
> index 591b78b0f..1c45cd9ff 100644
> --- a/lib/librte_cmdline/cmdline.c
> +++ b/lib/librte_cmdline/cmdline.c
> @@ -4,79 +4,183 @@
>   * All rights reserved.
>   */
>  
> +#include <ctype.h>
> +#include <histedit.h>

histedit.h would be better after system includes.


[...]

> @@ -207,48 +317,49 @@ cmdline_poll(struct cmdline *cl)
>  {
>  	struct pollfd pfd;
>  	int status;
> -	ssize_t read_status;
> -	char c;
> +	int read_status;
> +	int flags;
>  
>  	if (!cl)
>  		return -EINVAL;
> -	else if (cl->rdl.status == RDLINE_EXITED)
> +	else if (cl->error)
> +		return RDLINE_ERROR;
> +	else if (cl->eof)
>  		return RDLINE_EXITED;
>  
> -	pfd.fd = cl->s_in;
> +	pfd.fd = fileno(cl->f_in);
>  	pfd.events = POLLIN;
>  	pfd.revents = 0;
>  
>  	status = poll(&pfd, 1, 0);
>  	if (status < 0)
> -		return status;
> -	else if (status > 0) {
> -		c = -1;
> -		read_status = read(cl->s_in, &c, 1);
> -		if (read_status < 0)
> -			return read_status;
> -
> -		status = cmdline_in(cl, &c, 1);
> -		if (status < 0 && cl->rdl.status != RDLINE_EXITED)
> -			return status;
> -	}
> -
> -	return cl->rdl.status;
> +		return RDLINE_ERROR;
> +	if (!status)
> +		return RDLINE_RUNNING;
> +	flags = fcntl(pfd.fd, F_GETFL);
> +	if (!(flags & O_NONBLOCK))
> +		fcntl(pfd.fd, F_SETFL, flags | O_NONBLOCK);

We just checked that fd is readable, what is the purpose of
adding the O_NONBLOCK flag?


> +	if (!el_gets(cl->el, &read_status) && read_status == -1)
> +		cl->error = 1;

Either from documentation or libedit code, I don't think it is
possible that read_status is set to -1. Am I missing something?


> +	if (!(flags & O_NONBLOCK))
> +		fcntl(pfd.fd, F_SETFL, flags);
> +	return cl->error ? RDLINE_ERROR :
> +		cl->eof ? RDLINE_EXITED :
> +		RDLINE_RUNNING;
>  }
>  
>  void
>  cmdline_interact(struct cmdline *cl)
>  {
> -	char c;
> -
>  	if (!cl)
>  		return;
>  
> -	c = -1;
> -	while (1) {
> -		if (read(cl->s_in, &c, 1) <= 0)
> -			break;
> -		if (cmdline_in(cl, &c, 1) < 0)
> -			break;
> +	while (!cl->error && !cl->eof) {
> +		int read_status;
> +
> +		if (el_gets(cl->el, &read_status))
> +			continue;
> +		if (read_status == -1)
> +			cl->error = 1;

Same comment here about read_status.


Thanks
Olivier

  reply	other threads:[~2018-06-26 13:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-09 13:43 [dpdk-dev] [RFC] " Adrien Mazarguil
2017-11-15  4:12 ` Wiles, Keith
2017-11-15  8:04   ` Olivier MATZ
2017-11-15 16:31     ` Wiles, Keith
2017-11-16  9:23   ` Adrien Mazarguil
2017-11-16 16:48     ` Wiles, Keith
2017-11-16 18:07       ` Thomas Monjalon
2017-11-16 17:06     ` Ferruh Yigit
2017-11-16 17:27       ` Wiles, Keith
2017-11-16 18:05         ` Thomas Monjalon
2017-11-16 16:53 ` Jim Thompson
2018-04-17 15:21 ` [dpdk-dev] [PATCH v1] " Adrien Mazarguil
2018-04-17 15:59   ` Burakov, Anatoly
2018-04-19 15:13   ` [dpdk-dev] [PATCH v2] " Adrien Mazarguil
2018-06-26 13:21     ` Olivier Matz [this message]
2018-06-26 13:33       ` Olivier Matz
2018-06-27 10:36       ` Bruce Richardson
2018-06-27 11:35         ` Olivier Matz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180626132121.6qm3m3mx2ubkxyn3@platinum \
    --to=olivier.matz@6wind.com \
    --cc=adrien.mazarguil@6wind.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=jim@netgate.com \
    --cc=jingjing.wu@intel.com \
    --cc=keith.wiles@intel.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).