virresctrl.h 7.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * virresctrl.h:
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

19
#pragma once
20

21
#include "internal.h"
22

23 24 25
#include "virbitmap.h"
#include "virutil.h"
#include "virenum.h"
26 27 28 29 30 31 32 33 34 35

typedef enum {
    VIR_CACHE_TYPE_BOTH,
    VIR_CACHE_TYPE_CODE,
    VIR_CACHE_TYPE_DATA,

    VIR_CACHE_TYPE_LAST
} virCacheType;

VIR_ENUM_DECL(virCache);
36
VIR_ENUM_DECL(virCacheKernel);
37

38 39 40 41 42 43 44 45 46 47
typedef enum {
    VIR_RESCTRL_MONITOR_TYPE_UNSUPPORT,
    VIR_RESCTRL_MONITOR_TYPE_CACHE,
    VIR_RESCTRL_MONITOR_TYPE_MEMBW,

    VIR_RESCTRL_MONITOR_TYPE_LAST
} virResctrlMonitorType;

VIR_ENUM_DECL(virResctrlMonitorPrefix);

48

49 50 51
typedef struct _virResctrlInfoPerCache virResctrlInfoPerCache;
typedef virResctrlInfoPerCache *virResctrlInfoPerCachePtr;
struct _virResctrlInfoPerCache {
52 53 54 55 56 57 58 59 60 61
    /* Smallest possible increase of the allocation size in bytes */
    unsigned long long granularity;
    /* Minimal allocatable size in bytes (if different from granularity) */
    unsigned long long min;
    /* Type of the allocation */
    virCacheType scope;
    /* Maximum number of simultaneous allocations */
    unsigned int max_allocation;
};

62 63 64 65 66 67 68 69 70 71 72
typedef struct _virResctrlInfoMemBWPerNode virResctrlInfoMemBWPerNode;
typedef virResctrlInfoMemBWPerNode *virResctrlInfoMemBWPerNodePtr;
struct _virResctrlInfoMemBWPerNode {
    /* Smallest possible increase of the allocation bandwidth in percentage */
    unsigned int granularity;
    /* Minimal allocatable bandwidth in percentage */
    unsigned int min;
    /* Maximum number of simultaneous allocations */
    unsigned int max_allocation;
};

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
typedef struct _virResctrlInfoMon virResctrlInfoMon;
typedef virResctrlInfoMon *virResctrlInfoMonPtr;
struct _virResctrlInfoMon {
    /* Maximum number of simultaneous monitors */
    unsigned int max_monitor;
    /* null-terminal string list for monitor features */
    char **features;
    /* Number of monitor features */
    size_t nfeatures;
    /* Monitor type */
    virResctrlMonitorType type;
    /* This adjustable value affects the final reuse of resources used by
     * monitor. After the action of removing a monitor, the kernel may not
     * release all hardware resources that monitor used immediately if the
     * cache occupancy value associated with 'removed' monitor is above this
     * threshold. Once the cache occupancy is below this threshold, the
     * underlying hardware resource will be reclaimed and be put into the
     * resource pool for next reusing.*/
    unsigned int cache_reuse_threshold;
    /* The cache 'level' that has the monitor capability */
    unsigned int cache_level;
};

M
Martin Kletzander 已提交
96 97
typedef struct _virResctrlInfo virResctrlInfo;
typedef virResctrlInfo *virResctrlInfoPtr;
98

M
Martin Kletzander 已提交
99 100 101 102 103 104 105 106 107 108
virResctrlInfoPtr
virResctrlInfoNew(void);

int
virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
                       unsigned int level,
                       unsigned long long size,
                       size_t *ncontrols,
                       virResctrlInfoPerCachePtr **controls);

109 110 111 112
int
virResctrlInfoGetMemoryBandwidth(virResctrlInfoPtr resctrl,
                                 unsigned int level,
                                 virResctrlInfoMemBWPerNodePtr control);
113 114 115 116
/* Alloc-related things */
typedef struct _virResctrlAlloc virResctrlAlloc;
typedef virResctrlAlloc *virResctrlAllocPtr;

117 118 119 120 121
typedef int virResctrlAllocForeachCacheCallback(unsigned int level,
                                                virCacheType type,
                                                unsigned int cache,
                                                unsigned long long size,
                                                void *opaque);
122

123 124 125 126
typedef int virResctrlAllocForeachMemoryCallback(unsigned int id,
                                                 unsigned int size,
                                                 void *opaque);

127 128 129 130
virResctrlAllocPtr
virResctrlAllocNew(void);

bool
131
virResctrlAllocIsEmpty(virResctrlAllocPtr alloc);
132 133

int
134 135 136 137 138
virResctrlAllocSetCacheSize(virResctrlAllocPtr alloc,
                            unsigned int level,
                            virCacheType type,
                            unsigned int cache,
                            unsigned long long size);
139 140

int
141 142 143
virResctrlAllocForeachCache(virResctrlAllocPtr alloc,
                            virResctrlAllocForeachCacheCallback cb,
                            void *opaque);
144

145 146 147 148 149
int
virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr alloc,
                                  unsigned int id,
                                  unsigned int memory_bandwidth);

150 151 152 153 154
int
virResctrlAllocForeachMemory(virResctrlAllocPtr resctrl,
                             virResctrlAllocForeachMemoryCallback cb,
                             void *opaque);

155 156 157 158 159 160 161 162 163
int
virResctrlAllocSetID(virResctrlAllocPtr alloc,
                     const char *id);
const char *
virResctrlAllocGetID(virResctrlAllocPtr alloc);

char *
virResctrlAllocFormat(virResctrlAllocPtr alloc);

164 165 166 167
int
virResctrlAllocDeterminePath(virResctrlAllocPtr alloc,
                             const char *machinename);

168 169 170 171 172 173 174 175 176 177 178 179
int
virResctrlAllocCreate(virResctrlInfoPtr r_info,
                      virResctrlAllocPtr alloc,
                      const char *machinename);

int
virResctrlAllocAddPID(virResctrlAllocPtr alloc,
                      pid_t pid);

int
virResctrlAllocRemove(virResctrlAllocPtr alloc);

180 181 182 183 184 185 186
void
virResctrlInfoMonFree(virResctrlInfoMonPtr mon);

int
virResctrlInfoGetMonitorPrefix(virResctrlInfoPtr resctrl,
                               const char *prefix,
                               virResctrlInfoMonPtr *monitor);
187 188 189 190 191 192

/* Monitor-related things */

typedef struct _virResctrlMonitor virResctrlMonitor;
typedef virResctrlMonitor *virResctrlMonitorPtr;

193 194 195 196 197 198 199
typedef struct _virResctrlMonitorStats virResctrlMonitorStats;
typedef virResctrlMonitorStats *virResctrlMonitorStatsPtr;
struct _virResctrlMonitorStats {
    unsigned int id;
    unsigned int val;
};

200 201
virResctrlMonitorPtr
virResctrlMonitorNew(void);
202 203 204 205

int
virResctrlMonitorDeterminePath(virResctrlMonitorPtr monitor,
                               const char *machinename);
206 207 208 209

int
virResctrlMonitorAddPID(virResctrlMonitorPtr monitor,
                        pid_t pid);
210 211 212 213

int
virResctrlMonitorCreate(virResctrlMonitorPtr monitor,
                        const char *machinename);
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

int
virResctrlMonitorSetID(virResctrlMonitorPtr monitor,
                       const char *id);

const char *
virResctrlMonitorGetID(virResctrlMonitorPtr monitor);

void
virResctrlMonitorSetAlloc(virResctrlMonitorPtr monitor,
                          virResctrlAllocPtr alloc);

int
virResctrlMonitorRemove(virResctrlMonitorPtr monitor);

int
virResctrlMonitorGetCacheOccupancy(virResctrlMonitorPtr monitor,
231 232
                                   virResctrlMonitorStatsPtr **stats,
                                   size_t *nstats);
233 234 235 236

void
virResctrlMonitorFreeStats(virResctrlMonitorStatsPtr *stats,
                           size_t nstats);