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