Friday Oct 19, 2007

I've been using mdb on a project and thought I'd post some of the dcmds and walkers I have written down here. These are all executed with mdb -k, but most work if you're inspecting a core dump or running kmdb.

Kernel related
::mappings

ktextseg::print
ktextseg::ptable
ktextseg::pte
ktextseg::vatopfn
ktextseg::vtop


0xfffffffffb800000::vatopfn
0xfffffffffb800000::vtop
0xfffffffffb800000::page


::kmem_cachekmastats
::nm
::objects


VM related
::memlist
::memstat
::threadlist


Scheduler/Dispatcher related
::class

CPU related
::cpuinfo
::cpupart
::errorq
::interrupts
::modinfo
::regs


FS related
::fsinfo
::nfs_stat


NUMA related
::lgrp

And here's an example of how it works and how cool this thing is.
We list the existing lgrps in the system with ::lgrps, print the root lgrp using it's virtual address, walk the lgroup's cpu_list with the lgrp_cpulist walker and print one of them.

> ::lgrp   
   LGRPID             ADDR           PARENT         PLATHAND      #CPU      CPUS
        0 fffffffffbc1f610                0          DEFAULT         2      0-1
> fffffffffbc1f610::print
{
    lgrp_id = 0
    lgrp_latency = 0
    lgrp_plathand = 0xbabecafe
    lgrp_parent = 0
    lgrp_reserved1 = 0
    lgrp_childcnt = 0
    lgrp_children = 0
    lgrp_leaves = 0x1
    lgrp_set = [ 0x1, 0x1 ]
    lgrp_mnodes = 0x1
    lgrp_nmnodes = 0x1
    lgrp_reserved2 = 0
    lgrp_cpu = cpus
    lgrp_cpucnt = 0x2
    lgrp_kstat = 0xfffffffec0440330
}
> fffffffffbc1f610::walk lgrp_cpulist
fffffffffbc26b30
fffffffec113b800
> fffffffffbc26b30
> fffffffffbc26b30::print 
[
    {
        cpu_id = 0
        cpu_seqid = 0
        cpu_flags = 0x1b
        cpu_self = cpus
        cpu_thread = 0xfffffffec6d894a0
        cpu_idle_thread = 0xffffff0002005c80
        cpu_pause_thread = 0xffffff00022abc80
        cpu_lwp = 0xfffffffec56e18b0
        cpu_fpowner = 0
        cpu_part = cp_default
        ...


And the always helpful ::whatis dcmd, describing what's on a given address.

> fffffffffbc26b30::whatis
fffffffffbc26b30 is cpus+0 in unix's data segment


Sunday Sep 30, 2007

Last Thursday I gave a talk about the kernel at my university, about 20 people showed up.
I talked about the scheduler, dispatcher and virtual memory. I'm still working on the slide deck, it's an overview of those systems with some of the structures that represent things like processes, threads, cpus.

I'm trying to show it's not such a 'black box' - like some people might think - by pointing out how some things are implemented. My idea is to get more people interested in contributing to the project. Check out the slides and send me some feedback. I'm all in favor of improving it so any comment is appreciated.
You can get the BR-Portuguese version at our OSUGs website.

Here are some photos..

Then yesterday (Saturday) I gave pretty much the same talk at a kick ass event organized by the TcheLinux user group. I'm really glad those guys invited us there. It's just amazing to see a positive and open attitude towards technology, specifically open source technology. More pictures..

I'll tell you this, with the great work they are doing, I won't be surprised to see their events grow to national or even international size. We had a blast. I hope everyone who attended our talks left feeling they didn't wake up early on Sat for nothing.

We handed out around 30 'Intro to OSs with OpenSolaris' books and SXDE DVDs between the two events. Good to see our OSUG growing.

Friday Sep 28, 2007

I spent some portion of this week preparing slides for an OpenSolaris Kernel talk I gave yesterday at campus and that I'm repeating Saturday at a TcheLinux event. I'll post some pictures and the slide deck after the Saturday session.

The last three or four slides are about building/booting the kernel and I thought it might be interesting to post the steps here. This is for x86 but the SPARC version is just about the same.

Downloading the goods:
1. $hg clone ssh://anon@hg.opensolaris.org/hg/onnv/onnv-gate my-copy

Here's a tip to allow compression. It should decrease your download time:
Edit your .ssh/config file and add
Host *opensolaris.org
Compression yes

2. Go to http://dlc.sun.com/osol/on/downloads/current/ and download SUNWonbld.i386.tar.bz2.
3. Get and read (really) README.OpenSolaris.

Installing the ON build tools
1. pkgrm SUNWonbld
2. bunzip2 -c SUNWonbld.i386.tar.bz2 | tar xf -
3. pkgadd SUNWonbld

Setting your environment
1. cp usr/src/tools/env/opensolaris.sh my-copy
2. gedit opensolaris.sh
3. set GATE to my-copy
4. set CODEMGR_WS to my-copy's path
5. set STAFFER to your login
6. set VERSION to whatever you wanna call it

Building the kernel
1. bldenv -d ./opensolaris.sh
2. cd /usr/src/uts
3. dmake all

Because we didn't do nightly ./opensolaris & before, /src/tools/proto isn't built.
So just go there and build it.

Building the tools
1. cd /usr/src/tools
2. dmake all

Booting
1. Install -G my.kernel -k i86pc
2. su
3. cd /
4. tar xf /tmp/Install.my.kernel .
5. gedit /boot/solaris/filelist.ramdisk
6. add /platform/i86pc/my.kernel to the end
7. gedit /boot/grub/menu.lst
8. add an entry pointing kernel to my.kernel
9. reboot

First steps towards developing:
1. gedit /usr/src/uts/common/main.c
2. add printf("Hello Kernel World!\n"); somewhere halfway through main()
3. recompile, install and reboot!

Cool huh? :)

Monday Jul 02, 2007

So, I'm doing my graduation project about NUMA architectures and what OpenSolaris and Linux do to support them. I'm halfway through it, getting to the implementation part of the project.
Here's the current book pile residing at my desk, it started lower, got a little bigger with some other OS books that I had to return to the library, and it's been stable (except for the occasional accident) for the last couple of weeks.


Starting at the top:
   "Just Enough UNIX", Paul K. Anderson
   "Solaris 9 Administration Guide", Paul Watters
   "Concurrent Programming in Java: Design Principles and Patterns", Doug Lea
   "Design Patterns", the Gang of Four one
   "Operating Systems: Internals and Design Principles", Stallings
   "Linux Kernel Internals", Beck and a bunch of equally intelligent folks
   "Solaris Internals", Richard McDougall and Jim Mauro
   "Linux Kernel Development", Robert Love (from Novell)
   "UNIX Systems for Moderns Architectures", Schimmel
   "Pthreads Programming", Nichols et al
   "Linux Programming", Neil Matthew and Richard Stones
   "UNIX Internals", Vahalia

Check out a couple of paragraphs from the VM part of the monography, feel free to comment on it. It's what I'm calling a "release candidate for a draft".

"Usually, UNIX processes on 32bit architectures can theoretically occupy as much as 4Gb of space. However, memory is a scarce resource and the system shares it between all running processes. So when it is time to bring a new process to memory, the system begins by bringing a few necessary pieces of the program. This portion that resides in memory is called the resident set of the process. If the processor encounters a memory reference to a part of the process that is not currently loaded, it blocks the execution of such process and brings that data to memory from disk [STA 05]."
...
"UNIX systems use both virtual memory and paging as memory management techniques. We now have processes divided into pages, being loaded into memory frames as these pages are needed during execution. Such method of bringing pages as they're necessary is called demand paging."

I'm currently finishing the MPO/liblgrp and libnuma part of the paper. Once that's done, it's just a matter of polishing the whole thing and making it more readable. It gets difficult to explain even the simpler concepts with a new perspective, focusing on what the project is about.

But I'm getting there.

This blog copyright 2009 by rv