[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z7RxGlCkQG9M4AeM@smile.fi.intel.com>
Date: Tue, 18 Feb 2025 13:38:02 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: David Laight <david.laight.linux@...il.com>
Cc: linux-kernel@...r.kernel.org, Andrew Morton <akpm@...ux-foundation.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Randy Dunlap <rdunlap@...radead.org>
Subject: Re: [PATCH next 1/1] lib: Optimise hex_dump_to_buffer()
On Sun, Feb 16, 2025 at 10:37:15PM +0000, David Laight wrote:
> On Sun, 16 Feb 2025 22:47:49 +0200
> Andy Shevchenko <andriy.shevchenko@...ux.intel.com> wrote:
> > On Sun, Feb 16, 2025 at 08:19:01PM +0000, David Laight wrote:
...
> > > +extern size_t hex_dump_to_buffer(const void *buf, size_t len, size_t rowsize,
> > > + size_t groupsize, char *linebuf,
> > > + size_t linebuflen, bool ascii);
> >
> > Looking at another thread where upper layer function wants to have unsigned
> > long flags instead of bool ascii, I would also do the new API, that takes flags
> > and leave the old one as a simple wrapper with all restrictions being applied.
>
> I can't imagine any code relying on the rowsize being converted to 16.
> And (elsewhere) I've definitely needed to do hexdumps with strange numbers
> of bytes/line.
I didn't get how this is related to my comment.
...
> > > + dst[0] = hex_asc_hi(ch);
> > > + dst[1] = hex_asc_lo(ch);
> >
> > We have hex_pack_byte() or so
>
> At least some versions of gcc have generated better code if you don't
> use *ptr++ but do the increment afterwards.
> It is also what the old version used.
Do we really care? What versions, btw, are you talk about?
> Not to mention being another wrapper you need to look up to work out
> what the code is doing.
That's not an issue. We use a lot of wrappers in the Linux kernel.
Without a skill to quickly find this information it would be very
hard to develop the kernel code without reinventing a wheel.
...
> > > - linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
> > > + *dst++ = ch >= ' ' && ch < 0x7f ? ch : '.';
> >
> > Please also add a test case for this to make sure it has no changes.
>
> Well isascii() usually checks for the 0x80 bit being clear and isprint()
> rejects control characters and 'del' (0x7f).
> I'm not sure what isascii() does for EBCDIC type charsets - but I don't
> expect Linux runs on any of those so who cares.
Still, it's good to have a test cases for this change.
> Oh, and isprint() seems to be based on a memory lookup in an _ctype[] array.
> Very 1970s.
With enough CPU (data) caches it's quite effective.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists