public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: MAHESH BODAPATI <bmahi496@linux.ibm.com>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	libc-alpha@sourceware.org
Cc: rajis@linux.ibm.com, bergner@linux.ibm.com,
	Mahesh Bodapati <mahesh.bodapati@ibm.com>
Subject: Re: [PATCH v5] PowerPC: Influence cpu/arch hwcap features via GLIBC_TUNABLES.
Date: Thu, 13 Jul 2023 18:47:34 +0530	[thread overview]
Message-ID: <fc1e7d27-8894-2d66-9ff4-2b1b9a1fbcd1@linux.ibm.com> (raw)
In-Reply-To: <c9d1d484-e076-82bc-2ee6-e697ac67e759@linaro.org>


On 12/07/23 7:37 pm, Adhemerval Zanella Netto wrote:
>
> On 12/07/23 08:04, MAHESH BODAPATI wrote:
>> On 11/07/23 9:53 pm, Adhemerval Zanella Netto wrote:
>>> On 11/07/23 13:03, MAHESH BODAPATI wrote:
>>>> On 11/07/23 7:15 pm, Adhemerval Zanella Netto wrote:
>>>>> On 10/07/23 15:21, bmahi496@linux.ibm.com wrote:
>>>>>> From: Mahesh Bodapati <mahesh.bodapati@ibm.com>
>>>>>>
>>>>>> This patch enables the option to influence hwcaps used by PowerPC.
>>>>>> The environment variable, GLIBC_TUNABLES=glibc.cpu.hwcaps=-xxx,yyy,-zzz....,
>>>>>> can be used to enable CPU/ARCH feature yyy, disable CPU/ARCH feature xxx
>>>>>> and zzz, where the feature name is case-sensitive and has to match the ones
>>>>>> mentioned in the file{sysdeps/powerpc/dl-procinfo.c}.
>>>>>>
>>>>>> Note that the tunable only handles the features which are really used
>>>>>> in the IFUNC selection.  All others are ignored as the values are only
>>>>>> used inside glibc.
>>>>> It is still missing a regression test to check if tunable work as intended.
>>>> I ran glibc tests with and without setting hwcap tunables and no regressions were found.
>>>> Summary of test results:
>>>>      4458 PASS
>>>>         9 UNSUPPORTED
>>>>        16 XFAIL
>>>>         2 XPASS
>>>>
>>>> The runtime behavior is as expected when we set hwcap tunables.
>>>> We tested on power10,power9 BE and powerpc32 machines and the results were good.
>>>> Could you go through the attached sheet ,we have listed runtime behavior for some of the tunable options.
>>>> We are not sure on how to add regressions tests for tunable feature.
>>>> I didn't see hwcap tunable specific tests added for other targets as well.
>>> There are only tests for x86, so running the tests won't really exercise this
>>> code path for powerpc (and that's why you haven't seem a OOB access in a previous
>>> version):
>>>
>>> $ git grep glibc.cpu.hwcaps
>>> manual/tunables.texi:glibc.cpu.hwcaps:
>>> manual/tunables.texi:@deftp Tunable glibc.cpu.hwcaps
>>> manual/tunables.texi:The @code{glibc.cpu.hwcaps=-xxx,yyy,-zzz...} tunable allows the user to
>>> sysdeps/s390/cpu-features.c:     GLIBC_TUNABLES=glibc.cpu.hwcaps=-xxx,yyy,zzz,....
>>> sysdeps/x86/Makefile:tst-ifunc-isa-2-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=-SSE4_2,-AVX,-AVX2,-AVX512F
>>> sysdeps/x86/Makefile:tst-cet-legacy-5b-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK
>>> sysdeps/x86/Makefile:tst-cet-legacy-6b-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK
>>> sysdeps/x86/Makefile:tst-cet-legacy-9-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK
>>> sysdeps/x86/Makefile:tst-cet-legacy-9-static-ENV = GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK
>>> sysdeps/x86/cpu-features.c:          GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK
>>> sysdeps/x86/cpu-tunables.c:     GLIBC_TUNABLES=glibc.cpu.hwcaps=-xxx,yyy,-zzz,....
>>> sysdeps/x86/dl-cet.c:        GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK
>>> sysdeps/x86/include/cpu-features.h:     GLIBC_TUNABLES=glibc.cpu.hwcaps=-XSAVEC
>>> sysdeps/x86/tst-cet-legacy-9.c:   -fcf-protection and GLIBC_TUNABLES=glibc.cpu.hwcaps=-IBT,-SHSTK.  */
>>> sysdeps/x86_64/Makefile:        GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX512F,-AVX2
>>>
>>> Since testing depending of the auxv returned values from kernel and there is no
>>> easy way to override it, one possibility is to get the current hwcap/hwcap2,
>>> and spawn a new process with GLIBC_TUNABLES masking some bits, and check
>>> the result hwcap/hwcap2 to see if it matches the masked value.  You may
>>> add multiple tests and mark them UNSUPPORTED if the hwcap does not contain
>>> the expected bits (for instance ISA 2.07 or ISA 3.0).
>>
>> We didn't update the AT_HWCAP1/2 auxv. we have updated the values of cpu_features structure based on the
>> tunable set's. the hwcap1/2 values of struct cpu_features has been used for ifunc selection.
>> so we didn't change the values of auxv as similar to S390.
> You can still check the hwcap selection with __libc_ifunc_impl_list, which retrieve
> the ifunc selection based on the cpu_features.  The test below is for memcpy, but
> you can easily extend to other functions.  The __libc_ifunc_impl_list sets more
> ISA bits depending the current ISA to enable testing all the ifunc if the processor
> supports, so the test requires to disable more bits.

Thanks Adhemerval.
I enabled testing for powerpc32 in the same memcpy test and also did the
corrections from PATCH_v6 review comments. I will share the updated patch.


>
> diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile
> index 93783cae00..24827efe79 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/Makefile
> +++ b/sysdeps/unix/sysv/linux/powerpc/Makefile
> @@ -23,9 +23,14 @@ ifeq ($(subdir),misc)
>   sysdep_headers += bits/ppc.h
>   sysdep_routines += get_timebase_freq
>   tests-static += test-gettimebasefreq-static
> -tests += $(tests-static)
> -tests += test-gettimebasefreq
> -tests += test-powerpc-linux-sysconf
> +tests += \
> +  $(tests-static) \
> +  test-gettimebasefreq \
> +  test-powerpc-linux-sysconf \
> +  tst-hwcap-tunables \
> +  # tests
> +
> +tst-hwcap-tunables-ARGS = -- $(host-test-program-cmd)
>   endif
>   
>   ifeq ($(subdir),csu)
> diff --git a/sysdeps/unix/sysv/linux/powerpc/tst-hwcap-tunables.c b/sysdeps/unix/sysv/linux/powerpc/tst-hwcap-tunables.c
> new file mode 100644
> index 0000000000..6c14d717ea
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/powerpc/tst-hwcap-tunables.c
> @@ -0,0 +1,116 @@
> +/* Tests for powerpc GLIBC_TUNABLES=glibc.cpu.hwcaps filter.
> +   Copyright (C) 2023 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <array_length.h>
> +#include <getopt.h>
> +#include <ifunc-impl-list.h>
> +#include <spawn.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <support/check.h>
> +#include <support/support.h>
> +#include <support/xunistd.h>
> +#include <sys/auxv.h>
> +#include <sys/wait.h>
> +
> +/* Nonzero if the program gets called via `exec'.  */
> +#define CMDLINE_OPTIONS \
> +  { "restart", no_argument, &restart, 1 },
> +static int restart;
> +
> +/* Hold the four initial argument used to respawn the process, plus the extra
> +   '--direct', '--restart', and the function to check  */
> +static char *spargs[8];
> +static int fc;
> +
> +/* Called on process re-execution.  */
> +_Noreturn static void
> +handle_restart (int argc, char *argv[])
> +{
> +  TEST_VERIFY_EXIT (argc == 1);
> +  const char *funcname = argv[0];
> +
> +  struct libc_ifunc_impl impls[32];
> +  int cnt = __libc_ifunc_impl_list ("memcpy", impls, array_length (impls));
> +  TEST_VERIFY_EXIT (cnt >= 1);
> +  for (int i = 0; i < cnt; i++) {
> +    if (strcmp (impls[i].name, funcname) == 0)
> +      {
> +        TEST_COMPARE (impls[i].usable, false);
> +	break;
> +      }
> +  }
> +
> +  _exit (EXIT_SUCCESS);
> +}
> +
> +static void
> +run_test (const char *filter, const char *funcname)
> +{
> +  printf ("info: checking filter %s (expect %s ifunc selection to be removed)\n",
> +          filter, funcname);
> +  char *tunable = xasprintf ("GLIBC_TUNABLES=glibc.cpu.hwcaps=%s", filter);
> +  char *const newenvs[] = { (char*) tunable, NULL };
> +  spargs[fc] = (char *) funcname;
> +
> +  pid_t pid;
> +  TEST_COMPARE (posix_spawn (&pid, spargs[0], NULL, NULL, spargs, newenvs), 0);
> +  int status;
> +  TEST_COMPARE (xwaitpid (pid, &status, 0), pid);
> +  TEST_VERIFY (WIFEXITED (status));
> +  TEST_VERIFY (!WIFSIGNALED (status));
> +  TEST_COMPARE (WEXITSTATUS (status), 0);
> +
> +  free (tunable);
> +}
> +
> +static int
> +do_test (int argc, char *argv[])
> +{
> +  if (restart)
> +    handle_restart (argc - 1, &argv[1]);
> +
> +  TEST_VERIFY_EXIT (argc == 2 || argc == 5);
> +
> +  int i;
> +  for (i = 0; i < argc - 1; i++)
> +    spargs[i] = argv[i + 1];
> +  spargs[i++] = (char *) "--direct";
> +  spargs[i++] = (char *) "--restart";
> +  fc = i++;
> +  spargs[i] = NULL;
> +
> +  unsigned long int hwcap = getauxval (AT_HWCAP);
> +  unsigned long int hwcap2 = getauxval (AT_HWCAP2);
> +
> +  if (hwcap2 & PPC_FEATURE2_ARCH_3_1)
> +    run_test ("-arch_3_1", "__memcpy_power10");
> +  if (hwcap2 & PPC_FEATURE2_ARCH_2_07)
> +  run_test ("-arch_2_07", "__memcpy_power8_cached");
> +  if (hwcap & PPC_FEATURE_ARCH_2_06)
> +    run_test ("-arch_2_06", "__memcpy_power7");
> +  if (hwcap & PPC_FEATURE_ARCH_2_05)
> +    run_test ("-arch_2_06,-arch_2_05","__memcpy_power6");
> +  run_test ("-arch_2_06,-arch_2_05,-power5+,-power5,-power4", "__memcpy_power4");
> +
> +  return 0;
> +}
> +
> +#define TEST_FUNCTION_ARGV do_test
> +#include <support/test-driver.c>

      reply	other threads:[~2023-07-13 13:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-10 18:21 bmahi496
2023-07-10 21:28 ` Peter Bergner
2023-07-11 12:24   ` Adhemerval Zanella Netto
2023-07-11 16:05     ` MAHESH BODAPATI
2023-07-11 13:45 ` Adhemerval Zanella Netto
2023-07-11 16:03   ` MAHESH BODAPATI
2023-07-11 16:23     ` Adhemerval Zanella Netto
2023-07-11 16:23     ` Adhemerval Zanella Netto
2023-07-12 11:04       ` MAHESH BODAPATI
2023-07-12 14:07         ` Adhemerval Zanella Netto
2023-07-13 13:17           ` MAHESH BODAPATI [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fc1e7d27-8894-2d66-9ff4-2b1b9a1fbcd1@linux.ibm.com \
    --to=bmahi496@linux.ibm.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=bergner@linux.ibm.com \
    --cc=libc-alpha@sourceware.org \
    --cc=mahesh.bodapati@ibm.com \
    --cc=rajis@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).