more accuracy
This commit is contained in:
7
Makefile
7
Makefile
@@ -10,10 +10,9 @@ WARN=-Wall -Werror -Wno-format-truncation
|
||||
|
||||
ifeq ($(MODE), release)
|
||||
OPT=-Oz
|
||||
ifneq ($(CC), clang)
|
||||
# clang emits LLVM bitcode in lto mode, which only clang and lld understand
|
||||
OPT += -flto
|
||||
endif
|
||||
DEBUG=
|
||||
else ifeq ($(MODE), release-lto)
|
||||
OPT=-Oz -flto
|
||||
DEBUG=
|
||||
else
|
||||
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;
|
||||
}
|
||||
if(action == NN_DATA_SHA256) {
|
||||
// does not match OC, dunno why
|
||||
unsigned int *out = ComputeSHA256((unsigned char *)req->sha256.data, req->sha256.datalen);
|
||||
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;
|
||||
}
|
||||
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_GPU gpuConf = nn_defaultGPUs[3];
|
||||
gpuConf.maxWidth = 1920;
|
||||
gpuConf.maxHeight = 1080;
|
||||
nn_Component *gpuCard = ncl_createGPU(u, NULL, &gpuConf);
|
||||
nn_Component *keyboard = nn_createComponent(
|
||||
u, "mainKB", "keyboard");
|
||||
|
||||
ncl_ScreenState *scrstate = nn_getComponentState(screen);
|
||||
ncl_mountKeyboard(scrstate, "mainKB");
|
||||
ncl_setScreenMaxResolution(scrstate, 320, 90);
|
||||
|
||||
// we assume server basically
|
||||
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;
|
||||
memcpy(stat->label, drv->label, stat->labellen);
|
||||
stat->flash.currentWriteCount = drv->writeCount;
|
||||
// TODO: compute wear level
|
||||
stat->flash.wearlevel = 0;
|
||||
double wearlevel = 100;
|
||||
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;
|
||||
nn_unlock(drv->ctx, drv->lock);
|
||||
return;
|
||||
|
||||
@@ -1082,6 +1082,7 @@ struct nn_Computer {
|
||||
nn_Architecture desiredArch;
|
||||
double callBudget;
|
||||
double totalCallBudget;
|
||||
double directCost;
|
||||
nn_HashMap components;
|
||||
nn_DeviceInfoArray deviceInfo;
|
||||
double totalEnergy;
|
||||
@@ -1202,6 +1203,8 @@ nn_Computer *nn_createComputer(nn_Universe *universe, void *userdata, const char
|
||||
|
||||
c->totalCallBudget = 1;
|
||||
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)) {
|
||||
nn_destroyLock(ctx, c->lock);
|
||||
@@ -1304,6 +1307,14 @@ void nn_setComputerEnvironment(nn_Computer *computer, nn_Environment 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) {
|
||||
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);
|
||||
}
|
||||
|
||||
// TODO: configurable cost
|
||||
nn_costComponent(computer, 22000);
|
||||
nn_costComponent(computer, computer->directCost);
|
||||
|
||||
nn_ComponentRequest req;
|
||||
req.ctx = &c->universe->ctx;
|
||||
|
||||
@@ -450,6 +450,9 @@ void nn_forceCrashComputer(nn_Computer *computer, const char *s);
|
||||
bool nn_isComputerOn(nn_Computer *computer);
|
||||
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
|
||||
|
||||
// Standard device attribute fields
|
||||
|
||||
Reference in New Issue
Block a user