<?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 Leo Hou on Medium]]></title>
        <description><![CDATA[Stories by Leo Hou on Medium]]></description>
        <link>https://medium.com/@leohou1402?source=rss-1d0b9d86c100------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TJStlu4uAb7yJiH_tRUXxA.png</url>
            <title>Stories by Leo Hou on Medium</title>
            <link>https://medium.com/@leohou1402?source=rss-1d0b9d86c100------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 04:43:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leohou1402/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[Electronic Information Technology (Part 3): The Foundation of Digital Circuits]]></title>
            <link>https://medium.com/@leohou1402/electronic-information-technology-part-3-the-foundation-of-digital-circuits-3ed1bdda92d9?source=rss-1d0b9d86c100------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ed1bdda92d9</guid>
            <dc:creator><![CDATA[Leo Hou]]></dc:creator>
            <pubDate>Mon, 09 Mar 2026 02:24:30 GMT</pubDate>
            <atom:updated>2026-03-22T01:10:36.131Z</atom:updated>
            <content:encoded><![CDATA[<h3>Electronic Information Technology (III) — Digital Circuits</h3><p>A beginner’s guide to binary, logic operations, and the two major types of digital circuits</p><h3>Preface</h3><p>In the previous installment, we reviewed the history of electronic information technology and traced the major milestones in its development. This time, we turn our attention to <strong>digital circuits</strong>.</p><p>You might be wondering: shouldn’t we cover “Electronic Information Technology (II) — Analog Circuits” first?</p><p>In my understanding, analog circuits are indeed the foundation of digital circuits. However, analog circuits run very deep — I wouldn’t dare wade into that territory here. If there are analog circuit experts out there, feel free to contribute that chapter!</p><p>That said, let’s get to the point. Digital circuits are the backbone of modern information technology. Those who have studied digital circuits in college will recall that the subject is vast, typically spanning two semesters. Today, we’ll focus on four core concepts: binary numbers, logic operations, combinational logic circuits, and sequential logic circuits.</p><h3>1. Binary Numbers</h3><p>In everyday life, we use the <strong>decimal system</strong> — counting in base 10, where we carry when we reach ten. Binary works the same way, but in base 2: we carry when we reach two.</p><p>Binary data is represented using only two digits: <strong>0</strong> and <strong>1</strong>. The base is 2, the carry rule is “carry on two,” and the borrow rule is “borrow one as two.”</p><p>Introducing binary into electronics was a groundbreaking insight. In semiconductor circuits, signals have two distinct voltage states — high and low. Binary maps neatly onto this: <strong>high voltage → 1, low voltage → 0</strong>. This abstraction launched the era of digital circuits, enabling circuits to perform computations on binary data. The most complex digital circuit in existence today is arguably the <strong>CPU</strong>.</p><h3>2. Logic Operations</h3><p>Once binary numbers exist, we need ways to compute with them. Decimal arithmetic uses addition, subtraction, multiplication, and division. Binary supports these operations too — but binary also unlocks a powerful tool: <strong>logic operations</strong>.</p><p>Logic operations, also known as <strong>Boolean operations</strong>, use equations to represent judgments and treat reasoning as algebraic transformations.</p><p>There are three fundamental logic operations in Boolean algebra: <strong>AND</strong>, <strong>OR</strong>, and <strong>NOT</strong>. These can be expressed in multiple ways — natural language, algebraic expressions, truth tables, or Karnaugh maps.</p><p>SymbolMeaning ∨OR ∧AND ┐NOT =Equivalence 1 / 0True / False</p><p>Logic algebra introduces two types of variables. <strong>Logic constants</strong> have only two values — 0 and 1 — representing two opposing states. <strong>Logic variables</strong> can be represented by letters or symbols, but unlike ordinary algebra, they can <em>only</em> take the values 0 or 1. There are no intermediate values.</p><h3>3. Combinational vs. Sequential Logic Circuits</h3><p>Digital circuits can be divided into two major categories based on their logical characteristics: <strong>combinational logic circuits</strong> and <strong>sequential logic circuits</strong>.</p><h3>3.1 Combinational Circuits</h3><blockquote><em>The output depends </em>only<em> on the current input — nothing else.</em></blockquote><p>In a combinational circuit, the output is uniquely determined by the present input values. The circuit has <strong>no memory</strong> — it doesn’t know what its previous state was. As inputs change, outputs change immediately. This behavior is analogous to a purely resistive electrical circuit.</p><p>Key characteristics of combinational circuits:</p><ul><li>No feedback path between output and input</li><li>No memory elements in the circuit</li></ul><h3>3.2 Sequential Circuits</h3><blockquote><em>The output depends on </em>both<em> the current input </em><strong><em>and</em></strong><em> the circuit’s previous state.</em></blockquote><p>In a sequential circuit, any output at a given moment is influenced not only by the current inputs but also by the circuit’s history. Conceptually, this is like adding a <strong>feedback input</strong> to a combinational circuit, along with a <strong>storage element</strong> that remembers past states.</p><h3>3.2.1 Mathematical Description of Sequential Circuits</h3><p>A sequential circuit is typically described by three equations:</p><p><strong>1. Drive equation</strong> (excitation equation): Describes the input to the memory element.<br> Y = F(X, Qⁿ)</p><p><strong>2. State equation</strong>: Describes the relationship between the next state Qⁿ⁺¹ and the current state Qⁿ.<br> Qⁿ⁺¹ = H(Z, Qⁿ)</p><p><strong>3. Output equation</strong>: Describes the final circuit output as a function of the flip-flop output Qⁿ.<br> Y = F(X, Qⁿ)</p><p>Among these, the drive equation and state equation are the most important. For simple circuits, the flip-flop output Qⁿ is often the final output directly, making the output equation unnecessary.</p><h3>3.2.2 Classification of Sequential Circuits</h3><p><strong>By synchronization:</strong></p><p>TypeDescription <strong>Synchronous</strong>All flip-flop state changes occur simultaneously under a common clock signal <strong>Asynchronous</strong>Flip-flop state changes do not occur at the same time</p><p><strong>By output dependency:</strong></p><p>TypeDescription <strong>Mealy model</strong>Output depends on both the current input and the stored state <strong>Moore model</strong>Output depends <em>only</em> on the stored state (Moore is a special case of Mealy)</p><h3>Closing Thoughts</h3><p>Digital circuits may seem abstract at first, but the core ideas are elegant: reduce complex signals to 0s and 1s, perform logic operations on those values, and chain circuits together — some stateless, some with memory — to build increasingly powerful systems. These principles form the foundation of everything from simple logic gates to the modern CPU.</p><p><em>Reference: Yan Shi, “Fundamentals of Digital Electronics (5th Edition),” Higher Education Press.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ed1bdda92d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Brief History of Electronic Information Technology]]></title>
            <link>https://medium.com/@leohou1402/a-brief-history-of-electronic-information-technology-f2a00404b76c?source=rss-1d0b9d86c100------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2a00404b76c</guid>
            <dc:creator><![CDATA[Leo Hou]]></dc:creator>
            <pubDate>Mon, 09 Mar 2026 02:11:59 GMT</pubDate>
            <atom:updated>2026-03-21T15:23:32.089Z</atom:updated>
            <content:encoded><![CDATA[<p><em>From Franklin’s kite to billion-transistor chips — how humanity wired the modern world.</em></p><p>Electronic information technology has dramatically shaped the modern world. Its origins stretch back to the earliest scientific explorations of electricity and electromagnetic phenomena — a long chain of curious minds asking what invisible forces might be harnessed to carry light, sound, and thought across any distance.</p><p>The development of electronic technology has enabled the <strong>Human Information Age</strong> — a new era where electrical and electronic systems form the backbone of communication, computation, and modern life.</p><h3>From Electricity Discovery to Electronic Civilization</h3><p>The story begins with early scientists trying to understand the nature of electricity itself.</p><p><strong>1752 — Benjamin Franklin</strong> conducted his famous kite experiment in Philadelphia, successfully bringing lightning into a Leyden jar via a metal wire. This dramatic experiment symbolized humanity’s first real engagement with electrical phenomena.</p><p><strong>1820 — Hans Christian Ørsted</strong> discovered the magnetic effect of electric current — observing that an electric current flowing through a wire could deflect a magnetic needle. This laid the foundation for electromagnetic theory.</p><p><strong>1831 — Michael Faraday</strong> discovered electromagnetic induction — the principle that changing magnetic fields can generate electric current. This discovery would become central to electric power generation.</p><p><strong>1860s — James Clerk Maxwell</strong> unified electricity and magnetism with his celebrated equations, predicting the existence of electromagnetic waves and setting the stage for wireless communication.</p><h3>Wireless Communication Takes Shape</h3><p>In 1873, Heinrich Hertz experimentally demonstrated the existence of electromagnetic waves — confirming Maxwell’s predictions and proving that wireless transmission was feasible.</p><blockquote><em>Wireless telegraphy was not a single invention — it was the culmination of a century of theoretical and experimental work converging at exactly the right moment.</em></blockquote><p>By the late 1890s, innovators like <strong>Guglielmo Marconi</strong> successfully transmitted information via electromagnetic waves, effectively ushering in the age of wireless telegraphy and radio communication. In 1896, Marconi transmitted signals over longer distances using radio waves, pioneering the earliest forms of wireless communication.</p><h3>Enter the Electronic Age</h3><p>In 1904, British engineer <strong>John Ambrose Fleming</strong> invented the first practical vacuum tube diode — the beginning of the “electronic civilization.” Soon afterward, vacuum triodes emerged, accelerating the development of wireless broadcasting, telephony, and radio communication systems.</p><p>After World War II, the limitations of vacuum tubes became apparent. In 1947, the Bell Labs team — including <strong>William Shockley, John Bardeen, and Walter Brattain</strong> — invented the point‑contact transistor, marking the beginning of widespread solid‑state electronic circuits.</p><p>These inventions laid the foundation for integrated circuits and semiconductor technology.</p><h3>The Birth of Integrated Circuits</h3><p>In 1958, engineers at <strong>Texas Instruments</strong> successfully built one of the world’s earliest integrated circuits — tiny chips containing multiple electronic components. By the early 1960s, IC production became scalable, and throughout the 1970s, advancements led to chips containing hundreds of thousands of transistors.</p><p>By the early 21st century, <strong>billions of transistors</strong> could be placed on a single chip, culminating in nanometer‑scale processes used in modern microprocessors and digital systems.</p><h3>The Modern Electronic Information Era</h3><p>Today, electronic information technology is the cornerstone of the digital age. From computers and smartphones to global communications networks and the Internet, electronic systems pervade every aspect of modern life.</p><p>Yet challenges remain: physical limits of silicon scaling and emerging technologies such as <strong>quantum computing</strong> continue to be explored in the quest to push the boundaries of what electronic systems can do.</p><p>The history of electronic information technology is a long chain of scientific discovery, engineering innovation, and technological progress. From the first kite experiment to integrated semiconductor chips, each milestone brought us closer to the interconnected world we live in today.</p><p>The legacy of these developments reminds us to respect scientific inquiry, honor pioneers of technology, and continue learning and innovating in an age of information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2a00404b76c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Analysis of NUMA Architecture: From Hardware Topology to Linux Node Management]]></title>
            <link>https://medium.com/@leohou1402/an-analysis-of-numa-architecture-from-hardware-topology-to-linux-node-management-a5945eb9880b?source=rss-1d0b9d86c100------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5945eb9880b</guid>
            <category><![CDATA[numa]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Leo Hou]]></dc:creator>
            <pubDate>Fri, 22 Aug 2025 01:48:17 GMT</pubDate>
            <atom:updated>2025-08-22T01:48:17.396Z</atom:updated>
            <content:encoded><![CDATA[<p>In modern server architectures, as the number of CPU cores and memory capacity continue to climb, the traditional Symmetric Multiprocessor (SMP) architecture is gradually facing memory bandwidth bottlenecks (Uniform Memory Access — UMA). The Non-Uniform Memory Access (NUMA) architecture addresses this issue through a distributed memory design, but it also introduces new challenges for software optimization. This article comprehensively explains the working principles and performance optimization strategies of NUMA systems, from hardware topology to Linux kernel abstraction.</p><h3>I. NUMA Hardware Architecture: “Distributed Memory” at the Physical Level</h3><p>The core feature of NUMA (Non-Uniform Memory Access) is the non-uniformity of memory access latency. From a hardware perspective, a NUMA system consists of multiple independent “computing units” called cells (physical units), each containing:</p><ul><li>One or more CPU cores</li><li>Local memory (memory directly connected to the cell)</li><li>I/O buses (e.g., PCIe controllers)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*QKn0RjjBV8W0okHQjr2Ehg.png" /></figure><h3>1.1 Connection and Communication of Physical Units</h3><p>Multiple cells are connected via a System Interconnect. Common interconnect methods fall into two categories:</p><ul><li><strong>Crossbar Switch</strong>: Enables communication between cells through a central switching node, suitable for small to medium-sized NUMA systems.</li><li><strong>Point-to-Point Links</strong>: Cells are directly connected to form a mesh structure, supporting large-scale expansion.</li></ul><p>This design allows each CPU to access local memory much faster than “remote memory” in other cells. For example, in a server, local memory access latency may be only 50ns, while cross-cell access latency can exceed 200ns, with bandwidth also decreasing by 30%-50%.</p><h3>1.2 Cache Coherence and ccNUMA</h3><p>Linux primarily focuses on cache-coherent NUMA (ccNUMA) systems. In ccNUMA:</p><ul><li>All memory is visible to any CPU (global address space).</li><li>Hardware automatically maintains cache coherence (e.g., via mechanisms like the MESI protocol).</li><li>The “proximity” of memory access only affects latency and bandwidth, not availability.</li></ul><p>This means software does not need to manually manage memory coherence, but it must reduce remote access through reasonable memory allocation strategies to leverage hardware performance.</p><h3>II. Linux’s NUMA Abstraction</h3><p>The Linux kernel abstracts NUMA hardware resources into nodes, shielding hardware details through a software layer while exposing NUMA topology characteristics for application optimization.</p><h3>2.1 Mapping Between Nodes and Physical Units</h3><ul><li>Each node corresponds to one or more physical cells (depending on the hardware architecture).</li><li>A node contains a logical grouping of resources such as CPUs, memory, and I/O devices.</li><li>The kernel quantifies the access cost between nodes using “NUMA distance” (smaller values indicate closer proximity).</li></ul><p>For example, in x86 architectures, if a cell has no local memory, Linux will “migrate” its CPUs to a node with memory to avoid performance issues caused by memoryless nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*050FsaxJWtjtFh_9eDEwtA.png" /></figure><h3>2.2 NUMA Memory Management Mechanisms</h3><p>Each node with memory has an independent memory management subsystem, including:</p><ul><li><strong>Free Page Lists</strong>: Manage memory by page size and type.</li><li><strong>Zones</strong>: Such as DMA (Direct Memory Access) and NORMAL (ordinary memory).</li><li><strong>Zonelist</strong>: Defines the “fallback path” when memory allocation fails.</li></ul><h4>2.2.1 Zonelist Priority Strategy:</h4><p>Linux uses a default “node-first” strategy: when memory allocation fails, it first tries other zones within the same node, then accesses remote nodes in order of NUMA distance. This mechanism reduces cross-node access while ensuring the rational use of scarce resources (e.g., DMA memory).</p><h4>2.2.2 Memory Allocation Decision Tree</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NaUAGCXWzuDkvuZyT7GFjQ.png" /></figure><h3>2.3 NUMA Emulation: A Debugging Tool for Non-NUMA Platforms</h3><p>For non-NUMA platforms like ordinary PCs, Linux supports NUMA emulation:</p><ul><li>Divides physical memory into multiple virtual nodes.</li><li>Simulates differences in access latency between nodes.</li><li>Used to test NUMA optimization strategies or debug kernel functions.</li></ul><p>The numactl tool configures the number of emulated nodes and memory distribution. For example:</p><pre>numactl --interleave=all ./my_app  # Interleave memory allocation across nodes</pre><h3>III. NUMA Performance Optimization</h3><p>The key to NUMA performance lies in locality — enabling CPUs to access local memory as much as possible. The Linux kernel and application layer provide various optimization methods.</p><h3>3.1 Kernel’s Local Allocation Strategy</h3><ul><li>By default, the kernel allocates memory from the node to which the current CPU belongs (local allocation).</li><li>The scheduler is aware of NUMA topology through “scheduling domains” to reduce cross-node task migration.</li><li>When local memory is insufficient, remote nodes are accessed in zonelist order.</li></ul><p>However, the scheduler does not directly consider task memory distribution, which in extreme cases may lead to “frequent remote memory access after task migration.”</p><h3>3.2 Application-Level Optimization Tools and Interfaces</h3><h4>(1) CPU Affinity Binding</h4><ul><li>taskset: Binds processes to specific CPU cores (e.g., to node0&#39;s CPUs).</li></ul><pre>taskset -c 0-3 ./my_app  # Restrict the process to run on CPUs 0-3</pre><ul><li>numactl: Provides finer-grained NUMA control, such as binding memory allocation nodes.</li></ul><pre>numactl --cpunodebind=0 --membind=0 ./my_app  # Bind to node 0&#39;s CPUs and memory</pre><h4>(2) NUMA Memory Policies</h4><p>Memory policies can be set in code using the libnuma library. Common policies include:</p><ul><li>MPOL_BIND: Allocate memory only from specified nodes.</li><li>MPOL_PREFERRED: Prefer allocation from a specified node, with fallback if insufficient.</li><li>MPOL_INTERLEAVE: Round-robin allocation across nodes, suitable for high-memory throughput scenarios.</li></ul><pre>#include &lt;numa.h&gt;<br>int nodes[] = {0};  // Use only node 0<br>set_mempolicy(MPOL_BIND, nodes, 1);  // Set memory policy</pre><h4>(3) Control Groups (Cgroups) and CPUsets</h4><p>Administrators can restrict resource ranges for users/processes via cpusets:</p><ul><li>Limit the CPU cores and memory nodes available to processes.</li><li>Prevent non-privileged users from misusing remote node resources.</li><li>Often used for resource isolation in containerized environments.</li></ul><h3>3.3 NUMA Adaptation in Kernel Subsystems</h3><p>Some kernel components (e.g., slab allocators, performance analysis tools) require special handling for NUMA:</p><ul><li>Use numa_mem_id() to obtain the &quot;local memory node&quot; of a CPU (not the physical node).</li><li>Provide custom fallback mechanisms when allocation fails (e.g., cross-node caches for slabs).</li><li>Avoid initializing functions dependent on local memory on memoryless nodes.</li></ul><h3>IV. Conclusion</h3><p>NUMA brings performance improvements but also new challenges!</p><p>The NUMA architecture breaks through SMP’s bandwidth bottlenecks through a distributed memory design but introduces the new issue of “non-uniform memory access.” To fully leverage NUMA performance, one must:</p><ul><li>Understand hardware topology: Clarify node distribution and NUMA distances.</li><li>Allocate resources rationally: Improve locality through binding tools and memory policies.</li><li>Use monitoring tools: Analyze memory access patterns with numastat, perf, etc.</li></ul><p>As the number of CPU cores continues to grow, NUMA optimization will become an essential skill for high-performance application development. Mastering NUMA’s working principles enables the construction of efficient systems in the multi-core era.</p><h3>References</h3><p>[0] Linux Kernel Documentation: Documentation/mm/numa.rst</p><p>[2] Linux Kernel Documentation: Documentation/admin-guide/mm/numa_memory_policy.rst</p><p>[3] numactl Tool Manual: man numactl</p><p>[4] <em>Linux System Programming: In-depth Understanding of Underlying System Mechanisms</em> (NUMA chapter)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5945eb9880b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RISC-V series-detailed explanation of AMO instructions]]></title>
            <link>https://medium.com/@leohou1402/risc-v-series-detailed-explanation-of-amo-instructions-824c4287ad25?source=rss-1d0b9d86c100------2</link>
            <guid isPermaLink="false">https://medium.com/p/824c4287ad25</guid>
            <category><![CDATA[risc-v]]></category>
            <dc:creator><![CDATA[Leo Hou]]></dc:creator>
            <pubDate>Wed, 24 Apr 2024 17:03:49 GMT</pubDate>
            <atom:updated>2024-04-24T17:03:49.897Z</atom:updated>
            <content:encoded><![CDATA[<p>AMO (Aomic Memory Operation) instructions perform multi-object read-modify-write operations and are encoded in R-type form. These AMO instructions automatically load a data value from the address in rs1, place the value into register rd, apply binary operators to the loaded value and the original value in rs2, and store the result back to the address in rs1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*RpntGaQfbi-c66xGbnjVvg.png" /><figcaption>AMO instructions format</figcaption></figure><p>Supported operations are: swap, integer addition, bitwise AND, bitwise OR, bitwise XOR and maximum and minimum signed and unsigned integers.</p><p>If the aq bit is set, subsequent memory operations occurring before the AMO will not be observed in this RISC-V hart.</p><p>If the rl bit is set, then in this RISC-V hart, no other RISC-V hart will observe the AMO until the memory is accessed.</p><p><strong>AMOADDR：</strong></p><p>Taking AMOADDR as an example, this instruction can add the data in the register and the memory, write the addition result to the memory, and then return the original value of the memory. Assembly model:</p><pre>amoadd.{w/d}.{aqrl} rd,rs2,(rs1)</pre><p>This instruction puts the value in the memory address pointed to by the value in the rs1 register into the rd register, then adds the data in rs2 to the data in the memory unit pointed to by rs1, and writes the result to the memory unit at that address.</p><p><strong>Embed assembly example:</strong></p><pre>#include &lt;stdint.h&gt;<br>int32_t *addr = (int32_t *)0x480000000;<br><br>int main() {<br>    int32_t ret;     //Memory unit return register<br>    int32_t val = 3; //incrementing value<br>    <br>    *addr = 2<br>    //Execute AMOADD instruction<br>    asm volatile(&quot;amoadd.w %1, %2, %0&quot;<br>               : &quot;+A&quot; (*addr), &quot;+r&quot; (ret)<br>               : &quot;r&quot; (val)<br>               : &quot;memory&quot;);              <br>    // The value in addr has been incremented  <br>    printf(&quot;amoadd.w *addr : 0x%x\n&quot;, *addr);<br>    printf(&quot;amoadd.w val : 0x%x\n&quot;,  val);<br>    printf(&quot;amoadd.w ret : 0x%x\n&quot;,  ret);        <br>               <br>    return 0;<br>}</pre><p>result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*xMH2o4y8v0Zcwmz0GISLgw.png" /></figure><p>Take the value 2 from the address 0x610000000 pointed to by addr and put it into ret, add the value 2 and the value 3 in val and write it to the address 0x480000000</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=824c4287ad25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RISC-V-Standard Extension for Atomic Instructions]]></title>
            <link>https://medium.com/@leohou1402/risc-v-standard-extension-for-atomic-instructions-0d8efcb55f53?source=rss-1d0b9d86c100------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d8efcb55f53</guid>
            <category><![CDATA[atomic]]></category>
            <category><![CDATA[risc-v]]></category>
            <dc:creator><![CDATA[Leo Hou]]></dc:creator>
            <pubDate>Mon, 08 Apr 2024 00:27:38 GMT</pubDate>
            <atom:updated>2024-04-08T00:27:38.688Z</atom:updated>
            <content:encoded><![CDATA[<p>Atomic operations are operations on shared resources that are atomic (atoms are the smallest units of common matter), that is, operations that are not interrupted or interrupted by other threads, during concurrent programming based on operating systems.</p><p>In a multi-threaded or multi-process environment, if multiple threads access and modify shared data at the same time, it can cause Race Condition problems, resulting in uncertain behavior or errors. Atomic manipulation can effectively avoid these uncertain errors.</p><p>In the computer system, the essence of atomic operation is the CPU instruction level operation, in order to support atomic operation, each CPU instruction set architecture has designed the corresponding atomic operation instructions, the following mainly introduces the RISC-V atomic instruction extension.</p><p>RISC-V defines two types of atomic instructions, which I personally define as basic atomic instructions and computational atomic instructions.</p><p><strong>basic atomic instructions:</strong>load-reserved and store-conditional instructions</p><p><strong>computational atomic instructions:</strong>obtain, compute, and manipulate memory instructions for atoms</p><h3>1. Load-Reserved/Store-Conditional Instructions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*eDoX5xElaPQCdUjsWyBIHw.png" /><figcaption>Load-Reserved/Store-Conditional Instructions format</figcaption></figure><p><strong>LR.W: </strong>Loads a word from the address in rs1, puts the symbolic extension value in the rd, and registers a Reserve set — a set of bytes containing the bytes in the address word.</p><p><strong>SC.W: </strong>Conditionally writes a word from rs2 to an address in rs1: SC.W will succeed only if the reservation is still valid and the reservation set contains the bytes being written;</p><p>If SC.W is successfully executed, the instruction writes the words in rs2 to memory and 0 to rd; If SC.W fails to be executed, the command is not written to memory, and a non-zero value is written to rd.Whether successful or unsuccessful, executing the SC.W command invalidates any reservations held by the hart.</p><h3><strong>2. Atomic Memory Operations</strong></h3><p>Atomic Memory operation (AMO) instructions perform read-modified-write operations that are multi-processor synchronous and are encoded using the type r instruction format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*DTJyv3yo3ofVP10f78dLlA.png" /><figcaption>AMO instructions format</figcaption></figure><p>These AMO instructions automatically load a data value from an address in rs1, put that value into register rd, apply a binary operator to the loaded value and the original value in rs2, and then store the result back to the original address in rs1.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d8efcb55f53" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>