more accuracy
This commit is contained in:
7
Makefile
7
Makefile
@@ -10,10 +10,9 @@ WARN=-Wall -Werror -Wno-format-truncation
|
|||||||
|
|
||||||
ifeq ($(MODE), release)
|
ifeq ($(MODE), release)
|
||||||
OPT=-Oz
|
OPT=-Oz
|
||||||
ifneq ($(CC), clang)
|
DEBUG=
|
||||||
# clang emits LLVM bitcode in lto mode, which only clang and lld understand
|
else ifeq ($(MODE), release-lto)
|
||||||
OPT += -flto
|
OPT=-Oz -flto
|
||||||
endif
|
|
||||||
DEBUG=
|
DEBUG=
|
||||||
else
|
else
|
||||||
OPT=-O0
|
OPT=-O0
|
||||||
|
|||||||
14
src/main.c
14
src/main.c
@@ -104,10 +104,17 @@ static nn_Exit ne_dataBullshit(nn_DataCardRequest *req) {
|
|||||||
return NN_OK;
|
return NN_OK;
|
||||||
}
|
}
|
||||||
if(action == NN_DATA_SHA256) {
|
if(action == NN_DATA_SHA256) {
|
||||||
// does not match OC, dunno why
|
|
||||||
unsigned int *out = ComputeSHA256((unsigned char *)req->sha256.data, req->sha256.datalen);
|
unsigned int *out = ComputeSHA256((unsigned char *)req->sha256.data, req->sha256.datalen);
|
||||||
if(out == NULL) return NN_ENOMEM;
|
if(out == NULL) return NN_ENOMEM;
|
||||||
memcpy(req->sha256.checksum, out, 32);
|
unsigned char buf[32];
|
||||||
|
for(size_t i = 0; i < 8; i++) {
|
||||||
|
// OC does BE
|
||||||
|
buf[i*4+3] = (out[i] >> 0) & 0xFF;
|
||||||
|
buf[i*4+2] = (out[i] >> 8) & 0xFF;
|
||||||
|
buf[i*4+1] = (out[i] >> 16) & 0xFF;
|
||||||
|
buf[i*4+0] = (out[i] >> 24) & 0xFF;
|
||||||
|
}
|
||||||
|
memcpy(req->sha256.checksum, buf, 32);
|
||||||
return NN_OK;
|
return NN_OK;
|
||||||
}
|
}
|
||||||
if(action == NN_DATA_RANDOM) {
|
if(action == NN_DATA_RANDOM) {
|
||||||
@@ -687,15 +694,12 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
nn_Component *screen = ncl_createScreen(u, NULL, &nn_defaultScreens[3]);
|
nn_Component *screen = ncl_createScreen(u, NULL, &nn_defaultScreens[3]);
|
||||||
nn_GPU gpuConf = nn_defaultGPUs[3];
|
nn_GPU gpuConf = nn_defaultGPUs[3];
|
||||||
gpuConf.maxWidth = 1920;
|
|
||||||
gpuConf.maxHeight = 1080;
|
|
||||||
nn_Component *gpuCard = ncl_createGPU(u, NULL, &gpuConf);
|
nn_Component *gpuCard = ncl_createGPU(u, NULL, &gpuConf);
|
||||||
nn_Component *keyboard = nn_createComponent(
|
nn_Component *keyboard = nn_createComponent(
|
||||||
u, "mainKB", "keyboard");
|
u, "mainKB", "keyboard");
|
||||||
|
|
||||||
ncl_ScreenState *scrstate = nn_getComponentState(screen);
|
ncl_ScreenState *scrstate = nn_getComponentState(screen);
|
||||||
ncl_mountKeyboard(scrstate, "mainKB");
|
ncl_mountKeyboard(scrstate, "mainKB");
|
||||||
ncl_setScreenMaxResolution(scrstate, 320, 90);
|
|
||||||
|
|
||||||
// we assume server basically
|
// we assume server basically
|
||||||
nn_Computer *c = nn_createComputer(u, NULL, NULL, ramTotal, nn_defaultComponentLimits[3] * 4, 256);
|
nn_Computer *c = nn_createComputer(u, NULL, NULL, ramTotal, nn_defaultComponentLimits[3] * 4, 256);
|
||||||
|
|||||||
@@ -3517,8 +3517,11 @@ void ncl_statComponent(nn_Component *component, ncl_ComponentStat *stat) {
|
|||||||
stat->labellen = drv->labellen;
|
stat->labellen = drv->labellen;
|
||||||
memcpy(stat->label, drv->label, stat->labellen);
|
memcpy(stat->label, drv->label, stat->labellen);
|
||||||
stat->flash.currentWriteCount = drv->writeCount;
|
stat->flash.currentWriteCount = drv->writeCount;
|
||||||
// TODO: compute wear level
|
double wearlevel = 100;
|
||||||
stat->flash.wearlevel = 0;
|
size_t maxWrite = drv->conf.maxWriteCount;
|
||||||
|
size_t sectorCount = drv->conf.capacity / drv->conf.sectorSize;
|
||||||
|
if(maxWrite > 0 && sectorCount > 0) wearlevel = drv->writeCount * 100.0 / sectorCount / maxWrite;
|
||||||
|
stat->flash.wearlevel = wearlevel;
|
||||||
stat->flash.conf = &drv->conf;
|
stat->flash.conf = &drv->conf;
|
||||||
nn_unlock(drv->ctx, drv->lock);
|
nn_unlock(drv->ctx, drv->lock);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1082,6 +1082,7 @@ struct nn_Computer {
|
|||||||
nn_Architecture desiredArch;
|
nn_Architecture desiredArch;
|
||||||
double callBudget;
|
double callBudget;
|
||||||
double totalCallBudget;
|
double totalCallBudget;
|
||||||
|
double directCost;
|
||||||
nn_HashMap components;
|
nn_HashMap components;
|
||||||
nn_DeviceInfoArray deviceInfo;
|
nn_DeviceInfoArray deviceInfo;
|
||||||
double totalEnergy;
|
double totalEnergy;
|
||||||
@@ -1202,6 +1203,8 @@ nn_Computer *nn_createComputer(nn_Universe *universe, void *userdata, const char
|
|||||||
|
|
||||||
c->totalCallBudget = 1;
|
c->totalCallBudget = 1;
|
||||||
c->callBudget = c->totalCallBudget;
|
c->callBudget = c->totalCallBudget;
|
||||||
|
// OC defaults to Integer.MAX_VALUE, idk where the old number came from
|
||||||
|
c->directCost = 0;
|
||||||
|
|
||||||
if(nn_hashInit(&c->components, maxComponents, ctx, &nn_componentHasher)) {
|
if(nn_hashInit(&c->components, maxComponents, ctx, &nn_componentHasher)) {
|
||||||
nn_destroyLock(ctx, c->lock);
|
nn_destroyLock(ctx, c->lock);
|
||||||
@@ -1304,6 +1307,14 @@ void nn_setComputerEnvironment(nn_Computer *computer, nn_Environment env) {
|
|||||||
computer->env = env;
|
computer->env = env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nn_setDirectCost(nn_Computer *computer, double directCost) {
|
||||||
|
computer->directCost = directCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
double nn_getDirectCost(nn_Computer *computer) {
|
||||||
|
return computer->directCost;
|
||||||
|
}
|
||||||
|
|
||||||
const char *nn_deviceInfoAt(nn_Computer *computer, size_t idx) {
|
const char *nn_deviceInfoAt(nn_Computer *computer, size_t idx) {
|
||||||
return idx < computer->deviceInfo.len ? computer->deviceInfo.entries[idx].address : NULL;
|
return idx < computer->deviceInfo.len ? computer->deviceInfo.entries[idx].address : NULL;
|
||||||
}
|
}
|
||||||
@@ -2157,8 +2168,7 @@ nn_Exit nn_invokeComponent(nn_Computer *computer, const char *compAddress, const
|
|||||||
nn_pop(computer);
|
nn_pop(computer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: configurable cost
|
nn_costComponent(computer, computer->directCost);
|
||||||
nn_costComponent(computer, 22000);
|
|
||||||
|
|
||||||
nn_ComponentRequest req;
|
nn_ComponentRequest req;
|
||||||
req.ctx = &c->universe->ctx;
|
req.ctx = &c->universe->ctx;
|
||||||
|
|||||||
@@ -450,6 +450,9 @@ void nn_forceCrashComputer(nn_Computer *computer, const char *s);
|
|||||||
bool nn_isComputerOn(nn_Computer *computer);
|
bool nn_isComputerOn(nn_Computer *computer);
|
||||||
void nn_setComputerEnvironment(nn_Computer *computer, nn_Environment env);
|
void nn_setComputerEnvironment(nn_Computer *computer, nn_Environment env);
|
||||||
|
|
||||||
|
void nn_setDirectCost(nn_Computer *computer, double directCost);
|
||||||
|
double nn_getDirectCost(nn_Computer *computer);
|
||||||
|
|
||||||
// Device information
|
// Device information
|
||||||
|
|
||||||
// Standard device attribute fields
|
// Standard device attribute fields
|
||||||
|
|||||||
Reference in New Issue
Block a user