You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+20-15Lines changed: 20 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,11 @@ title: CPU Load Generator
5
5
6
6
# CPU Load Generator Project
7
7
8
-
Welcome to the CPU Load Generator project — a Python-based tool that generates a fixed CPU load for a finite period using a PID regulator.
8
+
Welcome to the CPU Load Generator project — a Python-based tool that generates a fixed CPU load for a finite or indefinite period on one or more CPU cores, using a **PI controller** (proportional–integral).
-**Monitor Thread** for actual CPU usage measurement
28
-
-**Controller Thread** (PID regulator)
28
+
-**Controller Thread** (PI regulator)
29
29
-**Actuator** adjusting sleep time for control
30
30
-**Disturbances** (e.g., other processes)
31
31
32
-
## 🧪 Monitor Thread
32
+
## Monitor Thread
33
33
34
-
Uses `psutil` to sample CPU load:
34
+
Uses `psutil` to sample the **current process**CPU usage (per core when affinity is set):
35
35
```python
36
-
psutil.cpu_percent(interval)
36
+
p = psutil.Process(os.getpid())
37
+
sample = p.cpu_percent(sampling_interval)
37
38
```
38
39
39
-
This blocks the thread for the sampling interval, ensuring timing consistency.
40
+
The call blocks for the sampling interval, ensuring timing consistency.
40
41
41
-
## 🔧 Controller Thread (PID Regulator)
42
+
## Controller Thread (PI Regulator)
42
43
43
-
Calculates a control signal to modulate load. If error is positive (load too low), it **reduces sleep** to increase load, and vice versa.
44
+
Calculates a control signal (sleep time) to modulate load. If the error is positive (load too low), it **reduces sleep** to increase load, and vice versa. Tuned experimentally with `kp` and `ki`.
45
+
46
+
## Actuator
47
+
48
+
The actuator applies the controller output by alternating CPU-bound work and sleep. Less sleep ⇒ higher load.
The figure below shows the controller maintaining 50% CPU load.
60
63
61
64

62
65
63
-
## 📎 Resources
66
+
**Supported platforms:** Linux, macOS, and Windows (see [README](https://github.com/GaetanoCarlucci/CPULoadGenerator#readme) for setup). Use `--plot` to show the load curve and save a PNG.
67
+
68
+
## Resources
64
69
65
70
-[Source Code on GitHub](https://github.com/GaetanoCarlucci/CPULoadGenerator)
0 commit comments