examples/vm_power: make branch ratio threshold per core
[dpdk.git] / doc / guides / sample_app_ug / vm_power_management.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2010-2014 Intel Corporation.
3
4 Virtual Machine Power Management Application
5 ============================================
6
7 Applications running in virtual environments have an abstract view of
8 the underlying hardware on the host. Specifically, applications cannot
9 see the binding of virtual components to physical hardware. When looking
10 at CPU resourcing, the pinning of Virtual CPUs (vCPUs) to Physical CPUs
11 (pCPUs) on the host is not apparent to an application and this pinning
12 may change over time. In addition, operating systems on Virtual Machines
13 (VMs) do not have the ability to govern their own power policy. The
14 Machine Specific Registers (MSRs) for enabling P-state transitions are
15 not exposed to the operating systems running on the VMs.
16
17 The solution demonstrated in this sample application shows an example of
18 how a DPDK application can indicate its processing requirements using
19 VM-local only information (vCPU/lcore, and so on) to a host resident VM
20 Power Manager. The VM Power Manager is responsible for:
21
22 - **Accepting requests for frequency changes for a vCPU**
23 - **Translating the vCPU to a pCPU using libvirt**
24 - **Performing the change in frequency**
25
26 This application demonstrates the following features:
27
28 - **The handling of VM application requests to change frequency.**
29   VM applications can request frequency changes for a vCPU. The VM
30   Power Management Application uses libvirt to translate that
31   virtual CPU (vCPU) request to a physical CPU (pCPU) request and
32   performs the frequency change.
33
34 - **The acceptance of power management policies from VM applications.**
35   A VM application can send a policy to the host application. The
36   policy contains rules that define the power management behaviour
37   of the VM. The host application then applies the rules of the
38   policy independent of the VM application. For example, the
39   policy can contain time-of-day information for busy/quiet
40   periods, and the host application can scale up/down the relevant
41   cores when required. See :ref:`sending_policy` for information on
42   setting policy values.
43
44 - **Out-of-band monitoring of workloads using core hardware event counters.**
45   The host application can manage power for an application by looking
46   at the event counters of the cores and taking action based on the
47   branch miss/hit ratio. See :ref:`enabling_out_of_band`.
48
49   **Note**: This functionality also applies in non-virtualised environments.
50
51 In addition to the ``librte_power`` library used on the host, the
52 application uses a special version of ``librte_power`` on each VM, which
53 directs frequency changes and policies to the host monitor rather than
54 the APCI ``cpufreq`` ``sysfs`` interface used on the host in non-virtualised
55 environments.
56
57 .. _figure_vm_power_mgr_highlevel:
58
59 .. figure:: img/vm_power_mgr_highlevel.*
60
61    Highlevel Solution
62
63 In the above diagram, the DPDK Applications are shown running in
64 virtual machines, and the VM Power Monitor application is shown running
65 in the host.
66
67 **DPDK VM Application**
68
69 - Reuse ``librte_power`` interface, but uses an implementation that
70   forwards frequency requests to the host using a ``virtio-serial`` channel
71 - Each lcore has exclusive access to a single channel
72 - Sample application reuses ``l3fwd_power``
73 - A CLI for changing frequency from within a VM is also included
74
75 **VM Power Monitor**
76
77 - Accepts VM commands over ``virtio-serial`` endpoints, monitored
78   using ``epoll``
79 - Commands include the virtual core to be modified, using ``libvirt`` to get
80   the physical core mapping
81 - Uses ``librte_power`` to affect frequency changes using Linux userspace
82   power governor (``acpi_cpufreq`` OR ``intel_pstate`` driver)
83 - CLI: For adding VM channels to monitor, inspecting and changing channel
84   state, manually altering CPU frequency. Also allows for the changings
85   of vCPU to pCPU pinning
86
87 Sample Application Architecture Overview
88 ----------------------------------------
89
90 The VM power management solution employs ``qemu-kvm`` to provide
91 communications channels between the host and VMs in the form of a
92 ``virtio-serial`` connection that appears as a para-virtualised serial
93 device on a VM and can be configured to use various backends on the
94 host. For this example, the configuration of each ``virtio-serial`` endpoint
95 on the host as an ``AF_UNIX`` file socket, supporting poll/select and
96 ``epoll`` for event notification. In this example, each channel endpoint on
97 the host is monitored for ``EPOLLIN`` events using ``epoll``. Each channel
98 is specified as ``qemu-kvm`` arguments or as ``libvirt`` XML for each VM,
99 where each VM can have several channels up to a maximum of 64 per VM. In this
100 example, each DPDK lcore on a VM has exclusive access to a channel.
101
102 To enable frequency changes from within a VM, the VM forwards a
103 ``librte_power`` request over the ``virtio-serial`` channel to the host. Each
104 request contains the vCPU and power command (scale up/down/min/max). The
105 API for the host ``librte_power`` and guest ``librte_power`` is consistent
106 across environments, with the selection of VM or host implementation
107 determined automatically at runtime based on the environment. On
108 receiving a request, the host translates the vCPU to a pCPU using the
109 libvirt API before forwarding it to the host ``librte_power``.
110
111
112 .. _figure_vm_power_mgr_vm_request_seq:
113
114 .. figure:: img/vm_power_mgr_vm_request_seq.*
115
116 In addition to the ability to send power management requests to the
117 host, a VM can send a power management policy to the host. In some
118 cases, using a power management policy is a preferred option because it
119 can eliminate possible latency issues that can occur when sending power
120 management requests. Once the VM sends the policy to the host, the VM no
121 longer needs to worry about power management, because the host now
122 manages the power for the VM based on the policy. The policy can specify
123 power behavior that is based on incoming traffic rates or time-of-day
124 power adjustment (busy/quiet hour power adjustment for example). See
125 :ref:`sending_policy` for more information.
126
127 One method of power management is to sense how busy a core is when
128 processing packets and adjusting power accordingly. One technique for
129 doing this is to monitor the ratio of the branch miss to branch hits
130 counters and scale the core power accordingly. This technique is based
131 on the premise that when a core is not processing packets, the ratio of
132 branch misses to branch hits is very low, but when the core is
133 processing packets, it is measurably higher. The implementation of this
134 capability is as a policy of type ``BRANCH_RATIO``.
135 See :ref:`sending_policy` for more information on using the
136 BRANCH_RATIO policy option.
137
138 A JSON interface enables the specification of power management requests
139 and policies in JSON format. The JSON interfaces provide a more
140 convenient and more easily interpreted interface for the specification
141 of requests and policies. See :ref:`power_man_requests` for more information.
142
143 Performance Considerations
144 ~~~~~~~~~~~~~~~~~~~~~~~~~~
145
146 While the Haswell microarchitecture allows for independent power control
147 for each core, earlier microarchitectures do not offer such fine-grained
148 control. When deploying on pre-Haswell platforms, greater care must be
149 taken when selecting which cores are assigned to a VM, for example, a
150 core does not scale down in frequency until all of its siblings are
151 similarly scaled down.
152
153 Configuration
154 -------------
155
156 BIOS
157 ~~~~
158
159 To use the power management features of the DPDK, you must enable
160 Enhanced Intel SpeedStep® Technology in the platform BIOS. Otherwise,
161 the ``sys`` file folder ``/sys/devices/system/cpu/cpu0/cpufreq`` does not
162 exist, and you cannot use CPU frequency-based power management. Refer to the
163 relevant BIOS documentation to determine how to access these settings.
164
165 Host Operating System
166 ~~~~~~~~~~~~~~~~~~~~~
167
168 The DPDK Power Management library can use either the ``acpi_cpufreq`` or
169 the ``intel_pstate`` kernel driver for the management of core frequencies. In
170 many cases, the ``intel_pstate`` driver is the default power management
171 environment.
172
173 Should the ``acpi-cpufreq driver`` be required, the ``intel_pstate``
174 module must be disabled, and the ``acpi-cpufreq`` module loaded in its place.
175
176 To disable the ``intel_pstate`` driver, add the following to the ``grub``
177 Linux command line:
178
179    ``intel_pstate=disable``
180
181 On reboot, load the ``acpi_cpufreq`` module:
182
183    ``modprobe acpi_cpufreq``
184
185 Hypervisor Channel Configuration
186 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187
188 Configure ``virtio-serial`` channels using ``libvirt`` XML.
189 The XML structure is as follows: 
190
191 .. code-block:: XML
192
193    <name>{vm_name}</name>
194    <controller type='virtio-serial' index='0'>
195       <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
196    </controller>
197    <channel type='unix'>
198       <source mode='bind' path='/tmp/powermonitor/{vm_name}.{channel_num}'/>
199       <target type='virtio' name='virtio.serial.port.poweragent.{vm_channel_num}'/>
200       <address type='virtio-serial' controller='0' bus='0' port='{N}'/>
201    </channel>
202
203 Where a single controller of type ``virtio-serial`` is created, up to 32
204 channels can be associated with a single controller, and multiple
205 controllers can be specified. The convention is to use the name of the
206 VM in the host path ``{vm_name}`` and to increment ``{channel_num}`` for each
207 channel. Likewise, the port value ``{N}`` must be incremented for each
208 channel.
209
210 On the host, for each channel to appear in the path, ensure the creation
211 of the ``/tmp/powermonitor/`` directory and the assignment of ``qemu``
212 permissions:
213
214 .. code-block:: console
215
216    mkdir /tmp/powermonitor/
217    chown qemu:qemu /tmp/powermonitor
218
219 Note that files and directories in ``/tmp`` are generally removed when
220 rebooting the host and you may need to perform the previous steps after
221 each reboot.
222
223 The serial device as it appears on a VM is configured with the target
224 element attribute name and must be in the form:
225 ``virtio.serial.port.poweragent.{vm_channel_num}``, where
226 ``vm_channel_num`` is typically the lcore channel to be used in
227 DPDK VM applications.
228
229 Each channel on a VM is present at:
230
231 ``/dev/virtio-ports/virtio.serial.port.poweragent.{vm_channel_num}``
232
233 Compiling and Running the Host Application
234 ------------------------------------------
235
236 Compiling the Host Application
237 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
238
239 For information on compiling the DPDK and sample applications, see
240 see :doc:`compiling`.
241
242 The application is located in the ``vm_power_manager`` subdirectory.
243
244 To build just the ``vm_power_manager`` application using ``make``:
245
246 .. code-block:: console
247
248    export RTE_SDK=/path/to/rte_sdk
249    export RTE_TARGET=build
250    cd ${RTE_SDK}/examples/vm_power_manager/
251    make
252
253 The resulting binary is ``${RTE_SDK}/build/examples/vm_power_manager``.
254
255 To build just the ``vm_power_manager`` application using ``meson``/``ninja``:
256
257 .. code-block:: console
258
259    export RTE_SDK=/path/to/rte_sdk
260    cd ${RTE_SDK}
261    meson build
262    cd build
263    ninja
264    meson configure -Dexamples=vm_power_manager
265    ninja
266
267 The resulting binary is ``${RTE_SDK}/build/examples/dpdk-vm_power_manager``.
268
269 Running the Host Application
270 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
271
272 The application does not have any specific command line options other
273 than the EAL options:
274
275 .. code-block:: console
276
277    ./build/vm_power_mgr [EAL options]
278
279 The application requires exactly two cores to run. One core for the CLI
280 and the other for the channel endpoint monitor. For example, to run on
281 cores 0 and 1 on a system with four memory channels, issue the command:
282
283 .. code-block:: console
284
285    ./build/vm_power_mgr -l 0-1 -n 4
286
287 After successful initialization, the VM Power Manager CLI prompt appears:
288
289 .. code-block:: console
290
291    vm_power>
292
293 Now, it is possible to add virtual machines to the VM Power Manager:
294
295 .. code-block:: console
296
297    vm_power> add_vm {vm_name}
298
299 When a ``{vm_name}`` is specified with the ``add_vm`` command, a lookup is
300 performed with ``libvirt`` to ensure that the VM exists. ``{vm_name}`` is a
301 unique identifier to associate channels with a particular VM and for
302 executing operations on a VM within the CLI. VMs do not have to be
303 running to add them.
304
305 It is possible to issue several commands from the CLI to manage VMs.
306
307 Remove the virtual machine identified by ``{vm_name}`` from the VM Power
308 Manager using the command:
309
310 .. code-block:: console
311
312    rm_vm {vm_name}
313
314 Add communication channels for the specified VM using the following
315 command. The ``virtio`` channels must be enabled in the VM configuration
316 (``qemu/libvirt``) and the associated VM must be active. ``{list}`` is a
317 comma-separated list of channel numbers to add. Specifying the keyword
318 ``all`` attempts to add all channels for the VM:
319
320 .. code-block:: console
321
322    set_pcpu {vm_name} {vcpu} {pcpu}
323
324   Enable query of physical core information from a VM:
325
326 .. code-block:: console
327
328    set_query {vm_name} enable|disable
329
330 Manual control and inspection can also be carried in relation CPU frequency scaling:
331
332   Get the current frequency for each core specified in the mask:
333
334 .. code-block:: console
335
336    show_cpu_freq_mask {mask}
337
338   Set the current frequency for the cores specified in {core_mask} by scaling each up/down/min/max:
339
340 .. code-block:: console
341
342    add_channels {vm_name} {list}|all
343
344 Enable or disable the communication channels in ``{list}`` (comma-separated)
345 for the specified VM. Alternatively, replace ``list`` with the keyword
346 ``all``. Disabled channels receive packets on the host. However, the commands
347 they specify are ignored. Set the status to enabled to begin processing
348 requests again:
349
350 .. code-block:: console
351
352    set_channel_status {vm_name} {list}|all enabled|disabled
353
354 Print to the CLI information on the specified VM. The information lists
355 the number of vCPUs, the pinning to pCPU(s) as a bit mask, along with
356 any communication channels associated with each VM, and the status of
357 each channel:
358
359 .. code-block:: console
360
361    show_vm {vm_name}
362
363 Set the binding of a virtual CPU on a VM with name ``{vm_name}`` to the
364 physical CPU mask:
365
366 .. code-block:: console
367
368    set_pcpu_mask {vm_name} {vcpu} {pcpu}
369
370 Set the binding of the virtual CPU on the VM to the physical CPU:
371  
372   .. code-block:: console
373
374    set_pcpu {vm_name} {vcpu} {pcpu}
375
376 It is also possible to perform manual control and inspection in relation
377 to CPU frequency scaling.
378
379 Get the current frequency for each core specified in the mask:
380
381 .. code-block:: console
382
383    show_cpu_freq_mask {mask}
384
385 Set the current frequency for the cores specified in ``{core_mask}`` by
386 scaling each up/down/min/max:
387
388 .. code-block:: console
389
390    set_cpu_freq {core_mask} up|down|min|max
391
392 Get the current frequency for the specified core:
393
394 .. code-block:: console
395
396    show_cpu_freq {core_num}
397
398 Set the current frequency for the specified core by scaling up/down/min/max:
399
400 .. code-block:: console
401
402    set_cpu_freq {core_num} up|down|min|max
403
404 .. _enabling_out_of_band:
405
406 Command Line Options for Enabling Out-of-band Branch Ratio Monitoring
407 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
408
409 There are a couple of command line parameters for enabling the out-of-band
410 monitoring of branch ratios on cores doing busy polling using PMDs as
411 described below:
412
413 ``--core-branch-ratio {list of cores}:{branch ratio for listed cores}``
414    Specify the list of cores to monitor the ratio of branch misses
415    to branch hits.  A tightly-polling PMD thread has a very low
416    branch ratio, therefore the core frequency scales down to the
417    minimum allowed value. On receiving packets, the code path changes,
418    causing the branch ratio to increase. When the ratio goes above
419    the ratio threshold, the core frequency scales up to the maximum
420    allowed value. The specified branch-ratio is a floating point number
421    that identifies the threshold at which to scale up or down for the
422    elements of the core-list. If not included the default branch ratio of
423    0.01 but will need adjustment for different workloads
424
425    This parameter can be used multiple times for different sets of cores.
426
427
428 Compiling and Running the Guest Applications
429 --------------------------------------------
430
431 It is possible to use the ``l3fwd-power`` application (for example) with the
432 ``vm_power_manager``.
433
434 The distribution also provides a guest CLI for validating the setup.
435
436 For both ``l3fwd-power`` and the guest CLI, the host application must use
437 the ``add_channels`` command to monitor the channels for the VM. To do this,
438 issue the following commands in the host application:
439
440 .. code-block:: console
441
442    vm_power> add_vm vmname
443    vm_power> add_channels vmname all
444    vm_power> set_channel_status vmname all enabled
445    vm_power> show_vm vmname
446
447 Compiling the Guest Application
448 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
449
450 For information on compiling DPDK and the sample applications in general,
451 see :doc:`compiling`.
452
453 For compiling and running the ``l3fwd-power`` sample application, see
454 :doc:`l3_forward_power_man`.
455
456 The application is in the ``guest_cli`` subdirectory under ``vm_power_manager``.
457
458 To build just the ``guest_vm_power_manager`` application using ``make``, issue
459 the following commands:
460
461 .. code-block:: console
462
463    export RTE_SDK=/path/to/rte_sdk
464    export RTE_TARGET=build
465    cd ${RTE_SDK}/examples/vm_power_manager/guest_cli/
466    make
467
468 The resulting binary is ``${RTE_SDK}/build/examples/guest_cli``.
469
470 **Note**: This sample application conditionally links in the Jansson JSON
471 library. Consequently, if you are using a multilib or cross-compile
472 environment, you may need to set the ``PKG_CONFIG_LIBDIR`` environmental
473 variable to point to the relevant ``pkgconfig`` folder so that the correct
474 library is linked in.
475
476 For example, if you are building for a 32-bit target, you could find the
477 correct directory using the following find command:
478
479 .. code-block:: console
480
481    # find /usr -type d -name pkgconfig
482    /usr/lib/i386-linux-gnu/pkgconfig
483    /usr/lib/x86_64-linux-gnu/pkgconfig
484
485 Then use:
486
487 .. code-block:: console
488
489    export PKG_CONFIG_LIBDIR=/usr/lib/i386-linux-gnu/pkgconfig
490
491 You then use the ``make`` command as normal, which should find the 32-bit
492 version of the library, if it installed. If not, the application builds
493 without the JSON interface functionality.
494
495 To build just the ``vm_power_manager`` application using ``meson``/``ninja``:
496
497 .. code-block:: console
498
499    export RTE_SDK=/path/to/rte_sdk
500    cd ${RTE_SDK}
501    meson build
502    cd build
503    ninja
504    meson configure -Dexamples=vm_power_manager/guest_cli
505    ninja
506
507 The resulting binary is ``${RTE_SDK}/build/examples/guest_cli``.
508
509 Running the Guest Application
510 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
511
512 The standard EAL command line parameters are necessary:
513
514 .. code-block:: console
515
516    ./build/vm_power_mgr [EAL options] -- [guest options]
517
518 The guest example uses a channel for each lcore enabled. For example, to
519 run on cores 0, 1, 2 and 3:
520
521 .. code-block:: console
522
523    ./build/guest_vm_power_mgr -l 0-3
524
525 .. _sending_policy:
526
527 Command Line Options Available When Sending a Policy to the Host
528 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
529
530 Optionally, there are several command line options for a user who needs
531 to send a power policy to the host application:
532
533 ``--vm-name {name of guest vm}``
534    Allows the user to change the virtual machine name
535    passed down to the host application using the power policy.
536    The default is ubuntu2.
537
538 ``--vcpu-list {list vm cores}``
539    A comma-separated list of cores in the VM that the user
540    wants the host application to monitor.
541    The list of cores in any VM starts at zero,
542    and the host application maps these to the physical cores
543    once the policy passes down to the host.
544    Valid syntax includes individual cores 2,3,4,
545    a range of cores 2-4, or a combination of both 1,3,5-7.
546
547 ``--busy-hours {list of busy hours}``
548    A comma-separated list of hours in which to set the core
549    frequency to the maximum.
550    Valid syntax includes individual hours 2,3,4,
551    a range of hours 2-4, or a combination of both 1,3,5-7.
552    Valid hour values are 0 to 23.
553
554 ``--quiet-hours {list of quiet hours}``
555    A comma-separated list of hours in which to set the core frequency
556    to minimum. Valid syntax includes individual hours 2,3,4,
557    a range of hours 2-4, or a combination of both 1,3,5-7.
558    Valid hour values are 0 to 23.
559
560 ``--policy {policy type}``
561    The type of policy. This can be one of the following values:
562
563    - TRAFFIC - Based on incoming traffic rates on the NIC.
564    - TIME - Uses a busy/quiet hours policy.
565    - BRANCH_RATIO - Uses branch ratio counters to determine core busyness.
566    - WORKLOAD - Sets the frequency to low, medium or high
567      based on the received policy setting.
568
569    **Note**: Not all policy types need all parameters.
570    For example, BRANCH_RATIO only needs the vcpu-list parameter.
571
572 After successful initialization, the VM Power Manager Guest CLI prompt
573 appears:
574
575 .. code-block:: console
576
577    vm_power(guest)>
578
579 To change the frequency of an lcore, use a ``set_cpu_freq`` command similar
580 to the following:
581
582 .. code-block:: console
583
584    set_cpu_freq {core_num} up|down|min|max
585
586 where, ``{core_num}`` is the lcore and channel to change frequency by
587 scaling up/down/min/max.
588
589 To start an application, configure the power policy, and send it to the
590 host, use a command like the following:
591
592 .. code-block:: console
593
594    ./build/guest_vm_power_mgr -l 0-3 -n 4 -- --vm-name=ubuntu --policy=BRANCH_RATIO --vcpu-list=2-4
595
596 Once the VM Power Manager Guest CLI appears, issuing the 'send_policy now' command
597 will send the policy to the host:
598
599 .. code-block:: console
600
601   send_policy now
602
603 Once the policy is sent to the host, the host application takes over the power monitoring
604 of the specified cores in the policy.
605
606 .. _power_man_requests:
607
608 JSON Interface for Power Management Requests and Policies
609 ---------------------------------------------------------
610
611 In addition to the command line interface for the host command, and a
612 ``virtio-serial`` interface for VM power policies, there is also a JSON
613 interface through which power commands and policies can be sent.
614
615 **Note**: This functionality adds a dependency on the Jansson library.
616 Install the Jansson development package on the system to avail of the
617 JSON parsing functionality in the app. Issue the ``apt-get install
618 libjansson-dev`` command to install the development package. The command
619 and package name may be different depending on your operating system. It
620 is worth noting that the app builds successfully if this package is not
621 present, but a warning displays during compilation, and the JSON parsing
622 functionality is not present in the app.
623
624 Send a request or policy to the VM Power Manager by simply opening a
625 fifo file at ``/tmp/powermonitor/fifo``, writing a JSON string to that file,
626 and closing the file.
627
628 The JSON string can be a power management request or a policy, and takes
629 the following format:
630
631 .. code-block:: javascript
632
633    {"packet_type": {
634    "pair_1": value,
635    "pair_2": value
636    }}
637
638 The ``packet_type`` header can contain one of two values, depending on
639 whether a power management request or policy is being sent. The two
640 possible values are ``instruction`` and ``policy`` and the expected name-value
641 pairs are different depending on which type is sent.
642
643 The pairs are in the format of standard JSON name-value pairs. The value
644 type varies between the different name-value pairs, and may be integers,
645 strings, arrays, and so on. See :ref:`json_interface_ex`
646 for examples of policies and instructions and
647 :ref:`json_name_value_pair` for the supported names and value types.
648
649 .. _json_interface_ex:
650
651 JSON Interface Examples
652 ~~~~~~~~~~~~~~~~~~~~~~~
653
654 The following is an example JSON string that creates a time-profile
655 policy.
656
657 .. code-block:: JSON
658
659    {"policy": {
660    "name": "ubuntu",
661    "command": "create",
662    "policy_type": "TIME",
663    "busy_hours":[ 17, 18, 19, 20, 21, 22, 23 ],
664    "quiet_hours":[ 2, 3, 4, 5, 6 ],
665    "core_list":[ 11 ]
666    }}
667
668 The following is an example JSON string that removes the named policy.
669
670 .. code-block:: JSON
671
672    {"policy": {
673    "name": "ubuntu",
674    "command": "destroy",
675    }}
676
677 The following is an example JSON string for a power management request.
678
679 .. code-block:: JSON
680
681    {"instruction": {
682    "name": "ubuntu",
683    "command": "power",
684    "unit": "SCALE_MAX",
685    "resource_id": 10
686    }}
687
688 To query the available frequences of an lcore, use the query_cpu_freq command.
689 Where {core_num} is the lcore to query.
690 Before using this command, please enable responses via the set_query command on the host.
691
692 .. code-block:: console
693
694   query_cpu_freq {core_num}|all
695
696 To query the capabilities of an lcore, use the query_cpu_caps command.
697 Where {core_num} is the lcore to query.
698 Before using this command, please enable responses via the set_query command on the host.
699
700 .. code-block:: console
701
702   query_cpu_caps {core_num}|all
703
704 To start the application and configure the power policy, and send it to the host:
705
706 .. code-block:: console
707
708  ./build/guest_vm_power_mgr -l 0-3 -n 4 -- --vm-name=ubuntu --policy=BRANCH_RATIO --vcpu-list=2-4
709
710 Once the VM Power Manager Guest CLI appears, issuing the 'send_policy now' command
711 will send the policy to the host:
712
713 .. code-block:: console
714
715   send_policy now
716
717 Once the policy is sent to the host, the host application takes over the power monitoring
718 of the specified cores in the policy.
719
720 .. _json_name_value_pair:
721
722 JSON Name-value Pairs
723 ~~~~~~~~~~~~~~~~~~~~~
724
725 The following are the name-value pairs supported by the JSON interface:
726
727 -  `avg_packet_thresh`_
728 -  `busy_hours`_
729 -  `command`_
730 -  `core_list`_
731 -  `mac_list`_
732 -  `max_packet_thresh`_
733 -  `name`_
734 -  `policy_type`_
735 -  `quiet_hours`_
736 -  `resource_id`_
737 -  `unit`_
738 -  `workload`_
739
740 avg_packet_thresh
741 ^^^^^^^^^^^^^^^^^
742
743 Description
744    The threshold below which the frequency is set to the minimum value
745    for the TRAFFIC policy.
746    If the traffic rate is above this value and below the maximum value,
747    the frequency is set to medium.
748 Type
749    integer
750 Values
751    The number of packets below which the TRAFFIC policy applies
752    the minimum frequency, or the medium frequency
753    if between the average and maximum thresholds.
754 Required
755    Yes
756 Example
757    ``"avg_packet_thresh": 100000``
758
759 busy_hours
760 ^^^^^^^^^^
761
762 Description
763    The hours of the day in which we scale up the cores for busy times.
764 Type
765    array of integers
766 Values
767    An array with a list of hour values (0-23).
768 Required
769    For the TIME policy only.
770 Example
771    ``"busy_hours":[ 17, 18, 19, 20, 21, 22, 23 ]``
772
773 command
774 ^^^^^^^
775
776 Description
777    The type of packet to send to the VM Power Manager.
778    It is possible to create or destroy a policy or send a direct command
779    to adjust the frequency of a core,
780    as is possible on the command line interface.
781 Type
782    string
783 Values
784    Possible values are:
785    - CREATE: Create a new policy.
786    - DESTROY: Remove an existing policy.
787    - POWER: Send an immediate command, max, min, and so on.
788 Required
789    Yes
790 Example
791    ``"command": "CREATE"``
792
793 core_list
794 ^^^^^^^^^
795
796 Description
797    The cores to which to apply a policy.
798 Type
799    array of integers
800 Values
801    An array with a list of virtual CPUs.
802 Required
803    For CREATE/DESTROY policy requests only.
804 Example
805    ``"core_list":[ 10, 11 ]``
806
807 mac_list
808 ^^^^^^^^
809
810 Description
811    When the policy is of type TRAFFIC,
812    it is necessary to specify the MAC addresses that the host must monitor.
813 Type
814    array of strings
815 Values
816    An array with a list of MAC address strings.
817 Required
818    For TRAFFIC policy types only.
819 Example
820    ``"mac_list":[ "de:ad:be:ef:01:01","de:ad:be:ef:01:02" ]``
821
822 max_packet_thresh
823 ^^^^^^^^^^^^^^^^^
824
825 Description
826    In a policy of type TRAFFIC,
827    the threshold value above which the frequency is set to a maximum.
828 Type
829    integer
830 Values
831    The number of packets per interval above which
832    the TRAFFIC policy applies the maximum frequency.
833 Required
834    For the TRAFFIC policy only.
835 Example
836    ``"max_packet_thresh": 500000``
837
838 name
839 ^^^^
840
841 Description
842    The name of the VM or host.
843    Allows the parser to associate the policy with the relevant VM or host OS.
844 Type
845    string
846 Values
847    Any valid string.
848 Required
849    Yes
850 Example
851    ``"name": "ubuntu2"``
852
853 policy_type
854 ^^^^^^^^^^^
855
856 Description
857    The type of policy to apply.
858    See the ``--policy`` option description for more information.
859 Type
860    string
861 Values
862    Possible values are:
863
864    - TIME: Time-of-day policy.
865      Scale the frequencies of the relevant cores up/down
866      depending on busy and quiet hours.
867    - TRAFFIC: Use statistics from the NIC and scale up and down accordingly.
868    - WORKLOAD: Determine how heavily loaded the cores are
869      and scale up and down accordingly.
870    - BRANCH_RATIO: An out-of-band policy that looks at the ratio
871      between branch hits and misses on a core
872      and uses that information to determine how much packet processing
873      a core is doing.
874
875 Required
876    For ``CREATE`` and ``DESTROY`` policy requests only.
877 Example
878    ``"policy_type": "TIME"``
879
880 quiet_hours
881 ^^^^^^^^^^^
882
883 Description
884    The hours of the day to scale down the cores for quiet times.
885 Type
886    array of integers
887 Values
888    An array with a list of hour numbers with values in the range 0 to 23.
889 Required
890    For the TIME policy only.
891 Example
892    ``"quiet_hours":[ 2, 3, 4, 5, 6 ]``
893
894 resource_id
895 ^^^^^^^^^^^
896
897 Description
898    The core to which to apply a power command.
899 Type
900    integer
901 Values
902    A valid core ID for the VM or host OS.
903 Required
904    For the ``POWER`` instruction only.
905 Example
906    ``"resource_id": 10``
907
908 unit
909 ^^^^
910
911 Description
912    The type of power operation to apply in the command.
913 Type
914    string
915 Values
916    - SCALE_MAX: Scale the frequency of this core to the maximum.
917    - SCALE_MIN: Scale the frequency of this core to the minimum.
918    - SCALE_UP: Scale up the frequency of this core.
919    - SCALE_DOWN: Scale down the frequency of this core.
920    - ENABLE_TURBO: Enable Intel® Turbo Boost Technology for this core.
921    - DISABLE_TURBO: Disable Intel® Turbo Boost Technology for this core.
922 Required
923    For the ``POWER`` instruction only.
924 Example
925    ``"unit": "SCALE_MAX"``
926
927 workload
928 ^^^^^^^^
929
930 Description
931    In a policy of type WORKLOAD,
932    it is necessary to specify how heavy the workload is.
933 Type
934    string
935 Values
936    - HIGH: Scale the frequency of this core to maximum.
937    - MEDIUM: Scale the frequency of this core to minimum.
938    - LOW: Scale up the frequency of this core.
939 Required
940    For the ``WORKLOAD`` policy only.
941 Example
942    ``"workload": "MEDIUM"``