Changeset 70e2b2d in mainline
- Timestamp:
- 2010-04-18T10:23:15Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c3d4bb45
- Parents:
- da98918
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/sysinfo/sysinfo.h
rda98918 r70e2b2d 68 68 69 69 /** Generated binary data function */ 70 typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t * );70 typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *, bool); 71 71 72 72 /** Sysinfo item binary data -
kernel/generic/src/sysinfo/stats.c
rda98918 r70e2b2d 85 85 /** Get statistics of all CPUs 86 86 * 87 * @param item Sysinfo item (unused). 88 * @param size Size of the returned data. 87 * @param item Sysinfo item (unused). 88 * @param size Size of the returned data. 89 * @param dry_run Do not get the data, just calculate the size. 89 90 * 90 91 * @return Data containing several stats_cpu_t structures. … … 92 93 * in the context of the sysinfo request. 93 94 */ 94 static void *get_stats_cpus(struct sysinfo_item *item, size_t *size) 95 { 95 static void *get_stats_cpus(struct sysinfo_item *item, size_t *size, 96 bool dry_run) 97 { 98 *size = sizeof(stats_cpu_t) * config.cpu_count; 99 if (dry_run) 100 return NULL; 101 96 102 /* Assumption: config.cpu_count is constant */ 97 stats_cpu_t *stats_cpus = 98 (stats_cpu_t *) malloc(sizeof(stats_cpu_t) * config.cpu_count, 99 FRAME_ATOMIC); 103 stats_cpu_t *stats_cpus = (stats_cpu_t *) malloc(*size, FRAME_ATOMIC); 100 104 if (stats_cpus == NULL) { 101 105 *size = 0; … … 120 124 interrupts_restore(ipl); 121 125 122 *size = sizeof(stats_cpu_t) * config.cpu_count;123 126 return ((void *) stats_cpus); 124 127 } … … 172 175 /** Get task IDs 173 176 * 174 * @param item Sysinfo item (unused). 175 * @param size Size of the returned data. 177 * @param item Sysinfo item (unused). 178 * @param size Size of the returned data. 179 * @param dry_run Do not get the data, just calculate the size. 176 180 * 177 181 * @return Data containing task IDs of all tasks. … … 179 183 * in the context of the sysinfo request. 180 184 */ 181 static void *get_stats_tasks(struct sysinfo_item *item, size_t *size) 185 static void *get_stats_tasks(struct sysinfo_item *item, size_t *size, 186 bool dry_run) 182 187 { 183 188 /* Messing with task structures, avoid deadlock */ … … 198 203 } 199 204 200 task_id_t *task_ids = 201 (task_id_t *) malloc(sizeof(task_id_t) * count, FRAME_ATOMIC); 205 *size = sizeof(task_id_t) * count; 206 if (dry_run) { 207 spinlock_unlock(&tasks_lock); 208 interrupts_restore(ipl); 209 return NULL; 210 } 211 212 task_id_t *task_ids = (task_id_t *) malloc(*size, FRAME_ATOMIC); 202 213 if (task_ids == NULL) { 203 214 /* No free space for allocation */ … … 216 227 interrupts_restore(ipl); 217 228 218 *size = sizeof(task_id_t) * count;219 229 return ((void *) task_ids); 220 230 } … … 326 336 /** Get physical memory statistics 327 337 * 328 * @param item Sysinfo item (unused). 329 * @param size Size of the returned data. 338 * @param item Sysinfo item (unused). 339 * @param size Size of the returned data. 340 * @param dry_run Do not get the data, just calculate the size. 330 341 * 331 342 * @return Data containing stats_physmem_t. … … 333 344 * in the context of the sysinfo request. 334 345 */ 335 static void *get_stats_physmem(struct sysinfo_item *item, size_t *size) 336 { 346 static void *get_stats_physmem(struct sysinfo_item *item, size_t *size, 347 bool dry_run) 348 { 349 *size = sizeof(stats_physmem_t); 350 if (dry_run) 351 return NULL; 352 337 353 stats_physmem_t *stats_physmem = 338 (stats_physmem_t *) malloc( sizeof(stats_physmem_t), FRAME_ATOMIC);354 (stats_physmem_t *) malloc(*size, FRAME_ATOMIC); 339 355 if (stats_physmem == NULL) { 340 356 *size = 0; … … 345 361 &(stats_physmem->used), &(stats_physmem->free)); 346 362 347 *size = sizeof(stats_physmem_t);348 363 return ((void *) stats_physmem); 349 364 } … … 351 366 /** Get system load 352 367 * 353 * @param item Sysinfo item (unused). 354 * @param size Size of the returned data. 368 * @param item Sysinfo item (unused). 369 * @param size Size of the returned data. 370 * @param dry_run Do not get the data, just calculate the size. 355 371 * 356 372 * @return Data several load_t values. … … 358 374 * in the context of the sysinfo request. 359 375 */ 360 static void *get_stats_load(struct sysinfo_item *item, size_t *size) 361 { 362 load_t *stats_load = 363 (load_t *) malloc(sizeof(load_t) * LOAD_STEPS, FRAME_ATOMIC); 376 static void *get_stats_load(struct sysinfo_item *item, size_t *size, 377 bool dry_run) 378 { 379 *size = sizeof(load_t) * LOAD_STEPS; 380 if (dry_run) 381 return NULL; 382 383 load_t *stats_load = (load_t *) malloc(*size, FRAME_ATOMIC); 364 384 if (stats_load == NULL) { 365 385 *size = 0; … … 378 398 interrupts_restore(ipl); 379 399 380 *size = sizeof(load_t) * LOAD_STEPS;381 400 return ((void *) stats_load); 382 401 } -
kernel/generic/src/sysinfo/sysinfo.c
rda98918 r70e2b2d 496 496 497 497 unative_t val; 498 void *data;499 498 size_t size; 500 499 … … 518 517 break; 519 518 case SYSINFO_VAL_FUNCTION_DATA: 520 data = cur->val.fn_data(cur, &size); 521 522 /* N.B.: The generated binary data should be freed */ 523 if (data != NULL) 524 free(data); 525 519 /* N.B.: No data was actually returned (only a dry run) */ 520 (void) cur->val.fn_data(cur, &size, true); 526 521 printf("+ %s (%" PRIs" bytes) [generated]\n", cur->name, 527 522 size); … … 579 574 * and sysinfo_lock held. 580 575 * 581 * @param name Sysinfo path. 582 * @param root Root item of the sysinfo (sub)tree. 583 * If it is NULL then consider the global 584 * sysinfo tree. 576 * @param name Sysinfo path. 577 * @param root Root item of the sysinfo (sub)tree. 578 * If it is NULL then consider the global 579 * sysinfo tree. 580 * @param dry_run Do not actually get any generated 581 * binary data, just calculate the size. 585 582 * 586 583 * @return Item value (constant or generated). 587 584 * 588 585 */ 589 static sysinfo_return_t sysinfo_get_item(const char *name, sysinfo_item_t **root) 586 static sysinfo_return_t sysinfo_get_item(const char *name, 587 sysinfo_item_t **root, bool dry_run) 590 588 { 591 589 if (root == NULL) … … 614 612 break; 615 613 case SYSINFO_VAL_FUNCTION_DATA: 616 ret.data.data = item->val.fn_data(item, &ret.data.size); 614 ret.data.data = item->val.fn_data(item, &ret.data.size, 615 dry_run); 617 616 break; 618 617 } … … 635 634 * (the last passed character must be null). 636 635 * 637 * @param ptr Sysinfo path in the user address space. 638 * @param size Size of the path string. 639 * 640 */ 641 static sysinfo_return_t sysinfo_get_item_uspace(void *ptr, size_t size) 636 * @param ptr Sysinfo path in the user address space. 637 * @param size Size of the path string. 638 * @param dry_run Do not actually get any generated 639 * binary data, just calculate the size. 640 * 641 */ 642 static sysinfo_return_t sysinfo_get_item_uspace(void *ptr, size_t size, 643 bool dry_run) 642 644 { 643 645 sysinfo_return_t ret; … … 652 654 if ((copy_from_uspace(path, ptr, size + 1) == 0) 653 655 && (path[size] == 0)) 654 ret = sysinfo_get_item(path, NULL );656 ret = sysinfo_get_item(path, NULL, dry_run); 655 657 656 658 free(path); … … 677 679 spinlock_lock(&sysinfo_lock); 678 680 679 /* Get the item */ 680 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size); 681 682 /* N.B.: The generated binary data should be freed */ 683 if ((ret.tag == SYSINFO_VAL_FUNCTION_DATA) && (ret.data.data != NULL)) 684 free(ret.data.data); 681 /* Get the item. 682 683 N.B.: There is no need to free any potential generated 684 binary data since we request a dry run */ 685 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 685 686 686 687 /* Map generated value types to constant types … … 720 721 spinlock_lock(&sysinfo_lock); 721 722 722 /* Get the item */ 723 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size); 723 /* Get the item. 724 725 N.B.: There is no need to free any potential generated 726 binary data since we request a dry run */ 727 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 724 728 int rc; 725 729 … … 730 734 rc = EINVAL; 731 735 732 /* N.B.: The generated binary data should be freed */733 if ((ret.tag == SYSINFO_VAL_FUNCTION_DATA) && (ret.data.data != NULL))734 free(ret.data.data);735 736 736 spinlock_unlock(&sysinfo_lock); 737 737 interrupts_restore(ipl); … … 762 762 spinlock_lock(&sysinfo_lock); 763 763 764 /* Get the item */ 765 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size); 764 /* Get the item. 765 766 N.B.: There is no need to free any potential generated 767 binary data since we request a dry run */ 768 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 766 769 int rc; 767 770 … … 773 776 rc = EINVAL; 774 777 775 /* N.B.: The generated binary data should be freed */776 if ((ret.tag == SYSINFO_VAL_FUNCTION_DATA) && (ret.data.data != NULL))777 free(ret.data.data);778 779 778 spinlock_unlock(&sysinfo_lock); 780 779 interrupts_restore(ipl); … … 811 810 812 811 /* Get the item */ 813 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size );812 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, false); 814 813 int rc; 815 814 -
uspace/app/uptime/uptime.c
rda98918 r70e2b2d 39 39 #include <sys/time.h> 40 40 #include <inttypes.h> 41 #include <malloc.h> 41 42 42 43 #define NAME "uptime" … … 74 75 print_load_fragment(load[i], 2); 75 76 } 77 78 free(load); 76 79 } 77 80
Note:
See TracChangeset
for help on using the changeset viewer.