summaryrefslogtreecommitdiff
path: root/virtinst/domain/cputune.py
blob: 8e7f740d1f2fc0e6dfaeec6058c14dbf084bc65a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
#
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.

from ..xmlbuilder import XMLBuilder, XMLProperty, XMLChildProperty


###############
# CPU Pinning #
###############

class _VCPUPin(XMLBuilder):
    """
    Class for generating <cputune> child <vcpupin> XML
    """
    XML_NAME = "vcpupin"
    _XML_PROP_ORDER = ["vcpu", "cpuset"]

    vcpu = XMLProperty("./@vcpu", is_int=True)
    cpuset = XMLProperty("./@cpuset")


class _IOThreadPin(XMLBuilder):
    """
    Class for generating <cputune> child <iothreadpin> XML
    """
    XML_NAME = "iothreadpin"
    _XML_PROP_ORDER = ["iothread", "cpuset"]

    iothread = XMLProperty("./@iothread", is_int=True)
    cpuset = XMLProperty("./@cpuset")


##############
# Scheduling #
##############

class _VCPUSched(XMLBuilder):
    """
    Class for generating <cputune> child <vcpusched> XML
    """
    XML_NAME = "vcpusched"
    _XML_PROP_ORDER = ["vcpus", "scheduler", "priority"]

    vcpus = XMLProperty("./@vcpus")
    scheduler = XMLProperty("./@scheduler")
    priority = XMLProperty("./@priority", is_int=True)


class _IOThreadSched(XMLBuilder):
    """
    Class for generating <cputune> child <iothreadsched> XML
    """
    XML_NAME = "iothreadsched"
    _XML_PROP_ORDER = ["iothreads", "scheduler", "priority"]

    iothreads = XMLProperty("./@iothreads")
    scheduler = XMLProperty("./@scheduler")
    priority = XMLProperty("./@priority", is_int=True)


###########################
# Cache & Memory Tunables #
###########################

class _CacheTuneCache(XMLBuilder):
    """
    Class for generating <cachetune> child <cache> XML
    """
    XML_NAME = "cache"
    _XML_PROP_ORDER = ["id", "level", "type", "size", "unit"]

    id = XMLProperty("./@id", is_int=True)
    level = XMLProperty("./@level", is_int=True)
    type = XMLProperty("./@type")
    size = XMLProperty("./@size", is_int=True)
    unit = XMLProperty("./@unit")


class _CacheTuneMonitor(XMLBuilder):
    """
    Class for generating <cachetune> child <monitor> XML
    """
    XML_NAME = "monitor"
    _XML_PROP_ORDER = ["level", "vcpus"]

    level = XMLProperty("./@level", is_int=True)
    vcpus = XMLProperty("./@vcpus")


class _CacheTune(XMLBuilder):
    """
    Class for generating <cputune> child <cachetune> XML
    """
    XML_NAME = "cachetune"
    _XML_PROP_ORDER = ["vcpus", "caches"]

    vcpus = XMLProperty("./@vcpus")
    caches = XMLChildProperty(_CacheTuneCache)
    monitors = XMLChildProperty(_CacheTuneMonitor)


class _MemoryTuneNode(XMLBuilder):
    """
    Class for generating <memorytune> child <node> XML
    """
    XML_NAME = "node"
    _XML_PROP_ORDER = ["id", "bandwidth"]

    id = XMLProperty("./@id", is_int=True)
    bandwidth = XMLProperty("./@bandwidth", is_int=True)


class _MemoryTune(XMLBuilder):
    """
    Class for generating <cputune> child <memorytune> XML
    """
    XML_NAME = "memorytune"
    _XML_PROP_ORDER = ["vcpus", "nodes"]

    vcpus = XMLProperty("./@vcpus")
    nodes = XMLChildProperty(_MemoryTuneNode)


#########################
# Actual CPUTune domain #
#########################

class DomainCputune(XMLBuilder):
    """
    Class for generating <cputune> XML
    """
    XML_NAME = "cputune"
    _XML_PROP_ORDER = ["shares", "period", "quota", "global_period", "global_quota",
            "emulator_period", "emulator_quota", "iothread_period", "iothread_quota",
            "vcpupins", "emulatorpin_cpuset", "iothreadpins",
            "emulatorsched_scheduler", "emulatorsched_priority", "vcpuscheds", "iothreadscheds",
            "cachetunes", "memorytunes"]

    # Resource quotas
    shares = XMLProperty("./shares", is_int=True)
    period = XMLProperty("./period", is_int=True)
    quota = XMLProperty("./quota", is_int=True)
    global_period = XMLProperty("./global_period", is_int=True)
    global_quota = XMLProperty("./global_quota", is_int=True)
    emulator_period = XMLProperty("./emulator_period", is_int=True)
    emulator_quota = XMLProperty("./emulator_quota", is_int=True)
    iothread_period = XMLProperty("./iothread_period", is_int=True)
    iothread_quota = XMLProperty("./iothread_quota", is_int=True)

    # CPU Pinning
    vcpupins = XMLChildProperty(_VCPUPin)
    emulatorpin_cpuset = XMLProperty("./emulatorpin/@cpuset")
    iothreadpins = XMLChildProperty(_IOThreadPin)

    # Scheduling
    emulatorsched_scheduler = XMLProperty("./emulatorsched/@scheduler")
    emulatorsched_priority = XMLProperty("./emulatorsched/@priority", is_int=True)
    vcpuscheds = XMLChildProperty(_VCPUSched)
    iothreadscheds = XMLChildProperty(_IOThreadSched)

    # Cache & Memory Tunables
    cachetunes = XMLChildProperty(_CacheTune)
    memorytunes = XMLChildProperty(_MemoryTune)