Changeset 3bacee1 in mainline for kernel/test
- Timestamp:
- 2018-04-12T16:27:17Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3cf22f9
- Parents:
- 76d0981d
- git-author:
- Jiri Svoboda <jiri@…> (2018-04-11 19:25:33)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-04-12 16:27:17)
- Location:
- kernel/test
- Files:
-
- 3 edited
-
cht/cht1.c (modified) (19 diffs)
-
synch/rcu1.c (modified) (29 diffs)
-
synch/workq-test-core.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/cht/cht1.c
r76d0981d r3bacee1 95 95 96 96 97 static const char * do_sanity_test(cht_t *h)98 { 99 if (cht_find_lazy(h, (void *)0))97 static const char *do_sanity_test(cht_t *h) 98 { 99 if (cht_find_lazy(h, (void *)0)) 100 100 return "Found lazy in empty table."; 101 101 102 if (cht_find(h, (void *)0))102 if (cht_find(h, (void *)0)) 103 103 return "Found in empty table."; 104 104 105 if (cht_remove_key(h, (void *)0))105 if (cht_remove_key(h, (void *)0)) 106 106 return "Removed from empty table."; 107 107 … … 149 149 return "Refused unique ins 4, 5."; 150 150 151 if (cht_find(h, (void *)0))151 if (cht_find(h, (void *)0)) 152 152 return "Phantom find."; 153 153 154 cht_link_t *item = cht_find(h, (void *)v[5]->unique_id);154 cht_link_t *item = cht_find(h, (void *)v[5]->unique_id); 155 155 if (!item || item != &v[5]->link) 156 156 return "Missing 5."; … … 160 160 return "Found nonexisting duplicate 5"; 161 161 162 item = cht_find(h, (void *)v[3]->unique_id);162 item = cht_find(h, (void *)v[3]->unique_id); 163 163 if (!item || item != &v[3]->link) 164 164 return "Missing 3."; … … 168 168 return "Found nonexisting duplicate 3, same hash as others."; 169 169 170 item = cht_find(h, (void *)v[0]->unique_id);171 ((val_t *)item)->mark = true;170 item = cht_find(h, (void *)v[0]->unique_id); 171 ((val_t *)item)->mark = true; 172 172 173 173 for (int k = 1; k < 3; ++k) { … … 176 176 return "Did not find an inserted duplicate"; 177 177 178 val_t *val = ((val_t *)item);178 val_t *val = ((val_t *)item); 179 179 180 180 if (val->unique_id != v[0]->unique_id) … … 195 195 return "Found non-existing duplicate."; 196 196 197 item = cht_find_next(h, cht_find(h, (void *)key[0]));198 199 ((val_t *)item)->mark = true;197 item = cht_find_next(h, cht_find(h, (void *)key[0])); 198 199 ((val_t *)item)->mark = true; 200 200 if (!cht_remove_item(h, item)) 201 201 return "Failed to remove inserted item"; 202 202 203 item = cht_find(h, (void *)key[0]);204 if (!item || ((val_t *)item)->mark)203 item = cht_find(h, (void *)key[0]); 204 if (!item || ((val_t *)item)->mark) 205 205 return "Did not find proper item."; 206 206 207 207 item = cht_find_next(h, item); 208 if (!item || ((val_t *)item)->mark)208 if (!item || ((val_t *)item)->mark) 209 209 return "Did not find proper duplicate."; 210 210 … … 213 213 return "Found removed duplicate"; 214 214 215 if (2 != cht_remove_key(h, (void *)key[0]))215 if (2 != cht_remove_key(h, (void *)key[0])) 216 216 return "Failed to remove all duplicates"; 217 217 218 if (cht_find(h, (void *)key[0]))218 if (cht_find(h, (void *)key[0])) 219 219 return "Found removed key"; 220 220 221 if (!cht_find(h, (void *)key[3]))221 if (!cht_find(h, (void *)key[3])) 222 222 return "Removed incorrect key"; 223 223 224 224 for (size_t k = 0; k < sizeof(v) / sizeof(v[0]); ++k) { 225 cht_remove_key(h, (void *)key[k]);225 cht_remove_key(h, (void *)key[k]); 226 226 } 227 227 228 228 for (size_t k = 0; k < sizeof(v) / sizeof(v[0]); ++k) { 229 if (cht_find(h, (void *)key[k]))229 if (cht_find(h, (void *)key[k])) 230 230 return "Found a key in a cleared table"; 231 231 } … … 234 234 } 235 235 236 static const char * sanity_test(void)236 static const char *sanity_test(void) 237 237 { 238 238 cht_t h; … … 279 279 static size_t stress_hash(const cht_link_t *item) 280 280 { 281 return ((stress_t *)item)->key >> 8;281 return ((stress_t *)item)->key >> 8; 282 282 } 283 283 static size_t stress_key_hash(void *key) … … 287 287 static bool stress_equal(const cht_link_t *item1, const cht_link_t *item2) 288 288 { 289 return ((stress_t *)item1)->key == ((stress_t*)item2)->key;289 return ((stress_t *)item1)->key == ((stress_t *)item2)->key; 290 290 } 291 291 static bool stress_key_equal(void *key, const cht_link_t *item) 292 292 { 293 return ((size_t)key) == ((stress_t *)item)->key;293 return ((size_t)key) == ((stress_t *)item)->key; 294 294 } 295 295 static void stress_rm_callback(cht_link_t *item) 296 296 { 297 if (((stress_t *)item)->free)297 if (((stress_t *)item)->free) 298 298 free(item); 299 299 else 300 ((stress_t *)item)->deleted = true;300 ((stress_t *)item)->deleted = true; 301 301 } 302 302 … … 335 335 size_t key = (i << 8) + work->id; 336 336 337 if (1 != cht_remove_key(work->h, (void *)key)) {337 if (1 != cht_remove_key(work->h, (void *)key)) { 338 338 TPRINTF("Err: Failed to remove inserted item\n"); 339 339 goto failed; … … 357 357 for (size_t i = 0; i < work->wave_elems; ++i) { 358 358 size_t key = (i << 8) + work->id; 359 cht_remove_key(work->h, (void *)key);359 cht_remove_key(work->h, (void *)key); 360 360 } 361 361 } … … 392 392 rcu_read_unlock(); 393 393 } else { 394 void *key = (void *)work->elem[elem_idx].key;394 void *key = (void *)work->elem[elem_idx].key; 395 395 if (1 != cht_remove_key(work->h, key)) { 396 396 TPRINTF("Err: did not rm the key\n"); … … 406 406 cht_link_t *dup; 407 407 if (!cht_insert_unique(work->h, &work->elem[elem_idx].link, 408 &dup)) {408 &dup)) { 409 409 TPRINTF("Err: already inserted\n"); 410 410 work->failed = true; … … 420 420 rcu_read_lock(); 421 421 cht_link_t *item = 422 cht_find(work->h, (void*)work->elem[elem_idx].key);422 cht_find(work->h, (void *)work->elem[elem_idx].key); 423 423 rcu_read_unlock(); 424 424 … … 444 444 /* Remove anything we may have inserted. */ 445 445 for (size_t i = 0; i < work->elem_cnt; ++i) { 446 void *key = (void *) work->elem[i].key;446 void *key = (void *) work->elem[i].key; 447 447 cht_remove_key(work->h, key); 448 448 } … … 469 469 470 470 /* Alloc hash table items. */ 471 size_t size = item_cnt * sizeof(stress_t) + work_cnt * sizeof(stress_work_t) 472 +sizeof(int);471 size_t size = item_cnt * sizeof(stress_t) + work_cnt * sizeof(stress_work_t) + 472 sizeof(int); 473 473 474 474 TPRINTF("Alloc and init table items. \n"); … … 482 482 stress_t *pitem = p + work_cnt * sizeof(stress_work_t); 483 483 stress_work_t *pwork = p; 484 int *pstop = (int *)(pitem + item_cnt);484 int *pstop = (int *)(pitem + item_cnt); 485 485 486 486 *pstop = 0; … … 517 517 518 518 TPRINTF("Running %zu ins/del/find stress threads + %zu resizers.\n", 519 op_thread_cnt, resize_thread_cnt);519 op_thread_cnt, resize_thread_cnt); 520 520 521 521 /* Create and run threads. */ -
kernel/test/synch/rcu1.c
r76d0981d r3bacee1 78 78 } 79 79 80 static void run_thread(size_t k, void (*func)(void *), void *arg)80 static void run_thread(size_t k, void (*func)(void *), void *arg) 81 81 { 82 82 assert(thread[k] == NULL); 83 83 84 84 thread[k] = thread_create(func, arg, TASK, THREAD_FLAG_NONE, 85 "test-rcu-thread");86 87 if (thread[k]) {85 "test-rcu-thread"); 86 87 if (thread[k]) { 88 88 /* Distribute evenly. */ 89 89 thread_wire(thread[k], &cpus[k % config.cpu_active]); … … 92 92 } 93 93 94 static void run_all(void (*func)(void *))94 static void run_all(void (*func)(void *)) 95 95 { 96 96 size_t thread_cnt = get_thread_cnt(); … … 127 127 } 128 128 129 static void run_one(void (*func)(void *), void *arg)129 static void run_one(void (*func)(void *), void *arg) 130 130 { 131 131 assert(one_idx < MAX_THREADS); … … 179 179 static bool do_nop_readers(void) 180 180 { 181 size_t seq[MAX_THREADS] = { 0};181 size_t seq[MAX_THREADS] = { 0 }; 182 182 get_seq(100, 100000, get_thread_cnt(), seq); 183 183 … … 185 185 186 186 for (size_t k = 0; k < get_thread_cnt(); ++k) 187 run_one(nop_reader, (void *)seq[k]);187 run_one(nop_reader, (void *)seq[k]); 188 188 189 189 TPRINTF("\nJoining %zu no-op readers\n", get_thread_cnt()); … … 220 220 static bool do_long_readers(void) 221 221 { 222 size_t seq[MAX_THREADS] = { 0};222 size_t seq[MAX_THREADS] = { 0 }; 223 223 get_seq(10, 1000 * 1000, get_thread_cnt(), seq); 224 224 225 225 TPRINTF("\nRun %zu thr: repeat long reader sections, will preempt, no cbs.\n", 226 get_thread_cnt());226 get_thread_cnt()); 227 227 228 228 for (size_t k = 0; k < get_thread_cnt(); ++k) 229 run_one(long_reader, (void *)seq[k]);229 run_one(long_reader, (void *)seq[k]); 230 230 231 231 TPRINTF("\nJoining %zu readers with long reader sections.\n", get_thread_cnt()); … … 238 238 239 239 240 static atomic_t nop_callbacks_cnt = { 0};240 static atomic_t nop_callbacks_cnt = { 0 }; 241 241 /* Must be even. */ 242 242 static const int nop_updater_iters = 10000; … … 250 250 static void nop_updater(void *arg) 251 251 { 252 for (int i = 0; i < nop_updater_iters; i += 2) {252 for (int i = 0; i < nop_updater_iters; i += 2) { 253 253 rcu_item_t *a = malloc(sizeof(rcu_item_t), FRAME_ATOMIC); 254 254 rcu_item_t *b = malloc(sizeof(rcu_item_t), FRAME_ATOMIC); … … 274 274 275 275 TPRINTF("\nRun %zu thr: post %zu no-op callbacks (%zu B used), no readers.\n", 276 get_thread_cnt(), exp_cnt, max_used_mem);276 get_thread_cnt(), exp_cnt, max_used_mem); 277 277 278 278 run_all(nop_updater); … … 303 303 static void one_cb_done(rcu_item_t *item) 304 304 { 305 assert( ((item_w_cookie_t *)item)->cookie == magic_cookie);305 assert(((item_w_cookie_t *)item)->cookie == magic_cookie); 306 306 one_cb_is_done = 1; 307 307 TPRINTF("Callback()\n"); … … 367 367 static errno_t seq_test_result = EOK; 368 368 369 static atomic_t cur_time = { 1};370 static atomic_count_t max_upd_done_time = { 0};369 static atomic_t cur_time = { 1 }; 370 static atomic_count_t max_upd_done_time = { 0 }; 371 371 372 372 static void seq_cb(rcu_item_t *rcu_item) … … 392 392 */ 393 393 #ifndef KARCH_riscv64 394 seq_work_t *work = (seq_work_t *)arg;394 seq_work_t *work = (seq_work_t *)arg; 395 395 396 396 /* Alternate between reader and updater roles. */ … … 401 401 atomic_count_t start_time = atomic_postinc(&cur_time); 402 402 403 for (volatile size_t d = 0; d < 10 * i; ++d ){403 for (volatile size_t d = 0; d < 10 * i; ++d) { 404 404 /* no-op */ 405 405 } … … 452 452 const size_t iters = 100; 453 453 const size_t total_cnt = 1000; 454 size_t read_cnt[MAX_THREADS] = { 0};454 size_t read_cnt[MAX_THREADS] = { 0 }; 455 455 seq_work_t item[MAX_THREADS]; 456 456 … … 476 476 477 477 TPRINTF("\nRun %zu th: check callback completion time in readers. " 478 "%zu callbacks total (max %" PRIu64 " %s used). Be patient.\n",479 get_thread_cnt(), total_cbs, mem_units, mem_suffix);478 "%zu callbacks total (max %" PRIu64 " %s used). Be patient.\n", 479 get_thread_cnt(), total_cbs, mem_units, mem_suffix); 480 480 481 481 for (size_t i = 0; i < get_thread_cnt(); ++i) { … … 500 500 static void reader_unlocked(rcu_item_t *item) 501 501 { 502 exited_t *p = (exited_t *)item;502 exited_t *p = (exited_t *)item; 503 503 p->exited = true; 504 504 } … … 511 511 rcu_read_unlock(); 512 512 513 rcu_call((rcu_item_t *)arg, reader_unlocked);513 rcu_call((rcu_item_t *)arg, reader_unlocked); 514 514 515 515 rcu_read_lock(); … … 566 566 static void preempted_reader_prev(void *arg) 567 567 { 568 preempt_t *p = (preempt_t *)arg;568 preempt_t *p = (preempt_t *)arg; 569 569 assert(!p->e.exited); 570 570 … … 586 586 static void preempted_reader_inside_cur(void *arg) 587 587 { 588 preempt_t *p = (preempt_t *)arg;588 preempt_t *p = (preempt_t *)arg; 589 589 assert(!p->e.exited); 590 590 … … 611 611 static void preempted_reader_cur(void *arg) 612 612 { 613 preempt_t *p = (preempt_t *)arg;613 preempt_t *p = (preempt_t *)arg; 614 614 assert(!p->e.exited); 615 615 … … 633 633 static void preempted_reader_next1(void *arg) 634 634 { 635 preempt_t *p = (preempt_t *)arg;635 preempt_t *p = (preempt_t *)arg; 636 636 assert(!p->e.exited); 637 637 … … 655 655 static void preempted_reader_next2(void *arg) 656 656 { 657 preempt_t *p = (preempt_t *)arg;657 preempt_t *p = (preempt_t *)arg; 658 658 assert(!p->e.exited); 659 659 … … 684 684 685 685 686 static bool do_one_reader_preempt(void (*f)(void *), const char *err)686 static bool do_one_reader_preempt(void (*f)(void *), const char *err) 687 687 { 688 688 preempt_t *p = malloc(sizeof(preempt_t), FRAME_ATOMIC); … … 719 719 720 720 ok = do_one_reader_preempt(preempted_reader_prev, 721 "Err: preempted_reader_prev()\n");721 "Err: preempted_reader_prev()\n"); 722 722 success = success && ok; 723 723 724 724 ok = do_one_reader_preempt(preempted_reader_inside_cur, 725 "Err: preempted_reader_inside_cur()\n");725 "Err: preempted_reader_inside_cur()\n"); 726 726 success = success && ok; 727 727 728 728 ok = do_one_reader_preempt(preempted_reader_cur, 729 "Err: preempted_reader_cur()\n");729 "Err: preempted_reader_cur()\n"); 730 730 success = success && ok; 731 731 732 732 ok = do_one_reader_preempt(preempted_reader_next1, 733 "Err: preempted_reader_next1()\n");733 "Err: preempted_reader_next1()\n"); 734 734 success = success && ok; 735 735 736 736 ok = do_one_reader_preempt(preempted_reader_next2, 737 "Err: preempted_reader_next2()\n");737 "Err: preempted_reader_next2()\n"); 738 738 success = success && ok; 739 739 … … 860 860 static void stress_reader(void *arg) 861 861 { 862 bool *done = (bool *) arg;862 bool *done = (bool *) arg; 863 863 864 864 while (!*done) { … … 896 896 897 897 /* Print a dot if we make a progress of 1% */ 898 if (s->master && 0 == (i % (s->iters /100)))898 if (s->master && 0 == (i % (s->iters / 100))) 899 899 TPRINTF("."); 900 900 } … … 921 921 922 922 TPRINTF("\nStress: Run %zu nop-readers and %zu updaters. %zu callbacks" 923 " total (max %" PRIu64 " %s used). Be very patient.\n",924 reader_cnt, updater_cnt, exp_upd_calls, mem_units, mem_suffix);923 " total (max %" PRIu64 " %s used). Be very patient.\n", 924 reader_cnt, updater_cnt, exp_upd_calls, mem_units, mem_suffix); 925 925 926 926 for (size_t k = 0; k < reader_cnt; ++k) { … … 961 961 --e->count_down; 962 962 963 if (0 == (e->count_down % (e->total_cnt /100))) {963 if (0 == (e->count_down % (e->total_cnt / 100))) { 964 964 TPRINTF("*"); 965 965 } … … 1046 1046 if (ok) { 1047 1047 TPRINTF("\nSubtest %s() ok (GPs: %" PRIu64 ").\n", 1048 test_func[i].desc, delta_gps);1048 test_func[i].desc, delta_gps); 1049 1049 } else { 1050 1050 TPRINTF("\nFailed: %s(). Pausing for 5 secs.\n", test_func[i].desc); -
kernel/test/synch/workq-test-core.h
r76d0981d r3bacee1 67 67 { 68 68 unsigned n = (unsigned)num; 69 return (n != 0) && 0 == (n & (n -1));70 } 71 72 static test_work_t * create_child(test_work_t *work)69 return (n != 0) && 0 == (n & (n - 1)); 70 } 71 72 static test_work_t *create_child(test_work_t *work) 73 73 { 74 74 test_work_t *child = malloc(sizeof(test_work_t), 0); … … 168 168 169 169 TPRINTF("waves: %d, count_down: %d, total expected calls: %zu\n", 170 WAVES, COUNT, exp_call_cnt * WAVES);170 WAVES, COUNT, exp_call_cnt * WAVES); 171 171 172 172 … … 179 179 180 180 for (int i = 0; i < WAVES; ++i) { 181 while (atomic_get(&call_cnt[i]) < exp_call_cnt 182 &&sleep_cnt < max_sleep_cnt) {181 while (atomic_get(&call_cnt[i]) < exp_call_cnt && 182 sleep_cnt < max_sleep_cnt) { 183 183 TPRINTF("."); 184 184 thread_usleep(MAIN_POLL_SLEEP_MS * 1000); … … 192 192 if (atomic_get(&call_cnt[i]) == exp_call_cnt) { 193 193 TPRINTF("Ok: %" PRIua " calls in wave %d, as expected.\n", 194 atomic_get(&call_cnt[i]), i);194 atomic_get(&call_cnt[i]), i); 195 195 } else { 196 196 success = false; 197 197 TPRINTF("Error: %" PRIua " calls in wave %d, but %zu expected.\n", 198 atomic_get(&call_cnt[i]), i, exp_call_cnt);198 atomic_get(&call_cnt[i]), i, exp_call_cnt); 199 199 } 200 200 }
Note:
See TracChangeset
for help on using the changeset viewer.
