Editing Fairsched API

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
There are several parameters tuning which the OpenVZ administrator can change the CPU usage of a CT. Usually one sets these parameters with the aid of the <code>vzctl</code> utility. But sometimes it can be useful to modify these parameters directly, without using <code>vzctl</code>. For example, it can be required by developers who want to implement an in-place solution to control a particular virtualization system based on OpenVZ. That is why the Fairsched API is introduced.
+
There are several parameters tuning which the OpenVZ administrator can change the CPU usage of a VE. Usually one sets these parameters with the aid of the <code>vzctl</code> utility. But sometimes it can be useful to modify these parameters directly, without using <code>vzctl</code>. For example, it can be required by developers who want to implement an in-place solution to control a particular virtualization system based on OpenVZ. That is why the Fairsched API is introduced.
  
 
The '''Fairsched API''' is the set of system calls that can be used (and that are, in fact, used in the <code>vzctl</code> utility) for altering various parameters of the [[CPU Fair scheduler]], such as <code>cpuunits</code>, <code>cpulimit</code>, <code>cpus</code>, and <code>cpumask</code>. The article is targeted at describing the API.
 
The '''Fairsched API''' is the set of system calls that can be used (and that are, in fact, used in the <code>vzctl</code> utility) for altering various parameters of the [[CPU Fair scheduler]], such as <code>cpuunits</code>, <code>cpulimit</code>, <code>cpus</code>, and <code>cpumask</code>. The article is targeted at describing the API.
Line 5: Line 5:
 
== CPU weight ==
 
== CPU weight ==
  
=== Synopsis ===
+
'''Synopsis:'''
  
 
<source lang="c">
 
<source lang="c">
Line 11: Line 11:
 
</source>
 
</source>
  
=== Description ===
+
'''Description:'''
  
The CPU weight defines how much CPU time a CT gets. The smaller the weight is, the more CPU time the container gets. The CPU weight is a relative parameter. That means that multiplying the weight of all running CTs by the same value does not change the CPU time distribution. The minimal value of the weight is 1, and the maximal value is <code>FSCHWEIGHT_MAX</code> (65535). The weight of a newly created CT is set to 500 by default.
+
The CPU weight defines how much CPU time a VE gets. The smaller the weight is, the more CPU time the container gets. The CPU weight is a relative parameter. That means that multiplying the weight of all running VEs by the same value does not change the CPU time distribution. The minimal value of the weight is 1, and the maximal value is <code>FSCHWEIGHT_MAX</code> (65535). The weight of a newly created VE is set to 500 by default.
  
The <code>fairsched_chwt()</code> system call sets the CPU weight of a CT. <code>id</code> is the id of the CT. <code>wght</code> is the desired weight.
+
The <code>fairsched_chwt()</code> system call sets the CPU weight of a VE. <code>id</code> is the id of the VE. <code>wght</code> is the desired weight.
  
=== Return value ===
+
'''Return value:'''
  
 
On success, <code>fairsched_chwt()</code> returns 0. On error, -1 is returned, and <code>errno</code> is set appropriately.
 
On success, <code>fairsched_chwt()</code> returns 0. On error, -1 is returned, and <code>errno</code> is set appropriately.
  
=== Errors ===
+
'''Errors:'''
  
 
* <code>EINVAL</code>: <code>id</code>=0.
 
* <code>EINVAL</code>: <code>id</code>=0.
 
* <code>EINVAL</code>: the value of <code>wght</code> is out of the allowed range.
 
* <code>EINVAL</code>: the value of <code>wght</code> is out of the allowed range.
* <code>ENOENT</code>: the CT does not exist.
+
* <code>ENOENT</code>: the VE does not exist.
* <code>EPERM</code>: the caller does not have permissions to modify the CPU parameters of the CT.
+
* <code>EPERM</code>: the caller does not have permissions to modify the CPU parameters of the VE.
  
=== Notes ===
+
'''Notes:'''
  
 
It is possible to change the CPU weight of the host system. The host system's id equals <code>INT_MAX</code> (2147483647).
 
It is possible to change the CPU weight of the host system. The host system's id equals <code>INT_MAX</code> (2147483647).
Line 35: Line 35:
  
 
''cpuweight = 500000 / cpuunits''
 
''cpuweight = 500000 / cpuunits''
 +
  
 
== CPU limit ==
 
== CPU limit ==
  
=== Synopsis ===
+
'''Synopsis:'''
  
 
<source lang="c">
 
<source lang="c">
Line 44: Line 45:
 
</source>
 
</source>
  
=== Description ===
+
'''Description:'''
  
The CPU limit is the upper bound to the CPU usage for a CT. The limit is set for all CPUs the CT can execute on. That means the maximal value of the CPU limit (i.e. no limit) is the maximal limit on 1 CPU, which equals 1024, multiplied by NUM_CPUS, the number of CPUs this VM can execute on. The CPU limit is an absolute parameter in the sense that altering the limit of one CT does not affect the limits of other CTs.
+
The CPU limit is the upper bound to the CPU usage for a VE. The limit is set for all CPUs the VE can execute on. That means the maximal value of the CPU limit (i.e. no limit) is the maximal limit on 1 CPU, which equals 1024, multiplied by NUM_CPUS, the number of CPUs this VM can execute on. The CPU limit is an absolute parameter in the sense that altering the limit of one VE does not affect the limits of other VEs.
  
The <code>fairsched_rate()</code> system call is used to set, get, or drop (i.e. set to the maximum) CPU limit of a CT. <code>id</code> is the id of the CT. <code>op</code> can be one of the following:
+
The <code>fairsched_rate()</code> system call is used to set, get, or drop (i.e. set to the maximum) CPU limit of a VE. <code>id</code> is the id of the VE. <code>op</code> can be one of the following:
  
 
* <code>FAIRSCHED_SET_RATE</code> to set the limit; in this case <code>rate</code> is the limit value to set.
 
* <code>FAIRSCHED_SET_RATE</code> to set the limit; in this case <code>rate</code> is the limit value to set.
Line 54: Line 55:
 
* <code>FAIRSCHED_GET_RATE</code> to get the current value of the limit; the function returns the limit value, <code>rate</code> is not used.
 
* <code>FAIRSCHED_GET_RATE</code> to get the current value of the limit; the function returns the limit value, <code>rate</code> is not used.
  
=== Return value ===
+
'''Return value:'''
  
 
On success, <code>fairsched_rate()</code> returns the current value of the CPU limit if <code>op</code> is <code>FAIRSCHED_SET_RATE</code> or <code>FAIRSCHED_GET_RATE</code>, or 0 if <code>op</code> is <code>FAIRSCHED_DROP_RATE</code>. On error, -1 is returned, and <code>errno</code> is set appropriately.
 
On success, <code>fairsched_rate()</code> returns the current value of the CPU limit if <code>op</code> is <code>FAIRSCHED_SET_RATE</code> or <code>FAIRSCHED_GET_RATE</code>, or 0 if <code>op</code> is <code>FAIRSCHED_DROP_RATE</code>. On error, -1 is returned, and <code>errno</code> is set appropriately.
  
=== Errors ===
+
'''Errors:'''
  
 
* <code>EINVAL</code>: <code>id</code>=0.
 
* <code>EINVAL</code>: <code>id</code>=0.
 
* <code>EINVAL</code>: <code>op</code> is invalid.
 
* <code>EINVAL</code>: <code>op</code> is invalid.
 
* <code>EINVAL</code>: <code>op</code>=<code>FAIRSCHED_SET_RATE</code>, and <code>rate</code><=0.
 
* <code>EINVAL</code>: <code>op</code>=<code>FAIRSCHED_SET_RATE</code>, and <code>rate</code><=0.
* <code>ENOENT</code>: the CT does not exist.
+
* <code>ENOENT</code>: the VE does not exist.
 
* <code>ENODATA</code>: <code>op</code>=<code>FAIRSCHED_GET_RATE</code>, and the limit is not set (or was dropped).
 
* <code>ENODATA</code>: <code>op</code>=<code>FAIRSCHED_GET_RATE</code>, and the limit is not set (or was dropped).
* <code>EPERM</code>: the caller does not have permissions to modify the CPU parameters of the CT.
+
* <code>EPERM</code>: the caller does not have permissions to modify the CPU parameters of the VE.
  
=== Notes ===
+
'''Notes:'''
  
 
It is possible to limit the CPU usage of the host system. The host system's id equals <code>INT_MAX</code> (2147483647).
 
It is possible to limit the CPU usage of the host system. The host system's id equals <code>INT_MAX</code> (2147483647).
  
CPU limits are available only in RHEL5-based and RHEL6-based kernels, and they behave a bit differently in them in respect of distributing CPU time among CPUs the CT can execute on.
+
CPU limits are available only in rhel5-based and rhel6-based kernels, and they behave a bit differently in them in respect of distributing CPU time among CPUs the VE can execute on.
  
In the RHEL5 kernel the limit has a container-wide meaning. For example, if there are 2 CPUs available for a container, and the limit is set to 1024 (of 2048), the container's CPU usage can be 100/0%, or 50/50%, or any other values whose sum does not exceed 100%.
+
In the rhel5 kernel the limit has a container-wide meaning. For example, if there are 2 CPUs available for a container, and the limit is set to 1024 (of 2048), the container's CPU usage can be 100/0%, or 50/50%, or any other values whose sum does not exceed 100%.
  
In the RHEL6 kernel the limit is divided between the CPUs proportionally, and a busy CPU cannot borrow time from an idle one, i.e. with a 2 CPUs container and 1024 (of 2048) limit set the usage of each CPU cannot exceed 50% in any case.
+
In the rhel6 kernel the limit is divided between the CPUs proportionally, and a busy CPU cannot borrow time from an idle one, i.e. with a 2 CPUs container and 1024 (of 2048) limit set the usage of each CPU cannot exceed 50% in any case.
 +
 
 +
As a result, the minimal value for the limit is 1 in the rhel5 kernel and 1 * NUM_CPUS in the rhel6 kernel. If the given limit is out of the allowed range it is automatically clamped to the range.
  
As a result, the minimal value for the limit is 1 in the RHEL5 kernel and 1 * NUM_CPUS in the RHEL6 kernel. If the given limit is out of the allowed range it is automatically clamped to the range.
 
  
 
== Number of CPUs ==
 
== Number of CPUs ==
  
=== Synopsis ===
+
'''Synopsis:'''
  
 
<source lang="c">
 
<source lang="c">
Line 87: Line 89:
 
</source>
 
</source>
  
=== Description ===
+
'''Description:'''
  
The <code>fairsched_vcpus()</code> system call sets the number of virtual CPUs available in a CT. <code>id</code> is the id of the CT. <code>vcpus</code> is the number of virtual CPUs to set for the CT. If <code>vcpus</code>=0, the call attempts to set the number of CPUs in the CT to the number of online CPUs.
+
The <code>fairsched_vcpus()</code> system call sets the number of virtual CPUs available in a VE. <code>id</code> is the id of the VE. <code>vcpus</code> is the number of virtual CPUs to set for the VE. If <code>vcpus</code>=0, the call attempts to set the number of CPUs in the VE to the number of online CPUs.
  
=== Return value ===
+
'''Return value:'''
  
 
On success, <code>fairsched_vcpus()</code> returns 0. On error, -1 is returned, and <code>errno</code> is set appropriately.
 
On success, <code>fairsched_vcpus()</code> returns 0. On error, -1 is returned, and <code>errno</code> is set appropriately.
  
=== Errors ===
+
'''Errors:'''
  
 
* <code>EINVAL</code>: <code>id</code>=0.
 
* <code>EINVAL</code>: <code>id</code>=0.
* <code>ENOENT</code>: the CT does not exist.
+
* <code>ENOENT</code>: the VE does not exist.
* <code>EPERM</code>: the caller does not have permissions to modify the CPU parameters of the CT.
+
* <code>EPERM</code>: the caller does not have permissions to modify the CPU parameters of the VE.
 +
 
 +
'''Notes:'''
  
=== Notes ===
+
The parameter have not been implemented in the rhel6 kernel yet.
  
The parameter have not been implemented in the RHEL6 kernel yet.
 
  
 
== CPU affinity mask ==
 
== CPU affinity mask ==
  
=== Synopsis ===
+
'''Synopsis:'''
  
 
<source lang="c">
 
<source lang="c">
int fairsched_cpumask(unsigned int id, unsigned int len, unsigned long *mask);
+
int fairsched_cpumask(unsigned int id, unsigned int len, unsigned long *mask)
 
</source>
 
</source>
  
=== Description ===
+
'''Description:'''
  
A CT's CPU affinity mask determines the set of CPUs on which it is eligible to run. A CPU affinity mask is represented by an array of <code>long</code>s so that a CT is allowed to execute on the n-th CPU if and only if the (<code>n%sizeof(long)</code>)-th bit of the (<code>n/sizeof(long)</code>)-th element of the array is set.
+
A VE's CPU affinity mask determines the set of CPUs on which it is eligible to run. A CPU affinity mask is represented by an array of <code>long</code>'s so that a VE is allowed to execute on the n-th CPU if and only if the (<code>n%sizeof(long)</code>)-th bit of the (<code>n/sizeof(long)</code>)-th element of the array is set.
  
The <code>fairsched_cpumask()</code> system call sets the CPU affinity mask for a CT. <code>id</code> is the id of the CT. <code>mask</code> is the mask, and <code>len</code> is the size of the mask, in bytes.
+
The <code>fairsched_cpumask()</code> system call sets the CPU affinity mask for a VE. <code>id</code> is the id of the VE. <code>mask</code> is the mask, and <code>len</code> is the size of the mask, in bytes.
  
=== Return value ===
+
'''Return value:'''
  
 
On success, <code>fairsched_cpumask()</code> returns 0. On error, -1 is returned, and <code>errno</code> is set appropriately.
 
On success, <code>fairsched_cpumask()</code> returns 0. On error, -1 is returned, and <code>errno</code> is set appropriately.
  
=== Errors ===
+
'''Errors:'''
  
* <code>EBUSY</code>: the CT has a child cpuset which is not a subset of the mask.
+
* <code>EBUSY</code>: the VE has a child cpuset which is not a subset of the mask.
 
* <code>EINVAL</code>: <code>id</code>=0.
 
* <code>EINVAL</code>: <code>id</code>=0.
* <code>EINVAL</code>: the mask intersects with a cpuset, and either that cpuset or the CT's cpuset is marked exclusive.
+
* <code>EINVAL</code>: the mask intersects with a cpuset, and either that cpuset or the VE's cpuset is marked exclusive.
* <code>ENOENT</code>: the CT does not exist.
+
* <code>ENOENT</code>: the VE does not exist.
 
* <code>ENOMEM</code>: there is no memory to copy the mask.
 
* <code>ENOMEM</code>: there is no memory to copy the mask.
 
* <code>ENOSPC</code>: the mask has no active CPUs set.
 
* <code>ENOSPC</code>: the mask has no active CPUs set.
* <code>EPERM</code>: the caller does not have permissions to modify the CPU parameters of the CT.
+
* <code>EPERM</code>: the caller does not have permissions to modify the CPU parameters of the VE.
  
=== Notes ===
+
'''Notes:'''
  
The parameter is available since the [[Download/kernel/rhel6|RHEL6]] kernel.
+
The parameter is available since the rhel6 kernel.
  
 
[[Category: Kernel]]
 
[[Category: Kernel]]
 
[[Category: Resource management]]
 
[[Category: Resource management]]

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)