* [dpdk-dev] [PATCH] pmdinfogen: allow using stdin and stdout
@ 2018-01-25 11:12 Bruce Richardson
2018-01-25 21:30 ` Neil Horman
0 siblings, 1 reply; 4+ messages in thread
From: Bruce Richardson @ 2018-01-25 11:12 UTC (permalink / raw)
To: Neil Horman; +Cc: dev, Bruce Richardson
Rather than having to work off files all the time, allow stdin and stdout
to be used as the source and destination for pmdinfogen. This will allow
other possible usages from scripts, e.g. taking files from ar archive and
building a single .pmd.c file from all the .o files in it.
for f in `ar t librte_pmd_xyz.a` ; do
ar p librte_pmd_xyz.a $f | pmdinfogen - - >> xyz_info.c
done
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
buildtools/pmdinfogen/pmdinfogen.c | 44 +++++++++++++++++++++++++++++++-------
1 file changed, 36 insertions(+), 8 deletions(-)
diff --git a/buildtools/pmdinfogen/pmdinfogen.c b/buildtools/pmdinfogen/pmdinfogen.c
index b07dbcf4b..45b267346 100644
--- a/buildtools/pmdinfogen/pmdinfogen.c
+++ b/buildtools/pmdinfogen/pmdinfogen.c
@@ -26,6 +26,7 @@
#define ADDR_SIZE 32
#endif
+static int use_stdin, use_stdout;
static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
{
@@ -39,11 +40,32 @@ static void *grab_file(const char *filename, unsigned long *size)
{
struct stat st;
void *map = MAP_FAILED;
- int fd;
+ int fd = -1;
+
+ if (!use_stdin) {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+ } else {
+ /* from stdin, use a temporary file to mmap */
+ FILE *infile;
+ char buffer[1024];
+ size_t n;
+
+ infile = tmpfile();
+ if (infile == NULL) {
+ perror("tmpfile");
+ return NULL;
+ }
+ while (!feof(stdin)) {
+ n = fread(buffer, 1, sizeof(buffer), stdin);
+ if (fwrite(buffer, 1, n, infile) != n)
+ goto failed;
+ }
+ fflush(infile);
+ fd = fileno(infile);
+ }
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- return NULL;
if (fstat(fd, &st))
goto failed;
@@ -358,10 +380,14 @@ static void output_pmd_info_string(struct elf_info *info, char *outfile)
struct rte_pci_id *pci_ids;
int idx = 0;
- ofd = fopen(outfile, "w+");
- if (!ofd) {
- fprintf(stderr, "Unable to open output file\n");
- return;
+ if (use_stdout)
+ ofd = stdout;
+ else {
+ ofd = fopen(outfile, "w+");
+ if (!ofd) {
+ fprintf(stderr, "Unable to open output file\n");
+ return;
+ }
}
drv = info->drivers;
@@ -411,6 +437,8 @@ int main(int argc, char **argv)
basename(argv[0]));
exit(127);
}
+ use_stdin = !strcmp(argv[1], "-");
+ use_stdout = !strcmp(argv[2], "-");
parse_elf(&info, argv[1]);
if (locate_pmd_entries(&info) < 0)
--
2.14.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] pmdinfogen: allow using stdin and stdout
2018-01-25 11:12 [dpdk-dev] [PATCH] pmdinfogen: allow using stdin and stdout Bruce Richardson
@ 2018-01-25 21:30 ` Neil Horman
2018-01-26 9:19 ` Bruce Richardson
2018-01-29 19:49 ` Thomas Monjalon
0 siblings, 2 replies; 4+ messages in thread
From: Neil Horman @ 2018-01-25 21:30 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev
On Thu, Jan 25, 2018 at 11:12:25AM +0000, Bruce Richardson wrote:
> Rather than having to work off files all the time, allow stdin and stdout
> to be used as the source and destination for pmdinfogen. This will allow
> other possible usages from scripts, e.g. taking files from ar archive and
> building a single .pmd.c file from all the .o files in it.
>
> for f in `ar t librte_pmd_xyz.a` ; do
> ar p librte_pmd_xyz.a $f | pmdinfogen - - >> xyz_info.c
> done
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
I think this is a great idea. FWIW, I think the ELF header at the front of the
file should have something that tells you the overall disk file size in it. The
ELF header is pretty easy to parse and do some basic evaluation on, so you could
accelerate that read a bit, by breaking it down into a read of the size of the
header, followed by a parsing of it and a subsequent read of the overall size,
but that probably just nice to have
Either way, this is a worthwhile feature to have
Acked-by: Neil Horman <nhorman@tuxdriver.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] pmdinfogen: allow using stdin and stdout
2018-01-25 21:30 ` Neil Horman
@ 2018-01-26 9:19 ` Bruce Richardson
2018-01-29 19:49 ` Thomas Monjalon
1 sibling, 0 replies; 4+ messages in thread
From: Bruce Richardson @ 2018-01-26 9:19 UTC (permalink / raw)
To: Neil Horman; +Cc: dev
On Thu, Jan 25, 2018 at 04:30:40PM -0500, Neil Horman wrote:
> On Thu, Jan 25, 2018 at 11:12:25AM +0000, Bruce Richardson wrote:
> > Rather than having to work off files all the time, allow stdin and
> > stdout to be used as the source and destination for pmdinfogen. This
> > will allow other possible usages from scripts, e.g. taking files
> > from ar archive and building a single .pmd.c file from all the .o
> > files in it.
> >
> > for f in `ar t librte_pmd_xyz.a` ; do ar p librte_pmd_xyz.a $f |
> > pmdinfogen - - >> xyz_info.c done
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> I think this is a great idea. FWIW, I think the ELF header at the
> front of the file should have something that tells you the overall
> disk file size in it. The ELF header is pretty easy to parse and do
> some basic evaluation on, so you could accelerate that read a bit, by
> breaking it down into a read of the size of the header, followed by a
> parsing of it and a subsequent read of the overall size, but that
> probably just nice to have
>
Yes, it's a good idea for future implementation. It would also allow
multiple .o files to be streamed together, since pmdinfogen could
recognise the end of one elf file and the start of another. That would
remove the need for the loop in the example above, since we could just
pipe the "ar p" output of the whole archive straight to pmdinfogen.
Not something for this release though. :-)
Thanks,
/Bruce
> Either way, this is a worthwhile feature to have
> Acked-by: Neil Horman <nhorman@tuxdriver.com>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] pmdinfogen: allow using stdin and stdout
2018-01-25 21:30 ` Neil Horman
2018-01-26 9:19 ` Bruce Richardson
@ 2018-01-29 19:49 ` Thomas Monjalon
1 sibling, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2018-01-29 19:49 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, Neil Horman
25/01/2018 22:30, Neil Horman:
> On Thu, Jan 25, 2018 at 11:12:25AM +0000, Bruce Richardson wrote:
> > Rather than having to work off files all the time, allow stdin and stdout
> > to be used as the source and destination for pmdinfogen. This will allow
> > other possible usages from scripts, e.g. taking files from ar archive and
> > building a single .pmd.c file from all the .o files in it.
> >
> > for f in `ar t librte_pmd_xyz.a` ; do
> > ar p librte_pmd_xyz.a $f | pmdinfogen - - >> xyz_info.c
> > done
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> I think this is a great idea. FWIW, I think the ELF header at the front of the
> file should have something that tells you the overall disk file size in it. The
> ELF header is pretty easy to parse and do some basic evaluation on, so you could
> accelerate that read a bit, by breaking it down into a read of the size of the
> header, followed by a parsing of it and a subsequent read of the overall size,
> but that probably just nice to have
>
> Either way, this is a worthwhile feature to have
> Acked-by: Neil Horman <nhorman@tuxdriver.com>
Applied, thanks
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-01-29 19:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-25 11:12 [dpdk-dev] [PATCH] pmdinfogen: allow using stdin and stdout Bruce Richardson
2018-01-25 21:30 ` Neil Horman
2018-01-26 9:19 ` Bruce Richardson
2018-01-29 19:49 ` Thomas Monjalon
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).