<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>/dev/urandom thoughts</title>
	<atom:link href="http://philipp.knechtges.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://philipp.knechtges.com</link>
	<description>Just another random blog</description>
	<lastBuildDate>Wed, 29 May 2013 20:38:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Running a Fujitsu ScanSnap S1500 on a CentOS 6 Machine</title>
		<link>http://philipp.knechtges.com/?p=190</link>
		<comments>http://philipp.knechtges.com/?p=190#comments</comments>
		<pubDate>Wed, 29 May 2013 20:38:03 +0000</pubDate>
		<dc:creator>Philipp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://philipp.knechtges.com/?p=190</guid>
		<description><![CDATA[Many people who need a duplex ADF scanner come across the Fujitsu ScanSnap S1500 and so did I. After giving it some thought it ended up being my preferable choice, altough the successor ScanSnap iX500 was already available. This decision &#8230; <a href="http://philipp.knechtges.com/?p=190">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Many people who need a duplex ADF scanner come across the Fujitsu ScanSnap S1500 and so did I. After giving it some thought it ended up being my preferable choice, altough the successor ScanSnap iX500 was already available. This decision was mostly due to the fact that there were reports that indicated SANE-support for S1500, which was unclear for the iX500.</p>
<p>My demands on an ADF scanner setup basically were:</p>
<ul>
<li>It should work together with CentOS 6.</li>
<li>There should be a one-button setup that saves the scanned A4 pages to a predefined Samba share.</li>
<li>Optimally it should autodetect whether it needs to be run in duplex mode.</li>
<li>Automatic OCR embedded in the pdf as an optional nice feature.</li>
</ul>
<p>Regarding the CentOS 6 setup one can say, that the scanner works out of the box. The only minus point is that, as has been indicated <a href="http://thread.gmane.org/gmane.comp.graphics.scanning.sane.devel/19326" target="_blank">here</a>, one has to pass the &#8220;-B&#8221; option to scanimage in order to fix some I/O errors in case of colored duplex mode.</p>
<p>For the one-button setup I used scanbuttond. There seems to be a &#8220;successor&#8221; scanbd, but I didn&#8217;t get it working. As scanbuttond is not provided in any CentOS repository you have to compile it on your own: I downloaded the latest 0.2.3 version, which apparently does not have support for the ScanSnap S1500 since the project is orphaned. Fortunately the Debian project provides a set of patches, where <a href="http://patch-tracker.debian.org/package/scanbuttond/0.2.3.cvs20090713-14" target="_blank">one</a> of them adds support for the scanner.</p>
<p>So in principle one now could write a working one-button-to-pdf script. The missing part with automatically deciding on whether to scan in duplex mode is more tricky and it ended up with a small script I found <a href="http://superuser.com/questions/343385/detecting-blank-image-files">here</a>, which does some sort of auto white page removal. At the moment it is a viable solution, though not a very fast one.</p>
<p>The last point with the automatic OCR is still missing since CentOS does not come with any decent OCR in the repositories. In one way or another it will probably be some combination of tesseract / Ocropus / cuneiform with hocr2pdf, but this is still under investigation.</p>
<p>In the end the script that gets called within buttonpressed.sh is the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">CURDIR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">TMPDIR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">mktemp</span> -d<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">OUT_DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>sambashares<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$TMPDIR</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting Scan:&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==============&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
scanimage <span style="color: #660033;">-b</span> <span style="color: #660033;">-B</span> <span style="color: #660033;">--resolution</span> <span style="color: #000000;">150</span> <span style="color: #660033;">--batch</span>=scan_<span style="color: #000000; font-weight: bold;">%</span>03d.tiff <span style="color: #660033;">--format</span>=tiff \
	<span style="color: #660033;">--mode</span> Color <span style="color: #660033;">--device-name</span> <span style="color: #ff0000;">&quot;fujitsu:ScanSnap S1500:111111&quot;</span> \
	<span style="color: #660033;">-x</span> <span style="color: #000000;">210</span> <span style="color: #660033;">-y</span> <span style="color: #000000;">297</span> <span style="color: #660033;">--brightness</span> +<span style="color: #000000;">10</span> \
	<span style="color: #660033;">--page-width</span> <span style="color: #000000;">210</span> <span style="color: #660033;">--page-height</span> <span style="color: #000000;">297</span> \
	<span style="color: #660033;">--sleeptimer</span> <span style="color: #000000;">1</span> <span style="color: #660033;">--source</span> <span style="color: #ff0000;">&quot;ADF Duplex&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Checking for blank pages:&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;=========================&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;scan_001.tiff&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> scan_<span style="color: #000000; font-weight: bold;">*</span>.tiff; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #007800;">histogram</span>=<span style="color: #000000; font-weight: bold;">`</span>convert <span style="color: #ff0000;">&quot;<span style="color: #007800;">${i}</span>&quot;</span> <span style="color: #660033;">-threshold</span> <span style="color: #000000;">50</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #660033;">-format</span> <span style="color: #000000; font-weight: bold;">%</span>c histogram:info:-<span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #007800;">white</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${histogram}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;white&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">'s/^ *\(.*\):.*$/\1/p'</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #007800;">black</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${histogram}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;black&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">'s/^ *\(.*\):.*$/\1/p'</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #007800;">blank</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=4; <span style="color: #007800;">${black}</span>/<span style="color: #007800;">${white}</span> &lt; 0.005&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lisah</span> <span style="color: #007800;">$i</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${blank}</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${i}</span> seems to be blank - removing it...&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${i}</span>&quot;</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #007800;">OUTPUTNAME</span>=scan_<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d-<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #000000; font-weight: bold;">`</span>.pdf
&nbsp;
tiffcp <span style="color: #660033;">-c</span> lzw scan_<span style="color: #000000; font-weight: bold;">*</span>.tiff allscans.tiff
tiff2pdf <span style="color: #660033;">-z</span> <span style="color: #660033;">-p</span> A4 allscans.tiff <span style="color: #000000; font-weight: bold;">&gt;</span> out.pdf
<span style="color: #c20cb9; font-weight: bold;">gs</span>      <span style="color: #660033;">-q</span> <span style="color: #660033;">-dNOPAUSE</span> <span style="color: #660033;">-dBATCH</span> <span style="color: #660033;">-dSAFER</span> \
        <span style="color: #660033;">-sDEVICE</span>=pdfwrite \
        <span style="color: #660033;">-dCompatibilityLevel</span>=<span style="color: #000000;">1.3</span> \
        <span style="color: #660033;">-dPDFSETTINGS</span>=<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">screen</span> \
        <span style="color: #660033;">-dEmbedAllFonts</span>=<span style="color: #c20cb9; font-weight: bold;">true</span> \
        <span style="color: #660033;">-dSubsetFonts</span>=<span style="color: #c20cb9; font-weight: bold;">true</span> \
        <span style="color: #660033;">-dColorImageDownsampleType</span>=<span style="color: #000000; font-weight: bold;">/</span>Bicubic \
        <span style="color: #660033;">-dColorImageResolution</span>=<span style="color: #000000;">300</span> \
        <span style="color: #660033;">-dGrayImageDownsampleType</span>=<span style="color: #000000; font-weight: bold;">/</span>Bicubic \
        <span style="color: #660033;">-dGrayImageResolution</span>=<span style="color: #000000;">300</span> \
        <span style="color: #660033;">-dMonoImageDownsampleType</span>=<span style="color: #000000; font-weight: bold;">/</span>Bicubic \
        <span style="color: #660033;">-dMonoImageResolution</span>=<span style="color: #000000;">300</span> \
        <span style="color: #660033;">-sOutputFile</span>=<span style="color: #007800;">$OUTPUTNAME</span> \
        out.pdf
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #007800;">$OUTPUTNAME</span> <span style="color: #007800;">$OUT_DIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$OUTPUTNAME</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chown</span> smbuser:smbuser <span style="color: #007800;">$OUT_DIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$OUTPUTNAME</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$CURDIR</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #800000;">${TMPDIR}</span></pre></div></div>

<p lang="bash">Just a few last remarks on the script:</p>
<ul>
<li>You have to get the scaner ID from &#8220;scanimage -L&#8221; and replace it accordingly in the scanimage call.</li>
<li>Using the jpeg compression feature of tiff2pdf gives the picture a red color cast, which I cannot explain so far.</li>
<li>In order to achieve a better compression ratio I also added the ghostscript call.</li>
</ul>
<div>Summing up I&#8217;m so far content with the feature the scanner provides and from hardware side there is only the point that it would have been nice to have a second button, e.g. for producing direct copies. Regarding the script there are still things I might want to try, most notably the automatic OCR, but in theory there is also support for color correction in SANE (but this is really low priority).</div>
]]></content:encoded>
			<wfw:commentRss>http://philipp.knechtges.com/?feed=rss2&#038;p=190</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fortran for C/C++ Programmers: Part I</title>
		<link>http://philipp.knechtges.com/?p=163</link>
		<comments>http://philipp.knechtges.com/?p=163#comments</comments>
		<pubDate>Thu, 18 Oct 2012 21:36:18 +0000</pubDate>
		<dc:creator>Philipp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://philipp.knechtges.com/?p=163</guid>
		<description><![CDATA[Due to my current occupation, which involves numerical computations, I have to deal with Fortran in its different flavors. Since in the past I have almost exclusively programmed C/C++ and never had used Fortan I ran into some nasty bugs, which &#8230; <a href="http://philipp.knechtges.com/?p=163">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Due to my current occupation, which involves numerical computations, I have to deal with Fortran in its different flavors. Since in the past I have almost exclusively programmed C/C++ and never had used Fortan I ran into some nasty bugs, which I want to share, guessing that there are probably more people in the same situation. Most of these bugs are simply because of the fact, that one projects the known C-semantics onto Fortran. Or saying it differently: the bug sits between the keyboard and the chair <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>In this first post I want to start with the following example</p>

<div class="wp_syntax"><div class="code"><pre class="fortran" style="font-family:monospace;"><span style="color: #b1b100;">subroutine</span> bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #000066;">implicit</span> <span style="color: #000066;">none</span>
&nbsp;
<span style="color: #000066;">logical</span> <span style="color: #339933;">::</span> <span style="color: #202020;">foo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">.<span style="color: #202020;">false</span>.</span>
<span style="color: #666666; font-style: italic;">! do other stuff</span>
<span style="color: #b1b100;">end</span> <span style="color: #b1b100;">subroutine</span></pre></div></div>

<p lang="fortran">which is compared to:</p>

<div class="wp_syntax"><div class="code"><pre class="fortran" style="font-family:monospace;"><span style="color: #b1b100;">subroutine</span> bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #000066;">implicit</span> <span style="color: #000066;">none</span>
&nbsp;
<span style="color: #000066;">logical</span> <span style="color: #339933;">::</span> <span style="color: #202020;">foo</span>
foo <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">.<span style="color: #202020;">false</span>.</span>
<span style="color: #666666; font-style: italic;">! do other stuff</span>
<span style="color: #b1b100;">end</span> <span style="color: #b1b100;">subroutine</span></pre></div></div>

<p>Looks basically the same. Apparently it is <strong>NOT</strong>. The problem is that for Fortran every variable which is initialized at declaration is automatically marked <strong>save</strong>d, which, just to make it clear, corresponds to the <strong>static</strong> keyword in the C world. To make it even more precise the first example is the same as:</p>

<div class="wp_syntax"><div class="code"><pre class="fortran" style="font-family:monospace;"><span style="color: #b1b100;">subroutine</span> bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #000066;">implicit</span> <span style="color: #000066;">none</span>
&nbsp;
<span style="color: #000066;">logical</span>, <span style="color: #000066;">save</span> <span style="color: #339933;">::</span> <span style="color: #202020;">foo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">.<span style="color: #202020;">false</span>.</span> <span style="color: #666666; font-style: italic;">! foo's value is persistent across subroutine calls</span>
<span style="color: #666666; font-style: italic;">! do other stuff</span>
<span style="color: #b1b100;">end</span> <span style="color: #b1b100;">subroutine</span></pre></div></div>

<p>Or the same function in C:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">static</span> bool foo <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// do other stuff</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is just a habit thing, since in C and C++ there is not a problem with initialization at declaration. When I experienced the bug above I luckily had a simple function and a unit test which helped to reveal the bug quite fast. Otherwise one probably could keep staring at code for some time, falsely assuming this part of the code being too simple to fail.</p>
]]></content:encoded>
			<wfw:commentRss>http://philipp.knechtges.com/?feed=rss2&#038;p=163</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a E-350 based NAS</title>
		<link>http://philipp.knechtges.com/?p=113</link>
		<comments>http://philipp.knechtges.com/?p=113#comments</comments>
		<pubDate>Sun, 13 May 2012 22:22:28 +0000</pubDate>
		<dc:creator>Philipp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://philipp.knechtges.com/?p=113</guid>
		<description><![CDATA[One of the things I wanted to have done for quite some time now was building a NAS from the ground up. Several weeks ago the two year old Buffalo Pro Duo capitulated such that I finally got my chance &#8230; <a href="http://philipp.knechtges.com/?p=113">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the things I wanted to have done for quite some time now was building a NAS from the ground up. Several weeks ago the two year old Buffalo Pro Duo capitulated such that I finally got my chance <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Over the time there have been some things I wanted to try, but which the Buffalo NAS due to several reasons wasn&#8217;t able to deliver. So there were certain requirements the new NAS would have to meet:</p>
<ul>
<li>Due to a misconception the Buffalo NAS was accessing the hard disks approximately every 20 seconds, which in the end probably led to the harddisk failure. Hence the new setup should use a SSD for the operating system partition in order to minimize the exposure of the mechanical parts.</li>
<li>Although the initial setup will only use two harddisks, I want to have the possibility to expand the RAID5 array in the future.</li>
<li>The processor should be powerful enough to handle a software RAID.</li>
</ul>
<div>After searching a bit I found the following combination appealing, which then also ended up in the NAS</div>
<div>
<ul>
<li>Asus E35M1-M with a passively cooled AMD E-350</li>
<li>beQuiet Straight Power E9 with 400 Watts</li>
<li>Samsung MZ-7PC in the 64 GB configuration</li>
<li>2x Western Digital WD20EARX  with 2TB each</li>
<li>4 GB Corsair PC1333 RAM</li>
<li>Xigmatek Midi Tower Asgard</li>
</ul>
<h1>The assembly</h1>
<p>The assembly was straightforward although one directly noticed that the Midi Tower is the cheapest link in the chain. The power supply&#8217;s radiator cowling was slightly poking out such that it didn&#8217;t exactly fit, but it worked somehow.</p>
<h1>Software setup</h1>
<p>In the beginning I was pondering whether to choose FreeNAS or CentOS. Both are probably good choices, but since I don&#8217;t consider ZFS as the holy grail of file systems and I&#8217;m a passionate Fedora user the final choice was the CentOS 6.2 minimal spin. One of the main arguments for CentOS compared to other Linux distributions was that it has a long life cycle and ships quite up-to-date packages, although GRUB2 and systemd are for example missing. The kernel is shipped in the version 2.6.32, which is IMHO a bit old, as it turned out it doesn&#8217;t support the CPU temperature sensors out of the box (see below).</p>
<p>During installation I only had to deal with a small problem, that the installer wouldn&#8217;t want to boot from the UNetbootin-prepared USB stick in the beginning. Finally looking at the ASUS EFI bootmenu unveiled a second entry for the USB stick which choosing did the trick. From there on there were just some minor bumps on the road to a complete NAS:</p>
<ul>
<li>Out of the box CentOS minimal is configured to use NetworkManager, although NetworkManager is not installed. As had been described <a href="http://it.toolbox.com/blogs/linux-gnu/configuring-the-ethernet-nic-in-centos-6-rhel-6-scientific-linux-6-48390">here</a> one has to edit <em>/etc/sysconfig/network-scripts/ifcfg-eth0 </em>to turn off NM and to enable eth0 on startup.</li>
<li>As usually there&#8217;s always a point where you start struggling with selinux. In my case this was fixed by calling

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">chcon <span style="color: #660033;">-t</span> samba_share_t <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>shares</pre></td></tr></table></div>

<p>for the samba share directory and</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">restorecon <span style="color: #660033;">-R</span> <span style="color: #660033;">-v</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.ssh</pre></td></tr></table></div>

<p>for the newly created ssh directory (otherwise public key authentication won&#8217;t work).</li>
<li>While doing the Samba setup I searched quite some time for the option probably everybody wants to use in a small home network

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="txt" style="font-family:monospace;">map to guest = Bad User</pre></td></tr></table></div>

<p lang="txt">which, as it says, maps everybody without proper authentication to the guest (normally the user &#8220;nobody&#8221;).</p>
</li>
<li><span style="color: #000000;"><span style="color: #000000;">A nice gimmick I wanted to try was AirPrint. I <a href="https://github.com/tjfontaine/airprint-generate">found</a> a script that autogenerates the avahi service files for the installed printers, but as it turned out one also needs to add</span></span>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="txt" style="font-family:monospace;">ServerAlias *</pre></td></tr></table></div>

<p><span style="color: #000000;">to the cups configuration.</span></li>
<li>Unfortunately does the 2.6.32 linux kernel not ship any support for the hardware sensors in the E-350 CPU. So I had to install the kmod-k10temp rpm from <a href="http://elrepo.org/">ElRepo</a>. The sensor data is then available in the <em>/sys/module/k10temp/drivers/pci:k10temp/0000:00:18.3</em> directory.</li>
</ul>
<h1>Testing the CPU-Cooling</h1>
<p>The thing I was most curious about was whether the passively-cooled CPU would even sustain under full load, since there&#8217;s also a PRO Version of the motherboard which is shipped with an additional fan. So I started twice</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">md5sum <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom</pre></td></tr></table></div>

<p lang="bash">and monitored the CPU temperature over time. The result can be seen below:</p>
<p><a href="http://philipp.knechtges.com/wp-content/uploads/AMD-E-350-temp-fullLoad.png"><img class="aligncenter size-full wp-image-128" title="AMD E-350 temperature under full load" src="http://philipp.knechtges.com/wp-content/uploads/AMD-E-350-temp-fullLoad.png" alt="" width="640" height="384" /></a></p>
<p>The first plot on a physicist&#8217;s blog and it doesn&#8217;t even have error bars, shame on me <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  It&#8217;s difficult to interpret these numbers as in the <a href="http://www.kernel.org/doc/Documentation/hwmon/k10temp">k10temp documentation</a> is stressed, that temp1_input is given in almost arbitrary units. But k10temp gives one also the following values in the same units</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="txt" style="font-family:monospace;">temp1_max = 70000, temp1_crit = 100000, temp1_crit_hyst = 97000</pre></td></tr></table></div>

<p lang="txt">According to the k10temp documentation the CPU is throttled to prevent damage once temp1_crit(_hyst) is reached, so operating a passively cooled E-350 in a NAS should be safe even under occasional load. At first I was a bit irritated of the temp1_max value, but apparently it seems to be just a dummy value (see <a href="http://lxr.free-electrons.com/source/drivers/hwmon/k10temp.c?v=2.6.33#L67">k10temp source</a>).</p>
<h1 lang="txt">Conclusion</h1>
<p>So far I&#8217;m quite content with the NAS, but there are still some benchmarks that I want to run and some options (e.g. spin-down time of the harddisks) which I want to tweak. Hopefully I&#8217;ll find some time to blog about it.</p>
<p lang="txt">That&#8217;s it <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://philipp.knechtges.com/?feed=rss2&#038;p=113</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Of painting less</title>
		<link>http://philipp.knechtges.com/?p=90</link>
		<comments>http://philipp.knechtges.com/?p=90#comments</comments>
		<pubDate>Mon, 13 Feb 2012 15:07:41 +0000</pubDate>
		<dc:creator>Philipp</dc:creator>
				<category><![CDATA[planetKDE]]></category>

		<guid isPermaLink="false">http://philipp.knechtges.com/?p=90</guid>
		<description><![CDATA[It has passed quite some time since my last blog post about optimizing KWin&#8217;s performance, so I felt the need to write a new one In the meantime KDE SC 4.8 including KWin 4.8 got released with all the features &#8230; <a href="http://philipp.knechtges.com/?p=90">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It has passed quite some time since my last <a title="Optimizing KWin 4.8" href="http://philipp.knechtges.com/?p=10">blog post</a> about optimizing KWin&#8217;s performance, so I felt the need to write a new one <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  In the meantime KDE SC 4.8 including KWin 4.8 got released with all the features I had described in that blog post, but there are already new optimizations that have landed in the kde-workspace git repository, which I just want to explain shortly:</p>
<ul>
<li>The first thing isn&#8217;t even new, it is already part of KWin 4.8 <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  It is a window property called <em>_NET_WM_OPAQUE_REGION</em> that allows an application with a translucent window to give the window manager a hint which parts of a window are still opaque. Hence KWin has more room for optimizations. It is part of the <a title="EWMH Spec" href="http://standards.freedesktop.org/wm-spec/latest/">ewmh spec</a> and I hope that more applications/styles will adopt it. So far the only style, that I&#8217;m aware of, which is using this feature is <a href="https://projects.kde.org/projects/playground/artwork/oxygen-transparent">oxygen-transparent</a>.</li>
<li>I ported the TaskbarThumbnail, SlidingPopups and WobblyWindows effects to the faster code path that uses paintSimpleScreen. This was a long overdue step, which I really would like to have had in 4.8, but it needed some nontrivial changes to paintSimpleScreen. The actual painting is now done only in one pass instead of two, such that more window-transforming effects can be ported to utilize this function.</li>
<li>In the spirit of optimizing paintSimpleScreen I also tried to cut down the number of all OpenGL calls. E.g. now KWin does no longer emit a single OpenGL call if the damaged part of the window is fully occluded. To achieve this I used <a href="https://github.com/apitrace/apitrace">apitrace</a>, which by the way really rocks.</li>
<li>These days there has finally been added faster repaint support for move/resize events in combination with oxygen-transparent. Before this patch KWin always had to invalidate the blur texture cache of a window if it overlapped with the area of a moving window, although the blurry window might have been below the moving one, which is usually the case. For several blurry windows stacked on top of each other, this meant that moving a window could considerably slow down KWin. At the moment I&#8217;m working on porting several window-transforming effects (e.g. WobblyWindows) to use this new and faster method.</li>
</ul>
<div>That&#8217;s it for now <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  For all the other cool new features in KWin I may refer you to <a href="http://blog.martin-graesslin.com/blog/">Martin&#8217;s blog</a>.</div>
]]></content:encoded>
			<wfw:commentRss>http://philipp.knechtges.com/?feed=rss2&#038;p=90</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WordPress and hphp: Part II</title>
		<link>http://philipp.knechtges.com/?p=75</link>
		<comments>http://philipp.knechtges.com/?p=75#comments</comments>
		<pubDate>Fri, 30 Dec 2011 13:09:26 +0000</pubDate>
		<dc:creator>Philipp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hphp]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://philipp.knechtges.com/?p=75</guid>
		<description><![CDATA[In my last post I had described how to circumvent some issues when compiling Wordpess 3.2.1 with Hiphop-Php. Unfortunately it came up that the compiled binary suffered from a memleak which took me quite some time to find and fix. As &#8230; <a href="http://philipp.knechtges.com/?p=75">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In <a title="Compiling WordPress with Hiphop-Php" href="http://philipp.knechtges.com/?p=44">my last post</a> I had described how to circumvent some issues when compiling Wordpess 3.2.1 with Hiphop-Php. Unfortunately it came up that the compiled binary suffered from a memleak which took me quite some time to find and fix.</p>
<p>As it turned out hphp has a regular expression cache which caches every regular expression indefinitely such that clearing the cache is only possible if you shutdown the application. In principle this is not a problem for an application which has only a limited set of static regular expression patterns (which should be the case for most of the applications). But once the regex pattern becomes a runtime option the cache fails. This seems to be due to the fact that hphp compares cacheentries according to their regex-pattern hash and there is no guarantee that two equal dynamically allocated regex-pattern strings have the same hash. In the specific case of WordPress you have the runtime option to specify the date format which is mangled into a regex pattern somewhere inside the mysql2date function.</p>
<p>The obvious workaround is to limit the number of cacheentries. The specific <a href="https://github.com/d1saster/hiphop-php/commit/7460b57716e79dad31c34a28f0a59f6a9e62b60e">commit</a> can be found in my <a href="https://github.com/d1saster/hiphop-php">hiphop-php branch</a>, which as the title says makes the PCRECache a least recently used cache. I strongly recommend those running a hphp-compiled WordPress to apply that patch. Feedback is as always welcome <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://philipp.knechtges.com/?feed=rss2&#038;p=75</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling WordPress with Hiphop-Php</title>
		<link>http://philipp.knechtges.com/?p=44</link>
		<comments>http://philipp.knechtges.com/?p=44#comments</comments>
		<pubDate>Fri, 09 Dec 2011 10:52:04 +0000</pubDate>
		<dc:creator>Philipp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hphp]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://philipp.knechtges.com/?p=44</guid>
		<description><![CDATA[This is a project that I started last weekend and where I just want to share some of the insights I had, because compiling with Hiphop-Php (hphp) is not as straightforward as compiling an application with gcc or clang The &#8230; <a href="http://philipp.knechtges.com/?p=44">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a project that I started last weekend and where I just want to share some of the insights I had, because compiling with Hiphop-Php (hphp) is not as straightforward as compiling an application with gcc or clang <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The first thing you realize when looking at the <a href="https://github.com/facebook/hiphop-php">github hiphop-php</a> page is that it has a long list of dependencies, which I wanted to reduce to a minimum. So I ended up <a href="https://github.com/d1saster/hiphop-php">forking</a> hiphop-php and adjusting it to my needs: it should work with a minimal set of dependencies and it should be easy to deploy. At the moment my list of dependencies, that are <strong>not</strong> provided by CentOS 5, is down to libevent, curl, oniguruma and libmemcached. I had to sacrifice the ICU SpoofChecker, but as it isn&#8217;t used by WordPress this shouldn&#8217;t be a problem. Additionally I&#8217;ve chosen to use the <a href="https://github.com/d1saster/hiphop-php/commit/ab6037e27955c5df4e5eaa73ab41dcaffc235825">static</a> library versions of these dependencies, because I compile this stuff in a separate virtual machine and I don&#8217;t want to mess with rpath issues.</p>
<p>Once when you get to the point where you have a working hphp and try to compile WordPress 3.2.1 you will notice that the function SpellChecker::loopback won&#8217;t compile. Introducing a temporary variable fixes the issue:</p>
<pre>$ret = func_get_args();
return $ret;</pre>
<p>Now you are at the point where you can compile WordPress <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  &#8230;., but it won&#8217;t work <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Some of the SQL queries will fail and the best workaround I could come up with is to set</p>
<pre>$q['suppress_filters'] = true;</pre>
<p>in query.php.</p>
<p>So was this all worth it? Given the current viewership numbers of this blog I wouldn&#8217;t say so, but it was quite funny <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  According to apachebench this blog is now capable to serve 50 request per second instead of 10.</p>
<p>At the end some last remarks about hphp:</p>
<ul>
<li>Using the mentioned approach generates huge binaries, so a normal WordPress blog needs about 40-50 MB. The problem seems to be that some files, especially the dynamic_*.cpp ones, accumulate the references to symbols in other files. This prevents the linker from stripping the unneeded sections, because the compiler by default puts all functions of the same source file into one section. There are compiler flags, namely &#8220;-ffunction-section&#8221; and &#8220;-fdata-section&#8221; in combination with the linker flag &#8220;-Wl,&#8211;gc-sections&#8221;, which can change this behavior, but so far I didn&#8217;t try.</li>
<li>The upstream hphp has some issues with the source files not being present at runtime, see <a href="https://github.com/d1saster/hiphop-php/commit/5f7d320c59cdede3df9993c1d76f171920633873">this commit</a>.</li>
<li>I personally don&#8217;t like the idea to have to execute cmake in the root path of hphp <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philipp.knechtges.com/?feed=rss2&#038;p=44</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Optimizing KWin 4.8</title>
		<link>http://philipp.knechtges.com/?p=10</link>
		<comments>http://philipp.knechtges.com/?p=10#comments</comments>
		<pubDate>Sun, 27 Nov 2011 01:05:38 +0000</pubDate>
		<dc:creator>Philipp</dc:creator>
				<category><![CDATA[planetKDE]]></category>

		<guid isPermaLink="false">http://philipp.knechtges.com/?p=10</guid>
		<description><![CDATA[Since KDE SC is actually in feature freeze I thought it might be a good idea to blog about my contributions to KWin 4.8. As some of you may have noticed it is also my first post to this blog &#8230; <a href="http://philipp.knechtges.com/?p=10">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Since KDE SC is actually in feature freeze I thought it might be a good idea to blog about my contributions to KWin 4.8. As some of you may have noticed it is also my first post to this blog and especially to planetKDE <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Many of my commits have been optimizing the existing code base, so despite the hopefully increased performance you should not see any changes. Or in other words: this will be a more technical blog post.</p>
<h1>Occlusion Culling in KWin</h1>
<p>All this started with <a href="http://blog.martin-graesslin.com/blog/">Martin</a> pointing me to the fact that kwin initially did not process XDamage events window specific, as they are reported by the X server, but rather gathering all events and then updating the corresponding screen region. This could lead to the strange behavior that although your current virtual desktop was empty kwin was busy repainting the background again and again, just because on another virtual desktop your videoplayer was running maximized. Clearly this is a waste of resources.</p>
<p>So the solution was to process the events on a per window basis, which required to change two of the main functions in KWin: paintGenericScreen and paintSimpleScreen. Now one has to know that if the screen gets repainted either one of those functions gets called no matter whether you use OpenGL or XRender for compositing. As a nice side effect this also means that the optimizations described here equally apply to the XRender backend.</p>
<ul>
<li><strong>paintGenericScreen</strong> is the general implementation which just draws the window stack <em>bottom to top</em>, doing the preprocessing and the rendering in the same pass. This has the advantage that you can draw every scene, but with the cost that it is not really optimized. Especially fullscreen effects use this code path.</li>
<li><strong>paintSimpleScreen</strong> is restricted to cases where no window is transformed by an effect. The actual rendering is done in three passes. The first one is the preprocessing pass, where all effects not only get informed about what will be painted but also have the opportunity to change this data (e.g. making the window transparent). The second pass then starts drawing all the opaque windows <em>top to bottom</em>. At last the third pass paints all the remaining translucent parts <em>bottom to top</em>. The most crucial point here is to do a proper clipping when splitting up the rendering process into two passes.</li>
</ul>
<p>While changing paintGenericScreen was straightforward by just accumulating the damage bottom to top, changing paintSimpleScreen needed a bit more work because of the aforementioned clipping. More precisely in the top to bottom pass one has to gather all the damaged translucent regions while cutting off all the regions that have already been rendered. The last pass then just has to render the remaining damaged translucent area. Or summarized one can say that kwin now implements some kind of occlusion culling.</p>
<h1>Blur effect</h1>
<p>Nearly everybody who asks in a KDE related chat, why KWin is performing poorly, gets the recommendation to deactivate the blur effect. The good news is that this should no longer be the case in KWin 4.8 <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The main reason for the poor performance was that the blur effect requires the windows to be painted bottom to top and as such was limited to the unoptimized paintGenericScreen. So in KWin 4.7 not a single frame is painted with paintSimpleScreen if the blur effect is used. Hence my first objective was to port the blur effect to use paintSimpleScreen. Fortunately kwin allows the effects not only to change the painting region in the preprocessing pass but also the clipping area. This way the blur effect can now mimic the paintGenericScreen behavior and control which regions of the screen get painted bottom to top.</p>
<p>But just porting to paintSimpleScreen still was not that satisfactory, mainly because the blur effect still suffered from something I would call an avalanche effect. This was due to the fact that once the blurry region was damaged we had to repaint the whole region, such that a small damaged region could lead to a big repaint event (e.g. a damaged system tray icon forcing KWin to repaint the entire system tray). KWin now avoids this by buffering the blurred background in a texture, which then gets updated partially.</p>
<p>That&#8217;s it. <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Last but not least I want to thank Martin Gräßlin, Fredrik Höglund and Thomas Lübking for fruitful discussions and especially for taking the time to review all these changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://philipp.knechtges.com/?feed=rss2&#038;p=10</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Just another random blog &#8230;..</title>
		<link>http://philipp.knechtges.com/?p=1</link>
		<comments>http://philipp.knechtges.com/?p=1#comments</comments>
		<pubDate>Wed, 23 Nov 2011 14:16:14 +0000</pubDate>
		<dc:creator>Philipp</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://philipp.knechtges.com/?p=1</guid>
		<description><![CDATA[As the blog name suggests, this blog is about some random thoughts of mine. Given the fact that the entropy of these thoughts wouldn&#8217;t justify /dev/random, I found it appropriate to call it &#8220;/dev/urandom thoughts&#8221;. Those hoping for random number, encryption or &#8230; <a href="http://philipp.knechtges.com/?p=1">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As the blog name suggests, this blog is about some random thoughts of mine. Given the fact that the entropy of these thoughts wouldn&#8217;t justify /dev/random, I found it appropriate to call it &#8220;/dev/urandom thoughts&#8221;.</p>
<p>Those hoping for random number, encryption or information theoretical related blog posts will probably be disappointed because I&#8217;m so far not planing any posts about these topics. The main topics I had in mind while setting up this blog are:</p>
<ul>
<li>KDE, especially kwin, related thoughts</li>
<li>maybe some physics</li>
<li>All the rest I haven&#8217;t thought about yet.</li>
</ul>
<p>I hope you enjoy reading <img src='http://philipp.knechtges.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Regards,</p>
<p>Philipp</p>
]]></content:encoded>
			<wfw:commentRss>http://philipp.knechtges.com/?feed=rss2&#038;p=1</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
