Home | History | Annotate | Download | only in os
      1 #ifndef FIO_OS_SOLARIS_H
      2 #define FIO_OS_SOLARIS_H
      3 
      4 #define	FIO_OS	os_solaris
      5 
      6 #include <errno.h>
      7 #include <malloc.h>
      8 #include <unistd.h>
      9 #include <sys/types.h>
     10 #include <sys/fcntl.h>
     11 #include <sys/pset.h>
     12 #include <sys/mman.h>
     13 #include <sys/dkio.h>
     14 #include <sys/byteorder.h>
     15 
     16 #include "../file.h"
     17 
     18 #define FIO_HAVE_CPU_AFFINITY
     19 #define FIO_HAVE_CHARDEV_SIZE
     20 #define FIO_USE_GENERIC_BDEV_SIZE
     21 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
     22 #define FIO_HAVE_GETTID
     23 
     24 #define OS_MAP_ANON		MAP_ANON
     25 #define OS_RAND_MAX		2147483648UL
     26 
     27 #define fio_swap16(x)	BSWAP_16(x)
     28 #define fio_swap32(x)	BSWAP_32(x)
     29 #define fio_swap64(x)	BSWAP_64(x)
     30 
     31 struct solaris_rand_seed {
     32 	unsigned short r[3];
     33 };
     34 
     35 #ifndef POSIX_MADV_SEQUENTIAL
     36 #define posix_madvise	madvise
     37 #define POSIX_MADV_SEQUENTIAL	MADV_SEQUENTIAL
     38 #define POSIX_MADV_DONTNEED	MADV_DONTNEED
     39 #define POSIX_MADV_RANDOM	MADV_RANDOM
     40 #endif
     41 
     42 #define os_ctime_r(x, y, z)     ctime_r((x), (y), (z))
     43 #define FIO_OS_HAS_CTIME_R
     44 
     45 typedef psetid_t os_cpu_mask_t;
     46 typedef struct solaris_rand_seed os_random_state_t;
     47 
     48 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
     49 {
     50 	struct dk_minfo info;
     51 
     52 	*bytes = 0;
     53 
     54 	if (ioctl(f->fd, DKIOCGMEDIAINFO, &info) < 0)
     55 		return errno;
     56 
     57 	*bytes = info.dki_lbsize * info.dki_capacity;
     58 	return 0;
     59 }
     60 
     61 static inline int blockdev_invalidate_cache(struct fio_file *f)
     62 {
     63 	return ENOTSUP;
     64 }
     65 
     66 static inline unsigned long long os_phys_mem(void)
     67 {
     68 	return 0;
     69 }
     70 
     71 static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
     72 {
     73 	rs->r[0] = seed & 0xffff;
     74 	seed >>= 16;
     75 	rs->r[1] = seed & 0xffff;
     76 	seed >>= 16;
     77 	rs->r[2] = seed & 0xffff;
     78 	seed48(rs->r);
     79 }
     80 
     81 static inline long os_random_long(os_random_state_t *rs)
     82 {
     83 	return nrand48(rs->r);
     84 }
     85 
     86 #define FIO_OS_DIRECTIO
     87 extern int directio(int, int);
     88 static inline int fio_set_odirect(int fd)
     89 {
     90 	if (directio(fd, DIRECTIO_ON) < 0)
     91 		return errno;
     92 
     93 	return 0;
     94 }
     95 
     96 /*
     97  * pset binding hooks for fio
     98  */
     99 #define fio_setaffinity(pid, cpumask)		\
    100 	pset_bind((cpumask), P_PID, (pid), NULL)
    101 #define fio_getaffinity(pid, ptr)	({ 0; })
    102 
    103 #define fio_cpu_clear(mask, cpu)	pset_assign(PS_NONE, (cpu), NULL)
    104 #define fio_cpu_set(mask, cpu)		pset_assign(*(mask), (cpu), NULL)
    105 
    106 static inline int fio_cpu_isset(os_cpu_mask_t *mask, int cpu)
    107 {
    108 	const unsigned int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
    109 	unsigned int num_cpus;
    110 	processorid_t *cpus;
    111 	int i, ret;
    112 
    113 	cpus = malloc(sizeof(*cpus) * max_cpus);
    114 
    115 	if (pset_info(*mask, NULL, &num_cpus, cpus) < 0) {
    116 		free(cpus);
    117 		return 0;
    118 	}
    119 
    120 	ret = 0;
    121 	for (i = 0; i < num_cpus; i++) {
    122 		if (cpus[i] == cpu) {
    123 			ret = 1;
    124 			break;
    125 		}
    126 	}
    127 
    128 	free(cpus);
    129 	return ret;
    130 }
    131 
    132 static inline int fio_cpu_count(os_cpu_mask_t *mask)
    133 {
    134 	unsigned int num_cpus;
    135 
    136 	if (pset_info(*mask, NULL, &num_cpus, NULL) < 0)
    137 		return 0;
    138 
    139 	return num_cpus;
    140 }
    141 
    142 static inline int fio_cpuset_init(os_cpu_mask_t *mask)
    143 {
    144 	if (pset_create(mask) < 0)
    145 		return -1;
    146 
    147 	return 0;
    148 }
    149 
    150 static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
    151 {
    152 	if (pset_destroy(*mask) < 0)
    153 		return -1;
    154 
    155 	return 0;
    156 }
    157 
    158 static inline int gettid(void)
    159 {
    160 	return pthread_self();
    161 }
    162 
    163 /*
    164  * Should be enough, not aware of what (if any) restrictions Solaris has
    165  */
    166 #define FIO_MAX_CPUS			16384
    167 
    168 #ifdef MADV_FREE
    169 #define FIO_MADV_FREE	MADV_FREE
    170 #endif
    171 
    172 #endif
    173