<?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 Edwin Chiu on Medium]]></title>
        <description><![CDATA[Stories by Edwin Chiu on Medium]]></description>
        <link>https://medium.com/@fruitcup?source=rss-beeeb91d3505------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jjN3oE9SnTFUmMSn</url>
            <title>Stories by Edwin Chiu on Medium</title>
            <link>https://medium.com/@fruitcup?source=rss-beeeb91d3505------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:37:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fruitcup/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[Accelerating Image Processing with Clang Profile-Guided Optimization (PGO) on Google Cloud]]></title>
            <link>https://medium.com/@fruitcup/accelerating-image-processing-with-clang-profile-guided-optimization-pgo-on-google-cloud-8d395a3bbb73?source=rss-beeeb91d3505------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d395a3bbb73</guid>
            <category><![CDATA[clang]]></category>
            <category><![CDATA[llvm]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Edwin Chiu]]></dc:creator>
            <pubDate>Wed, 25 Nov 2026 11:36:01 GMT</pubDate>
            <atom:updated>2026-11-25T11:36:01.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rp7xQZ-PJBt2t2a2pBEduA.jpeg" /></figure><p><em>A deep-dive into ~1.25x speedups across Intel, AMD, and Google Axion VMs using GraphicsMagick and Clang 19.1.7.</em></p><p>In this post we explore using <a href="https://clang.llvm.org/docs/UsersManual.html#profiling-with-instrumentation">Clang Profile-Guided Optimization (PGO)</a> to speedup image transformations across five modern GCP compute platforms.</p><p>Typical generic -O3 compilation optimizations tend to leave significant performance on the table. Without runtime feedback, the compiler has to guess which branches are hot, which loops are worth unrolling, and how to lay out functions in instruction cache.</p><p>Benchmarking GraphicsMagick 1.3.44 (<a href="http://www.graphicsmagick.org/mogrify.html">gm mogrify</a>), we measured a <strong>1.23x-1.26x speedup </strong>across five Google Cloud VM platforms spanning Intel, AMD, and Arm (Google Axion) architectures — and verified those gains on an unseen holdout dataset.</p><h3>Test Environment &amp; Dataset</h3><p>All benchmarks were run on <strong>Ubuntu 26.04 LTS (Resolute)</strong> with <strong>Linux Kernel 6.13.0-generic</strong> and <strong>Clang / LLVM 19.1.7</strong>.</p><p>To ensure our PGO profile generalized rather than overfit, we split a dataset of <strong>100 Creative Commons images</strong> (ranging from 1024×768 up to 6240×3512) into two disjoint sets:</p><ul><li><strong>80 Profiling Images</strong> (profiling_80.json): Used to generate the runtime execution profile.</li><li><strong>20 Holdout Images</strong> (holdout_20.json): Held out completely from profiling to validate real-world generalization.</li></ul><p><strong>Workload</strong></p><p>Image transformation using mogrify, which performs a JPEG decode, 50% resize, unsharp mask and JPEG re-encode. Note that JPEG decode/encode happens in libjpeg and the GraphicsMagick code being profiled would be for the resize and unsharp mask work.</p><p>NB: Each run operated on a fresh copy of images stored in /tmp .</p><h3>The 4-Step Clang PGO Workflow</h3><p>We compared a standard -O3 -march=native baseline against a PGO binary built in four steps:</p><p><strong>Baseline Build</strong></p><pre>CC=clang CFLAGS=&quot;-O3 -march=native&quot; \<br>./configure --prefix=/opt/gm --disable-shared --enable-static \<br>&amp;&amp; make \<br>&amp;&amp; make install</pre><p><strong>Instrumented Build</strong></p><pre>CC=clang CFLAGS=&quot;-O2 -fprofile-instr-generate -march=native&quot; \<br>LDFLAGS=&quot;-fprofile-instr-generate&quot; \<br>./configure --prefix=/opt/gm_instr --disable-shared --enable-static \<br> &amp;&amp; make \<br> &amp;&amp; make install</pre><p><strong>Profile Collection &amp; Merge</strong></p><p>Run the instrumented binary over the 80 profiling images, then merge the raw .profraw files into a single indexed profile:</p><pre>LLVM_PROFILE_FILE=&quot;/opt/gm_profraw/gm-%p.profraw&quot; \<br> /opt/gm_instr/bin/gm mogrify -resize &quot;50%&quot; \<br>  -unsharp 1.5x1.0+1.5+0.02 -quality 88 \<br>  -format jpg &quot;/tmp/images/*.jpg&quot;</pre><pre>llvm-profdata merge \<br>-output=/opt/gm.profdata /opt/gm_profraw/*.profraw</pre><p><strong>Final PGO Build (based on profiling data)</strong></p><p>Recompile with -O3 and feed the merged profile back into Clang so LLVM can attach <a href="https://llvm.org/docs/BranchWeightMetadata.html">branch-weight metadata</a> during optimization:</p><pre>CC=clang CFLAGS=&quot;-O3 -fprofile-instr-use=/opt/gm.profdata -march=native&quot; \<br>LDFLAGS=&quot;-fprofile-instr-use=/opt/gm.profdata&quot; \<br>./configure --prefix=/opt/gm_optimized --disable-shared --enable-static \<br>&amp;&amp; make &amp;&amp; make install</pre><h3>Platform Execution Time Results</h3><p>Across every tested Google Cloud VM family, Clang PGO delivered nearly identical 1.23x-1.26x speedups on both the 80-image profiling set and the 20-image unseen holdout set:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zm6Q0FdWIxtTzQtGaijV6A.png" /><figcaption>Total batch runtime across 5 GCP VM families (80-image profiling set vs. 20-image holdout set)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vKFTj0G_6B1_VDDnkx-68w.png" /><figcaption>Average per-image runtime across fiveGCP VM families — showing performance on holdout images matches expectations</figcaption></figure><p>Total execution time for profiling and holdout datasets with baseline → PGO optimized build:</p><p><a href="https://docs.cloud.google.com/compute/docs/general-purpose-machines#c4_series"><strong>c4-standard-4</strong></a><strong> (Intel Emerald Rapids)</strong></p><ul><li>Profiling (80 images): 142.5s → 113.2s (1.26x faster)</li><li>Holdout (20 images): 35.8s → 28.5s (1.26x<strong> </strong>faster)</li></ul><p><a href="https://docs.cloud.google.com/compute/docs/general-purpose-machines#c4a_series"><strong>c4a-standard-4</strong></a><strong> (Google Axion / Arm Neoverse V2)</strong></p><ul><li>Profiling (80 images): 148.2s → 118.9s (1.25x<strong> </strong>faster)</li><li>Holdout (20 images): 37.3s → 29.9s (1.25x faster)</li></ul><p><a href="https://docs.cloud.google.com/compute/docs/general-purpose-machines#n4a_series"><strong>n4a-standard-4</strong></a><strong> (Google Axion / Arm Neoverse N3)</strong></p><ul><li>Profiling (80 images): 155.4s → 124.8s (1.25x faster)</li><li>Holdout (20 images): 39.0s → 31.3s (1.25x faster)</li></ul><p><a href="https://docs.cloud.google.com/compute/docs/general-purpose-machines#n4d_series"><strong>n4d-standard-4</strong></a><strong> (AMD EPYC Turin)</strong></p><ul><li>Profiling (80 images): 160.4s → 129.9s (1.23x faster)</li><li>Holdout (20 images): 40.2s → 32.6s (1.23x faster)</li></ul><p><a href="https://docs.cloud.google.com/compute/docs/general-purpose-machines#n4_series"><strong>n4-standard-4</strong></a><strong> (Intel Emerald Rapids)</strong></p><ul><li>Profiling (80 images): 168.0s → 136.1s (1.23x faster)</li><li>Holdout (20 images): 42.1s → 34.1s (1.23x faster)</li></ul><h3>Microarchitectural peek</h3><p>To see <em>why</em> PGO sped up runtime by ~1.25x, we collected hardware performance counters using <a href="https://perfwiki.github.io/main/tutorial/#counting-with-perf-stat">perf stat</a> on the C4 and C4A VMs where hardware PMU telemetry is exposed:</p><p><strong>c4-standard-4 (Intel Emerald Rapids)</strong></p><ul><li><strong>IPC (Instructions Per Cycle):</strong> 1.42 → 1.78 (<strong>+25%</strong>)</li><li><strong>Branch Miss Rate:</strong> 4.82% → 2.15% (<strong>-55%</strong>)</li></ul><p><strong>c4a-standard-4 (Google Axion / Arm Neoverse V2)</strong></p><ul><li><strong>IPC (Instructions Per Cycle):</strong> 1.38 → 1.71 (<strong>+24%</strong>)</li><li><strong>Branch Miss Rate:</strong> 4.75% → 2.10% (<strong>-56%</strong>)</li></ul><p>Using the gathered profile, Clang inlines hot paths, moves cold code out of hot loops and optimizes data dependent branches, resulting in higher IPC and lower branch mispredictions.</p><h3>Key Takeaways</h3><ol><li><strong>Clang PGO helped deliver a 1.25x speedup </strong>on an image transformation workload, holding steady across x86 (Intel, AMD) and Arm (Google Axion) VMs.</li><li><strong>Gains generalize to unseen inputs:</strong> The 20-image holdout set matched the 80-image profiling set across all platforms.</li></ol><h3>Appendix — Future work</h3><ul><li>Would be interesting to next explore `-fprofile-generate` for lower overhead profiling, paired with ThinLTO (-flto=thin) to unlock profile-guided inlining across source files which will likely yield even better performance.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d395a3bbb73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using llvm-mca to make sense of a Go memmove optimization by Gemini]]></title>
            <link>https://medium.com/@fruitcup/using-llvm-mca-to-make-sense-of-a-go-memmove-optimization-by-gemini-88b90919a76a?source=rss-beeeb91d3505------2</link>
            <guid isPermaLink="false">https://medium.com/p/88b90919a76a</guid>
            <category><![CDATA[llvm]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[gemini]]></category>
            <dc:creator><![CDATA[Edwin Chiu]]></dc:creator>
            <pubDate>Tue, 24 Nov 2026 11:01:01 GMT</pubDate>
            <atom:updated>2026-11-24T11:01:01.600Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kXSAUxSFGcmViIpAhIiEiQ.jpeg" /></figure><p>Gemini wrote a four-line assembly change to Go’s arm64 memmove that reduced the time of some 128-byte copies up to 27% on Google Axion C4A VMs (Neoverse V2). The change landed in both Go (<a href="https://github.com/golang/go/commit/575a9bd2ac6bda1db130c5474d85abcf37260c17">575a9bd2ac</a>) and Arm’s optimized routines repo (<a href="https://github.com/ARM-software/optimized-routines/commit/2ee4b0d45680a9880412c1d186224b08652c35f6">2ee4b0d456</a>). Special thanks to <a href="https://github.com/Wilco1">Wilco1</a> for their expert review and confirmation of the optimization.</p><p>Afterwards, I wanted to better understand how the optimization worked and turned to <a href="https://llvm.org/docs/CommandGuide/llvm-mca.html">llvm-mca</a>, which is a tool that simulates how a CPU will execute instructions.</p><h3>The optimization</h3><p><strong>Before optimization</strong></p><pre>copy128:<br> FLDPQ 32(src), (E_q, F_q)<br> CMP $96, count<br> BLS copy96<br> FLDPQ -64(srcend), (G_q, H_q)<br> FSTPQ (G_q, H_q), -64(dstend)<br>copy96:<br> FSTPQ (A_q, B_q), (dstin)<br> FSTPQ (E_q, F_q), 32(dstin)<br> FSTPQ (C_q, D_q), -32(dstend)<br> RET</pre><p><strong>After optimization</strong></p><pre>copy128:<br> FLDPQ 32(src), (E_q, F_q)<br> CMP $96, count<br> BLS copy96<br> FLDPQ -64(srcend), (G_q, H_q)<br> FSTPQ (A_q, B_q), (dstin)<br> FSTPQ (E_q, F_q), 32(dstin)<br> FSTPQ (G_q, H_q), -64(dstend)<br> FSTPQ (C_q, D_q), -32(dstend)<br> RET<br>copy96:<br> FSTPQ (A_q, B_q), (dstin)<br> FSTPQ (E_q, F_q), 32(dstin)<br> FSTPQ (C_q, D_q), -32(dstend)<br> RET</pre><p><strong>Result</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UryEqQkaRebpxx3jc7CSdw.png" /><figcaption>128-byte copy latency on Google Axion C4A (Neoverse V2), benchstat median of 8 runs</figcaption></figure><h3>Exploring with llvm-mca</h3><p>We explore the execution with llvm-mca and visualize with Gemini</p><pre>llvm-mca -mtriple=aarch64 -mcpu=neoverse-v2 -iterations=1 -timeline data/old.s</pre><p>Gemini then helped me take the output and generate a nice graphic</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pYTSE6CamoPY4bTVJidXqg.png" /><figcaption>Side-by-side llvm-mca execution timelines before and after optimization</figcaption></figure><p>From llvm-mca, we expect a 1 cycle savings per copy based on the instruction optimization above.</p><p><strong>Understanding the optimization by looking at the llvm-mca timeline</strong></p><p>(in llvm-mca, map registers A_q..H_q → q0..q7)</p><p>On the left, the store of q6, q7 waits for its load until cycle 11. In llvm-mca&#39;s model a store can&#39;t start before an earlier store, so the store of q0, q1 can&#39;t start before it either, even though its data was ready at cycle 8.</p><p>Once the load lands, all four stores are ready at once. Each one ties up one of the two vector store-data pipes for 2 cycles, so they go out in two waves, at cycles 11 and 13.</p><p>On the right (optimized code), the two stores ahead of the q6, q7 store already have their data, so they go at cycles 8 and 10, while the last load is still in flight. When it lands, one pipe is still busy with the q4, q5 store, so the last two go at cycles 11 and 12, one cycle sooner than on the left.</p><p><strong>Improvement of 27% far exceeded expected 5.9% gain</strong></p><p>A one cycle improvement from 17 cycles to 16 cycles is roughly 5.9%. However, we achieved a much larger gain of 27%.</p><p>I asked Gemini for the likely reason:</p><blockquote>llvm-mca models the in-core execution pipeline, not the memory hierarchy.</blockquote><blockquote>Writing the four chunks in ascending address order keeps consecutive stores on the same 64-byte cache line together so the store buffer can merge them into fewer L1D write transactions, avoiding the store-buffer drain stalls caused by the old order jumping across cache lines on unaligned destinations.</blockquote><p>Seems plausible. Validation is left as an exercise to the reader :)</p><p>llvm-mca won&#39;t replace benchmarking on real hardware—its model stops at the core boundary and real-world gains may be larger (or smaller) than the simulated cycle count. However, it is a fast, hardware-free feedback loop for AI agents: an agent can test scheduling ideas in milliseconds, explain <em>why</em> a change should help, and focus real-hardware benchmarking on the candidates that matter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88b90919a76a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beyond grep for coding agents]]></title>
            <link>https://medium.com/@fruitcup/beyond-grep-for-coding-agents-c2cb251b3ffb?source=rss-beeeb91d3505------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2cb251b3ffb</guid>
            <category><![CDATA[gemini-cli]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Edwin Chiu]]></dc:creator>
            <pubDate>Thu, 25 Jun 2026 10:36:00 GMT</pubDate>
            <atom:updated>2026-06-25T10:36:00.855Z</atom:updated>
            <content:encoded><![CDATA[<p>For AI agents operating in codebases of all sizes, we want to be efficient with our token usage, not just for costs, but for time and performance.</p><p>Recently I was using Gemini CLI to ask a simple question of how reconciler backoff worked and what options were available to me in the controller-runtime package.</p><p>I watched fascinated as it used a loop of grep, sed and built in read_file tool to walk through the codebase and I instinctively frowned. While this worked, I was sure there was a better way.</p><h3><strong>Introducing ast-grep</strong></h3><p>Unlike line-oriented tools, ast-grep operates directly on the Abstract Syntax Tree (AST). This enables agents to target, analyze, and transform specific syntax nodes with high precision, ensuring context windows are populated only with the logical constructs required for the task.</p><p>Integrating structural search and manipulation enables deterministic code navigation and editing. This flattens the marginal cost of multi-file refactoring and improves reasoning accuracy by providing cleaner, structured input to the model.</p><p>I had Gemini evaluate the scenarios with and without the ast-grep skill enabled to compare the token costs:</p><h3>Scenario 1: Text-based search (rg + read_file)</h3><p>Text-based tools lack semantic awareness of code structure. In a complex framework like controller-runtime, keyword-based searches for common terms result in high-volume, low-signal payloads.</p><ul><li><strong>Step 1:</strong> rg -i “backoff” pkg/, Extracts roughly 20 noisy lines (~250 tokens)</li><li><strong>Step 2:</strong> read_file on pkg/reconcile/reconcile.go to grasp the basic interface contract (~500 tokens)</li><li><strong>Step 3:</strong> rg -C 5 “Reconcile” pkg/internal/controller/ to locate the actual execution loop. Because “Reconcile” is ubiquitous, the agent receives a massive dump of tests, mocks, and variable declarations (~1,200 tokens)</li><li><strong>Step 4:</strong> rg -C 5 “RateLimiter” pkg/controller/ to find default configurations, resulting in another flooded payload (~1,000 tokens)</li></ul><h3>Scenario 2: AST-based search (ast-grep)</h3><p>By leveraging AST pattern matching, the agent executes precise queries and transformations that isolate definitions or function bodies, eliminating textual noise and preventing accidental side effects during editing.</p><ul><li><strong>Overhead:</strong> The agent must first read SKILL.md to understand how to format ast-grep queries (~1,800 tokens)</li><li><strong>Step 1:</strong> sg run -p ‘RateLimiter: $VAL’ Instantly finds exact structural assignments of the rate limiter (~150 tokens)</li><li><strong>Step 2:</strong> sg run -p ‘func DefaultTypedControllerRateLimiter($$$) { $$$ }’ Returns strictly the function signature and body, completely ignoring tests and documentation (~200 tokens)</li><li><strong>Step 3 (The Guess):</strong> Finding the execution loop via func (c *Controller[R])reconcileHandler($$) { $$$ }</li><li>Failed attempt (syntax mismatch): ~100 tokens + 1 extra turn</li><li>Successful correction: Returns exactly the method body (~300 tokens)</li></ul><h3><strong>Efficiency of ast-grep</strong></h3><ul><li>Without ast-grep, I used roughly 2950 tokens, with ast-grep I used 2550 tokens</li><li>Without ast-grep, each search used between 250 and 1200 tokens</li><li>With ast-grep, each search used between 150–300 tokens</li><li>The primary overhead of ast-grep was the loading of the skill (roughly 1800 tokens)</li></ul><p>While the initial overhead of loading the ast-grep skill (1,800 tokens) eats into the immediate savings, the long-term ROI for complex tasks is undeniable. In multi-step workflows, the drastic reduction in per-search tokens compounds quickly.</p><p>More importantly, this structural precision prevents context pollution, which will fundamentally improve the agent’s reasoning speed and accuracy.</p><h3><strong>More than a search tool</strong></h3><p>The benefits of using an AST aware tool go beyond reading code, it extends to editing and updating code, allowing for agents to perform more deterministic editing.</p><p>AST based editing understands scopes, syntax (function names vs variables, etc) and can perform more intelligent refactoring. One such use case is addressing API deprecations and automating changes across hundreds or thousands of files much more efficiently.</p><h3>Further reading</h3><p>Following the use of ast-grep, I learned about the tree-sitter library that ast-grep uses and an interesting looking skill that uses tree-sitter as well:</p><ul><li><a href="https://github.com/vudovn/ag-kit/blob/main/.agents/skills/code-review-graph/SKILL.md?plain=1">Token-efficient code review skill using Tree-sitter AST graphs and MCP</a></li><li>Tree Sitter — <a href="https://tree-sitter.github.io/tree-sitter/">https://tree-sitter.github.io/tree-sitter/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2cb251b3ffb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging Assembly: How Gemini helped us root cause a production issue]]></title>
            <link>https://medium.com/@fruitcup/debugging-assembly-how-gemini-helped-us-root-cause-a-production-issue-e981529686f9?source=rss-beeeb91d3505------2</link>
            <guid isPermaLink="false">https://medium.com/p/e981529686f9</guid>
            <category><![CDATA[assembly-language]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[gemini]]></category>
            <dc:creator><![CDATA[Edwin Chiu]]></dc:creator>
            <pubDate>Mon, 02 Mar 2026 11:26:00 GMT</pubDate>
            <atom:updated>2026-03-02T11:26:00.537Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, we faced a critical issue where the trail led directly to <a href="https://go.dev/src/runtime/memmove_amd64.s">memmove.s</a> — the low-level assembly implementation behind Go’s copy() function on AMD64.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*lBOz2xSga7s5Pnyb-XDlhg.png" /></figure><p>When you’re in the middle of a production incident, you don’t have hours to learn x86–64 assembly and (painfully?) step through each instruction. This is where Gemini proved to be more than capable of interpreting and summarizing assembly code, a leap forward from the typical languages most programmers would use.</p><h3>The Challenge: Unwinding the complexity of assembly instructions</h3><p>Go’s <a href="https://go.dev/src/runtime/memmove_amd64.s">memmove</a> is not just a loop that copies bytes. It is a highly tuned, CPU-feature-aware routine that represents decades of performance engineering. It handles everything from tiny 1-byte copies to multi-megabyte moves, each with a different strategy:</p><ul><li><strong>Small Sizes (0–256 bytes):</strong> It avoids loops entirely, using a “straight-line” approach with direct register moves.</li><li><strong>Medium Sizes (256B to 2KB):</strong> It shifts to using SIMD (Single Instruction, Multiple Data) registers (<em>XMM</em> for SSE or <em>YMM</em> for AVX). This allows the CPU to move 16 or 32 bytes in a single instruction.</li><li><strong>Large Moves (&gt;2KB):</strong> It dynamically chooses between hardware-accelerated instructions like <em>REP MOVSQ </em>or 256-bit AVX extensions.</li><li><strong>Huge Data (&gt;1MB):</strong> It uses “non-temporal” hints to bypass the CPU cache entirely, preventing “cache pollution” that would slow down the rest of your program</li></ul><p>During a production incident, it’s easy to overlook the details and nuances of assembly unless you are familiar with the code or assembly language.</p><h3>Gemini to the rescue</h3><p>We turned to Gemini to help us interpret the implementation quickly and concisely. The results were eye opening to understand the issue at hand.</p><p>We asked Gemini 3 Flash to explain memmove.s and we quickly received a high-level overview in seconds. It correctly identified the various optimization scenarios and differences depending on the size of data being copied in a clear and concise manner.</p><p>Gemini 3 Flash provided a detailed yet concise summary that correctly identified the use of AVX for larger blocks and explained the “tail” strategy — handling the remaining bytes of a copy — with high precision.</p><p>This ability to parse low-level assembly into a high-level logic map proved invaluable. It enabled us to bypass the need to understand assembly and instead spend minutes verifying a comprehensive summary against the source.</p><h3>Test reproduction</h3><p>When it comes to debugging an issue, a small reproducible test case is also important when asking for help. This helps others to participate easily and rapidly debug the issue allowing us to iterate quickly on different theories, potential mitigations and fixes.</p><p>Now that we had a good working theory of the problem, we were able to quickly come up with a small reproducible test case. Here Gemini helped us quickly write a small Golang program that we were able to share with teams to help debug the issue.</p><h3>A comparative look at other frontier models</h3><p>A few days later I was curious on how other frontier models might perform when examining assembly code.</p><p>I tested several “frontier” models (anonymized to protect the innocent) and found varying levels of technical accuracy, here are some relevant snippets of output that were good/bad:</p><h3><strong>Model 1</strong></h3><blockquote><strong>Medium Sizes (257–2048 bytes)</strong></blockquote><blockquote>* Uses XMM registers (128-bit SSE)<br> * Copies in 256-byte chunks when possible<br> * For overlapping regions, checks if overlap exists and switches to backward copy if needed</blockquote><p><strong>Issue(s): </strong>Failed to recognize use of AVX at 256–2048 size</p><h3><strong>Model 2</strong></h3><blockquote>In human terms:<br> * Tiny copy? → straight register move<br> * Medium copy? → SSE unrolled loops<br> * Large copy? → AVX with alignment tricks<br> * Huge copy? → non-temporal AVX streaming<br> * Overlap? → reverse direction safely</blockquote><p><strong>Issue(s): </strong>Failed to identify where AVX was used, abstraction of size (tiny, medium, large, huge) was not helpful</p><p>NB: Medium in this case was 256–2048 bytes, which was buried somewhere in the response</p><h3>Popular AI search engine</h3><blockquote>The function dynamically selects the fastest approach for the situation:<br> 1. Small sizes: Use in-register moves (no loops).<br> 2. Medium sizes (≤2 KB): Use SSE unrolled loops for throughput.<br> 3. Large sizes (≥2 KB): Prefer REP MOVSQ or AVX loops depending on hardware flags.<br> 4. Very large (≥1 MB): Use non-temporal writes plus prefetching for bulk memory transfer.<br> 5. Overlap: Reverse direction to preserve correctness.</blockquote><p><strong>Issues(s): </strong>Failed to recognize use of AVX at 256–2047 size. Provided reference for size (e.g. medium ≤ 2KB). The unit “KB” is not accurate, “KiB” would have been better. IMO a range would make it more clear as well.</p><h3>Takeaway</h3><p>Using Gemini didn’t just explain the code; it gave us the ideal concise summary of the code. Instead of potentially spending an hour (or more?) reading the memmove.s source file, we spent minutes verifying the Gemini’s summary against the code.</p><h3>Related</h3><ul><li><a href="https://github.com/golang/go/issues/49063">https://github.com/golang/go/issues/49063</a></li><li><a href="https://github.com/torvalds/linux/commit/ebec25438f3dbc79ea1ff274b1fe97d277b1545f">https://github.com/torvalds/linux/commit/ebec25438f3dbc79ea1ff274b1fe97d277b1545f</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e981529686f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Further explorations in GCP Axion performance with ffmpeg]]></title>
            <link>https://medium.com/@fruitcup/further-explorations-in-gcp-axion-performance-with-ffmpeg-127e12826f30?source=rss-beeeb91d3505------2</link>
            <guid isPermaLink="false">https://medium.com/p/127e12826f30</guid>
            <category><![CDATA[google-compute-engine]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[ffmpeg]]></category>
            <category><![CDATA[axion]]></category>
            <category><![CDATA[arm]]></category>
            <dc:creator><![CDATA[Edwin Chiu]]></dc:creator>
            <pubDate>Tue, 24 Feb 2026 12:06:00 GMT</pubDate>
            <atom:updated>2026-02-24T12:06:00.875Z</atom:updated>
            <content:encoded><![CDATA[<p>We further explore the performance of C4A and N4A GCP Axion instances and examine the possible role of compilers for easy optimization wins.</p><h3>FFmpeg transcoding</h3><p>FFmpeg is a free and popular open-source software suite of libraries and programs used for handling, processing, and manipulating multimedia files, including video, audio, and images.</p><h3>Benchmark</h3><p>We decide to transcode a 1 min 4k video clip of <a href="https://peach.blender.org/">Big Buck Bunny</a> to 1080p using VP9 as the video codec. This is a fairly intensive compute bound workload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n_PO89DNk3Wqau4H7FTLuQ.png" /><figcaption>ref: <a href="https://storage.googleapis.com/fruitcup-medium/bbb_sunflower_4k_clip.mp4">https://storage.googleapis.com/fruitcup-medium/bbb_sunflower_4k_clip.mp4</a></figcaption></figure><h3>Results</h3><p><strong>C4A results</strong></p><pre>hyperfine -w1 -m 10 &#39;ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libx265 -preset medium -crf 25 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4&#39;<br>Benchmark 1: ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4<br>  Time (mean ± σ):     237.008 s ±  0.531 s    [User: 422.759 s, System: 1.000 s]<br>  Range (min … max):   236.358 s … 237.694 s    10 runs</pre><p><strong>N4A Results</strong></p><pre>hyperfine -w1 -m 10 &#39;ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libx265 -preset medium -crf 25 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4&#39;<br>Benchmark 1: ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4<br>  Time (mean ± σ):     276.035 s ±  0.290 s    [User: 496.059 s, System: 0.563 s]<br>  Range (min … max):   275.527 s … 276.456 s    10 runs</pre><p><strong>5th gen Xeon Scalable Emerald Rapids</strong></p><pre>$ hyperfine -w1 -m10 &#39;ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4&#39;<br>Benchmark 1: ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4<br>  Time (mean ± σ):     324.581 s ±  0.636 s    [User: 594.793 s, System: 1.624 s]<br>  Range (min … max):   323.334 s … 325.474 s    10 runs</pre><p><strong>Pretty good right?</strong></p><p>First place to C4A at ~237s, second place to N4A at 276s and last place to our x86 instance at 324s</p><h3>But can do better?</h3><p>Looking at the version of ffmpeg that comes with Debian 12 bookworm seems pretty new? Or is it.</p><pre>ffmpeg version 5.1.7-0+deb12u1 Copyright (c) 2000-2025 the FFmpeg developers</pre><ul><li>5.1.7 is actually quite old, it’s an LTS release first released in 5.1 and updated throughout the years</li><li>The latest release is 8.0</li></ul><p>Using prebuilt binaries to compare</p><ul><li>ARM Build: <a href="https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2025-09-30-13-19/ffmpeg-N-121271-g74115b017c-linuxarm64-gpl.tar.xz">https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2025-09-30-13-19/ffmpeg-N-121271-g74115b017c-linuxarm64-gpl.tar.xz</a></li><li>x86-64: <a href="https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2025-09-30-13-19/ffmpeg-N-121271-g74115b017c-linux64-gpl.tar.xz">https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2025-09-30-13-19/ffmpeg-N-121271-g74115b017c-linux64-gpl.tar.xz</a></li></ul><h3>Results — round 2</h3><p><strong>C4A</strong></p><pre>$ hyperfine -w1 -m10 &#39;./ffmpeg-N-121271-g74115b017c-linuxarm64-gpl/bin/ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4&#39;<br>Benchmark 1: ./ffmpeg-N-121271-g74115b017c-linuxarm64-gpl/bin/ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4<br>  Time (mean ± σ):     178.649 s ±  0.429 s    [User: 315.854 s, System: 1.317 s]<br>  Range (min … max):   178.190 s … 179.464 s    10 runs</pre><p><strong>N4A</strong></p><pre>$ hyperfine -w1 -m10 &#39;./ffmpeg-N-121271-g74115b017c-linuxarm64-gpl/bin/ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4&#39;<br>Benchmark 1: ./ffmpeg-N-121271-g74115b017c-linuxarm64-gpl/bin/ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4<br>  Time (mean ± σ):     199.595 s ±  0.596 s    [User: 353.325 s, System: 0.660 s]<br>  Range (min … max):   198.482 s … 200.738 s    10 runs</pre><p><strong>5th gen Xeon Scalable Emerald Rapids</strong></p><pre>$ hyperfine -w1 -m10 &#39;./ffmpeg-N-121271-g74115b017c-linux64-gpl/bin/ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4&#39;<br>Benchmark 1: ./ffmpeg-N-121271-g74115b017c-linux64-gpl/bin/ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4<br>  Time (mean ± σ):     266.352 s ±  8.607 s    [User: 484.395 s, System: 1.461 s]<br>  Range (min … max):   255.912 s … 280.088 s    10 runs</pre><p>All machines benefited greatly with the newer version</p><ul><li>C4A improved ~25% to 178s from 237s</li><li>N4A improved ~27% to 199s from 276s</li><li>N4A improved ~18% to 266s from 324s</li></ul><p>Upgrading FFmpeg to the latest version offers substational performance gains across the board.</p><h3>What if?</h3><p>That got me thinking a bit, what if we recompile the binaries for architectural specific optimizations?</p><p>e.g. C4A uses the Neoverse V2 core using Arm ISA 9.0-A and N4A uses the Neoverse N3 core using Arm ISA 9.2-A</p><h3>Recompiling from Source</h3><p>Source: <a href="https://github.com/BtbN/FFmpeg-Builds/archive/refs/tags/autobuild-2025-09-30-13-19.tar.gz">https://github.com/BtbN/FFmpeg-Builds/archive/refs/tags/autobuild-2025-09-30-13-19.tar.gz</a></p><p>We rebuild binaries for</p><ul><li>C4A — Replace cpu=armv8-a with cpu=neoverse-v2</li><li>N4A — Replace cpu=armv8-a with cpu=armv9–2</li></ul><h3>Results</h3><p>C4A</p><pre>Benchmark 1: ./ffmpeg-N-121749-g203c6a93d7-linuxarm64-gpl/bin/ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4<br>  Time (mean ± σ):     178.905 s ±  0.129 s    [User: 315.805 s, System: 1.387 s]<br>  Range (min … max):   178.776 s … 179.035 s    3 runs</pre><p>N4A</p><pre>Benchmark 1: ffmpeg-N-121749-g203c6a93d7-linuxarm64-gpl/bin/ffmpeg -i bbb_sunflower_4k_clip.mp4 -c:v libvpx-vp9 -preset fast -crf 29 -c:a aac -b:a 192k -vf scale=1080:-2 -y /tmp/output_vp9.mp4<br>  Time (mean ± σ):     209.352 s ±  0.209 s    [User: 369.528 s, System: 0.863 s]<br>  Range (min … max):   209.229 s … 209.593 s    3 runs</pre><p>🙁</p><p>No difference. This is not all that surprising as FFmpeg has native hand optimized optimizations across both platforms, including Arm SVE2 optimizations.</p><h3>Performance summary</h3><p>The ARM-based C4A and N4A instances consistently outperformed a modern Intel<strong> </strong>Emerald Rapids CPU in this transcoding task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*WaAGDfnOB8S6ESQn9O3Mvw.png" /><figcaption>FFmpeg 5.17 vs 8.0 performance</figcaption></figure><p>In particular, simply moving from the default Debian 12 provided package (v5.1.7) to the latest prebuilt binary (v8.0) provided a massive boost for all architectures:</p><ul><li><strong>C4A (Neoverse V2):</strong> Improved by 25% (237s to 179s)</li><li><strong>N4A (Neoverse N3):</strong> Improved by 27% (276s to 200s)</li><li><strong>5th Gen Xeon:</strong> Improved by 18% (325s to 266s)</li></ul><h3>Conclusions</h3><ul><li>If possible, always use the latest software. While the majority of open source software runs on Axion, we may see optimized code in more recent releases, further cementing Axion’s advantage.</li><li>Do explore compiler optimizations, don’t be discouraged by this result as compiler optimizations can offer (small) incremental gains as well</li></ul><h3>References and further reading</h3><ul><li>Arm® Neoverse™ V2 Core Technical Reference Manual — <a href="https://developer.arm.com/documentation/102375/0002?lang=en">https://developer.arm.com/documentation/102375/0002?lang=en</a></li><li>The Neoverse™ N3 core — <a href="https://developer.arm.com/documentation/107997/0001/The-Neoverse--N3--core">https://developer.arm.com/documentation/107997/0001/The-Neoverse--N3--core</a></li><li>C/C++ on Arm Neoverse processors — <a href="https://learn.arm.com/learning-paths/servers-and-cloud-computing/migration/c">https://learn.arm.com/learning-paths/servers-and-cloud-computing/migration/c</a></li><li>An introduction to autovectorization — <a href="https://learn.arm.com/learning-paths/cross-platform/loop-reflowing/introduction-to-autovectorization/">https://learn.arm.com/learning-paths/cross-platform/loop-reflowing/introduction-to-autovectorization/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=127e12826f30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Initial look at Axion based N4A compute performance]]></title>
            <link>https://medium.com/@fruitcup/initial-look-at-axion-based-n4a-compute-performance-587c33589305?source=rss-beeeb91d3505------2</link>
            <guid isPermaLink="false">https://medium.com/p/587c33589305</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[google-compute-engine]]></category>
            <category><![CDATA[cloud-performance]]></category>
            <category><![CDATA[axion]]></category>
            <dc:creator><![CDATA[Edwin Chiu]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 11:41:00 GMT</pubDate>
            <atom:updated>2026-02-18T11:41:00.792Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>TL;DR:</strong> Google’s new Axion-based N4A instances deliver nearly <strong>2x the raw performance</strong> of comparable current-gen x86 instances in compute-bound image processing tasks, while offering significant sustainability benefits.</p><p>Google Cloud has officially announced the General Availability (GA) of <strong>N4A instances</strong>, marking a significant milestone in the evolution of Google’s custom silicon portfolio.</p><p>Powered by the latest generation of <strong>Google Axion Processors</strong> — built on the <strong>Arm® Neoverse® N3</strong> compute core — the N4A series is designed to redefine infrastructure efficiency for modern enterprise workloads.</p><p>For engineering leaders evaluating migration paths or new architectural standards, the N4A series presents a clear case for adoption.</p><h3>Value Proposition: Why move to Axion?</h3><p>The shift to Google Axion CPUs addresses the “performance vs. cost vs. sustainability” trilemma that often plagues cloud architecture decisions.</p><ul><li><strong>Price-Performance Leadership:</strong> up to <strong>2x better price-performance</strong> compared to equivalent current-gen x86-based virtual machines. Resulting in an immediate reduction in TCO for compute heavy workloads</li><li><strong>Energy Efficiency:</strong> Achieves <strong>80% better performance-per-watt</strong>, providing a more sustainable path for high-density compute requirements without sacrificing performance.</li><li><strong>Architectural:</strong> By leveraging the Neoverse N3 core, these instances provide high-throughput and low-latency performance at a lower cost</li></ul><p>For teams looking to modernize their infrastructure, N4A is a clear and compelling upgrade.</p><h3>Quick look at performance</h3><p>To validate performance gains for compute heavy workloads, we conducted a real-world, compute-bound benchmark using <strong>GraphicsMagick, </strong>a widely used image processing tool in media pipelines.</p><h3>Test Setup</h3><p><strong>Environment</strong></p><ul><li>N4A (Google Axion, Neoverse N3)</li><li>C4A (Google Axion, Neoverse V2)</li><li>x86 Gen 5 Emerald Rapids</li></ul><p><strong>Methodology</strong></p><p>We use the “mogrify” operation in GraphicsMagick to resize a high resolution JPEG from 6240x3512 down to 1024x768. This operation stresses integer performance.</p><ol><li><strong>Prepare the Test Image</strong></li></ol><p>Download a high resolution photo (6240x3512 JPEG):</p><pre>wget -O pexels-photo-17077861.jpeg https://images.pexels.com/photos/17077861/pexels-photo-17077861.jpeg</pre><p><strong>2. Install GraphicsMagick and Hyperfine</strong></p><pre>sudo apt install hyperfine graphicsmagick-imagemagick-compat</pre><p><strong>3. Run a benchmark</strong></p><p>Execute the following command on each of the three instances. This command uses hyperfine to warm up 10 times (-w 10) and measure 100 runs (-m 100) of the gm mogrify resizing operation:</p><pre><br>hyperfine -w 10 -m 100 &#39;gm mogrify -limit memory 2G -limit disk 1 -limit map 1 -colorspace RGB -quality 80 -define jpeg:max-warnings=100 -size 6240x3512 -resize 1024x768 -auto-orient -output-directory /tmp/ pexels-photo-17077861.jpeg&#39;</pre><h3><strong>Benchmark results</strong></h3><p>N4A</p><pre>$ hyperfine -w 10 -m 100 &#39;gm mogrify -limit memory 2G -limit disk 1 -limit map 1 -colorspace RGB -quality 80 -define jpeg:max-warnings=100 -size 6240x3512 -resize 1024x768 -auto-orient -output-directory /tmp/ pexels-photo-17077861.jpeg&#39;<br>Benchmark 1: gm mogrify -limit memory 2G -limit disk 1 -limit map 1 -colorspace RGB -quality 80 -define jpeg:max-warnings=100 -size 6240x3512 -resize 1024x768 -auto-orient -output-directory /tmp/ pexels-photo-17077861.jpeg<br>  Time (mean ± σ):     309.3 ms ±   1.7 ms    [User: 450.1 ms, System: 18.4 ms]<br>  Range (min … max):   306.2 ms … 313.6 ms    100 runs</pre><p>C4A</p><pre>$ hyperfine -w 10 -m 100 &#39;gm mogrify -limit memory 2G -limit disk 1 -limit map 1 -colorspace RGB -quality 80 -define jpeg:max-warnings=100 -size 6240x3512 -resize 1024x768 -auto-orient -output-directory /tmp/ pexels-photo-17077861.jpeg&#39;<br>Benchmark 1: gm mogrify -limit memory 2G -limit disk 1 -limit map 1 -colorspace RGB -quality 80 -define jpeg:max-warnings=100 -size 6240x3512 -resize 1024x768 -auto-orient -output-directory /tmp/ pexels-photo-17077861.jpeg<br>  Time (mean ± σ):     255.4 ms ±   1.0 ms    [User: 369.0 ms, System: 14.7 ms]<br>  Range (min … max):   253.1 ms … 258.6 ms    100 runs</pre><p>x86 Emerald Rapids</p><pre>$ hyperfine -w 10 -m 100 &#39;gm mogrify -limit memory 2G -limit disk 1 -limit map 1 -colorspace RGB -quality 80 -define jpeg:max-warnings=100 -size 6240x3512 -resize 1024x768 -auto-orient -output-directory /tmp/ pexels-photo-17077861.jpeg&#39;<br>Benchmark 1: gm mogrify -limit memory 2G -limit disk 1 -limit map 1 -colorspace RGB -quality 80 -define jpeg:max-warnings=100 -size 6240x3512 -resize 1024x768 -auto-orient -output-directory /tmp/ pexels-photo-17077861.jpeg<br>  Time (mean ± σ):     575.9 ms ±  12.1 ms    [User: 871.4 ms, System: 70.6 ms]<br>  Range (min … max):   553.6 ms … 610.2 ms    100 runs</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*QlMCmyn8Q2R5Bx034o7dLw.png" /></figure><p>Relative to modern x86 Emerald Rapids (575.9ms)</p><ul><li>C4A is <strong>2.25x faster </strong>(255.4ms)</li><li>N4A is <strong>1.86x faster </strong>(309.3ms)</li><li>Smaller carbon footprint? <strong><em>priceless</em></strong></li></ul><h3>Credits</h3><ul><li><em>High resolution photo from:</em><a href="https://www.pexels.com/photo/photo-of-photographic-films-17077861/"><em> https://www.pexels.com/photo/photo-of-photographic-films-17077861/</em></a><em>)</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=587c33589305" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlock Granular CPU Insights: PMU Support on GKE is now generally available]]></title>
            <link>https://medium.com/@fruitcup/unlock-granular-cpu-insights-pmu-support-on-gke-is-now-generally-available-689ea8c54147?source=rss-beeeb91d3505------2</link>
            <guid isPermaLink="false">https://medium.com/p/689ea8c54147</guid>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[gke]]></category>
            <category><![CDATA[intel]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Edwin Chiu]]></dc:creator>
            <pubDate>Thu, 12 Jun 2025 18:13:57 GMT</pubDate>
            <atom:updated>2025-06-12T18:13:57.443Z</atom:updated>
            <content:encoded><![CDATA[<p>When examining workload performance, CPU utilization, a staple of any monitoring dashboard, tells you <em>if</em> your processor is busy, but it doesn’t tell you <em>why</em>. Is the CPU effectively executing instructions, or is it stalled, waiting for memory or contending for resources? Answering these questions has historically required specialized tools and deep expertise.</p><p>With the recent general availability of<a href="https://cloud.google.com/kubernetes-engine/docs/how-to/analyzing-cpu-performance-using-pmu"> <strong>Performance Monitoring Unit (PMU) counters on Google Kubernetes Engine (GKE)</strong></a>, this now gives you direct access to the hardware-level telemetry of your CPU, providing a deeper level of insight into how your workloads interact with the underlying silicon.</p><h3>The Challenge: A Flood of Complex Data</h3><p>The PMU provides access to a collection of hundreds of hardware events that track events within the CPU’s microarchitecture (e.g see <a href="https://en.wikipedia.org/wiki/Golden_Cove#/media/File:Golden_Cove.png">Golden Cove</a>). These events can measure everything from instruction cycles and cache misses to branch prediction failures and much more.</p><p>The sheer volume can be seen in Intel’s performance monitoring event lists, detailing hundreds of events.</p><h4>Example <a href="https://github.com/intel/perfmon/blob/main/EMR/events/emeraldrapids_core.json">Emerald Rapids core</a> events file with 389 events:</h4><pre>❯ cat emeraldrapids_core.json|jq &quot;.Events[].EventName&quot; | wc -l<br>     389<br>❯ cat emeraldrapids_core.json|jq &quot;.Events[].EventName&quot; | head -25<br>&quot;INST_RETIRED.ANY&quot;<br>&quot;INST_RETIRED.PREC_DIST&quot;<br>&quot;CPU_CLK_UNHALTED.THREAD&quot;<br>&quot;CPU_CLK_UNHALTED.REF_TSC&quot;<br>&quot;TOPDOWN.SLOTS&quot;<br>&quot;LD_BLOCKS.ADDRESS_ALIAS&quot;<br>&quot;LD_BLOCKS.STORE_FORWARD&quot;<br>&quot;LD_BLOCKS.NO_SR&quot;<br>&quot;INT_MISC.RECOVERY_CYCLES&quot;<br>&quot;INT_MISC.CLEARS_COUNT&quot;<br>&quot;INT_MISC.UOP_DROPPING&quot;<br>&quot;INT_MISC.MBA_STALLS&quot;<br>&quot;INT_MISC.UNKNOWN_BRANCH_CYCLES&quot;<br>&quot;INT_MISC.CLEAR_RESTEER_CYCLES&quot;<br>&quot;DTLB_LOAD_MISSES.WALK_COMPLETED_4K&quot;<br>&quot;DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4M&quot;<br>&quot;DTLB_LOAD_MISSES.WALK_COMPLETED_1G&quot;<br>&quot;DTLB_LOAD_MISSES.WALK_COMPLETED&quot;<br>&quot;DTLB_LOAD_MISSES.WALK_ACTIVE&quot;<br>&quot;DTLB_LOAD_MISSES.WALK_PENDING&quot;<br>&quot;DTLB_LOAD_MISSES.STLB_HIT&quot;<br>&quot;DTLB_STORE_MISSES.WALK_COMPLETED_4K&quot;<br>&quot;DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M&quot;<br>&quot;DTLB_STORE_MISSES.WALK_COMPLETED_1G&quot;<br>&quot;DTLB_STORE_MISSES.WALK_COMPLETED&quot;</pre><p>Making sense of individual events like “INT_MISC.UOP_DROPPING” requires deep knowledge of CPU microarchitecture. This raw data presents a challenge: how do you translate these low-level events into high-level, actionable insights without deep knowledge of CPU microarchitecture?</p><h3><strong>Solution: Top-Down Analysis with Intel PerfSpect and Prometheus</strong></h3><p>Rather than analyze individual events in isolation, we look to use a structured methodology from Intel, called <a href="https://www.intel.com/content/www/us/en/docs/vtune-profiler/cookbook/2023-0/top-down-microarchitecture-analysis-method.html"><strong>Top-Down Microarchitecture Analysis (TMA)</strong></a>. TMA categorizes CPU pipeline behavior into a simple hierarchy, with the first level being:</p><ul><li><strong>Retiring:</strong> The CPU is efficiently executing instructions. This is the “good” state.</li><li><strong>Front-End Bound:</strong> The CPU is starved for instructions and cannot fetch them fast enough.</li><li><strong>Back-End Bound:</strong> The core is stalled, often waiting for data from memory or for an execution unit to become available.</li><li><strong>Bad Speculation:</strong> The CPU wasted effort executing instructions that were ultimately not needed due to branch misprediction.</li></ul><p>We will look to deploy <a href="https://github.com/intel/PerfSpect"><strong>Intel PerfSpect</strong></a>, an open-source tool that automates PMU metric data collection and analysis, including TMA metrics.</p><h4>Useful metrics predefined in PerfSpect</h4><p>PerfSpect provides us with a number of predefined metrics that are derived from raw events.</p><p>For example “TMA_Retiring_(%)” is calculated based on the following expression:</p><pre>&quot;expression&quot;: &quot;100 * ( [PERF_METRICS.RETIRING] / <br>( [PERF_METRICS.FRONTEND_BOUND] + [PERF_METRICS.BAD_SPECULATION] <br>  + [PERF_METRICS.RETIRING] + [PERF_METRICS.BACKEND_BOUND] ) )&quot;</pre><h4>Prometheus compatible metrics endpoint</h4><p>More <a href="https://github.com/intel/PerfSpect/commit/8661c5f99533cbb9a08f246e3826e24add9445d4">recently</a> PerfSpect can now be seamlessly integrated into your cloud-native monitoring stack by exposing a Prometheus compatible metrics endpoint. We now have a convenient and scalable method to expose TMA metrics for any Kubernetes cluster with PMU enabled nodes.</p><h3>Adding cluster-wide per core PMU metrics with Google Kubernetes Engine (GKE)</h3><h4>Example Deployment in GKE</h4><p><strong>Step 1: </strong>Create a GKE Standard Cluster with C4 machines (Intel Emerald Rapids or newer) with PMU enabled: <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/analyzing-cpu-performance-using-pmu.md">https://cloud.google.com/kubernetes-engine/docs/how-to/analyzing-cpu-performance-using-pmu.md</a></p><pre>CLUSTER_NAME=cluster-vpmu<br>MACHINE_TYPE=c4-standard-4<br>PMU_LEVEL=standard<br><br>gcloud container clusters create ${CLUSTER_NAME} \<br>  --performance-monitoring-unit=${PMU_LEVEL} \<br>  --machine-type=${MACHINE_TYPE} \<br>  --region &quot;us-central1&quot; --num-nodes &quot;1&quot;</pre><ul><li>Example cluster using C4-Standard-4 machines with STANDARD level PMU enabled</li></ul><p><strong>Step 2: </strong>Deploy “perfspect.yml” to GKE, which uses a <a href="https://hub.docker.com/repository/docker/fruitcup/perfspect/tags/20250605/sha256-80e81604474a3a854d7f58b135139fb2e441484ac39ecc26eeaccd236778fad7">prebuilt</a> PerfSpect container built on 2025–06–05.</p><pre>apiVersion: apps/v1<br>kind: DaemonSet<br>metadata:<br>  name: perfspect<br>  namespace: default<br>  labels:<br>    name: perfspect<br>spec:<br>  selector:<br>    matchLabels:<br>      name: perfspect<br>  template:<br>    metadata:<br>      labels:<br>        name: perfspect<br>    spec:<br>      containers:<br>      - name: perfspect<br>        image: fruitcup/perfspect:20250605<br>        imagePullPolicy: Always<br>        securityContext:<br>          privileged: true<br>        args:<br>          - &quot;/perfspect&quot;<br>          - &quot;metrics&quot;<br>          - &quot;--log-stdout&quot;<br>          - &quot;--granularity&quot;<br>          - &quot;cpu&quot;<br>          - &quot;--noroot&quot;<br>          - &quot;--interval&quot;<br>          - &quot;15&quot;<br>          - &quot;--prometheus-server-addr&quot;<br>          - &quot;:9090&quot;<br>        ports:<br>        - name: metrics-port # Name of the port, referenced by PodMonitoring<br>          containerPort: 9090 # The port your application inside the container listens on for metrics<br>          protocol: TCP<br>        resources:<br>          requests:<br>            memory: &quot;200Mi&quot;<br>            cpu: &quot;500m&quot;<br><br>---<br>apiVersion: monitoring.googleapis.com/v1<br>kind: PodMonitoring<br>metadata:<br>  name: perfspect-podmonitoring<br>  namespace: default<br>  labels:<br>    name: perfspect<br>spec:<br>  selector:<br>    matchLabels:<br>      name: perfspect<br>  endpoints:<br>  - port: metrics-port<br>    interval: 30s</pre><p><strong>Step 3: </strong>Done! ☕</p><h3>Exploring the new metrics</h3><p>You should now see a number of new metrics in Cloud Monitoring:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DiIBkAP91LUGlqFtZeEsfA.gif" /></figure><h4>Explanation of some of the TMA metrics</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4473f1decf9e1be77accd5e00750a7c6/href">https://medium.com/media/4473f1decf9e1be77accd5e00750a7c6/href</a></iframe><p>With these metrics in your central monitoring system, you can now operate at a fleet level:</p><ul><li><strong>Visualize:</strong> Create cluster-wide dashboards in Grafana or Cloud Monitoring</li><li><strong>Correlate:</strong> e.g. Pinpoint the exact deployment that caused a sudden spike in TMA_Backend_Bound_Percentage, indicating a possible memory access issue.</li><li><strong>Alert:</strong> e.g. Set up alerts to trigger when a critical workload becomes excessively “Front-End Bound,” allowing you to proactively investigate performance regressions.</li></ul><h3>Deploy stress-ng memory read/write test and examining the impact</h3><p><strong>Step 1:</strong> Deploy stress.yml k8s job</p><pre>apiVersion: batch/v1<br>kind: Job<br>metadata:<br>  name: stress<br>spec:<br>  template:<br>    spec:<br>      containers:<br>      - name: stress<br>        image: fruitcup/stress-ng:0.19.01<br>        command: [&quot;/stress-ng&quot;]<br>        args: [&quot;--memrate&quot;, &quot;0&quot;, &quot;--memrate-wr-mbs&quot;, &quot;128000&quot;, &quot;--memrate-rd-mbs&quot;, &quot;128000&quot;, &quot;--timeout&quot;, &quot;600&quot;]<br>      restartPolicy: OnFailure</pre><p><strong>Step 2:</strong> Determine which node the job is running on</p><pre>❯ kubectl describe pod stress-gf6fs |grep -i Node:<br>Node:             gke-cluster-vpmu-default-pool-8329056f-0uqj/10.128.0.55</pre><p><strong>Step 3:</strong> Examining “TMA__Memory_Bound_pct” after stress job is deployed</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fxv14Ks6vly4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dxv14Ks6vly4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fxv14Ks6vly4%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c844bc6b2a83f8cf4c18e7501dc4ca90/href">https://medium.com/media/c844bc6b2a83f8cf4c18e7501dc4ca90/href</a></iframe><p>We can see that after the job is deployed, the “TMA__Memory_Bound_pct” increases dramatically, likely indicating stalls due to cache misses or memory access. This gives us an indication where to look next to determine what is causing the stalls.</p><p>TMA Analysis uses multiple levels of analysis, the first level being: TMA_Retiring_pct, TMA_Frontend_Bound_pct, TMA_Backend_Bound_pct and TMA_Bad_Speculation_pct.</p><p>PerfSpect creates metrics for each level and exposes them depending on your instance shape. The most detailed metrics will be available with GCE VMs supporting ENHANCED level of PMU support, such as C4 with 96 or 192 vCPUs.</p><p>Each level of TMA analysis is indicated with additional “_” after TMA, e.g.</p><pre>TMA_Backend_Bound_pct -&gt; TMA__Memory_Bound_pct -&gt; TMA_____L1_Bound_pct</pre><h3><strong>Conclusion</strong></h3><p>By combining the raw power of PMU events, the structured TMA methodology through PerfSpect, and the cloud-native observability of Prometheus, we can now collect insightful CPU telemetry on GKE nodes.</p><p>This enables you to make data-driven decisions that can lead to significant reductions in infrastructure costs and tangible improvements in application latency and throughput.</p><h3>Topics to explore further</h3><ol><li><strong>Enable PMU on your GKE cluster:</strong><a href="https://cloud.google.com/kubernetes-engine/docs/how-to/analyzing-cpu-performance-using-pmu"> How-to: Analyzing CPU performance using PMU</a></li><li><strong>Explore the analysis tool:</strong><a href="https://github.com/intel/PerfSpect"> Intel PerfSpect on GitHub</a></li><li><strong>Learn more about TMA Analysis:</strong><a href="https://www.intel.com/content/www/us/en/docs/vtune-profiler/cookbook/2023-0/top-down-microarchitecture-analysis-method.html"> Intel’s Top-Down Microarchitecture Analysis Method</a></li><li><strong>Integrate with Google Cloud’s monitoring suite:</strong><a href="https://cloud.google.com/stackdriver/docs/managed-prometheus"> Google Cloud Managed Service for Prometheus</a></li><li><strong>Using Intel vTune to profile application performance: </strong><a href="https://www.intel.com/content/www/us/en/docs/vtune-profiler/cookbook/2025-0/profiling-apps-in-pmu-enabled-google-cloud-vms.html">Profiling Applications in Performance Monitoring Unit (PMU)-Enabled Google Cloud VMs</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=689ea8c54147" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>