Samsung EVO 16GB MB-MP16D micro-SD card corrupted on Raspberry Pi 2 model B

Yesterday, and today again, the micro-SD card got corrupted after a session of normal functioning and a shutdown or reboot. Root filesystem was formatted as ext4. After reading these sites:

  1. http://www.vanheusden.com/misc/rpi.php
  2. http://www.raspberrypi.org/forums/viewtopic.php?f=29&t=25703

I decided it was time to test f2fs filesystem with Raspbian on Raspberry Pi 2.

Migrating was easy, just format the partition as f2fs on Linux (you need f2fs-tools), and then copy the files with tar. There is no fsck.f2fs for Raspbian yet, but you can download the deb package from https://packages.debian.org/sid/armhf/f2fs-tools/download. Follow the instructions on the 1st link above in order to changes the root filesystem expected by kernel at boot (change it in cmdline.txt) and change filesystem in /etc/fstab as well.

Raspberry booted a while ago two times with this new configuration. I have just upgraded it and will give it a try for the whole day.

Advertisements

Raspberry Pi Model B vs Raspberry Pi 2 Model B

I have just received a new RPi 2 Model B. Yesterday I prepared a microSD card copying the three partitions of another SD card with Raspbian installed. The method was as follows:

– Partition the new microSD card with fdisk, same size except the last partition (swap) that was slightly smaller in the microSD.

– From my home computer, dd from original partition to final one:

# dd if=/dev/mmcblk0p1 of=/dev/sdb1 bs=4096
# dd if=/dev/mmcblk0p2 of=/dev/sdb2 bs=4096
# dd if=/dev/mmcblk0p3 of=/dev/sdb3 bs=4096

Raspbian was updated just before migrating the SD, so it has the last kernel and bootloader updates.  uname -a reports:

Linux parpuja 3.18.5-v7+ #225 SMP PREEMPT Fri Jan 30 18:53:55 GMT 2015 armv7l GNU/Linux

Raspberry Pi 2 boots without any issue, faster than the previous model, as was expected.

Some pictures of the two models:

IMG_20150210_123821IMG_20150210_123856

The only problem was the case. Since the new model has four USB slots instead of two, it does not fit into my homemade Video8 case.

I have some benchmarks made to compare the two models. I found some precompiled benchmarks for RPi ARM A6 here (thanks Roy Longbottom): http://www.roylongbottom.org.uk/Raspberry%20Pi%20Benchmarks.htm

Compiling the benchmarks from source code is not trivial because they include some assembler code for x86. Roy has source code adapted for ARM in his page.

The benchmarks are:

  • busspeed
  • dhrystone
  • linkpack
  • liverloops
  • memspeed
  • whetstone

The two models compared are:

Raspberry Pi B 2011.12 512MB Raspberry Pi 2 Model B V1.1 2014

Benchmarks

 ########################################################

 Linpack Double Precision Unrolled Benchmark n @ 100
 Optimisation Opt 3 32 Bit, Thu Feb  5 11:17:03 2015

 Speed      41.37 MFLOPS

 Numeric results were as expected

 ########################################################
 ########################################################

 Linpack Double Precision Unrolled Benchmark n @ 100
 Optimisation Opt 3 32 Bit, Tue Feb 10 12:54:23 2015

 Speed     119.02 MFLOPS

 Numeric results were as expected

 ########################################################
SYSTEM INFORMATION

From File /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 1
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 2
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 3
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

Busspeed

 #####################################################

   BusSpeed 32 Bit V1.1 Thu Feb  5 11:17:24 2015
 
    Reading Speed 4 Byte Words in MBytes/Second
  Memory  Inc32  Inc16   Inc8   Inc4   Inc2   Read
  KBytes  Words  Words  Words  Words  Words    All

      16    290    284    581    984   1044   1185
      32    133    106    121    121    225    426
      64     84     73     87     93    170    341
     128     53     51     48     62    109    249
     256     34     37     32     43     86    177
     512     31     32     31     42     84    173
    1024     31     34     32     45     84    183
    4096     32     32     32     43     87    190
   16384     32     34     34     41     83    176
   65536     31     32     33     44     83    176

        End of test Thu Feb  5 11:17:36 2015

SYSTEM INFORMATION

From File /proc/cpuinfo
processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 2.00
Features	: half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2708
Revision	: 000f
Serial		: 0000000022401f90
 #####################################################

   BusSpeed 32 Bit V1.1 Tue Feb 10 12:51:46 2015
 
    Reading Speed 4 Byte Words in MBytes/Second
  Memory  Inc32  Inc16   Inc8   Inc4   Inc2   Read
  KBytes  Words  Words  Words  Words  Words    All

      16    511    533   1333   1777   1706   1750
      32   1023    984   1163   1422   1638   1706
      64    426    409    761   1092   1365   1365
     128    372    393    682   1137   1638   1300
     256    213    232    426    758   1191   1094
     512    148    146    292    546    910    730
    1024     78     85    171    335    662    440
    4096     68     76    146    305    629    322
   16384     67     74    149    290    645    335
   65536     69     74    148    296    592    353

        End of test Tue Feb 10 12:51:57 2015

SYSTEM INFORMATION

From File /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt 
   vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 1
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt 
   vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 2
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt 
   vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 3
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt 
   vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

Dhrystone

 #####################################################

 Dhrystone Benchmark 2.1 Opt 3 32 Bit, Thu Feb  5 11:13:07 2015

 Nanoseconds one Dhrystone run:       675.00
 Dhrystones per Second:              1481481
 VAX MIPS rating =                    843.19

 Numeric results were correct

 #####################################################
 #####################################################

 Dhrystone Benchmark 2.1 Opt 3 32 Bit, Tue Feb 10 12:52:43 2015

 Nanoseconds one Dhrystone run:       368.75
 Dhrystones per Second:              2711864
 VAX MIPS rating =                   1543.46

 Numeric results were correct

 #####################################################
SYSTEM INFORMATION

From File /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 1
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 2
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 3
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

Linpack

Livermore Loops

 #####################################################

 Livermore Loops Benchmark Opt 3 32 Bit via C/C++ Thu Feb  5 11:17:50 2015

 MFLOPS for 24 loops
   64.3   79.3  128.8  145.0   22.9   29.0  106.7  125.8   89.9   37.6   30.8   24.2
   21.9   19.2   60.6   58.8   80.6   62.3   73.9   46.6   30.0   22.4   69.0   29.4

 Overall Ratings
 Maximum Average Geomean Harmean Minimum
   148.3    64.5    55.0    46.8    19.2

 Numeric results were as expected

 ########################################################
 #####################################################

 Livermore Loops Benchmark Opt 3 32 Bit via C/C++ Tue Feb 10 12:52:47 2015

 MFLOPS for 24 loops
  113.9  129.1  221.3  203.4   84.5   91.3  195.8  246.4  155.2  136.9   74.2   63.6
   62.6   70.2  125.9  125.2  196.3  153.0  132.6  116.2   77.3   41.6  161.2   89.0

 Overall Ratings
 Maximum Average Geomean Harmean Minimum
   246.5   125.7   114.7   103.8    41.5

 Numeric results were as expected

 ########################################################
SYSTEM INFORMATION

From File /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 1
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 2
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 3
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

MemSpeed

 #####################################################

     Memory Reading Speed Test 32 Bit Version 4 by Roy Longbottom

               Start of test Thu Feb  5 11:19:32 2015

  Memory   x[m]=x[m]+s*y[m] Int+   x[m]=x[m]+y[m]         x[m]=y[m]
  KBytes    Dble   Sngl  Int32   Dble   Sngl  Int32   Dble   Sngl  Int32
    Used    MB/S   MB/S   MB/S   MB/S   MB/S   MB/S   MB/S   MB/S   MB/S

       8     568    602    853    639    731   1094   1122    465    653
      16     538    602    787    602    682   1023   1142    533    727
      32     301    269    319    292    269    353    984    511    571
      64     243    213    238    232    217    255    341    269    301
     128     182    167    182    176    165    189    284    243    243
     256     142    131    142    136    131    148    146    128    134
     512     140    131    142    136    131    148    121    113    119
    1024     138    129    140    136    131    146    121    108    113
    2048     140    129    140    136    131    146    128    111    119
    4096     140    129    142    136    131    146    124    111    116
    8192     140    131    140    136    131    146    122    111    117
 #####################################################

     Memory Reading Speed Test 32 Bit Version 4 by Roy Longbottom

               Start of test Tue Feb 10 12:54:25 2015

  Memory   x[m]=x[m]+s*y[m] Int+   x[m]=x[m]+y[m]         x[m]=y[m]
  KBytes    Dble   Sngl  Int32   Dble   Sngl  Int32   Dble   Sngl  Int32
    Used    MB/S   MB/S   MB/S   MB/S   MB/S   MB/S   MB/S   MB/S   MB/S

       8    1024   1333   1142   2133   1406   1523   2666   1666   1523
      16    1023   1306   1185   2133   1406   1523   2461   1641   1523
      32    1023   1185   1094   1777   1333   1333   1939   1454   1422
      64     930   1094   1067   1662   1142   1230   1422   1333   1333
     128     930   1067    985   1524   1094   1142   1142   1333   1333
     256     930   1016    986   1525   1094   1186   1142   1454   1334
     512     538    639    568    682    682    639    986    728    728
    1024     393    512    393    465    512    445    891    496    537
    2048     310    445    320    353    445    341    895    460    496
    4096     310    445    310    353    445    330    904    511    465
    8192     297    427    307    338    446    338    906    491    491

SYSTEM INFORMATION

From File /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 1
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 2
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 3
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 57.60
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

Whetstone

##############################################

Whetstone Single Precision C Benchmark  Opt 3 32 Bit, Thu Feb  5 11:12:19 2015


Loop content                   Result              MFLOPS      MOPS   Seconds

N1 floating point      -1.12475013732910156        97.087               0.053
N2 floating point      -1.12274742126464844       100.053               0.360
N3 if then else         1.00000000000000000                 693.450     0.040
N4 fixed point         12.00000000000000000                 422.100     0.200
N5 sin,cos etc.         0.49911010265350342                   5.822     3.830
N6 floating point       0.99999982118606567        85.035               1.700
N7 assignments          3.00000000000000000                 550.293     0.090
N8 exp,sqrt etc.        0.75110864639282227                   2.694     3.700

MWIPS                                             268.726               9.973
##############################################

Whetstone Single Precision C Benchmark  Opt 3 32 Bit, Tue Feb 10 12:57:53 2015


Loop content                   Result              MFLOPS      MOPS   Seconds

N1 floating point      -1.12475013732910156       247.727               0.041
N2 floating point      -1.12274742126464844       263.324               0.270
N3 if then else         1.00000000000000000                1368.787     0.040
N4 fixed point         12.00000000000000000                1110.900     0.150
N5 sin,cos etc.         0.49911010265350342                  10.259     4.290
N6 floating point       0.99999982118606567       224.679               1.270
N7 assignments          3.00000000000000000                 888.720     0.110
N8 exp,sqrt etc.        0.75110864639282227                   5.165     3.810

MWIPS                                             530.007               9.981
SYSTEM INFORMATION

From File /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 1
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 2
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

processor	: 3
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

I have ommited system information for tests after the first one for the old model, but not for Model 2. The first difference you can find is the four cores in model B, with an A7 architecture. In the original RPi, the cpuinfo declares 2 BogoMIPS, while in the new one each one is displayed with 57.60 BogoMIPS and sometimes less, 38.40. It has to be due to the frequency, that can vary between 600 and 900MHz. Maybe I shoud repeat the tests forcing 900MHz to optimize for performance. That’s why I left system information, so bogomips can be found for each test.
As can be seen, results are much better for the new model (2-3 times faster, depending on the test), and must be taken into account that the code has been compiled for A6 architecture, and that the tests are designed for one core, so the difference has to be due to the frequency, the new architecture and the improved bus and memory speed (3-4 times faster).

Please leave any comment if you have any additional data or interpretation. Further study and analysis of results are needed, of course.

Python / Cython / Java / Go / Rust

I’m in love with Python. At first I had to use it because I had to make and maintain some Subversion hooks, and hated its indentations, that reminded me of Fortran.

Some years ago I rediscovered it, and I love it as a programming language, it is a language you can have fun programming with, powerful, logical and complete. And it is open source. Recently I discovered Django, and it has become my web framework of choice.

But this Python has a problem. It is not fast as a rattle snake, but slow as a snail. As you may know, Python is interpreted. Unlike C or C++, you cannot compile a machine code executable that the CPU can run directly. The interpreter takes the source file and generates a “*.pyc” byte-code file that is then read for execution. It is a step further than simply interpreting the source code, like BASIC, but it is not real machine code compilation. There are other languages, like Java, that use the same technique.

So let’s do something to accelerate a language we love. Can we compile Python? We have “Cython”, a tool we can use to generate machine code from a Python source code.  Cool! So we have it! Fast Python code, the panacea. Well, it depends. Let’s have a look.

Let’s take a little piece of code that concatenates strings, in Python:

def test_fun():
 s = ""
 for i in range(100000):
 s = s + "/" + str(i)

def main():
 test_fun()

if __name__ == "__main__": main()

If we execute it with python interpreter:

$ time python test.py
real 0m3.766s
user 0m1.812s
sys 0m1.955s

With cython, a C source can be generated, that you can compile with gcc. Let’s give it a chance:

$ cython -2 --embed test.py
$ gcc -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.7 -lpython2.7 -o test test.c
$ time ./test
real 0m6.895s
user 0m3.293s
sys 0m3.552s

Oh, no! Compilation <> acceleration. I’m sure this test is too simple, optimizations can be done and all that, maybe cython is good at some specifical tasks, etc. But as you can see, the time as almost double. Not very promising. C code generated by Cython is not optimized at all. In this particular case, it is pesimized.

If we want fast programs, I’m afraid Python is not the choice. But if you want to program fast, Python is your language.

Let’s try to fall in love with some other languages. Well, I have been a Java programmer for years, and I used to love it. I suspect Java will be faster. Let’s translate that simple program to Java. I don’t want to use StringBuffer, instead I want to do it as clear and simple as it is in my Python example above:

package javatest;

public class Test {
   public static void main(String []args) {
     String s = "";
     for (int i=0;i<100000;i++){
        s = s + "/" + Integer.toString(i);
     }
   }
}

How faster will it be?
time will tell us the truth:

$ time java javatest.Test

real	0m36.517s
user	0m37.533s
sys	0m0.277s

Oh, no! My good old Java is slower than Python for this simple task! What can I do now?
It is not two times slower, but TEN times slower. I’m sure that with StringBuffer we can do something better, maybe another day (or you can give me the answer in the comments below).

I’m afraid I will have to learn a new programming language. No problem, I like it. I have heard of two languages with cool names: Go and Rust

Go is a quite new language by people at Google. It is interpreted, very easy to learn and quite interesting. The translation will be something like this:

package main

import (
            "strconv"
        )

func main() {
   s := ""
   for i := 0; i < 100000; i++ {
        s = s + "/" + strconv.Itoa(i)
   }
}

The mecanism for running Go is similar to that of Python: you generate a byte-code file and run it. So let’s Go:

$ time go run test.go 

real	0m2.789s
user	0m2.363s
sys	0m0.093s

Good! Faster than Python, 1 second below Python’s mark. Very promising.

Our other option for today’s little benchmark is Rust. Rust is compilable, like C.   I am not a Rust expert, so I’m sure my translation below could be improved in many ways. In addition to that, Rust development is very active and the language definition is changing to some degree.

fn main() {

    let mut count: int = 0;
    let mut s = "".to_string();
    let mut count_s = "".to_string();
    let bar = "/".to_string();

    loop {
       count += 1;
       count_s = count.to_string();
       s = s + bar.as_slice() + count_s.as_slice();
       if count == 100000 {
            break;
        }
    }
}
$ rustc test.rs
$ time ./test

real	0m0.038s
user	0m0.037s
sys	0m0.001s

What? 38 milliseconds? Rust is similar to C in performance, and this result was expected. Really good result in terms of performace, and Rust is being developed to be a enjoyable language, at least more than C. I agree that C is THE language if you want to program close to the machine, but Rust can be a good alternative if you want to have fun while programming. You have even some web frameworks for it: nickel and Iron, for example.

Web frameworks for Go are also available, and they are very active. Go will go very far (I didn’t want to make more word plays with the name, I swear, but it is too easy…).

I know this benchmark is a I-do-not-know-what-to do-before-going-to-bed-let’s-do-a-benchmark, not very comprehensive, not very accurate, not scientific at all. Comparing Rust with the rest of the languages is not fair. But it served me to have an overview of these programming languages in terms of performance, and wanted to share it with the community.

In summary:

  • Python: 3.8s
  • Cython compiled: 6.9s
  • Java: 36.5s
  • Go: 2.8s
  • Rust: 38ms

Linux on AIRIS Kira N7000

Yesterday I installed Linux (a distribution called Kirbian, excellent job by these guys: http://kirbian.wordpress.com, thanks!!! ) on a AIRIS Kira N7000, an arm based netbook.

Just to help anyone who wants to do the same, I managed to make Wikidpad work on this device. The original wxPython library did not work in this hardware, it threw an “illegal instruction” exception, but after compiling the library on the device, it worked perfectly. Even with 256MB of RAM, it is perfectly suitable for my purposes.

I would like to have Dropbox in the device, but there is still no dropbox for arm. If you are a dropbox user, you can vote for this development in: https://www.dropbox.com/votebox/358/linux-arm-support, as I mentioned in my previous post.

So I installed btsync in both my laptop and kira, and will synchronize Dropbox between them, until there is some arm support from dropbox…

Image

OpenSuSE not booting after upgrading from 12.1 to 12.2

Hi all, this post has nothing to do with Raspberri Pi, but following its advices will be very valuable in any Linux system.

The problem.

I upgraded my PC with OpenSuSE 12.1 to 12.2 following this guide: http://en.opensuse.org/SDB:System_upgrade

Nothing new, I have been upgrading this system from 11.2 following more or less the same procedure.

After upgrading, the system does not boot. Well, it did boot, but got stuck at some point and did not show neither XWindow nor shell.
I tried booting in single mode (in OpenSuSE, just write “single” when the grub menu shows up), and the same symthoms.
This system, since 12.1 upgrade, is booting with systemd instead of sysvinit, so I tried to go back to old sysvinit (press F5 in grub menu or add init=/sbin/init to boot command line). It said that I did not have any /etc/inittab, maybe I lost it during the upgrade. So let’s try the shell boot.

On boot menu, write “init=/bin/sh” or press F5 and choose “Shell”. That drives you to a system with no network, no graphical interface, a very limited system with no services at all, but with a PROPMT!
On this shell, you can see, as I saw, that the special device files for a mirror disk had changed from /dev/md1 to /dev/md127. Linux, did not find my mirror. Also, I found that special device files for raw disks had also changed, but fortunately I had them mounted using either LVM or /dev/disks/by-id device files.

The solution
Well, using this shell boot you can edit fstab and make the system boot again. Once you have booted (or before, but you don’t have copy paste features 🙂 ), use udevadm to find information about mounted disks, this way:
# udevadm info -q all -n /dev/sda1 | grep DEVLINKS

You get something like:
E: DEVLINKS=/dev/disk/by-id/ata-ST9320423AS_5VH3W3P8-part1 /dev/disk/by-id/scsi-SATA_ST9320423AS_5VH3W3P8-part1 /dev/disk/by-id/wwn-0x5000c50029cb080f-part1 /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part1

Use one of the by-id special device files instead of /dev/sdXP because the latter can change due to upgrades, race conditions or simply hardware relocation of disks. Using /dev/disk/by-path device files can yield the same problems, because it depends on the hardware path of the disk, and it can change if you have a screwdriver at home.

I also got rid of md mirroring and migrated the disk to LVM, for one thing, I didn’t have a mirror at all, just a “one disk mirror”… historical reasons… LVM could have mounted this disk, because lvols device files do not depend on disk location or udev discovering. For instance, /dev/vg01/lvol1 will always be /dev/vg01/lvol1 as long as the vg metadata is not corrupted, so you can trust LVM and use lvol device files in fstab.

You can also write udev rules in order to call your disks anything you want, depending on serial number, size of the disk, etc. and use that name in fstab.

Trusting any kind of raw special device files is not a good practice at all. This is the same that trusting /dev/dsk/cXtYdZ device files in HP-UX, they depend on the path to the disk. On the other hand, /dev/disk/diskX special device depend on the disk itself. As long as you do not change WWID of disk, this device file does not change even if you change the hardware path of the disk (in HP-UX 11.31 at least). However, it is a good practice to use LVM in HP-UX because it isolate you from hardware details, you can even migrate disks physically and keep the same fstab, because the LVM device files depend on the metadata, not the hardware paths.

Raspberry supernintendo emulation, working recipe

After messing around with libretro-snes9x and not getting video through hdmi at all, I tried to compile retroarch and pocketsnes from scratch, ending with a working configuration.

Get retroarch:

$ git clone https://github.com/Themaister/RetroArch.git

Compile:

$ ./configure
$ make

If you get errors like these ones:

CC gfx/vg.c
gfx/vg.c: In function ‘vg_init’:
gfx/vg.c:102:4: error: too many arguments to function ‘vg->driver->update_window_title’
gfx/vg.c: In function ‘vg_frame’:
gfx/vg.c:390:4: error: too many arguments to function ‘vg->driver->update_window_title’

Just edit gfx/vg.c and change update_window_title(true/false) with update_window_title() at those lines mentioned above.

after that:

$ sudo make install

Compiled retroarch is at /usr/local/bin/retroarch

Get pocketsnes:

$ git clone https://github.com/ToadKing/pocketsnes-libretro.git

Compile:

$ make

This Makefile does not have an “install” target, so you have to copy library by hand:

$ sudo cp libretro.so /usr/lib/retroarch-pocketsnes.so

Configure RCB so this binaries are called, for instance:
config.xml

...

/usr/local/bin/retroarch
"%ROM%" -f -c ~/.config/retroarch/retroarch-snes.cfg
...

retroarch-snes.cfg

video_driver = "gl"
libretro_path = "/usr/lib/libretro-pocketsnes.so"
video_fullscreen = true
audio_enable = true
audio_out_rate = 48000
audio_driver = sdl
...

I’ll try with different drivers, but this configuration does work. Sound is not very good, but I’m affraid that, unless I overclock my RPi I will not get much better results. And I want my little berry to last very long…

Raspbian + XBMC + retroarch : Gamepad does not work!

I did buy a new brand gamepad for 21€ in Amazon and connected to my Raspberry Pi. Dmesg didn’t report many details about it, just:

[    3.342426] usb 1-1.2: new full-speed USB device number 4 using dwc_otg
[    3.476789] usb 1-1.2: New USB device found, idVendor=044f, idProduct=b326
[    3.502087] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    3.529629] usb 1-1.2: Product: GPX Gamepad
[    3.551359] usb 1-1.2: Manufacturer: Thrustmaster
[    3.582106] usb 1-1.2: SerialNumber: 00000001

Well, at least it exists for the kernel.

Executing retroarch-joyconfig:

$ sudo retroarch-joyconfig
Cannot find joystick at index #0, only have 0 joystick(s) available ...

Oh, my God, my wife is going to kill me!!!

Don’t panic, maybe I need a driver or something. I had tried an old Joystick before and everything was ok but its lacking of buttons and axises and some calibration problems made me go for a new gamepad.

This is the Joystick:

411evC+bYYL._AA160_This is a GP XID from Thrustmaster, and I had bought it with the promise of being XBox compatible, and I remembered something about XBox gamepads being compatible with retroarch. After some googling I found a driver for this devices:

http://pingus.seul.org/~grumbel/xboxdrv/

Developed by Ingo Ruhnke (thanks Ingo).

Installed with: apt-get install xboxdrv (it’t in raspbian repository, fortunately).

It has an user space part, so you have to run a command:

$ sudo xboxdrv
xboxdrv 0.8.4 - http://pingus.seul.org/~grumbel/xboxdrv/
Copyright © 2008-2011 Ingo Ruhnke <grumbel@gmx.de>
Licensed under GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html&gt;
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions; see the
file COPYING for details.

-- [ ERROR ] ------------------------------------------------------
No Xbox or Xbox360 controller found

Oh, no, I’m lost again!!!!

No, you have to RTFM. The FM is REALLY GOOD for this product, and you find some things like:

–device-by-id : force the driver to drive a device by vendor / productid

–type xbox360 : if you use the above parameter, you have to tell what kind of thing it is

–trigger-as-zaxis: it helped me to map the triggers, it tells the driver to manage the triggers as a Z axis instead of two independent axises.

So, with this command:

$ xboxdrv --silent --device-by-id 044f:b326 --type xbox360 --trigger-as-zaxis
xboxdrv 0.8.4 - http://pingus.seul.org/~grumbel/xboxdrv/
Copyright © 2008-2011 Ingo Ruhnke <grumbel@gmx.de>
Licensed under GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html&gt;
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions; see the
file COPYING for details.

Controller:        unknown
Vendor/Product:    044f:b326
USB Path:          001:004
Controller Type:   Xbox360

Your Xbox/Xbox360 controller should now be available as:
/dev/input/js0
/dev/input/event2

Press Ctrl-c to quit

Voila! It works, and now you can map the buttons and axises with retroarch-joyconfig. In my case, I obtained the following configuration:

# Defines axis threshold. Possible values are [0.0, 1.0]
# input_axis_threshold = 0.5
input_player1_joypad_index = "0"
input_player1_a_btn = "0"
input_player1_b_btn = "1"
input_player1_x_btn = "2"
input_player1_y_btn = "3"
input_player1_l_btn = "4"
input_player1_r_btn = "5"
input_player1_l2_axis = "-2"
input_player1_r2_axis = "+2"
input_player1_l3_axis = "-2"
input_player1_r3_axis = "+2"
input_player1_start_btn = "7"
input_exit_emulator_btn = "6"  # Added my hand, found the button with jset-gtk
input_player1_select_btn = "8"
input_player1_left_btn = "h0left"
input_player1_up_btn = "h0up"
input_player1_right_btn = "h0right"
input_player1_down_btn = "h0down"
input_player1_l_x_plus_axis = "+0"
input_player1_l_y_plus_axis = "+1"
input_player1_l_x_minus_axis = "-0"
input_player1_l_y_minus_axis = "-1"
input_player1_r_x_plus_axis = "+3"
input_player1_r_y_plus_axis = "+4"
input_player1_r_x_minus_axis = "-3"
input_player1_r_y_minus_axis = "-4"

You can experiment with different –type parameters (please, RTFM).

In my case, I added the xboxdrv execution to:

/home/pi/.xbmc/addons/script.games.rom.collection.browser/applaunch.sh

So it gets executed only when I need it. At the end of the script, I kill (pkill) the xboxdrv process.

Good luck with your gamepads!!

Raspberry Pi enclosure with an 8mm videotape case

This is a picture of my Raspberry Pi model B 512MB in an 8mm videotape case:

enclosure with an 8mm videotape case

The finishing is not perfect, I am not very skilled in plastic works. At first, temperature reached 58ºC. After making some holes on top of the SoC, temperature lowered to 50ºC. I suspect that the Lan chip is hotter than the SoC, as you can see in this post:
http://www.zipfelmaus.com/blog/raspberry-pi-thermal-images/

XBMC + ROM Collection Browser + retroarch: sound and joystick calibration

A new modification to applaunch.sh, so you calibrate and map the joystick and force mixer before launching the emulator.
Don’t take the arguments as is, they are just an example. Well, the amixer arguments force audio output to HDMI.


#!/bin/bash

# Check for arguments
if [ -z "$*" ]; then
echo "No arguments provided."
echo "Usage:"
echo "launcher.sh [/path/to/]executable [arguments]"
exit
fi

echo "Trying to stop xbmc "
sudo /etc/init.d/xbmc stop
# Deactivates HDMI output
sudo /opt/vc/bin/tvservice -o
# Activates HDMI output again
sudo /opt/vc/bin/tvservice -p

# Wait for the kill
sleep 1

# Joystick calibration and mapping
jscal -s 3,1,0,82,82,8388352,8134160,1,0,99,99,6882750,8388352,1,2,84,84,7254791,7063875 /dev/input/js0
jscal -u 3,0,1,6,4,288,289,290,291 /dev/input/js0
# Force audio output
amixer cset numid=3 2

echo "$@"

# Launch app - escaped!
"$@"

echo "Emulator terminated"

# Done? Restart XBMC
sudo /etc/init.d/xbmc start