?? dougan.txt
字號:
Lies, Misdirection, and Real-time
by Cort Dougan and Zwane Mwaikambo
Listing 1: RTLinux Clock Resolution Report
Clock Resolution
271.26 ns, 3 MHz
Listing 2(a): RTLinux context switch time pseudocode.
Thread A
clock_gettime(CLOCK_REALTIME, &start);
pthread_wakeup_np(thread_B);
Thread B
clock_gettime(CLOCK_REALTIME, &end);
pthread_suspend_np(thread_B);
Listing 2(b): RTLinux Context Switch Time Measurement Output
Context Switch - Realtime thread to Realtime thread: (96h 0m 0s test)
48.2 us
Listing 3(a): RTLinux Interrupt Latency Pseudo-Code
ISR
if (start) {
ticks = rtl_getticks() - start;
if (ticks > worst)
worst = ticks;
}
start = rtl_getticks();
rtl_settimer(period);
main()
....
intr_latency = ((worst period) * NSECS_PER_SEC) / rtl_clock_tick_rate;
Listing 3(b): RTLinux Interrupt Latency Output
Interrupt Latency: (96h 0m 0s test)
39.6 us
Listing 4(a): RTLinux Jitter Test
timespec_add_ns(&ts_next_wakeup, PERIOD);
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts_next_wakeup, NULL);
clock_gettime(CLOCK_REALTIME, &ts_wakeup);
Listing 4(b): RTLinux Jitter Output
Scheduling Jitter: (96h 0m 0s test)
88.2 us
Listing 5(a): RTLinux Interrupt Latency Dispatch Test
ISR
start = rtl_getticks();
sem_post(&semaphore);
Thread
sem_wait(&semaphore);
ticks = rtl_getticks() - start;
Listing 5(b): RTLinux Interrupt Latency Dispatch Output
Interrupt Thread Latency - Realtime ISR to Realtime thread (via Semaphore): (46.0 us
Listing 6(a): RTLinux Yield Test
Thread A
clock_gettime(CLOCK_REALTIME, &start);
sched\_yield();
sem_wait(&semaphore);
Thread B
clock_gettime(CLOCK_REALTIME, &end);
sem_post(&sem);
Listing 6(b): RTLinux Yield Output
Thread Yield - Realtime thread to Realtime thread: (96h 0m 0s test)
24.9 us
Listing 7(a): RTLinux Cancel Test
main()
for (i = 0; i < NUM_THREADS; i++)
pthread_create(&threads[i], NULL, test_thread, NULL);
Thread
for (i = 0; i < NUM_THREADS; i++) {
clock_gettime(CLOCK_REALTIME, &start);
pthread_cancel(threads[i]);
pthread_join(threads[i], NULL);
clock_gettime(CLOCK_REALTIME, &end);
}
Listing 7(b): RTLinux Cancel Output
Thread Cancellation:
10051.5 us
Listing 8(a): RTLinux Semaphore Test
Thread A
clock_gettime(CLOCK_REALTIME, &start);
sem_post(&sem);
Thread B
sem_wait(&sem);
clock_gettime(CLOCK_REALTIME, &end);
Listing 8(b): RTLinux Semaphore Output
Semaphore Latency: (96h 0m 0s test)
48.0 us
Listing 9(a): RTLinux Mutex Test
Thread
clock_gettime(CLOCK_REALTIME, &start);
pthread_mutex_unlock(&mutex);
pthread_mutex_lock(&mutex);
clock_gettime(CLOCK_REALTIME, &end);
Listing 9(b): RTLinux Mutex Output
Uncontested Mutex Acquisition: (96h 0m 0s test)
19.2 us
Listing 10(a): RTLinux Contested Mutex Test
Thread A
clock_gettime(CLOCK_REALTIME, &start);
pthread_mutex_lock(&mutex);
sem_post(&start_sem);
pthread_mutex_unlock(&mutex);
Thread B
sem_wait(&start_sem);
pthread_mutex_lock(&mutex);
clock_gettime(CLOCK_REALTIME, &end);
pthread_mutex_unlock(&mutex);
Listing 10(b): RTLinux Contested Mutex Output
Contested Mutex Acquisition: (96h 0m 0s test)
40.6 us
Listing 11(a): RTLinux Priority Inversion Test
Thread A
pthread_suspend_np(thread_A);
clock_gettime(CLOCK_REALTIME, &start);
pthread_mutex_lock(&mutex);
clock_gettime(CLOCK_REALTIME, &end);
Thread B
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond, &mutex);
pthread_wakeup_np(thread_A);
do_something(SLEEP_PERIOD);
pthread_mutex_unlock(&mutex);
Thread C
pthread_cond_signal(&cond);
Listing 11(b): RTLinux Priority Inversion Output
Priority Inversion Recovery: (96h 0m 0s test)
64.0 us
Listing 12(a): RTLinux Conditional Variable Test
Thread A
clock_gettime(CLOCK_REALTIME, &start);
pthread_cond_signal(&cond);
Thread B
pthread_mutex_lock(&cond_mutex);
pthread_cond_wait(&cond, &cond_mutex);
clock_gettime(CLOCK_REALTIME, &end);
pthread_mutex_unlock(&cond_mutex);
Listing 12(b): RTLinux Conditional Variable Output
Pthread Condition Variable Latency: (96h 0m 0s test)
48.0 us
Listing 13(a): RTLinux Spinlock Test
Thread
clock_gettime(CLOCK_REALTIME, &start);
pthread_spin_unlock(&lock);
pthread_spin_lock(&lock);
clock_gettime(CLOCK_REALTIME, &end);
Listing 13(b): RTLinux Spinlock Output
Uncontested Spinlock Acquisition: (96h 0m 0s test)
16.2 us
Listing 14(a): RTLinux Contested Spinlock Test
Thread A
pthread_spin_lock(&lock);
sem_post(&sem);
clock_gettime(CLOCK_REALTIME, &start);
pthread_spin_unlock(&lock);
Thread B
sem_wait(&start_sem);
pthread_spin_lock(&lock);
clock_gettime(CLOCK_REALTIME, &end);
pthread_spin_unlock(&lock);
Listing 14(b): RTLinux Contested Spinlock Output
Contested Spinlock Acquisition: (96h 0m 0s test)
38.5 us
Listing 15(a): RTLinux FIFO test
rtl_no_interrupts(flags);
clock_gettime(clock_REALTIME, &start);
rtf_put(rtl_fds[fd].f_priv, buf, size);
clock_gettime( clock_REALTIME, &end);
clock_gettime(clock_REALTIME, &start);
for (j = 0; j < num_runs; j++)
rtl_write(fd, buf, size);
clock_gettime(clock_REALTIME, &end);
rtl_restore_interrupts(flags);
Listing 15(b): RTLinux FIFO Output
FIFO Latency:
15 NULL rtl_write() took 22.7 us
15 NULL rtl_write() took 17.6 us
15 NULL rtl_write() took 17.3 us
15 NULL rtf_put() took 8.6 us
15 NULL rtf_put() took 8.4 us
15 NULL rtf_put() took 8.6 us
15 128b rtl_write() took 56.6 us
15 128b rtl_write() took 31.7 us
15 128b rtl_write() took 32.5 us
15 128b rtf_put() took 23.8 us
15 128b rtf_put() took 10.0 us
15 128b rtf_put() took 5.1 us
Listing 16(a): RTLinux FIFO Latency
Thread
rtl_no_interrupts(flags);
clock_gettime(CLOCK_REALTIME, &start);
rtl_write(fd, buf, 0);
rtl_restore_interrupts(flags);
Handler
clock_gettime(CLOCK_REALTIME, &end);
Listing 16(b): RTLinux FIFO Latency Output
Testing handler latency...
NULL rtl_write() handler took 8.1 us
NULL rtl_write() handler took 2.9 us
NULL rtl_write() handler took 2.9 us
6
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -