<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Luiz on Nothing &#187; hacking</title>
	<atom:link href="http://blog.cpu.eti.br/category/hacking/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cpu.eti.br</link>
	<description></description>
	<lastBuildDate>Wed, 03 Nov 2010 13:14:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>QEMU has been accepted for GSoC 2010!</title>
		<link>http://blog.cpu.eti.br/2010/03/19/qemu-has-been-accepted-for-gsoc-2010/</link>
		<comments>http://blog.cpu.eti.br/2010/03/19/qemu-has-been-accepted-for-gsoc-2010/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 18:36:02 +0000</pubDate>
		<dc:creator>Luiz Capitulino</dc:creator>
				<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.cpu.eti.br/?p=219</guid>
		<description><![CDATA[Three days working until late at night to make this happen and we did it: QEMU has been accepted for Google Summer of Code 2010.
Take a look at our ideas page:
http://wiki.qemu.org/Google_Summer_of_Code_2010
We have all kinds of projects there: a library, application protocol, hardware emulation, kernel, and a lot more.
Please, note that QEMU is not only an [...]]]></description>
			<content:encoded><![CDATA[<p>Three days working until late at night to make this happen and we did it: QEMU has been <a href="http://socghop.appspot.com/gsoc/org/show/google/gsoc2010/qemu">accepted</a> for <a href="http://socghop.appspot.com">Google Summer of Code 2010</a>.</p>
<p>Take a look at our ideas page:</p>
<p><a href="http://wiki.qemu.org/Google_Summer_of_Code_2010">http://wiki.qemu.org/Google_Summer_of_Code_2010</a></p>
<p>We have all kinds of projects there: a library, application protocol, hardware emulation, kernel, and a lot more.</p>
<p>Please, note that QEMU is not only an emulator. Some people I know still think of QEMU as being the old emulator they used to use years ago. But today QEMU is also a virtualizer, it supports Xen and KVM, being the upstream project of KVM user-space.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cpu.eti.br/2010/03/19/qemu-has-been-accepted-for-gsoc-2010/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Learning Scheme</title>
		<link>http://blog.cpu.eti.br/2008/12/14/learning-scheme/</link>
		<comments>http://blog.cpu.eti.br/2008/12/14/learning-scheme/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 00:11:02 +0000</pubDate>
		<dc:creator>Luiz Capitulino</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.cpu.eti.br/?p=108</guid>
		<description><![CDATA[Exercise: Write a function that returns the length of a list (without using the scheme length function).
My try:

(define mylengh
  (lambda (ilist)
    (letrec ((mylengh-rec
               (lambda (rlist nr)
            [...]]]></description>
			<content:encoded><![CDATA[<p>Exercise: Write a function that returns the length of a list (without using the scheme length function).</p>
<p>My try:</p>
<pre>
(define mylengh
  (lambda (ilist)
    (letrec ((mylengh-rec
               (lambda (rlist nr)
                 (if (eqv? rlist '()) nr
                   (mylengh-rec (cdr rlist) (+ nr 1))))))
             (mylengh-rec ilist 0))))
</pre>
<p>Solution:</p>
<pre>
(define (mylength a)
  (if (null? a) 0
      (+ 1 (mylength (cdr a)))))
</pre>
<p>Well&#8230; It is a start. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cpu.eti.br/2008/12/14/learning-scheme/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Initial VMA data and vfork()</title>
		<link>http://blog.cpu.eti.br/2008/10/18/initial-vma-data-and-vfork/</link>
		<comments>http://blog.cpu.eti.br/2008/10/18/initial-vma-data-and-vfork/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 23:32:30 +0000</pubDate>
		<dc:creator>Luiz Capitulino</dc:creator>
				<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.cpu.eti.br/?p=104</guid>
		<description><![CDATA[As I am going to play with the VMA code and its main data structure (a red-black tree), I have started to collect some data by using systemtap, and got a bit impressed by the number of times find_vma() is called by some processes, as shows the table below.


PID
exec name
nr calls (5 seconds)
doing&#8230;

21984
cc1
1570
Compiling Linux kernel

11533
X
13252
Switching [...]]]></description>
			<content:encoded><![CDATA[<p>As I am going to play with the VMA code and its main data structure (a red-black tree), I have started to collect some data by using systemtap, and got a bit impressed by the number of times find_vma() is called by some processes, as shows the table below.</p>
<table border="1">
<tr>
<td>PID</td>
<td>exec name</td>
<td>nr calls (5 seconds)</td>
<td>doing&#8230;</td>
<tr>
<td>21984</td>
<td>cc1</td>
<td>1570</td>
<td>Compiling Linux kernel</td>
<tr>
<td>11533</td>
<td>X</td>
<td>13252</td>
<td>Switching work spaces</td>
<tr>
<td>23554</td>
<td>git-index-pack</td>
<td>42213</td>
<td>Resolving deltas</td>
</table>
<p>So, in this specific case gcc has searched its VMA tree 1570 in five seconds while (probably) compiling some C file. Is that a big number? I am not sure but X, for example, is calling find_vma() more than 2600 times in a second if I switch fast between work spaces in Window Maker. I did not expect this.</p>
<p>Git is the winner so far, more than 8000 searches in one second while resolving deltas in a clone operation.</p>
<p>I also wanted to know what are the most called system calls that may search (or change) the VMAs&#8217; tree, and here goes some more numbers:</p>
<table border="1">
<tr>
<td>system call</td>
<td>nr calls (5 seconds)</td>
</tr>
<tr>
<td>sys_mmap2</td>
<td>11039</td>
</tr>
<tr>
<td>sys_munmap</td>
<td>5102</td>
</tr>
<tr>
<td>sys_brk</td>
<td>3574</td>
</tr>
<tr>
<td>sys_execve</td>
<td>392</td>
</tr>
<tr>
<td>sys_clone</td>
<td>255</td>
</tr>
<tr>
<td>sys_vfork</td>
<td>82</td>
</tr>
</table>
<p>This snapshot has been taken while compiling the Linux kernel and while the numbers are of no surprise, there are two interesting functions in that table, brk() and vfork(). I thought that their usage would be very rare these days: users of brk() are now using mmap() and I was wondering whether it makes sense to use vfork() in a modern kernel like Linux, with very fast process creation time and copy on write support.</p>
<p>But a quick look at the code shows that sys_vfork() passes the CLONE_VM flag to do_fork(), this in turn will avoid the creation of a new address space for the child. In other words, they will share the same mm_struct and that makes vfork() faster than regular fork() (threads also share the same mm_struct).</p>
<p>Very cool stuff, I am being good at choosing projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cpu.eti.br/2008/10/18/initial-vma-data-and-vfork/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A new blog</title>
		<link>http://blog.cpu.eti.br/2008/10/07/a-new-blog/</link>
		<comments>http://blog.cpu.eti.br/2008/10/07/a-new-blog/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 14:43:56 +0000</pubDate>
		<dc:creator>Luiz Capitulino</dc:creator>
				<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.cpu.eti.br/?p=103</guid>
		<description><![CDATA[While reading the 2.6.27-rc9 announcement email today (looking for fixed bugs, of course) I found this:

PS. I already bugged people on the git lists with this, but since I&#8217;m
totally shameless and can&#8217;t help but hope that some random kernel person
also does tcl/tk or just wants to help improve my kids-time-tracker, I can
just point to
	http://torvalds-family.blogspot.com/2008/10/tracking-time-kids-spend-online.html
and hope [...]]]></description>
			<content:encoded><![CDATA[<p>While reading the 2.6.27-rc9 announcement <a href="http://lkml.org/lkml/2008/10/6/300">email</a> today (looking for fixed bugs, of course) I found this:</p>
<blockquote><p>
PS. I already bugged people on the git lists with this, but since I&#8217;m<br />
totally shameless and can&#8217;t help but hope that some random kernel person<br />
also does tcl/tk or just wants to help improve my kids-time-tracker, I can<br />
just point to</p>
<p>	http://torvalds-family.blogspot.com/2008/10/tracking-time-kids-spend-online.html</p>
<p>and hope that somebody would like to make that GUI better and/or feel like<br />
they really want to do a &#8220;management interface&#8221; too ;)
</p></blockquote>
<p>I got a bit confused because the keywords that blinked in my brain were &#8220;git&#8221;, &#8220;tcl/tk&#8221;, &#8220;kernel&#8221;, &#8220;kids&#8221; and &#8220;family&#8221;.</p>
<p>Then I discovered that Linus has a <a href="http://torvalds-family.blogspot.com/">blog</a> now and the coolest thing about it is that it is not just another tech- or kernel- blog, he is going to talk about his family too.</p>
<p>That is cool because I am always looking for ways to improve my son&#8217;s education and there are not lots of kernel hackers&#8217; blogs about that out there. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cpu.eti.br/2008/10/07/a-new-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JOS Virtual Memory (part 2)</title>
		<link>http://blog.cpu.eti.br/2008/05/05/jos-virtual-memory-part-2/</link>
		<comments>http://blog.cpu.eti.br/2008/05/05/jos-virtual-memory-part-2/#comments</comments>
		<pubDate>Mon, 05 May 2008 12:55:40 +0000</pubDate>
		<dc:creator>Luiz Capitulino</dc:creator>
				<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.cpu.eti.br/?p=99</guid>
		<description><![CDATA[Introduction
This post will briefly explain what copy-on-write fork() is, then we will discuss JOS&#8217;s very particular copy-on-write fork() implementation which is mostly done in user-space.
Hopefully this post will give you a good understanding of the system calls presented in the first part of this series.
To be honest, I am not sure whether copy-on-write fork() is [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>This post will briefly explain what copy-on-write fork() is, then we will discuss JOS&#8217;s very particular copy-on-write fork() implementation which is mostly done in user-space.</p>
<p>Hopefully this post will give you a good understanding of the system calls presented in the first part of this series.</p>
<p>To be honest, I am not sure whether copy-on-write fork() is the best example for beginners, but it is very helpful to demonstrate how exokernel implementations move functionality normally implemented in kernel-space to user-space.</p>
<p>I recommend you to read the <a href="http://blog.cpu.eti.br/?p=98">first post of this series</a> if you have not done so yet.</p>
<p><span id="more-99"></span></p>
<p><strong>Copy-on-write fork()</strong></p>
<p>The <a href="http://linux.die.net/man/2/fork">fork()</a> system call creates a new process by duplicating the calling process. That means that the new process created by fork(), known as the child, is a complete copy of the process which called fork(), known as the parent (actually, not everything is copied but we can ignore the details for now).</p>
<p>One of the parent&#8217;s resources which has to be duplicated is its <a href="http://en.wikipedia.org/wiki/Address_space">memory address space</a>, which include all the pages allocated for the parent. There are two ways to do this.</p>
<p>The simpler way is easy to understand and implement, it is something like the following:</p>
<pre>
for each mapped page in the parent do
	1. allocate a new page
	2. insert it into the address space of the child, at the same virtual address
           of the parent's page
	3. copy the parent's page contents into the child's allocated page
</pre>
<p>Again, that is not the full story, I have omitted some details but the algorithm does show the problems of this solution which is basically an unnecessary overhead.</p>
<p>For example, if the child process uses only a small subset of its address space, all the work done on the unused pages would have been completely wasted.</p>
<p>Think about the shell now, its main duty in life is to fork() and <a href="http://linux.die.net/man/2/execve">exec()</a> new programs. Exec() destroys the address space of the process calling it and builds a new one. So, if you are using the dumb algorithm showed above, for each command you type into the shell prompt, fork() will duplicate the address of the shell just to allow exec() to destroy it.</p>
<p>Of course this algorithm is awful and today&#8217;s operating systems use something better called copy-on-write.</p>
<p>Copy-on-write fork() works like this: instead of duplicating the address space of the parent into the child, the kernel marks all the parent&#8217;s pages as read-only and inserts them into child address space. By doing that both processes will <em>share</em> the parent&#8217;s pages. When any of the two writes into one of the shared pages, the <a href="http://en.wikipedia.org/wiki/Memory_management_unit">MMU hardware</a> issues a <a href="http://en.wikipedia.org/wiki/Page_fault">page fault</a>. The page fault handler executes and learns that a process is trying to write into a copy-on-write page. At this moment the page fault handler does the following:</p>
<pre>
1. Allocates a new page
2. Makes the new page read-write
3. Copies the contents of the copy-on-write page into the allocated one
4. Inserts the new page into the address space of the process doing the write, at the
   same virtual address of the copy-on-write page
</pre>
<p>After the fourth step, the page fault handler exits and the processor continues to execute in the instruction which caused the page fault. In this way the change is transparent for the running process.</p>
<p>Copy-on-write fork() is a little bit more complex to implement and it depends on the hardware to work, but it does make fork() low overhead as it does not have to duplicate the entire address space of the calling process.</p>
<p>Let&#8217;s consider the shell case again. In a system with copy-on-write support, the fork()/exec() sequence is much faster because no page is duplicated between the fork() and exec() calls.</p>
<p>Note that copy-on-write is potentially useful to any process which forks new processes, because pages are duplicated only when needed.</p>
<p><strong>JOS copy-on-write fork()</strong></p>
<p>In JOS fork() is not a system call. It is a library function which uses various system calls to perform its task.</p>
<p>The code of fork() can be found <a href="http://repo.or.cz/w/mit-so-course.git?a=blob;f=src/lib/fork.c;h=c19c987a68c87dee52f4ebb33b70a882b131012b;hb=HEAD">here</a>, I recommend you to keep it open while reading this section. Also note that for now on, when I say fork(), I will be referring to JOS&#8217;s fork().</p>
<p>Besides the memory management system calls presented in the first part of this series, fork() also uses the following system calls which deals with environment handling:</p>
<p>envid_t sys_exofork(void);<br />
int sys_env_set_status(envid_t envid, int status);<br />
int sys_env_set_pgfault_upcall(envid_t envid, void *upcall);</p>
<p>I will describe now how fork() works and will introduce the functions above when necessary. It is important to note that my goal here is just to give you a general overview.</p>
<p>In JOS, page faults caused by environments are handled in user-space. When a page fault happens, the kernel checks whether the environment which issued the page fault has registered a <em>page fault handler</em>. If it did, the kernel returns to user-space and executes the registered handler. If the environment did not register a page fault handler the kernel will kill it when a page fault happens.</p>
<p>The first thing fork() does on line 122 is to setup the calling process page fault handler. Both the parent and the child have to setup a page fault handler.</p>
<p>The next step on line 124 is to create a new environment by calling sys_exofork(). That function allocates a new environment from the poll maintained by the kernel, initializes it and copies the current context of the parent (that is, the parent&#8217;s registers&#8217; contents) into it. It is important to realize that sys_exofork() does only the very first part of the forking process.</p>
<p>After the new environment has been created, fork() executes its main code. It goes all over the parent&#8217;s <a href="http://en.wikipedia.org/wiki/Page_table">page tables</a> and each writable page is marked COW and read-only before being inserted into the address space of the child. Note that we have to remap the page into the parent as well, since the page permissions have been changed.</p>
<p>When the page setup is done, the parent does the final setup. Firstly it configures the child&#8217;s page fault handler and then the parent marks the child runnable with the call to sys_env_set_status(). That is, in exokernels it is up to the application to say when a newly created environment is runnable, not up to the kernel.</p>
<p>As long as the child is marked runnable, it can execute at anytime. If there are just a few environments running, it will probably run within the next few clock interruptions.</p>
<p>When the child is put to run by the kernel, it starts executing as if it was returning from sys_exofork(). The code in fork() is prepared to deal with this situation and on line 127 it checks whether it is the child which is executing and if it is, fork() finishes the setup and returns 0.</p>
<p>The process is now forked, and when any of the two tries to write to a page a page fault is issued by the hardware.</p>
<p>When the page fault happens the kernel will return to user-space and branch out to the page fault handler registered by fork(), which is pgfault() function on line 15. This function duplicates the page exactly as was explained in the first section of this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cpu.eti.br/2008/05/05/jos-virtual-memory-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JOS Virtual Memory (part 1)</title>
		<link>http://blog.cpu.eti.br/2008/04/15/jos-virtual-memory-part-1/</link>
		<comments>http://blog.cpu.eti.br/2008/04/15/jos-virtual-memory-part-1/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 20:37:48 +0000</pubDate>
		<dc:creator>Luiz Capitulino</dc:creator>
				<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.cpu.eti.br/?p=98</guid>
		<description><![CDATA[Introduction
In my last post I mentioned I was writing about JOS&#8217; virtual memory implementation. At first, I was going to write only one post but I have written so much that I had to split the post into two parts.
The first (this one), will talk about the exokernel design and will have a first look [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>In <a href="http://blog.cpu.eti.br/?p=93">my last post</a> I mentioned I was writing about JOS&#8217; virtual memory implementation. At first, I was going to write only one post but I have written so much that I had to split the post into two parts.</p>
<p>The first (this one), will talk about the exokernel design and will have a first look at JOS&#8217; memory management interface with user-space.</p>
<p>The second post will explain how the system calls presented in the first post work. But, instead of a boring explanation, I will show how the system calls fit together to implement a real JOS&#8217; feature: fork() with copy-on-write support. This feature is impressive because it is done mostly in user-space.</p>
<p>For both posts some background in memory management and operating systems is needed. For those who have learned it but forgot the details, the <a href="http://en.wikipedia.org/wiki/Virtual_memory">wikipedia article on virtual memory</a> <em>seems</em> to be sufficient. If you have never studied this subject before, I recommend you to read the memory management chapter from some operating systems book (I have learned from <a href="http://www.amazon.com/Operating-Systems-Implementation-Prentice-Software/dp/0131429388/ref=pd_bbs_sr_3?ie=UTF8&#038;s=books&#038;qid=1208282300&#038;sr=1-3">Tanenbaum&#8217;s</a>).</p>
<p>Something important to bear in mind is that I am just a beginner on this subject. Everything I know I have learned while working on JOS, so it is likely that you will find mistakes in this text. If you do, please, let me know by sending me an <a href="mailto: lcapitulino@gmail.com">email</a>.</p>
<p><span id="more-98"></span></p>
<p><strong>Quick introduction to exokernel design</strong></p>
<p>The important idea behind the exokernel design is that its interface with user-space is as simple as possible. In fact, what an exokernel does is to securely export all hardware resources to user-space and give applications the freedom to manage the hardware resources for themselves.</p>
<p>Most of what a Unix user would recognize as being an operating system task is implemented as an application library in an exokernel.</p>
<p>For example, in Unix kernels the basic system call to create a new process is <a href="http://linux.die.net/man/2/fork">fork()</a>. The application calls fork() and a new process is created. Everything is done in kernel-space and, roughly speaking, the application has no control over the process.</p>
<p>In an exokernel design, though, fork() is implemented in user-space. Here the application has full control over the process and could even define its own fork() with different semantics. Actually, fork() is not even special because it is just an ordinary library function.</p>
<p>Additionally, most kernel services that are usually implemented in kernel-space (such as File-systems and Networking) can be implemented by user-space applications in an exokernel design.</p>
<p>The main advantages of this design are:</p>
<p>1. The kernel does not limit the freedom of the application to design its own abstractions for physical resources<br />
2. In some cases, due to the high costs of heavy abstractions in kernel-space, you can have performance benefits from implementing abstractions in user-space<br />
3. Exokernels are small</p>
<p>Of course, there are disadvantages, one of them being that exokernel applications may not be portable among different exokernel implementations.</p>
<p>For more information regarding the exokernel design, I recommend to read the <a href="http://delivery.acm.org/10.1145/230000/224076/p251-engler.pdf?key1=224076&#038;key2=2519598511&#038;coll=&#038;dl=ACM&#038;CFID=15151515&#038;CFTOKEN=6184618">original exokernel&#8217;s paper</a>.</p>
<p><strong>A First look at JOS&#8217; memory management interface</strong></p>
<p>The following system calls are available to user-space applications:</p>
<p>int sys_page_alloc(envid_t envid, void *va, int perm);<br />
int sys_page_map(envid_t srcenvid, void *srcva, envid_t dstenvid, void *dstva, int perm);<br />
int sys_page_unmap(envid_t envid, void *va);<br />
int sys_env_set_pgfault_upcall(envid_t envid, void *func);</p>
<p>Before going into the details, it is important to understand what an environment is. In exokernels, an environment is the same entity as a process in Unix. Environments also have identification numbers, referred to as &#8216;envid&#8217;.</p>
<p>I will now describe in detail what each of the system calls above do. You may have the feeling that things are not very clear. Do not worry, things will get clearer soon:</p>
<p>sys_page_alloc(): allocates a page of physical memory from the free list maintained by the kernel and inserts that page into the address space of the environment at address &#8216;va&#8217;. The page permissions is set to perm.</p>
<p>sys_page_map(): maps the page of memory at &#8217;srcva&#8217; of environment &#8217;srcenvid&#8217; into address &#8216;dstva&#8217; of environment &#8216;destva&#8217;. The page permissions are set to &#8216;perm&#8217;.</p>
<p>sys_page_unmap(): unmap the page of memory at &#8216;va&#8217; in the address space of &#8216;envid&#8217;. If this is the lasting mapping of the page, it&#8217;s inserted back to the free list.</p>
<p>sys_env_set_pgfault_upcall(): set the environment &#8216;envid&#8217; page fault handler. When a page fault happens, the kernel branches to &#8216;func&#8217;.</p>
<p>Basically, to allocate memory in JOS, an application has to call sys_page_alloc(). It means that it has to know where the physical page should be mapped in its address space.</p>
<p>Of course, for widely used features (like memory allocation), the application could (and should) implement a memory allocation function, say malloc(). Such a function would define a specific area in the address space of the application for memory allocations, and manage it.</p>
<p>Indeed, JOS has malloc() implemented as a library function and it works as just explained. But it is important to note that it is more like a convention, because the application is still free to implement its own memory allocation function with whatever features it needs.</p>
<p>The next post will explain how the system calls presented above work in a real life JOS feature: fork() with copy-on-write support.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cpu.eti.br/2008/04/15/jos-virtual-memory-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JOS v0.1</title>
		<link>http://blog.cpu.eti.br/2008/04/02/jos-v01/</link>
		<comments>http://blog.cpu.eti.br/2008/04/02/jos-v01/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 12:49:52 +0000</pubDate>
		<dc:creator>Luiz Capitulino</dc:creator>
				<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.cpu.eti.br/?p=93</guid>
		<description><![CDATA[Since I really understood for the first time what an operating system kernel was, I had this utopian desire to write a simple (but functional) kernel.
Although I did not write JOS from scratch and had some help from others, I feel that I have finally archived my goal, because I have written most of JOS&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>Since I really understood for the first time what an <a href="http://en.wikipedia.org/wiki/Operating_system">operating system</a> <a href="http://en.wikipedia.org/wiki/Kernel_%28computer_science%29">kernel</a> was, I had this utopian desire to write a simple (but functional) kernel.</p>
<p>Although I did not write JOS from scratch and had some help from others, I feel that I have finally archived my goal, because I have written most of JOS&#8217; important parts.</p>
<p>But let me explain what JOS is about.</p>
<p>Last year, <a href="http://web.mit.edu">MIT</a>&#8217;s computer science department has made their <a href="http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-828Fall-2006/CourseHome/index.htm">Operating System Engineering course</a> available through <a href="http://ocw.mit.edu/OcwWeb/web/home/home/index.htm">MIT OpenCourseWare (OCW)</a>.</p>
<p>The course is just amazing. The <a href="http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-828Fall-2006/Syllabus/index.htm">goal</a> is to write a small operating system called JOS based on <a href="http://en.wikipedia.org/wiki/Exokernel">exokernel</a> design, and all the laboratory material is <a href="http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-828Fall-2006/Labs/index.htm">available online</a>.</p>
<p>Besides that, they provide test-cases for your code. The tests make it easy to know if you have done something wrong. Also, at the end of each class you are asked to run a script which will tell you whether you have passed to the next class.</p>
<p>This is the operating system course I have dreamed about since I started studying kernels, and I am very glad because I finished the course last December.</p>
<p>The final version of the system features the following:</p>
<p>- i386 support<br />
- Virtual memory<br />
- Preemptive multitasking<br />
- Simple IPC mechanism<br />
- Kernel debuger and monitor<br />
- Simple FS (supports file creation, writting and removal)<br />
- Basic shell<br />
- Minimalist bootloader</p>
<p>There are two more important features I have implemented but they are not fully functional: 4M pages and SYSENTER/SYSEXIT support.</p>
<p>If I remember correctly I did all the exercises and most of the &#8220;mandatory&#8221; challenges.</p>
<p>The source code is available <a href="http://repo.or.cz/w/mit-so-course.git">online</a> in a <a href="http://git.or.cz/">GIT</a> repository, you can clone it as follows:</p>
<p>$ git clone git://repo.or.cz/mit-so-course.git</p>
<p>You can also browse the source tree by clicking <a href="http://repo.or.cz/w/mit-so-course.git?a=tree">here</a>.</p>
<p>Now, if you are an MIT student, I have two things to tell you. First, before looking at my code be honest and check with your TA whether it is ok to study solutions from others.</p>
<p>The second thing is that your computer science course is just fantastic, I would not miss a single class if I were you!</p>
<p>By the way, I am about to finish an article about JOS&#8217;  <a href="http://en.wikipedia.org/wiki/Virtual_memory">virtual memory</a> implementation and will post it soon.</p>
<p>PS: I have another post about JOS in Portuguese, which I have written while I was still working on JOS, you can read it <a href="http://blog.cpu.eti.br/?p=65">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cpu.eti.br/2008/04/02/jos-v01/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Summer Of Code</title>
		<link>http://blog.cpu.eti.br/2008/03/17/summer-of-code/</link>
		<comments>http://blog.cpu.eti.br/2008/03/17/summer-of-code/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 13:20:40 +0000</pubDate>
		<dc:creator>Luiz Capitulino</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[summer of code]]></category>

		<guid isPermaLink="false">http://blog.cpu.eti.br/?p=91</guid>
		<description><![CDATA[Last year my application was selected by Google for their Summer of Code program, and before I tell you how wonderful the program is, I&#8217;ll show you one of the things I&#8217;ve done.
It&#8217;s a GIT binding for Python. So, you&#8217;ll have to know a little bit about them to understand the demonstration.
For example, say that [...]]]></description>
			<content:encoded><![CDATA[<p>Last year my application was selected by Google for their <a href="http://code.google.com/soc/2008/">Summer of Code program</a>, and before I tell you how wonderful the program is, I&#8217;ll show you one of the things I&#8217;ve done.</p>
<p>It&#8217;s a <a href="http://git.or.cz">GIT</a> binding for <a href="http://www.python.org">Python</a>. So, you&#8217;ll have to know a little bit about them to understand the demonstration.</p>
<p>For example, say that you want to get some information about commit<br />
4fbef206daead133085fe33905f5e842d38fb8da from <a href="http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=summary">Linus&#8217; GIT tree</a>, you could do:</p>
<p><code>&gt;&gt;&gt; import pygit<br />
&gt;&gt;&gt;<br />
&gt;&gt;&gt; linux = '/home/lcapitulino/src/kernels/upstream/linux-2.6'<br />
&gt;&gt;&gt; repo = pygit.open(linux)<br />
&gt;&gt;&gt;<br />
&gt;&gt;&gt; id = '4fbef206daead133085fe33905f5e842d38fb8da'<br />
&gt;&gt;&gt; com = repo.lookup_commit(id)<br />
&gt;&gt;&gt;<br />
&gt;&gt;&gt; print com.id()<br />
4fbef206daead133085fe33905f5e842d38fb8da<br />
&gt;&gt;&gt;<br />
&gt;&gt;&gt; print com.message()<br />
nfsd: fix nfsd_vfs_read() splice actor setup</p>
<p>When nfsd was transitioned to use splice instead of sendfile() for data<br />
transfers, a line setting the page index was lost. Restore it, so that<br />
nfsd is functional when that path is used.</p>
<p>Signed-off-by: Jens Axboe &lt;jens.axboe@oracle.com&gt;<br />
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;</p>
<p>&gt;&gt;&gt;</code></p>
<p>You can also, compare two commits.</p>
<p><code>&gt;&gt;&gt; com1 = repo.lookup_commit(repo.head_commit())<br />
&gt;&gt;&gt;<br />
&gt;&gt;&gt; id = '4fbef206daead133085fe33905f5e842d38fb8da'<br />
&gt;&gt;&gt; com2 = repo.lookup_commit(id)<br />
&gt;&gt;&gt;<br />
&gt;&gt;&gt; if com1 &gt; com2:<br />
...  print 'com1 is more recent'<br />
...<br />
com1 is more recent<br />
&gt;&gt;&gt;</code></p>
<p>[ For a complete demonstration click <a href="http://repo.or.cz/w/git/libgit-gsoc.git?a=blob;f=libgit-thin/pygit/README;h=dff14379188b544d1be60ad119a5f6efd6db9dcf;hb=HEAD">here</a> ].</p>
<p>One of the good things about the binding is that it doesn&#8217;t fork()/exec() GIT processes. Instead, it uses a <a href="http://en.wikipedia.org/wiki/Library_%28computing%29">library</a> which makes it fast and easy to deal with errors.</p>
<p>The goal of the <a href="http://code.google.com/soc/2007/git/appinfo.html?csaid=5DB940E4533E058B">project</a> was to write a high-level library for GIT. The reason for this is that GIT&#8217;s own library is very low-level. It means that to understand how to use it you have to understand GIT&#8217;s internals, but even then the API isn&#8217;t stable and it&#8217;s hard to link against (since it was written to only link against GIT&#8217;s programs).</p>
<p>Currently, the standard way to create software which accesses GIT repositories is to fork()/exec() GIT programs. The main disadvantages of this approach are:</p>
<p>1. It can be a slow operation<br />
2. It may not be easy to handle process execution<br />
3. It&#8217;s not easy to deal with errors<br />
4. There&#8217;s no flexibility</p>
<p>A well written library can solve all those problems. Besides that, in order to demonstrate the API usage and usefulness, I would write a binding for any high-level language. I chose Python.</p>
<p>The project was just wonderful. I&#8217;ve had a great time working on it. I&#8217;ve learned a lot about GIT, Python bindings and a little bit more about C and general program design. <a href="http://www.spearce.org">My mentor</a> is just a great person. He was always patient and taught me everything I know about GIT and its internals.</p>
<p>However, I&#8217;m not very proud of the final result. Firstly, I was very excited about the project as a whole and my expectations were quite high. I thought it would be merged upstream or at least would attract the attention of lots of interested people.</p>
<p>But that wasn&#8217;t exactly what happened. The main problem is that at the end of the project I had only a <a href="http://en.wikipedia.org/wiki/Proof_of_concept#In_software_development">Proof-Of-Concept</a> of the thing. Only a small amount of functions to extract information from repositories were written (plus the Python binding).</p>
<p>We did some successful experiments though, which showed us we were on the right track. For example, we made an initial port of one of the GIT graphical browsers, <a href="http://digilander.libero.it/mcostalba/">QGit</a>. We&#8217;ve removed a big portion of its code (which was dedicated to handling GIT processes) and although some changes were needed, the library fell into place nicely.</p>
<p>But I still feel a bit frustrated for not getting the project up to a &#8220;production&#8221; level. Some people are still interested in it, I receive about two emails per month asking questions about the project&#8230; Which makes me feel a bit worse.</p>
<p>After thinking about it for some time, I concluded that the main problems were:</p>
<p>1. I thought the four hours per day I had would be enough<br />
2. I didn&#8217;t expect to spend time as long as I did studying GIT and trying different designs</p>
<p>These are the reasons why I have decided not to participate this year (I still have only four hours per day). Maybe next year I&#8217;ll try again.</p>
<p>But it was a great <a href="http://repo.or.cz/w/git/libgit-gsoc.git">project</a>. I will never forget it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cpu.eti.br/2008/03/17/summer-of-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cool stuff at my junk code repo</title>
		<link>http://blog.cpu.eti.br/2007/08/29/cool-stuff-at-my-junk-code-repo/</link>
		<comments>http://blog.cpu.eti.br/2007/08/29/cool-stuff-at-my-junk-code-repo/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 16:37:17 +0000</pubDate>
		<dc:creator>Luiz Capitulino</dc:creator>
				<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.cpu.eti.br/?p=70</guid>
		<description><![CDATA[I&#8217;ve been organizing the stuff I have in my junk code repository and for my surprise I have a lot of cool stuff in there.
There&#8217;re examples of: mmap(), longjump(), fifos, signals, sockets and a lot more. On the data structures side: lists, queues , hash tables (here and here) and others.
But it&#8217;s important to say [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been organizing the stuff I have in <a href="http://blog.cpu.eti.br/?p=56">my junk code repository</a> and for my surprise I have a lot of cool stuff in there.</p>
<p>There&#8217;re examples of: <a href="http://repo.or.cz/w/lcapit-junk-code.git?a=blob;f=books/apue/mmap.c;h=2fe4225bda5d6c57aa46f3b8e6124d7824e67c53;hb=HEAD">mmap()</a>, <a href="http://repo.or.cz/w/lcapit-junk-code.git?a=blob;f=books/apue/longjump.c;h=737a91da1203f7595b1f1d0b5e73f0714be4504a;hb=HEAD">longjump()</a>, <a href="http://repo.or.cz/w/lcapit-junk-code.git?a=tree;f=books/apue/fifo;h=ab28c059657f8c94e1a1020cb9747c2718f6b07c;hb=HEAD">fifos</a>, <a href="http://repo.or.cz/w/lcapit-junk-code.git?a=blob;f=signal.c;h=9a721a085c174e6def6d7de6f346933e0468cb36;hb=HEAD">signals</a>, <a href="http://repo.or.cz/w/lcapit-junk-code.git?a=tree;f=books/tcpv1;h=af77f4a6be462033cb345d7f9ebc55096c274df4;hb=HEAD">sockets</a> and a lot more. On the data structures side: <a href="http://repo.or.cz/w/lcapit-junk-code.git?a=tree;f=books/mawc/lists;h=20f4522cc544ed027d11a305f9ce3da80121a01b;hb=HEAD">lists</a>, <a href="http://repo.or.cz/w/lcapit-junk-code.git?a=tree;f=books/mawc/queue;h=e999b389c7e0c7f856690692c25809d19a0a3f61;hb=HEAD">queues</a> , hash tables (<a href="http://repo.or.cz/w/lcapit-junk-code.git?a=tree;f=books/mawc/hash-tables;h=9ae4d59c40dcd8e6d9dce8740eeccc9aa75e3d9c;hb=HEAD">here</a> and <a href="http://repo.or.cz/w/lcapit-junk-code.git?a=tree;f=mega-sena;h=e90fe7a37029f71b233ae3556e3321e7c0dbf49f;hb=HEAD">here</a>) and others.</p>
<p>But it&#8217;s important to say that <strong>most of these examples were taken from books</strong> (mainly from <a href="http://www.amazon.com/exec/obidos/ISBN=0201563177/wrichardstevensA/">this</a> and <a href="http://www.amazon.com/Mastering-Algorithms-C-Kyle-Loudon/dp/1565924533">this one</a>), although I might have modified some of them.</p>
<p>There&#8217;re also some interesting Linux kernel code examples. For example, when I was working on the <a href="http://marc.info/?l=linux-usb-devel&#038;m=114921742628790&#038;w=2">USB-Serial layer port to the Serial Core API</a>, <a href="http://repo.or.cz/w/lcapit-junk-code.git?a=tree;f=linux-kernel/fake-serial;h=f0a1c673b71135b5421dcbfd5ef31526afa2cb6c;hb=HEAD">I&#8217;ve written two drivers</a> for a fake serial device. One driver uses the Serial layer directly (that&#8217;s what the USB-Serial layer does) and the other one uses the Serial Core API. Cool stuff, and was fun coding it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cpu.eti.br/2007/08/29/cool-stuff-at-my-junk-code-repo/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>repo.or.cz</title>
		<link>http://blog.cpu.eti.br/2007/07/20/repoorcz/</link>
		<comments>http://blog.cpu.eti.br/2007/07/20/repoorcz/#comments</comments>
		<pubDate>Fri, 20 Jul 2007 22:52:12 +0000</pubDate>
		<dc:creator>Luiz Capitulino</dc:creator>
				<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://blog.cpu.eti.br/?p=58</guid>
		<description><![CDATA[If you&#8217;ve read my last post and you&#8217;re not a repo.or.cz user, then you probably had a WTF moment.
The problem is that this:
http://repo.or.cz/w/lcapit-junk-code.git
Is not a valid git repository to be cloned, it&#8217;s just my repository&#8217;s gitweb page. Yeah, I know, the &#8216;.git&#8217; at the end makes you think it&#8217;s a git repository&#8230;
But it can get [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve read <a title="junk code" href="http://blog.cpu.eti.br/?p=56">my last post</a> and you&#8217;re not a <a href="http://repo.or.cz/">repo.or.cz</a> user, then you probably had a <em>WTF moment</em>.</p>
<p>The problem is that this:</p>
<p align="center"><a href="http://repo.or.cz/w/lcapit-junk-code.git">http://repo.or.cz/w/lcapit-junk-code.git</a></p>
<p align="left">Is <strong>not</strong> a valid git repository to be cloned, it&#8217;s just my repository&#8217;s gitweb page. Yeah, I know, the &#8216;.git&#8217; at the end makes you think it&#8217;s a git repository&#8230;</p>
<p align="left">But it can get even more confusing! Besides the gitweb&#8217;s URL, each project hosted by repo.or.cz also has three additional URLs, take a look:</p>
<p align="center">git://repo.or.cz/lcapit-junk-code.git</p>
<p align="center">http://repo.or.cz/r/lcapit-junk-code.git</p>
<p align="center">git+ssh://repo.or.cz/srv/git/lcapit-junk-code.git</p>
<p align="left">The first is the one you should use to clone my repository:</p>
<p align="center">$ git clone git://repo.or.cz/lcapit-junk-code.git</p>
<p align="left">So that git-clone can clone by using git&#8217;s protocol.</p>
<p align="left">The HTTP one can also be used to clone the repository, but git-clone will clone through (guess what) HTTP and that&#8217;s <em>slow</em>. You don&#8217;t want to use it, trust me. You should only use it if you&#8217;re behind a firewall or something like that.</p>
<p align="left">The last one is used by the repository&#8217;s owner to push into the repository, just ignore it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cpu.eti.br/2007/07/20/repoorcz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

