[Tutorial] running golang using latest release gcc 5.2 on OpenWRT (WiTi Board/MIPS CPU)

442 views
Skip to first unread message

Michal Wisler

unread,
Sep 1, 2015, 3:31:15 AM9/1/15
to golang-nuts
Hi, guys

I like golang a lot. I want to play golang an my router and develop some applications for router using golang. 

Here comes a tutorial let you running golang using the official gcc latest release - gcc 5.2.

You will learn how to build a OpenWRT OS and toolchain from scratch.

The device i am testing is WiTi board. They are crowd funding at indiegogo

If you have any problem on compilation, I'm willing to help.


The performance is not bad, my test program is:

import (                                               
        "fmt"                                          
        "runtime"                                      
        "time"                                         
)                                                      
                                                       
func GetCPUCount() {                                   
        print("GOOS:", runtime.GOOS, "\n")             
        print("GOARCH:", runtime.GOARCH, "\n")         
        print("NumCPU:", fmt.Sprintf("%d", runtime.NumCPU()), "\n")
}                                                      
                                                       
func perfTest(c chan bool, n int) {                    
        x := 0                                         
        for i := 0; i < 100000000; i++ {               
                x += i                                 
        }                                              
        println(n, " ", x)                             
        if n == 9 {                                    
                c <- true                              
        }                                              
}                                                      
                                                       
func PerfTest() {   
  GetCPUCount()                 
        println("start")                               
        t1 := time.Now()                               
        c := make(chan bool)                           
        for i := 0; i < 10; i++ {                      
                go perfTest(c, i)                      
        }                                              
        <-c                                            
        println("done, ", time.Now().Sub(t1).String()) 
}


The result is

root@Witi:/mnt/sda1# ./startMIPSTest
GOOS:linux                          
GOARCH:mipso32                      
NumCPU:4                            
start                               
0   887459712                       
1   887459712                       
5   887459712                       
2   887459712                       
4   887459712                       
3   887459712                       
8   887459712                       
9   887459712                       
done,  9.848502s                    
root@Witi:/mnt/sda1#      

cpuinfo

root@Witi:/mnt/sda1# cat /proc/cpuinfo
system type             : MT7621
machine                 : Witi
processor               : 0
cpu model               : MIPS 1004Kc V2.15
BogoMIPS                : 583.68
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc,
0x0ffb, 0x0ffb]
isa                     : mips1 mips2 mips32r1 mips32r2
ASEs implemented        : mips16 dsp mt
shadow register sets    : 1
kscratch registers      : 0
core                    : 0
VPE                     : 0
VCED exceptions         : not available
VCEI exceptions         : not available

processor               : 1
cpu model               : MIPS 1004Kc V2.15
BogoMIPS                : 583.68
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc,
0x0ffb, 0x0ffb]
isa                     : mips1 mips2 mips32r1 mips32r2
ASEs implemented        : mips16 dsp mt
shadow register sets    : 1
kscratch registers      : 0
core                    : 0
VPE                     : 1
VCED exceptions         : not available
VCEI exceptions         : not available

processor               : 2
cpu model               : MIPS 1004Kc V2.15
BogoMIPS                : 583.68
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc,
0x0ffb, 0x0ffb]
isa                     : mips1 mips2 mips32r1 mips32r2
ASEs implemented        : mips16 dsp mt
shadow register sets    : 1
kscratch registers      : 0
core                    : 1
VPE                     : 0
VCED exceptions         : not available
VCEI exceptions         : not available

processor               : 3
cpu model               : MIPS 1004Kc V2.15
BogoMIPS                : 583.68
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc,
0x0ffb, 0x0ffb]
isa                     : mips1 mips2 mips32r1 mips32r2
ASEs implemented        : mips16 dsp mt
shadow register sets    : 1
kscratch registers      : 0
core                    : 1
VPE                     : 1
VCED exceptions         : not available
VCEI exceptions         : not available



miao...@gmail.com

unread,
Dec 7, 2015, 9:43:03 AM12/7/15
to golang-nuts
Sounds good!


Could you have a test https://github.com/gin-gonic/gin on openwrt?

Fino

unread,
Dec 7, 2015, 9:10:12 PM12/7/15
to golang-nuts
interesting! 
can I ask what's the real use case for Golang in a router?  

BR-fino 

在 2015年9月1日星期二 UTC+8下午3:31:15,Michal Wisler写道:

miao...@gmail.com

unread,
Dec 8, 2015, 11:59:30 PM12/8/15
to golang-nuts
I want to have a try on high performance http server on OpenWrt with golang.

However, when I compile or run ,i found the golang depends on the eglibc, but my router uses uclibc, which do not officially support golang's runtime or lib. The patch will need a lot of work to do.

So I think Lua or C is better on OpenWrt before Google have a better support on MIPS.


在 2015年12月8日星期二 UTC+8上午10:10:12,Fino写道:

Fino Meng

unread,
Dec 9, 2015, 8:53:50 PM12/9/15
to miao...@gmail.com, golang-nuts
I am thinking port Golang env to a x86_64 base mobilephone.
not started yet.
I didn't choose ARM phone because I think Golang's software may support x86_64 best.

BR-fino

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/Jz2QK2hvCac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages