* @brief Retrieve system information. * * This function provides details about the current state of the system, such as uptime, memory usage, * load average, and other key statistics. The information is stored in a structure pointed to by `info`. * * @param[out] info A pointer to a buffer where system information will be stored. The structure should * be compatible with the
| 8701 | * memory for the structure. |
| 8702 | */ |
| 8703 | sysret_t sys_sysinfo(void *info) |
| 8704 | { |
| 8705 | #ifdef ARCH_MM_MMU |
| 8706 | struct sysinfo kinfo = {0}; |
| 8707 | rt_size_t total_pages = 0, free_pages = 0; |
| 8708 | |
| 8709 | if (!lwp_user_accessable(info, sizeof(struct sysinfo))) |
| 8710 | { |
| 8711 | return -EFAULT; |
| 8712 | } |
| 8713 | |
| 8714 | kinfo.uptime = rt_tick_get_millisecond() / 1000; |
| 8715 | /* TODO: 1, 5, and 15 minute load averages */ |
| 8716 | kinfo.loads[0] = kinfo.loads[1] = kinfo.loads[2] = rt_object_get_length(RT_Object_Class_Thread); |
| 8717 | rt_page_get_info(&total_pages, &free_pages); |
| 8718 | kinfo.totalram = total_pages; |
| 8719 | kinfo.freeram = free_pages; |
| 8720 | |
| 8721 | /* TODO: implementation procfs, here is counter the lwp number */ |
| 8722 | struct lwp_avl_struct *pids = lwp_get_pid_ary(); |
| 8723 | for (int index = 0; index < RT_LWP_MAX_NR; index++) |
| 8724 | { |
| 8725 | struct rt_lwp *lwp = (struct rt_lwp *)pids[index].data; |
| 8726 | |
| 8727 | if (lwp) |
| 8728 | { |
| 8729 | kinfo.procs++; |
| 8730 | } |
| 8731 | } |
| 8732 | |
| 8733 | rt_page_high_get_info(&total_pages, &free_pages); |
| 8734 | kinfo.totalhigh = total_pages; |
| 8735 | kinfo.freehigh = free_pages; |
| 8736 | kinfo.mem_unit = ARCH_PAGE_SIZE; |
| 8737 | |
| 8738 | if (lwp_put_to_user(info, &kinfo, sizeof(struct sysinfo)) != sizeof(struct sysinfo)) |
| 8739 | { |
| 8740 | return -EFAULT; |
| 8741 | } |
| 8742 | |
| 8743 | return 0; |
| 8744 | #else |
| 8745 | return -1; |
| 8746 | #endif |
| 8747 | } |
| 8748 | |
| 8749 | /** |
| 8750 | * @brief Set scheduling parameters for a specific thread. |
nothing calls this directly
no test coverage detected