1classdef CacheTask < Task
2 % A software server in a LayeredNetwork.
4 % Supports multi-level cache hierarchies with configurable capacities
5 % per level (e.g., L1, L2, L3 caches).
7 % Copyright (c) 2012-2026, Imperial College London
13 itemLevelCap; % Scalar or array
for multi-level cache capacities
15 retrieval =
false; % delayed-hit retrieval on
the miss path
20 %
public methods, including constructor
23 function self = CacheTask(model, name, nitems, itemLevelCap, replStrat, multiplicity, scheduling)
24 %self = CacheTask(model, name, nitems, itemLevelCap, replStrat, multiplicity, scheduling)
26 % itemLevelCap can be:
27 % - Scalar: Single-level cache with given capacity
28 % - Vector: Multi-level cache with capacity per level
30 if ~exist(
'name',
'var')
31 line_error(mfilename,'Constructor requires to specify at least a name.');
39 scheduling = SchedStrategy.FCFS;
41 self@Task(model, name, multiplicity, scheduling);
45 % Validate and store itemLevelCap (scalar or array)
46 if isscalar(itemLevelCap)
47 self.itemLevelCap = itemLevelCap;
48 elseif isvector(itemLevelCap)
49 self.itemLevelCap = itemLevelCap(:)'; % Ensure row vector
51 line_error(mfilename, 'itemLevelCap must be scalar or vector');
54 self.replacestrategy = replStrat;
57 % Get item level capacity
58 function cap = getItemLevelCap(self, level)
59 % CAP = GETITEMLEVELCAP(SELF, LEVEL)
61 % Get capacity for a specific cache level or all levels.
64 % level: (optional) Cache level index (1-based)
67 % cap: Capacity value(s) - scalar if level specified, array otherwise
71 cap = self.itemLevelCap;
73 % Return specific level
74 if isscalar(self.itemLevelCap)
77 line_error(mfilename, 'Single-level cache only has level 1');
79 cap = self.itemLevelCap;
82 if level < 1 || level > length(self.itemLevelCap)
83 line_error(mfilename, sprintf('Level %d out of range [1, %d]', level, length(self.itemLevelCap)));
85 cap = self.itemLevelCap(level);
90 % Get total capacity across all levels
91 function total = getTotalCapacity(self)
92 % TOTAL = GETTOTALCAPACITY(SELF)
94 % Get
the sum of capacities across all cache levels.
97 % total: Sum of all level capacities
99 total = sum(self.itemLevelCap);
102 % Enable/disable delayed-hit retrieval on
the miss path
103 function self = setRetrieval(self, retrieval)
104 % SETRETRIEVAL(SELF, RETRIEVAL)
106 % Enable a retrieval system with delayed-hit coalescing on
the cache
107 % miss path. When set, concurrent misses for
the same item arriving
108 % while a fetch (
the miss-branch activity and its backend calls)
is in
109 % flight are parked and released together as delayed hits when
the
110 % fetch completes, instead of each triggering an independent fetch.
114 self.retrieval = logical(retrieval);
117 function tf = hasRetrieval(self)
121 % Set item level capacity
122 function setItemLevelCap(self, caps)
123 % SETITEMLEVELCAP(SELF, CAPS)
125 % Set cache level capacities.
128 % caps: Scalar for single-level or vector for multi-level
131 self.itemLevelCap = caps;
132 elseif isvector(caps)
133 self.itemLevelCap = caps(:)'; % Ensure row vector
135 line_error(mfilename, 'caps must be scalar or vector');
139 % Get number of cache levels
140 function n = getNumberOfLevels(self)
141 % N = GETNUMBEROFLEVELS(SELF)
143 % Get
the number of cache levels.
146 % n: Number of levels (1 for single-level, >1 for multi-level)
148 if isscalar(self.itemLevelCap)
151 n = length(self.itemLevelCap);