Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Clock / Timer
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
HORINOUCHI Masato
December 15, 2015
Technology
190
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
120
Church Numerals
thermes
0
55
CPS & CTO
thermes
0
250
FM synthesis
thermes
0
41
A440
thermes
0
67
Inside mml2wav.rb
thermes
0
93
Scheme Interpreter in Ruby
thermes
0
76
Hash Tree
thermes
0
84
POSIX Threads
thermes
0
59
Other Decks in Technology
See All in Technology
Account Factory for Terraformによる 標準化されたアカウント発行の自動化
pensuke628
0
120
20260929_AmazonGuardDutyの検出通知メールにAWS DevOpsAgentの調査結果を追加する
yhana
1
390
Claude Designがめちゃくちゃ便利なので使ってほしい
diggymo
0
170
AIは爆速なのに、私が詰まっていた話 ― 音声入力と鳴くマスコットでボトルネックを削る
yama3133
0
150
HacobuにおけるFDEとは/登壇資料(戸井田 裕貴)
hacobu
PRO
1
660
20260930_Gemma4_Hands-on
tsho
0
190
AWS FinOps Agent 結局何が得意なの?
siromi
0
230
AIに会社の文脈を理解させる技術~上流工程・非エンジニアにも広げるハーネスエンジニアリング実践~
ochtum
0
200
MCPゲートウェイを作って運用してわかったこと — Agent時代の権限管理の現在地
mtpooh
7
2.4k
「大丈夫そう?」をObservabilityで確かめる
mrmtsu
0
240
キャリアLT今日までそして明日から
kentapapa
1
140
Incremental HTTP
kazuho
5
1.8k
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
580
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
530
Utilizing Notion as your number one productivity tool
mfonobong
4
610
Thoughts on Productivity
jonyablonski
76
5.4k
エンジニアに許された特別な時間の終わり
watany
109
250k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Being A Developer After 40
akosma
91
590k
Why Our Code Smells
bkeepers
PRO
340
58k
Writing Fast Ruby
sferik
630
63k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
530
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
600
Git: the NoSQL Database
bkeepers
PRO
432
67k
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Λ༻͍Δ͖͔ʁ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠