Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Clock / Timer
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
HORINOUCHI Masato
December 15, 2015
Technology
170
0
Share
Clock / Timer
社内LT大会 0x64物語 #03 OS Kernel 資料
HORINOUCHI Masato
December 15, 2015
More Decks by HORINOUCHI Masato
See All by HORINOUCHI Masato
balenaCloud
thermes
0
85
Church Numerals
thermes
0
51
CPS & CTO
thermes
0
250
FM synthesis
thermes
0
37
A440
thermes
0
64
Inside mml2wav.rb
thermes
0
87
Scheme Interpreter in Ruby
thermes
0
71
Hash Tree
thermes
0
79
POSIX Threads
thermes
0
57
Other Decks in Technology
See All in Technology
(きっとたぶん)人材育成や教育のような何かの話
sejima
0
740
CyberAgent YJC Connect
shimaf4979
1
180
Gaussian Splattingの実用化 - 映像制作への展開
gpuunite_official
0
180
生成AI時代に信頼性をどう保ち続けるか - Policy as Code の実践
akitok_
1
360
SLI/SLO、「完全に理解した」から「チョットデキル」へ
maruloop
5
480
可視化から活用へ — Mesh化・Segmentation・アライメントの研究動向
gpuunite_official
0
200
AI 時代の Platform Engineering
recruitengineers
PRO
1
190
AIエージェントの支払い基盤 AgentCore Payments概要
kmiya84377
2
180
How to learn AWS Well-Architected with AWS BuilderCards: Security Edition
coosuke
PRO
0
140
試作とデモンストレーション / Prototyping and Demonstrations
ks91
PRO
0
200
Terragrunt x Snowflake + dbt で作るマルチテナントなデータ基盤構築プラットフォーム
gak_t12
0
140
ボトムアップ限界を越える - 20チームを束る "Drive Map" / Beyond Bottom-Up: A 'Drive Map' for 20 Teams
kaonavi
0
210
Featured
See All Featured
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
200
Prompt Engineering for Job Search
mfonobong
0
300
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
390
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
550
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
A Soul's Torment
seathinner
6
2.8k
Done Done
chrislema
186
16k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
140
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.8k
The Pragmatic Product Professional
lauravandoore
37
7.3k
Transcript
Clock / Timer 2015/12/15 0x64 Tales #03 OS Kernel Livesense
Inc. HORINOUCHI Masato
Linux Kernel Clock େผ͢ΔͱҎԼͷ 2ͭʹ͚ΒΕΔɻ • Hardware Clock • ͦͷ໊ͷ௨ΓϋʔυΣΞ্ʹ͋Δ
Clock σόΠεɻ • System Clock • Linux Kernel ෦ʹ͋Δ Clock Ͱشൃੑɻ
Linux࣌ࠁཧͷΈͱઃఆ ͔ΒҾ༻
HW Clock • Real&me Clock (RTC), BIOS Clock, CMOS Clock
ͱݺΕΔɻ • ҰൠతʹόοςϦʔόοΫΞοϓ͕ߦͳΘΕΔɻ • ిݯ͕Ε͍ͯͯόοςϦʔίϯσϯαʔʹΑΓۦಈɻ • &mezone Λҙࣝ͠ͳ͍ɻUTC ͔ local&me ͔Θ͔Βͳ͍ɻ • Windows ڥ local&me ͱͯ͠ɺLinux ڥ UTC ͱͯ͠ ಈ࡞͢ΔͨΊɺJST-9 ڥͩͱ 9࣌ؒͷζϨ͕ൃੜ͢Δɻ
System Clock • Linux Kernel ෦ͷϝϞϦʔͰอ͍࣋ͯ͠ΔɻͳͷͰشൃੑɻ • 2ͭͷσʔλΛ͍࣋ͬͯΔɻ • x-me:
UNIX Epoch (1970/01/01 00:00:00 UTC) ͔Βͷඵ • jiffies: ݱࡏඵ͔Βͷܦաφϊඵ • UTC Ͱಈ࡞͢Δɻ
Interval Timer • ϋʔυΣΞʹΑΓׂΓࠐΈΛൃੜͤ͞ΔσόΠεɻ • ׂΓࠐΈൃੜ͢Δʹ jiffies Λ૿͍ͯ͘͠ɻ • Ұൠతͳ
Linux Kernel Ͱ 1,000Hz (1ms) ຖʹׂΓࠐΈൃ ੜɻ • jiffies ͷ૿ՃΛ x7me ʹө͍ͯ͘͠ɻ
HW Clock ʹΞΫηε • hwclock ͱ͍͏πʔϧͰΞΫηεͰ͖Δɻ • hwclock /etc/adj/me
ΛΈͯ UTC ͔ local/me ͔Λผɻ $ sudo hwclock --show --localtime 201512݄15 08࣌0442ඵ .785058 seconds $ cat /etc/adjtime 0.000000 1450089054 0.000000 1450089054 UTC
HW Clock ͱ System Clock ͷؔ • SysVinit (Upstart) ͷ߹
• Ubuntu Ͱ /etc/init.d/hwclock.sh Ͱ OS ىಈ/ऴྃ ࣌ʹಉظɻ • CentOS 6 Ͱ /etc/rc.d/init.d/halt Ͱ OS ऴྃ࣌ʹ ಉظɻ • ىಈ࣌Ͳ͏͍ͯ͠Δͷ͔ͪΐͬͱௐ͚ͨͲෆ໌…ɻ
Systemd Ͱ RTC ʹΞΫηε • "medatectl ͱ͍͏πʔϧͰΞΫηεͰ͖Δɻ $ timedatectl Local
time: Ր 2015-12-15 17:06:22 JST Universal time: Ր 2015-12-15 08:06:22 UTC RTC time: Ր 2015-12-15 08:06:20 Time zone: Asia/Tokyo (JST, +0900) Network time on: yes NTP synchronized: yes RTC in local TZ: no
Raspberry Pi • ࣮ RTC Λࡌ͍ͯ͠ͳ͍ɻ • ͚Ͳࣗ࡞͢Δऀɻ • RaspberryPiʹRTCϞδϡʔϧΛࡌͯ͠ɺϋʔυΣΞىಈ
࣌ʹ࣌ࠁΛ߹ΘͤΔ
Tickless Kernel • ϋʔυΣΞʹΑΓ CPU ʹׂΓࠐΈൃੜͤ͞Δͱిྗফඅʹݒ ೦ɻ • ࣌ؒͷߋ৽ΛఆظతͳׂΓࠐΈͰͳ͘ Clock
Source Λࢀর͢ Δ͜ͱʹɻ • ͜ΕʹΑΓ CPU ͕লిྗϞʔυͰ͍ΒΕΔ࣌ؒΛ͘͢Δ ͜ͱ͕Մೳʹɻ
Clock Source ओʹҎԼͷͷ͕͋Δɻ্ʹ͋Δํ͕ΞΫηείετ͕͍ɻ • kvm-clock • Time Stamp Counter (TSC)
• High Precision Event Timer (HPET) • ACPI Power Management Timer (ACPI_PM) • Programmable Interval Timer (PIT) • Real Time Clock (RTC)
RHEL6ͷ&ckless kernel ͔ΒҾ༻
Clock Source ΛௐΔ • VirtualBox 5.0.10 (४ԾԽΠϯλʔϑΣʔε KVM) • Ubuntu
15.10 64bit + Guest Add@ons $ uname -a Linux ubuntu 4.2.0-19-generic #23-Ubuntu SMP Wed Nov 11 11:39:30 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux $ cat /sys/devices/system/clocksource/clocksource0/available_clocksource kvm-clock tsc acpi_pm $ cat /sys/devices/system/clocksource/clocksource0/current_clocksource kvm-clock
Clock Source ͷΛܭଌ ݩίʔυ1 Λվมͯ͠ 10,000,000 ճ࣮ߦɻ #include <sys/time.h> #include
<stdio.h> int main() { struct timeval tv; for (int i=0; i<10000000; i++) { int r = gettimeofday(&tv, 0); if (r < 0) { perror("gettimeofday"); return 1; } } return 0; } 1 VirtualBox 5 Ͱར༻Մೳʹͳͬͨ Paravirtualiza1on ػೳ kvmclock Λ͏ ͔ΒҾ༻ɻ
ܭଌͯ͠ΈΔ ͜Μͳ shell script ʹͯ͠Έͨɻ #! /bin/zsh # kvm-clock sudo
sh -c "echo kvm-clock > /sys/devices/system/clocksource/clocksource0/current_clocksource" cat /sys/devices/system/clocksource/clocksource0/current_clocksource time ./t # tsc sudo sh -c "echo tsc > /sys/devices/system/clocksource/clocksource0/current_clocksource" cat /sys/devices/system/clocksource/clocksource0/current_clocksource time ./t # acpi_pm sudo sh -c "echo acpi_pm > /sys/devices/system/clocksource/clocksource0/current_clocksource" cat /sys/devices/system/clocksource/clocksource0/current_clocksource time ./t
Clock Source ߟ • kvm-clock ΑΓ TSC ͷํ͕ 2ഒ΄Ͳ͍ɻ •
͕ɺVM ͩͱ TSC ͷ͕ո͍͠έʔεଟͦ͏ɻ • ͳͷͰૉʹ kvm-clock Λ͏ͷ͕ྑͦ͞͏ɻ • acpi_pm ेഒ(30ʙ70ഒ)͍ɻ • ͔͠γεςϜίʔϧ͠·͘Γ system ͍࣌ؒ·͘Γɻ
·ͱΊ • Linux Kernel ͷ Clock / Timer पΓྺ࢙తܦҢʹΑΓෳࡶɻ •
Clock / Timer ͷղ૾ਫ਼্͕͍ͬͯΔɻ • Ҏલ VM ͩͱ Clock ζϨ·ͬͨ͘ͷ͕ͩɺ͜ͷลղܾ͠ ͖͍ͯͯΔɻ • ͱ͍͑݁ہ Guest OS Ͱ ntp ͏ͷ͕ྑ͍༷ → KVM ʹ͓͍ͯ ϗετͱήετͷ࣌ؒཧNTPΛ༻͍Δ͖͔ʁ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠