Changeset 38d8849 in mainline for uspace/app
- Timestamp:
- 2018-07-16T15:58:51Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- db51219f
- Parents:
- c124c985
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-14 16:53:46)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-16 15:58:51)
- Location:
- uspace/app
- Files:
-
- 4 edited
-
rcubench/rcubench.c (modified) (4 diffs)
-
rcutest/rcutest.c (modified) (2 diffs)
-
tester/float/float1.c (modified) (5 diffs)
-
tester/thread/thread1.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/rcubench/rcubench.c
rc124c985 r38d8849 40 40 #include <mem.h> 41 41 #include <errno.h> 42 #include <thread.h>43 42 #include <assert.h> 44 43 #include <async.h> … … 105 104 } 106 105 107 static voidthread_func(void *arg)106 static errno_t thread_func(void *arg) 108 107 { 109 108 bench_t *bench = (bench_t *)arg; … … 113 112 /* Signal another thread completed. */ 114 113 futex_up(&bench->done_threads); 114 return EOK; 115 115 } 116 116 … … 123 123 } 124 124 125 fibril_test_spawn_runners(bench->nthreads - 1); 126 125 127 /* Create and run the first nthreads - 1 threads.*/ 126 128 for (size_t k = 1; k < bench->nthreads; ++k) { 127 thread_id_t tid; 128 /* Also sets up a fibril for the thread. */ 129 errno_t ret = thread_create(thread_func, bench, "rcubench-t", &tid); 130 if (ret != EOK) { 129 fid_t f = fibril_create(thread_func, bench); 130 if (!f) { 131 131 printf("Error: Failed to create benchmark thread.\n"); 132 132 abort(); 133 133 } 134 thread_detach(tid); 134 fibril_detach(f); 135 fibril_add_ready(f); 135 136 } 136 137 -
uspace/app/rcutest/rcutest.c
rc124c985 r38d8849 41 41 #include <mem.h> 42 42 #include <errno.h> 43 #include <thread.h>44 43 #include <assert.h> 45 44 #include <async.h> … … 759 758 /*--------------------------------------------------------------------*/ 760 759 761 static FIBRIL_MUTEX_INITIALIZE(blocking_mtx);762 763 static void dummy_fibril(void *arg)764 {765 /* Block on an already locked mutex - enters the fibril manager. */766 fibril_mutex_lock(&blocking_mtx);767 assert(false);768 }769 770 760 static bool create_threads(size_t cnt) 771 761 { 772 762 /* Sanity check. */ 773 763 assert(cnt < 1024); 774 775 /* Keep this mutex locked so that dummy fibrils never exit. */ 776 bool success = fibril_mutex_trylock(&blocking_mtx); 777 assert(success); 778 779 for (size_t k = 0; k < cnt; ++k) { 780 thread_id_t tid; 781 782 errno_t ret = thread_create(dummy_fibril, NULL, "urcu-test-worker", &tid); 783 if (EOK != ret) { 784 printf("Failed to create thread '%zu' (error: %s)\n", k + 1, str_error_name(ret)); 785 return false; 786 } 787 } 788 764 fibril_test_spawn_runners(cnt); 789 765 return true; 790 766 } -
uspace/app/tester/float/float1.c
rc124c985 r38d8849 33 33 #include <stddef.h> 34 34 #include <atomic.h> 35 #include <thread.h> 35 #include <fibril.h> 36 #include <fibril_synch.h> 36 37 #include <inttypes.h> 37 38 #include "../tester.h" … … 43 44 #define PRECISION 100000000 44 45 45 static atomic_t threads_finished;46 static FIBRIL_SEMAPHORE_INITIALIZE(threads_finished, 0); 46 47 static atomic_t threads_fault; 47 48 48 static voide(void *data)49 static errno_t e(void *data) 49 50 { 50 51 for (unsigned int i = 0; i < ATTEMPTS; i++) { … … 64 65 } 65 66 66 atomic_inc(&threads_finished); 67 fibril_semaphore_up(&threads_finished); 68 return EOK; 67 69 } 68 70 … … 71 73 atomic_count_t total = 0; 72 74 73 atomic_set(&threads_finished, 0);74 75 atomic_set(&threads_fault, 0); 76 fibril_test_spawn_runners(THREADS); 75 77 76 78 TPRINTF("Creating threads"); 77 79 for (unsigned int i = 0; i < THREADS; i++) { 78 if (thread_create(e, NULL, "e", NULL) != EOK) { 80 fid_t f = fibril_create(e, NULL); 81 if (!f) { 79 82 TPRINTF("\nCould not create thread %u\n", i); 80 83 break; 81 84 } 85 fibril_detach(f); 86 fibril_add_ready(f); 82 87 83 88 TPRINTF("."); … … 87 92 TPRINTF("\n"); 88 93 89 while (atomic_get(&threads_finished) < total) { 90 TPRINTF("Threads left: %" PRIua "\n", 91 total - atomic_get(&threads_finished)); 92 thread_sleep(1); 94 for (unsigned int i = 0; i < total; i++) { 95 TPRINTF("Threads left: %" PRIua "\n", total - i); 96 fibril_semaphore_down(&threads_finished); 93 97 } 94 98 -
uspace/app/tester/thread/thread1.c
rc124c985 r38d8849 33 33 #include <atomic.h> 34 34 #include <errno.h> 35 #include <thread.h> 35 #include <fibril.h> 36 #include <fibril_synch.h> 36 37 #include <stdio.h> 37 38 #include <stddef.h> … … 40 41 41 42 static atomic_t finish; 42 static atomic_t threads_finished;43 43 44 static void threadtest(void *data) 44 static FIBRIL_SEMAPHORE_INITIALIZE(threads_finished, 0); 45 46 static errno_t threadtest(void *data) 45 47 { 46 thread_detach(thread_get_id());48 fibril_detach(fibril_get_id()); 47 49 48 50 while (atomic_get(&finish)) 49 thread_usleep(100000);51 fibril_usleep(100000); 50 52 51 atomic_inc(&threads_finished); 53 fibril_semaphore_up(&threads_finished); 54 return EOK; 52 55 } 53 56 … … 58 61 59 62 atomic_set(&finish, 1); 60 atomic_set(&threads_finished, 0); 63 64 fibril_test_spawn_runners(THREADS); 61 65 62 66 TPRINTF("Creating threads"); 63 67 for (i = 0; i < THREADS; i++) { 64 if (thread_create(threadtest, NULL, "threadtest", NULL) != EOK) { 68 fid_t f = fibril_create(threadtest, NULL); 69 if (!f) { 65 70 TPRINTF("\nCould not create thread %u\n", i); 66 71 break; 67 72 } 73 fibril_add_ready(f); 68 74 TPRINTF("."); 69 75 total++; … … 71 77 72 78 TPRINTF("\nRunning threads for %u seconds...", DELAY); 73 thread_sleep(DELAY);79 fibril_sleep(DELAY); 74 80 TPRINTF("\n"); 75 81 76 82 atomic_set(&finish, 0); 77 while (atomic_get(&threads_finished) < total) {83 for (i = 0; i < total; i++) { 78 84 TPRINTF("Threads left: %" PRIua "\n", 79 total - atomic_get(&threads_finished));80 thread_sleep(1);85 total - i); 86 fibril_semaphore_down(&threads_finished); 81 87 } 82 88
Note:
See TracChangeset
for help on using the changeset viewer.
