Release of COREMU

July 21st, 2010 2 comments

PPI 半年了,COREMU 终于在 sourceforge 上发布了。COREMU 的主要工作是王肇国(我本科同学,现在也在 PPI)完成的,其他开发人员可以在 PPI 的 COREMU 项目主页上找到。

简单说 COREMU 把 Qemu 并行化了。原先的 Qemu 只能使用一个物理 CPU,COREMU 则是使用多个物理 CPU 来模拟虚拟 CPU。

目前 COREMU 只能在 x86_64 Linux 系统上运行,支持模拟 x86_64 和 ARM Cortex A9 MPCore。在我们的测试用的 4 核系统上能模拟出 255 核,并且成功运行 Linux。

在这里宣传一下。半年来一直与 bug 做斗争,现在终于发布了,希望 COREMU 能够发挥些作用。有什么问题的话欢迎发邮件联系 :) cyfdecyf at gmail dot com

Tags:

RDC 远程 64bit win 7 没声音的解决方法

July 7th, 2010 1 comment

找的有点辛苦。。。装个 hotfix 就可以了,注意不同版本的系统要下不同的 hotfix。

话说微软的 hotfix 要用起来还真麻烦,邮件申请,还要用密码解压。。。好在很快能搞定

另外装了这个 hotfix 以后 CoRD 还是没声音,只好用 RDC 了。

Tags:

Linux initial ramdisk 以及启动过程

May 1st, 2010 1 comment

推荐一篇 IBM developerworks 上的文章,Linux initial RAM disk (initrd) overview,很详细一篇介绍,包括了内核里哪些函数涉及到启动过程。另外 man initrd 也有相关的介绍。

不过文章的内容已经有点过时,内核启动过程调用的函数发生变化,默认执行的 initrd 里的程序也从 /linuxrc 变成 /init。另外现在 Linux 发行版大多用 cpio 格式的 initrd),这篇文章介绍的是 ext2 格式的。如何提取和创建 cpio 格式的 initrd 可以参考下面这篇文章Debian Lenny 5.0.1 PXE initrd update,主要的命令如下:

# 提取
zcat ../initrd.gz | cpio -iv
# 创建
find . -print0 | cpio -0 -H newc -ov | gzip -c > ../initrd.gz

如果有 Linux 内核源码的话还可以参考 Documentation/initrd.txt,里面有启动过程的介绍和创建和提取 initrd 的说明,内容比 man initrd 更详细,不过也有一点过时。

Tags: ,

推荐个 C 库 sglib

April 8th, 2010 2 comments

SGLIB – A Simple Generic Library for C 完全用宏实现,只有一个头文件。提供了如下功能:

  • sorting arrays
  • manipulating linked lists
  • manipulating sorted linked lists
  • manipulating double linked lists
  • manipulating red-black trees
  • manipulating hashed containers

网页提供的下载链接地址不对,提供个sourceforge的下载地址。下载的 tarball 里有 sample 和 doc,看下就知道怎么用了。

一个我比较喜欢的特点是数据结构完全由用户自己定义,sglib 帮你生成操作数据结构的宏,函数声明以及定义。这样做的好处是不需要因为使用库而对数据结构做修改。相比 queue.h,我觉得 sglib 的更容易使用和理解,而且有更多功能。

Tags: ,

Get the current module in Python

December 31st, 2009 4 comments

It’s sometimes useful to do introspection on the module itself you are writing. But python doesn’t provide any direct way to support this. In fact a PEP about this feature has been rejected.

A little google find a solution to this problem. Here’s the code

import sys
# get the current module's name
modname = globals()['__name__']
# get the module
module = sys.modules[modname]
# or more simply as suggested by E.T
module = sys.modules[__name__]
Tags:

Reviewboard, PIL and virtualenv

December 2nd, 2009 No comments

I created a separate no site-packages virtualenv directory, and use easy_install to install Reviewboard.

However, easy_install installs PIL version 1.1.7 which does not work with the latest stable Reviewboard version 1.0.5.1.

Using easy_install PIL==1.1.6 doesn’t work because of build error. The workaround is to manually download PIL and install it.

To make reviewboard work under virtualenv, additional steps are needed, which in fact are steps for Django application to work under virtualenv.

  • If you use mod_python and apache, this article maybe useful. This works for Reviewboard.
  • For mod_wsgi, look here.

更新 zsh 的 command hash table

November 14th, 2009 4 comments

zsh 下新装了一个软件,tab 补全时新装软件的命令不会出现。以前的解决办法是执行 export PATH=$PATH 让 zsh 去更新缓存。

今天在 Pylons 的 activate 脚本里看到了一条 builtin 命令 hash (man zshbuiltins),这条命令可以直接修改 command hash table。$PATH 路径下的内容发生变化时可以用 hash -r 来更新。

Tags: ,

screen & LD_LIBRARY_PATH

November 13th, 2009 No comments

这篇 post 居然是在今年 1 月份的时候放到 draft 里,到现在才 publish……

因为用 intel 的编译器,所以设置了 LD_LIBRARY_PATH 这个环境变量,但是每次启动 screen 后这个环境本来都会被 unset。google 到的结果

screen 可执行文件是 setuid 的(为了 share session,debian 的 screen 安装时默认没有 setuid),glibc 对这样的可执行文件会把那些“危险”的环境变量去掉,所以出现了上面的情况

解决办法两个

1. 把 setuid 位去掉,当然这样 screen 的 share session 就不能工作了,还好一般用不到
2. 把 LD_LIBRARY_PATH 的设置放到 .zshrc/.bashrc 之类的文件里去,这样每次启动 shell 的时候自然会把这个环境变量读入的

if [ -z $LD_LIBRARY_PATH ]; then
    export $LD_LIBRARY_PATH=XXX
else
    export $LD_LIBRARY_PATH=$LD_LIBRARY_PATH:XXX
fi

LD_LIBRARY_PATH 这个环境变量设置起来还真的挺麻烦的,系统的库目录和自己的库目录下有同名不同版本的库的时候,不是自己的程序有问题就是系统的程序有问题。

Tags: , , ,

zsh + screen

November 12th, 2009 No comments

screen 提供多个 shell 来回切换是很方便,不过有时会忘记应该切换到哪个 window。如果可以根据执行的命令和当前目录来动态设置 window title 的话来回切换时就会可以方便的找到目标 window。其实 zsh-lovers 里就有说明。

screen 可以通过 echo 特殊的字符来设置 window 的 title,而 zsh 有两个特殊的函数 preexec 和 precmd,前者在用户输入命令按下回车但 zsh 还未执行命令前被调用,后者在 zsh 更新 prompt 前被调用(具体说明见 man zshmisc)。把 zsh 和 screen 的功能结合起来就可以在执行命令时把 screen window 的标题设置成当前执行的命令,而在 zsh 等待用户命令时,将 title 设置成当前目录

先贴 zsh 的相关配置,PS1 的配置不喜欢可以去掉。

autoload colors
colors

case $TERM in
    screen*)
        function sctitle() { print -Pn "\ek$1\e\\"}
        function precmd() { sctitle "%20< ..<%~%<<" }
        function preexec() { sctitle "%20>..>$1%< <" }
        export PS1="%{${fg[cyan]}%}[%D{%H:%M} %20<..<%~%<<]%{$reset_color%} "
    ;;
    *)
        export PS1="%{${fg[cyan]}%}[%D{%H:%M} %n@%m:%20<..<%~%<<]%{$reset_color%} "
    ;;
esac

有时命令或者当前目录很长,screen 的 status bar 宽度会不够,zsh 有内置的截短字符串的功能,用 %20< ..<%~%<< 限制目录最长为 20 个字符,把左边的多余字符去掉,截短后用两个点表示,%~ 表示当前目录,如果包含 HOME 目录则用波浪号表示,%<< 标志截短操作的结束。%20>..>$1%< < 类似,preexec 的第一个参数是完整的命令行输入,同样截短成 20 个字符,不过是去掉右边的多余字符。sctitle 就是打印特殊字符来设置 screen window title 的函数。

接下来是 .screenrc。

startup_message off
# use visual bell
vbell off
# replace Ctrl-A by `
escape ``
# set a big scrolling buffer
defscrollback 5000
# Set the caption on the bottom line
caption always '%{= kg}[%{G}%H%{g}][%= %{= kw}%?%-Lw%?%{+b r}(%{y}%n %t%?(%u)%?%{r})%{= w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
# %{= kG} first set default color (=), back ground black (k), foreground green (G)
# [%{G}%H%{g}] color bright green, host name (%H), color green
# [%= ...] padding (%=), window left to the current focus window if exists,
#      (current focus window with color yellow), window to the right of the
#      focus window
# [%{B} %m/%d %{W}%c %{g}] color bright blue, month/date (%m%d), color bright white,
#      current time(%c), color green

# open several terminals at startup
screen 5
screen 4
screen 3
screen 2
screen 1

因为我用 vim,而且我觉得切换 window 时要按数字键,所以我把 escape 设置成 back tick。这个配置最关键的就是 caption 了,忘记从哪里 copy 过来的了(用 hardstatus 的话 screen 的消息也是在 hardstatus 上显示,所以我喜欢用 caption)。我直接在配置文件里加了点注释,语法很恶心,我都看晕了。关于 caption/hardstatus 里的转义字符说明见 man screen 的 string escape 一节。

试试看吧,这个配置还是很炫而且也蛮实用的。

Tags: ,

我也来推荐 bpython

November 12th, 2009 3 comments

在光华上看到 Zellux 推荐的,bpython

bpython 对输入的代码有高亮显示,输入代码同时自动补全,不需要按 tab,调用函数时打完左括号文档就自动出现。

现在只是刚刚试了一下,印象不错。

有些 ipython 支持的功能 bpython 里没有,现在发现的是不支持直接执行 shell 命令。(文件名补全的话当前目录的要用 ./ 以后才会出来。)

Tags: