4/22/2014

How To determine Linux Kernel Timer Interrupt Frequency

How To determine Linux Kernel Timer Interrupt Frequency

Linux timer interrupt frequency is an important parameter for near to real-time and multimedia applications running on Linux. The timer interrupt frequency directly impacts the capability of any near-to real time and multimedia application to process events at high frequencies. The term high in this context means usually greater than 100 Hz (10 ms).
In the old days the kernel configuration setting CONFIG_HZ was the most important setting for the kernel timer frequency. It was defined at compilation time of the kernel and settings varied between distributions and kernel versions.
Today, a number of other kernel settings - such as NO_HZ, HIGH_RES_TIMERS - impact the kernel timer interrupt frequency as well. Finally the availability of High Precision Event Timer (HPET) support is also an important feature.
All these settings may be retrieved easily from the current kernel configuration. For example:
01$ cat /boot/config-`uname -r` | grep HZ
02# CONFIG_HZ_1000 is not set
03# CONFIG_HZ_300 is not set
04CONFIG_MACHZ_WDT=m
05CONFIG_NO_HZ=y
06CONFIG_HZ=100
07CONFIG_HZ_100=y
08# CONFIG_HZ_250 is not set
09 
10$ cat /boot/config-`uname -r` | grep HIGH_RES_TIMERS
11CONFIG_HIGH_RES_TIMERS=y
However, for a near to real-time or multimedia application the effective achievable timer interrupt frequency counts. This frequency can be estimated quite well with timer interrupts. The small example program below depicts an algorithm to determine the actual achievable timer interrupt frequency using by actually requesting timer interrupts at high frequencies.
01#include
02#include
03#include
04#include
05#include
06 
07 
08#define USECREQ 250
09#define LOOPS   1000
10 
11void event_handler (int signum)
12{
13 static unsigned long cnt = 0;
14 static struct timeval tsFirst;
15 if (cnt == 0) {
16   gettimeofday (&tsFirst, 0);
17 }
18 cnt ++;
19 if (cnt >= LOOPS) {
20   struct timeval tsNow;
21   struct timeval diff;
22   setitimer (ITIMER_REAL, NULL, NULL);
23   gettimeofday (&tsNow, 0);
24   timersub(&tsNow, &tsFirst, &diff);
25   unsigned long long udiff = (diff.tv_sec * 1000000) + diff.tv_usec;
26   double delta = (double)(udiff/cnt)/1000000;
27   int hz = (unsigned)(1.0/delta);
28   printf ("kernel timer interrupt frequency is approx. %d Hz", hz);
29   if (hz >= (int) (1.0/((double)(USECREQ)/1000000))) {
30     printf (" or higher");
31   }      
32   printf ("\n");
33   exit (0);
34 }
35}
36 
37int main (int argc, char **argv)
38{
39 struct sigaction sa;
40 struct itimerval timer;
41 
42 memset (&sa, 0, sizeof (sa));
43 sa.sa_handler = &event_handler;
44 sigaction (SIGALRM, &sa, NULL);
45 timer.it_value.tv_sec = 0;
46 timer.it_value.tv_usec = USECREQ;
47 timer.it_interval.tv_sec = 0;
48 timer.it_interval.tv_usec = USECREQ;
49 setitimer (ITIMER_REAL, &timer, NULL);
50 while (1);
51}
To check your particular system regarding time interrupt frequency capabilities please follow the instructions below create a local copy of this small program, as e.g. frequency-test.c. Issue is that this setting has an important impact on near to real-time applications.
  • Create a local copy of this small program, as e.g. frequency-test.c
  • Compile it with gcc: "gcc frequency-test.c"
  • Run it: "./a.out"
On a Ubuntu 8.04 LTS server (Hardy) ge got:
1$ ./a.out
2kernel timer interrupt frequency is approx. 4016 Hz or higher
On a Ubuntu 10.04 LTS server (Lucid) ge got:
1$ ./a.out
2kernel timer interrupt frequency is approx. 4016 Hz or higher
On a little bit older OpenSUSE with kernel 2.6.22.5-31-bigsmp we achieved:
1$ ./a.out
2kernel timer interrupt frequency is approx. 249 Hz
Both systems are multicore server chassis.
If the timer interrupt frequency determined on your system is for example around 250Hz, it will be very difficult for any near to real-time or multimedia application to send out an isochronous data stream of 250 packets per second (pps).

MS,US,NS,PS,FS,AS,FPS,HZ,MHZ

1. 컴퓨터의 처리 속도
ms : 밀리초 0.001 = 10^(-3)초
㎲ : 마이크로초 0.000001초 = 10^(-6)초
㎱: 나노초 0.000000001초 = 10^(-9)초
㎰ : 피코초 0.000000000001초 = 10^(-12)초
fs : 펨토초 0.000000000000001초 = 10^(-15)초
as : 아토초 0.000000000000000001초 = 10^(-18)초



여담으로,

보통 VGA메모리보면 2.8ns다 4ns다 이런식으로 메모리속도 표기를 하게됩니다.

ns(나노 초, 나노 세컨드)는 한 파장의 길이를 뜻합니다.

만약 4ns 의 램이 있다고 치면,
1s(초) = 1,000,000,000ns(나노 초) 니까, 1,000,000,000ns/4ns 하면 1s(초)안에 4ns(나노 초)가 250,000,000개 들어가는가지요.

그러면 Hz 는 1s(초)를 기준으로 하는 진동수이므로 250,000,000Hz 가 되지요.
결국 250,000,000Hz 를 단위 변환하여 메가 헤르츠(10^-6)로 바꾸면 250Mhz 가 되는것입니다.
그러니까 4ns = (1,000,000,000/4)/10^6 Hz = 250MHz 입니다.
ns와 MHz 사이의 관계를 공식으로 표현하면 x (ns) = 1,000/x (MHz) 가 되는겁니다.

오버클럭에도 적용할수 있는데, 만약 내 VGA램속도가 4ns라면 250MHz(DDR이면500MHz)까지는

정말 안정적으로 메모리클럭을 올릴수 있다는 얘기가 됩니다.

따라서 고급형 그래픽카드의 경우 ns가 낮은램을 써서 메모리클럭을 올려서 출시하는경우를 보실수 있을겁니다. 같은클럭이라도 ns가 낮은램이 오버클럭에 유리한건 당연지사입니다.


2. 컴퓨터의 기억 용량
1024byte = 1KB (kilo byte)
1024KB = 1MB (mega byte)
1024MB = 1GB (giga byte) = 1048576 KB
1024GB = 1TB (tela byte)
1024TB = 1PB (peta byte)



또 여담으로

200기가 짜리를 사서 포맷을 하면 200기가로 표기되지 않는이유가 여기에 있습니다.

보통제조사는 200,000,000,000바이트 용량의 하드를 200기가라고 표기하게 되는데

실제 1000으로 나뉘는게 아니라 1024로 나뉘므로 1024로 계속 나누면 186기가쯤으로 잡힙니다.


3. 자료의 표현 단위
Bit(비트) : Binary digit의 약자. 정보를 표현하는 최소 단위.
0 또는 1 : Binary digit (bit) 기록의 최소 단위
n개의 비트는 2n의 자료를 표시함.
nibble(니블) : 4비트로 이루어진 정보 표현의 단위.
Byte(바이트) : 8bit = 1byte로 문자표현의 최소 단위
8개의 비트로 256가지의 자료 표현이 가능함.(28 = 256)
영문 : 1 byte = 8bit
한글 : 2 byte = 16bit
Word(워드) : 몇 개의 바이트를 묶어서 이루어진 한 개의 기억단위.
하프워드 = 2바이트
풀워드 = 4바이트
더블워드 = 8바이트
Field (=Item. 필드) : 여러 개의 바이트나 워드가 모여 이루어진 정보 단위.
Record(레코드) : 프로그램 내의 자료 처리 단위.
Block(블록) : 자료의 입·출력의 기본 단위. 물리적 레코드.
File(파일) : 하나의 프로그램 처리 단위.
Data Base(데이터 베이스) : 계층적 구조를 갖는 자료 단위.



4. 단위에 관계된 여러 가지 용어
BUS : 32bit, 16bit, 64bit
bit란 한번에 전달해 주는 자료의 수. Bus를 따지는 용어.
PC속도 : KHz(킬로 헤르쯔) , MHz(메가 헤르쯔), GHz(기가 헤르쯔)
PC용량 : 하드의 용량 ex)1.2GB

참고 : 대역폭 계산

DDR400의 램인 경우(200*2)
400 * (64bit / 8bit) = 3200 MB/s = 3.2 GB/s

64를 8로 나눈 것은 바이트로 바꾸기 위한 것


펜티엄4 노스우드C인 경우(200*4)
800 * (32 / 8) = 3200 MB/s = 3.2 GB/s

한마디로 동작클럭에 비트수를 바이트로 변환하여 곱하면 됨.

printf - usage

function

printf

int printf ( const char * format, ... );
Print formatted data to stdout
Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.


Parameters

format
C string that contains the text to be written to stdout.
It can optionally contain embedded format specifiers that are replaced by the values specified in subsequent additional arguments and formatted as requested.

A format specifier follows this prototype: [see compatibility note below]
%[flags][width][.precision][length]specifier

Where the specifier character at the end is the most significant component, since it defines the type and the interpretation of its corresponding argument:
specifierOutputExample
d or iSigned decimal integer392
uUnsigned decimal integer7235
oUnsigned octal610
xUnsigned hexadecimal integer7fa
XUnsigned hexadecimal integer (uppercase)7FA
fDecimal floating point, lowercase392.65
FDecimal floating point, uppercase392.65
eScientific notation (mantissa/exponent), lowercase3.9265e+2
EScientific notation (mantissa/exponent), uppercase3.9265E+2
gUse the shortest representation: %e or %f392.65
GUse the shortest representation: %E or %F392.65
aHexadecimal floating point, lowercase-0xc.90fep-2
AHexadecimal floating point, uppercase-0XC.90FEP-2
cCharactera
sString of characterssample
pPointer addressb8000000
nNothing printed.
The corresponding argument must be a pointer to a signed int.
The number of characters written so far is stored in the pointed location.
%A % followed by another % character will write a single % to the stream.%

The format specifier can also contain sub-specifiers: flags, width, .precision and modifiers (in that order), which are optional and follow these specifications:

flagsdescription
-Left-justify within the given field width; Right justification is the default (see width sub-specifier).
+Forces to preceed the result with a plus or minus sign (+ or -) even for positive numbers. By default, only negative numbers are preceded with a - sign.
(space)If no sign is going to be written, a blank space is inserted before the value.
#Used with o, x or X specifiers the value is preceeded with 0, 0x or 0X respectively for values different than zero.
Used with a, A, e, E, f, F, g or G it forces the written output to contain a decimal point even if no more digits follow. By default, if no digits follow, no decimal point is written.
0Left-pads the number with zeroes (0) instead of spaces when padding is specified (see width sub-specifier).

widthdescription
(number)Minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.
*The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.

.precisiondescription
.numberFor integer specifiers (d, i, o, u, x, X): precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer. A precision of 0 means that no character is written for the value 0.
For a, A, e, E, f and F specifiers: this is the number of digits to be printed after the decimal point (by default, this is 6).
For g and G specifiers: This is the maximum number of significant digits to be printed.
For s: this is the maximum number of characters to be printed. By default all characters are printed until the ending null character is encountered.
If the period is specified without an explicit value for precision, 0 is assumed.
.*The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.

The length sub-specifier modifies the length of the data type. This is a chart showing the types used to interpret the corresponding arguments with and without length specifier (if a different type is used, the proper type promotion or conversion is performed, if allowed):
specifiers
lengthd iu o x Xf F e E g G a Acspn
(none)intunsigned intdoubleintchar*void*int*
hhsigned charunsigned charsigned char*
hshort intunsigned short intshort int*
llong intunsigned long intwint_twchar_t*long int*
lllong long intunsigned long long intlong long int*
jintmax_tuintmax_tintmax_t*
zsize_tsize_tsize_t*
tptrdiff_tptrdiff_tptrdiff_t*
Llong double
Note that the c specifier takes an int (or wint_t) as argument, but performs the proper conversion to a char value (or a wchar_t) before formatting it for output.

Note: Yellow rows indicate specifiers and sub-specifiers introduced by C99. See for the specifiers for extended types.
... (additional arguments)
Depending on the format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string (or a pointer to a storage location, for n).
There should be at least as many of these arguments as the number of values specified in the format specifiers. Additional arguments are ignored by the function.


Return Value

On success, the total number of characters written is returned.

If a writing error occurs, the error indicator (ferror) is set and a negative number is returned.

If a multibyte character encoding error occurs while writing wide characters, errno is set to EILSEQ and a negative number is returned.


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* printf example */
#include 

int main()
{
   printf ("Characters: %c %c \n", 'a', 65);
   printf ("Decimals: %d %ld\n", 1977, 650000L);
   printf ("Preceding with blanks: %10d \n", 1977);
   printf ("Preceding with zeros: %010d \n", 1977);
   printf ("Some different radices: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
   printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
   printf ("Width trick: %*d \n", 5, 10);
   printf ("%s \n", "A string");
   return 0;
}


Output:

Characters: a A
Decimals: 1977 650000
Preceding with blanks:       1977
Preceding with zeros: 0000001977
Some different radices: 100 64 144 0x64 0144
floats: 3.14 +3e+000 3.141600E+000
Width trick:    10
A string


Compatibility

Particular library implementations may support additional specifiers and sub-specifiers.
Those listed here are supported by the latest C and C++ standards (both published in 2011), but those in yellow were introduced in C99 (only required for C++ implementations since C++11), and may not be supported by libraries that comply with older standards.

Cb3 A20-compiling Android Image For Cubietruck

Cb3 A20-compiling Android Image For Cubietruck

About this Article

Download the source code

$mkdir cubietruck-android && cd cubietruck-android
$wget http://dl.cubieboard.org/software/a20-cubieboard/android/A20-android-4.2.tar.xz
$tar -xvf A20-android-4.2.tar.xz

Compiling image

After get the source code,you could use common to build it as follow:

Build Linux kernel

$cd lichee/
$cp linux-3.3/arch/arm/configs/cubietruck_defconfig linux-3.3/arch/arm/configs/sun7ismp_android_defconfig
$./build.sh -p sun7i_android 
Start Building:

Success Building:

Build Android image

$cd ../android42
$source build/envsetup.sh
$lunch 16 (select sugar_cubietruck-eng)
$extract-bsp
$make -j8
Finish building:

Pack Final image:
$pack
Pack success:

Install image

The final image is at /lichee/tools/pack/sun7i_android_sugar-cubietruck.img
You can use Livesuit to install it

4/21/2014

ubuntu 12.04 에서 jdk6 설치 - for Android build - cubietruck

ubuntu 12.04 에서 jdk6 설치하기


sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java6-installer 


일부 검색 사이트에서는 install 시에 sun-java6-jdk 만 언급하는 경우만 있는데
다른 ubuntu 버전에서는 성공했을지 몰라고 12.04 에서는 에러가 발생한다.
찾아보니 sun-java6-plugin 도 같이 설치해줘야 한다.

1. 소스 설치
sudo add-apt-repository ppa:flexiondotorg/java
(ppa:guido-iodice/precise-quasi-rolling)
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-plugin

2. java vm 변경
sudo update-alternatives --config java

3. /etc/profile 수정해서 환경변수 설정
JAVA_HOME=/usr/lib/jvm/java-6-sun/
export JAVA_HOME
export PATH=$PATH:/usr/lib/jvm/java-6-sun/bin

4. 새로운 터미널창을 열어서 version 확인하기
java -version
javac -version

5. HelloJava.java 작성해서 실행확인하기
cat > HelloJava.java
class HelloJava{
    public static void main(String args[]) {
        System.out.println("Hello World");
    }
}