2013年10月10日木曜日

PATCH for SystemC-2.3 to keep the module hierarchy in VCD

As I have posted to SystemC Forum I wrote a small patch to keep the module hierarchy in VCD.
The patch modifies a PoC simulator to treat signal name as a dot-separated path.
VCD Hierarchy Manipulator is no more necessary.

How to get the patch

Please see my github page or simply wget it.

How to apply

% tar zxvf systemc-2.3.0.tgz
% cd systemc-2.3.0
% patch -p0 <  ../sc_vcd_trace.patch
% ./configure --any-options
% make
% make install 
 

How to Use

No need to modify the SystemC model. All you need to do is just rebuild your design with the patched systemc library. You will get the VCD as a following screen shot.

If you want to disable this feature, set an environmental variable SC_VCD_NO_HIERARCHY.


Feedbacks

I only tested with a small example. Any feedback is welcome.

2013年7月29日月曜日

OpenRISC toolchain

Toolchain for OpenRISC cannot be built with the mainline source code. It was difficult for me to find the right way from openrisc web site.

After a couple of days of crawling, I found a repository maintained by Kevin Mehall.
It works perfectly, and its good point is gdb is also maintained.

If all libraries(GMP, MPFR and MPC) to build GCC have already been installed, simply do as following.
 
% git clone https://github.com/kevinmehall/openrisc-tools-build
% cd openrisc-tools-build
% git submodule update --init
% make -j3 PREFIX=

I wanted to build them on CentOS5.x machine and these libraries are not installed by default.
I wrote a preparation script to download and build these libraries.
These libraries are built as a static library, so setting LD_LIBRARY_PATH is not required.
If you faced the same problem, please try the following procedure.

% git clone https://github.com/kevinmehall/openrisc-tools-build
% cd openrisc-tools-build 
% git submodule update --init
% wget https://raw.github.com/yTakatsukasa/misc/master/openrisc_toolchain/toolchain.patch -O - | patch -p1
% bash ./prepare.sh
% make -j3 PREFIX=

Note that this patch disables openOCD. If you need openOCD, add openOCD to all: in Makefile.

2013年6月25日火曜日

SystemC-AMS 1.0 with clang

On some system, linking with libsystemc-ams.a compiled with clang may cause multiple definitions. In that case, systemc-ams must be compiled with
-fgnu89-inline option.
 

Howto

 tar zxvf systemcams-1.0.tar.gz 

 cd systemcams-1.0
 ./configure --with-systemc=/your/systemc/path
 make CC="clang -fgnu89-inline"
 make install

configure script ignores environmental variable CFLAGS, so -fgnu89-inline option must be specified during make.

Background

Clang assumes .c file as a C99 source code. Some C program assumes its language is C89 with gnu extension (aka gnu89).
gnu89 and C99 have several differences. The biggest one is a function with 'extern inline'.
In gnu89, functions with 'extern inline' are not necessarily compiled to normal non-inlined function.
In C99, such functions must be also compiled to a normal non-inlined function.
Source code which is expected to be compiled with gnu89 may cause link error of multiple definitions for this case.
If you use inline function in C, use 'static inline'. Its meaning is same for both C99 and gnu89.

2013年6月12日水曜日

SystemC-2.3 with Clang

Clang is a compiler which features fast compile, friendly error messages and high-compatibility with the latest C++ standard.
SystemC-2.2 can not be compiled with clang due to syntax violation of SystemC library.
Such violations are fixed in SystemC-2.3 but not perfect.
Clang emits warnings with -Wall and -Wextra option.
It is important to set the warning level higher to keep code clean.
If warnings are emitted at the library, warnings of user code may be concealed by them.
This is why libraries must be warning-free.

I wrote small patch to suppress such warnings.
https://github.com/yTakatsukasa/misc/tree/master/systemc-2.3_clang

Apply systemc-2.3_clang.patch before configure., then build it as usual.
 
  1. tar zxvf systemc-2.3.0.tgz
  2. patch -p0 < systemc-2.3_clang.patch
  3. cd systemc-2.3.0
  4. env CC=clang CXX=clang++ CPP="clang -E" ./configure
  5. make
  6. make install

2013年6月10日月曜日

JCPU shows pretty good performance

I changed the name or QCPU (in previous post) to JCPU, because noun QCPU is already used in a FA industry. 'J' derives from JIT (Just In Time compilation).
Only limited instructions are implemented, but now it can execute simple program.
I tested with a bubble sort with printf and get the result of more than 100 million instructions / sec without any optimization techniques.
Exceptions, MMU and supervisor mode is still unimplemented. These feature will decrease the performance. I hope I can cancel these negative effect with optimization.

(2013/06/12 update)
very primitive version can be seen at https://github.com/yTakatsukasa/JCPU

2013年6月3日月曜日

Started a new project : QCPU

I started a new project QCPU, which is a fast processor model using LLVM.
There are several related projects like QEMU, libcpu, and ArchC.
QEMU is mature project and supporting many architectures.
So I had been struggling for 2-3 weeks to cut out the processor model from QEMU., but QEMU is written in C and uses a lot of C macro tricks, so many files that are not necessary for processor models. Finally I gave up to cut out from QEMU. But the project name QCPU still derives from QEMU even though no source code of QEMU is used any more.

libcpu uses LLVM, but it does not looks to be actively developed.

ArchC is ongoing ambitions project. But it does not look focusing a performance.

So I started by myself.

I want to achieve the following points in QCPU.
  • Performance
  • Clean C++ code, no static/global object
  • Multi-instance friendly

According to the result of LLVM-QEMU of GSoC2007, it will be very difficult to get the similar performance as QEMU, but it's OK because this is just a hobby.

Currently only several instructions of openrisc is implemented.
  • Implement all instruction of OpenRISC
  • Support more archtectures (arm, mips, ppc, xtensa)
  • Implement MMU emulation framework
  • GDB stub
  • Performance optimization

I hope I can make the initial version in public in this month. The license will be GPL.

2013年4月28日日曜日

Manipulate the Hierarchy of VCDs generated by ASI (OSCI) PoC SystemC Simulator

All signals are recorded in one hierarchy named 'SystemC' in VCD generated by SystemC simulator even though VCD can describe hierarchy.

Just modifying the header of VCD is sufficient to set hierarchy structure. The easiest way is to write such script in Ruby or Python. I once wrote such script but it was slow for a large VCD file.
It had to read and write the main part of VCD even the header is need to be modified.

I wrote a small program to manipulate VCD very quickly. Mapping a file to memory is key point to get a good performance. If the file size does not change, head of file can be modified and only the modified portion is written.

It is available at github.

It might have been easy if I used std::string, but I used string_view class to avoid copying strings for future program.

2013年4月7日日曜日

How to hook the memory access in TLMu

In my fork of TLMu, SystemC world is mapped as a tlmu_ramd in QEMU. tlmu_ramd is similar to romd in QEMU, but accepts both read and write requets. romd is a kind of device in QEMU to model Flash memory devices. Flash memory devices require special sequece to erase and write, and romd provides memory access functions to model such operations. Without such functions, QEMU accesses memory regions with direct a memory pointer.

TLM2.0 provides direct memory interface (DMI) but special sequeice is necessary to get memory pointers.  So romd is good abstraction scheme for TLMu, but it allows only write hooks. So I add tlmu_ramd which provides both read and write hook functions.

Detailed modifications can be seen at the commit.
QEMU and TLM2.0 provides debug memory access method. To meet them I make memory access function pointer as array in tlm_mem.c:320.  Operations are switched at line 1884 and 1953 of exec.c.

2013年3月13日水曜日

Installing Munin on gentoo and CentOS

Munin, which is a software to monitor the servers requires less effort to setup than MRTG.
I setup Munin server on gentoo box and munin-node on centos boxes.
Munin server collects status from munin-nodes and generates charts.

Setup Munin server on gentoo

Article in gentoo wiki is helpful.
Before installing munin, it is better to serup httpd like apache, lighttpd.
If you have already installed httpd, simple emerge it, but you cannot use -minimal flag.
# emerge -v munin
# emerge --config net-analyzer/munin
If you also want to monitor this box, it should also be munin-node.
# rc-update add munin-node default
# /etc/init.d/munin-node



Then edit the /etc/munin/munin.conf and add following entry if not exists.
[yourserver.example.com]
        address 127.0.0.1
        use_node_name yes
emerge --config commands installs crontab, so you will find newly generated charts within 5 minutes at /var/www/localhost/htdocs/munin/.

Setup Munin-node on centos

Enable EPEL

Because munin is not hosted in the default repository, you have to enable EPEL (Extra Packages for Enterprise Linux).
On CentOS 5.x x86_64 
# rpm -ivh http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm
 On CentOS 6.x x86_64
# rpn -ivh http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-5.noarch.rpm
Then edit/etc/yum.repos.d/epel-testing.repo and set enable of [epel-testing].
enabled=1

Install munin-node

Just yum it.
# yum install munin-node
Edit /etc/munin/munin-node.conf and  add allow entry for Munin server. Note that the IP address must be described as a regular expression.
allow ^192\.168\.0\.\d+$
Then boot munin-node and make it executed automatically.
# /etc/init.d/munin-node start
# chkconfig --add munin-node
# chkconfig munin-node on

Add munin-node to be monitored

Edit /etc/munin/munin.conf on gentoo box and add an entry of centos box.
 [centos.example.com]
        address 192.168.0.2
        use_node_name yes
Now you can check the status at http://gentoobox.example.com/munin/.

2013年3月7日木曜日

802.1X PEAP-md5 authentification with freeradius

A few wireless access point supports WPA2-EAP, each user can have different password to connect wifi with it.
Some model of corega supports WPA2-EAP, you have to check the datasheet before you buy.

RADIUS server, which manages accounts is necessary for EAP auth.
I realized WPA2-EAP wifi access point with freeradius on gentoo linux.
Following is the procedure of it.

Install freeradius

Simply emerge it.
# emerge freeradius -v

Setup the config files

Edit /etc/raddb/clients.conf to allow clients(access point) to query the account.
Add an entry like following.
client 192.168.0.0/24 {
        secret = secretphrase
        shortname = yourservername
}

Make account

Edit /etc/raddb/users to add accounts.
The following 3 lines are required for each account.

account_name Cleartext-Password := "password"
        Service-Type = Framed-User,
        Framed-Protocol = PPP

Setup access point 

Setup the access point to use WPA2-EAP auth.
You have to specify at least 2 information below.
  1. IP address or hostname of radius server
  2. secret key specified in clients.conf




Start daemon with debug mode

# radiusd -X
If you try to connect the access point, access point queries the radius server and radiusd will show the debug messages.
You will have to enter the account name and password as in /etc/radvd/users.

I tested with 4 clients, windows8 pro, android 2.3, android 4.0 and android 4.2. Only android 2.3 failed to connect. I am not sure the reason.

Let radiusd starts at boot time

# rc-update add radiusd default

What is TLMu?

TLMu, which is originaly written by Edgar Iglesias  is a software based on QEMU.

QEMU is a emulator which supports various kinds of architectures like x86, arm, ppc, mips, xtensa and so on.
TLMu lets you connect CPU core in QEMU to SystemC models.
TLMu hooks memory access from CPU core and redirect to TLM-2.0 access.
CPU core in QEMU can access SystemC world and vice versa.

Edgar seemed to focus on cris and I found several problems on arm and mips.
I had fixed them and Edgar accepted my patches.
After the modifications, I managed to boot the latest Linux kernel (3.4) on TLMu + SystemC peripheral environment. Whole environment is available at here.

Edgar's original TLMu is based on relatively older QEMU (maybe around 1.0).
I wanted to catch up with the mainline QEMU release, so I forked and rebased onto the QEMU-1.2.0.
The internal of QEMU has greatly changed between 1.0 and 1.2, so I had to rewrite the most part of memory access hooks. As a byproduct of the rewrite, I add turbo mode, in which Linux boot time is 7x accelerated.

My TLMu branch keeps up with the mainline QEMU  and has original features like OpenRISC support, turbo mode now.

I will explain the memory access hooks and turbo mode in the next post.

2013年2月25日月曜日

SCV for x86_64 linux patch





I made a patch for scv to be compiled on x86_64 linux platform.

I posted it to SystemC Japan BBS.

You can apply the patch with the following procedure.

  1. Save the text below (from BEGIN to END, exlucde these 2 lines) to scv_x86_64.patch.base64
  2.  tar scv-1.0p2-sysc2.2.12jun06.tgz
  3. cd scv-1.0p2-sysc2.2/
  4. cat scv_x86_64.patch.base64 | base64 -d --ignore | gunzip | patch -p0
  5. aclocal --force 
  6. autoheader --force
  7. automake --force-missing --add-missing --copy
  8. autoconf --force
  9. ./configure --with-systemc=$SYSTEMC_HOME --prefix=$SYSTEMC_HOME
  10. make
  11. make install
I have not tested all functionality of patched SCV.
If you find any problems, please let me know.

--BEGIN
 H4sIAAtwok0AA70Za1ubTPaz/opTal9DgQjkYoxNn6qJNruauIn2tev6UIRJwlsCLJCa1vW/75nh
EiCJl7a7edqQOXPutzmDkiRBeScwfMsLg50z/SsZWTYp69Oy61vjDVWWK5LcwH8gy81KoymrZTn5
gCDvyfKmIAirWSC1okhylVIrlaZabarKEvWHDyBVVVHFdfT48GETNkG3bWjSb0mfguETPSSa4XoW
8QPcFl7HMEDY97bll4NJAdiZ61PPJsHyzrG1AAckBI/4UysILNdB1nlR0NyUNlbJgg1iTFzgXr/a
ubWcnWAC0oSD9ysw3G/Ev/OtkLS27tPfGvVQ8IAUeRJDD2HrPvAN0/IfdhZbZcvJoxa0yhoLG9YI
QhKE8Aokv7i9D+GEOPAvRAMwvIK0DCKU9xnWyCoKS/33iBOWcJ7jhgzRsiOSzYUrUnSq31IgN4zJ
1DVBF+aZuBX0x3DbRHekO9f/SnwabFYNhuuMrPHMJygrLYO6JCuSWgUZs3ivKTfWlEGWNpf/SFZr
qvXV+V+tiXXMf3zssvw3HXsTrECbeJ7e4hyXYyvbcmbzaCkky3p1sR94um/ES0MPCHBboe6PSagZ
3owDy9kEhsJHQmsVJrRWFRtM6EYq8DsJuP195Hl9XanW6jc3jfpbPkKIdYgxhHmjrtWruClsZDVK
GDCqgyPtbHiidQaD/qB0wRSCo/NLCL97BBw3hGDmea4fErOZ15inLEigG0zfhtKg+jZURawpkcJA
P0dXV9qnzqD1ZQt/gWTOph7mF80C+A/od19BOi7D9r3nWw7mlMKVuS31YftLQ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n3pVKpju7tQmviqUjLAFtQMYzW/eRJS+9tzBE
c5Agt+NQjos9hefhLYRxh3lMADrjV2XQBsTuKonZrdRs/lk2OrPpoWl+wjb+O616MdeFHfdRq8tL
CGExYTBDSTG+JB/fxHTKMuXyeHzJi3xP8IoW++IxGcsh/gkxhSCTlUHOafFLQSYrDfvVIJNVQc5J
IEmQl/sQmXs+YX+1yvWhmqTIklqhf29SdpvKusviek7FPlRrKvLKPlTBS+MuCNEjudMHhnb7Tbul
f2vAU7lEyvTNz60VaneWGU5KPJ/c6tkGosxICb8TMH29WYoHJpzR4B3lUg6sH6SE0wDOF3RGiIfv
dEgKp158X8F55o1tvgnw0kXpqAic282SxYuQYvGwmIce41CipwH/OB/G5SF6+CSc0Wkx2Y8j91+X
dgpUKh8AAA==

--END

2013年2月19日火曜日

TLMu-1.4.0 is released

I have rebased the tlmu-1.4.0_work branch and renamed it tlmu-1.4.0. I will not rebase it.
It is available at github.

You can try it with the following procedure.

1) Get the package
% git clone https://github.com/yTakatsukasa/tlmu

2) Build
run in the directory tlmu.
% mkdir build
% cd build
% ../configure --extra-cflags=-fPIC --disable-pie --disable-curses --disable-sdl --disable-vnc --disable-xen --disable-kvm --target-list=or32-softmmu,arm-softmmu,mipsel-softmmu,cris-softmmu
% make
% make tlmu
% make -C tests/tlmu install-tlmu
% cd tests/tlmu/
% make
% env LD_LIBRARY_PATH=./lib:$LD_LIBRARY_PATH ./c_example

Then you will see the Hello world message from arm, cris, mips and openrisc.

2013年2月17日日曜日

TLMu based on QEMU-1.4.0

I have released experimental TLMu based on latest QEMU, version 1.4.0.
It is now available at github .
Please note that this is just experimental release.
I am planning to reorganize and rebase it again!

The most troubling change for me is that the CPU name of OpenRISC has been changed from or1200 to or1200-or32-cpu. I am afraid that the source code in mainline QEMU is still using "or1200" for cpu_openrisc_init() in openrisc_sim.c.

During rebasing TLMu onto the latest QEMU, I wished QEMU had been written in C++.
C++ is better than C in many points. Following points are especially applicable for current QEMU implementation. 

  • templates in C++ is much type safer than complicated C macro tricks
  • class member variables are safer and multi-instance-friendly. global variables are not.
  • native class system in C++ is safer and easy to understand than gtk-like type system. opaque pointers are dangerous.

Now even the basic software like GCC is partially written in C++, why not QEMU.