Changeset 9f8745c5 in mainline
- Timestamp:
- 2012-07-10T18:07:34Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b23c88e
- Parents:
- 5b6c033
- Location:
- kernel
- Files:
-
- 2 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/Makefile
r5b6c033 r9f8745c5 305 305 test/synch/semaphore1.c \ 306 306 test/synch/semaphore2.c \ 307 test/synch/rcu1.c \308 test/synch/workqueue1.c \309 307 test/synch/workqueue2.c \ 310 308 test/synch/workqueue3.c \ 309 test/synch/rcu1.c \ 311 310 test/print/print1.c \ 312 311 test/print/print2.c \ -
kernel/generic/include/synch/workqueue.h
r5b6c033 r9f8745c5 1 /* 2 * Copyright (c) 2012 Adam Hraska 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** @addtogroup generic 30 * @{ 31 */ 32 /** @file 33 */ 1 34 2 35 #ifndef KERN_WORKQUEUE_H_ … … 46 79 47 80 #endif /* KERN_WORKQUEUE_H_ */ 81 82 /** @} 83 */ -
kernel/generic/src/synch/workqueue.c
r5b6c033 r9f8745c5 1 /* 2 * Copyright (c) 2012 Adam Hraska 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** @addtogroup generic 30 * @{ 31 */ 32 33 /** 34 * @file 35 * @brief Work queue/thread pool that automatically adjusts its size 36 * depending on the current load. Queued work functions may sleep.. 37 */ 38 1 39 #include <synch/workqueue.h> 2 40 #include <synch/spinlock.h> … … 934 972 #endif 935 973 } 974 975 /** @} 976 */ -
kernel/test/synch/workq-test-core.h
r5b6c033 r9f8745c5 203 203 return NULL; 204 204 else { 205 return "Failed to invoke the expected number of calls. ";206 } 207 } 205 return "Failed to invoke the expected number of calls.\n"; 206 } 207 } -
kernel/test/synch/workqueue2.c
r5b6c033 r9f8745c5 47 47 48 48 49 /*-------------------------------------------------------------------*/ 50 51 static work_t basic_work; 52 static int basic_done = 0; 53 54 static void basic_test_work(work_t *work_item) 55 { 56 basic_done = 1; 57 TPRINTF("basic_test_work()"); 58 } 59 60 61 static void basic_test(void) 62 { 63 TPRINTF("Issue a single work item.\n"); 64 basic_done = 0; 65 workq_global_enqueue(&basic_work, basic_test_work); 66 67 while (!basic_done) { 68 TPRINTF("."); 69 thread_sleep(1); 70 } 71 72 TPRINTF("\nBasic test done\n"); 73 } 74 75 /*-------------------------------------------------------------------*/ 76 77 49 78 struct work_queue *workq = NULL; 50 79 … … 53 82 return workq_enqueue(workq, work_item, func); 54 83 } 84 /*-------------------------------------------------------------------*/ 55 85 56 86 57 58 const char *test_workqueue2(void) 87 static const char *test_custom_workq_impl(bool stop, const char *qname) 59 88 { 60 workq = workq_create( "test-workq");89 workq = workq_create(qname); 61 90 62 91 if (!workq) { 63 return "Failed to create a work queue. ";92 return "Failed to create a work queue.\n"; 64 93 } 65 94 66 const char *ret = run_workq_core( false);95 const char *ret = run_workq_core(stop); 67 96 68 97 TPRINTF("Stopping work queue...\n"); … … 71 100 TPRINTF("Destroying work queue...\n"); 72 101 workq_destroy(workq); 73 74 102 return ret; 75 103 } 76 104 105 static const char *test_custom_workq(void) 106 { 107 TPRINTF("Stress testing a custom queue.\n"); 108 return test_custom_workq_impl(false, "test-workq"); 109 } 77 110 78 const char *test_workqueue2stop(void) 111 112 static const char *test_custom_workq_stop(void) 79 113 { 80 workq = workq_create("test-workq"); 114 TPRINTF("Stress testing a custom queue. Stops prematurely. " 115 "Errors are expected.\n"); 116 test_custom_workq_impl(true, "test-workq-stop"); 117 /* Errors are expected. */ 118 return 0; 119 } 120 121 122 const char *test_workqueue_all(void) 123 { 124 const char *err = 0; 125 const char *res; 81 126 82 if (!workq) { 83 return "Failed to create a work queue."; 127 basic_test(); 128 129 res = test_custom_workq(); 130 if (res) { 131 TPRINTF(res); 132 err = res; 84 133 } 85 134 86 const char *ret = run_workq_core(true); 135 res = test_custom_workq_stop(); 136 if (res) { 137 TPRINTF(res); 138 err = res; 139 } 87 140 88 TPRINTF("Stopping work queue...\n");89 workq_stop(workq);90 91 TPRINTF("Destroying work queue...\n");92 workq_destroy(workq);141 res = test_workqueue3(); 142 if (res) { 143 TPRINTF(res); 144 err = res; 145 } 93 146 94 return ret;147 return err; 95 148 } 96 -
kernel/test/synch/workqueue2.def
r5b6c033 r9f8745c5 1 1 { 2 "workqueue 2",3 "Separate work queuetest",4 &test_workqueue 2,2 "workqueue", 3 "Separate and system work queue stress test", 4 &test_workqueue_all, 5 5 true 6 6 }, 7 {8 "workqueue2stop",9 "Separate work queue test, stops early",10 &test_workqueue2stop,11 true12 }, -
kernel/test/synch/workqueue3.c
r5b6c033 r9f8745c5 57 57 { 58 58 const char *err = 0; 59 59 TPRINTF("Stress testing system queue.\n"); 60 60 TPRINTF("First run:\n"); 61 61 err = run_workq_core(exit_early); -
kernel/test/synch/workqueue3.def
r5b6c033 r9f8745c5 1 {2 "workqueue3",3 "Global work queue test",4 &test_workqueue3,5 true6 },7 1 { 8 2 "workqueue3quit", -
kernel/test/test.c
r5b6c033 r9f8745c5 51 51 #include <synch/semaphore2.def> 52 52 #include <synch/rcu1.def> 53 #include <synch/workqueue1.def>54 53 #include <synch/workqueue2.def> 55 54 #include <synch/workqueue3.def> -
kernel/test/test.h
r5b6c033 r9f8745c5 76 76 extern const char *test_thread1(void); 77 77 extern const char *test_smpcall1(void); 78 extern const char *test_workqueue1(void); 79 extern const char *test_workqueue2(void); 80 extern const char *test_workqueue2stop(void); 78 extern const char *test_workqueue_all(void); 81 79 extern const char *test_workqueue3(void); 82 80 extern const char *test_workqueue3quit(void);
Note:
See TracChangeset
for help on using the changeset viewer.