LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
CacheTask.m
1classdef CacheTask < Task
2 % A software server in a LayeredNetwork.
3 %
4 % Supports multi-level cache hierarchies with configurable capacities
5 % per level (e.g., L1, L2, L3 caches).
6 %
7 % Copyright (c) 2012-2026, Imperial College London
8 % All rights reserved.
9
10 properties
11
12 items;
13 itemLevelCap; % Scalar or array for multi-level cache capacities
14 replacestrategy;
15 retrieval = false; % delayed-hit retrieval on the miss path
16
17 end
18
19 methods
20 %public methods, including constructor
21
22 %constructor
23 function self = CacheTask(model, name, nitems, itemLevelCap, replStrat, multiplicity, scheduling)
24 %self = CacheTask(model, name, nitems, itemLevelCap, replStrat, multiplicity, scheduling)
25 %
26 % itemLevelCap can be:
27 % - Scalar: Single-level cache with given capacity
28 % - Vector: Multi-level cache with capacity per level
29
30 if ~exist('name','var')
31 line_error(mfilename,'Constructor requires to specify at least a name.');
32 end
33
34 if nargin < 6
35 multiplicity = 1;
36 end
37
38 if nargin < 7
39 scheduling = SchedStrategy.FCFS;
40 end
41 self@Task(model, name, multiplicity, scheduling);
42
43 self.items = nitems;
44
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
50 else
51 line_error(mfilename, 'itemLevelCap must be scalar or vector');
52 end
53
54 self.replacestrategy = replStrat;
55 end
56
57 % Get item level capacity
58 function cap = getItemLevelCap(self, level)
59 % CAP = GETITEMLEVELCAP(SELF, LEVEL)
60 %
61 % Get capacity for a specific cache level or all levels.
62 %
63 % Args:
64 % level: (optional) Cache level index (1-based)
65 %
66 % Returns:
67 % cap: Capacity value(s) - scalar if level specified, array otherwise
68
69 if nargin == 1
70 % Return all levels
71 cap = self.itemLevelCap;
72 else
73 % Return specific level
74 if isscalar(self.itemLevelCap)
75 % Single-level cache
76 if level ~= 1
77 line_error(mfilename, 'Single-level cache only has level 1');
78 end
79 cap = self.itemLevelCap;
80 else
81 % Multi-level cache
82 if level < 1 || level > length(self.itemLevelCap)
83 line_error(mfilename, sprintf('Level %d out of range [1, %d]', level, length(self.itemLevelCap)));
84 end
85 cap = self.itemLevelCap(level);
86 end
87 end
88 end
89
90 % Get total capacity across all levels
91 function total = getTotalCapacity(self)
92 % TOTAL = GETTOTALCAPACITY(SELF)
93 %
94 % Get the sum of capacities across all cache levels.
95 %
96 % Returns:
97 % total: Sum of all level capacities
98
99 total = sum(self.itemLevelCap);
100 end
101
102 % Enable/disable delayed-hit retrieval on the miss path
103 function self = setRetrieval(self, retrieval)
104 % SETRETRIEVAL(SELF, RETRIEVAL)
105 %
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.
111 if nargin < 2
112 retrieval = true;
113 end
114 self.retrieval = logical(retrieval);
115 end
116
117 function tf = hasRetrieval(self)
118 tf = self.retrieval;
119 end
120
121 % Set item level capacity
122 function setItemLevelCap(self, caps)
123 % SETITEMLEVELCAP(SELF, CAPS)
124 %
125 % Set cache level capacities.
126 %
127 % Args:
128 % caps: Scalar for single-level or vector for multi-level
129
130 if isscalar(caps)
131 self.itemLevelCap = caps;
132 elseif isvector(caps)
133 self.itemLevelCap = caps(:)'; % Ensure row vector
134 else
135 line_error(mfilename, 'caps must be scalar or vector');
136 end
137 end
138
139 % Get number of cache levels
140 function n = getNumberOfLevels(self)
141 % N = GETNUMBEROFLEVELS(SELF)
142 %
143 % Get the number of cache levels.
144 %
145 % Returns:
146 % n: Number of levels (1 for single-level, >1 for multi-level)
147
148 if isscalar(self.itemLevelCap)
149 n = 1;
150 else
151 n = length(self.itemLevelCap);
152 end
153 end
154 end
155end
Definition Station.m:245