From 4fbcb02573d7fa750501594eb107329fbb564926 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Mon, 2 May 2011 13:06:02 +0530 Subject: [PATCH] Bug 9534 : implement CPU cap Changes specific for Xen hypervisor, and DB upgrade. Changes for vmware chcked-in already in commit 1c310a0d2ae81108386f0dd5c2e899ff00fee9e9, e71112e2f587f5d6c9c6d5337cfeb1f239f29633. KVM will not support this feature. --- .../xen/resource/CitrixResourceBase.java | 14 ++++++++------ setup/db/db/schema-224to225.sql | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index eda38edf31e..ec30c5b2e1e 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -245,8 +245,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe protected String _instance; //instance name (default is usually "VM") protected IAgentControl _agentControl; - - int _userVMCap = 0; + final int _maxWeight = 256; protected final XenServerHost _host = new XenServerHost(); @@ -791,16 +790,19 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe Integer speed = vmSpec.getSpeed(); if (speed != null) { - int utilization = _userVMCap; //cpu_cap - //Configuration cpu.uservm.cap is not available in default installation. Using this parameter is not encouraged - + int cpuWeight = _maxWeight; //cpu_weight - + int utilization = 0; // max CPU cap, default is unlimited + // weight based allocation cpuWeight = (int)((speed*0.99) / _host.speed * _maxWeight); if (cpuWeight > _maxWeight) { cpuWeight = _maxWeight; } + + if (vmSpec.getLimitCpuUse()) { + utilization = (int)((speed*0.99) / _host.speed * 100); + } vcpuParams.put("weight", Integer.toString(cpuWeight)); vcpuParams.put("cap", Integer.toString(utilization)); diff --git a/setup/db/db/schema-224to225.sql b/setup/db/db/schema-224to225.sql index 4bb38d5dcee..f48ab82f908 100644 --- a/setup/db/db/schema-224to225.sql +++ b/setup/db/db/schema-224to225.sql @@ -4,6 +4,8 @@ ALTER TABLE `cloud`.`mshost` ADD COLUMN `runid` bigint NOT NULL DEFAULT 0 COMMENT 'run id, combined with msid to form a cluster session'; ALTER TABLE `cloud`.`mshost` ADD COLUMN `state` varchar(10) NOT NULL default 'Down'; +ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `limit_cpu_use` tinyint(1) NOT NULL DEFAULT 0 ; +ALTER TABLE `cloud`.`service_offering` ADD COLUMN `limit_cpu_use` tinyint(1) NOT NULL DEFAULT 0 ; DROP TABLE IF EXISTS `cloud`.`certificate`; CREATE TABLE `cloud`.`keystore` (