# 2025q1 Homework5 (assessment) contributed by < [otischung](https://github.com/otischung) > ## [因為自動飲料機而延畢的那一年](https://www.opasschang.com/docs/the-story-of-auto-beverage-machine-1) 心得 這堂課給我的最大提醒是:要多想、多思考真實世界的問題。 我們經常會以消費者的心態去看待一項事物,總是覺得我們「花錢了」,就應該得到我們想要的東西,總覺得這些事物好像「本該如此」,但這所謂的「本該如此」,是前人花費多少心力完成的呢?為什麼手機可以上網?為什麼原子筆可以一直寫,寫到沒水為止?姑且先不提 10 年前的多核手機就已經有多複雜,就是請我自己開發一隻價值 10 元的原子筆,我都很難做到。 課程在 [2025.05.06 問答簡記](https://hackmd.io/8rwu2EOaQwW7AzjJOFK-gw) 中提到 long-tailed distribution 與 subexponential distribution,我真的沒有印象之前大學學機率統計的時候有學過,所以我特別搜尋了大學時期的教材 [Fundamentals of Probability with Stochastic Processes](https://www.tenlong.com.tw/products/9781498755092),這裡只有在 Ch6.3 的習題中提到 Pareto random variable,並未正式介紹。 但是,難道大學沒有學過,就真的不用學嗎? - PELT 被應用於排程器中,詳見 [2025.05.06 問答簡記](https://hackmd.io/8rwu2EOaQwW7AzjJOFK-gw#%E4%BB%A5-PELT-%E8%BF%BD%E8%B9%A4-CPU-%E8%B2%A0%E8%BC%89) - 財富、亮度、強度值取對數後,會呈現均勻分佈,且遵循 Benford's law - 有顯著的機率產生極大的樣本 - 已知此人存款有 1M,那麼他的實際總資產有 10M 的機率很大 - Power law / 二八定律 - 大小排名前 20% 的樣本會佔據所有樣本總和 80% 以上 - 當變化量正比於之前的總量時,那麼就會出現重尾分佈 - 有錢人的財富依賴乘積,也就是投資,而投資是看收益率的,投資收益正比於投入本金 - 人類身高、地區溫度...等高斯分佈不滿足取對數後均勻分佈 - 此分佈通常有界限且聚集,產生極大樣本的機率極低 - 已知世界紀錄最高身高 Robert Pershing Wadlow 有 272cm,你不會覺得有人身高 300cm - 已知世界紀錄最高地表溫度 盧特沙漠 測得 70.7 攝氏度,你不會覺得有一個地區溫度 100 攝氏度 - [【漫士】世界是对数的……吗?为什么?](https://youtu.be/AcGOrZNKUg8?si=Z3ZP8QHxpEUE-Pd1) - ![Screenshot_20250525_172256](https://hackmd.io/_uploads/HycWfPeMge.jpg) - Gaussian Distribution - 擲 1000 次硬幣,正面為 1,反面為 0,計算從 0 開始之總和 - 得到中心 500,左右對稱的分佈 - 中央極限定理 - Log-Normal Distribution - 擲 1000 次硬幣,正面 \*2,反面 / 2,計算從 1 開始之乘積 - 此分佈明顯有偏斜,而且有一些非常大的樣本存在 - 在對數座標下,此分佈會變成一個常態分佈 - $\ln(x_1 \times x_2) = \ln x_1 + \ln x_2$ 我們真的需要正視這些應用,就算裡面的基礎知識已經忘記,或是像我對於上述的例子一樣完全沒有學過,也沒有關係,從已知應用場合中學習,更加有趣也更加能記得,也期待之後繼續發現更多數學在生活中的應用。 ## Project Goal - The details of the task descriptions are in [this page](https://hackmd.io/@sysprog/BkHQfVYWgg) - Enable the KVM host to run on the Raspberry Pi 4 and/or 5, or the NVIDIA Jetson Orin Nano, allowing it to load a Linux guest. - Address and resolve issues involving ARM GIC (Generic Interrupt Controller), VirtIO, and VirtIO-net. Read the [KVM](https://hackmd.io/@sysprog/linux-kvm) and take note of any questions, especially those related to ARM64. ## Questions 1. Docker Docker uses Docker VM/Engine as the runtime of the containers. To enable the Docker Engine in Windows OS, we have to enable Windows Hyper-V to use Docker Engine. :::info Is Docker a type-2 hypervisor? ::: :::info What is the difference between docker and type-2 hypervisor? (Namespace?) ::: ## Development Record ## Note [Linux KVM Initialization and Configuration Process](https://hackmd.io/@otischung/kvm-init) This is the note for the YouTube tutorial. ### Introduction of the Virtual Machine There are 2 types of the hypervisors. 1. Type-1 Hypervisor: The virtualization manager is run on the hardware directly. The most well-known example is Xen project hypervisor. 2. Type-2 Hypervisor: KVM, which we want to discuss here, is a type-2 hypervisor. There are a general-purpose operating system, such as linux, on which the hypervisor runs. KVM is a kernel module in Linux system. After inserting the module, users can utilize KVM to create a series of virtual machines. KVM is not a virtual machine, instead, it is the **infrastructure** of virtual machine. The operation of KVM relies on hardware virtualization support, such as Intel VT, AMD-V. The OS runs on the hypervisor is called guest OS. Guest OS may not have a real OS. For instance, Bare Metal System. There have many benefits for server virtualization: 1. Workload consolidation 2. Legacy OS support 3. Instant Provisioning 4. Migration ### Type-1 Hypervisor The "Domain 0" is used to resolve the device virtualization. It contains serveral hardware drivers. The other guest OS with "Domain U" uses the hardware using *frontend driver*, which commumicates with the *backend driver* in "Domain 0". Dispite Xen's extraordinary performance, and the fact that Xen-based VMs are still offererd by AWS EC2, Xen can not fully leverage the latest techinologies. All device drivers must be rewritten to match the requirements of "Domain 0". Therefore, AWS EC2 has adopted KVM as its newer solution, as KVM can more easily keep pace with Linux kernel development. ### KVM Features - KSM (Kernel Same-Page Merge) - There may have multiple instances of the same OS version and user programs across different guest OS. - As a result, KSM makes multiple virtual pages point to a physical page. ### KVM Philosophy - Reuse the Linux code as much as possible. - The Linux scheduler is responsible for scheduling a virtual CPU, as it is a normal thread. - [RCU](https://hackmd.io/@sysprog/linux-rcu) improves scalability by allowing reads to occur concurrency with updates. - MMU Virtualization overview ![MMU](https://images.squarespace-cdn.com/content/v1/5e1f51eb1bb1681137ea90b8/1585672028530-KQT55NFF0MV8HKI59V1A/image-asset.png?format=2500w) ### KVM Emulation There are some situations must be emulated without hardware acceleration. - Memory Protection: rw protect shadow pagetable faults. - MMIO on Emulated Devices - Multiple guest OSs use the same monitor. - Windowed mode - Full-screen mode - Normally faster since we can use the physical MMIO. [userfaultfd](https://docs.kernel.org/admin-guide/mm/userfaultfd.html)