]>
Commit | Line | Data |
---|---|---|
a0619f9c A |
1 | #include <sys/sysctl.h> |
2 | #include <dispatch/dispatch.h> | |
3 | #include <dispatch/private.h> | |
4 | #include "darwintest_defaults.h" | |
5 | ||
6 | T_DECL(wq_pool_limits, "test overcommit limit") | |
7 | { | |
8 | dispatch_semaphore_t sema = dispatch_semaphore_create(0); | |
9 | dispatch_group_t g = dispatch_group_create(); | |
10 | dispatch_time_t t; | |
11 | uint32_t wq_max_threads, wq_max_constrained_threads; | |
12 | ||
13 | dispatch_block_t b = ^{ | |
14 | dispatch_group_leave(g); | |
15 | dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); | |
16 | }; | |
17 | ||
18 | size_t s = sizeof(uint32_t); | |
19 | sysctlbyname("kern.wq_max_threads", &wq_max_threads, &s, NULL, 0); | |
20 | sysctlbyname("kern.wq_max_constrained_threads", &wq_max_constrained_threads, | |
21 | &s, NULL, 0); | |
22 | ||
23 | for (uint32_t i = 0; i < wq_max_constrained_threads; i++) { | |
24 | dispatch_group_enter(g); | |
25 | dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), b); | |
26 | } | |
27 | ||
28 | t = dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC); | |
29 | T_ASSERT_EQ(dispatch_group_wait(g, t), 0L, | |
30 | "%d constrained threads bringup", wq_max_constrained_threads); | |
31 | ||
32 | dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{ | |
33 | T_ASSERT_FAIL("Should never run"); | |
34 | }); | |
35 | ||
36 | sleep(5); | |
37 | T_PASS("constrained limit looks fine"); | |
38 | ||
39 | for (uint32_t i = wq_max_constrained_threads; i < wq_max_threads; i++) { | |
40 | dispatch_group_enter(g); | |
41 | dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, | |
42 | DISPATCH_QUEUE_OVERCOMMIT), b); | |
43 | } | |
44 | t = dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC); | |
45 | T_ASSERT_EQ(dispatch_group_wait(g, t), 0L, | |
46 | "%d threads bringup", wq_max_threads); | |
47 | ||
48 | ||
49 | dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, | |
50 | DISPATCH_QUEUE_OVERCOMMIT), ^{ | |
51 | T_ASSERT_FAIL("Should never run"); | |
52 | }); | |
53 | ||
54 | sleep(5); | |
55 | T_PASS("thread limit looks fine"); | |
56 | T_END; | |
57 | } |