minimumShareAdmissionGenerator function
Creates a minimum-share policy with reclaimable capacity above each share.
minimumShares reserves only the entries still needed for another pool to
reach its minimum occupancy. A selected pool below its own minimum is
always admitted when aggregate capacity is available. A pool already at its
minimum may borrow only capacity beyond every other pool's remaining
minimum-share deficit.
Implementation
SharedPoolAdmissionGenerator minimumShareAdmissionGenerator(
List<int> minimumShares,
{required int totalCapacity}) =>
(
{required poolSelected,
required poolOccupancies,
required capacityAvailable,
required accepted,
required clk,
required reset,
required name}) {
if (minimumShares.length != poolSelected.length ||
minimumShares.length != poolOccupancies.length ||
minimumShares.any((share) => share < 0) ||
minimumShares.fold(0, (sum, share) => sum + share) > totalCapacity) {
throw ArgumentError.value(minimumShares, 'minimumShares',
'Must fit capacity and provide one non-negative share per pool.');
}
Logic totalOccupancy = Const(0, width: poolOccupancies.first.width);
for (final occupancy in poolOccupancies) {
totalOccupancy =
(totalOccupancy + occupancy).zeroExtend(totalOccupancy.width);
}
final freeSlots =
Const(totalCapacity, width: totalOccupancy.width) - totalOccupancy;
// With same-cycle refill enabled, a full adapter has one newly freed
// slot even though the registered occupancy still reports full.
final refillOnlyCapacity = (capacityAvailable & freeSlots.eq(0))
.named('${name}_refill_only_capacity');
final availableSlots =
mux(refillOnlyCapacity, Const(1, width: freeSlots.width), freeSlots)
.named('${name}_available_slots');
Logic admitted = Const(0);
for (var pool = 0; pool < minimumShares.length; pool++) {
Logic otherDeficits = Const(0, width: availableSlots.width);
for (var other = 0; other < minimumShares.length; other++) {
if (other == pool) {
continue;
}
final occupancy = poolOccupancies[other];
final belowMinimum = occupancy
.lt(Const(minimumShares[other], width: occupancy.width))
.named('${name}_below_minimum_${pool}_$other');
final missingMinimumShare =
(Const(minimumShares[other], width: occupancy.width) - occupancy)
.named('${name}_missing_minimum_share_${pool}_$other');
final deficit = mux(belowMinimum, missingMinimumShare,
Const(0, width: occupancy.width))
.named('${name}_deficit_${pool}_$other');
otherDeficits =
(otherDeficits + deficit).zeroExtend(otherDeficits.width);
}
final belowOwnMinimum = poolOccupancies[pool]
.lt(Const(minimumShares[pool], width: poolOccupancies[pool].width))
.named('${name}_below_own_minimum_$pool');
final poolMayUseSharedCapacity =
(belowOwnMinimum | availableSlots.gt(otherDeficits))
.named('${name}_pool_may_use_shared_capacity_$pool');
admitted = (admitted | (poolSelected[pool] & poolMayUseSharedCapacity))
.named('${name}_admitted_through_pool_$pool');
}
return admitted.named('${name}_minimum_share_admitted');
};