1function [QN,UN,RN,TN,CN,XN,lGN,runtime,iter,method,hitproblist,itemprob] = solver_mva_cache_analyzer(sn, options)
2% [Q,U,R,T,C,X,LG,RUNTIME,ITER,METHOD,HITPROBLIST] = SOLVER_MVA_CACHE_ANALYZER(QN, OPTIONS)
4% Copyright (c) 2012-2026, Imperial College London
11XN = zeros(1,sn.nclasses);
15line_debug(
'MVA cache analyzer starting: method=%s, nclasses=%d', options.method, sn.nclasses);
17source_ist = sn.nodeToStation(sn.nodetype == NodeType.Source);
18sourceRate = sn.rates(source_ist,:);
19sourceRate(isnan(sourceRate)) = 0;
20TN(source_ist,:) = sourceRate;
22ch = sn.nodeparam{sn.nodetype == NodeType.Cache};
33 if ~isnan(ch.pread{v})
34 lambda(v,k,l) = sourceRate(v) * ch.pread{v}(k);
42 % Default linear cache routing: items flow from list l to list l+1
46 Rmat = diag(ones(1, h), 1);
53gamma = cache_gamma_lp(lambda,Rcost);
55% per-list (per-level) hit probabilities are reported only from
the exact
56% algorithm, where
the miss
column and
the per-list columns of pij share one
57% consistent solution (so
the per-list rows sum to
the aggregate hit). For
58%
the approximate algorithms
the per-list breakdown
is left undefined (NaN).
59pijlist = []; % genuine per-list occupancy (n x h), set in
the exact branch
62 line_debug(
'Using exact cache method');
63 switch sn.nodeparam{sn.nodetype == NodeType.Cache}.replacestrat
64 case {ReplacementStrategy.RR, ReplacementStrategy.FIFO}
65 line_debug(
'Replacement strategy: RR/FIFO, calling cache_mva');
66 [~,~,pij] = cache_mva(gamma, m);
67 pij = [abs(1-sum(pij,2)),pij];
68 pijlist = pij(:, 2:end);
70 line_error(mfilename,
'MVA does not support exact solution of the specified cache replacement policy.')
73 line_debug('Default method: using approximate cache method\n');
74 line_debug('Using approximate cache method');
75 switch sn.
nodeparam{sn.nodetype == NodeType.Cache}.replacestrat
76 case {ReplacementStrategy.RR, ReplacementStrategy.FIFO}
77 line_debug(
'Replacement strategy: RR/FIFO, calling cache_prob_fpi');
78 pij = cache_prob_fpi(gamma,m); % FPI method
79 case ReplacementStrategy.LRU
80 % Marked (
MMAP) source: items are driven by per-mark MAPs, so
81 %
the request sequence
is not IRM; use
the LRU(m)-MAP TTL
82 % approximation (Gast-Van Houdt, PEVA 2017). For a plain MAP
83 % source with i.i.d. popularity marks
the sequence
is IRM and
84 % cache_ttl_lrua
is already sequence-exact.
85 markedreaders = isfield(sn,
'markidx') && ~isempty(sn.markidx) ...
86 && any(sn.markidx(source_ist,:) > 0);
88 Dcell = sn.proc{source_ist}{find(sn.markidx(source_ist,:)>0,1)};
89 D0 = Dcell{1}; D1agg = Dcell{2};
90 D0c = cell(1,n); D1c = cell(1,n);
93 D1c{k} = zeros(size(D0));
95 if ~isnan(ch.pread{v})
96 if sn.markidx(source_ist,v) > 0
97 D1c{k} = D1c{k} + Dcell{2+sn.markidx(source_ist,v)} * ch.pread{v}(k);
98 elseif sourceRate(v) > 0 && any(ch.pread{v} > 0)
99 allmarked = false; % unmarked reader mixed in
103 D0c{k} = D0 + D1agg - D1c{k};
106 line_debug(
'Replacement strategy: LRU with marked MAP source, calling cache_ttl_lrum_map');
107 pij = cache_ttl_lrum_map(D0c, D1c, m);
109 line_debug(
'Replacement strategy: LRU, calling cache_ttl_lrua');
110 pij = cache_ttl_lrua(lambda, Rcost, m); % allows trees and access costs
113 line_debug(
'Replacement strategy: LRU, calling cache_ttl_lrua');
114 pij = cache_ttl_lrua(lambda, Rcost, m); % allows trees and access costs
116 case ReplacementStrategy.HLRU
117 % h-LRU / LRU(m) characteristic-time approximation (linear
118 % list topology; access-cost graphs are not supported)
119 line_debug(
'Replacement strategy: HLRU, calling cache_ttl_hlru');
120 pij = cache_ttl_hlru(lambda, m);
122 line_error(mfilename,
'MVA does not support approximate solution of the specified cache replacement policy.')
125missRate = zeros(1,u);
127 missRate(v) = lambda(v,:,1)*pij(:,1);
130% per-list (per-level) hit probabilities (access-weighted), only where
the
131% exact algorithm produced a genuine per-list occupancy matrix.
132hitproblist = NaN(u, h);
135 if any(~isnan(ch.pread{v}))
136 pread = ch.pread{v}(:).
';
138 hitproblist(v,l) = pread * pijlist(:,l);
144% per-item occupancy [nitems x (lists+1)] (col 1 = miss, cols 2..end per-list).
145% This requires a genuine per-list distribution (rows summing to 1):
146% - exact algorithm: pij is already genuine;
147% - approximate LRU (cache_ttl_lrua): pij is a genuine per-list distribution;
148% - approximate RR/FIFO: the FPI algorithm (cache_prob_fpi) replicates the
149% aggregate hit across list columns, so it is NOT a genuine per-list
150% breakdown; derive it from the exact product-form algorithm cache_mva instead
151% (the FPI pij is still used above for the aggregate miss rate).
152% The exact RR/FIFO recursion (cache_mva) is only tractable for small item
153% sets, so it is skipped (NaN, with a warning) for caches with more than 10
157 itemprob = pij; % exact branch: already [n x (h+1)] with col 1 = miss
158elseif size(pij,2) == h+1
159 switch sn.nodeparam{sn.nodetype == NodeType.Cache}.replacestrat
160 case {ReplacementStrategy.RR, ReplacementStrategy.FIFO}
162 line_warning(mfilename, 'Per-item cache occupancy (getAvgItemTable)
requires the exact algorithm
for RR/FIFO and
is skipped
for caches with more than 10 items (%d items); reporting NaN.
', n);
163 itemprob = NaN(n, h+1);
165 [~,~,pij_ex] = cache_mva(gamma, m);
166 itemprob = [abs(1-sum(pij_ex,2)), pij_ex];
169 itemprob = pij; % LRU-TTL: genuine per-list distribution
174 if length(ch.hitclass)>=r && ch.missclass(r)>0 && ch.hitclass(r)>0
175 XN(ch.missclass(r)) = XN(ch.missclass(r)) + missRate(r);
176 XN(ch.hitclass(r)) = XN(ch.hitclass(r)) + (sourceRate(r) - missRate(r));
180% Set the actual method used
181if strcmp(options.method, 'exact
')
184 switch sn.nodeparam{sn.nodetype == NodeType.Cache}.replacestrat
185 case {ReplacementStrategy.RR, ReplacementStrategy.FIFO}
187 case ReplacementStrategy.LRU
190 method = options.method;