|
Packit |
6c4009 |
/* Test the implementation of __ppc_set_ppr_* functions.
|
|
Packit |
6c4009 |
Copyright (C) 2017-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <inttypes.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdint.h>
|
|
Packit |
6c4009 |
#include <sys/auxv.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sys/platform/ppc.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <support/test-driver.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __powerpc64__
|
|
Packit |
6c4009 |
typedef uint64_t ppr_t;
|
|
Packit |
6c4009 |
# define MFPPR "mfppr"
|
|
Packit |
6c4009 |
/* The thread priority value is obtained from bits 11:13. */
|
|
Packit |
6c4009 |
# define EXTRACT_THREAD_PRIORITY(x) ((x >> 50) & 7)
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
typedef uint32_t ppr_t;
|
|
Packit |
6c4009 |
# define MFPPR "mfppr32"
|
|
Packit |
6c4009 |
/* For 32-bit, the upper 32 bits of the Program Priority Register (PPR)
|
|
Packit |
6c4009 |
are used, so the thread priority value is obtained from bits 43:46. */
|
|
Packit |
6c4009 |
# define EXTRACT_THREAD_PRIORITY(x) ((x >> 18) & 7)
|
|
Packit |
6c4009 |
#endif /* !__powerpc64__ */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Read the thread priority value set in the PPR. */
|
|
Packit |
6c4009 |
static __inline__ ppr_t
|
|
Packit |
6c4009 |
get_thread_priority (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Read the PPR. */
|
|
Packit |
6c4009 |
ppr_t ppr;
|
|
Packit |
6c4009 |
asm volatile (MFPPR" %0" : "=r"(ppr));
|
|
Packit |
6c4009 |
/* Return the thread priority value. */
|
|
Packit |
6c4009 |
return EXTRACT_THREAD_PRIORITY (ppr);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Check the thread priority bits of PPR are set as expected. */
|
|
Packit |
6c4009 |
uint8_t
|
|
Packit |
6c4009 |
check_thread_priority (uint8_t expected)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
ppr_t actual = get_thread_priority ();
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (actual != expected)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("FAIL: Expected %"PRIu8" got %"PRIuMAX".\n", expected,
|
|
Packit |
6c4009 |
(uintmax_t) actual);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
printf ("PASS: Thread priority set to %"PRIu8" correctly.\n", expected);
|
|
Packit |
6c4009 |
return 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The Power ISA 2.06 allows the following thread priorities for any
|
|
Packit |
6c4009 |
problem state program: low (2), medium low (3), and medium (4).
|
|
Packit |
6c4009 |
Power ISA 2.07b added very low (1).
|
|
Packit |
6c4009 |
Check whether the values set by __ppc_set_ppr_* are correct. */
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Check for the minimum required Power ISA to run these tests. */
|
|
Packit |
6c4009 |
if ((getauxval (AT_HWCAP) & PPC_FEATURE_ARCH_2_06) == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("Requires an environment that implements the Power ISA version"
|
|
Packit |
6c4009 |
" 2.06 or greater.\n");
|
|
Packit |
6c4009 |
return EXIT_UNSUPPORTED;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
uint8_t rc = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef _ARCH_PWR8
|
|
Packit |
6c4009 |
__ppc_set_ppr_very_low ();
|
|
Packit |
6c4009 |
rc |= check_thread_priority (1);
|
|
Packit |
6c4009 |
#endif /* _ARCH_PWR8 */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__ppc_set_ppr_low ();
|
|
Packit |
6c4009 |
rc |= check_thread_priority (2);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__ppc_set_ppr_med_low ();
|
|
Packit |
6c4009 |
rc |= check_thread_priority (3);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__ppc_set_ppr_med ();
|
|
Packit |
6c4009 |
rc |= check_thread_priority (4);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return rc;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <support/test-driver.c>
|