1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-04 05:17:40 +03:00

Fix wrong threshold casting to int in Scheduler.cc

(cherry picked from commit 381f26d52b)
This commit is contained in:
Ruben S. Montero 2010-09-02 20:26:02 +02:00
parent 32292a134c
commit 4fe14cdd14
2 changed files with 5 additions and 18 deletions

View File

@ -46,7 +46,7 @@ public:
* @param memory the host free memory * @param memory the host free memory
* @param threshold to consider the host totally free * @param threshold to consider the host totally free
*/ */
void get_capacity(int& cpu, int& memory, int threshold) const; void get_capacity(int& cpu, int& memory, float threshold) const;
/** /**
* Tests whether a new VM can be hosted by the host or not * Tests whether a new VM can be hosted by the host or not
@ -80,9 +80,7 @@ public:
}; };
protected: private:
// TODO Check if any of these are not needed, and delete them.
int oid; int oid;
// Host share values // Host share values
@ -98,13 +96,8 @@ protected:
int free_mem; /**< Free memory from the IM monitor */ int free_mem; /**< Free memory from the IM monitor */
int free_cpu; /**< Free cpu from the IM monitor */ int free_cpu; /**< Free cpu from the IM monitor */
int used_disk; /**< Used disk from the IM monitor */
int used_mem; /**< Used memory from the IM monitor */
int used_cpu; /**< Used cpu from the IM monitor */
int running_vms; /**< Number of running VMs in this Host */ int running_vms; /**< Number of running VMs in this Host */
void init_attributes(); void init_attributes();
}; };

View File

@ -18,19 +18,17 @@
#include "HostXML.h" #include "HostXML.h"
void HostXML::get_capacity(int& cpu, int& memory, int threshold) const void HostXML::get_capacity(int& cpu, int& memory, float threshold) const
{ {
int total_cpu;
vector<string> result; vector<string> result;
memory = free_mem; memory = free_mem;
cpu = free_cpu; cpu = free_cpu;
total_cpu = max_cpu;
/* eg. 96.7 >= 0.9 * 100, We need to round */ /* eg. 96.7 >= 0.9 * 100, We need to round */
if ( cpu >= threshold * total_cpu ) if ( cpu >= static_cast<int>(threshold * static_cast<float>(max_cpu)) )
{ {
cpu = (int) ceil((float)cpu/100.0) * 100; cpu = static_cast<int>(ceil(static_cast<float>(cpu)/100.0) * 100);
} }
} }
@ -53,10 +51,6 @@ void HostXML::init_attributes()
free_mem = atoi(((*this)["/HOST/HOST_SHARE/FREE_MEM"])[0].c_str()); free_mem = atoi(((*this)["/HOST/HOST_SHARE/FREE_MEM"])[0].c_str());
free_cpu = atoi(((*this)["/HOST/HOST_SHARE/FREE_CPU"])[0].c_str()); free_cpu = atoi(((*this)["/HOST/HOST_SHARE/FREE_CPU"])[0].c_str());
used_disk = atoi(((*this)["/HOST/HOST_SHARE/USED_DISK"])[0].c_str());
used_mem = atoi(((*this)["/HOST/HOST_SHARE/USED_MEM"])[0].c_str());
used_cpu = atoi(((*this)["/HOST/HOST_SHARE/USED_CPU"])[0].c_str());
running_vms = atoi(((*this)["/HOST/HOST_SHARE/RUNNING_VMS"])[0].c_str()); running_vms = atoi(((*this)["/HOST/HOST_SHARE/RUNNING_VMS"])[0].c_str());
} }