tag:blogger.com,1999:blog-53649087147082735452024-03-13T07:11:19.356-07:00Interrupt EnableLife is a series of rude awakeningsDaniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-5364908714708273545.post-50399379460254937902011-06-30T13:36:00.000-07:002011-06-30T14:10:29.382-07:00/* TODO */This is a list of topics I plan to write some posts about:<br /><br />* softlockup and hung tasks. <br />* kernel debugging tools: kmememleak, lockdep, kmemcheck, perf <br />* how to submit patches to Linux kernel. <br />* getting started with the Linux kernel. <br />* anatomy of the TCP/IP Linux stack.<br />* analyze TCP connection setup using tcpdump.<br />* kernel/userspace communication.Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com0tag:blogger.com,1999:blog-5364908714708273545.post-17536733745528347352009-05-06T01:50:00.000-07:002009-05-06T03:46:29.796-07:00Introducing preadThere are many situations when you just want to read some data from a file starting with a given offset. The usual way of doing this is:<pre> <br /> lseek(fd, offset, SEEK_SET);<br /> read(fd, buffer, LEN);<br /></pre><br />You can do this in one function call using <i>pread(2) </i>. The above code is equivalent with:<pre><br /> pread(fd, buffer, LEN, offset);<br /></pre><br />In a similar manner you can notice the existence of <i>pwrite(2)</i> which writes some data into a file at a given position.Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com0tag:blogger.com,1999:blog-5364908714708273545.post-55854530393305461602009-03-18T02:59:00.000-07:002009-03-18T09:50:15.966-07:00call stack without words<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_t9BeJ81cm7k/ScDGXubMsbI/AAAAAAAABuA/6ySZOeEm6Xc/s1600-h/Call_stack.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 399px; height: 299px;" src="http://1.bp.blogspot.com/_t9BeJ81cm7k/ScDGXubMsbI/AAAAAAAABuA/6ySZOeEm6Xc/s400/Call_stack.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5314465671198585266" /></a>Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com4tag:blogger.com,1999:blog-5364908714708273545.post-33169038537208717442009-03-11T00:29:00.000-07:002009-03-11T00:57:17.927-07:00ltrace<span style="font-style: italic;">Usage: ltrace [option ...] [command [arg ...]]</span><br /><br /><a href="http://linux.die.net/man/1/ltrace">ltrace</a> is a tool that simply runs the specified command until it exits. It intercepts and records the dynamic library calls which are called by the executed process.<br /><pre><br />dan@lemon:~/playground$ ltrace -n 8 -C date<br />__libc_start_main(0x8049780, 1, 0xbfb1e874, 0x8052c50, 0x8052c40 <unfinished><br /> setlocale(6, "") = "en_US.UTF-8"<br /> bindtextdomain("coreutils", "/usr/share/locale") = "/usr/share/locale"<br /> textdomain("coreutils") = "coreutils"<br /> __cxa_atexit(0x804cd70, 0, 0, 0xb7ee4ff4, 0xbfb1e7d8) = 0<br /> getopt_long(1, 0xbfb1e874, "d:f:I::r:Rs:u", 0x8053ea0, NULL) = -1<br /> nl_langinfo(131180, 0xbfb1e874, 0x8053e85, 0x8053ea0, 0) = 0xb7ef3915<br /> clock_gettime(0, 0xbfb1e7b8, 0xb7dae8f5, 0xb7ee4ff4, 0) = 0<br /> localtime(0xbfb1e6c8) = 0xb7ee8380<br /> strftime(" Wed", 1024, " %a", 0xb7ee8380) = 4<br /> fwrite("Wed", 3, 1, 0xb7ee54c0) = 1<br /> fputc(' ', 0xb7ee54c0) = 32<br /> strftime(" Mar", 1024, " %b", 0xb7ee8380) = 4<br /> fwrite("Mar", 3, 1, 0xb7ee54c0) = 1<br /> fputc(' ', 0xb7ee54c0) = 32<br /> fwrite("11", 2, 1, 0xb7ee54c0) = 1<br /> fputc(' ', 0xb7ee54c0) = 32<br /> fputc('0', 0xb7ee54c0) = 48<br /> fwrite("9", 1, 1, 0xb7ee54c0) = 1<br /> fputc(':', 0xb7ee54c0) = 58<br /> fwrite("38", 2, 1, 0xb7ee54c0) = 1<br /> fputc(':', 0xb7ee54c0) = 58<br /> fwrite("33", 2, 1, 0xb7ee54c0) = 1<br /> fputc(' ', 0xb7ee54c0) = 32<br /> strlen("EET") = 3<br /> fwrite("EET", 3, 1, 0xb7ee54c0) = 1<br /> fputc(' ', 0xb7ee54c0) = 32<br /> fwrite("2009", 4, 1, 0xb7ee54c0) = 1<br /> __overflow(0xb7ee54c0, 10, 0x1e08f70c, 0, 0x1e08f70cWed Mar 11 09:38:33 EET 2009<br />) = 10<br /> exit(0 <unfinished><br /> __fpending(0xb7ee54c0, 0xb7f20ff4, 0x8048704, 0xb7ee4ff4, 0) = 0<br /> fclose(0xb7ee54c0) = 0<br /> __fpending(0xb7ee5560, 0xb7f20ff4, 0x8048704, 0xb7ee4ff4, 0) = 0<br /> fclose(0xb7ee5560) = 0<br />+++ exited (status 0) +++<br /></pre><br />ltrace accepts a lot of options. You can trace also for system calls, count time , follow forks etc. A short list with options can be found below:<br /><pre><br /> -a, --align=COLUMN align return values in a secific column.<br /> -c count time and calls, and report a summary on exit.<br /> -C, --demangle decode low-level symbol names into user-level names.<br /> -d, --debug print debugging info.<br /> -e expr modify which events to trace.<br /> -f follow forks.<br /> -h, --help display this help and exit.<br /> -i print instruction pointer at time of library call.<br /> -l, --library=FILE print library calls from this library only.<br /> -L do NOT display library calls.<br /> -n, --indent=NR indent output by NR spaces for each call level nesting.<br /> -o, --output=FILE write the trace output to that file.<br /> -p PID attach to the process with the process ID pid.<br /> -r print relative timestamps.<br /> -s STRLEN specify the maximum string size to print.<br /> -S display system calls.<br /> -t, -tt, -ttt print absolute timestamps.<br /> -T show the time spent inside each call.<br /> -u USERNAME run command with the userid, groupid of username.<br /> -V, --version output version information and exit.<br /> -x NAME treat the global NAME like a library subroutine.<br /></pre>Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com0tag:blogger.com,1999:blog-5364908714708273545.post-28879664746715639852009-03-03T04:10:00.000-08:002009-03-03T04:29:21.736-08:00dmidecode<span style="font-weight: bold; font-style: italic;"><span class="blsp-spelling-error" id="SPELLING_ERROR_0">dmidecode</span></span> is a tool for dumping a computer's <span class="blsp-spelling-error" id="SPELLING_ERROR_1">DMI</span> table contents in a human readable format. This table contains information regarding system's hardware components as described in BIOS.<br /><br />More information you can find <a href="http://www.nongnu.org/dmidecode/">here</a> or in <a href="http://linux.die.net/man/8/dmidecode">dmidecode(8)</a> manpage.Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com0tag:blogger.com,1999:blog-5364908714708273545.post-10661646233895129042009-02-22T02:40:00.001-08:002009-02-22T02:55:32.949-08:00Compilation without words<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_t9BeJ81cm7k/SaEubOGPS7I/AAAAAAAABp0/VHTye5DAN4E/s1600-h/compilation.png"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 102px;" src="http://3.bp.blogspot.com/_t9BeJ81cm7k/SaEubOGPS7I/AAAAAAAABp0/VHTye5DAN4E/s400/compilation.png" alt="" id="BLOGGER_PHOTO_ID_5305572881194765234" border="0" /></a>Click on the image to have a better view.Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com2tag:blogger.com,1999:blog-5364908714708273545.post-43650663370990142972009-02-13T23:09:00.000-08:002009-02-13T23:55:58.326-08:00Lindent<span class="blsp-spelling-error" id="SPELLING_ERROR_0"><span style="font-style: italic; font-weight: bold;">Lindent</span> is a script that changes the appearance of a C program according to linux kernel coding style. It can be found in <span style="font-style: italic;">linux/scripts</span>/ and it makes use of <span style="font-style: italic;">indent</span>.(see indent(1) manual page).<br /><br />For a debian based distribution running Lindent is straightforward:<br /><br />#install indent<br />apt-get install indent<br />#run Lindent over a file<br />linux/scripts/Lindent file.c<br /><br />The</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_1">preferred coding style used in linux kernel is described in <span style="font-style: italic;">linux/Documentation/CodingStyle</span>.</span>Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com1tag:blogger.com,1999:blog-5364908714708273545.post-11448344633995092102008-12-08T04:59:00.000-08:002009-01-04T06:42:11.808-08:00Top 10 interview questions of 2008Hi all,<p><br /> Feel free to add a comment with interesting technical questions that you received in interviews during this year.<br /><br /> At the end of the week i will collect the best ten of them and publish here.Also i would like you to share the company that interviewed you but this is not really necessary.</p><span style="font-style: italic;">Due to small number of comments received the top is canceled this year.</span><br /><p><br /></p>Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com6tag:blogger.com,1999:blog-5364908714708273545.post-291717239063575032008-12-03T08:58:00.000-08:002008-12-03T12:19:06.114-08:00Cycle detection in linked lists<i>Find if a linked list has a cycle given a pointer to it's first element.</i><br><br />There are several ways of solving this problem.<br /><ul><br /><li>iterate over the list and insert elements into a hash table. We have a cycle if we insert the same element twice. This solution requires <b>0(n)</b> time and <b>0(n)</b> memory.</li><br /><li>adapt the list to this particular situation. Insert a field that marks the node as visited or not. This solution has the drawback of modifying the list which is not always possible.</li><br /><li>Floyd algorithm which will be presented below its an efficient and easy to understand algorithm and requires <b> O(n) </b> time and <b> O(1) </b> additional memory. </li><br /></ul><br />Also known as the <span style="font-style:italic;">tortoise and hare</span> algorithm it uses two pointers <span style="font-style:italic;">a</span> and <span style="font-style:italic;">b</span> , where <span style="font-style:italic;">a</span> moves two times faster than <span style="font-style:italic;">b</span>.<br />The pseudocode for the algorithm is as follows:<br /><pre> <br /> a <- list_head<br /> b <- list_head<br /> do<br /> a <- a.next.next<br /> b <- b.next<br /> while a <> b <br />//if there is a cycle then a will be equal at some point with b. <br /></pre><br />An immediate application of Floyd's algorithm is retrieving the element in the middle of a list without computing it's length.Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com0tag:blogger.com,1999:blog-5364908714708273545.post-64482654139233443522008-12-01T06:21:00.000-08:002008-12-01T10:17:33.826-08:00GCC hacks in the Linux kernelDiscover GCC extensions for the C language <a href="http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/index.html?ca=dgr-lnxw09GCCKernel&S_Tact=105AGX59&S_CMP=GRsitelnxw09"> here</a>.<br />This article talks about <span style="font-style:italic;">functionality extensions </span> that bring new functionality from GCC and about <span style="font-style:italic;">optimization extensions</span> that are used for generating more efficient code.<br /><br />One thing that it's easy to remember is using ranges with case statements.<br> So instead of:<br /><pre> switch(level){<br /> case 1:<br /> case 2:<br /> case 3: /* do something */<br /> ......<br /> default: /* */<br /> }<br /></pre>you can use:<br /><pre> switch(level){<br /> case 1..3: /* do something */<br /> break;<br /> }<br /></pre>Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com0tag:blogger.com,1999:blog-5364908714708273545.post-64799743044286077432008-11-30T02:42:00.000-08:002008-12-01T06:21:53.080-08:00isTwoPowerVery simple and elegant function to test if a number is a power of two.<pre><br />int isTwoPower(int n){<br /> if( n < 1 )<br /> return 0;<br /> return !(n & (n-1));<br />}<br /></pre>Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com1tag:blogger.com,1999:blog-5364908714708273545.post-23752513801065940382008-11-29T06:37:00.000-08:002008-11-29T08:33:33.187-08:00Hello World!<code><pre>.data<br />hello:<br /> .ascii "Hello World!\n"<br /> len = . - hello<br />.text<br /> .global _start<br />_start:<br /> movl $4, %eax<br /> movl $1, %ebx<br /> movl $hello, %ecx<br /> movl $len, %edx<br /> int $0x80<br /><br /> movl $1, %eax<br /> movl $0, %ebx<br /> int $0x80 </pre></code>Daniel Băluțăhttp://www.blogger.com/profile/09955949494641268279noreply@blogger.com0