sapling/eden/fs/store/ImportPriority.h
Ailin Zhang ce28ec8caa deprioiritize when fetch count exceeds threshold
Summary:
check fetch count before `getPriority()` is used. If fetch count has exceeded `fetchThreshold_`, lower the priority by 1.

Note: this diff only guarantees that the `getPriority()` function is returning the lowered priority. How the returned value is used for scheduling is handled by `HgQueuedBackingStore`

Reviewed By: kmancini

Differential Revision: D22550640

fbshipit-source-id: c032f8f72ca658618ac118dfb3ad3dcae61e9735
2020-07-24 08:24:02 -07:00

66 lines
1.9 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <cstdint>
namespace facebook {
namespace eden {
enum class ImportPriorityKind : int16_t { Low = 0, Normal = 1, High = 2 };
struct ImportPriority {
ImportPriorityKind kind;
uint64_t offset : 48;
static constexpr ImportPriority kLow() {
return ImportPriority{ImportPriorityKind::Low};
}
static constexpr ImportPriority kNormal() {
return ImportPriority{ImportPriorityKind::Normal};
}
static constexpr ImportPriority kHigh() {
return ImportPriority{ImportPriorityKind::High};
}
// set half of the maximum offset as default offset to allow equal
// space for raising and lowering priority offset.
explicit constexpr ImportPriority()
: kind(ImportPriorityKind::Normal), offset(0x7FFFFFFFFFFF) {}
explicit constexpr ImportPriority(ImportPriorityKind kind)
: kind(kind), offset(0x7FFFFFFFFFFF) {}
constexpr ImportPriority(ImportPriorityKind kind, uint64_t offset)
: kind(kind), offset(offset) {}
constexpr inline int64_t value() const noexcept {
return (static_cast<int16_t>(kind) * (static_cast<uint64_t>(1) << 48)) +
offset;
}
/**
* Deprioritize ImportPriority by decreasing offset by delta.
* Note: this function maintains ImportPriorityKind, as jobs
* with higher priority kind are usually designed to be scheduled
* ealier and should not lower their kind even when deprioritized.
*/
constexpr ImportPriority getDeprioritized(uint64_t delta) const noexcept {
return ImportPriority{kind, offset > delta ? offset - delta : 0};
}
friend bool operator<(
const ImportPriority& lhs,
const ImportPriority& rhs) noexcept {
return lhs.value() < rhs.value();
}
};
} // namespace eden
} // namespace facebook