Changes in kernel/generic/src/sysinfo/sysinfo.c [c6218327:e1b6742] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/sysinfo/sysinfo.c
rc6218327 re1b6742 37 37 #include <print.h> 38 38 #include <syscall/copy.h> 39 #include <synch/ mutex.h>39 #include <synch/spinlock.h> 40 40 #include <arch/asm.h> 41 41 #include <errno.h> … … 52 52 static slab_cache_t *sysinfo_item_slab; 53 53 54 /** Sysinfo lock */55 static mutex_t sysinfo_lock;54 /** Sysinfo spinlock */ 55 SPINLOCK_STATIC_INITIALIZE_NAME(sysinfo_lock, "sysinfo_lock"); 56 56 57 57 /** Sysinfo item constructor … … 98 98 sizeof(sysinfo_item_t), 0, sysinfo_item_constructor, 99 99 sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED); 100 101 mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE);102 100 } 103 101 104 102 /** Recursively find an item in sysinfo tree 105 103 * 106 * Should be called with sysinfo_lock held. 104 * Should be called with interrupts disabled 105 * and sysinfo_lock held. 107 106 * 108 107 * @param name Current sysinfo path suffix. … … 169 168 /** Recursively create items in sysinfo tree 170 169 * 171 * Should be called with sysinfo_lock held. 170 * Should be called with interrupts disabled 171 * and sysinfo_lock held. 172 172 * 173 173 * @param name Current sysinfo path suffix. … … 299 299 { 300 300 /* Protect sysinfo tree consistency */ 301 mutex_lock(&sysinfo_lock); 301 ipl_t ipl = interrupts_disable(); 302 spinlock_lock(&sysinfo_lock); 302 303 303 304 if (root == NULL) … … 310 311 } 311 312 312 mutex_unlock(&sysinfo_lock); 313 spinlock_unlock(&sysinfo_lock); 314 interrupts_restore(ipl); 313 315 } 314 316 … … 330 332 { 331 333 /* Protect sysinfo tree consistency */ 332 mutex_lock(&sysinfo_lock); 334 ipl_t ipl = interrupts_disable(); 335 spinlock_lock(&sysinfo_lock); 333 336 334 337 if (root == NULL) … … 342 345 } 343 346 344 mutex_unlock(&sysinfo_lock); 347 spinlock_unlock(&sysinfo_lock); 348 interrupts_restore(ipl); 345 349 } 346 350 … … 357 361 { 358 362 /* Protect sysinfo tree consistency */ 359 mutex_lock(&sysinfo_lock); 363 ipl_t ipl = interrupts_disable(); 364 spinlock_lock(&sysinfo_lock); 360 365 361 366 if (root == NULL) … … 368 373 } 369 374 370 mutex_unlock(&sysinfo_lock); 375 spinlock_unlock(&sysinfo_lock); 376 interrupts_restore(ipl); 371 377 } 372 378 … … 388 394 { 389 395 /* Protect sysinfo tree consistency */ 390 mutex_lock(&sysinfo_lock); 396 ipl_t ipl = interrupts_disable(); 397 spinlock_lock(&sysinfo_lock); 391 398 392 399 if (root == NULL) … … 399 406 } 400 407 401 mutex_unlock(&sysinfo_lock); 408 spinlock_unlock(&sysinfo_lock); 409 interrupts_restore(ipl); 402 410 } 403 411 … … 412 420 { 413 421 /* Protect sysinfo tree consistency */ 414 mutex_lock(&sysinfo_lock); 422 ipl_t ipl = interrupts_disable(); 423 spinlock_lock(&sysinfo_lock); 415 424 416 425 if (root == NULL) … … 421 430 item->val_type = SYSINFO_VAL_UNDEFINED; 422 431 423 mutex_unlock(&sysinfo_lock); 432 spinlock_unlock(&sysinfo_lock); 433 interrupts_restore(ipl); 424 434 } 425 435 … … 436 446 { 437 447 /* Protect sysinfo tree consistency */ 438 mutex_lock(&sysinfo_lock); 448 ipl_t ipl = interrupts_disable(); 449 spinlock_lock(&sysinfo_lock); 439 450 440 451 if (root == NULL) … … 450 461 } 451 462 452 mutex_unlock(&sysinfo_lock); 463 spinlock_unlock(&sysinfo_lock); 464 interrupts_restore(ipl); 453 465 } 454 466 … … 467 479 /** Dump the structure of sysinfo tree 468 480 * 469 * Should be called with sysinfo_lock held. 481 * Should be called with interrupts disabled 482 * and sysinfo_lock held. Because this routine 483 * might take a reasonable long time to proceed, 484 * having the spinlock held is not optimal, but 485 * there is no better simple solution. 470 486 * 471 487 * @param root Root item of the current (sub)tree. … … 543 559 /* Avoid other functions to mess with sysinfo 544 560 while we are dumping it */ 545 mutex_lock(&sysinfo_lock); 561 ipl_t ipl = interrupts_disable(); 562 spinlock_lock(&sysinfo_lock); 546 563 547 564 if (root == NULL) … … 550 567 sysinfo_dump_internal(root, 0); 551 568 552 mutex_unlock(&sysinfo_lock); 569 spinlock_unlock(&sysinfo_lock); 570 interrupts_restore(ipl); 553 571 } 554 572 555 573 /** Return sysinfo item value determined by name 556 574 * 557 * Should be called with sysinfo_lock held. 575 * Should be called with interrupts disabled 576 * and sysinfo_lock held. 558 577 * 559 578 * @param name Sysinfo path. … … 613 632 /** Return sysinfo item determined by name from user space 614 633 * 615 * The path string passed from the user space has to be properly null-terminated 634 * Should be called with interrupts disabled 635 * and sysinfo_lock held. The path string passed from 636 * the user space has to be properly null-terminated 616 637 * (the last passed character must be null). 617 638 * … … 635 656 636 657 if ((copy_from_uspace(path, ptr, size + 1) == 0) 637 && (path[size] == 0)) { 638 /* 639 * Prevent other functions from messing with sysinfo while we 640 * are reading it. 641 */ 642 mutex_lock(&sysinfo_lock); 658 && (path[size] == 0)) 643 659 ret = sysinfo_get_item(path, NULL, dry_run); 644 mutex_unlock(&sysinfo_lock); 645 } 660 646 661 free(path); 647 662 return ret; … … 662 677 unative_t sys_sysinfo_get_tag(void *path_ptr, size_t path_size) 663 678 { 664 /* 665 * Get the item. 666 * 667 * N.B.: There is no need to free any potential generated 668 * binary data since we request a dry run. 669 */ 679 /* Avoid other functions to mess with sysinfo 680 while we are reading it */ 681 ipl_t ipl = interrupts_disable(); 682 spinlock_lock(&sysinfo_lock); 683 684 /* Get the item. 685 686 N.B.: There is no need to free any potential generated 687 binary data since we request a dry run */ 670 688 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 671 689 672 /* 673 * Map generated value types to constant types (user space does not care 674 * whether the value is constant or generated). 675 */ 690 /* Map generated value types to constant types 691 (user space does not care whether the 692 value is constant or generated) */ 676 693 if (ret.tag == SYSINFO_VAL_FUNCTION_VAL) 677 694 ret.tag = SYSINFO_VAL_VAL; … … 679 696 ret.tag = SYSINFO_VAL_DATA; 680 697 698 spinlock_unlock(&sysinfo_lock); 699 interrupts_restore(ipl); 700 681 701 return (unative_t) ret.tag; 682 702 } … … 699 719 void *value_ptr) 700 720 { 721 /* Avoid other functions to mess with sysinfo 722 while we are reading it */ 723 ipl_t ipl = interrupts_disable(); 724 spinlock_lock(&sysinfo_lock); 725 726 /* Get the item. 727 728 N.B.: There is no need to free any potential generated 729 binary data since we request a dry run */ 730 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 701 731 int rc; 702 703 /*704 * Get the item.705 *706 * N.B.: There is no need to free any potential generated binary data707 * since we request a dry run.708 */709 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);710 732 711 733 /* Only constant or generated numerical value is returned */ … … 715 737 rc = EINVAL; 716 738 739 spinlock_unlock(&sysinfo_lock); 740 interrupts_restore(ipl); 741 717 742 return (unative_t) rc; 718 743 } … … 735 760 void *size_ptr) 736 761 { 762 /* Avoid other functions to mess with sysinfo 763 while we are reading it */ 764 ipl_t ipl = interrupts_disable(); 765 spinlock_lock(&sysinfo_lock); 766 767 /* Get the item. 768 769 N.B.: There is no need to free any potential generated 770 binary data since we request a dry run */ 771 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 737 772 int rc; 738 739 /*740 * Get the item.741 *742 * N.B.: There is no need to free any potential generated binary data743 * since we request a dry run.744 */745 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);746 773 747 774 /* Only the size of constant or generated binary data is considered */ … … 752 779 rc = EINVAL; 753 780 781 spinlock_unlock(&sysinfo_lock); 782 interrupts_restore(ipl); 783 754 784 return (unative_t) rc; 755 785 } … … 777 807 void *buffer_ptr, size_t buffer_size) 778 808 { 779 int rc; 809 /* Avoid other functions to mess with sysinfo 810 while we are reading it */ 811 ipl_t ipl = interrupts_disable(); 812 spinlock_lock(&sysinfo_lock); 780 813 781 814 /* Get the item */ 782 815 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, false); 783 816 int rc; 817 784 818 /* Only constant or generated binary data is considered */ 785 819 if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) { … … 797 831 free(ret.data.data); 798 832 833 spinlock_unlock(&sysinfo_lock); 834 interrupts_restore(ipl); 835 799 836 return (unative_t) rc; 800 837 }
Note:
See TracChangeset
for help on using the changeset viewer.