ppsspp: add ppsspp-0004 CWE-407 mutex waitingThreads dedup, extend unit test to 8/8 PASS
ppsspp-0004: sceKernelLockMutex/CB and sceKernelLockLwMutex/CB (4 sites) scan mutex->waitingThreads vector with std::find before push_back -- O(W) per lock attempt. Fix: parallel unordered_set for O(1) dedup. Unit test extended to cover ppsspp-0004; all 8/8 PASS (ratios 5-27x).
This commit is contained in:
parent
7fa196837a
commit
54827d6eb7
3 changed files with 79 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import java.util.*;
|
|||
* ppsspp-0001: sceKernelThread waitingThreads vector dedup O(W^2)
|
||||
* ppsspp-0002: sceKernelSemaphore waitingThreads vector dedup O(W^2)
|
||||
* ppsspp-0003: IRJit byPage_ block removal O(P*B)
|
||||
* ppsspp-0004: sceKernelMutex waitingThreads vector dedup O(W^2) -- 4 sites
|
||||
*/
|
||||
public class PpssppKernelDedup {
|
||||
|
||||
|
|
@ -169,6 +170,47 @@ public class PpssppKernelDedup {
|
|||
if (ok) passed++; else failed++;
|
||||
}
|
||||
|
||||
// --- Test 7: ppsspp-0004 correctness (mutex, 4 sites, same pattern) ---
|
||||
// Models sceKernelLockMutex / sceKernelLockMutexCB /
|
||||
// sceKernelLockLwMutex / sceKernelLockLwMutexCB tight-loop timeout.
|
||||
{
|
||||
int nThreads = 30;
|
||||
int nRetries = 20; // each thread retries 20x under timeout
|
||||
List<Integer> defect = new ArrayList<>();
|
||||
List<Integer> fixed = new ArrayList<>();
|
||||
Set<Integer> fixedSet = new HashSet<>();
|
||||
for (int retry = 0; retry < nRetries; retry++) {
|
||||
for (int tid = 0; tid < nThreads; tid++) {
|
||||
addWaiter_defective(defect, tid);
|
||||
addWaiter_fixed(fixed, fixedSet, tid);
|
||||
}
|
||||
}
|
||||
boolean ok = defect.size() == nThreads && fixed.size() == nThreads;
|
||||
System.out.println((ok ? "PASS" : "FAIL") + " ppsspp-0004 correctness: mutex waiter dedup (4 sites)");
|
||||
if (ok) passed++; else failed++;
|
||||
}
|
||||
|
||||
// --- Test 8: ppsspp-0004 performance (mutex contention scale) ---
|
||||
{
|
||||
int W = 3000;
|
||||
List<Integer> defect = new ArrayList<>();
|
||||
long t0 = System.nanoTime();
|
||||
for (int tid = 0; tid < W; tid++) addWaiter_defective(defect, tid);
|
||||
long defectNs = System.nanoTime() - t0;
|
||||
|
||||
List<Integer> fixed = new ArrayList<>();
|
||||
Set<Integer> fixedSet = new HashSet<>();
|
||||
t0 = System.nanoTime();
|
||||
for (int tid = 0; tid < W; tid++) addWaiter_fixed(fixed, fixedSet, tid);
|
||||
long fixedNs = System.nanoTime() - t0;
|
||||
|
||||
double ratio = (double) defectNs / Math.max(fixedNs, 1);
|
||||
boolean ok = ratio > 5.0;
|
||||
System.out.printf("%s ppsspp-0004 performance: W=%d defect=%.1fms fixed=%.1fms ratio=%.1fx%n",
|
||||
ok ? "PASS" : "FAIL", W, defectNs / 1e6, fixedNs / 1e6, ratio);
|
||||
if (ok) passed++; else failed++;
|
||||
}
|
||||
|
||||
System.out.printf("%n%d/%d tests passed%n", passed, passed + failed);
|
||||
if (failed > 0) System.exit(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue