[PATCH 1/1] riscv: Get cache information through sysconf
Zong Li
zong.li@sifive.com
Thu Oct 29 03:36:31 GMT 2020
On Tue, Oct 27, 2020 at 6:15 PM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Zong Li:
>
> > On Tue, Oct 27, 2020 at 5:44 PM Florian Weimer <fweimer@redhat.com> wrote:
> >>
> >> * Zong Li:
> >>
> >> > Okay, thanks for pointing out that, I would fix it in the next
> >> > version.
> >>
> >> I posted a patch that should simplify the implementation:
> >>
> >> Subject: [PATCH] misc: Add internal __getauxval2 function
> >>
> >
> > Many thanks, I should base on top of your patch, let me change to use
> > __getauxval2 here.
>
> It probably makes sense to add your own static local function
> getauxval2_einval, with the same signature as __getauxval2, but which
> also sets EINVAL on error.
>
Like my previous mail, I'd like to make sure that I actually pick up
all suggestions before I send the next version. This modification adds
a local getauxval2_einval function for internal use to handle the
error setting. Thanks for everyone's review.
+static bool
+getauxval2_einval (unsigned long int type, unsigned long int *result)
+{
+ int save_errno = errno;
+
+ __set_errno (0);
+
+ if (!__getauxval2 (type, result))
+ {
+ __set_errno (EINVAL);
+ return false;
+ }
+
+ __set_errno (save_errno);
+
+ return true;
+}
+
static inline long int
sysconf_get_cache_associativity (unsigned long type)
{
- return (__getauxval (type) & 0xffff0000) >> 16;
+ unsigned long int result;
+
+ if (getauxval2_einval (type, &result))
+ return (result & 0xffff0000) >> 16;
+
+ return -1;
}
static inline long int
sysconf_get_cache_linesize (unsigned long type)
{
- return __getauxval (type) & 0xffff;
+ unsigned long int result;
+
+ if (getauxval2_einval (type, &result))
+ return result & 0xffff;
+
+ return -1;
}
static inline long int
sysconf_get_cache_size (unsigned long type)
{
- return __getauxval (type);
+ unsigned long int result;
+
+ if (getauxval2_einval (type, &result))
+ return result;
+
+ return -1;
}
> Thanks,
> Florian
> --
> Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
> Commercial register: Amtsgericht Muenchen, HRB 153243,
> Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
>
More information about the Libc-alpha
mailing list