<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tabriz Gulmammadov on Medium]]></title>
        <description><![CDATA[Stories by Tabriz Gulmammadov on Medium]]></description>
        <link>https://medium.com/@tabriz.gulmammadov?source=rss-23076abc5108------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BmKAjcpTvVHkDRBh33k8SQ.jpeg</url>
            <title>Stories by Tabriz Gulmammadov on Medium</title>
            <link>https://medium.com/@tabriz.gulmammadov?source=rss-23076abc5108------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:44:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tabriz.gulmammadov/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scalability and Maintainability]]></title>
            <link>https://medium.com/@tabriz.gulmammadov/scalability-and-maintainability-7a1b919f4c1a?source=rss-23076abc5108------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a1b919f4c1a</guid>
            <category><![CDATA[tail-latency]]></category>
            <category><![CDATA[performance-metrics]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[maintainability]]></category>
            <dc:creator><![CDATA[Tabriz Gulmammadov]]></dc:creator>
            <pubDate>Thu, 12 Feb 2026 05:20:45 GMT</pubDate>
            <atom:updated>2026-02-12T05:20:45.184Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JHOtn1daBT2jUSeB_MJS5Q.png" /></figure><h3>Building Systems That Grow and Endure</h3><p>In <a href="https://medium.com/@tabriz.gulmammadov/building-reliable-systems-d151fddc6649"><strong>Part 1</strong></a>, we explored <strong>reliability</strong> — building systems that continue working correctly even when things go wrong. But a reliable system that can’t handle growth or becomes impossible to maintain is ultimately doomed to fail.</p><p>Here, we’ll dive into <strong>scalability</strong> and <strong>maintainability</strong> — the two pillars that determine whether your system can grow with demand and evolve with changing requirements.</p><h3>Scalability</h3><p>Your system works great with 10,000 users. But what happens when you reach 100,000? Or 1 million? Scalability is your system’s ability to cope with increased load.</p><p><strong>Important:</strong> Scalability isn’t a binary property. You can’t just label a system as “scalable” or “not scalable.” It’s always about how a system scales under specific growth patterns.</p><p>A system that works today may fail tomorrow due to growth:</p><ul><li>More users</li><li>More requests</li><li>More data</li><li>More features</li></ul><blockquote><strong>Scalability means: How well a system copes with increased load.</strong></blockquote><h3>Describing Load</h3><p>Before talking about scalability, we must describe load using <strong>load parameters</strong>, such as:</p><ul><li>Requests per second</li><li>Reads vs writes</li><li>Active users</li><li>Cache hit rate</li><li>Data volume</li></ul><p>The right metrics depend on your system. Sometimes average cases matter. Sometimes rare but extreme cases dominate performance.</p><h3>Describing Performance</h3><p>There are two key questions:</p><p><strong>1.</strong> What happens to performance if load increases but resources stay the same?</p><p><strong>2.</strong> How many resources are needed to keep performance stable as load increases?</p><h3>Latency vs Response Time</h3><ul><li><strong>Response time</strong> — What the client sees (processing + network + queueing)</li><li><strong>Latency</strong> — Time spent waiting before being handled</li></ul><p>In batch systems, we often care about <strong>throughput</strong>. In online systems, <strong>response time</strong> is usually more important.</p><h3>Why Averages Don’t Tell the Whole Story</h3><p>Many teams report average response times, but this metric is misleading. The arithmetic mean doesn’t tell you how many users actually experienced that delay. A few very slow requests can skew the average significantly.</p><p><strong>Instead, use percentiles.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UBA-ZyCYUS-N4ElmXbsnSA.png" /><figcaption>Percentile charts</figcaption></figure><h3>Percentiles: The Better Metric</h3><p>Sort all response times from fastest to slowest. The percentile tells you what percentage of requests were faster than a given threshold:</p><ul><li><strong>p50 (median)</strong> — 50% of requests are faster than this threshold</li><li><strong>p95</strong>–95% of requests are faster; 5% are slower</li><li><strong>p99</strong>–99% of requests are faster; 1% are slower</li><li><strong>p99.9</strong>–99.9% of requests are faster; only 1 in 1,000 is slower</li></ul><p><strong>Example:</strong> If your p95 is 1.5 seconds, that means 95 out of 100 requests complete in under 1.5 seconds, while 5 out of 100 take 1.5 seconds or more.</p><h3>Why Tail Latencies Matter</h3><p>High percentiles (p95, p99, p999) represent <strong>tail latencies</strong> — the slowest requests. These matter tremendously because:</p><ul><li>They directly affect user experience</li><li>Amazon measures internal service requirements at p99.9, even though it only affects 1 in 1,000 requests</li><li>Customers experiencing slow responses are often your most valuable ones (they’ve made more requests)</li></ul><h3>SLI, SLO, and SLA: Setting Performance Expectations</h3><p>These acronyms are critical for production systems:</p><p><strong>SLI (Service Level Indicator)</strong> — A specific metric used to measure service performance (e.g., response time, error rate)</p><p><strong>SLO (Service Level Objective)</strong> — Target values for SLIs that define acceptable performance (e.g., p99 &lt; 1 second)</p><p><strong>SLA (Service Level Agreement)</strong> — A contract defining expected performance with consequences if not met (e.g., refunds)</p><p><strong>Example SLA:</strong> Service must have median response time &lt; 200ms and p99 &lt; 1 second, with 99.9% uptime. If these targets aren’t met, customers may demand refunds.</p><h3>Queueing, Head-of-Line Blocking, and Tail Amplification</h3><p>Servers can only process a limited number of requests in parallel. If a few requests are slow:</p><ul><li>They block others</li><li>Queueing delays increase</li><li>Tail latencies explode</li></ul><p>This is known as <strong>head-of-line blocking</strong>.</p><p>If a user request depends on multiple backend calls, even small tail delays get amplified — this is <strong>tail latency amplification</strong>.</p><h3>Coping with Load</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rlQBn3G6l2zr9VFMpBlxeg.png" /><figcaption>Scailing approaches</figcaption></figure><p>Two classic approaches:</p><p><strong>Scale up (vertical scaling)</strong> — Use bigger, more powerful machines</p><p><strong>Scale out (horizontal scaling)</strong> — Distribute load across many machines</p><p>Horizontal scaling often uses a <strong>shared-nothing architecture</strong>, where each node is independent.</p><h3>Maintainability</h3><p>Here’s a reality check: <strong>The majority of software costs don’t come from initial development — they come from ongoing maintenance.</strong></p><p>Fixing bugs, investigating failures, adapting to new platforms, modifying for new use cases, repaying technical debt, and adding features all add up over time.</p><p>DDIA highlights three principles:</p><ul><li><strong>Operability</strong> — Make systems easy to run and monitor</li><li><strong>Simplicity</strong> — Reduce complexity so humans can understand the system</li><li><strong>Evolvability</strong> — Make change easy as requirements evolve</li></ul><h3>Operability: Supporting Operations Teams</h3><p>Operations teams keep systems running smoothly. Good operability means making their routine tasks easy so they can focus on high-value activities.</p><h3>Good operability includes:</h3><ul><li>Clear monitoring and observability</li><li>Automation support</li><li>No dependency on single machines</li><li>Good documentation</li><li>Safe defaults with override options</li><li>Predictable behavior</li><li>Controlled self-healing</li></ul><h3>Simplicity: Managing Complexity</h3><p>Small projects can have delightfully simple, expressive code. But as projects grow, they often become complex and difficult to understand. This complexity slows everyone down and increases maintenance costs.</p><h3>Complex systems suffer from:</h3><ul><li>Tight coupling</li><li>Tangled dependencies</li><li>Special-case hacks</li><li>Inconsistent terminology</li><li>Growing state space</li></ul><p>This leads to the dreaded “big ball of mud.”</p><blockquote><strong>Simplicity is not about fewer features — it’s about clear structure.</strong></blockquote><h3>Evolvability: Embracing Change</h3><p>It’s extremely unlikely that your system’s requirements will remain unchanged forever. In fact, they’re almost certain to be in constant flux.</p><h3>Change is inevitable:</h3><ul><li>New features</li><li>New platforms</li><li>Legal constraints</li><li>Growth</li><li>New use cases</li></ul><p><strong>Systems that are easy to change survive. Those that aren’t… don’t.</strong></p><h3>Bringing It All Together</h3><p>Chapter 1 of DDIA doesn’t just introduce concepts — it fundamentally changes how we think about building systems. <strong>Reliability, Scalability, and Maintainability</strong> aren’t separate concerns; they’re deeply interconnected pillars that support everything else.</p><p>When you design for reliability (Part 1), you’re thinking about all the ways things can go wrong and building systems that continue working despite faults.</p><p>When you design for scalability, you’re planning for growth and measuring what matters — not with misleading averages, but with percentiles that reveal the true user experience.</p><p>When you design for maintainability, you’re making life easier for everyone who will work on the system after you — through good operability, simplicity, and evolvability.</p><p>As you work through the rest of DDIA, these principles will come up again and again. They’re not just theory — they’re battle-tested wisdom from years of building and maintaining production systems at scale.</p><h3>Key Takeaways</h3><p><strong>Scalability isn’t a label</strong> — it’s about how your system handles growth. Measure with load parameters and percentiles, not averages.</p><p><strong>Use percentiles (p50, p95, p99) instead of averages</strong> to understand real user experience.</p><p><strong>Tail latencies matter tremendously,</strong> especially for high-value users who make many requests.</p><p><strong>SLIs, SLOs, and SLAs</strong> define performance expectations and consequences — use them to set clear targets.</p><p><strong>Maintainability reduces long-term costs</strong> through good operability, simplicity, and evolvability.</p><p><strong>The majority of software costs come from maintenance,</strong> not initial development — design accordingly.</p><p><strong>Reference</strong></p><p>Kleppmann, Martin. <em>Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems.</em> O’Reilly Media, 2017.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a1b919f4c1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Reliable Systems]]></title>
            <link>https://medium.com/@tabriz.gulmammadov/building-reliable-systems-d151fddc6649?source=rss-23076abc5108------2</link>
            <guid isPermaLink="false">https://medium.com/p/d151fddc6649</guid>
            <category><![CDATA[fault]]></category>
            <category><![CDATA[reliability]]></category>
            <category><![CDATA[failure]]></category>
            <category><![CDATA[fault-tolerance]]></category>
            <category><![CDATA[design-data-intensive]]></category>
            <dc:creator><![CDATA[Tabriz Gulmammadov]]></dc:creator>
            <pubDate>Wed, 11 Feb 2026 05:12:09 GMT</pubDate>
            <atom:updated>2026-02-11T05:12:09.849Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*adiSXLC7LjezTzgTGnGamQ.jpeg" /><figcaption>Building Reliable Systems</figcaption></figure><h3>Understanding Reliability in Data-Intensive Applications</h3><p>When you start reading <em>Designing Data-Intensive Applications</em> (DDIA), one thing becomes obvious very quickly: this book is dense — in a good way. Every chapter is packed with ideas, trade-offs, and real-world lessons.</p><p><a href="https://orkhanhuseyn.medium.com/">A friend of mine</a> once said: “This is one of those books you should read at least once every year.” I agree. Each reread reveals something new, especially as your experience grows.</p><p>In this article, we’ll dive deep into <strong>reliability</strong> — what it means, why it matters, and how to build systems that continue working correctly even when things go wrong.</p><h3>Thinking About Data Systems</h3><p>Most modern applications are <strong>data-intensive</strong>. That means they spend more time storing, retrieving, processing, and moving data than doing complex computations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rAkAQQUnKWnLaBlEFN8gdA.png" /><figcaption>Building blocks of data systems</figcaption></figure><h3>Building blocks of data systems</h3><p>Instead of building everything from scratch, we combine standard building blocks:</p><ul><li><strong>Databases</strong> — store data so it can be found later</li><li><strong>Caches</strong> — remember results of expensive operations</li><li><strong>Search indexes</strong> — search or filter data efficiently</li><li><strong>Stream processing</strong> — send messages asynchronously</li><li><strong>Batch processing</strong> — crunch large volumes of data periodically</li></ul><p>The art of system design is not inventing new components, but connecting these building blocks correctly.</p><p>Across all such systems, DDIA focuses on three fundamental concerns:</p><ul><li><strong>Reliability</strong> — does the system keep working when things go wrong?</li><li><strong>Scalability</strong> — can it handle growth?</li><li><strong>Maintainability</strong> — can humans work with it productively over time?</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T82Cz9VuMiPXkmDPJrnsrw.png" /><figcaption>Three fundamental concerns</figcaption></figure><h3>What is Reliability?</h3><p>Imagine you’re using an ATM to withdraw cash. You expect it to give you the correct amount, accept your legitimate card, and not crash mid-transaction. That’s reliability in action.</p><p>Intuitively, we call a system reliable if it:</p><ul><li>Does what users expect</li><li>Behaves reasonably even when users make mistakes</li><li>Performance stays acceptable under expected load</li><li>Unauthorized access is prevented</li></ul><p><strong>In short: Reliability means continuing to work correctly, even when things go wrong.</strong></p><h3>Faults vs Failures (Important Distinction)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i4sYA7G7eR6zcV-QWEKeHw.png" /><figcaption>Faults vs Failures</figcaption></figure><p>This distinction is critical:</p><p><strong>Fault</strong> — A fault is when one component deviates from its specification.</p><p><em>Example:</em> a disk crashes, a process runs out of memory, a service returns bad data.</p><p><strong>Failure</strong> — A failure is when the system as a whole stops providing the expected service to the user.</p><blockquote><strong><em>👉 Faults are inevitable. Failures are not.</em></strong></blockquote><p>A well-designed system expects faults and is built to tolerate them.</p><h3>Hardware Faults</h3><p>Hard drives crash. RAM becomes faulty. Power grids fail. Network cables get unplugged. With large datacenters, these aren’t hypotheticals — they’re everyday occurrences.</p><p>Consider this: Hard disks have a Mean Time To Failure (MTTF) of 10–50 years. Sounds reliable, right? But in a storage cluster with 10,000 disks, you should expect <strong>one disk to fail every single day</strong>.</p><h3>How do we handle this?</h3><ul><li><strong>Add redundancy:</strong> Dual power supplies, hot-swappable components</li><li><strong>Design for failure:</strong> Assume components will fail and plan accordingly</li><li><strong>Use software fault-tolerance:</strong> Distribute workloads across multiple machines</li></ul><h3>Software Errors (Systematic Faults)</h3><p>Unlike random hardware failures, software errors are often <strong>systematic and correlated</strong>. When they strike, they can bring down multiple components simultaneously — making them far more dangerous.</p><h3>Common examples:</h3><p><strong>A bug that crashes all instances</strong> — Remember <a href="https://hpiers.obspm.fr/eop-pc/earthor/utc/leapsecond.html">the leap second bug on June 30, 2012</a>? It caused many applications to hang simultaneously due to a Linux kernel bug.</p><p><strong>Runaway processes</strong> — A process consuming all available CPU, memory, disk space, or network bandwidth.</p><p><strong>Degraded dependencies</strong> — A service you depend on becomes slow, unresponsive, or returns corrupted data.</p><p><strong>Cascading failures</strong> — A small fault triggers another fault, which triggers more faults.</p><p>These faults are dangerous because they affect many nodes at once.</p><h3>There is no silver bullet, but helpful practices include:</h3><ul><li>Careful reasoning about assumptions</li><li>Test thoroughly (unit → integration → system tests)</li><li>Process isolation</li><li>Letting processes crash and restart</li><li>Monitoring and production observability</li><li>Make recovery fast and easy (rollbacks, recomputation)</li></ul><h3>Human Errors</h3><p><strong>Humans are often the largest source of outages.</strong></p><p>Studies of large internet services found that configuration errors by operators caused more outages than hardware failures. Hardware faults accounted for only 10–25% of outages, while human errors dominated.</p><p>We can’t eliminate humans from the equation (nor should we want to), but we can design systems that minimize the impact of human mistakes.</p><h3>Good systems assume humans will make mistakes and design accordingly:</h3><ul><li>Make the right thing easy, and the wrong thing hard</li><li>Provide safe sandbox environments</li><li>Use strong monitoring and telemetry</li><li>Invest in training and good operational practices</li></ul><blockquote><strong>A reliable system is not one where humans never make mistakes, but one where mistakes are survivable.</strong></blockquote><h3>Key Takeaways</h3><p><strong>Reliability means continuing to work correctly even when faults occur.</strong> Design for fault tolerance, not fault prevention.</p><p><strong>Faults are inevitable. Failures are not.</strong> Build systems that expect components to fail and can tolerate those failures.</p><p><strong>Hardware faults are random but manageable</strong> through redundancy and distributed architectures.</p><p><strong>Software errors are systematic and correlated,</strong> making them more dangerous. Combat them with thorough testing, monitoring, and quick recovery.</p><p><strong>Human errors cause more outages than hardware failures.</strong> Design systems that minimize the impact of human mistakes.</p><h3>What’s Next?</h3><p>In <strong>Part 2</strong>, we’ll explore <strong>Scalability</strong> and <strong>Maintainability</strong> — understanding how systems handle growth and how we can build systems that humans can work with productively over time.</p><p>We’ll dive into load parameters, percentiles vs averages, tail latencies, and why the p99 metric matters more than you might think. We’ll also explore the three principles of maintainable systems: operability, simplicity, and evolvability.</p><p><strong>Reference</strong></p><p>Kleppmann, Martin. <em>Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems.</em> O’Reilly Media, 2017.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d151fddc6649" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Transistors to Logic Gates]]></title>
            <link>https://medium.com/@tabriz.gulmammadov/from-transistors-to-logic-gates-591b7100070b?source=rss-23076abc5108------2</link>
            <guid isPermaLink="false">https://medium.com/p/591b7100070b</guid>
            <category><![CDATA[transistor]]></category>
            <category><![CDATA[binary-decoder]]></category>
            <category><![CDATA[instruction]]></category>
            <category><![CDATA[logic-gates]]></category>
            <category><![CDATA[cpu]]></category>
            <dc:creator><![CDATA[Tabriz Gulmammadov]]></dc:creator>
            <pubDate>Sun, 08 Feb 2026 12:21:04 GMT</pubDate>
            <atom:updated>2026-02-09T05:15:59.284Z</atom:updated>
            <content:encoded><![CDATA[<h3>How Computing Really Begins (From Physical Reality to Logic)</h3><p>Most programming journeys begin with something simple:</p><pre>Hello, World!</pre><p>Then we move on to:</p><ul><li>Addition and subtraction</li><li>Conditions</li><li>Loops</li><li>etc</li></ul><p>For a while, this feels enough.</p><p>But after gaining experience, a deeper curiosity naturally appears:</p><blockquote><strong><em>What actually happens underneath my code?</em></strong><em><br> What does the hardware do when I write </em><em>a + b?</em></blockquote><p>Many developers, including myself, didn’t receive deep, practical education in <strong>computer architecture</strong> or <strong>operating systems</strong> at university. So later, driven by curiosity, I started learning the foundations that ideally should have come <strong>before</strong> high-level programming.</p><p>This article is the first in a series where I’ll try to explore the journey from the most basic hardware component to complex digital systems:</p><pre>Transistors → Logic Gates → Latches → Flip-Flops → Registers → ALU → CPU</pre><p>Today, we focus on the <strong>first two building blocks</strong>:</p><blockquote><strong><em>Transistors</em></strong><em> and </em><strong><em>Logic Gates</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2DHJMO9qFVhfT1WF0mEIUA.png" /><figcaption>Transistors and logic gates</figcaption></figure><h3>1. What Is a Transistor?</h3><p>A <strong>transistor</strong> is an electronic switch — the most fundamental building block of all modern computers. Think of it as a tiny device that can turn electrical current on or off, similar to a light switch in your room.</p><p>A transistor is not magic, and not just an abstract switch. It is a <strong>physical component</strong> where:</p><ul><li>A <strong>small current</strong> decides</li><li>Whether a <strong>larger current</strong> can flow</li></ul><p>This behavior maps perfectly to binary logic:</p><pre>OFF → 0<br>ON  → 1</pre><p>Modern computers are built from <strong>billions of transistors</strong>, all doing this exact job.</p><h3>2. The Three Parts of a Transistor</h3><p>A transistor has <strong>three official terminals</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*wYwhtUtHNmegs_PYMhW3jw.png" /><figcaption>parts of transistor</figcaption></figure><h3>What each part does (conceptually)</h3><p><strong>Base — r</strong>eceives a <strong>small control current</strong></p><p><strong>Collector — s</strong>upplies the <strong>larger current</strong></p><p><strong>Emitter — o</strong>utputs that current</p><h3>Key idea (do not skip this)</h3><blockquote><em>A small current flowing into the </em><strong><em>base</em></strong><em><br>allows a larger current to flow from </em><strong><em>collector to emitter</em></strong></blockquote><p>The base <strong>does not carry the main current</strong>. It <strong>controls</strong> whether that current is allowed to flow.</p><h3>3. Simple Analogy: A Valve 🚰</h3><p>Think of a transistor like a water valve:</p><ul><li><strong>Collector → Emitter</strong> → the pipe</li><li><strong>Base</strong> → the handle</li></ul><p>Turning the handle slightly:</p><ul><li>Opens the valve</li><li>Allows a strong water flow</li></ul><p>No handle movement:</p><ul><li>Valve stays closed</li><li>No flow</li></ul><p>This is why transistors are powerful:<br> 👉 <strong>small signal controls large signal</strong></p><h3>4. From Transistors to Logic</h3><p>A single transistor can represent:</p><ul><li>ON or OFF</li><li>1 or 0</li></ul><p>But <strong>computation begins</strong> when we <strong>combine transistors together</strong>.</p><p>That’s how <strong>logic gates </strong>are<strong> </strong>created.</p><h3>5. What Is a Logic Gate?</h3><p>A <strong>logic gate</strong>:</p><ul><li>Takes one or more <strong>binary inputs</strong></li><li>Produces a <strong>binary output</strong></li><li>Always follows a fixed rule</li></ul><p>Logic gates are built by <strong>connecting transistors in specific patterns</strong>.</p><h3>6. The Fundamental Logic Gates</h3><h3>NOT Gate</h3><p>The simplest gate.</p><pre>Input ──►[ NOT ]──► Output<br><br><br>| Input | Output |<br>|-------|--------|<br>| 0     | 1      |<br>| 1     | 0      |</pre><p>It simply flips the value.</p><h3>AND Gate</h3><p>Output is 1 <strong>only if all inputs are </strong><strong>1</strong>.</p><pre>A ──┐<br>    ├──►[ AND ]──► Output<br>B ──┘<br><br><br>| A | B | Output |<br>| - | - | ------ |<br>| 0 | 0 | 0      |<br>| 0 | 1 | 0      |<br>| 1 | 0 | 0      |<br>| 1 | 1 | 1      |</pre><h3>OR Gate</h3><p>Output is 1 if <strong>at least one input is </strong><strong>1</strong>.</p><pre>A ──┐<br>    ├──►[ OR ]──► Output<br>B ──┘<br><br><br>| A | B | Output |<br>| - | - | ------ |<br>| 0 | 0 | 0      |<br>| 0 | 1 | 1      |<br>| 1 | 0 | 1      |<br>| 1 | 1 | 1      |</pre><h3>XOR Gate (Exclusive OR)</h3><p>Output is 1 <strong>only when inputs are different</strong>.</p><pre>A ──┐<br>    ├──►[ XOR ]──► Output<br>B ──┘<br><br><br>| A | B | Output |<br>| - | - | ------ |<br>| 0 | 0 | 0      |<br>| 0 | 1 | 1      |<br>| 1 | 0 | 1      |<br>| 1 | 1 | 0      |</pre><p>XOR is essential for <strong>binary addition</strong>.</p><h3>NAND Gate (NOT AND)</h3><p>Output is <strong>0 only when both inputs are 1</strong>.<br>In all other cases, output is <strong>1</strong>.</p><pre>A ──┐<br>├──►[ NAND ]──► Output<br>B ──┘<br><br><br>A | B | Output<br>--------------<br>0 | 0 |   1<br>0 | 1 |   1<br>1 | 0 |   1<br>1 | 1 |   0</pre><p>NAND is <strong>functionally complete (</strong>using only NAND gates, we can build every other logic gate<strong>)</strong>, meaning <strong>any digital circuit (</strong>CPU, memory, adders, decoders<strong>) </strong>can be built using only NAND gates.</p><h3>NOR Gate (NOT OR)</h3><p>Output is <strong>1 only when both inputs are 0</strong>.<br>If <strong>any input is 1</strong>, the output becomes <strong>0</strong>.</p><pre>A ──┐<br>├──►[ NOR ]──► Output<br>B ──┘<br><br><br>A | B | Output<br>--------------<br>0 | 0 |   1<br>0 | 1 |   0<br>1 | 0 |   0<br>1 | 1 |   0</pre><p>NOR is also <strong>functionally complete (</strong>means<strong> — </strong>using only NOR gates, we can build every other logic gate<strong>) </strong>and is often used in <strong>control logic and signal inversion (</strong>flipping a signal — 0 becomes 1, 1 becomes 0<strong>)</strong>.</p><p>P.S.: <strong>Control logic</strong> is the part of a digital system that decides <strong>what should happen and when</strong>. It does <strong>not</strong> calculate values like addition or multiplication. Instead, it <strong>controls behavior</strong>. In simple terms:</p><blockquote><strong><em>Control logic decides which parts of the hardware are enabled, disabled, reset, or allowed to proceed.</em></strong></blockquote><p>Control logic answers questions like:</p><ul><li>Should the CPU execute an instruction now?</li><li>Should memory be read or written?</li><li>Should a pipeline stage stall?</li><li>Should the system reset?</li><li>Should a unit be disabled because of an error?</li></ul><p>These decisions are made using <strong>logic gates</strong>, not arithmetic.</p><h3>7. Adding Two Bits: Half Adder</h3><p>Now let’s see how logic gates enable computers to perform arithmetic. We’ll start with the simplest addition circuit: adding two single-bit numbers.</p><p>Binary addition can produce:</p><ul><li><strong>Sum — </strong>The addition result</li><li><strong>Carry — </strong>Overflow to the next position</li></ul><p><strong>Half Adder Truth Table</strong></p><pre>Input A | Input B | Sum (S) | Carry (C)<br>--------|---------|---------|----------<br>   0    |    0    |    0    |    0<br>   0    |    1    |    1    |    0<br>   1    |    0    |    1    |    0<br>   1    |    1    |    0    |    1</pre><p><strong>How to Build It</strong></p><p>Looking at the truth table:</p><ul><li><strong>Sum</strong> behaves like XOR gate (1 when inputs differ)</li><li><strong>Carry</strong> behaves like AND gate (1 only when both inputs are 1)</li></ul><pre>Sum   = A XOR B<br>Carry = A AND B</pre><p><strong>Half Adder Circuit</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*ETLQRQf1VE0Hza_Kk02Ebg.png" /><figcaption>half adder circuit</figcaption></figure><p><strong>Real Example: Adding 1 + 1</strong></p><pre>A = 1, B = 1<br><br>XOR gate: 1 XOR 1 = 0 → Sum = 0<br>AND gate: 1 AND 1 = 1 → Carry = 1<br><br>Result: 10 in binary (2 in decimal) ✓</pre><p>This circuit is called a <strong>Half Adder</strong>.</p><h3>8. Full Adder: Adding with Carry</h3><p>The Half Adder works for single-bit addition, but what about adding numbers with multiple bits? We need to account for the carry from the previous position. This is where the <strong>Full Adder</strong> comes in.</p><blockquote><em>A </em><strong><em>Full Adder is still a 1-bit adder</em></strong><em>, but it is a 1-bit adder </em><strong><em>that can accept a carry from a previous bit</em></strong><em>.</em></blockquote><p>A <strong>Full Adder</strong> adds THREE bits:</p><ol><li><strong>A</strong>: First input bit</li><li><strong>B</strong>: Second input bit</li><li><strong>Cin</strong> (Carry-in): Carry from the previous addition</li></ol><p>It produces:</p><ol><li><strong>Sum</strong>: Addition result</li><li><strong>Cout</strong> (Carry-out): Carry to the next position</li></ol><p><strong>Full Adder Truth Table</strong></p><pre>A | B | Cin | Sum | Cout<br>--|---|-----|-----|-----<br>0 | 0 |  0  |  0  |  0<br>0 | 0 |  1  |  1  |  0<br>0 | 1 |  0  |  1  |  0<br>0 | 1 |  1  |  0  |  1<br>1 | 0 |  0  |  1  |  0<br>1 | 0 |  1  |  0  |  1<br>1 | 1 |  0  |  0  |  1<br>1 | 1 |  1  |  1  |  1</pre><h3>How to Build It</h3><p>We can build a Full Adder using two Half Adders and one OR gate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*Q6KNnKh87PYMbs8M8NloVQ.png" /><figcaption>full adder circuit</figcaption></figure><h3>Step-by-Step Example:</h3><pre>A = 1, B = 1, Cin = 1<br><br>Half Adder 1:<br>  temp_sum = 1 XOR 1 = 0<br>  carry1 = 1 AND 1 = 1<br><br>Half Adder 2:<br>  Sum = 0 XOR 1 = 1<br>  carry2 = 0 AND 1 = 0<br><br>Carry Out:<br>  Cout = 1 OR 0 = 1<br><br>Result: Sum = 1, Cout = 1 → &quot;11&quot; in binary (3 in decimal) ✓</pre><h3>Multi-Bit Addition</h3><p>By chaining Full Adders, we can add numbers of any size:</p><pre>Example: 5 + 3 = 8<br>Binary: 101 + 011 = 1000<br><br>Position:     [2]  [1]  [0]<br>A:             1    0    1<br>B:             0    1    1<br>           ---------------<br>Cout chain: 0→ 1 → 1 → 0<br>Sum:           1    0    0    0</pre><h3>9. From Adders to CPU Instructions (Smooth Transition)</h3><p>Now that we understand how adders work, let’s connect this to how a CPU executes instructions. When you write code like int result = 5 + 3;, the CPU doesn&#39;t magically know what to do. It follows a precise instruction format.</p><h3>10. CPU Instructions: High-Level View</h3><p><strong>Conceptually</strong>, CPU instructions can be described using the following logical structure:</p><pre>operation + inputs + output</pre><p>For learning purposes, we often represent this as:</p><pre>[Instruction Category] [Opcode] [Operands] [Destination]</pre><p><strong>This is a teaching model, not a universal hardware format.</strong></p><p>Let’s break down each component:</p><h3>1. Instruction Type</h3><p>Categorizes what kind of operation this is:</p><p><strong>Common Types</strong>:</p><ul><li><strong>Arithmetic</strong>: ADD, SUB, MUL, DIV</li><li><strong>Logic</strong>: AND, OR, XOR, NOT</li><li><strong>Memory</strong>: LOAD, STORE</li><li><strong>Control/Jump</strong>: JMP, BRANCH, CALL, RETURN</li></ul><p><strong>Example</strong>:</p><pre>Type = &quot;Arithmetic&quot; → CPU knows to use the ALU (Arithmetic Logic Unit)</pre><blockquote><em>In real CPUs, the instruction category is </em><strong><em>not always stored in a separate field</em></strong><em>. It is often </em><strong><em>implied by the opcode and other instruction bits</em></strong><em>.</em></blockquote><h3>2. Opcode (Operation Code)</h3><p>Specifies the exact operation to perform.</p><p><strong>Example Opcodes</strong> (simplified):</p><pre>Binary    | Mnemonic | Operation<br>----------|----------|------------------<br>0000      | ADD      | Addition<br>0001      | SUB      | Subtraction<br>0010      | MUL      | Multiplication<br>0011      | DIV      | Division<br>0100      | AND      | Bitwise AND<br>0101      | OR       | Bitwise OR<br>1000      | LOAD     | Load from memory<br>1001      | STORE    | Store to memory<br>1100      | JMP      | Jump to address</pre><blockquote><em>The following opcodes are </em><strong><em>simplified examples</em></strong><em> used to illustrate the idea.<br>Real CPUs use architecture-specific encodings.</em></blockquote><h3>3. Operands</h3><p>The data or addresses the operation uses.</p><p><strong>Example</strong>:</p><pre>ADD R1, R2, R3  →  R1 = R2 + R3<br><br>Operand 1: R2 (source register 1)<br>Operand 2: R3 (source register 2)<br>Destination: R1 (where result goes)</pre><p>Some instructions have fewer operands, implicit operands, or no operands at all.</p><p>In real architectures, opcode bits and register bits are often interleaved, and different instruction types use different layouts. One possible <strong>simplified teaching example</strong> of an instruction layout:</p><pre>[Type: 2 bits][Opcode: 4 bits][R1: 3 bits][R2: 3 bits][R3: 3 bits][unused: 1 bit]<br>   00           0000              001         010         011          0<br><br>Type = 00 (Arithmetic)<br>Opcode = 0000 (ADD)<br>R1 = 001 (register 1)<br>R2 = 010 (register 2)<br>R3 = 011 (register 3)</pre><h3>11. From Instructions to Binary Decoding</h3><p>Instructions are stored as <strong>binary patterns</strong>:</p><pre>10100110</pre><p>Hardware must interpret them. This is the role of a <strong>Binary Decoder</strong>.</p><h3>12. What Is a Binary Decoder?</h3><p>A <strong>binary decoder</strong>:</p><ul><li>Takes n input bits</li><li>Activates <strong>one of 2ⁿ outputs</strong></li></ul><p>Think of it as a translator: it converts binary codes into specific control signals.</p><h3>Example: 2-to-4 Decoder</h3><pre>A B | Output<br>------------<br>0 0 | Out0<br>0 1 | Out1<br>1 0 | Out2<br>1 1 | Out3</pre><h3>Diagram</h3><pre>A ──┐<br>    ├──►[ Decoder ]──► Out0<br>B ──┘               ─► Out1<br>                    ─► Out2<br>                    ─► Out3</pre><p>Decoders are used to:</p><ul><li>Select operations</li><li>Enable hardware units</li><li>Control data flow</li></ul><h3>Practical Example: Vending Machine (Binary Decoder)</h3><p>Imagine a vending machine that sells <strong>four different items</strong>.<br>Each item is selected using a <strong>2-bit binary code</strong>.</p><pre>Input Code → Selected Item<br>--------------------------<br>00 → Water   (Y0)<br>01 → Soda    (Y1)<br>10 → Juice   (Y2)<br>11 → Coffee  (Y3)</pre><p>The vending machine uses a <strong>2-to-4 binary decoder</strong>.</p><ul><li>Inputs: A1, A0</li><li>Outputs: Y0, Y1, Y2, Y3</li><li>Only <strong>one output</strong> is active at a time</li></ul><h3>Putting It All Together</h3><p>Let’s trace the complete flow for: result = 5 + 3</p><h3>1. High-Level Code</h3><pre>int result = 5 + 3;</pre><h3>2. Assembly Instruction</h3><pre>ADD R3, R1, R2</pre><h3>3. Binary Encoding</h3><pre>Type   Opcode  Dest  Src1  Src2<br>[00]   [0000]  [011] [001] [010]</pre><h3>4. Hardware Execution</h3><p><strong>Step 1: Instruction Fetch</strong><br>- CPU fetches binary instruction from memory</p><p><strong>Step 2: Decode</strong><br>- <strong>Opcode bits (0000) </strong>→ Decoder activates Y0 (ADD)<br>- Control signals route to ALU</p><p><strong>Step 3: Execute</strong><br>- R1 contains: 0101 (5 in binary)<br>- R2 contains: 0011 (3 in binary)<br>- <strong>Full Adder chain</strong> computes:</p><pre>Position   [3][2][1][0]<br>  A:        0  1  0  1<br>  B:        0  0  1  1<br>            ----------<br>  Sum:      1  0  0  0  = 8</pre><p><strong>Step 4: Write Back</strong></p><ul><li>Result (1000) written to R3</li></ul><h3>Conclusion</h3><p>In this article, we’ve journeyed from the most basic building block — the <strong>transistor</strong> — all the way to <strong>binary decoders</strong> that help CPUs interpret instructions. Here’s what we covered:</p><ol><li><strong>Transistors</strong>: Electronic switches controlled by voltage</li><li><strong>Logic Gates</strong>: Combinations of transistors that perform logical operations</li><li><strong>Half Adder</strong>: Adds two bits using XOR and AND gates</li><li><strong>Full Adder</strong>: Enables multi-bit arithmetic</li><li><strong>CPU Instructions</strong>: Structured format with type, opcode, and operands</li><li><strong>Binary Decoder</strong>: Converts opcodes into control signals</li></ol><p>Remember: every line of code you write ultimately becomes billions of transistor switches turning on and off. Understanding this foundation transforms how you think about programming.</p><p>In the next article, I’ll try to explore <strong>latches</strong> and <strong>flip-flops</strong> — circuits that add <em>memory</em> to our logic, enabling computers to store state and build sequential circuits.</p><h3>References</h3><ul><li><a href="https://www.youtube.com/watch?v=HjneAhCy2N4&amp;list=PL9vTTBa7QaQOoMfpP3ztvgyQkPWDPfJez"><strong>Core Dump — Computer Architecture From Scratch (YouTube Playlist)</strong></a></li><li><strong>“Computer Systems: A Programmer’s Perspective”</strong> by Bryant &amp; O’Hallaron — The definitive textbook bridging hardware and software</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=591b7100070b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interrupts, Context Switching, and State Saving in Operating Systems]]></title>
            <link>https://medium.com/@tabriz.gulmammadov/interrupts-context-switching-and-state-saving-in-operating-systems-1a621f5224c4?source=rss-23076abc5108------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a621f5224c4</guid>
            <category><![CDATA[interrupt]]></category>
            <category><![CDATA[cpu]]></category>
            <category><![CDATA[context-switching]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[cpu-scheduling]]></category>
            <dc:creator><![CDATA[Tabriz Gulmammadov]]></dc:creator>
            <pubDate>Wed, 04 Feb 2026 05:11:26 GMT</pubDate>
            <atom:updated>2026-02-04T05:11:26.261Z</atom:updated>
            <content:encoded><![CDATA[<h3>Personal Context</h3><p>Until about a year ago, my learning was mostly driven by immediate project needs. I focused on .NET, Python, and Golang, keeping up with new features, APIs, and code patterns, and applying them as quickly as possible.</p><p>Over time, discussions with experienced friends changed how I evaluated my own approach. I began to realize that beyond a certain point, knowing <em>what</em> to use matters less than understanding <em>what actually changes underneath</em> when you use it — how abstractions affect performance, memory, and overall system behavior.</p><p>Recognizing this gap pushed me toward revisiting fundamentals and reading more systems-level and computer science literature.</p><p>Joining <strong>Simbrella</strong> accelerated this shift even further. Working on large-scale systems made it clear that even small changes can have significant consequences, forcing deeper discussions around performance, concurrency, and correctness.</p><p>This article is a direct result of that mindset shift — a focus on understanding what really happens behind the abstractions we rely on every day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-4nWWo5apywY1uU8jIpmDA.png" /><figcaption>Interrupts, Context Switching, and State Saving</figcaption></figure><h3>From Hardware Mechanisms to Kernel Data Structures</h3><p>When I try to learn operating systems, I encountered seemingly contradictory explanations about <strong>how process state is saved during interrupts and context switches <em>(at least in my thoughts)</em></strong>.</p><p>Some sources emphasize <strong>hardware mechanisms</strong> like <em>multiple register sets</em> or <em>hardware-assisted register saving (</em><a href="https://www.youtube.com/watch?v=7ge7u5VUSbE&amp;list=PL9vTTBa7QaQPdvEuMTqS9McY-ieaweU8M"><em>Core Dumped — Operating Systems Theory</em></a><em>)</em>.</p><p>Another one (such as <em>Operating Systems: Three Easy Pieces</em>) focus on <strong>PCB (Process Control Block)</strong> and <strong>kernel stacks</strong>.</p><p>So which one is correct?</p><p><strong>Both are — but they operate at different layers.</strong></p><p>This article explains the full picture, <strong>from hardware to OS</strong>, clarifying <em>what happens</em>, <em>when</em>, and <em>why</em>.</p><h3>1. The Core Problem: What Happens During an Interrupt?</h3><p>An <strong>interrupt</strong> is an asynchronous event that forces the CPU to temporarily stop executing the current instruction stream.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*CMr6ubTPWW1DRDQjTzLAIg.png" /><figcaption>Figure 1: High-level layers in an OS interrupt: hardware saves minimal state, OS manages context switching.</figcaption></figure><p>Examples:</p><ul><li>Timer interrupt (preemption)</li><li>I/O completion</li><li>System call</li><li>CPU exception (page fault, divide by zero)</li></ul><p>The fundamental requirement is simple:</p><blockquote><strong><em>The interrupted execution must be resumed correctly later.</em></strong></blockquote><p>To do that, the system must preserve the execution state.</p><h3>2. What “State” Actually Means</h3><p>Execution state includes:</p><ul><li>Program Counter (PC / IP)</li><li>CPU registers</li><li>CPU flags</li><li>Stack pointer</li><li>Privilege level (a single bit points to user / kernel mode)</li><li>Memory context (address space)</li></ul><p>But <strong>not all of this is saved at the same time or by the same component</strong>.</p><p>P.S.: M<strong>emory context</strong> is slightly higher-level. It’s part of the <strong>process state</strong>, not just CPU state.</p><ul><li>Each process in an OS has its <strong>own virtual address space</strong> (text/code, data, heap, stack).</li><li>The <strong>page tables / memory mapping structures</strong> define this memory context.</li><li>When the OS switches from one process to another, it <strong>saves/restores the memory context</strong> so each process sees its own virtual memory layout.</li></ul><blockquote><em>So, when I said </em>“Memory context (address space) is part of state”<em>, I meant </em><strong><em>process state</em></strong><em>, which is broader than just CPU state. It’s included in the OS’s internal bookkeeping for a process. Without it, switching processes would corrupt memory.</em></blockquote><h3>3. Hardware Responsibility: Immediate State Protection</h3><h3>3.1 Hardware-Assisted State Saving (Modern CPUs)</h3><p>On modern architectures (x86, ARM, RISC-V), when an interrupt occurs:</p><ol><li>CPU switches to <strong>kernel mode</strong></li><li>CPU automatically saves a <strong>minimal execution context</strong>:</li></ol><ul><li>Program counter (PC / IP)</li><li>Flags / status register</li><li>Sometimes stack pointer</li></ul><p>3. CPU jumps to a predefined <strong>interrupt handler</strong></p><p>This is called <strong>hardware-assisted state saving</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*mVrVLOzn9uUZ7Lzre3io_g.png" /><figcaption>Figure 2: Each process has a kernel stack used for interrupts and system calls.</figcaption></figure><p>Importantly:</p><ul><li>This happens <strong>before the OS code runs</strong></li><li>It is defined by the <strong>CPU architecture</strong></li><li>The OS cannot skip or replace it</li></ul><h3>3.2 Which Stack Is Used?</h3><p>A critical detail often misunderstood:</p><blockquote><em>The CPU uses the </em><strong><em>interrupted process’s kernel stack</em></strong><em>.</em></blockquote><p>Each process has:</p><ul><li>a <strong>user stack</strong> (user mode)</li><li>a <strong>kernel stack</strong> (kernel mode)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2NNhLCr3oQl0F3bQEZ6Uow.png" /><figcaption>Figure 3: Hardware-assisted interrupt entry; minimal state saved before kernel executes.</figcaption></figure><p>During an interrupt:</p><ul><li>user stack is abandoned</li><li>kernel stack of the <em>current process</em> becomes active</li><li>hardware pushes state onto that kernel stack</li></ul><p>There is <strong>no single global OS stack</strong>.</p><h3>4. Historical Hardware Approach: Multiple Register Sets</h3><p>Some older or specialized CPUs used a different approach.</p><h3>Multiple Register Sets (Register Banking)</h3><p>Used in:</p><ul><li>SPARC</li><li>Itanium</li><li>some embedded systems</li></ul><p>How it worked:</p><ul><li>CPU had multiple register banks</li><li>On interrupt, CPU switched to a different register set</li><li>No memory writes required</li></ul><p>Advantages:</p><ul><li>Extremely fast interrupt latency</li></ul><p>Disadvantages:</p><ul><li>Hardware complexity</li><li>Limited nesting depth</li><li>Poor scalability</li></ul><p>➡️ This approach is largely abandoned in general-purpose CPUs.</p><h3>5. Operating System Responsibility: Full Context Switching</h3><p>The hardware only saves a <strong>minimal state</strong>.</p><p>The OS decides:</p><ul><li>Should the current process continue?</li><li>Or should another process run?</li></ul><p>This decision is made by the <strong>scheduler</strong>.</p><p>If a context switch is required, the OS must save <strong>the full execution context</strong>.</p><h3>6. Kernel Stack vs PCB: Different Roles</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KMwW7mDVvlRGzCCFdvHnoQ.png" /><figcaption>Figure 4: Kernel stack holds active execution; PCB stores persistent process state for context switching.</figcaption></figure><h3>Kernel Stack</h3><ul><li>Short-term execution context</li><li>Used during:<br> — interrupts<br> — system calls<br> — kernel execution</li><li>Stores:<br> — call frames<br> — temporarily saved registers</li></ul><p>Think of it as:</p><blockquote><em>Where the kernel runs </em>on behalf of<em> a process.</em></blockquote><h3>Process Control Block (PCB)</h3><p>The <strong>Process Control Block (PCB)</strong> is a kernel-resident data structure that represents a process. It is stored in <strong>kernel memory</strong> and exists for the entire lifetime of the process.</p><p>The PCB typically contains:</p><ul><li>Saved CPU registers (when the process is not running)</li><li>Program Counter</li><li>Scheduling state (running, ready, blocked)</li><li>Memory context (page table pointers)</li><li>Open file references and other resources</li></ul><p><strong>Think of the PCB as:</strong></p><blockquote>The OS’s permanent record of a process.</blockquote><p>or</p><blockquote><em>Everything needed to restart the process later.</em></blockquote><h3>Why Both Are Needed</h3><p><strong><em>Kernel stack</em></strong> → Active execution context<br><strong><em>PCB</em></strong> → Long-term saved process state</p><p>During a context switch:</p><ol><li>Kernel saves registers from kernel stack → PCB</li><li>Scheduler selects another PCB</li><li>Registers restored from new PCB</li><li>Kernel stack switches to new process</li></ol><h3>7. Interrupt Type Does NOT Change the Mechanism</h3><p>Whether the interrupt is:</p><ul><li>timer</li><li>I/O</li><li>syscall</li><li>exception</li></ul><p>The mechanism remains the same:</p><ol><li>Hardware saves minimal state</li><li>Kernel executes handler</li><li>Scheduler may run</li><li>PCB used only if switching processes</li></ol><p>Interrupt <strong>type</strong> affects:</p><ul><li>which handler runs</li><li>whether scheduling happens</li></ul><p>Not <strong>how state is saved</strong>.</p><h3>8. Why OSTEP Focuses on PCB and Kernel Stack</h3><p><em>Operating Systems: Three Easy Pieces</em> deliberately abstracts hardware specifics.</p><p>Its goal:</p><ul><li>explain OS principles</li><li>remain architecture-independent</li></ul><p>So it focuses on:</p><ul><li>kernel stacks</li><li>PCBs</li><li>scheduler logic</li></ul><p>Hardware mechanisms are assumed as given.</p><h3>9. Putting It All Together (Execution Timeline)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*KQsTLrLhvh9A3HczLedRKQ.png" /><figcaption>Figure 5: Complete interrupt and context switch timeline, showing hardware and OS responsibilities.</figcaption></figure><h3>10. Key Takeaways</h3><ul><li>Hardware and OS mechanisms are <strong>complementary</strong>, not competing</li><li>Hardware handles <strong>immediate safety</strong></li><li>OS handles <strong>process management</strong></li><li>Kernel stack ≠ PCB</li><li>Multiple register sets are historical</li><li>Modern systems rely on stack-based saving</li></ul><h3>References</h3><ul><li><strong>Operating Systems: Three Easy Pieces</strong><br> Remzi H. Arpaci-Dusseau, Andrea C. Arpaci-Dusseau<br> <a href="https://pages.cs.wisc.edu/~remzi/OSTEP/">https://pages.cs.wisc.edu/~remzi/OSTEP/</a></li><li><strong>Core Dump YouTube Channel — Operating Systems Theory Playlist</strong><br> <a href="https://www.youtube.com/@CoreDumpp">https://www.youtube.com/@CoreDumpp</a></li><li>Intel® 64 and IA-32 Architectures Software Developer’s Manual</li><li>Linux Kernel Documentation</li></ul><h3>Final Thought</h3><blockquote><em>Understanding operating systems requires separating </em><strong><em>what hardware must do</em></strong><em> from </em><strong><em>what the OS chooses to do</em></strong><em>. Once you draw that line clearly, most “contradictions” disappear.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a621f5224c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>