[PATCH 1/1] riscv: Get cache information through sysconf

Zong Li zong.li@sifive.com
Tue Oct 27 08:50:53 GMT 2020


On Tue, Oct 27, 2020 at 4:13 PM Andrew Waterman <andrew@sifive.com> wrote:
>
> On Tue, Oct 27, 2020 at 12:46 AM Zong Li <zong.li@sifive.com> wrote:
> >
> > On Tue, Oct 27, 2020 at 3:29 PM Florian Weimer <fw@deneb.enyo.de> wrote:
> > >
> > > * Zong Li:
> > >
> > > > On Mon, Oct 26, 2020 at 4:27 PM Florian Weimer <fw@deneb.enyo.de> wrote:
> > > >>
> > > >> * Zong Li:
> > > >>
> > > >> > Add support to query cache information on RISC-V through sysconf()
> > > >> > function. The cache information had been added in AUX vector of RISC-V
> > > >> > architecture in Linux kernel v.5.10-rc1.
> > > >>
> > > >> I think this needs error reporting in case the auxiliary vector does
> > > >> not contain the requested information.
> > > >
> > > > Does the error reporting mean that we need to check the errno and
> > > > return the error number when AUX vector is unavailable?
> > >
> > > I think you need to return -1 and arrange for errno being set.
> > > getauxval sets errno, but the masking and shifting means that
> > > sysconf does not necessarily return -1.
> >
> > Yeah, it is good to me for returning -1. For errno, it seems to me
> > that we could keep the errno which is set by getauxval, the ENOENT is
> > good to present the lack of information in the AUX vector, so we don't
> > set the errno again. I was wondering if the following changes are good
> > to you as well?
>
> I believe getauxval does not clear errno on success, so to use this
> approach, you'd need to save errno, clear it, call getauxval, check
> errno, then OR the saved errno into the new one.
>

Okay, thanks for pointing out that, I would fix it in the next version.

> Instead, can we treat a getauxval return value of 0 as an error in
> these cases?  Then, we could check for a 0 return value, set errno,
> and return -1.
>

The return value of 0 from getauxval couldn't recognize the error for
the following difference:
 - AUX vector doesn't contain the requested information.
 - AUX vector contains the information, but it gets the zero value due
to no caches in real.
So we might still need to use ENOENT which is set by getauxval to
recognize the difference.

>
> >
> > diff --git a/sysdeps/unix/sysv/linux/riscv/sysconf.c
> > b/sysdeps/unix/sysv/linux/riscv/sysconf.c
> > index e73095528c..22ac4f8d19 100644
> > --- a/sysdeps/unix/sysv/linux/riscv/sysconf.c
> > +++ b/sysdeps/unix/sysv/linux/riscv/sysconf.c
> > @@ -24,19 +24,34 @@ static long int linux_sysconf (int name);
> >  static inline long int
> >  sysconf_get_cache_associativity (unsigned long type)
> >  {
> > -  return (__getauxval (type) & 0xffff0000) >> 16;
> > +  unsigned long int val = __getauxval (type);
> > +
> > +  if (errno == ENOENT)
> > +    return -1;
> > +  else
> > +    return (val & 0xffff0000) >> 16;
> >  }
> >
> >  static inline long int
> >  sysconf_get_cache_linesize (unsigned long type)
> >  {
> > -  return __getauxval (type) & 0xffff;
> > +  unsigned long int val = __getauxval (type);
> > +
> > +  if (errno == ENOENT)
> > +    return -1;
> > +  else
> > +    return val & 0xffff;
> >  }
> >
> >  static inline long int
> >  sysconf_get_cache_size (unsigned long type)
> >  {
> > -  return __getauxval (type);
> > +  unsigned long int val = __getauxval (type);
> > +
> > +  if (errno == ENOENT)
> > +    return -1;
> > +  else
> > +    return val;
> >  }


More information about the Libc-alpha mailing list