Fix backlight problem in Arch Linux

Sometimes, ACPI does not work well due to different motherboard implementations and ACPI quirks. This includes some laptops with dual graphics (e.g. Nvidia/Radeon dedicated GPU with Intel/AMD integrated GPU) – some examples of laptops with these problems are Dell Studio, Dell XPS 14/15/17 and some Lenovo series’ laptops. Kamal Mostafa, a kernel developer made patches for solving this problem – these are included after Linux 3.1 . Additionally, on Nvidia-optimus laptops, the kernel parameter nomodeset can interfere with the ability to adjust the backlight. You can try adding the following kernel parameters in your bootloader(grub, syslinux…) to adjust ACPI model:


Note: This kernel setting was added in Linux 3.13.


基于 Nginx 的网关级 HTTP 透明代理

出于某些需求在网关级架设 HTTP 透明代理,劫持用户 HTTP 请求,转发或直接进行响应。

iptables 配置
iptables 用于将经过网关的 TCP 80 端口的上行流量转发至网关上的 Nginx 服务。

sudo iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j DNAT \
--to-destination 网关IP:端口

Nginx 演示配置

worker_processes  1;
events {
    worker_connections  1024;
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8000;
        server_name  localhost;
        location /test {
            proxy_buffers 256 4k;
            proxy_max_temp_file_size 0k;
        location / {
            # 包含关键词 '计算机' 重定向至 /test
            rewrite ^.*计算机.*$ /test last;
            # 通用透明代理
            proxy_pass $scheme://$host$request_uri;
            proxy_set_header Host $http_host;
            proxy_buffers 256 4k;
            proxy_max_temp_file_size 0k;
    # 匹配 * 域名
    server {
        listen       8000;
        server_name  *;
        location / {
            root   html;
            index  index.html index.htm;


Firefox 30.0a1 for 龙芯3初步评测

经过一段时间的 OdinMonkey for MIPS N32 的移植,现在 Firefox 30.0a1 终于可以在龙芯3A笔记本上跑起来了,OdinMonkey for MIPS N32 基于 OdinMonkey for MIPS O32,这过程中感谢 Branislav Rankov 的热心帮助。初步跑了一下 Octane 2.0 性能评测,得分为 1010,比 Firefox 17.0.1 增加了 405 分。下一步的工作是针对龙芯平台的特定优化。


虽然 JavaScript 的性能有所提升了,但部分页面滚动的响应仍然不是太好,经简单的分析发现瓶颈有可能在 Xorg 上。


GDB 使用自定义命令实现一次执行多个命令

在调试 JIT 的过程中,经常要输出一些信息再跳过断点,使用 GDB 的自定义命令可以使工作变得简单。

(gdb) define mynext
Type commands for definition of "mynext".
End with a line saying just "end".
>i r
>x/8x $sp
>set $pc = $pc + 4
(gdb) mynext


MIPS o32 ‘__sync_add_and_fetch_8’ for Loongson

编译 WebKitGtk 过程中,链接测试程序阶段报出 undefined symbol ‘__sync_add_and_fetch_8’,这是由于 ‘__sync_add_and_fetch_8’ 在 MIPS O32 平台上没有实现,但龙芯实际上是 64-bit 的 CPU,所以可以使用下面的实现:

#include <sys/regdef.h>
#include <sys/asm.h>
    .set push
    .set mips64r2
    .set noreorder
    dins t0, a2, 0, 32
    dins t0, a3, 32, 32
    lld t1, 0(a0)
    daddu t1, t1, t0
    scd t1, 0(a0)
    beqz t1, _retry
    daddu t1, t1, t0
    dext v0, t1, 0, 32
    jr ra
    dext v1, t1, 32, 32
    .set pop