1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  24  * Copyright 2017 RackTop Systems.
  25  *
  26  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  27  * Use is subject to license terms.
  28  */
  29 
  30 #ifndef _LGRP_USER_H
  31 #define _LGRP_USER_H
  32 
  33 /*
  34  * latency group definitions for user
  35  */
  36 
  37 #ifdef  __cplusplus
  38 extern "C" {
  39 #endif
  40 
  41 
  42 #include <sys/inttypes.h>
  43 #include <sys/lgrp.h>
  44 #include <sys/procset.h>
  45 #include <sys/processor.h>
  46 #include <sys/pset.h>
  47 #include <sys/types.h>
  48 
  49 
  50 /*
  51  * lgroup interface version
  52  */
  53 #define LGRP_VER_NONE           0       /* no lgroup interface version */
  54 #define LGRP_VER_CURRENT        2       /* current lgroup interface version */
  55 
  56 
  57 /*
  58  * lgroup system call subcodes
  59  */
  60 #define LGRP_SYS_MEMINFO        0       /* meminfo(2) aka MISYS_MEMINFO */
  61 #define LGRP_SYS_GENERATION     1       /* lgrp_generation() */
  62 #define LGRP_SYS_VERSION        2       /* lgrp_version() */
  63 #define LGRP_SYS_SNAPSHOT       3       /* lgrp_snapshot() */
  64 #define LGRP_SYS_AFFINITY_GET   4       /* lgrp_affinity_set() */
  65 #define LGRP_SYS_AFFINITY_SET   5       /* lgrp_affinity_get() */
  66 #define LGRP_SYS_LATENCY        6       /* lgrp_latency() */
  67 #define LGRP_SYS_HOME           7       /* lgrp_home() */
  68 
  69 
  70 /*
  71  * lgroup resources
  72  */
  73 #define LGRP_RSRC_COUNT         2       /* no. of resource types in lgroup */
  74 #define LGRP_RSRC_CPU           0       /* CPU resources */
  75 #define LGRP_RSRC_MEM           1       /* memory resources */
  76 
  77 typedef int lgrp_rsrc_t;
  78 
  79 
  80 
  81 /*
  82  * lgroup affinity
  83  */
  84 #define LGRP_AFF_NONE           0x0     /* no affinity */
  85 #define LGRP_AFF_WEAK           0x10    /* weak affinity */
  86 #define LGRP_AFF_STRONG         0x100   /* strong affinity */
  87 
  88 typedef int lgrp_affinity_t;
  89 
  90 /*
  91  * Arguments to lgrp_affinity_{get,set}()
  92  */
  93 typedef struct lgrp_affinity_args {
  94         idtype_t        idtype; /* ID type */
  95         id_t            id;     /* ID */
  96         lgrp_id_t       lgrp;   /* lgroup */
  97         lgrp_affinity_t aff;    /* affinity */
  98 } lgrp_affinity_args_t;
  99 
 100 
 101 /*
 102  * Flags to specify contents of lgroups desired
 103  */
 104 typedef enum lgrp_content {
 105         LGRP_CONTENT_ALL,       /* everything in lgroup */
 106             /* everything in lgroup's hierarchy (for compatability) */
 107         LGRP_CONTENT_HIERARCHY = LGRP_CONTENT_ALL,
 108         LGRP_CONTENT_DIRECT     /* what's directly contained in lgroup */
 109 } lgrp_content_t;
 110 
 111 
 112 /*
 113  * Flags for lgrp_latency_cookie() specifying what hardware resources to get
 114  * latency between
 115  */
 116 typedef enum lgrp_lat_between {
 117         LGRP_LAT_CPU_TO_MEM     /* latency between CPU and memory */
 118 } lgrp_lat_between_t;
 119 
 120 
 121 /*
 122  * lgroup memory size type
 123  */
 124 typedef longlong_t      lgrp_mem_size_t;
 125 
 126 
 127 /*
 128  * lgroup memory size flags
 129  */
 130 typedef enum lgrp_mem_size_flag {
 131         LGRP_MEM_SZ_FREE,               /* free memory */
 132         LGRP_MEM_SZ_INSTALLED           /* installed memory */
 133 } lgrp_mem_size_flag_t;
 134 
 135 
 136 /*
 137  * View of lgroups
 138  */
 139 typedef enum lgrp_view {
 140         LGRP_VIEW_CALLER,       /* what's available to the caller */
 141         LGRP_VIEW_OS            /* what's available to operating system */
 142 } lgrp_view_t;
 143 
 144 
 145 /*
 146  * lgroup information needed by user
 147  */
 148 typedef struct lgrp_info {
 149         lgrp_id_t       info_lgrpid;            /* lgroup ID */
 150         int             info_latency;           /* latency */
 151         ulong_t         *info_parents;          /* parent lgroups */
 152         ulong_t         *info_children;         /* children lgroups */
 153         ulong_t         *info_rset;             /* lgroup resources */
 154         pgcnt_t         info_mem_free;          /* free memory */
 155         pgcnt_t         info_mem_install;       /* installed memory */
 156         processorid_t   *info_cpuids;           /* CPU IDs */
 157         int             info_ncpus;             /* number of CPUs */
 158 } lgrp_info_t;
 159 
 160 
 161 /*
 162  * Type of lgroup cookie to use with interface routines
 163  */
 164 typedef uintptr_t       lgrp_cookie_t;
 165 
 166 #define LGRP_COOKIE_NONE        0       /* no cookie */
 167 
 168 
 169 /*
 170  * Type of lgroup generation number
 171  */
 172 typedef uint_t  lgrp_gen_t;
 173 
 174 
 175 /*
 176  * Format of lgroup hierarchy snapshot
 177  */
 178 typedef struct lgrp_snapshot_header {
 179         int             ss_version;     /* lgroup interface version */
 180         int             ss_levels;      /* levels of hierarchy */
 181         int             ss_nlgrps;      /* number of lgroups */
 182         int             ss_nlgrps_os;   /* number of lgroups (OS view) */
 183         int             ss_nlgrps_max;  /* maximum number of lgroups */
 184         int             ss_root;        /* root lgroup */
 185         int             ss_ncpus;       /* total number of CPUs */
 186         lgrp_view_t     ss_view;        /* view of lgroup hierarchy */
 187         psetid_t        ss_pset;        /* caller's pset ID */
 188         lgrp_gen_t      ss_gen;         /* snapshot generation ID */
 189         size_t          ss_size;        /* total size of snapshot */
 190         uintptr_t       ss_magic;       /* snapshot magic number */
 191         lgrp_info_t     *ss_info;       /* lgroup info array */
 192         processorid_t   *ss_cpuids;     /* lgroup CPU ID array */
 193         ulong_t         *ss_lgrpset;    /* bit mask of available lgroups */
 194         ulong_t         *ss_parents;    /* lgroup parent bit masks */
 195         ulong_t         *ss_children;   /* lgroup children bit masks */
 196         ulong_t         *ss_rsets;      /* lgroup resource set bit masks */
 197         int             **ss_latencies; /* latencies between lgroups */
 198 } lgrp_snapshot_header_t;
 199 
 200 
 201 #ifdef  _SYSCALL32
 202 /*
 203  * lgroup information needed by 32-bit user
 204  */
 205 typedef struct lgrp_info32 {
 206         int             info_lgrpid;            /* lgroup ID */
 207         int             info_latency;           /* latency */
 208         caddr32_t       info_parents;           /* parent lgroups */
 209         caddr32_t       info_children;          /* children lgroups */
 210         caddr32_t       info_rset;              /* lgroup resources */
 211         uint32_t        info_mem_free;          /* free memory */
 212         uint32_t        info_mem_install;       /* installed memory */
 213         caddr32_t       info_cpuids;            /* CPU IDs */
 214         int             info_ncpus;             /* number of CPUs */
 215 } lgrp_info32_t;
 216 
 217 
 218 /*
 219  * Format of lgroup hierarchy snapshot for 32-bit programs
 220  */
 221 typedef struct lgrp_snapshot_header32 {
 222         int             ss_version;     /* lgroup interface version */
 223         int             ss_levels;      /* levels of hierarchy */
 224         int             ss_nlgrps;      /* number of lgroups */
 225         int             ss_nlgrps_os;   /* number of lgroups (OS view) */
 226         int             ss_nlgrps_max;  /* maximum number of lgroups */
 227         int             ss_root;        /* root lgroup */
 228         int             ss_ncpus;       /* total number of CPUs */
 229         int             ss_view;        /* view of lgroup hierarchy */
 230         int             ss_pset;        /* caller's pset ID */
 231         uint_t          ss_gen;         /* snapshot generation ID */
 232         size32_t        ss_size;        /* total size of snapshot */
 233         uint32_t        ss_magic;       /* snapshot magic number */
 234         caddr32_t       ss_info;        /* lgroup info array */
 235         caddr32_t       ss_cpuids;      /* lgroup CPU ID array */
 236         caddr32_t       ss_lgrpset;     /* bit mask of available lgroups */
 237         caddr32_t       ss_parents;     /* lgroup parent bit masks */
 238         caddr32_t       ss_children;    /* lgroup children bit masks */
 239         caddr32_t       ss_rsets;       /* lgroup resource set bit masks */
 240         caddr32_t       ss_latencies;   /* latencies between lgroups */
 241 } lgrp_snapshot_header32_t;
 242 
 243 #endif  /* _SYSCALL32 */
 244 
 245 
 246 #if !defined(_KERNEL) && !defined(_FAKE_KERNEL) && !defined(_KMEMUSER)
 247 
 248 lgrp_affinity_t lgrp_affinity_get(idtype_t idtype, id_t id, lgrp_id_t lgrp);
 249 
 250 int             lgrp_affinity_set(idtype_t idtype, id_t id, lgrp_id_t lgrp,
 251     lgrp_affinity_t aff);
 252 
 253 int             lgrp_children(lgrp_cookie_t cookie, lgrp_id_t lgrp,
 254     lgrp_id_t *children, uint_t count);
 255 
 256 int             lgrp_cookie_stale(lgrp_cookie_t cookie);
 257 
 258 int             lgrp_cpus(lgrp_cookie_t cookie, lgrp_id_t lgrp,
 259     processorid_t *cpuids, uint_t count, lgrp_content_t content);
 260 
 261 int             lgrp_fini(lgrp_cookie_t cookie);
 262 
 263 int             lgrp_latency(lgrp_id_t from, lgrp_id_t to);
 264 
 265 int             lgrp_latency_cookie(lgrp_cookie_t cookie, lgrp_id_t from,
 266     lgrp_id_t to, lgrp_lat_between_t between);
 267 
 268 lgrp_id_t       lgrp_home(idtype_t idtype, id_t id);
 269 
 270 lgrp_cookie_t   lgrp_init(lgrp_view_t view);
 271 
 272 lgrp_mem_size_t lgrp_mem_size(lgrp_cookie_t cookie, lgrp_id_t lgrp,
 273     lgrp_mem_size_flag_t type, lgrp_content_t content);
 274 
 275 int             lgrp_nlgrps(lgrp_cookie_t cookie);
 276 
 277 int             lgrp_parents(lgrp_cookie_t cookie, lgrp_id_t lgrp,
 278     lgrp_id_t *parents, uint_t count);
 279 
 280 int             lgrp_resources(lgrp_cookie_t cookie, lgrp_id_t lgrp,
 281     lgrp_id_t *lgrps, uint_t count, lgrp_rsrc_t type);
 282 
 283 lgrp_id_t       lgrp_root(lgrp_cookie_t cookie);
 284 
 285 int             lgrp_version(int version);
 286 
 287 lgrp_view_t     lgrp_view(lgrp_cookie_t cookie);
 288 
 289 #endif  /* !_KERNEL && !_FAKE_KERNEL && !_KMEMUSER */
 290 
 291 #ifdef  __cplusplus
 292 }
 293 #endif
 294 
 295 #endif /* _LGRP_USER_H */