2017-10-04 19:33:43 +03:00
|
|
|
/*
|
2010-05-18 02:18:00 +04:00
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 08:38:26 +04:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
|
|
|
*
|
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2008-05-26 08:38:26 +04:00
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 08:38:26 +04:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-18 02:18:00 +04:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
2017-10-04 19:33:43 +03:00
|
|
|
*/
|
2008-05-26 08:38:26 +04:00
|
|
|
|
2008-03-04 21:22:31 +03:00
|
|
|
#ifndef _SPL_SYSMACROS_H
|
2018-02-07 22:49:38 +03:00
|
|
|
#define _SPL_SYSMACROS_H
|
2008-03-04 21:22:31 +03:00
|
|
|
|
|
|
|
#include <linux/module.h>
|
2013-03-04 08:42:32 +04:00
|
|
|
#include <linux/sched.h>
|
2019-11-12 19:59:06 +03:00
|
|
|
#include <linux/sched/rt.h>
|
2010-07-21 02:44:28 +04:00
|
|
|
#include <linux/cpumask.h>
|
2008-04-19 03:39:58 +04:00
|
|
|
#include <sys/debug.h>
|
2008-03-13 02:48:28 +03:00
|
|
|
#include <sys/zone.h>
|
2008-03-17 21:29:57 +03:00
|
|
|
#include <sys/signal.h>
|
2017-01-31 21:36:18 +03:00
|
|
|
#include <asm/page.h>
|
2008-03-04 21:22:31 +03:00
|
|
|
|
2013-03-04 08:42:32 +04:00
|
|
|
|
2008-03-04 21:22:31 +03:00
|
|
|
#ifndef _KERNEL
|
2018-02-07 22:49:38 +03:00
|
|
|
#define _KERNEL __KERNEL__
|
2008-03-04 21:22:31 +03:00
|
|
|
#endif
|
|
|
|
|
2018-02-07 22:49:38 +03:00
|
|
|
#define FALSE 0
|
|
|
|
#define TRUE 1
|
|
|
|
|
|
|
|
#define INT8_MAX (127)
|
|
|
|
#define INT8_MIN (-128)
|
|
|
|
#define UINT8_MAX (255)
|
|
|
|
#define UINT8_MIN (0)
|
|
|
|
|
|
|
|
#define INT16_MAX (32767)
|
|
|
|
#define INT16_MIN (-32768)
|
|
|
|
#define UINT16_MAX (65535)
|
|
|
|
#define UINT16_MIN (0)
|
|
|
|
|
|
|
|
#define INT32_MAX INT_MAX
|
|
|
|
#define INT32_MIN INT_MIN
|
|
|
|
#define UINT32_MAX UINT_MAX
|
|
|
|
#define UINT32_MIN UINT_MIN
|
|
|
|
|
|
|
|
#define INT64_MAX LLONG_MAX
|
|
|
|
#define INT64_MIN LLONG_MIN
|
|
|
|
#define UINT64_MAX ULLONG_MAX
|
|
|
|
#define UINT64_MIN ULLONG_MIN
|
|
|
|
|
|
|
|
#define NBBY 8
|
|
|
|
|
|
|
|
#define MAXMSGLEN 256
|
|
|
|
#define MAXNAMELEN 256
|
2018-02-15 04:01:15 +03:00
|
|
|
#define MAXPATHLEN 4096
|
2018-02-07 22:49:38 +03:00
|
|
|
#define MAXOFFSET_T LLONG_MAX
|
|
|
|
#define MAXBSIZE 8192
|
|
|
|
#define DEV_BSIZE 512
|
|
|
|
#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
|
|
|
|
|
|
|
|
#define proc_pageout NULL
|
|
|
|
#define curproc current
|
|
|
|
#define max_ncpus num_possible_cpus()
|
|
|
|
#define boot_ncpus num_online_cpus()
|
|
|
|
#define CPU_SEQID smp_processor_id()
|
2020-11-02 22:51:12 +03:00
|
|
|
#define CPU_SEQID_UNSTABLE raw_smp_processor_id()
|
2018-02-07 22:49:38 +03:00
|
|
|
#define is_system_labeled() 0
|
2008-03-04 21:22:31 +03:00
|
|
|
|
2010-11-09 21:34:10 +03:00
|
|
|
#ifndef RLIM64_INFINITY
|
2018-02-07 22:49:38 +03:00
|
|
|
#define RLIM64_INFINITY (~0ULL)
|
2010-11-09 21:34:10 +03:00
|
|
|
#endif
|
2008-03-10 20:05:34 +03:00
|
|
|
|
2018-02-07 22:49:38 +03:00
|
|
|
/*
|
|
|
|
* 0..MAX_PRIO-1: Process priority
|
2008-03-04 21:22:31 +03:00
|
|
|
* 0..MAX_RT_PRIO-1: RT priority tasks
|
|
|
|
* MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks
|
|
|
|
*
|
|
|
|
* Treat shim tasks as SCHED_NORMAL tasks
|
|
|
|
*/
|
2018-02-07 22:49:38 +03:00
|
|
|
#define minclsyspri (MAX_PRIO-1)
|
|
|
|
#define maxclsyspri (MAX_RT_PRIO)
|
|
|
|
#define defclsyspri (DEFAULT_PRIO)
|
2008-03-04 21:22:31 +03:00
|
|
|
|
2014-05-07 21:57:19 +04:00
|
|
|
#ifndef NICE_TO_PRIO
|
2018-02-07 22:49:38 +03:00
|
|
|
#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
|
2014-05-07 21:57:19 +04:00
|
|
|
#endif
|
|
|
|
#ifndef PRIO_TO_NICE
|
2018-02-07 22:49:38 +03:00
|
|
|
#define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
|
2014-05-07 21:57:19 +04:00
|
|
|
#endif
|
2008-03-04 21:22:31 +03:00
|
|
|
|
2014-08-17 02:16:08 +04:00
|
|
|
/*
|
|
|
|
* Missing macros
|
2008-03-04 21:22:31 +03:00
|
|
|
*/
|
2014-08-17 02:16:08 +04:00
|
|
|
#ifndef PAGESIZE
|
2018-02-07 22:49:38 +03:00
|
|
|
#define PAGESIZE PAGE_SIZE
|
2014-08-17 02:16:08 +04:00
|
|
|
#endif
|
2008-03-04 21:22:31 +03:00
|
|
|
|
2017-01-31 21:36:18 +03:00
|
|
|
#ifndef PAGESHIFT
|
2018-02-07 22:49:38 +03:00
|
|
|
#define PAGESHIFT PAGE_SHIFT
|
2017-01-31 21:36:18 +03:00
|
|
|
#endif
|
|
|
|
|
2008-03-07 02:12:55 +03:00
|
|
|
/* Missing globals */
|
2018-10-09 07:57:02 +03:00
|
|
|
extern char spl_gitrev[64];
|
2011-04-11 23:49:50 +04:00
|
|
|
extern unsigned long spl_hostid;
|
2008-03-04 21:22:31 +03:00
|
|
|
|
2008-03-07 02:12:55 +03:00
|
|
|
/* Missing misc functions */
|
2009-02-19 22:26:17 +03:00
|
|
|
extern uint32_t zone_get_hostid(void *zone);
|
2009-10-02 03:06:15 +04:00
|
|
|
extern void spl_setup(void);
|
|
|
|
extern void spl_cleanup(void);
|
2008-03-07 02:12:55 +03:00
|
|
|
|
2016-07-14 22:51:24 +03:00
|
|
|
#define highbit(x) __fls(x)
|
|
|
|
#define lowbit(x) __ffs(x)
|
|
|
|
|
2014-10-01 02:07:07 +04:00
|
|
|
#define highbit64(x) fls64(x)
|
2018-02-07 22:49:38 +03:00
|
|
|
#define makedevice(maj, min) makedev(maj, min)
|
2008-03-04 21:22:31 +03:00
|
|
|
|
|
|
|
/* common macros */
|
|
|
|
#ifndef MIN
|
2018-02-07 22:49:38 +03:00
|
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
2008-03-04 21:22:31 +03:00
|
|
|
#endif
|
|
|
|
#ifndef MAX
|
2018-02-07 22:49:38 +03:00
|
|
|
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
2008-03-04 21:22:31 +03:00
|
|
|
#endif
|
|
|
|
#ifndef ABS
|
2018-02-07 22:49:38 +03:00
|
|
|
#define ABS(a) ((a) < 0 ? -(a) : (a))
|
2009-05-20 23:23:24 +04:00
|
|
|
#endif
|
|
|
|
#ifndef DIV_ROUND_UP
|
2018-02-07 22:49:38 +03:00
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
|
2009-05-20 23:23:24 +04:00
|
|
|
#endif
|
|
|
|
#ifndef roundup
|
2018-02-07 22:49:38 +03:00
|
|
|
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
|
2008-03-04 21:22:31 +03:00
|
|
|
#endif
|
2014-04-27 05:56:03 +04:00
|
|
|
#ifndef howmany
|
2018-02-07 22:49:38 +03:00
|
|
|
#define howmany(x, y) (((x) + ((y) - 1)) / (y))
|
2014-04-27 05:56:03 +04:00
|
|
|
#endif
|
2008-03-04 21:22:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compatibility macros/typedefs needed for Solaris -> Linux port
|
|
|
|
*/
|
2018-02-07 22:49:38 +03:00
|
|
|
#define P2ALIGN(x, align) ((x) & -(align))
|
|
|
|
#define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
|
|
|
|
#define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1)
|
|
|
|
#define P2PHASE(x, align) ((x) & ((align) - 1))
|
|
|
|
#define P2NPHASE(x, align) (-(x) & ((align) - 1))
|
|
|
|
#define ISP2(x) (((x) & ((x) - 1)) == 0)
|
|
|
|
#define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
|
|
|
|
#define P2BOUNDARY(off, len, align) \
|
2010-06-12 01:57:49 +04:00
|
|
|
(((off) ^ ((off) + (len) - 1)) > (align) - 1)
|
2008-03-04 21:22:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Typed version of the P2* macros. These macros should be used to ensure
|
|
|
|
* that the result is correctly calculated based on the data type of (x),
|
|
|
|
* which is passed in as the last argument, regardless of the data
|
|
|
|
* type of the alignment. For example, if (x) is of type uint64_t,
|
|
|
|
* and we want to round it up to a page boundary using "PAGESIZE" as
|
|
|
|
* the alignment, we can do either
|
2010-06-12 01:57:49 +04:00
|
|
|
*
|
2008-03-04 21:22:31 +03:00
|
|
|
* P2ROUNDUP(x, (uint64_t)PAGESIZE)
|
|
|
|
* or
|
|
|
|
* P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
|
|
|
|
*/
|
2018-02-07 22:49:38 +03:00
|
|
|
#define P2ALIGN_TYPED(x, align, type) \
|
|
|
|
((type)(x) & -(type)(align))
|
|
|
|
#define P2PHASE_TYPED(x, align, type) \
|
|
|
|
((type)(x) & ((type)(align) - 1))
|
|
|
|
#define P2NPHASE_TYPED(x, align, type) \
|
|
|
|
(-(type)(x) & ((type)(align) - 1))
|
|
|
|
#define P2ROUNDUP_TYPED(x, align, type) \
|
|
|
|
((((type)(x) - 1) | ((type)(align) - 1)) + 1)
|
|
|
|
#define P2END_TYPED(x, align, type) \
|
|
|
|
(-(~(type)(x) & -(type)(align)))
|
|
|
|
#define P2PHASEUP_TYPED(x, align, phase, type) \
|
|
|
|
((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
|
|
|
|
#define P2CROSS_TYPED(x, y, align, type) \
|
|
|
|
(((type)(x) ^ (type)(y)) > (type)(align) - 1)
|
|
|
|
#define P2SAMEHIGHBIT_TYPED(x, y, type) \
|
|
|
|
(((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
|
2008-03-04 21:22:31 +03:00
|
|
|
|
2019-10-25 23:38:37 +03:00
|
|
|
#define SET_ERROR(err) \
|
|
|
|
(__set_error(__FILE__, __func__, __LINE__, err), err)
|
|
|
|
|
2019-12-03 20:49:40 +03:00
|
|
|
#include <linux/sort.h>
|
|
|
|
#define qsort(base, num, size, cmp) \
|
|
|
|
sort(base, num, size, cmp, NULL)
|
|
|
|
|
|
|
|
#if !defined(_KMEMUSER) && !defined(offsetof)
|
2008-03-04 21:22:31 +03:00
|
|
|
|
|
|
|
/* avoid any possibility of clashing with <stddef.h> version */
|
|
|
|
|
2018-02-07 22:49:38 +03:00
|
|
|
#define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
|
2008-03-04 21:22:31 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _SPL_SYSMACROS_H */
|