Skip to content

Commit 8cfd804

Browse files
Update index.html
1 parent 6ed499a commit 8cfd804

File tree

1 file changed

+61
-12
lines changed

1 file changed

+61
-12
lines changed

docs/index.html

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
layout: default # use the layout that ships with jekyll-theme-minimal
3-
title: CPU Load Generator # appears in the <title> tag and navbar (if any)
2+
layout: default # jekyll-theme-minimal supplies this layout
3+
title: CPU Load Generator
44
---
55

66
<!-- lightweight, self‑contained styling -->
@@ -57,13 +57,12 @@
5757
}
5858
</style>
5959

60-
<!-- ===== Hero ===== -->
6160
<header>
6261
<h1>CPU Load Generator</h1>
6362
<p>
6463
Generate a fixed, precisely regulated CPU load with a lean Python script that uses a PID controller.<br />
6564
<a href="https://github.com/GaetanoCarlucci/CPULoadGenerator"
66-
target="_blank" rel="noopener">View the project on GitHub ↗︎</a>
65+
target="_blank" rel="noopener">View the project on GitHub ↗︎</a>
6766
</p>
6867
</header>
6968

@@ -76,11 +75,11 @@ <h2>Motivation</h2>
7675
<strong>stable CPU load for a finite period</strong> by closing the loop with a PID regulator.
7776
</p>
7877
<ul>
79-
<li><strong>Performance&nbsp;testing:&nbsp;</strong>Stress‑test applications and full systems to uncover bottlenecks and verify robustness under load.</li>
80-
<li><strong>Resource‑allocation optimisation:&nbsp;</strong>Reproduce real‑world utilisation scenarios so you can fine‑tune CPU quotas and scheduling policies.</li>
81-
<li><strong>Benchmarking:&nbsp;</strong>Generate a consistent, repeatable workload that makes it easy to compare CPUs, machines, or configurations.</li>
82-
<li><strong>Education&nbsp;&amp;&nbsp;training:&nbsp;</strong>Give students hands‑on experience with discrete PID control and demonstrate how load impacts performance.</li>
83-
<li><strong>Thermal&nbsp;/&nbsp;power analysis:&nbsp;</strong>Investigate heat dissipation and energy consumption under a controlled, steady workload.</li>
78+
<li><strong>Performance&nbsp;testing:</strong> Stress‑test applications and full systems to uncover bottlenecks and verify robustness under load.</li>
79+
<li><strong>Resource‑allocation optimisation:</strong> Reproduce real‑world utilisation scenarios so you can fine‑tune CPU quotas and scheduling policies.</li>
80+
<li><strong>Benchmarking:</strong> Generate a consistent, repeatable workload that makes it easy to compare CPUs, machines, or configurations.</li>
81+
<li><strong>Education&nbsp;&amp;&nbsp;training:</strong> Give students hands‑on experience with discrete PID control and demonstrate how load impacts performance.</li>
82+
<li><strong>Thermal&nbsp;/&nbsp;power analysis:</strong> Investigate heat dissipation and energy consumption under a controlled, steady workload.</li>
8483
</ul>
8584
</section>
8685

@@ -110,12 +109,62 @@ <h3>Controller Thread</h3>
110109
(<code>K<sub>i</sub></code>) actions. The derivative term is not used.
111110
</p>
112111

113-
```python
114-
# actuator snippet
112+
<pre><code># actuator snippet
115113
def generate_load(self, sleep_time):
116114
interval = time.time() + self.period - sleep_time
117115
while time.time() < interval:
118116
pr = 213123 # busy‑work
119117
_ = pr * pr
120118
pr = pr + 1
121-
time.sleep(sleep_time)
119+
time.sleep(sleep_time)</code></pre>
120+
121+
<pre><code># main PI control loop
122+
def run(self):
123+
def cpu_model(cpu_period):
124+
return self.period - cpu_period # maps period to sleep time
125+
126+
self.shutdown_flag.clear()
127+
while not self.shutdown_flag.is_set():
128+
time.sleep(self.sampling_interval)
129+
130+
with self.target_lock, self.cpu_lock:
131+
CT = self.CT # target load
132+
cpu = self.cpu # measured load
133+
134+
self.err = CT - cpu * 0.01
135+
ts = time.time()
136+
samp_int = ts - self.last_ts
137+
self.int_err += self.err * samp_int
138+
self.last_ts = ts
139+
self.cpuPeriod = (self.kp * self.err +
140+
self.ki * self.int_err)
141+
142+
# anti‑windup
143+
self.cpuPeriod = max(0, min(self.cpuPeriod, self.period))
144+
self.set_sleep_time(cpu_model(self.cpuPeriod))</code></pre>
145+
146+
<h3>PI tuning insights</h3>
147+
<p>
148+
Raising <code>K<sub>p</sub></code> speeds up the response but risks overshoot; adding an
149+
integral term removes steady‑state error at the cost of sluggishness
150+
and potential oscillations, so anti‑windup is essential.
151+
</p>
152+
</section>
153+
154+
<!-- ===== Results ===== -->
155+
<section id="results">
156+
<h2>Results</h2>
157+
<p>
158+
Quick test in a GitHub Codespace or local shell:<br>
159+
<code>./CPULoadGenerator.py -c 0 -c 3 -l 0.55 -l 0.12</code>
160+
</p>
161+
162+
<p>Example 50 % target load on core 0 for 20 s:</p>
163+
<img src="https://gaetanocarlucci.altervista.org/wp-content/uploads/2024/07/50-Target-Load.png"
164+
alt="CPU‑load plot" loading="lazy">
165+
</section>
166+
</main>
167+
168+
<footer>
169+
MIT License &bull; © 2025 Gaetano Carlucci
170+
</footer>

0 commit comments

Comments
 (0)