<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Systemd on Giedrius Statkevičius</title><link>https://giedrius.blog/categories/systemd/</link><description>Recent content in Systemd on Giedrius Statkevičius</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Fri, 19 Feb 2021 15:13:17 +0000</lastBuildDate><atom:link href="https://giedrius.blog/categories/systemd/feed.xml" rel="self" type="application/rss+xml"/><item><title>Running systemd Units Only If Certain CPU Features Are Available</title><link>https://giedrius.blog/2021/02/19/running-systemd-units-only-if-certain-cpu-features-are-available/</link><pubDate>Fri, 19 Feb 2021 15:13:17 +0000</pubDate><guid isPermaLink="false">https://giedrius.blog/?p=823</guid><description>&lt;figure&gt;
&lt;img loading="lazy" src="https://giedrius.blog/wp-content/uploads/2021/02/systemd-logomark.png"
alt="systemd&amp;#39;s logo (C) https://brand.systemd.io/"/&gt; &lt;figcaption&gt;
&lt;p&gt;systemd&amp;rsquo;s logo (C) &lt;a href="https://brand.systemd.io/"&gt;https://brand.systemd.io/&lt;/a&gt;&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Do you have some kind of application that should only be executed when the user&amp;rsquo;s CPU has a certain feature? Or maybe your application has horrible performance unless some certain instructions are available? As you might know already, the Linux kernel exposes this information via &lt;code&gt;/proc/cpuinfo&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-gdscript3" data-lang="gdscript3"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;processor : &lt;span style="color:#ae81ff"&gt;15&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;vendor_id : AuthenticAMD
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cpu family : &lt;span style="color:#ae81ff"&gt;23&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;model : &lt;span style="color:#ae81ff"&gt;96&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;model name : AMD Ryzen &lt;span style="color:#ae81ff"&gt;7&lt;/span&gt; PRO &lt;span style="color:#ae81ff"&gt;4750&lt;/span&gt;U with Radeon Graphics
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd _apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt;dnowprefetch osvw ibs skinit wdt tce to poext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xge tbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif umip rdpid overflow_recov succor smca
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Where does this data come from? One source of information is the &lt;code&gt;cpuid&lt;/code&gt; instruction. On the x86 architecture systemd starting from v248 is now able to start or stop an unit based on the features exposed by the &lt;a href="https://en.wikipedia.org/wiki/CPUID"&gt;CPUID&lt;/a&gt; instruction. Enter &lt;code&gt;ConditionCPUFeature&lt;/code&gt;. On CPUs that do not have the CPUID instruction i.e. ARM CPUs, it is assumed that the CPU implements no features and thus any potential &lt;em&gt;CPUFeature&lt;/em&gt; conditions will fail.&lt;/p&gt;</description></item></channel></rss>