resctrl: Add functions to work with resctrl allocations

With this commit we finally have a way to read and manipulate basic resctrl
settings.  Locking is done only on exposed functions that read/write from/to
resctrlfs.  Not in functions that are exposed in virresctrlpriv.h as those are
only supposed to be used from tests.

More information about how resctrl works:

  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/x86/intel_rdt_ui.txt

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2017-10-16 17:17:32 +02:00
parent 434848d7dc
commit a64c761c27
5 changed files with 1260 additions and 2 deletions

View File

@ -167,7 +167,7 @@ UTIL_SOURCES = \
util/virprocess.c util/virprocess.h \ util/virprocess.c util/virprocess.h \
util/virqemu.c util/virqemu.h \ util/virqemu.c util/virqemu.h \
util/virrandom.h util/virrandom.c \ util/virrandom.h util/virrandom.c \
util/virresctrl.h util/virresctrl.c \ util/virresctrl.h util/virresctrl.c util/virresctrlpriv.h \
util/virrotatingfile.h util/virrotatingfile.c \ util/virrotatingfile.h util/virrotatingfile.c \
util/virscsi.c util/virscsi.h \ util/virscsi.c util/virscsi.h \
util/virscsihost.c util/virscsihost.h \ util/virscsihost.c util/virscsihost.h \

View File

@ -2552,6 +2552,16 @@ virRandomInt;
# util/virresctrl.h # util/virresctrl.h
virCacheTypeFromString; virCacheTypeFromString;
virCacheTypeToString; virCacheTypeToString;
virResctrlAllocAddPID;
virResctrlAllocCreate;
virResctrlAllocForeachSize;
virResctrlAllocFormat;
virResctrlAllocGetID;
virResctrlAllocGetUnused;
virResctrlAllocNew;
virResctrlAllocRemove;
virResctrlAllocSetID;
virResctrlAllocSetSize;
virResctrlGetInfo; virResctrlGetInfo;
virResctrlInfoGetCache; virResctrlInfoGetCache;
virResctrlInfoNew; virResctrlInfoNew;

File diff suppressed because it is too large Load Diff

View File

@ -65,4 +65,53 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
size_t *ncontrols, size_t *ncontrols,
virResctrlInfoPerCachePtr **controls); virResctrlInfoPerCachePtr **controls);
/* Alloc-related things */
typedef struct _virResctrlAlloc virResctrlAlloc;
typedef virResctrlAlloc *virResctrlAllocPtr;
typedef int virResctrlAllocForeachSizeCallback(unsigned int level,
virCacheType type,
unsigned int cache,
unsigned long long size,
void *opaque);
virResctrlAllocPtr
virResctrlAllocNew(void);
bool
virResctrlAllocIsEmpty(virResctrlAllocPtr resctrl);
int
virResctrlAllocSetSize(virResctrlAllocPtr resctrl,
unsigned int level,
virCacheType type,
unsigned int cache,
unsigned long long size);
int
virResctrlAllocForeachSize(virResctrlAllocPtr resctrl,
virResctrlAllocForeachSizeCallback cb,
void *opaque);
int
virResctrlAllocSetID(virResctrlAllocPtr alloc,
const char *id);
const char *
virResctrlAllocGetID(virResctrlAllocPtr alloc);
char *
virResctrlAllocFormat(virResctrlAllocPtr alloc);
int
virResctrlAllocCreate(virResctrlInfoPtr r_info,
virResctrlAllocPtr alloc,
const char *machinename);
int
virResctrlAllocAddPID(virResctrlAllocPtr alloc,
pid_t pid);
int
virResctrlAllocRemove(virResctrlAllocPtr alloc);
#endif /* __VIR_RESCTRL_H__ */ #endif /* __VIR_RESCTRL_H__ */

27
src/util/virresctrlpriv.h Normal file
View File

@ -0,0 +1,27 @@
/*
* virresctrlpriv.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/>.
*/
#ifndef __VIR_RESCTRL_PRIV_H__
# define __VIR_RESCTRL_PRIV_H__
# include "virresctrl.h"
virResctrlAllocPtr
virResctrlAllocGetUnused(virResctrlInfoPtr resctrl);
#endif /* __VIR_RESCTRL_PRIV_H__ */