Contenu connexe Similaire à Ruby gvl-improvement at ruby 1.9.3 (20) Ruby gvl-improvement at ruby 1.9.33. •
• IO OS
• usa
Sunday, July 17, 2011
9. What’s GVL
• Global(or Giant) VM Lock
•
• multi thread issue Ruby script
• CPU
• Python
Sunday, July 17, 2011
11. f = false
Thread.new {
....;
f = true
}
Thread.pass until f
Sunday, July 17, 2011
12. GVL design
• Lock
wait (e.g. write)
• lock, unlock
Python, QEMU, Linux
• GVL acquire/release
pthread_mutex_{lock,unlock}
Sunday, July 17, 2011
14. GVL design (cont.)
• ON if (th->interrupt_flag) {
gvl_release();
sched_yield();
gvl_acquire();
}
Sunday, July 17, 2011
15. • OSS while (true) {
( ) lock();
if (hoge) {
unlock();
break;
• }
unlock();
• thread lock rep_nop();
}
hoge=1
lock();
hoge = 1;
unlock();
Sunday, July 17, 2011
17. CPU
cpu1 cpu2
memory core core core core memory
1 2
core core core core
Sunday, July 17, 2011
18. if (th->interrupt_flag) {
gvl_release();
sched_yield();
gvl_acquire();
}
•gvl_release() gvl_acquire() sched_yield()
• sched_yield() yield
Sunday, July 17, 2011
19. sched_yield
• Unix API
http://pubs.opengroup.org/onlinepubs/009695399/
functions/sched_yield.html
int sched_yield(void);
• The sched_yield() function shall force the
running thread to relinquish the processor
until it again becomes the head of its
thread list.
•
Sunday, July 17, 2011
20. Thread
core
Thread Thread Thread
Thread
core
Thread
core
Sunday, July 17, 2011
21. (ry
CPU
Thread
core Thread Thread
Thread
core Thread
Thread
core Thread
Sunday, July 17, 2011
22. Yield!
Ruby
Thread
core Thread
Thread
core Ruby
Thread
Sunday, July 17, 2011
23. thread list
head
Thread
core Ruby
Thread
Thread
core Ruby
Thread
Sunday, July 17, 2011
24. Ruby
Thread
core Thread
Thread
core Ruby
Thread
POSIX
Sunday, July 17, 2011
25. CFS yield
• Linux RHEL5 RHEL6
• RHEL6 (CFS) sched_yield
(RHEL5 knob
• Java
• Linux upstream knob
CPU
Sunday, July 17, 2011
26. • fairness
Sunday, July 17, 2011
27. • fairness
• GVL
gvl_acquire gvl_release
mutex_lock(&lock->lock) mutex_lock(&lock->lock)
cond_wait(&lock->wait) lock->acquired = 0;
lock->acquired = 1; cond_signal(&lock->wait_cond)
// //
cond_signal(&lock->switch_cond) cond_wait(&lock->switch_cond)
mutex_unlock(&lock->lock) mutex_unlock(&lock->lock)
Sunday, July 17, 2011
28. vm_thread_pipe
lmax = 100_000
r, w = IO.pipe
[Thread.new{
lmax.times{
w.write('a')
}
p "w:exit"
}, Thread.new{
lmax.times{
r.read(1)
}
p "r:exit"
}].each{|t| t.join}
Sunday, July 17, 2011
29. (´ ω )
Sunday, July 17, 2011
30. • fairness
• unfairness
• Linux
•
Sunday, July 17, 2011
31. 1.9.3
• 1.9.3 IO GVL release
GVL release
• IO GVL 1.9.2 IO GVL
switch
•
GVL release switch
GVL
•
Sunday, July 17, 2011
32. 1.9.2 1.9.3
2
1.5
1
0.5
0
create_join mutex1 mutex2 mutex3 pass_flood pipe
Sunday, July 17, 2011
33. • 1.9.2
•
•
•
Sunday, July 17, 2011
36. • CPU
• GVL CPU
• Ruby
Sunday, July 17, 2011
Notes de l'éditeur \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n