Tuesday, May 17, 2011

Musical computing

It is common to wait for operation to finish, and meanwhile we want to do other things and not worry about what happened to process/operation.

Useful/Interesing program is beep which can produce sounds using integrated speaker on motherboard. On my ubuntu I also needed to modprobe pcspkr (alternatively add pcspkr to /etc/modules).

Run these two commands in shell

true && beep -f 80 || beep
false && beep -f 80 || beep

Different sound is produced depending on the outcome of operation. It would be nice to make a wrapper script for this usage pattern.

Also, network cable accidentally drops out from one computer outside my room

#!/bin/sh
while true; do
ping -c 1 -a -w 1 10.101.95.231 || beep
sleep 1
done

Perhaps, better alternative is to find out how to send notifications to gnome/ubuntu, that way I can see the outcome even if I have headphones with loud music

Monday, May 16, 2011

Redis virtual memory and Linux

Reading though virtual memory of redis documentation and redis.conf:

... specify an amount of RAM that's more or less between 60 and 80% of your free RAM.

Sounds simple enough: Dedicate majority of your RAM for redis process and rest will be automatically saved into redis swap file, no worries. Reality is not that simple.

What happens is that, linux kernel aggressively caches file contents and inodes to RAM for "perfomance" reasons. Redis server will start writing to swap file which will be kept in RAM for "performance" and redis process will lack regular RAM for its normal operation. As a result, portions of redis swap-file are kept inside the RAM and portions of redis process are swapped by system onto a disk. A major trashing and inversion of memory hierarchy.

Issue is that redis decided to use non-standard VM mechanism, and that is ok. But developers should have described a proper way to configure kernel for all of this to be possible.

For instance, I have 2.0G of RAM, and value vm-max-memory is set to 1500mb. When this memory fills up redis starts writing to swap file, and after a while, simple redis GET operation takes tens of seconds to complete.

In order to fix this problem, what needs to be done is to moderate VM settings of kernel. Firstly, you can increase tendency to reclaim memory by changing cache pressure: (I not sure about the exact values)

echo 200 > /proc/sys/vm/vfs_cache_pressure

Swappiness will reduce amount of pages that are swapped

echo 20 > /proc/sys/vm/swappiness

If you are in memory/trashing trouble and need to quickly reclaim some memory, issue this cmd:

sync; echo 3 > /proc/sys/vm/drop_caches

It is interesting that drop_caches is not really a kernel setting, but writing to it will send a signal/message the the kernel.

To summarize, I really like redis and what it is doing, but documentation is missing few relevant details regarding its virtual memory capabilites and it will not run smoothly unless kernel is compliant to the rules of redis.

Tuesday, November 09, 2010

Stipedija za Maleziju (IIUM)

This post is written in Bosnian language due to target audience, sorry for inconvenience.

Iskustvo vezano za upis i stipendiju u maleziju se razlikuje medju studentima, tako da neke stvari koje su meni bile lahke drugima su ispale teske i obratno. Moje iskustvo je od prije vise od 4 godine, neke stvari su se promjenile.

Upis u fakultet i engleski jezik

Ja cu opisati kako biti primljen na univerzitet IIUM, odnosno jedan od fakulteta, oni to zovu Kulliyyah. Ovo nije tesko, oni ce primiti vecinu kandidata. Status ovog univerziteta opada vremenom, tako da (bar mislim) da sada cak primaju manje aplikacija nego prije (nisam siguran).

Ja sam se upisao tako sto sam skinuo formular sa njihove stranice, popunio ga i poslao zajedno sa dokumentima. Ja sam poslao preko studenta koji se bio privremeno vratio u Sarajevo. Ako nista, mozete probati poslati preko poste.

Sada vidim da imaju neki sistem registracije preko interneta, tako da to olaksava stvari. Ali na ovoj stranici pise da prihvacaju stari i novi nacin apliciranja, tako da imate izbor.

Dokumente za poslati

Standardne stvari poput pasosa, diplome, rodni list... oni su to napisali na aplikaciji. Ja sam oradio jednu stvar: preveo sam, i ovjerio potpis od mojih diploma sa takmicenja. Mislim da ovo nije potrebno. Oni vecinom vise obracaju paznju na ocjene u skoli nego van-nastavne aktivnosti.

Ima jedna sekcija u aplikaciji koja vas pita kako se planirate finansirati, ovo zavisi od stipendije kakvu uspijete dobiti. (Kasnije o ovome.) U krajnjem slucaju mozete staviti da ce te finansirati sami-sebe, ili napisati ime roditelja. Ja sam izganjao stipediju nakon sto sam bio primljen.

Za aplikaciju treba jedno pismo i potpis od reisa. Mozete otici u ured ispred Carove dzamije. Trebate ponijete diplomu sa sobom, ako se dobro sjecam prolazna ocjena treba biti 4 ili 5. Jedno upozorenje: oni su VELIKI lazovi i gadovi (nemojte im to reci). Ja nisam otisao nikada u njihov ured, a da oni nisu lagali. Ovaj ured igra jos jednu ulogu: oni su zaduzeni za jednu stipendiju koju cu opisati kasnije. Mozda potpis od reisa ne treba za upis na fakultet, zbunjen sam.

Engleski jezik

Da bi poceli predavanja trebate pokazati da znate engleski. To se moze uraditi na nekoliko nacina. Prvo je da se ode u Englesku Ambasadu, i prijavite se na ispit iz Engleskog jezika. Mislim da treba uzeti malo vremena da se pripremite za ovaj ispit, jer neke stvari su drugacije od onoga sto se ucilo u srednjoj skoli. Priznati ispiti su TOEFL i IELTS.

Druga opcija je da prisustvujete ispitu EPT koji je organizovan u Maleziji na univezitetu. Ja mislim da je puno bolje zavrsiti ispit u Bosni preko ambasade.

Viza za maleziju

Ovo je kontraverzna tema. Dosta ljudi ce vam reci da ne treba viza, oni su upravu i u krivu.

Situacija 1: ja sam dobio vizu u Malezijskoj ambasadi u Sarajevu. Ali na aerodromu, glupi oficer mi nije to vidio pa je udario jos jednu. Ja sam morao platiti 500RM za nesto nisam siguran sta.

Situacija 2: moj prijatelj je dobio vizu u Malezijskoj ambasadi u Sarajevu, i njemu su vidjeli tu vizu na aerodromu u Kuala Lumpuru. On nije trebao nista dodatno placati.

Situacija 3: studenti koji nisu imali vizu, dobili su turisticku vizu na aerodromu, ali su trebali placati isto 500RM za neznam sta tacno.

Ima jedan trik. Ja nisam uradio taj trik, ali se moze dobiti neko pismo, izaci iz Malezije privremeno u Singapur pa se onda vratiti sa tim pismom. I onda se ne treba placati 500RM. Posto ovo nisam uradio, moram pitati nekog drugog kako to ide.

Stipendija

1) Dosta studenata iz Bosne trenutno u Maleziji imaju stipendiju od Albukhary. Koliko sam ja cuo, oni vise ne daju stipendije za IIUM, nego prave vlastiti univerzitet. Evo nasao sam. Koliko vidim jos uvijek daju za bosance, samo ne za IIUM nego vlastiti AIU.

Citat odavde:
As at the end of March 2009, 383 students from 46 countries have been awarded Albukhary scholarships; most of them are currently studying at the International Islamic University Malaysia. Future intakes are expected to attend the Albukhary International University in Alor Setar, Kedah which will begin its operations in January 2011.
Glavni kampus od IIUM je u Gombaku.

2) Na IIUM univerzitetu imaju neke stipedije Ummatic scholarship i Excellence awards (tako nesto). Ovo daju onima koji su imali neke uspjehe u medjunarodnim takmicenjima i dobre ocjene na prvoj godini fakulteta na IIUM. Nije sigurno da se ova stipendija moze dobiti. Kockanje.

Na ovoj stranici oni spominju vise stipendija, ali vjerovatno se ne mogu dobiti prije nego se pocne sa fakultetom. Neke od ovih stipedija su samo za Malajce.

3) Islamic Development Bank iz Dzedde, daju stipediju za neke fakultete. Inzinjering, agrikultura, medicina itd. Trenutno im web stranica ne radi.

IDB, imaju scholarship za non-member countries. Ja sam ovo dobio. Njihov standardni proces jeste da rijaset treba odabrati najbolje studente, i onda ti studenti dobiju stipediju koja se kasnije vraca u malim porcijama u Vakuf.

Rijaset nije bas bio pri pomoci sa ovom situacijom, meni je jedan covjek pomogao stupiti u kontakt sa IDB direktno. Ured rijaseta je ispred Careve dzamije, oprez, oni su veliki lazovi.

4) Ima jos organizacija koje daju stipedije, trebao bi se raspitati.

Wednesday, September 15, 2010

Running PC^2 on windows.

PC^2 is Programming Contest Control System, official PC^2 website. Version I am using is pc2-9.1.5-1969.

Needless to say, you should move "pc2v9.ini" into a "bin" directory and change it appropriately. In addition, path to your compiler executable should be in your environment variable PATH.

Only difference compared to *nix systems is in specification of Languages. For a MinGW compiler this is correct language spec. (Pay attention to details.)


And for Cygwin compiler this is the spec.


Since cygwin is using symbolic links we have to specify a link to actual .exe file. This is for gcc version 3, you can guess what will happen with different versions.

Running pc2server.bat

Default settings for version 9 are:
  • Username: site1
  • Password:
  • Contest Password: site1

Running pc2admin.bat

Default settings for version 9 are:
  • Username: root
  • Password:

Saturday, August 28, 2010

Pipeline creation

When you have a large chunk of combinational logic, sometimes it is useful to create pipeline out of it. Benefits are that critical path is much lower and you can work with higher clock, whereas throughput of your circuit is still almost 1 operation/cycle. Only downside is that results are delayed a couple of cycles.

I have had a not-so-succesfull attempt to make a pipeline geneartor for verilog. But I was informed recently that synopsys design compiler has option to do this automatically.

This is design I want to pipeline.

module addxor(input [5:0] A, input [5:0] B, output C, input clock);
wire [5:0] M = A + B;
wire [5:0] N = M * M;
wire [5:0] H = A - N;
wire [5:0] J = H - B;
wire [5:0] G = A[0] ? H : J;
assign C = |G;
endmodule

pipeline_design

From the desing compiler there is a straight-forward command which is:
design_vision-xg-t> pipeline_design
I don't like this command, since it modifies the behaviour of original RTL design. Pre-synthesis and post-synthesis results are different. In pre-synthesis pipeline is not functional, at this means I have to write different tests for pre and post synthesis.

Retiming to the rescue

Retiming was invented in 1981, and synthesis tools such as DC use it. It allows it to move registers arround the combinational logic in order to optimize it.
module addxor_pipelined(input [5:0] A, input [5:0] B, output reg C, input clock);
wire C1;
addxor U1(A,B,C1,clock);
reg C2,C3,C4,C5;
always @ (posedge clock)
begin
C2 <= C1;
C3 <= C2;
C4 <= C3;
C5 <= C4;
C <= C5;
end
endmodule
This could be a common design pattern for pipeline, which consists of two steps:
  1. Encapsulate a combinational module; and
  2. Delay the output.
Our hopes are that synthesis tool will balance timing in circuit, thus producing a pipeline.

Without mapping/retiming this design looks like this.
After running the compile command, design does not change much, at the end there are flip-flops in series at the output of circuit. But circuit does have a timing violations.
design_vision-xg-t> source config.con
design_vision-xg-t> compile # there will be timing violations
design_vision-xg-t> optimize_registers -period 0 -flatten
Voilà!
Large squares are flip-flops, and you will notice that they are spread out through an entire design, this is what we wanted. No more timing violations. In case you are interested:
my DC configuration.

In conclusion, with this method for pipelining, you can use same testing code for pre-synthesis and post-synthesis design.

Thanks for reading, leave your comments below.

Sunday, July 30, 2006

2006.07.30

redacted