Category Archives: Programming

Ampere Altra Mt. Jade OpenBMC and EDKII build guide on ARM64 platform

Ampere announce Altra CPU, it’s a 80 cores ARM64v8 CPU for cloud native workloads. Altra Max CPU is 128 cores. Follow the CPU, Ampere also has a CRB (customer reference board) named Mt. Jade, and Ampere also open source OpenBMC and EDKII source code for Mt. Jade platform.

This article is personal note, all information can be found from internet. And open source project keeps going, it might be some minor differences when you find this article.

Read more »

Python 取得 PM2.5 和天氣資訊

最近終於將很久之前就說要架的室內 PM 2.5 偵測弄起來,上一版是用 Cacti 做的,但是有點過時了,這一版是用 Grafana + Prometheus 做的,看起來就漂亮多了

不過架上去之後的問題是,想比較數值,但是又不想再組一套系統出來,畢竟感測器也是成本,不如就用現成的氣象和環保局的數據吧,反正都只是參考用的,看個大概就好了

Read more »

PyCharm 內執行 QT Designer 和 ui 轉 py

看了幾篇文章都有些疏漏,並沒有辦法真正的做到直接在程式內直接呼叫 External tool 做到這兩件事

都會有一些錯誤訊息

Read more »

RSS Toeplitz Hash Calculation C Code

Toeplitz RSS(Receive Side Scaling) sample code 如下, 從 ODP Code 借來的

因為是測試用 code, 所以也不要太在乎語法什麼的
輸出可以正確的跑出 microsoft 網站的 sample

$ ./a.out
sip: 187.149.9.66   dip:80.100.142.161 sport:1766   dport:2794   hash: 51ccc178

目前的 code 會計算 4 個 IP
像是這樣

$ ./a.out
sip: 192.168.1.100  dip:10.0.0.100     sport:1000   dport:1000   hash: 8c2cb4f
sip: 193.168.1.100  dip:10.0.0.100     sport:1000   dport:1000   hash: ef1317e8
sip: 194.168.1.100  dip:10.0.0.100     sport:1000   dport:1000   hash: 5f061160
sip: 195.168.1.100  dip:10.0.0.100     sport:1000   dport:1000   hash: 2324d4ee

連檔名都叫 a.out 我真懶

#include <stdint.h>
#include <stdio.h>
#include <endian.h>
#include <string.h>
#include <arpa/inet.h>

/** rss data type */
typedef union {
uint8_t u8[40];
uint32_t u32[10];
} rss_key;

/** IPv4 tuple
*
*/
typedef struct thash_ipv4_tuple {
uint32_t src_addr;
uint32_t dst_addr;
union {
struct {
uint16_t sport;
uint16_t dport;
};
uint32_t sctp_tag;
};
} thash_ipv4_tuple_t;

/** Thash tuple union */
typedef union {
thash_ipv4_tuple_t v4;
//thash_ipv6_tuple_t v6;
} thash_tuple_t;
static const rss_key default_rss = {
.u8 = {
0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa,
}
};

static inline
uint32_t thash_softrss(uint32_t *tuple, uint8_t len,
const rss_key key)
{
uint32_t i, j, ret = 0;

for (j = 0; j < len; j++) {
for (i = 0; i < 32; i++) {
if (tuple[j] & (1 << (31 – i))) {
ret ^= htobe32(((const uint32_t *)
key.u32)[j]) << i | (uint32_t)((uint64_t) (htobe32(((const uint32_t *)key.u32) [j + 1])) >> (32 – i));
}
}
}

return ret;
}
int main(int argc,char *argv[]){
thash_tuple_t tuple;
uint32_t hash;
uint32_t tuple_len;
struct in_addr ip_addr_s,ip_addr_d;
char str_s[15], str_d[15];

#if 0
tuple.v4.src_addr = (uint32_t) inet_addr(“66.9.149.187”);
tuple.v4.dst_addr = (uint32_t) inet_addr(“161.142.100.80”);
ip_addr_s.s_addr = tuple.v4.src_addr;
ip_addr_d.s_addr = tuple.v4.dst_addr;
tuple_len += 2;
tuple.v4.sport = htobe16(2794);
tuple.v4.dport = htobe16(1766);
tuple_len += 1;
#endif

for(int i=0;i<4;i++){
tuple_len = 0;
hash = 0;

tuple.v4.src_addr = (uint32_t) inet_addr(“192.168.1.100”);
tuple.v4.src_addr = be32toh(tuple.v4.src_addr);
tuple.v4.src_addr=tuple.v4.src_addr+i*4;
tuple.v4.src_addr = htobe32(tuple.v4.src_addr);
tuple.v4.dst_addr = (uint32_t) inet_addr(“10.0.0.100”);
ip_addr_s.s_addr = tuple.v4.src_addr;
ip_addr_d.s_addr = tuple.v4.dst_addr;
tuple_len += 2;
tuple.v4.sport = htobe16(1000);
tuple.v4.dport = htobe16(1000);
tuple_len += 1;

if (tuple_len){
tuple.v4.src_addr = be32toh(tuple.v4.src_addr);
tuple.v4.dst_addr = be32toh(tuple.v4.dst_addr);
tuple.v4.sctp_tag = be32toh(tuple.v4.sctp_tag);
hash = thash_softrss((uint32_t *)&tuple,
tuple_len, default_rss);
}

ip_addr_s.s_addr = htobe32(tuple.v4.src_addr);
ip_addr_d.s_addr = htobe32(tuple.v4.dst_addr);
strcpy(str_s,inet_ntoa(ip_addr_s));
strcpy(str_d,inet_ntoa(ip_addr_d));
printf(“sip: %-14s dip:%-14s sport:%-6d dport:%-6d hash: %x \n”,
str_s,str_d,
tuple.v4.sport,
tuple.v4.dport, hash);

}

return hash;
}

附帶一提, 如果在 Linux 下要修改 hash key . 可以用 ethtool 這個指令, ex:

$ ethtool -X enp5s0f4 hkey 6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a:6d:5a

ref.
Verifying the RSS Hash Calculation : 可以比對計算出是不是正確
Symmetric RSS : 有趣的文章, 提到原來的功能沒有辦法有效的 hash , 將所有的 key 都改 0x6d5a 就可以
Scalable TCP Session Monitoring with Symmetric Receive-side Scaling
Scaling in the Linux Networking Stack
odp_classification.c

Ubuntu 16.04 error: undefined reference to `create_module’

Ubuntu 16.04 error: undefined reference to `create_module’

Building module-init-tools-3.2 in Ubuntu16.04 failed:
lsmod.o: In function `try_old_version':
./module-init-tools-3.2/backwards_compat.c:56: undefined reference to `create_module'

這一篇Ubuntu 16.04 error: undefined reference to `create_module’對我沒有用, 但是解法是對的, 這時就要用粗暴的方式, 直接改 backwards_compat.c
加上

#define CONFIG_NO_BACKWARDS_COMPAT

暫時解決問題

SIGALARM / timer_create 造成 CPU sys 100% 的問題

最近遇到一個怪問題, 某一隻程式跑起來的時候, 有一定的機率 sys 佔有率是 100%

Cpu0  :  0.0%us,100.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Read more »

git subversion

git 真是很難操控的東西. 好像寫了很多次, 但是都忘記怎麼用..
Read more »

HTC One XL Jelly Bean ROM

今天將 HTC One XL AT&T 版升 Jelly Bean 了.
感覺比 CleanROM 5 (Ice cream) 有著長足的進步.
之前的頓挫感不見了, 感覺手機升級了.
Read more »

[GIT] 將現有的目錄改成 bare 並且修改 remote server

git 如果從另一個目錄 clone 出來, 兩邊都有 source code, 是不能直接 master push 到 master 的.
會出現錯誤訊息
[TEXT]
git push error ‘[remote rejected] master -> master (branch is currently checked out)’
[/TEXT]

這時可以產生另一個 bare 目錄, 然後到 git 目錄內下指令, 將該目錄變成 bare
[BASH]
# cp -a (path_to_source_dir) (path_to_bare_dir)
# cd (path_to_bare_dir)
# git config –bool core.bare true
# rm (all source code)
# mv .git/* .
# rmdir .git
[/BASH]

這樣就可以了.

原來的目錄可以修改 remote url 的方式指到新的目錄
[BASH]
# cd (path_to_source_dir)
# git remote set-url origin //(path_to_bare_dir)
[/BASH]

這時有 source code 的目錄還是用 git push/pull 更新 source code.
如果是 bare 的話就是 git push, git fetch/merge 更新 source code.

Ref web.
http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked
http://stackoverflow.com/questions/2432764/how-to-change-a-remote-repository-uri-using-git

[敗家] HTC One XL AT&T 版.

我沒事找自己麻煩做什麼 -___-

剛剛入手一隻 HTC One X AT&T 版, 一般稱這個版本為 HTC One XL.

不過因為有鎖 AT&T 的 sim 卡才能使用, 所以國外使用比較不便.

P.S 這隻手機也有人叫, HTC ONE X ATT Version .

以下的動作都有風險讓你的 HTC One XL 變磚, 本人不負任何責任
先不要升級, 預設出廠的 Firmware 版本是比較容易升級的.

如果要買回台灣用, 至少要做 Sim Unlock , 要花點錢去買 Unlock code.
我是在http://www.htcsimunlock.com/買的, US$12.95.-
Unlock Code 是可以用的.

內建的輸入法就有中文, 顯示中文也沒有問題

接下來可以 root, 請參考這一篇.
[ROOT] One Click HTC One X (AT&T/Rogers/Others) (Win/Mac/Linux)

root 完要 unlock bootloader
How To: Unlock AT&T One X Bootloader

然後就可以升級 RUU v1.85.502 . 感覺升完最新的 RUU 之後, 3G Data 網路比較正常.
這部的的文章可以參考這一篇.
[TUTORIAL] Prepare Your AT&T HTC One X for Custom ROMs

簡單的說明步驟
1) Relock (重新 lock) 之後才能進行 RUU 升級
2) 執行 RUU 進行系統升級
3) 用之前的 unlock token file 再 unlock , 在 bootloader 會看到 UNLOCKER 字樣, 這個步驟有可能要跑非常非常多次, 有人一次就成功, 有人跑了二小時, 我大概 flash 了有 20 次吧.
4) 燒新的 Recovery , 有二個, CWM , ClockWorkMod Touch 及 TWRP (TeamWinRecoveryProject). 我 TWRP 開不起來, 最後是用 CWM 才成功.
5) 用 Recovery 燒之前 SuperRoot 的 root.zip, 可以躲過其他權限讓 su 取得 superuser 的 right. 這樣就 OK 了.

這樣就有了一個最新版 Firmware 的 AT&T HTC One XL 手機.

最後就是移除討人厭的 Bloatware 了
[HOW TO] How to do virtually everything to your ONE X …
這篇文章的內有一個 Link, 點下去之後會下載一個 PDF File, 依照第八章的方式移除 Apk 和 resource file
這樣就不會有討人厭的 AT&T 相關 resource 了

Tethering 也己得要開, AT&T 這個功能要收錢的
http://forum.xda-developers.com/showthread.php?t=1677261

Wifi Tether
http://forum.xda-developers.com/showthread.php?t=1646795&page=2

最後一步, 要刷 ASIA 版的 Radio 看起來 3G 才會比較正常一點, 如果有人還沒有刷的可以先測試一下自己的 3G 是不是正常
我刷之前 3G DATA 都無法順利使用
http://forum.xda-developers.com/showthread.php?t=1694012

這是 SpeedTest 的結果, 上傳慢很多, 不過可以接受了, 而且 Server 是放在遠傳電信, 可能會有誤差

至少 Google Play 可以下載了.

希望這篇有幫到有想要買 HTC One X AT&T 版人的忙.. :p

— 20120626 Update —
如果系統整個爛了, 開不了機, 那就要 relock 之後抓 RUU 下來 Update Firmware.
RUU 內有原來的 Radio, kernel 和 system file.
像是 “Can’t Find SDCard” 這樣的怪問題也可以用這個方法解決掉.

只要 fastboot 進得去, 就可以用這一招恢復變磚的系統.
然後我現在沒有用 Stock ROM, 改用 Clean Rom SE, 試試看會不會比較好.

— 20140120 Update —
升級到 3.18 RUU, 升完之後才可以刷 TWRP 2.6.3.0-SELinux 版.
才可以刷 4.2.2
升 RUU 之前要先 S-OFF
http://forum.xda-developers.com/showthread.php?t=2155071
RUU 升級方法
http://forum.xda-developers.com/showthread.php?t=2593037
TWRP 2.6.3.9-SELinux 版
http://forum.xda-developers.com/showthread.php?t=2558503
CM 11.0
http://forum.xda-developers.com/showthread.php?p=44053927

ref.
[INDEX] AT&T/ROGERS One X Resources Compilation Roll-Up (6/5/12)