[libdispatch-dev] libdispatch's timer implementation
Mark Heily
mark at heily.com
Fri Dec 25 16:37:55 PST 2009
Mario Schwalbe wrote:
>
> @Mark Heily: In addition to the report, I sent yesterday, I'd like to add:
> On Linux, the application will spin forever, never dispatching any jobs if using
> the global queue, or won't do anything if using the main queue. Looks like
> you're right: EVFILT_USER isn't working properly.
>
> ciao,
> Mario
>
> Appendix I: The test aplication
>
> #include <dispatch/dispatch.h>
> #include <sys/time.h>
> #include <unistd.h>
> #include <stdio.h>
>
> void work(void *context __attribute__((unused)))
> {
> struct timeval now;
> intptr_t n = (intptr_t)context;
>
> gettimeofday(&now, NULL);
> printf("[%lu.%lu] starting work #%zd\n", now.tv_sec, now.tv_usec, n);
>
> sleep(2);
>
> gettimeofday(&now, NULL);
> printf("[%lu.%lu] finished work #%zd\n", now.tv_sec, now.tv_usec, n);
> }
>
> int main(void)
> {
> #if 1
> dispatch_queue_t dispatch_q = dispatch_get_global_queue(0, 0);
> #else
> dispatch_queue_t dispatch_q = dispatch_get_main_queue();
> #endif
>
> printf("=====> before dispatching jobs <=====\n");
> dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_q, (void *)1, work);
> dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_q, (void *)2, work);
> printf("=====> after dispatching jobs <=====\n");
>
> dispatch_main();
> return 0;
> }
>
Mario,
Thanks a lot for contributing this tracing code and the test program. I used
it to find a bug in the EV_RECEIPT implementation in libkqueue. I've
committed the fix as r127.
After fixing this bug, your test program runs successfully. I did observe
the spinning behavior you reported, and agree that this is likely a problem
with libdispatch.
As an additional bonus, all of the libdispatch unit tests appear to work
under Linux now. See below for the output, which includes some "[FAIL]"
notices but the summary indicates that everything was successful.
Regards,
- Mark
$ time make check
make check-TESTS
make[1]: Entering directory `/home/mheily/proj/libdispatch/trunk/testing'
==================================================
[TEST] Dispatch (Public) API
[PID] 24747
==================================================
Actual: 0x6020a0
Expected: 0x6020a0
[PASS] dispatch_get_main_queue
PASS: dispatch_api
==================================================
[TEST] Dispatch C99
[PID] 24765
==================================================
Actual: 0x6020a0
Expected: 0x6020a0
[PASS] dispatch_get_main_queue
PASS: dispatch_c99
==================================================
[TEST] Dispatch Cascade
[PID] 24783
==================================================
maxcount = 5245
*
*
*
*
*
*
*
*
*
*
*
*
* *
* *
** *
*** *
*** *
*** *
*** *
PASS: dispatch_cascade
==================================================
[TEST] Dispatch Debug
[PID] 24857
==================================================
PASS: dispatch_debug
==================================================
[TEST] Dispatch Priority
[PID] 24874
==================================================
LOW: 12
********
DEFAULT: 60
**************************************
HIGH: 120
***************************************************************************
Actual: 192
Expected: 192
[PASS] blocks completed
Actual: 12
Expected: <120
[PASS] high priority precedence
PASS: dispatch_priority
==================================================
[TEST] Dispatch Priority (Set Target Queue)
[PID] 25302
==================================================
Actual: 0x1848010
Expected: 0x1848010
[PASS] q[i]
Actual: 0x1848470
Expected: 0x1848470
[PASS] q[i]
Actual: 0x1848570
Expected: 0x1848570
[PASS] q[i]
LOW: 66
******************************************
DEFAULT: 68
*******************************************
HIGH: 58
*************************************
Actual: 192
Expected: 192
[PASS] blocks completed
Actual: 66
Expected: <58
[FAIL] high priority precedence (dispatch_priority.c:83)
dispatch_priority.c:83
PASS: dispatch_priority2
==================================================
[TEST] Dispatch Starfish
[PID] 25346
==================================================
lap: 10
count: 1000
delta: 1226474575 ns
math: 612.624663 ns / lap
Actual: 612
Expected: <1000
[PASS] Latency
lap: 9
count: 1000
delta: 1147699538 ns
math: 573.276493 ns / lap
Actual: 573
Expected: <1000
[PASS] Latency
lap: 8
count: 1000
delta: 660240103 ns
math: 329.790261 ns / lap
Actual: 329
Expected: <1000
[PASS] Latency
lap: 7
count: 1000
delta: 688541555 ns
math: 343.926851 ns / lap
Actual: 343
Expected: <1000
[PASS] Latency
lap: 6
count: 1000
delta: 809393830 ns
math: 404.292622 ns / lap
Actual: 404
Expected: <1000
[PASS] Latency
lap: 5
count: 1000
delta: 644676636 ns
math: 322.016302 ns / lap
Actual: 322
Expected: <1000
[PASS] Latency
lap: 4
count: 1000
delta: 805161899 ns
math: 402.178771 ns / lap
Actual: 402
Expected: <1000
[PASS] Latency
lap: 3
count: 1000
delta: 680219288 ns
math: 339.769874 ns / lap
Actual: 339
Expected: <1000
[PASS] Latency
lap: 2
count: 1000
delta: 691456997 ns
math: 345.383115 ns / lap
Actual: 345
Expected: <1000
[PASS] Latency
lap: 1
count: 1000
delta: 664566329 ns
math: 331.951213 ns / lap
Actual: 331
Expected: <1000
[PASS] Latency
PASS: dispatch_starfish
==================================================
[TEST] Dispatch Queue Finalizer
[PID] 25626
==================================================
Actual: 0x13d1010
Expected: 0x13d1010
[PASS] dispatch_queue_new
Actual: 0xcccdf07b5815715a
Expected: 0xcccdf07b5815715a
[PASS] finalizer ran
PASS: queue_finalizer
==================
All 8 tests passed
==================
make[1]: Leaving directory `/home/mheily/proj/libdispatch/trunk/testing'
real 1m38.150s
user 2m54.530s
sys 0m3.710s
More information about the libdispatch-dev
mailing list