Tuesday, June 23, 2009

Debug bash function interactively


#!/bin/bash

# processing command line parameters
if [ $# -eq 2 ]; then
p1=$1
p2=$2
fi

# setup some environment
export A=a
export B=b

tmpfile=/tmp/myshell-$$-$RANDOM

trap "rm $tmpfile" EXIT

cat <<EOF > $tmpfile
if [ -f /etc/bash.bashrc ]; then
source /etc/bash.bashrc
fi

if [ -f $HOME/.bashrc ]; then
source $HOME/.bashrc
fi

source <shell functions in this file>

export PS1="My Shell$ "
EOF

/bin/bash --rcfile $tmpfile

Shell script parameters - a simpler way


#!/bin/sh

for param in "$@"; do
eval "$param"
done

param1=${param1:-param1}
param2=${param2:-param2}
param3=${param3:-param3}

echo $param1 $param2 $param3

Usage:


param.sh param1=<param1> param2=<param2> param3=<param3>

Friday, June 19, 2009

GNOME desktop layout for small screen

Default GNOME desktop layout is for typical workstation screen (> XGA). For smaller screen such as netbook (typically 1024x600), too much vertical space is been occupied by two desktop panel and window title bar. This is worse for wide screen, which has relatively small vertical space.

Desktop screenshot before optimizing

To optimize vertical space utility, the following method can be used:

  • Remove bottom panel (or top panel)
  • Replace expanded menubar in panel with collapsed one.
  • Compile and install window-picker-applet, which provides a compact task icon list and focus task title.

    It can downloaded from here. I write a small patch to add window maximizing toggling support to it, which can be downloaded from here.

  • Remove window title bar for maximized window. For metacity this can be done via theme customization, that is, change the "frame_geometry" with name "normal_maximized" as follow:
 <frame_geometry name="normal_maximized" parent="normal"  rounded_top_left="false"
rounded_top_right="false" rounded_bottom_left="false" rounded_bottom_right="false" has_title="false">
<!-- strip frame spacing off the normal geometry when maximized -->
<distance name="left_width" value="0"/>
<distance name="right_width" value="0"/>
<distance name="bottom_height" value="0"/>
<distance name="left_titlebar_edge" value="0"/>
<distance name="right_titlebar_edge" value="0"/>
<distance name="title_vertical_pad" value="0"/>
<border name="title_border" left="0" right="0" top="0" bottom="0"/>
</frame_geometry>

Desktop screenshot after optimizing

Saturday, June 13, 2009

Reading notes: optimizing Linux performance

Chapter 3

  1. vmstat can show swap in/out pages. A simultaneously high swap-in and swap-out rate could indicate that the system does not have enough memory to handle all the running processes.
  2. slabtop is "top" for slab.

Chapter 4

  1. strace can show system call performance statistics too (strace -c).
  2. ltrace: performance statistics for library (like strace, but library function instead of system call).
  3. ld.so: dynamic load/link statistics for libraries. Example: env LD_DEBUG=statistics LD_DEBUG_OUTPUT=lddebug gcalctool

Chapter 6

  1. iostate: show disk IO statistics

Chapter 7

  1. netstat -c: period update
  2. netstat -t: choose tcp protocol
  3. netstat -l, -a: listening sockets or listening + conntected.

Chapter 8

  1. script: record what you have done and the output, seems useful.
  2. gcc -g3: provide more debug information then gcc -g (default to
    • g2), such as the macro definitions present in the source.

Chapter 11

  1. Use gdb to check call chain:
    • Set a breakpoint at check-point
    • gdb can execute a given set of commands when it hits a breakpoint. By using the command command, we can tell gdb to execute bt; cont every time it hits the breakpoint.
    • Conditional breakpoint can be implemented via gdb script (commands) too. For example, we can enable breakpoint 2, when we reach breakpoint 1.
    • gdb output can be logged to a text file via: set logging on
  2. oprofile reveals which function is hot, but do not show how many times it is called. ltrace or some other traces shows which function (including subfunctions) consumes most CPU time. This is from two perspective, and they can be combined to inspect the performance property.
  3. For Fedora and Enterprise Linux, Red Hat provides a set of debuginfo rpms that contain all the symbol information and sources that were generated by the compiler when the application was complied. Each binary package or library has a corresponding debuginfo rpm that contains the debugging information. This allows Red Hat to ship the binaries without the disk-space–consuming debugging information. However, it allows developers, or those investigating performance problems, to download the appropriate debuginfo packages and use them. In this case, Red Hat's version of oprofile will also recognize the debuginfo packages and pick up the symbols when profiling both an application, such a nautilus, and a library, such as gtk.
    • Debian has similar binary debug symbol packages: -dbg

Chapter 12

  1. strace to find bottleneck of IO intensive application.
    • Oprofile can be used only for CPU intensive application. Because IO is performed in kernel space, strace is the right tool to reveal which kind of IO application is performing.

Chapter 13

  1. This call-tree tool would be useful even if it dramatically slowed down application performance as it runs. A common way of using this would be to run oprofile to figure out which functions in an application are "hot," and then run the call-tree program to figure out why the application called them.

Reading notes of internals of the RT patch

  1. Real-time is something about predictability instead of performance, throughput or latency. That is, real-time system may have worse average throughput or latency, but it will have better largest latency or lowest throughput. Linux kernel have great average performance but the worst one is not so good.
  2. The drawback of Robert Love's kernel preemption patch is: A high priority process must still wait on a lower priority process while it is in a critical section, even if that same high priority process did not need to access that section.
  3. The RT patch is all about determinism and being able to have full control of the kernel. But, like being root, the more power you give the user the more likely they will destroy themselves with it. Such as, a user process can have higher priority than IRQ handler, if the process holding the CPU, system will hang.

Why NMI is not used widely in Linux kernel

"There are some systems where NMIs are broken (e.g. a lot of ThinkPads explode when they get NMI inside SMI). This was one of the reasons the NMI watchdog is not enabled by default anymore." From Andi Kleen.

force_sig_info

Behavior of force_sig_info

  • If SIGXXX is blocked or ignored: unblock SIGXXX, reset action to SIG_DFL

Force_sig_info in some special environment

  • kvm_arch_vcpu_ioctl_run(), SIGXXX is blocked
    • SIGXXX is unblocked, but before returning from kernel:kvm_arch_vcpu_ioctl_run(), it is blocked again (restore host signal mask).
  • In sys_rt_sigtimedwait(), SIGXXX is blocked
    • SIGXXX is unblocked, but before returning from sys_rt_sigtimedwait(), it is blocked again (restore to original signal mask).

Fast boot

How to make Linux boot faster?

  1. Keep CPU and disk I/O usage rate to or near 100%, that is, take full advantage of CPU speed and disk I/O throughput.
  2. Reduce works needed in boot.

Previous, I think the method 2 is more important, such as substituting boot with resuming from hibernation. But I think Moblin team achieve a great result with mainly method 1.

Audio and real-time

Only audio playback and audio recording do not need much real-time capability of system. Because you can just need to prepare a buffer big enough until next refill (or re-consume).

The real real-time demanding work is something like VOIP, a small buffer should be used to keep speak-to-hear lag low.

SNES9x for Zaurus Akita with rotate

The resolution of zaurus akita is 480x640 (or 240x320) instead of 640x480 (or 320x240). While SNES9x uses resolution 640x480 or 320x240, so rotation should be implemented in some layer of the graphic stack. The possible graphic stacks are:

  1. SNES9x + X Window + frame buffer
  2. SNES9x + SDL + X Window + frame buffer
  3. SNES9x + SDL + frame buffer

Rotation has been implemented in X window so for 1 and 2, there is no need to implement rotation in SDL or SNES9x. But the performance of 1 and 2 is worse than 3. So I implement the rotation in SNES9x. The patch can be downloaded here.

Some software for tablet PC

  • Stroke (gesture recognition)
    • I find easystroke is the best so far. To make it easier to enable/disable easytroke, (because several gesture recognition programs in system may conflict, for example, there is gesture recognition in firefox too.) I write a small patch to disable/enable easystroke with left button, which can be downloaded from here.
  • Note taking with pen
    • I think xournal is very good. It can be used to add annotations to PDF files.

Firefox addons for tablet PC

  • Grab and Drag

    Enables Adobe Acrobat-style grab and drag scrolling in Mozilla applications.

  • All-in-One Gestures

    This extension allows you to execute common commands using mouse (pen) gestures.

    Several mouse gestures programs may conflict each other, so I write a simple AIOGControl (All-in-One Gestures) control addon to enable/disable All-in-One Gestures via a Firefox toolbar button. This is easier for pen to operate.

Finger friendly scrollbar in GTK+

Standard GTK+ scrollbar is too small for finger, to make it bigger, you can put following code in your .gtkrc-2.0 or gtkrc file of theme.

style "big-scrolls" {
GtkRange::stepper-size = 50
GtkRange::slider-width = 50
}

class "GtkScrollbar" style "big-scrolls"

Please refer to http://www.roosmaa.net/index.php/2009/02/09/making-gtk-scrollbars-more-touchscreen-friendly/ too.

Comparison against overflow

Time variables are subject to overflow. So, the comparison statement as follow will return incorrect result if t1 has overflowed and t2 has not overflowed.

unsigned long t1, t2; if (t1 > t2) printf("t1 > t2");

The code as follow can be used to deal with the above issue.

unsigned long t1, t2; if ((long)(t1 - t2) > 0) printf("t1 > t2");

Suppose sizeof(unsigned long) = 4, and t1 < t2, the result of t1 - t2 under the unsigned semantics is (0x100000000 + t1 - t2), because of borrow, if the result < 0x80000000, in signed semantics and complemental code, the result is positive.

Screen with title in status bar

screen is a nice terminal tool.

  1. cp example screenrc from doc to home directory
  2. Add following lines to screenrc, window titles of current screen session will be shown in status bar with current window title hilighted.
hardstatus string "%h"
caption always "%{=r}%?%{b}%-Lw%?%{+bu r}%n*%f %t%{R}%{-bu}%?%{b}%+Lw%: %?%{+b B}%=%C:%s"

Mer: Comparison with desktop distributions

Comes from a presentation of mer community.

Is Mer just yet another linux distribution? Many people would disagree since we break quite a lot of things (Maemo GTK is a big one!), and I'll tell you some of the ways we differ.

Like Maemo we focus on power saving, some things that make sense on desktop/laptop distributions simply doesn't make sense on mobile devices that's supposed to last on the same charge several days being always­connected.

A tablet still comes with limited storage space, so there might be a need to shrink packages or dependancies (why do we need a weather library for NetworkManager?); but not hard as on an embedded system; there's miles difference between 256m flash and 64mb flash.

Yes, you can't run Crysis on a tablet, it has CPU, memory and bandwidth constraints and apps should be suited towards that. But, what it can do is to be more powerful because of the environment and services surrounding it.

Hard disk image in qemu

create/update image

Install a mini linux system in </sub-linux>. It is very easy to install debian inside another Linux.

Update image quickly

quick_upimg.sh

 qemu-img create -b <hd.img> -f qcow2 <hd.qcow2> 

Update image

upimg.sh

 sudo genext2fs -d </sub-linux> -b 344800 <hd.img> chown <yourself>. <hd.img> quick_upimg.sh 

If you use <hd.qcow2> in QEMU, <hd.img> will not changed for ordinary usage.

commit changes

You can explicitely commit changes to <hd.img> by qemu monitor command "commit".

access qcow2 image

 $ qemu-nbd [-p <port>] hd.qcow2 $ sudo modprobe nbd nbds_max=<2> $ sudo nbd-client localhost <port> /dev/nbd0 $ sudo mount /dev/nbd0 /mnt 

after using:

 $ sudo umount /mnt $ sudo nbd-client -d /dev/nbd0 

Blog with muse

Recently I decide to use muse as my primary composing tool. Because:

  • Easy to use.
  • Mark based instead of WYSIWYG. Full control of output and document structure.
  • Can convert to many other format, including docbook and latex. So if formating capability of muse is not enough, we can use other format instead later.

To use muse to write blog (mainly for blogspot):

  • Instal muse-el
  • Add "(require 'muse-blosxom)" into your .emacs
  • Write your blog in emacs with muse mode.
  • "C-c C-t" to generate output in blosxom-html format.
  • Open generated blosxom-html, "C-x h" to mark whole buffer, "M-!" to run a external shell script on your current buffer to do some post-processing. The shell script can be as follow.
 sed -e '1d' -e '/^#postdate/d' | tr '\r\n' '  ' 

ACPI dump

  1. acpidump > <dump_file>
  2. acpixtract -a <dump_file>
  3. iasl -d <TAB>.dat

New process group in shell script

To create a new process group for a command (or another shell script) in bash script, the following method can be used.

 b=$(bash -i -c "<command> & echo \$!") 

This can be put in a shell script. String after -c will be executed by the (sub-)bash, while -i means the (sub-)bash will behave like a interactive bash. So "<command> &" in string will execute <command> in a new process group, just like "<command> &" is typed in a login shell. The "echo \$!" in string will print the process ID, that is, the new process group ID, so you can operate on the new created process group, such as send signal to process group via "kill -SIGNAL -$b".

Saturday, May 16, 2009

A new method to distinguish between ring buffer full and empty

One design choice for ring buffer implementation is to distinguish
between full buffer and empty buffer. Traditional methods including
waste one entry for full (head + 1 == tail), or use
another flag for full. A new method is implemented as follow:

#define RING_LEN   16
#define RING_LIMIT (2 * RING_LEN - 1)

struct ring_entry
{
...
};

struct ring
{
int head;
int tail;
struct ring_entry entries[RING_LEN];
};

int ring_index(int n)
{
if (n > RING_LEN)
return n - RING_LEN;
else
return n;
};

int ring_get(struct ring *ring, struct ring_entry *entry)
{
/* empty */
if (ring->head == ring->tail)
return 0;

*entry = ring->entries[ring_index(ring->tail)];

ring->tail++;
if (ring->tail > RING_LIMIT)
ring->tail = 0;
return 1;
}

int ring_put(struct ring *ring, struct ring_entry *entry)
{
int ihead, itail;

ihead = ring_index(ring->head);
itail = ring_index(ring->tail);

/* full */
if (ihead == itail && ring->head != ring->tail)
return 0;

ring->entries[ihead] = *entry;

ring->head++;
if (ring->head > RING_LIMIT)
ring->head = 0;
return 1;
}

Buffers in Linux kernel

For 2.6.30

Oprofile Buffer

  • One cpu_buffer for each CPU
    • NMI or IRQ handler add record to cpu_buffer
    • Timer based per-cpu work queue remove record from cpu_buffer
    • One reader and one writer, so it is easy for mutual exclusion and synchronization
    • fix size, may overflow if write too much or not removed quickly enough
  • One event_buffer
    • Timer based per-cpu work queue add record to event_buffer from that of cpu_buffer
    • User space program remove record from event_buffer. User space program is waken up based on threshold.
    • One reader and multiple writer, mutex is used on write side, because writers are in process context (work queue).
    • fix size, may overflow if write too much or not read out quickly enough
  • Synchronization between cpu_buffer, event_buffer and use space program
    • Used for profile, so record flow bandwidth is predictable
      • Maximum bandwidth for cpu_buffer: CPU number * (cpu_buffer size / timer interval)

Unified trace ring buffer

  • One ring_buffer_per_cpu for each CPU
    • In fact two levels of records, the first level is struct buffer_page, the second level is struct ring_buffer_event.
    • Preempt disabling is used to provide mutual exclusion between process contexts.
    • Inside one struct buffer_page, atomic operation (local_add_return) is used to provide mutual exclusion for struct ring_buffer_event. Because process context can only be preempted by IRQ and NMI, and process context can not continue until IRQ and NMI finishes. The length of struct buffer_page is known (local_add_return may exceed buffer_page length).
    • In writer side, "write" indicates allocated records, while "commit" indicates completed records.
    • spinlock (ring_buffer_per_cpu->lock) and IRQ disable is used to provide mutual exclusion for struct buffer_page (reader and writer). In NMI environment, if try_spin_lock failed, the record is discarded, this acceptable for tracing.
    • At least 3 pages are needed for each CPU, 2 buffer_page, 1 reader page.
    • ring_buffer_per_cpu->reader_lock is used to provide mutual exclusion between multiple readers, while ring_buffer_per_cpu->lock is used to provide mutual exclusion between reader and writer.
    • fix size, may overflow if write too much or not consumed quickly enough
    • Iterator (iter) can be used on reader side

Mcelog buffer

  • One global buffer with fixed record length, fixed size. May overflow.
  • Writer side lock-less, implemented using cmpxchg() + finished flag. Records are added in NMI/timer context.
  • Memory order should be considered explicitly because of lock-less
  • Reader side is protected by mutex, because normally there is only one reader. Records are removed in process context.
  • Multiple writers, one reader, throughput bottleneck lies in reader side.

SMP preemption -> UP preemption

Sometimes, a SMP environment can turn into a UP environment via per-CPU data structure. Such as unified trace ring buffer is a per-CPU data structure, so the mutual exclusion can be considered in UP model for each per-CPU buffer.

Preemption in UP

There are 3 kinds of contexts in UP environment.

  1. Process context
  2. IRQ context
  3. NMI context

Where 1 can be preempted by 1, 2 or 3; 2 can be preempted by 2 or 3; 3 can not be preempted.

If preempt is off in 1, 1 can only be preempted by 2 or 3. And there is no interleave between contexts, that is, if 1 is preempted by 2, 1 will not be resumed until 2 is finished, so do 2 and 3. This can be used to develop more efficient synchronization algorithm.

If IRQ is off in 1 and 2, 1 and 2 can only be preempted by 3, without interleave.

Saturday, May 9, 2009

Reading notes of on submit kennel patches (OLS)

!!! Important kernel design point !!!

Very generic notifiers and hooks tend to have a large maintenance impact because they have the potential to alter the code flow in unexpected ways, lead to lock order problems, bugs, and unexpected behavior, and generally making code harder to maintain and debug later.

Linux kernel is a lock-based complex parallel system, the main method to prevent ABBA style dead-lock is enforcing lock order. But notifiers or hooks makes it hard to audit the order of locks.

Notifiers or hooks in lower layer to call functions on higher layer should be avoided. One method to call higher layer function in lower layer is via work queue like asynchronous mechanism.

Notifiers or hooks in higher layer to call functions on lower layer is OK. Such as struct file_operations is collections of function pointers (a kind of hooks?), it is only used as some kind of abstraction for lower layer, make adding new lower layer component more convenient.

Maintenance

For a project which is very complex like Linux kernel, (seems that most projects become more and more complex as time goes by), maintenance is something in the core of Linux kernel development.

To make code maintainable, firstly, code should be made readable. The code is clean-upped and redesigned again and again to make it cleaner, thus more readable.

It is much easier to add a component under the current design. Such as add a new device driver. If you need something to be changed in subsystem core, you should consider the design, maybe you need clean-up or redesign some part of the subsystem core to make code maintainable.

A patch submitter should maintain his code at least for a short while after merging.

Interface designs for user space programs is very important too. It should be stable for imaginable future.

Changing a published interface later is much harder and often special backwards compatiblility code is required.

Friday, May 8, 2009

Why MID?

What I need for a Mobile device

  • Fast from picking up to using (Fast boot)
  • light, easy for taking and hand holding
  • Applications
    • Web browsering
    • Electric book
    • Online video and offline video
    • PIM
    • Game
    • GPS?

MID vs Notebook

pros:
  • Fast from picking up to using: fast boot time or always suspend to RAM instead of power off.
  • lighter, easy for taking and hand holding
cons:
  • Screen is too small for some applications, especially most web page, PDF, DJVU ebooks
  • Notebook has better Linux support, some application has best usability on Notebook.

MID vs Smartphone

pros:
  • Screen is bigger, although smaller than Notebook, much better than smartphone's.
  • OS is compatible with Desktop ones (Linux or Windows), most desktop applications can run on MID. Although Linux based smartphone can run most desktop applications too, the resource of most smartphone is not enough for desktop application.
  • Computing resource of MID (CPU, RAM, storage) is much better than smartphone.
cons:
  • Smartphone is all-in-one solution, that is, you can bring just smartphone or smartphone AND MID.
  • Smartphone has GPRS support in China, while most MID has not.
  • Some smartphone application is good for small screen, such as ucweb for web browsing. Some desktop application is not good for small screen, even bigger screen of MID.

Comparison

Notebook(X61T) MID (no yet) Smartphone(N78) PDA (Zaurus)
Fast usage 1 4.5 5 4.5
Weight 1 4.5 5 5
Browsing 5 4 ~ 4.5 3 (ucweb) 2
EBook 5 3 ~ 3.5 2.5 (screen) 3
Online Video 5 4.5 0 (no WIFI) 0 (too slow)
Offline Video 5 4.5 4 3.5
PIM 4 4 4 3
Game 5 5 2 (keypad) 4
GPS 0 5 (maybe) 5 0

Conclusion

  • Although MID should be better than smartphone, there is no good choice until now. Aigo or Vilivs is too expensive. Smart Q5 is not better than Zaurus (No stable software too). Most functions of MID can be accomplished with smartphone.
  • Notebook + smartphone is good for now, waiting for better MID.

Sunday, April 26, 2009

On screen keyboard

On screen keyboard is necessary for a tablet PC. Have tried several on screen keyboard implementation under X window, no one is perfect. Currently using one is cellwriter. Hope the one developed for Moblin will be better.

Requirement for on screen keyboard:
  • Focus: the on screen keyboard should not be focused, and the faked key should be sent to the focused window.
  • Window placement: the on screen keyboard window should not be covered by other windows (for example to be the top-most window), and it should not cover other windows completely (semi-transparent or docked at the desktop side, but it seems docking is not supported well in my metacity 2.24.0).
  • Compatible with XIM. I am Chinese, I need use XIM to input Chinese.
  • Configurable layout (to keep only the needed keys).
  • Show/Hide can be controlled easily (via a panel button is preferable).
  • Support screen rotation. On screen keyboard should not outside the screen or bigger than screen after rotation.
Tried on screen keyboard software:
  • xvkbd: does not handle focus perfectly, the xvkbd itself seem be focused too (titlebar highlighted), so need two click for one key; need to specify which widget faked keys go, not very conveniently.
  • matchbox-keyboard: good support for rotation, configurable laout, XIM, focus. Docking support for matchbox-wm is good. Original version does not support docking for metacity. I have a hack to support docking for metacity, but the hack doesn't support metacity 2.24.0. Show/Hide control can be done with daemon mode (-d) + matchbox-keyboard-toggler utility.
  • gok (gnome on screen keyboard): recommended by many guys, but not good for me. Appears not works with XIM, and not works well without pointer in/out event.
  • onboard: not used too much, I think it is good and simple.
  • cellwriter: hand writing recoganizing program, but it is a good and simple on screen keyboard too. To use it as on screen keyboard add "--keyboard-only" to command line. Do no support configurable layout. Seems not support docking good.

Lenovo Thinkpad X61 Tablet

Bought a Lenovo Thinkpad X61 Tablet recently. Will post some usage tips. Most useful links:

http://www.thinkwiki.org/wiki/ThinkWiki

Evtouch configuration

This article is mainly for Tablet Classmate PC.

Evtouch is a Xorg (X window system) input driver for touchscreen device with Linux kernel input/event driver. For example some USB touchscreen device with USBHID class.

To use evtouch Xorg driver, xorg should be setup as follow:


--------------------------------------------------------------------------------
Section "InputDevice"
Identifier "TOUCH"
Driver "evtouch"
Option "Device" "/dev/input/by-path/pci-0000:00:1d.3-usb-0:1:1.0-event-"

Option "DeviceName" "touchscreen"
Option "ReportingMode" "Raw"
Option "MoveLimit" "10"
Option "SendCoreEvents" "On"
# Option "Calibrate" "1"
Option "MinX" "1"
Option "MinY" "1"
Option "MaxX" "4090"
Option "MaxY" "4090"
Option "x0" "-6"
Option "y0" "8"
Option "x1" "1"
Option "y1" "2"
Option "x2" "12"
Option "y2" "2"
Option "x3" "5"
Option "y3" "3"
Option "x4" "-6"
Option "y4" "3"
Option "x5" "-4"
Option "y5" "3"
Option "x6" "0"
Option "y6" "5"
Option "x7" "1"
Option "y7" "5"
Option "x8" "1"
Option "y8" "5"
EndSection

Section "ServerLayout"
......
InputDevice "TOUCH"
EndSection
--------------------------------------------------------------------------------


Calibrate by hand


Evtouch comes with a calibration utility. It works, but I find the result is not very accurate. In fact it can be calibrated further by editing xorg.conf directly.

  • If you find when you touch the margin of the screen, the cursor is not at margin, you can change the "MinX", "MinY", "MaxX", "MaxY" in xorg.conf to calibrate.
  • The x0-y0 to x9-y9 corresponds to 9 regions on screen, with the x0-y0 at the left-bottom corner, x2-y0 at the right-bottom corner, x9-y9 at the right-top corner. To calibrate the touch screen in the region, just the values of corresponding options.

Rotate screen


To rotate screen:
xrandr --output LVDS --rotate left

evtouch should have supported rotation automatically. But the evtouch-0.8.7 in my debian does not work. I write a small patch 08__fix_rotate.patch to fix this issue.

Suspend and Resume


My touchscreen device is a usb device. This means it will be removed by Linux kernel before suspend and re-plugged after resume. Evtouch xorg driver has suspend and resume support mechansim, but it does not work sometimes. From the error message in /var/log/Xorg.0.log, it seems that the underlaying usb kernel device is not ready when evtouch xorg driver is being initialized. Fortunatally, it works sometimes. So if it your touchscreen does not work after resume, just go suspend again and hope it works after next resume.

Right Button


I am not successful in configuring right button. Maybe a kernel input driver issue, usbhid can not report BTN_TOUCHED for my device. But it seems that the following configuration should work for correct kernel input drivers.


--------------------------------------------------------------------------------
Section "InputDevice"
Identifier "TOUCH"
Driver "evtouch"
......
Option "longtouched_action" "down"
Option "longtouched_button" "3"
EndSection
--------------------------------------------------------------------------------

Thursday, April 2, 2009

IBSuite

To read book on my PRS505 e-book reader, I write some tools. Now I collect these tools into IBSuite (Image Book Suite), and put that on sourceforge. You can download the source code from the git of sourceforge project. Hope that can be useful for somebody.

http://sourceforge.net/projects/ibsuite/

IBSUITE

ibsuite stands for image book suite. It contains a set of tools to convert ebook in various format (pdf, chm, html) into a set of images, reformat the images (crop, embold, divide, etc), and assemble the result images into a new ebook.


COMPONENTS

  • ibhtml2img: convert html to image with xulrunner
  • ibhtml2pdf: convert html to pdf with xulrunner
  • iblineparser: parser input image, extract line information
  • ibpdfinfo: get some meta-information from pdf file, such as title, author, table of contents etc.
  • ibpy: python module, which is the driver of the whole system, it uses above programs to convert input file to image, extract line information from image, dilate image, and re-assemble lines into a new image, generate output e-book.
  • ibtools: A set of utilities and tools, some of them are used internal by ibsuite, others are user command provided by ibsuite.


USAGE

The most important command of ibsuite is ibreformat, the basic usage is as follow:

ibreformat [options] <input file>

In most cases, something like following:

ibreformat -o <output file> --iprof=<iprof> --oprof=<oprof>
--pprof=<pprof> <input file>

Where <input file> is input file name, <output file> is output file name, <iprof> is input profile, <pprof> is output profile, is <pprof> processing profile.

Available input/output/processing profiles are as follow:


input profiles:
img: for scanned book

output profiles:
prs505p: for Sony PRS505 in portrait mode
prs505l: for Sony PRS505 in landscape mode

processing profiles:

divide2: divide one line into two line (a kind of simple reflow)
resize: Resize and dilate pages
repage: Re-page input book, without much other processing such as dilate.

For other command line options, please refer to "ibreformat -h".


Some useful command line option combinations:

For scanned book on PRS505:

ibsuite -o -iprof=img -pprof=resize -oprof=prs505l
<input file>

For chm file on PRS505:

ibchm2imb .chm

When it finishs, .imb will be generated, then

ibsuite -o -pprof=repage --oprof=prs505l .imb


INSTALL

Currently, only Linux is supported, but I think it may work on some unix enviroment (including cygwin on Windows) after some work. Currently only install from source code is supported.

Pre-requirement:

  • gcc, g++, bash, make
  • libfontconfig-dev, libnetpbm-dev, libgtk-dev
  • python, python-imaging
  • imagemagick
  • for HTML/CHM support: python-chm, xulrunner
  • for scanned book: unpaper

Build:

./configure [--prefix=]
make [PREFIX=] [NO_XUL=1]

Install:

# become root
make install [PREFIX=]