This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Variations of memset()


On Fri, Aug 04, 2017 at 02:09:11PM -0400, Carlos O'Donell wrote:
> On 08/04/2017 01:11 PM, Matthew Wilcox wrote:
> > void *memset16(uint16_t *s, uint16_t v, size_t count);
> > void *memset32(uint32_t *s, uint32_t v, size_t count);
> > void *memset64(uint64_t *s, uint64_t v, size_t count);
> > void *memset_s(unsigned short *p, unsigned short v, size_t count);
> > void *memset_i(unsigned int *p, unsigned int v, size_t count);
> > void *memset_l(unsigned long *p, unsigned long v, size_t count);
> > void *memset_ll(unsigned long long *p, unsigned long long v, size_t count);
> > void *memset_p(void **p, void *v, size_t count);
> 
> How are users expected to use these functions?
> 
> What current uses to users use them for?

I've identified three places in the Linux kernel which are quite
dissimilar that can make use of such functions.

1. Initialising an array of uint32_t to a particular value.  This is part
of the Symbios SCSI driver.  It is initialisation code.  This benefits
from smaller code size.

2. Decompression in the zram driver.  The zram driver can compress a page
of RAM which consists entirely of a repeated pattern (up to the size of a
'long').  This benefits from the speed of memset_l.

3. Various console tricks (scrolling, etc).  The VGA console consists
of two-byte entries in an array, and inserting a blank line is done with
a call to memset16().

Here's the sample usage from the symbios driver:

-               for (i = 0 ; i < 64 ; i++)
-                       tp->luntbl[i] = cpu_to_scr(vtobus(&np->badlun_sa));
+               memset32(tp->luntbl, cpu_to_scr(vtobus(&np->badlun_sa)), 64);

I expect a lot of users would be of this type; simply replacing the
explicit for-loop equivalent with a library call.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]