LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_nc_retrieval_analyzer.m
1function [QN,UN,RN,TN,CN,XN,lG,hitprob,missprob,delayedprob,hitproblist,itemprob,latency,runtime,method] = solver_nc_retrieval_analyzer(sn, options)
2% [Q,U,R,T,C,X,LG,HITPROB,MISSPROB,DELAYEDPROB,HITPROBLIST,LATENCY,RUNTIME,METHOD] = SOLVER_NC_RETRIEVAL_ANALYZER(SN, OPTIONS)
3%
4% Exact analysis of a delayed-hit (retrieval-system) cache via the product-form
5% recurrence algorithms: retrieval_nc (normalizing constant) and retrieval_metrics
6% (hit / miss / delayed-hit ratios). Latency is left to SolverMVA
7% (retrieval_fpi_latency) and returned as NaN here.
8
9% Copyright (c) 2012-2026, Imperial College London
10% All rights reserved.
11
12T0 = tic;
13CN = [];
14XN = zeros(1, sn.nclasses);
15QN = zeros(sn.nstations, sn.nclasses);
16UN = zeros(sn.nstations, sn.nclasses);
17RN = zeros(sn.nstations, sn.nclasses);
18TN = zeros(sn.nstations, sn.nclasses);
19method = 'exact';
20
21line_debug('NC retrieval analyzer starting: nclasses=%d', sn.nclasses);
22
23[m, lambda, gamma, eta, alpha, T, R, station_type] = cache_retrieval_inputs(sn); %#ok<ASGLU>
24n = numel(lambda);
25r = sum(station_type == "PS");
26
27% --- exact normalizing constant E(m) = retrieval_nc(0,m,...) ---
28E = retrieval_nc(zeros(1, r), m, lambda, eta, gamma);
29lG = log(E);
30
31% --- exact hit / miss / delayed-hit ratios ---
32[pmiss, phit, pdh] = retrieval_metrics(m, lambda, eta, gamma);
33pi0 = pmiss(:).'; % per-item miss pi_{i,0}
34pih = sum(phit, 1); % per-item hit sum_j pi_{i,j}
35phid = sum(pdh, 1); % per-item delayed sum_s phi_{s,i}
36
37% --- read class and per-class aggregates (single read class) ---
38ci = find(sn.nodetype == NodeType.Cache);
39ch = sn.nodeparam{ci};
40rk = keys(ch.retrievalSystemQueueIndices);
41jobinClass = double(rk{1}) + 1;
42w = lambda(:) / sum(lambda); % access-weighted item mixture
43hitAgg = sum(w .* pih(:));
44missAgg = sum(w .* pi0(:));
45delayedAgg = sum(w .* phid(:));
46
47% --- source throughput ---
48source_ist = sn.nodeToStation(sn.nodetype == NodeType.Source);
49sourceRate = sn.rates(source_ist, :);
50sourceRate(isnan(sourceRate)) = 0;
51TN(source_ist, :) = sourceRate;
52
53% --- cache results (per-class vectors; read-class entry set, rest NaN).
54% hitprob is the TRUE hit fraction; delayedprob the delayed-hit fraction;
55% true hit + delayed + miss = 1 ---
56hitprob = NaN(1, sn.nclasses);
57missprob = NaN(1, sn.nclasses);
58delayedprob = NaN(1, sn.nclasses);
59latency = NaN(1, sn.nclasses);
60hitprob(jobinClass) = hitAgg;
61missprob(jobinClass) = missAgg;
62delayedprob(jobinClass) = delayedAgg; % delayed implicit: 1 - hit - miss = sum_s phi
63
64% per-list (per-level) hit fractions for the read class: phit is (h x n);
65% access-weighted over items gives the per-list hit probability.
66hitproblist = NaN(sn.nclasses, numel(m));
67hitproblist(jobinClass, :) = (phit * w(:)).';
68
69% per-item occupancy [nitems x (lists+1)]: column 1 = miss (item not cached),
70% columns 2..end = probability the item resides in each list.
71itemprob = [pi0(:), phit.'];
72
73% --- throughputs: misses -> missclass, hits+delayed -> hitclass ---
74hc = ch.hitclass(jobinClass);
75mc = ch.missclass(jobinClass);
76if hc > 0, XN(hc) = sourceRate(jobinClass) * (hitAgg + delayedAgg); end
77if mc > 0, XN(mc) = sourceRate(jobinClass) * missAgg; end
78
79% --- retrieval-station mean occupancy (QLen) and throughput from phi/visits ---
80% phi_{s,i} (pdh) is the mean number of item i being retrieved at station s;
81% summing over items gives the station occupancy.
82queueNodes = double(ch.retrievalSystemQueueIndices(rk{1}));
83S = numel(queueNodes);
84isIdx = find(station_type == "IS"); %#ok<NASGU>
85psIdx = find(station_type == "PS" | station_type == "SIRO" | station_type == "FCFS" | station_type == "LCFSPR"); % SIRO/FCFS/LCFSPR as PS
86for s = 1:S
87 sst = sn.nodeToStation(queueNodes(s));
88 if station_type(s) == "PS" || station_type(s) == "SIRO" || station_type(s) == "FCFS" || station_type(s) == "LCFSPR"
89 prow = 1 + find(psIdx == s); % pdh row for this PS/SIRO/FCFS/LCFSPR station
90 else
91 prow = 1; % IS aggregate row
92 end
93 phi_s = 0;
94 if prow <= size(pdh, 1)
95 phi_s = sum(pdh(prow, :)); % station occupancy = utilization (paper phi_s)
96 end
97 % fetch throughput through station s = sum_i (item fetch rate)*visits_{s,i}
98 tput_s = 0;
99 for i = 1:n
100 Ri = R(:, :, i);
101 a = Ri(1, 2:S+1);
102 Pmat = Ri(2:S+1, 2:S+1);
103 vis = a / (eye(S) - Pmat);
104 tput_s = tput_s + sourceRate(jobinClass) * (lambda(i)/sum(lambda)) * pi0(i) * vis(s);
105 end
106 QN(sst, jobinClass) = phi_s;
107 UN(sst, jobinClass) = phi_s;
108 TN(sst, jobinClass) = tput_s;
109 if tput_s > 0
110 RN(sst, jobinClass) = phi_s / tput_s; % Little's law sojourn time
111 end
112end
113
114runtime = toc(T0);
115end
Definition Station.m:245