Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
Fix the calculation for Create Goal 10% deviation
Browse files Browse the repository at this point in the history
- Added accessor method for totalCapacityinGib in MemoryAllocationRequest
- Calculated  10% difference based on totalDIMMCapacity
- Correct formatting errors

Signed-off-by: Swetha Venkatachari Sundarajan <[email protected]>
  • Loading branch information
swetha-intel authored and aallada committed Jul 11, 2017
1 parent 9192471 commit 029538f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/cli/features/core/CreateGoalCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ static const std::string CREATE_GOAL_APP_DIRECT_NOT_SUPPORTED_BY_DRIVER_WARNING
"App Direct capacity which is not supported by the host software.");
static const std::string CREATE_GOAL_REQUESTED_MEMORY_MODE_NOT_USABLE_WARNING = TR("The requested goal will result in Memory "
"Mode capacity that is unusable with the currently selected platform BIOS volatile mode.");
static const std::string CREATE_GOAL_ADJUSTED_MORE_THAN_10PERCENT_WARNING = TR("The requested goal was adjusted more than 10% "
"to find a valid configuration.");
static const std::string CREATE_GOAL_ADJUSTED_MORE_THAN_10PERCENT_WARNING = TR("The requested goal was adjusted more than 10%% "
"to find a valid configuration."); // Escape the '%' character to print it safely using printf statement
static const std::string CREATE_GOAL_SKU_MAPPED_MEMORY_LIMITED_WARNING = TR("The amount of mapped memory was limited based "
"on the SKU resulting in un-mapped Storage only capacity.");

Expand Down
46 changes: 31 additions & 15 deletions src/core/memory_allocator/LayoutStepCheckRequestLayoutDeviation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,60 +53,76 @@ void core::memory_allocator::LayoutStepCheckRequestLayoutDeviation::execute(cons
{
LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

checkIfMemoryCapacityLayoutIsAcceptable(request, layout);
checkAppDirectCapacityLayoutIsAcceptable(request, layout);
bool isAcceptableDeviation = false;

isAcceptableDeviation = isMemoryCapacityLayoutAcceptable(request, layout) &&
isAppDirectCapacityLayoutAcceptable(request, layout);

if(!isAcceptableDeviation)
{
layout.warnings.push_back(LAYOUT_WARNING_GOAL_ADJUSTED_MORE_THAN_10PERCENT);
}
}

double core::memory_allocator::LayoutStepCheckRequestLayoutDeviation::findPercentDeviation(
NVM_UINT64 expectedValue, NVM_UINT64 observedValue)
NVM_UINT64 expectedValue, NVM_UINT64 observedValue, NVM_UINT64 totalCapacity)
{
LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

int deviation = ABSOLUTEDIFFERENCE(observedValue, expectedValue);

return (double)100.0 * (deviation)/expectedValue;
return (double) 100 * deviation / totalCapacity;
}

bool core::memory_allocator::LayoutStepCheckRequestLayoutDeviation::layoutDeviationIsWithinBounds(
bool core::memory_allocator::LayoutStepCheckRequestLayoutDeviation::isLayoutDeviationWithinBounds(
double percentDeviation)
{
LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
return (percentDeviation <= ACCEPTED_PERCENT_DEVIATION);
}

void core::memory_allocator::LayoutStepCheckRequestLayoutDeviation::checkIfMemoryCapacityLayoutIsAcceptable(
bool core::memory_allocator::LayoutStepCheckRequestLayoutDeviation::isMemoryCapacityLayoutAcceptable(
const struct MemoryAllocationRequest& request,
MemoryAllocationLayout& layout)
{
LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

if (request.getMemoryModeCapacityGiB())
bool isDeviationWithinBounds = true;
if (request.getAllMappableDimmCapacityInGiB() > 0 && request.getMemoryModeCapacityGiB() > 0)
{
double percentDeviation =
findPercentDeviation(request.getMemoryModeCapacityGiB(), layout.memoryCapacity);
findPercentDeviation(request.getMemoryModeCapacityGiB(), layout.memoryCapacity, request.getAllMappableDimmCapacityInGiB());

if ((layout.memoryCapacity == 0) ||
(!layoutDeviationIsWithinBounds(percentDeviation)))
(!isLayoutDeviationWithinBounds(percentDeviation)))
{
layout.warnings.push_back(LAYOUT_WARNING_GOAL_ADJUSTED_MORE_THAN_10PERCENT);
isDeviationWithinBounds = false;
}
}

return isDeviationWithinBounds;
}

void core::memory_allocator::LayoutStepCheckRequestLayoutDeviation::checkAppDirectCapacityLayoutIsAcceptable(
bool core::memory_allocator::LayoutStepCheckRequestLayoutDeviation::isAppDirectCapacityLayoutAcceptable(
const struct MemoryAllocationRequest& request,
MemoryAllocationLayout& layout)
{
LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

if (request.getAppDirectCapacityGiB() > 0)
bool isDeviationWithinBounds = true;
if (request.getAllMappableDimmCapacityInGiB() > 0 && request.getAppDirectCapacityGiB() > 0)
{
NVM_UINT64 layoutAppDirectCapacity = getNonReservedAppDirectCapacityGiBFromLayout(request, layout);
double percentDeviation = findPercentDeviation(request.getAppDirectCapacityGiB(),
layoutAppDirectCapacity);
if (!layoutDeviationIsWithinBounds(percentDeviation))
layoutAppDirectCapacity, request.getAllMappableDimmCapacityInGiB());

if(!isLayoutDeviationWithinBounds(percentDeviation))
{
layout.warnings.push_back(LAYOUT_WARNING_GOAL_ADJUSTED_MORE_THAN_10PERCENT);
isDeviationWithinBounds = false;
}
}

return isDeviationWithinBounds;
}

NVM_UINT64 core::memory_allocator::LayoutStepCheckRequestLayoutDeviation::getReservedAppDirectCapacityGiB(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class NVM_API LayoutStepCheckRequestLayoutDeviation : public LayoutStep
virtual void execute(const MemoryAllocationRequest &request, MemoryAllocationLayout &layout);

protected:
void checkIfMemoryCapacityLayoutIsAcceptable(
bool isMemoryCapacityLayoutAcceptable(
const struct MemoryAllocationRequest& request,
MemoryAllocationLayout& layout);

void checkAppDirectCapacityLayoutIsAcceptable(
bool isAppDirectCapacityLayoutAcceptable(
const struct MemoryAllocationRequest& request,
MemoryAllocationLayout& layout);

Expand All @@ -62,9 +62,9 @@ class NVM_API LayoutStepCheckRequestLayoutDeviation : public LayoutStep
bool reservedDimmIsAppDirect(const struct MemoryAllocationRequest& request);
NVM_UINT64 getReservedAppDirectCapacityGiB(const struct MemoryAllocationRequest& request);

double findPercentDeviation(NVM_UINT64 expectedValue, NVM_UINT64 observedValue);
double findPercentDeviation(NVM_UINT64 expectedValue, NVM_UINT64 observedValue, NVM_UINT64 totalCapacity);

bool layoutDeviationIsWithinBounds(double percentDeviation);
bool isLayoutDeviationWithinBounds(double percentDeviation);
};

} /* namespace memory_allocator */
Expand Down
6 changes: 3 additions & 3 deletions src/core/memory_allocator/MemoryAllocationRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ namespace memory_allocator
{

MemoryAllocationRequest::MemoryAllocationRequest() :
m_memoryCapacityGiB(0), m_appDirectExtent(), m_storageRemaining(false),
m_reserveStorageCapacityGiB(0), m_reserveDimmUid(""), m_reserveDimmType(RESERVE_DIMM_NONE),
m_dimms()
m_memoryCapacityGiB(0), m_appDirectExtent(), m_storageRemaining(false),
m_reserveStorageCapacityGiB(0), m_reserveDimmUid(""), m_reserveDimmType(RESERVE_DIMM_NONE),
m_dimms()
{
LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
}
Expand Down
60 changes: 30 additions & 30 deletions src/core/memory_allocator/MemoryAllocationRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,36 @@ class NVM_API MemoryAllocationRequest
* All requested capacity is in GiB.
*/

NVM_UINT64 getMemoryModeCapacityGiB() const;
void setMemoryModeCapacityGiB(const NVM_UINT64 capacity);

NVM_UINT64 getAppDirectCapacityGiB() const;
AppDirectExtent getAppDirectExtent() const;
void setAppDirectExtent(const AppDirectExtent &extent);

bool isStorageRemaining() const;
void setStorageRemaining(const bool storageIsRemaining);
bool hasStorage() const;

NVM_UINT64 getReserveStorageCapacityGiB() const;
void setReserveStorageCapacityGiB(const NVM_UINT64 capacity);

std::string getReservedDimmUid() const;
void setReservedDimmUid(const std::string &uid);
ReserveDimmType getReservedDimmCapacityType() const;
void setReservedDimmCapacityType(const ReserveDimmType type);
bool hasReservedDimm() const;
Dimm getReservedDimm() const;

std::vector<Dimm> getDimms() const;
size_t getNumberOfDimms() const;
void addDimm(const Dimm &dimm);
void setDimms(const std::vector<Dimm> &dimmList);
std::vector<Dimm> getNonReservedDimms() const;

NVM_UINT64 getAllMappableNonReservedCapacity() const;
NVM_UINT64 getAllMappableDimmCapacityInGiB() const;
NVM_UINT64 getRequestedMappedCapacityInBytes() const;
virtual NVM_UINT64 getMemoryModeCapacityGiB() const;
virtual void setMemoryModeCapacityGiB(const NVM_UINT64 capacity);

virtual NVM_UINT64 getAppDirectCapacityGiB() const;
virtual AppDirectExtent getAppDirectExtent() const;
virtual void setAppDirectExtent(const AppDirectExtent &extent);

virtual bool isStorageRemaining() const;
virtual void setStorageRemaining(const bool storageIsRemaining);
virtual bool hasStorage() const;

virtual NVM_UINT64 getReserveStorageCapacityGiB() const;
virtual void setReserveStorageCapacityGiB(const NVM_UINT64 capacity);

virtual std::string getReservedDimmUid() const;
virtual void setReservedDimmUid(const std::string &uid);
virtual ReserveDimmType getReservedDimmCapacityType() const;
virtual void setReservedDimmCapacityType(const ReserveDimmType type);
virtual bool hasReservedDimm() const;
virtual Dimm getReservedDimm() const;

virtual std::vector<Dimm> getDimms() const;
virtual size_t getNumberOfDimms() const;
virtual void addDimm(const Dimm &dimm);
virtual void setDimms(const std::vector<Dimm> &dimmList);
virtual std::vector<Dimm> getNonReservedDimms() const;

virtual NVM_UINT64 getAllMappableNonReservedCapacity() const;
virtual NVM_UINT64 getAllMappableDimmCapacityInGiB() const;
virtual NVM_UINT64 getRequestedMappedCapacityInBytes() const;

// TODO: Update this function and move it to utils when nvm_get_socket
// is updated to get mapped memory limit (US20271)
Expand Down

0 comments on commit 029538f

Please sign in to comment.