- Timestamp:
- 2010-04-18T00:24:40Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a80687e5
- Parents:
- d8e3467
- Location:
- kernel
- Files:
-
- 1 added
- 9 deleted
- 14 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
kernel/Makefile
rd8e3467 r9dae191e 230 230 generic/src/security/cap.c \ 231 231 generic/src/sysinfo/sysinfo.c \ 232 generic/src/ps/ps.c \ 233 generic/src/ps/cpu.c \ 234 generic/src/ps/load.c \ 235 generic/src/ps/uptime.c \ 236 generic/src/ps/mem.c 232 generic/src/sysinfo/stats.c 237 233 238 234 ## Kernel console support -
kernel/generic/include/mm/frame.h
rd8e3467 r9dae191e 169 169 extern bool zone_merge(size_t, size_t); 170 170 extern void zone_merge_all(void); 171 extern uint64_t zone _total_size(void);172 extern void zone _busy_and_free(uint64_t *out_busy, uint64_t *out_free);171 extern uint64_t zones_total_size(void); 172 extern void zones_stats(uint64_t *, uint64_t *, uint64_t *, uint64_t *); 173 173 174 174 /* 175 175 * Console functions 176 176 */ 177 extern void zone _print_list(void);177 extern void zones_print_list(void); 178 178 extern void zone_print_one(size_t); 179 179 -
kernel/generic/include/proc/task.h
rd8e3467 r9dae191e 56 56 #include <ipc/kbox.h> 57 57 #include <mm/as.h> 58 59 #include <ps/taskinfo.h> 58 #include <sysinfo/abi.h> 60 59 61 60 struct thread; … … 81 80 task_id_t taskid; 82 81 /** Task security context. */ 83 context_id_t context; 82 context_id_t context; 84 83 85 84 /** Number of references (i.e. threads). */ … … 89 88 90 89 /** Task capabilities. */ 91 cap_t capabilities; 90 cap_t capabilities; 92 91 93 92 /* IPC stuff */ 94 93 answerbox_t answerbox; /**< Communication endpoint */ 95 94 phone_t phones[IPC_MAX_PHONES]; 96 task_ipc_info_t ipc_info;/**< IPC statistics */95 stats_ipc_t ipc_info; /**< IPC statistics */ 97 96 /** 98 97 * Active asynchronous messages. It is used for limiting uspace to … … 120 119 mutex_t futexes_lock; 121 120 /** B+tree of futexes referenced by this task. */ 122 btree_t futexes; 121 btree_t futexes; 123 122 124 123 /** Accumulated accounting. */ -
kernel/generic/include/proc/thread.h
rd8e3467 r9dae191e 69 69 #define THREAD_FLAG_NOATTACH (1 << 3) 70 70 71 /* We need state_t enum definition */ 72 #include <ps/taskinfo.h> 71 /** Thread states. */ 72 typedef enum { 73 /** It is an error, if thread is found in this state. */ 74 Invalid, 75 /** State of a thread that is currently executing on some CPU. */ 76 Running, 77 /** Thread in this state is waiting for an event. */ 78 Sleeping, 79 /** State of threads in a run queue. */ 80 Ready, 81 /** Threads are in this state before they are first readied. */ 82 Entering, 83 /** After a thread calls thread_exit(), it is put into Exiting state. */ 84 Exiting, 85 /** Threads that were not detached but exited are Lingering. */ 86 Lingering 87 } state_t; 73 88 74 89 /** Thread structure. There is one per thread. */ -
kernel/generic/include/syscall/syscall.h
rd8e3467 r9dae191e 71 71 SYS_IPC_REGISTER_IRQ, 72 72 SYS_IPC_UNREGISTER_IRQ, 73 73 74 74 SYS_EVENT_SUBSCRIBE, 75 75 … … 89 89 SYS_DEBUG_ENABLE_CONSOLE, 90 90 SYS_DEBUG_DISABLE_CONSOLE, 91 92 SYS_PS_GET_CPU_INFO, 93 SYS_PS_GET_MEM_INFO, 94 SYS_PS_GET_TASKS, 95 SYS_PS_GET_TASK_INFO, 96 SYS_PS_GET_THREADS, 97 SYS_PS_GET_UPTIME, 98 SYS_PS_GET_LOAD, 99 91 100 92 SYS_IPC_CONNECT_KBOX, 101 93 SYSCALL_END -
kernel/generic/include/sysinfo/abi.h
rd8e3467 r9dae191e 1 1 /* 2 * Copyright (c) 2010 Stanislav Kozina2 * Copyright (c) 2010 Martin Decky 3 3 * All rights reserved. 4 4 * … … 33 33 */ 34 34 35 #ifndef KERN_PS_CPU_H_ 36 #define KERN_PS_CPU_H_ 35 #ifndef KERN_ABI_H_ 36 #define KERN_ABI_H_ 37 38 #define LOAD_STEPS 3 39 #define TASK_NAME_BUFLEN 20 37 40 38 41 typedef struct { … … 41 44 uint64_t idle_ticks; 42 45 uint64_t busy_ticks; 43 } uspace_cpu_info_t; 46 } stats_cpu_t; 47 48 typedef struct { 49 uint64_t total; 50 uint64_t unavail; 51 uint64_t used; 52 uint64_t free; 53 } stats_physmem_t; 54 55 typedef struct { 56 uint64_t call_sent; 57 uint64_t call_recieved; 58 uint64_t answer_sent; 59 uint64_t answer_recieved; 60 uint64_t irq_notif_recieved; 61 uint64_t forwarded; 62 } stats_ipc_t; 63 64 typedef struct { 65 char name[TASK_NAME_BUFLEN]; 66 size_t virtmem; 67 size_t threads; 68 uint64_t ucycles; 69 uint64_t kcycles; 70 stats_ipc_t ipc_info; 71 } stats_task_t; 72 73 typedef uint32_t load_t; 44 74 45 75 #endif -
kernel/generic/include/sysinfo/stats.h
rd8e3467 r9dae191e 1 1 /* 2 * Copyright (c) 2010 Stanislav Kozina2 * Copyright (c) 2010 Martin Decky 3 3 * All rights reserved. 4 4 * … … 33 33 */ 34 34 35 #ifndef KERN_ PS_UPTIME_H_36 #define KERN_ PS_UPTIME_H_35 #ifndef KERN_STATS_H_ 36 #define KERN_STATS_H_ 37 37 38 extern int sys_ps_get_uptime(uint64_t *user_load); 38 extern void kload(void *arg); 39 extern void stats_init(void); 39 40 40 41 #endif -
kernel/generic/include/sysinfo/sysinfo.h
rd8e3467 r9dae191e 59 59 typedef unative_t (*sysinfo_fn_val_t)(struct sysinfo_item *); 60 60 typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *); 61 typedef struct sysinfo_item *(*sysinfo_fn_subtree_t)(const char *);62 61 63 62 typedef struct { … … 73 72 } sysinfo_item_val_t; 74 73 74 typedef struct { 75 sysinfo_item_val_type_t tag; 76 union { 77 unative_t val; 78 sysinfo_data_t data; 79 }; 80 } sysinfo_return_t; 81 82 typedef sysinfo_return_t (*sysinfo_fn_subtree_t)(const char *); 83 75 84 typedef union { 76 85 struct sysinfo_item *table; 77 sysinfo_fn_subtree_t find_item;86 sysinfo_fn_subtree_t get_data; 78 87 } sysinfo_subtree_t; 79 88 … … 90 99 } sysinfo_item_t; 91 100 92 typedef struct {93 sysinfo_item_val_type_t tag;94 union {95 unative_t val;96 sysinfo_data_t data;97 };98 } sysinfo_return_t;99 100 extern void sysinfo_init(void);101 102 101 extern void sysinfo_set_item_val(const char *, sysinfo_item_t **, unative_t); 103 102 extern void sysinfo_set_item_data(const char *, sysinfo_item_t **, void *, 104 103 size_t); 105 extern void sysinfo_set_item_ val_fn(const char *, sysinfo_item_t **,104 extern void sysinfo_set_item_fn_val(const char *, sysinfo_item_t **, 106 105 sysinfo_fn_val_t); 107 extern void sysinfo_set_item_ data_fn(const char *, sysinfo_item_t **,106 extern void sysinfo_set_item_fn_data(const char *, sysinfo_item_t **, 108 107 sysinfo_fn_data_t); 109 108 extern void sysinfo_set_item_undefined(const char *, sysinfo_item_t **); 110 109 111 extern sysinfo_return_t sysinfo_get_item(const char *, sysinfo_item_t **); 112 extern void sysinfo_dump(sysinfo_item_t **, unsigned int); 110 extern void sysinfo_set_subtree_fn(const char *, sysinfo_item_t **, 111 sysinfo_fn_subtree_t); 112 113 extern void sysinfo_init(void); 114 extern void sysinfo_dump(sysinfo_item_t *); 113 115 114 116 unative_t sys_sysinfo_get_tag(void *, size_t); -
kernel/generic/src/console/cmd.c
rd8e3467 r9dae191e 886 886 int cmd_sysinfo(cmd_arg_t * argv) 887 887 { 888 sysinfo_dump(NULL , 0);888 sysinfo_dump(NULL); 889 889 return 1; 890 890 } … … 935 935 int cmd_zones(cmd_arg_t * argv) 936 936 { 937 zone _print_list();937 zones_print_list(); 938 938 return 1; 939 939 } -
kernel/generic/src/cpu/cpu.c
rd8e3467 r9dae191e 75 75 76 76 cpus[i].id = i; 77 cpus[i].idle_ticks = 0;78 cpus[i].busy_ticks = 0;79 77 80 78 spinlock_initialize(&cpus[i].lock, "cpu_t.lock"); … … 97 95 cpu_identify(); 98 96 cpu_arch_init(); 99 100 sysinfo_set_item_val("cpu.count", NULL, config.cpu_count);101 97 } 102 98 -
kernel/generic/src/main/kinit.c
rd8e3467 r9dae191e 67 67 #include <debug.h> 68 68 #include <str.h> 69 #include < ps/load.h>69 #include <sysinfo/stats.h> 70 70 71 71 #ifdef CONFIG_SMP … … 123 123 } else 124 124 panic("Unable to create kmp thread."); 125 125 126 thread_join(thread); 126 127 thread_detach(thread); … … 151 152 arch_post_smp_init(); 152 153 154 /* Start thread computing system load */ 155 thread = thread_create(kload, NULL, TASK, 0, "kload", false); 156 if (thread != NULL) 157 thread_ready(thread); 158 else 159 printf("Unable to create kload thread\n"); 160 153 161 #ifdef CONFIG_KCONSOLE 154 162 if (stdin) { … … 164 172 #endif /* CONFIG_KCONSOLE */ 165 173 166 /* Start thread computing system load */167 thread = thread_create(kload_thread, NULL, TASK, 0, "kload", false);168 if (thread != NULL)169 thread_ready(thread);170 else171 printf("Unable to create kload thread\n");172 173 174 interrupts_enable(); 174 175 -
kernel/generic/src/main/main.c
rd8e3467 r9dae191e 85 85 #include <ipc/event.h> 86 86 #include <sysinfo/sysinfo.h> 87 #include <sysinfo/stats.h> 87 88 88 89 /** Global configuration structure. */ … … 225 226 226 227 printf("Detected %" PRIs " CPU(s), %" PRIu64" MiB free memory\n", 227 config.cpu_count, SIZE2MB(zone _total_size()));228 config.cpu_count, SIZE2MB(zones_total_size())); 228 229 229 230 LOG_EXEC(cpu_init()); … … 249 250 LOG_EXEC(event_init()); 250 251 LOG_EXEC(klog_init()); 252 LOG_EXEC(stats_init()); 251 253 252 254 /* -
kernel/generic/src/mm/frame.c
rd8e3467 r9dae191e 1202 1202 1203 1203 /** Return total size of all zones. */ 1204 uint64_t zone _total_size(void)1204 uint64_t zones_total_size(void) 1205 1205 { 1206 1206 ipl_t ipl = interrupts_disable(); … … 1218 1218 } 1219 1219 1220 void zone_busy_and_free(uint64_t *out_busy, uint64_t *out_free) 1221 { 1220 void zones_stats(uint64_t *total, uint64_t *unavail, uint64_t *busy, 1221 uint64_t *free) 1222 { 1223 ASSERT(total != NULL); 1224 ASSERT(unavail != NULL); 1225 ASSERT(busy != NULL); 1226 ASSERT(free != NULL); 1227 1222 1228 ipl_t ipl = interrupts_disable(); 1223 1229 spinlock_lock(&zones.lock); 1224 1225 uint64_t busy = 0, free = 0; 1230 1231 *total = 0; 1232 *unavail = 0; 1233 *busy = 0; 1234 *free = 0; 1235 1226 1236 size_t i; 1227 1237 for (i = 0; i < zones.count; i++) { 1228 bool available = zone_flags_available(zones.info[i].flags); 1229 /* Do not count reserved memory */ 1230 if (available) { 1231 busy += (uint64_t) FRAMES2SIZE(zones.info[i].busy_count); 1232 free += (uint64_t) FRAMES2SIZE(zones.info[i].free_count); 1233 } 1234 } 1235 1238 *total += (uint64_t) FRAMES2SIZE(zones.info[i].count); 1239 1240 if (zone_flags_available(zones.info[i].flags)) { 1241 *busy += (uint64_t) FRAMES2SIZE(zones.info[i].busy_count); 1242 *free += (uint64_t) FRAMES2SIZE(zones.info[i].free_count); 1243 } else 1244 *unavail += (uint64_t) FRAMES2SIZE(zones.info[i].count); 1245 } 1246 1236 1247 spinlock_unlock(&zones.lock); 1237 1248 interrupts_restore(ipl); 1238 *out_busy = busy;1239 *out_free = free;1240 1249 } 1241 1250 1242 1251 /** Prints list of zones. */ 1243 void zone _print_list(void)1252 void zones_print_list(void) 1244 1253 { 1245 1254 #ifdef __32_BITS__ -
kernel/generic/src/syscall/syscall.c
rd8e3467 r9dae191e 54 54 #include <console/console.h> 55 55 #include <udebug/udebug.h> 56 #include <ps/ps.h>57 #include <ps/load.h>58 #include <ps/uptime.h>59 56 60 57 /** Dispatch system call */ … … 147 144 (syshandler_t) sys_ipc_register_irq, 148 145 (syshandler_t) sys_ipc_unregister_irq, 149 146 150 147 /* Event notification syscalls. */ 151 148 (syshandler_t) sys_event_subscribe, … … 170 167 (syshandler_t) sys_debug_enable_console, 171 168 (syshandler_t) sys_debug_disable_console, 172 173 /* Ps calls */174 (syshandler_t) sys_ps_get_cpu_info,175 (syshandler_t) sys_ps_get_mem_info,176 (syshandler_t) sys_ps_get_tasks,177 (syshandler_t) sys_ps_get_task_info,178 (syshandler_t) sys_ps_get_threads,179 (syshandler_t) sys_ps_get_uptime,180 (syshandler_t) sys_ps_get_load,181 169 182 170 (syshandler_t) sys_ipc_connect_kbox -
kernel/generic/src/sysinfo/sysinfo.c
rd8e3467 r9dae191e 37 37 #include <print.h> 38 38 #include <syscall/copy.h> 39 #include <synch/spinlock.h> 39 40 #include <errno.h> 40 41 … … 45 46 static sysinfo_item_t *global_root = NULL; 46 47 static slab_cache_t *sysinfo_item_slab; 48 49 SPINLOCK_STATIC_INITIALIZE_NAME(sysinfo_lock, "sysinfo_lock"); 47 50 48 51 static int sysinfo_item_constructor(void *obj, int kmflag) … … 76 79 } 77 80 81 /** Recursively find item in sysinfo tree 82 * 83 * Should be called with interrupts disabled 84 * and sysinfo_lock held. 85 * 86 */ 78 87 static sysinfo_item_t *sysinfo_find_item(const char *name, 79 sysinfo_item_t *subtree) 80 { 88 sysinfo_item_t *subtree, sysinfo_return_t **ret) 89 { 90 ASSERT(subtree != NULL); 91 ASSERT(ret != NULL); 92 81 93 sysinfo_item_t *cur = subtree; 82 94 … … 98 110 case SYSINFO_SUBTREE_TABLE: 99 111 /* Recursively find in subtree */ 100 return sysinfo_find_item(name + i + 1, cur->subtree.table); 112 return sysinfo_find_item(name + i + 1, 113 cur->subtree.table, ret); 101 114 case SYSINFO_SUBTREE_FUNCTION: 102 /* Get generated item */ 103 return cur->subtree.find_item(name + i + 1); 115 /* Get generated data */ 116 **ret = cur->subtree.get_data(name + i + 1); 117 return NULL; 104 118 default: 105 119 /* Not found */ 120 *ret = NULL; 106 121 return NULL; 107 122 } … … 111 126 } 112 127 128 *ret = NULL; 113 129 return NULL; 114 130 } 115 131 132 /** Recursively create items in sysinfo tree 133 * 134 * Should be called with interrupts disabled 135 * and sysinfo_lock held. 136 * 137 */ 116 138 static sysinfo_item_t *sysinfo_create_path(const char *name, 117 139 sysinfo_item_t **psubtree) … … 224 246 unative_t val) 225 247 { 248 ipl_t ipl = interrupts_disable(); 249 spinlock_lock(&sysinfo_lock); 250 226 251 if (root == NULL) 227 252 root = &global_root; … … 232 257 item->val.val = val; 233 258 } 259 260 spinlock_unlock(&sysinfo_lock); 261 interrupts_restore(ipl); 234 262 } 235 263 … … 237 265 void *data, size_t size) 238 266 { 267 ipl_t ipl = interrupts_disable(); 268 spinlock_lock(&sysinfo_lock); 269 239 270 if (root == NULL) 240 271 root = &global_root; … … 246 277 item->val.data.size = size; 247 278 } 248 } 249 250 void sysinfo_set_item_val_fn(const char *name, sysinfo_item_t **root, 279 280 spinlock_unlock(&sysinfo_lock); 281 interrupts_restore(ipl); 282 } 283 284 void sysinfo_set_item_fn_val(const char *name, sysinfo_item_t **root, 251 285 sysinfo_fn_val_t fn) 252 286 { 287 ipl_t ipl = interrupts_disable(); 288 spinlock_lock(&sysinfo_lock); 289 253 290 if (root == NULL) 254 291 root = &global_root; … … 259 296 item->val.fn_val = fn; 260 297 } 261 } 262 263 void sysinfo_set_item_data_fn(const char *name, sysinfo_item_t **root, 298 299 spinlock_unlock(&sysinfo_lock); 300 interrupts_restore(ipl); 301 } 302 303 void sysinfo_set_item_fn_data(const char *name, sysinfo_item_t **root, 264 304 sysinfo_fn_data_t fn) 265 305 { 306 ipl_t ipl = interrupts_disable(); 307 spinlock_lock(&sysinfo_lock); 308 266 309 if (root == NULL) 267 310 root = &global_root; … … 272 315 item->val.fn_data = fn; 273 316 } 317 318 spinlock_unlock(&sysinfo_lock); 319 interrupts_restore(ipl); 274 320 } 275 321 276 322 void sysinfo_set_item_undefined(const char *name, sysinfo_item_t **root) 277 323 { 324 ipl_t ipl = interrupts_disable(); 325 spinlock_lock(&sysinfo_lock); 326 278 327 if (root == NULL) 279 328 root = &global_root; … … 282 331 if (item != NULL) 283 332 item->val_type = SYSINFO_VAL_UNDEFINED; 284 } 285 333 334 spinlock_unlock(&sysinfo_lock); 335 interrupts_restore(ipl); 336 } 337 338 void sysinfo_set_subtree_fn(const char *name, sysinfo_item_t **root, 339 sysinfo_fn_subtree_t fn) 340 { 341 ipl_t ipl = interrupts_disable(); 342 spinlock_lock(&sysinfo_lock); 343 344 if (root == NULL) 345 root = &global_root; 346 347 sysinfo_item_t *item = sysinfo_create_path(name, root); 348 if ((item != NULL) && (item->subtree_type != SYSINFO_SUBTREE_TABLE)) { 349 item->subtree_type = SYSINFO_SUBTREE_FUNCTION; 350 item->subtree.get_data = fn; 351 } 352 353 spinlock_unlock(&sysinfo_lock); 354 interrupts_restore(ipl); 355 } 356 357 /** Sysinfo dump indentation helper routine 358 * 359 */ 286 360 static void sysinfo_indent(unsigned int depth) 287 361 { … … 291 365 } 292 366 293 void sysinfo_dump(sysinfo_item_t **proot, unsigned int depth) 294 { 295 if (proot == NULL) 296 proot = &global_root; 297 298 sysinfo_item_t *cur = *proot; 367 /** Dump the structure of sysinfo tree 368 * 369 * Should be called with interrupts disabled 370 * and sysinfo_lock held. Because this routine 371 * might take a reasonable long time to proceed, 372 * having the spinlock held is not optimal, but 373 * there is no better simple solution. 374 * 375 */ 376 static void sysinfo_dump_internal(sysinfo_item_t *root, unsigned int depth) 377 { 378 sysinfo_item_t *cur = root; 299 379 300 380 while (cur != NULL) { … … 302 382 303 383 unative_t val; 384 void *data; 304 385 size_t size; 305 386 … … 322 403 break; 323 404 case SYSINFO_VAL_FUNCTION_DATA: 324 cur->val.fn_data(cur, &size); 405 data = cur->val.fn_data(cur, &size); 406 if (data != NULL) 407 free(data); 408 325 409 printf("+ %s (%" PRIs" bytes) [generated]\n", cur->name, 326 410 size); … … 334 418 break; 335 419 case SYSINFO_SUBTREE_TABLE: 336 sysinfo_dump (&(cur->subtree.table), depth + 1);420 sysinfo_dump_internal(cur->subtree.table, depth + 1); 337 421 break; 338 422 case SYSINFO_SUBTREE_FUNCTION: 339 423 sysinfo_indent(depth + 1); 340 printf(" 424 printf("+ [generated subtree]\n"); 341 425 break; 342 426 default: 343 427 sysinfo_indent(depth + 1); 344 printf(" 428 printf("+ [unknown subtree]\n"); 345 429 } 346 430 … … 349 433 } 350 434 351 sysinfo_return_t sysinfo_get_item(const char *name, sysinfo_item_t **root) 435 void sysinfo_dump(sysinfo_item_t *root) 436 { 437 ipl_t ipl = interrupts_disable(); 438 spinlock_lock(&sysinfo_lock); 439 440 if (root == NULL) 441 sysinfo_dump_internal(global_root, 0); 442 else 443 sysinfo_dump_internal(root, 0); 444 445 spinlock_unlock(&sysinfo_lock); 446 interrupts_restore(ipl); 447 } 448 449 /** Return sysinfo item determined by name 450 * 451 * Should be called with interrupts disabled 452 * and sysinfo_lock held. 453 * 454 */ 455 static sysinfo_return_t sysinfo_get_item(const char *name, sysinfo_item_t **root) 352 456 { 353 457 if (root == NULL) 354 458 root = &global_root; 355 459 356 sysinfo_item_t *item = sysinfo_find_item(name, *root);357 460 sysinfo_return_t ret; 461 sysinfo_return_t *ret_ptr = &ret; 462 sysinfo_item_t *item = sysinfo_find_item(name, *root, &ret_ptr); 358 463 359 464 if (item != NULL) { 465 ret.tag = item->val_type; 360 466 switch (item->val_type) { 361 467 case SYSINFO_VAL_UNDEFINED: 468 break; 469 case SYSINFO_VAL_VAL: 470 ret.val = item->val.val; 471 break; 472 case SYSINFO_VAL_DATA: 473 ret.data = item->val.data; 474 break; 475 case SYSINFO_VAL_FUNCTION_VAL: 476 ret.val = item->val.fn_val(item); 477 break; 478 case SYSINFO_VAL_FUNCTION_DATA: 479 ret.data.data = item->val.fn_data(item, &ret.data.size); 480 break; 481 } 482 } else { 483 if (ret_ptr == NULL) 362 484 ret.tag = SYSINFO_VAL_UNDEFINED; 363 break; 364 case SYSINFO_VAL_VAL: 365 ret.tag = SYSINFO_VAL_VAL; 366 ret.val = item->val.val; 367 break; 368 case SYSINFO_VAL_DATA: 369 ret.tag = SYSINFO_VAL_DATA; 370 ret.data = item->val.data; 371 break; 372 case SYSINFO_VAL_FUNCTION_VAL: 373 ret.tag = SYSINFO_VAL_VAL; 374 ret.val = item->val.fn_val(item); 375 break; 376 case SYSINFO_VAL_FUNCTION_DATA: 377 ret.tag = SYSINFO_VAL_DATA; 378 ret.data.data = item->val.fn_data(item, &ret.data.size); 379 break; 380 } 381 } else 382 ret.tag = SYSINFO_VAL_UNDEFINED; 485 } 383 486 384 487 return ret; 385 488 } 386 489 490 /** Return sysinfo item determined by name from user space 491 * 492 * Should be called with interrupts disabled 493 * and sysinfo_lock held. 494 * 495 */ 387 496 static sysinfo_return_t sysinfo_get_item_uspace(void *ptr, size_t size) 388 497 { … … 397 506 398 507 if ((copy_from_uspace(path, ptr, size + 1) == 0) 399 && (path[size] == 0)) {508 && (path[size] == 0)) 400 509 ret = sysinfo_get_item(path, NULL); 401 free(path); 402 } 403 510 511 free(path); 404 512 return ret; 405 513 } … … 407 515 unative_t sys_sysinfo_get_tag(void *path_ptr, size_t path_size) 408 516 { 409 return (unative_t) sysinfo_get_item_uspace(path_ptr, path_size).tag; 517 ipl_t ipl = interrupts_disable(); 518 spinlock_lock(&sysinfo_lock); 519 520 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size); 521 522 if ((ret.tag == SYSINFO_VAL_FUNCTION_DATA) && (ret.data.data != NULL)) 523 free(ret.data.data); 524 525 if (ret.tag == SYSINFO_VAL_FUNCTION_VAL) 526 ret.tag = SYSINFO_VAL_VAL; 527 else if (ret.tag == SYSINFO_VAL_FUNCTION_DATA) 528 ret.tag = SYSINFO_VAL_DATA; 529 530 spinlock_unlock(&sysinfo_lock); 531 interrupts_restore(ipl); 532 533 return (unative_t) ret.tag; 410 534 } 411 535 … … 413 537 void *value_ptr) 414 538 { 539 ipl_t ipl = interrupts_disable(); 540 spinlock_lock(&sysinfo_lock); 541 415 542 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size); 416 417 if (ret.tag != SYSINFO_VAL_VAL) 418 return (unative_t) EINVAL; 419 420 return (unative_t) copy_to_uspace(value_ptr, &ret.val, 421 sizeof(ret.val)); 543 int rc; 544 545 if ((ret.tag == SYSINFO_VAL_VAL) || (ret.tag == SYSINFO_VAL_FUNCTION_VAL)) 546 rc = copy_to_uspace(value_ptr, &ret.val, sizeof(ret.val)); 547 else 548 rc = EINVAL; 549 550 if ((ret.tag == SYSINFO_VAL_FUNCTION_DATA) && (ret.data.data != NULL)) 551 free(ret.data.data); 552 553 spinlock_unlock(&sysinfo_lock); 554 interrupts_restore(ipl); 555 556 return (unative_t) rc; 422 557 } 423 558 … … 425 560 void *size_ptr) 426 561 { 562 ipl_t ipl = interrupts_disable(); 563 spinlock_lock(&sysinfo_lock); 564 427 565 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size); 428 429 if (ret.tag != SYSINFO_VAL_DATA) 430 return (unative_t) EINVAL; 431 432 return (unative_t) copy_to_uspace(size_ptr, &ret.data.size, 433 sizeof(ret.data.size)); 566 int rc; 567 568 if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) 569 rc = copy_to_uspace(size_ptr, &ret.data.size, 570 sizeof(ret.data.size)); 571 else 572 rc = EINVAL; 573 574 if ((ret.tag == SYSINFO_VAL_FUNCTION_DATA) && (ret.data.data != NULL)) 575 free(ret.data.data); 576 577 spinlock_unlock(&sysinfo_lock); 578 interrupts_restore(ipl); 579 580 return (unative_t) rc; 434 581 } 435 582 … … 437 584 void *buffer_ptr, size_t buffer_size) 438 585 { 586 ipl_t ipl = interrupts_disable(); 587 spinlock_lock(&sysinfo_lock); 588 439 589 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size); 440 441 if (ret.tag != SYSINFO_VAL_DATA) 442 return (unative_t) EINVAL; 443 444 if (ret.data.size != buffer_size) 445 return ENOMEM; 446 447 return (unative_t) copy_to_uspace(buffer_ptr, ret.data.data, 448 ret.data.size); 590 int rc; 591 592 if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) { 593 if (ret.data.size == buffer_size) 594 rc = copy_to_uspace(buffer_ptr, ret.data.data, 595 ret.data.size); 596 else 597 rc = ENOMEM; 598 } else 599 rc = EINVAL; 600 601 if ((ret.tag == SYSINFO_VAL_FUNCTION_DATA) && (ret.data.data != NULL)) 602 free(ret.data.data); 603 604 spinlock_unlock(&sysinfo_lock); 605 interrupts_restore(ipl); 606 607 return (unative_t) rc; 449 608 } 450 609 -
kernel/generic/src/time/clock.c
rd8e3467 r9dae191e 86 86 uptime->seconds1 = 0; 87 87 uptime->seconds2 = 0; 88 uptime->useconds = 0; 88 uptime->useconds = 0; 89 89 90 90 clock_parea.pbase = (uintptr_t) faddr;
Note:
See TracChangeset
for help on using the changeset viewer.