|
Packit Service |
b439df |
/*
|
|
Packit Service |
b439df |
* libhugetlbfs - Easy use of Linux hugepages
|
|
Packit Service |
b439df |
* Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
|
|
Packit Service |
b439df |
*
|
|
Packit Service |
b439df |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
b439df |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit Service |
b439df |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
b439df |
* the License, or (at your option) any later version.
|
|
Packit Service |
b439df |
*
|
|
Packit Service |
b439df |
* This library is distributed in the hope that it will be useful, but
|
|
Packit Service |
b439df |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b439df |
* MECHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
b439df |
* Lesser General Public License for more details.
|
|
Packit Service |
b439df |
*
|
|
Packit Service |
b439df |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
b439df |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
b439df |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
b439df |
*/
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#ifndef _HUGETESTS_H
|
|
Packit Service |
b439df |
#define _HUGETESTS_H
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#include <errno.h>
|
|
Packit Service |
b439df |
#include <string.h>
|
|
Packit Service |
685a72 |
#include <unistd.h>
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#include "libhugetlbfs_privutils.h"
|
|
Packit Service |
b439df |
#include "libhugetlbfs_testprobes.h"
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#define DEBUG
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
/* Test return codes */
|
|
Packit Service |
b439df |
#define RC_PASS 0
|
|
Packit Service |
b439df |
#define RC_CONFIG 1
|
|
Packit Service |
b439df |
#define RC_FAIL 2
|
|
Packit Service |
b439df |
#define RC_XFAIL 3 /* Expected Failure */
|
|
Packit Service |
b439df |
#define RC_XPASS 4 /* Unexpected Pass */
|
|
Packit Service |
b439df |
#define RC_BUG 99
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#define FOURGB (1UL << 32)
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
extern int verbose_test;
|
|
Packit Service |
b439df |
extern char *test_name;
|
|
Packit Service |
b439df |
void check_free_huge_pages(int nr_pages_needed);
|
|
Packit Service |
b439df |
void check_must_be_root(void);
|
|
Packit Service |
b439df |
void check_hugetlb_shm_group(void);
|
|
Packit Service |
03a960 |
void check_online_cpus(int[], int);
|
|
Packit Service |
b439df |
void test_init(int argc, char *argv[]);
|
|
Packit Service |
b439df |
int test_addr_huge(void *p);
|
|
Packit Service |
b439df |
unsigned long long get_mapping_page_size(void *p);
|
|
Packit Service |
b439df |
long read_meminfo(const char *tag);
|
|
Packit Service |
b439df |
ino_t get_addr_inode(void *p);
|
|
Packit Service |
b439df |
int range_is_mapped(unsigned long low, unsigned long high);
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
|
Packit Service |
b439df |
#define PALIGN(p, a) ((void *)ALIGN((unsigned long)(p), (a)))
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#ifndef barrier
|
|
Packit Service |
b439df |
# ifdef mb
|
|
Packit Service |
b439df |
# define barrier() mb()
|
|
Packit Service |
b439df |
# else
|
|
Packit Service |
b439df |
# define barrier() __asm__ __volatile__ ("" : : : "memory")
|
|
Packit Service |
b439df |
# endif
|
|
Packit Service |
b439df |
#endif
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
/* Each test case must define this function */
|
|
Packit Service |
b439df |
void cleanup(void);
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#define verbose_printf(...) \
|
|
Packit Service |
b439df |
if (verbose_test) { \
|
|
Packit Service |
b439df |
printf(__VA_ARGS__); \
|
|
Packit Service |
b439df |
fflush(stdout); \
|
|
Packit Service |
b439df |
}
|
|
Packit Service |
b439df |
#define ERR "ERR: "
|
|
Packit Service |
b439df |
#define ERROR(fmt, args...) fprintf(stderr, ERR fmt, ## args)
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#define PASS() \
|
|
Packit Service |
b439df |
do { \
|
|
Packit Service |
b439df |
cleanup(); \
|
|
Packit Service |
b439df |
printf("PASS\n"); \
|
|
Packit Service |
b439df |
exit(RC_PASS); \
|
|
Packit Service |
b439df |
} while (0)
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#define PASS_INCONCLUSIVE() \
|
|
Packit Service |
b439df |
do { \
|
|
Packit Service |
b439df |
cleanup(); \
|
|
Packit Service |
b439df |
printf("PASS (inconclusive)\n"); \
|
|
Packit Service |
b439df |
exit(RC_PASS); \
|
|
Packit Service |
b439df |
} while (0)
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#define IRRELEVANT() \
|
|
Packit Service |
b439df |
do { \
|
|
Packit Service |
b439df |
cleanup(); \
|
|
Packit Service |
b439df |
printf("PASS (irrelevant)\n"); \
|
|
Packit Service |
b439df |
exit(RC_PASS); \
|
|
Packit Service |
b439df |
} while (0)
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
/* Look out, gcc extension below... */
|
|
Packit Service |
b439df |
#define FAIL(fmt, ...) \
|
|
Packit Service |
b439df |
do { \
|
|
Packit Service |
b439df |
cleanup(); \
|
|
Packit Service |
b439df |
printf("FAIL\t" fmt "\n", ##__VA_ARGS__); \
|
|
Packit Service |
b439df |
exit(RC_FAIL); \
|
|
Packit Service |
b439df |
} while (0)
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#define CONFIG(fmt, ...) \
|
|
Packit Service |
b439df |
do { \
|
|
Packit Service |
b439df |
cleanup(); \
|
|
Packit Service |
b439df |
printf("Bad configuration: " fmt "\n", ##__VA_ARGS__); \
|
|
Packit Service |
b439df |
exit(RC_CONFIG); \
|
|
Packit Service |
b439df |
} while (0)
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#define TEST_BUG(fmt, ...) \
|
|
Packit Service |
b439df |
do { \
|
|
Packit Service |
b439df |
cleanup(); \
|
|
Packit Service |
b439df |
printf("BUG in testsuite: " fmt "\n", ##__VA_ARGS__); \
|
|
Packit Service |
b439df |
exit(RC_BUG); \
|
|
Packit Service |
b439df |
} while (0)
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
/* stressutils.c stuff */
|
|
Packit Service |
b439df |
int remove_shmid(int shmid);
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
extern long gethugepagesize (void) __attribute__ ((weak));
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
static inline long check_hugepagesize()
|
|
Packit Service |
b439df |
{
|
|
Packit Service |
b439df |
long __hpage_size = gethugepagesize();
|
|
Packit Service |
b439df |
if (__hpage_size < 0) {
|
|
Packit Service |
b439df |
if (errno == ENOSYS)
|
|
Packit Service |
b439df |
CONFIG("No hugepage kernel support\n");
|
|
Packit Service |
b439df |
else if (errno == EOVERFLOW)
|
|
Packit Service |
b439df |
CONFIG("Hugepage size too large");
|
|
Packit Service |
b439df |
else
|
|
Packit Service |
b439df |
CONFIG("Hugepage size (%s)", strerror(errno));
|
|
Packit Service |
b439df |
}
|
|
Packit Service |
b439df |
return __hpage_size;
|
|
Packit Service |
b439df |
}
|
|
Packit Service |
b439df |
|
|
Packit Service |
685a72 |
static inline void check_if_gigantic_page(void)
|
|
Packit Service |
685a72 |
{
|
|
Packit Service |
685a72 |
long page_size, hpage_size, max_order;
|
|
Packit Service |
685a72 |
FILE *fp;
|
|
Packit Service |
685a72 |
|
|
Packit Service |
685a72 |
page_size = sysconf(_SC_PAGESIZE);
|
|
Packit Service |
685a72 |
hpage_size = gethugepagesize();
|
|
Packit Service |
685a72 |
fp = popen("cat /proc/pagetypeinfo | "
|
|
Packit Service |
685a72 |
"awk '/Free pages count per migrate type at order/ "
|
|
Packit Service |
685a72 |
"{print $NF}'", "r");
|
|
Packit Service |
685a72 |
if (!fp || fscanf(fp, "%lu", &max_order) < 0)
|
|
Packit Service |
685a72 |
FAIL("Couldn't determine max page allocation order");
|
|
Packit Service |
685a72 |
|
|
Packit Service |
685a72 |
pclose(fp);
|
|
Packit Service |
685a72 |
if (hpage_size > ((1 << max_order) * page_size))
|
|
Packit Service |
685a72 |
CONFIG("Gigantic pages are not supported");
|
|
Packit Service |
685a72 |
}
|
|
Packit Service |
685a72 |
|
|
Packit Service |
b439df |
int using_system_hpage_size(const char *mount);
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
/* WARNING: Racy -- use for test cases only! */
|
|
Packit Service |
b439df |
int kernel_has_private_reservations(void);
|
|
Packit Service |
b439df |
|
|
Packit Service |
b439df |
#endif /* _HUGETESTS_H */
|