Created
February 11, 2026 14:04
-
-
Save franz1981/013bb0de952647086cd477c46e36a186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from mpl_toolkits.mplot3d import Axes3D | |
| # 1. Set up parameter ranges | |
| # Global injection rate from 10k to 90k TPS | |
| Lambdas = np.linspace(10000, 90000, 20) | |
| # Service times from 5 us to 150 us | |
| S_FJ = np.linspace(0.000005, 0.000150, 20) | |
| S_IO = np.linspace(0.000005, 0.000150, 20) | |
| # Create 3D grid | |
| L, FJ, IO = np.meshgrid(Lambdas, S_FJ, S_IO) | |
| L_flat, FJ_flat, IO_flat = L.flatten(), FJ.flatten(), IO.flatten() | |
| # 2. System 1: 8 FJ + 8 EL pairs | |
| lambda_pair = L_flat / 8.0 | |
| # Doubled for Req + Res signals | |
| lambda_signal_pair = lambda_pair * 2 | |
| rho_FJ = lambda_signal_pair * FJ_flat | |
| rho_IO = lambda_signal_pair * IO_flat | |
| P_idle_FJ = 1 - rho_FJ | |
| P_idle_IO = 1 - rho_IO | |
| ctx_sw_FJ_total = 8 * (lambda_signal_pair * P_idle_FJ) | |
| ctx_sw_IO_total = 8 * (lambda_signal_pair * P_idle_IO) | |
| total_CS_FJ_IO = ctx_sw_FJ_total + ctx_sw_IO_total | |
| # 3. System 2: 16 Custom Scheduler instances | |
| lambda_custom = L_flat / 16.0 | |
| # Doubled for Req + Res signals | |
| lambda_signal_custom = lambda_custom * 2 | |
| S_Custom = FJ_flat + IO_flat | |
| rho_C = lambda_signal_custom * S_Custom | |
| P_idle_C = 1 - rho_C | |
| total_CS_Custom = 16 * (lambda_signal_custom * P_idle_C) | |
| # 4. Masking to prevent queue buildup (rho < 0.9 for all queues) | |
| mask = (rho_FJ < 0.9) & (rho_IO < 0.9) & (rho_C < 0.9) | |
| # 5. Calculate the Ratio | |
| ratio = total_CS_FJ_IO[mask] / total_CS_Custom[mask] | |
| # 6. Plotting | |
| fig = plt.figure(figsize=(10, 8)) | |
| ax = fig.add_subplot(111, projection='3d') | |
| # Color 'c' is mapped to the ratio | |
| scatter = ax.scatter(L_flat[mask], FJ_flat[mask] * 1e6, IO_flat[mask] * 1e6, | |
| c=ratio, cmap='viridis', alpha=0.8, marker='o') | |
| cbar = fig.colorbar(scatter, ax=ax, shrink=0.5, aspect=5) | |
| cbar.set_label('Ratio (FJ+IO Context Switches / Custom Context Switches)') | |
| ax.set_xlabel('Global Injection Rate ($\Lambda$)') | |
| ax.set_ylabel('FJ Service Time ($\mu s$)') | |
| ax.set_zlabel('IO Service Time ($\mu s$)') | |
| ax.set_title('Ratio of Total Context Switches\n(Traditional vs Custom)') | |
| plt.tight_layout() | |
| # Print the min and max to the console to prove it's a constant | |
| print(f"Minimum Ratio calculated: {np.min(ratio)}") | |
| print(f"Maximum Ratio calculated: {np.max(ratio)}") | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment