This commit is contained in:
2026-04-04 02:26:06 +02:00
parent a1b0f47f47
commit f9bbe58894
4 changed files with 80 additions and 20 deletions

View File

@@ -66,9 +66,3 @@ NOTE: we're mostly bottlenecked by the architecture (typically a Lua VM) and the
- make signals use a circular buffer instead of a simple array - make signals use a circular buffer instead of a simple array
- use more arenas if possible - use more arenas if possible
# Drive costs
The drive has platters just like in OC, as well as a cache line.
The read cost is only factored in if `cachelineOf(lastSector) != cachelineOf(newSector)`.
Seek cost is also in whole cache lines.

View File

@@ -382,7 +382,8 @@ int main(int argc, char **argv) {
"component.invoke(g, 'set', 1, 1, 'starting sequential bench...')\n" "component.invoke(g, 'set', 1, 1, 'starting sequential bench...')\n"
"local start = computer.uptime()\n" "local start = computer.uptime()\n"
"local cap = component.invoke(d, 'getCapacity')\n" "local cap = component.invoke(d, 'getCapacity')\n"
"local bc = component.invoke(d, 'getCapacity') / component.invoke(d, 'getSectorSize')\n" "local ss = component.invoke(d, 'getSectorSize')\n"
"local bc = cap / ss\n"
"for i=1,bc do component.invoke(d, 'readSector', i) end\n" "for i=1,bc do component.invoke(d, 'readSector', i) end\n"
"local now = computer.uptime()\n" "local now = computer.uptime()\n"
"component.invoke(g, 'set', 1, 2, 'took ' .. (now - start) .. 's')\n" "component.invoke(g, 'set', 1, 2, 'took ' .. (now - start) .. 's')\n"
@@ -391,15 +392,15 @@ int main(int argc, char **argv) {
"component.invoke(g, 'bind', s, true)\n" "component.invoke(g, 'bind', s, true)\n"
"component.invoke(g, 'set', 1, 1, 'starting random bench...')\n" "component.invoke(g, 'set', 1, 1, 'starting random bench...')\n"
"start = computer.uptime()\n" "start = computer.uptime()\n"
"local shortcut = 4\n" "local rand = 256\n"
"for i=1,bc/shortcut do local i = math.random(1, bc) component.invoke(d, 'readSector', i) end\n" "for i=1,rand do local i = math.random(1, bc) component.invoke(d, 'readSector', i) end\n"
"now = computer.uptime()\n" "now = computer.uptime()\n"
"component.invoke(g, 'set', 1, 2, 'took ' .. (now - start) .. 's')\n" "component.invoke(g, 'set', 1, 2, 'took ' .. (now - start) .. 's')\n"
"component.invoke(g, 'set', 1, 3, 'random read speed: ' .. (cap / shortcut / (now - start)) .. 'B/s')\n" "component.invoke(g, 'set', 1, 3, 'random read speed: ' .. (rand * ss / (now - start)) .. 'B/s')\n"
"while computer.uptime() < now + 3 do computer.pullSignal(0.05) end\n" "while computer.uptime() < now + 3 do computer.pullSignal(0.05) end\n"
"computer.shutdown(true)\n" "computer.shutdown(true)\n"
; ;
nn_Component *testDrive = ncl_createDrive(u, NULL, &nn_floppyDrive, testDriveData, strlen(testDriveData), false); nn_Component *testDrive = ncl_createDrive(u, NULL, &nn_defaultSSDs[3], testDriveData, strlen(testDriveData), false);
ncl_setCLabel(managedfs, "Main Filesystem"); ncl_setCLabel(managedfs, "Main Filesystem");
ncl_setCLabel(testingfs, "Secondary Filesystem"); ncl_setCLabel(testingfs, "Secondary Filesystem");
@@ -450,6 +451,7 @@ restart:;
// collects stats // collects stats
nn_setEnergyHandler(c, NULL, ne_energy_accumulator); nn_setEnergyHandler(c, NULL, ne_energy_accumulator);
} }
nn_setCallBudget(c, 0);
// default for 64-bit // default for 64-bit
if(sizeof(void *) > 4) nn_setMemoryScale(c, 1.8); if(sizeof(void *) > 4) nn_setMemoryScale(c, 1.8);

View File

@@ -2423,7 +2423,7 @@ const nn_Filesystem nn_defaultTmpFS = NN_INIT(nn_Filesystem) {
.spaceTotal = 64 * NN_KiB, .spaceTotal = 64 * NN_KiB,
.readsPerTick = 1024, .readsPerTick = 1024,
.writesPerTick = 512, .writesPerTick = 512,
.dataEnergyCost = 512.0 / NN_MiB, .dataEnergyCost = 0.1 / NN_MiB,
}; };
const nn_Drive nn_defaultDrives[4] = { const nn_Drive nn_defaultDrives[4] = {
@@ -2436,7 +2436,7 @@ const nn_Drive nn_defaultDrives[4] = {
.writesPerTick = 10, .writesPerTick = 10,
.rpm = 3600, .rpm = 3600,
.onlySpinForwards = false, .onlySpinForwards = false,
.dataEnergyCost = 256.0 / NN_MiB, .dataEnergyCost = 4.0 / NN_MiB,
}, },
NN_INIT(nn_Drive) { NN_INIT(nn_Drive) {
.capacity = 2 * NN_MiB, .capacity = 2 * NN_MiB,
@@ -2447,29 +2447,29 @@ const nn_Drive nn_defaultDrives[4] = {
.writesPerTick = 15, .writesPerTick = 15,
.rpm = 5400, .rpm = 5400,
.onlySpinForwards = false, .onlySpinForwards = false,
.dataEnergyCost = 512.0 / NN_MiB, .dataEnergyCost = 8.0 / NN_MiB,
}, },
NN_INIT(nn_Drive) { NN_INIT(nn_Drive) {
.capacity = 4 * NN_MiB, .capacity = 4 * NN_MiB,
.sectorSize = 512, .sectorSize = 512,
.platterCount = 8, .platterCount = 8,
.cacheLineSize = 4, .cacheLineSize = 8,
.readsPerTick = 40, .readsPerTick = 40,
.writesPerTick = 20, .writesPerTick = 20,
.rpm = 7200, .rpm = 7200,
.onlySpinForwards = false, .onlySpinForwards = false,
.dataEnergyCost = 1024.0 / NN_MiB, .dataEnergyCost = 16.0 / NN_MiB,
}, },
NN_INIT(nn_Drive) { NN_INIT(nn_Drive) {
.capacity = 8 * NN_MiB, .capacity = 8 * NN_MiB,
.sectorSize = 512, .sectorSize = 512,
.platterCount = 16, .platterCount = 16,
.cacheLineSize = 8, .cacheLineSize = 16,
.readsPerTick = 60, .readsPerTick = 60,
.writesPerTick = 30, .writesPerTick = 30,
.rpm = 7200, .rpm = 7200,
.onlySpinForwards = false, .onlySpinForwards = false,
.dataEnergyCost = 2048.0 / NN_MiB, .dataEnergyCost = 32.0 / NN_MiB,
}, },
}; };
@@ -2482,9 +2482,67 @@ const nn_Drive nn_floppyDrive = {
.writesPerTick = 5, .writesPerTick = 5,
.rpm = 1800, .rpm = 1800,
.onlySpinForwards = true, .onlySpinForwards = true,
.dataEnergyCost = 128.0 / NN_MiB, .dataEnergyCost = 1.0 / NN_MiB,
}; };
const nn_Drive nn_defaultSSDs[4] = {
NN_INIT(nn_Drive) {
.capacity = 512 * NN_KiB,
.sectorSize = 512,
.platterCount = 2,
.cacheLineSize = 2,
.readsPerTick = 20,
.writesPerTick = 10,
.rpm = 0,
.onlySpinForwards = false,
.dataEnergyCost = 64.0 / NN_MiB,
},
NN_INIT(nn_Drive) {
.capacity = 1 * NN_MiB,
.sectorSize = 512,
.platterCount = 4,
.cacheLineSize = 4,
.readsPerTick = 30,
.writesPerTick = 15,
.rpm = 0,
.onlySpinForwards = false,
.dataEnergyCost = 128.0 / NN_MiB,
},
NN_INIT(nn_Drive) {
.capacity = 2 * NN_MiB,
.sectorSize = 512,
.platterCount = 8,
.cacheLineSize = 8,
.readsPerTick = 40,
.writesPerTick = 20,
.rpm = 0,
.onlySpinForwards = false,
.dataEnergyCost = 256.0 / NN_MiB,
},
NN_INIT(nn_Drive) {
.capacity = 4 * NN_MiB,
.sectorSize = 512,
.platterCount = 16,
.cacheLineSize = 16,
.readsPerTick = 60,
.writesPerTick = 30,
.rpm = 0,
.onlySpinForwards = false,
.dataEnergyCost = 512.0 / NN_MiB,
},
};
const nn_Drive nn_floppySSD = {
.capacity = 256 * NN_KiB,
.sectorSize = 512,
.platterCount = 1,
.cacheLineSize = 2,
.readsPerTick = 10,
.writesPerTick = 5,
.rpm = 0,
.onlySpinForwards = true,
.dataEnergyCost = 16.0 / NN_MiB,
};
const nn_ScreenConfig nn_defaultScreens[4] = { const nn_ScreenConfig nn_defaultScreens[4] = {
NN_INIT(nn_ScreenConfig) { NN_INIT(nn_ScreenConfig) {
@@ -2667,7 +2725,7 @@ static void nn_splitColor(int color, double *r, double *g, double *b) {
*b = (double)_b / 255; *b = (double)_b / 255;
} }
static double nn_colorLuminance(int color) { double nn_colorLuminance(int color) {
double r, g, b; double r, g, b;
nn_splitColor(color, &r, &g, &b); nn_splitColor(color, &r, &g, &b);
// taken from https://stackoverflow.com/questions/687261/converting-rgb-to-grayscale-intensity // taken from https://stackoverflow.com/questions/687261/converting-rgb-to-grayscale-intensity
@@ -3945,6 +4003,7 @@ static nn_Exit nn_drvHandler(nn_ComponentRequest *request) {
if(nn_drive_cachelineOf(curPos, cacheline) != nn_drive_cachelineOf(sec, cacheline)) { if(nn_drive_cachelineOf(curPos, cacheline) != nn_drive_cachelineOf(sec, cacheline)) {
nn_drive_seekPenalty(C, curPos, sec, &state->drive); nn_drive_seekPenalty(C, curPos, sec, &state->drive);
nn_costComponent(C, request->compAddress, state->drive.readsPerTick); nn_costComponent(C, request->compAddress, state->drive.readsPerTick);
nn_removeEnergy(C, state->drive.dataEnergyCost * cacheline * ss);
} }
char *sector = nn_alloc(ctx, ss); char *sector = nn_alloc(ctx, ss);

View File

@@ -1118,6 +1118,9 @@ typedef struct nn_Drive {
extern const nn_Drive nn_defaultDrives[4]; extern const nn_Drive nn_defaultDrives[4];
extern const nn_Drive nn_floppyDrive; extern const nn_Drive nn_floppyDrive;
extern const nn_Drive nn_defaultSSDs[4];
extern const nn_Drive nn_floppySSD;
typedef enum nn_DriveAction { typedef enum nn_DriveAction {
// drive gone // drive gone
NN_DRIVE_DROP, NN_DRIVE_DROP,
@@ -1449,6 +1452,8 @@ extern int nn_ocpalette8[256];
// initializes the contents of the palettes. // initializes the contents of the palettes.
void nn_initPalettes(); void nn_initPalettes();
// Returns a number from 0 to 1 representing the perceived luminance.
double nn_colorLuminance(int color);
// Expensive. // Expensive.
// Maps a color to the closest match in a palette. // Maps a color to the closest match in a palette.
int nn_mapColor(int color, int *palette, size_t len); int nn_mapColor(int color, int *palette, size_t len);