VIR_LOG_INIT("util.virresctrl")
-/* Common definitions */
-#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl"
-
/* Resctrl is short for Resource Control. It might be implemented for various
* resources, but at the time of this writing this is only supported for cache
* allocation technology (aka CAT). Hence the reson for leaving 'Cache' out of
* all the structure and function names for now (can be added later if needed.
*/
+
+/* Common definitions */
+#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl"
+
+
/* Our naming for cache types and scopes */
VIR_ENUM_IMPL(virCache, VIR_CACHE_TYPE_LAST,
"both",
"code",
"data")
-
/*
* This is the same enum, but for the resctrl naming
* of the type (L<level><type>)
"DATA")
-/* Info-related definitions and InfoClass-related functions */
+/* All private typedefs so that they exist for all later definitions. This way
+ * structs can be included in one or another without reorganizing the code every
+ * time. */
typedef struct _virResctrlInfoPerType virResctrlInfoPerType;
typedef virResctrlInfoPerType *virResctrlInfoPerTypePtr;
+
+typedef struct _virResctrlInfoPerLevel virResctrlInfoPerLevel;
+typedef virResctrlInfoPerLevel *virResctrlInfoPerLevelPtr;
+
+typedef struct _virResctrlAllocPerType virResctrlAllocPerType;
+typedef virResctrlAllocPerType *virResctrlAllocPerTypePtr;
+
+typedef struct _virResctrlAllocPerLevel virResctrlAllocPerLevel;
+typedef virResctrlAllocPerLevel *virResctrlAllocPerLevelPtr;
+
+
+/* Class definitions and initializations */
+static virClassPtr virResctrlInfoClass;
+static virClassPtr virResctrlAllocClass;
+
+
+/* virResctrlInfo */
struct _virResctrlInfoPerType {
/* Kernel-provided information */
char *cbm_mask;
virResctrlInfoPerCache control;
};
-typedef struct _virResctrlInfoPerLevel virResctrlInfoPerLevel;
-typedef virResctrlInfoPerLevel *virResctrlInfoPerLevelPtr;
struct _virResctrlInfoPerLevel {
virResctrlInfoPerTypePtr *types;
};
size_t nlevels;
};
-static virClassPtr virResctrlInfoClass;
static void
virResctrlInfoDispose(void *obj)
}
-static int
-virResctrlInfoOnceInit(void)
-{
- if (!VIR_CLASS_NEW(virResctrlInfo, virClassForObject()))
- return -1;
-
- return 0;
-}
-
-
-VIR_ONCE_GLOBAL_INIT(virResctrlInfo)
-
-
-virResctrlInfoPtr
-virResctrlInfoNew(void)
-{
- if (virResctrlInfoInitialize() < 0)
- return NULL;
-
- return virObjectNew(virResctrlInfoClass);
-}
-
-
-/* Alloc-related definitions and AllocClass-related functions */
+/* virResctrlAlloc */
/*
* virResctrlAlloc represents one allocation (in XML under cputune/cachetune and
* virBitmaps named `masks` indexed the same way as `sizes`. The upper bounds
* of the sparse arrays are stored in nmasks or nsizes, respectively.
*/
-typedef struct _virResctrlAllocPerType virResctrlAllocPerType;
-typedef virResctrlAllocPerType *virResctrlAllocPerTypePtr;
struct _virResctrlAllocPerType {
/* There could be bool saying whether this is set or not, but since everything
* in virResctrlAlloc (and most of libvirt) goes with pointer arrays we would
size_t nmasks;
};
-typedef struct _virResctrlAllocPerLevel virResctrlAllocPerLevel;
-typedef virResctrlAllocPerLevel *virResctrlAllocPerLevelPtr;
struct _virResctrlAllocPerLevel {
virResctrlAllocPerTypePtr *types; /* Indexed with enum virCacheType */
/* There is no `ntypes` member variable as it is always allocated for
char *path;
};
-static virClassPtr virResctrlAllocClass;
static void
virResctrlAllocDispose(void *obj)
}
+/* Global initialization for classes */
static int
-virResctrlAllocOnceInit(void)
+virResctrlOnceInit(void)
{
+ if (!VIR_CLASS_NEW(virResctrlInfo, virClassForObject()))
+ return -1;
+
if (!VIR_CLASS_NEW(virResctrlAlloc, virClassForObject()))
return -1;
return 0;
}
-
-VIR_ONCE_GLOBAL_INIT(virResctrlAlloc)
-
-
-virResctrlAllocPtr
-virResctrlAllocNew(void)
-{
- if (virResctrlAllocInitialize() < 0)
- return NULL;
-
- return virObjectNew(virResctrlAllocClass);
-}
+VIR_ONCE_GLOBAL_INIT(virResctrl)
/* Common functions */
}
-/* Info-related functions */
-static bool
-virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl)
-{
- size_t i = 0;
- size_t j = 0;
-
- if (!resctrl)
- return true;
-
- for (i = 0; i < resctrl->nlevels; i++) {
- virResctrlInfoPerLevelPtr i_level = resctrl->levels[i];
-
- if (!i_level)
- continue;
-
- for (j = 0; j < VIR_CACHE_TYPE_LAST; j++) {
- if (i_level->types[j])
- return false;
- }
- }
-
- return true;
-}
-
-
+/* virResctrlInfo-related definitions */
int
virResctrlGetInfo(virResctrlInfoPtr resctrl)
{
}
+virResctrlInfoPtr
+virResctrlInfoNew(void)
+{
+ if (virResctrlInitialize() < 0)
+ return NULL;
+
+ return virObjectNew(virResctrlInfoClass);
+}
+
+
+static bool
+virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl)
+{
+ size_t i = 0;
+ size_t j = 0;
+
+ if (!resctrl)
+ return true;
+
+ for (i = 0; i < resctrl->nlevels; i++) {
+ virResctrlInfoPerLevelPtr i_level = resctrl->levels[i];
+
+ if (!i_level)
+ continue;
+
+ for (j = 0; j < VIR_CACHE_TYPE_LAST; j++) {
+ if (i_level->types[j])
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
int
virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
unsigned int level,
}
-/* Alloc-related functions */
+/* virResctrlAlloc-related definitions */
+virResctrlAllocPtr
+virResctrlAllocNew(void)
+{
+ if (virResctrlInitialize() < 0)
+ return NULL;
+
+ return virObjectNew(virResctrlAllocClass);
+}
+
+
bool
virResctrlAllocIsEmpty(virResctrlAllocPtr alloc)
{