diff --git a/apps/file_manager/main.cpp b/apps/file_manager/main.cpp index 910f2a5..83fcb7e 100644 --- a/apps/file_manager/main.cpp +++ b/apps/file_manager/main.cpp @@ -523,7 +523,7 @@ void _start() { nonBlockingTaskWorkAvailable = EsEventCreate(true /* autoReset */); EsThreadInformation _nonBlockingTaskThread = {}; - for (uintptr_t i = 0; i < EsSystemGetConstant(ES_SYSTEM_CONSTANT_OPTIMAL_WORK_QUEUE_THREAD_COUNT); i++) { + for (uintptr_t i = 0; i < EsSystemGetOptimalWorkQueueThreadCount(); i++) { EsThreadCreate(NonBlockingTaskThread, &_nonBlockingTaskThread, nullptr); } diff --git a/desktop/api.cpp b/desktop/api.cpp index b388f74..8c46ac8 100644 --- a/desktop/api.cpp +++ b/desktop/api.cpp @@ -116,7 +116,6 @@ struct { Array mountPoints; bool foundBootFileSystem; EsProcessStartupInformation *startupInformation; - uint64_t systemConstants[ES_SYSTEM_CONSTANT_COUNT]; GlobalData *global; EsMutex messageMutex; @@ -132,7 +131,7 @@ struct { EsSpinlock performanceTimerStackLock; #define PERFORMANCE_TIMER_STACK_SIZE (100) - uint64_t performanceTimerStack[PERFORMANCE_TIMER_STACK_SIZE]; + double performanceTimerStack[PERFORMANCE_TIMER_STACK_SIZE]; uintptr_t performanceTimerStackCount; ThreadLocalStorage firstThreadLocalStorage; @@ -905,10 +904,6 @@ EsMessage *EsMessageReceive() { EsMessageType type = message.message.type; - if (type == ES_MSG_SYSTEM_CONSTANT_UPDATED) { - api.systemConstants[message.message.systemConstantUpdated.index] = message.message.systemConstantUpdated.newValue; - } - if (type == ES_MSG_EYEDROP_REPORT) { EsMessageSend((EsElement *) message.object, &message.message); } else if (type == ES_MSG_TIMER) { @@ -1186,8 +1181,8 @@ void EsInstanceSaveComplete(EsMessage *message, bool success) { message->instanceSave.file->operationComplete = true; } -uint64_t EsSystemGetConstant(uintptr_t index) { - return api.systemConstants[index]; +uintptr_t EsSystemGetOptimalWorkQueueThreadCount() { + return api.startupInformation->optimalWorkQueueThreadCount; } void ThreadInitialise(ThreadLocalStorage *local) { @@ -1216,7 +1211,6 @@ extern "C" void _start(EsProcessStartupInformation *_startupInformation) { // Initialise the API. _init(); - EsSyscall(ES_SYSCALL_SYSTEM_GET_CONSTANTS, (uintptr_t) api.systemConstants, 0, 0, 0); EsRandomSeed(EsTimeStamp()); ThreadInitialise(&api.firstThreadLocalStorage); EsMessageMutexAcquire(); @@ -1384,7 +1378,7 @@ void EsPerformanceTimerPush() { EsSpinlockAcquire(&api.performanceTimerStackLock); if (api.performanceTimerStackCount < PERFORMANCE_TIMER_STACK_SIZE) { - api.performanceTimerStack[api.performanceTimerStackCount++] = EsTimeStamp(); + api.performanceTimerStack[api.performanceTimerStackCount++] = EsTimeStampMs(); } EsSpinlockRelease(&api.performanceTimerStackLock); @@ -1395,8 +1389,8 @@ double EsPerformanceTimerPop() { EsSpinlockAcquire(&api.performanceTimerStackLock); if (api.performanceTimerStackCount) { - uint64_t start = api.performanceTimerStack[--api.performanceTimerStackCount]; - result = ((double) (EsTimeStamp() - start) / (double) (api.systemConstants[ES_SYSTEM_CONSTANT_TIME_STAMP_UNITS_PER_MICROSECOND])) / 1000000.0; + double start = api.performanceTimerStack[--api.performanceTimerStackCount]; + result = (EsTimeStampMs() - start) / 1000.0 /* ms to seconds */; } EsSpinlockRelease(&api.performanceTimerStackLock); diff --git a/desktop/gui.cpp b/desktop/gui.cpp index 37a22e7..4dd0d68 100644 --- a/desktop/gui.cpp +++ b/desktop/gui.cpp @@ -1732,8 +1732,8 @@ void ProcessAnimations() { EsMessage m = {}; m.type = ES_MSG_ANIMATE; - int64_t deltaUs = (timeStamp - element->lastTimeStamp) / api.systemConstants[ES_SYSTEM_CONSTANT_TIME_STAMP_UNITS_PER_MICROSECOND]; - m.animate.deltaMs = deltaUs / 1000; + int64_t deltaMs = (timeStamp - element->lastTimeStamp) / api.startupInformation->timeStampTicksPerMs; + m.animate.deltaMs = deltaMs; m.animate.complete = true; if (!m.animate.deltaMs) { @@ -1779,7 +1779,7 @@ void ProcessAnimations() { waitMs = m.animate.waitMs; } - element->lastTimeStamp += m.animate.deltaMs * 1000 * api.systemConstants[ES_SYSTEM_CONSTANT_TIME_STAMP_UNITS_PER_MICROSECOND]; + element->lastTimeStamp += m.animate.deltaMs * api.startupInformation->timeStampTicksPerMs; UIWindowNeedsUpdate(element->window); } @@ -2779,7 +2779,6 @@ EsScrollbar *ScrollbarCreate(EsElement *parent, uint64_t flags) { } else if (message->type == ES_MSG_ANIMATE) { if (scrollbar->position != scrollbar->smoothScrollTarget) { double factor = EsCRTexp2f(-5.0f / message->animate.deltaMs); - // EsPrint("%dmcs -> %F\n", message->animate.deltaUs, factor); scrollbar->position += (scrollbar->smoothScrollTarget - scrollbar->position) * factor; ScrollbarSetPosition(scrollbar, scrollbar->smoothScrollTarget, true, true); bool done = scrollbar->position == scrollbar->smoothScrollTarget; diff --git a/desktop/list_view.cpp b/desktop/list_view.cpp index 7d408ea..490d8da 100644 --- a/desktop/list_view.cpp +++ b/desktop/list_view.cpp @@ -1484,7 +1484,7 @@ struct EsListView : EsElement { EsMessageSend(this, &m); return true; } else if (!ctrl && !alt) { - uint64_t currentTime = EsTimeStamp() / (api.systemConstants[ES_SYSTEM_CONSTANT_TIME_STAMP_UNITS_PER_MICROSECOND] * 1000); + uint64_t currentTime = EsTimeStamp() / api.startupInformation->timeStampTicksPerMs; if (searchBufferLastKeyTime + GetConstantNumber("listViewSearchBufferTimeout") < currentTime) { searchBufferBytes = 0; @@ -1787,7 +1787,7 @@ struct EsListView : EsElement { DragSelect(); } - uint64_t currentTime = EsTimeStamp() / (api.systemConstants[ES_SYSTEM_CONSTANT_TIME_STAMP_UNITS_PER_MICROSECOND] * 1000); + uint64_t currentTime = EsTimeStamp() / api.startupInformation->timeStampTicksPerMs; int64_t remainingTime = searchBufferLastKeyTime + GetConstantNumber("listViewSearchBufferTimeout") - currentTime; if (remainingTime < 0) { diff --git a/desktop/os.header b/desktop/os.header index c205865..01d78fc 100644 --- a/desktop/os.header +++ b/desktop/os.header @@ -330,10 +330,6 @@ define ES_ERROR_NODE_NOT_LOADED (-71) define ES_ERROR_DIRECTORY_ENTRY_BEING_REMOVED (-72) define ES_ERROR_CANCELLED (-73) -define ES_SYSTEM_CONSTANT_TIME_STAMP_UNITS_PER_MICROSECOND (0) -define ES_SYSTEM_CONSTANT_OPTIMAL_WORK_QUEUE_THREAD_COUNT (1) -define ES_SYSTEM_CONSTANT_COUNT (2) - define ES_INVALID_HANDLE ((EsHandle) (0)) define ES_CURRENT_THREAD ((EsHandle) (0x10)) define ES_CURRENT_PROCESS ((EsHandle) (0x11)) @@ -764,31 +760,31 @@ enum EsSyscallType { // Processing. - ES_SYSCALL_PROCESS_CREATE - ES_SYSCALL_PROCESS_GET_CREATION_ARGUMENT - ES_SYSCALL_THREAD_TERMINATE - ES_SYSCALL_THREAD_CREATE - ES_SYSCALL_WAIT - ES_SYSCALL_PROCESS_TERMINATE ES_SYSCALL_EVENT_CREATE - ES_SYSCALL_EVENT_SET - ES_SYSCALL_EVENT_RESET - ES_SYSCALL_PROCESS_PAUSE - ES_SYSCALL_PROCESS_CRASH - ES_SYSCALL_THREAD_GET_ID - ES_SYSCALL_PROCESS_GET_STATE - ES_SYSCALL_YIELD_SCHEDULER - ES_SYSCALL_SLEEP - ES_SYSCALL_PROCESS_OPEN - ES_SYSCALL_PROCESS_SET_TLS - ES_SYSCALL_PROCESS_GET_TLS - ES_SYSCALL_PROCESS_GET_STATUS ES_SYSCALL_EVENT_FORWARD + ES_SYSCALL_EVENT_RESET + ES_SYSCALL_EVENT_SET ES_SYSCALL_EVENT_SINK_CREATE ES_SYSCALL_EVENT_SINK_POP ES_SYSCALL_EVENT_SINK_PUSH - ES_SYSCALL_THREAD_STACK_SIZE + ES_SYSCALL_PROCESS_CRASH + ES_SYSCALL_PROCESS_CREATE + ES_SYSCALL_PROCESS_GET_CREATION_ARGUMENT + ES_SYSCALL_PROCESS_GET_STATE + ES_SYSCALL_PROCESS_GET_STATUS + ES_SYSCALL_PROCESS_GET_TLS + ES_SYSCALL_PROCESS_OPEN + ES_SYSCALL_PROCESS_PAUSE + ES_SYSCALL_PROCESS_SET_TLS ES_SYSCALL_PROCESS_SHARE + ES_SYSCALL_PROCESS_TERMINATE + ES_SYSCALL_SLEEP + ES_SYSCALL_THREAD_CREATE + ES_SYSCALL_THREAD_GET_ID + ES_SYSCALL_THREAD_STACK_SIZE + ES_SYSCALL_THREAD_TERMINATE + ES_SYSCALL_WAIT + ES_SYSCALL_YIELD_SCHEDULER // Windowing. @@ -823,15 +819,15 @@ enum EsSyscallType { // IO. ES_SYSCALL_NODE_OPEN + ES_SYSCALL_NODE_DELETE + ES_SYSCALL_NODE_MOVE + ES_SYSCALL_NODE_SHARE ES_SYSCALL_FILE_READ_SYNC ES_SYSCALL_FILE_WRITE_SYNC ES_SYSCALL_FILE_RESIZE ES_SYSCALL_FILE_GET_SIZE - ES_SYSCALL_DIRECTORY_ENUMERATE - ES_SYSCALL_NODE_DELETE - ES_SYSCALL_NODE_MOVE ES_SYSCALL_FILE_CONTROL - ES_SYSCALL_NODE_SHARE + ES_SYSCALL_DIRECTORY_ENUMERATE ES_SYSCALL_VOLUME_GET_INFORMATION // Networking. @@ -851,11 +847,6 @@ enum EsSyscallType { ES_SYSCALL_PIPE_WRITE ES_SYSCALL_PIPE_READ - // System information. - - ES_SYSCALL_SYSTEM_GET_CONSTANTS - ES_SYSCALL_SYSTEM_TAKE_SNAPSHOT - // Misc. ES_SYSCALL_PRINT @@ -864,6 +855,7 @@ enum EsSyscallType { ES_SYSCALL_SHUTDOWN ES_SYSCALL_POSIX ES_SYSCALL_DEBUG_COMMAND + ES_SYSCALL_SYSTEM_TAKE_SNAPSHOT // End. @@ -987,7 +979,6 @@ enum EsMessageType { // Misc messages: ES_MSG_EYEDROP_REPORT = 0x5001 - ES_MSG_SYSTEM_CONSTANT_UPDATED = 0x5002 ES_MSG_TIMER = 0x5003 ES_MSG_PING = 0x5004 // Sent by Desktop to check processes are processing messages. ES_MSG_WAKEUP = 0x5005 // Sent to wakeup the message thread, so that it can process locally posted messages. @@ -1727,11 +1718,6 @@ struct EsMessageTabOperation { EsError error; }; -struct EsMessageSystemConstantUpdated { - uintptr_t index; - uint64_t newValue; -}; - struct EsMessageRegisterFileSystem { EsHandle rootDirectory; bool isBootFileSystem; @@ -1815,7 +1801,6 @@ struct EsMessage { // Internal messages: void *_argument; EsMessageProcessCrash crash; - EsMessageSystemConstantUpdated systemConstantUpdated; EsMessageDesktop desktop; EsMessageEyedrop eyedrop; EsMessageCreateInstance createInstance; @@ -1901,7 +1886,7 @@ function uintptr_t _EsSyscall(uintptr_t a, uintptr_t b, uintptr_t c, uintptr_t d // Configuration and settings. -function uint64_t EsSystemGetConstant(uintptr_t index); +function uintptr_t EsSystemGetOptimalWorkQueueThreadCount(); function int64_t EsSystemConfigurationReadInteger(STRING section, STRING key, int64_t defaultValue = 0); function char *EsSystemConfigurationReadString(STRING section, STRING key, size_t *valueBytes = ES_NULL); // Free with EsHeapFree. diff --git a/desktop/posix.cpp b/desktop/posix.cpp index 180d45a..66c32fb 100644 --- a/desktop/posix.cpp +++ b/desktop/posix.cpp @@ -531,11 +531,10 @@ long EsPOSIXSystemCall(long n, long a1, long a2, long a3, long a4, long a5, long case SYS_clock_gettime: { // We'll ignore the clockid_t in a1, since we don't have proper timekeeping yet. struct timespec *tp = (struct timespec *) a2; - uint64_t timeStamp = EsTimeStamp(); - uint64_t unitsPerMicrosecond = EsSystemGetConstant(ES_SYSTEM_CONSTANT_TIME_STAMP_UNITS_PER_MICROSECOND); - uint64_t microseconds = timeStamp / unitsPerMicrosecond; - tp->tv_sec = microseconds / 1000000; - tp->tv_nsec = (microseconds % 1000000) * 1000; + double timeStampMs = EsTimeStampMs(); + uint64_t ns = timeStampMs * 1e6; + tp->tv_sec = ns / 1000000000; + tp->tv_nsec = (ns % 1000000000) * 1000; } break; case SYS_wait4: { diff --git a/desktop/prefix.h b/desktop/prefix.h index 3b0df81..7d870c8 100644 --- a/desktop/prefix.h +++ b/desktop/prefix.h @@ -250,6 +250,8 @@ struct EsProcessStartupInformation { uintptr_t tlsImageStart; uintptr_t tlsImageBytes; uintptr_t tlsBytes; // All bytes after the image are to be zeroed. + uintptr_t timeStampTicksPerMs; + uintptr_t optimalWorkQueueThreadCount; }; struct _EsPOSIXSyscall { diff --git a/desktop/syscall.cpp b/desktop/syscall.cpp index 8f2bfbc..b43fa43 100644 --- a/desktop/syscall.cpp +++ b/desktop/syscall.cpp @@ -3,10 +3,10 @@ ThreadLocalStorage *GetThreadLocalStorage() { } double EsTimeStampMs() { - if (!api.systemConstants[ES_SYSTEM_CONSTANT_TIME_STAMP_UNITS_PER_MICROSECOND]) { + if (!api.startupInformation->timeStampTicksPerMs) { return 0; } else { - return (double) EsTimeStamp() / api.systemConstants[ES_SYSTEM_CONSTANT_TIME_STAMP_UNITS_PER_MICROSECOND] / 1000; + return (double) EsTimeStamp() / api.startupInformation->timeStampTicksPerMs; } } diff --git a/kernel/scheduler.cpp b/kernel/scheduler.cpp index 4ec041d..d551c69 100644 --- a/kernel/scheduler.cpp +++ b/kernel/scheduler.cpp @@ -628,6 +628,8 @@ void NewProcess() { startupInformation->tlsImageStart = application.tlsImageStart; startupInformation->tlsImageBytes = application.tlsImageBytes; startupInformation->tlsBytes = application.tlsBytes; + startupInformation->timeStampTicksPerMs = timeStampTicksPerMs; + startupInformation->optimalWorkQueueThreadCount = scheduler.currentProcessorID; // TODO Update this as processors are added/removed. } } diff --git a/kernel/syscall.cpp b/kernel/syscall.cpp index 2a83f7f..28c14de 100644 --- a/kernel/syscall.cpp +++ b/kernel/syscall.cpp @@ -1418,15 +1418,6 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_YIELD_SCHEDULER) { SYSCALL_RETURN(ES_SUCCESS, false); } -SYSCALL_IMPLEMENT(ES_SYSCALL_SYSTEM_GET_CONSTANTS) { - uint64_t systemConstants[ES_SYSTEM_CONSTANT_COUNT]; - EsMemoryZero(systemConstants, sizeof(systemConstants)); - systemConstants[ES_SYSTEM_CONSTANT_TIME_STAMP_UNITS_PER_MICROSECOND] = timeStampTicksPerMs / 1000; - systemConstants[ES_SYSTEM_CONSTANT_OPTIMAL_WORK_QUEUE_THREAD_COUNT] = scheduler.currentProcessorID; // TODO Update this as processors are added/removed. - SYSCALL_WRITE(argument0, systemConstants, sizeof(systemConstants)); - SYSCALL_RETURN(ES_SUCCESS, false); -} - SYSCALL_IMPLEMENT(ES_SYSCALL_SYSTEM_TAKE_SNAPSHOT) { SYSCALL_PERMISSION(ES_PERMISSION_TAKE_SYSTEM_SNAPSHOT); diff --git a/util/api_table.ini b/util/api_table.ini index fb7b4b6..c40530b 100644 --- a/util/api_table.ini +++ b/util/api_table.ini @@ -6,7 +6,6 @@ EsPOSIXInitialise=4 EsFileStoreReadAll=5 EsPOSIXSystemCall=6 EsINIParse=7 -EsSystemGetConstant=8 EsTakeSystemSnapshot=9 EsListViewFocusItem=10 _EsInstanceCreate=11 @@ -444,3 +443,4 @@ EsDrawTextSimple=442 EsColorInterpolate=443 EsBufferReadInt32Endian=444 EsBufferWriteInt32Endian=445 +EsSystemGetOptimalWorkQueueThreadCount=446