


Modify go to use Gem5 m5ops: go tool dist displays import message and then exits
php editor Apple is here to introduce to you a method of modifying the Go language to use Gem5 m5ops. Gem5 is a widely used emulator, and m5ops is a set of operating system interfaces in Gem5. By modifying the Go language, we can use Gem5's m5ops interface for performance analysis and debugging. The specific steps are to add support for m5ops to the Go tool chain, and then use the functions provided by m5ops for performance monitoring and debugging operations. In this way, we can better understand how the Go language is running in the simulation environment and perform corresponding optimization and debugging work.
Question content
I am still new to golang.
I'm trying to insert some c function calls (specifically m5ops) into golang's runtime (specifically src/proc.go).
I tried using cgo, which resulted in adding this import to the beginning of proc.go
:
// #cgo cflags: -i$(gem5_path)/include -static // #cgo ldflags: -l$(gem5_path)/util/m5/build/x86/out -lm5 // #include <gem5/m5ops.h> import "c"
But when I try to rebuild using ./all.bash
the script outputs and then exits:
./all.bash building go cmd/dist using /usr/local/go. (go1.20.5 linux/amd64) building go toolchain1 using /usr/local/go. building go bootstrap cmd/go (go_bootstrap) using go toolchain1. go tool dist: /home/landerx/goroot/src/runtime/proc.go imports c
A more detailed version of the above output:
./all.bash -v Building Go cmd/dist using /usr/local/go. (go1.20.5 linux/amd64) cmd/dist Building Go toolchain1 using /usr/local/go. internal/goarch internal/coverage/rtcov internal/goos internal/race internal/unsafeheader internal/goexperiment unicode runtime/internal/syscall sync/atomic runtime/internal/atomic internal/cpu unicode/utf8 internal/itoa math/bits internal/abi runtime/internal/math runtime/internal/sys bootstrap/internal/goarch bootstrap/internal/goexperiment bootstrap/math/bits encoding bootstrap/internal/unsafeheader bootstrap/internal/platform bootstrap/internal/coverage internal/bytealg bootstrap/internal/abi math unicode/utf16 bootstrap/internal/goversion internal/goversion bootstrap/internal/race bootstrap/cmd/compile/internal/test runtime internal/reflectlite runtime/metrics sync internal/testlog internal/godebug bootstrap/internal/bisect math/rand errors sort bootstrap/sort io internal/oserror internal/safefilepath path strconv bootstrap/strconv syscall bootstrap/container/heap hash text/tabwriter bytes strings hash/adler32 hash/fnv hash/crc32 crypto reflect bootstrap/internal/types/errors go/build/constraint bootstrap/go/build/constraint bufio regexp/syntax html internal/syscall/execenv internal/syscall/unix time regexp context io/fs internal/poll internal/fmtsort bootstrap/internal/saferio encoding/binary os bootstrap/cmd/internal/notsha256 encoding/base64 bootstrap/cmd/internal/sys crypto/md5 bootstrap/internal/lazyregexp internal/lazyregexp path/filepath fmt os/exec log bootstrap/internal/buildcfg flag bootstrap/cmd/internal/src text/scanner bootstrap/cmd/internal/edit bootstrap/cmd/internal/pkgpath go/token bootstrap/compress/flate bootstrap/internal/zstd go/doc/comment bootstrap/debug/dwarf encoding/json runtime/debug bootstrap/math/big bootstrap/cmd/internal/bio net/url go/scanner bootstrap/cmd/internal/objabi bootstrap/cmd/compile/internal/abt bootstrap/cmd/internal/goobj bootstrap/cmd/internal/gcprog bootstrap/cmd/internal/quoted bootstrap/compress/zlib encoding/hex compress/flate go/ast internal/buildcfg internal/goroot bootstrap/cmd/internal/dwarf runtime/trace bootstrap/cmd/internal/archive bootstrap/cmd/internal/obj bootstrap/debug/macho bootstrap/debug/elf bootstrap/debug/pe bootstrap/internal/xcoff bootstrap/cmd/link/internal/dwtest compress/gzip bootstrap/internal/profile runtime/pprof go/doc go/printer go/internal/typeparams go/parser bootstrap/cmd/internal/codesign bootstrap/go/constant bootstrap/internal/pkgbits bootstrap/cmd/compile/internal/syntax bootstrap/cmd/link/internal/benchmark bootstrap/cmd/compile/internal/pgo/internal/graph go/build go/format bootstrap/cmd/cgo bootstrap/cmd/internal/obj/loong64 bootstrap/cmd/internal/obj/mips bootstrap/cmd/internal/obj/wasm bootstrap/cmd/internal/obj/arm bootstrap/cmd/internal/obj/arm64 bootstrap/cmd/internal/obj/s390x bootstrap/cmd/internal/obj/riscv bootstrap/cmd/internal/obj/ppc64 bootstrap/cmd/internal/obj/x86 bootstrap/cmd/asm/internal/flags bootstrap/cmd/compile/internal/base bootstrap/cmd/compile/internal/logopt bootstrap/cmd/asm/internal/lex bootstrap/cmd/link/internal/sym bootstrap/cmd/link/internal/loader bootstrap/cmd/compile/internal/bitvec bootstrap/cmd/compile/internal/types bootstrap/cmd/compile/internal/types2 bootstrap/cmd/link/internal/loadelf bootstrap/cmd/link/internal/loadmacho bootstrap/cmd/link/internal/loadpe bootstrap/cmd/link/internal/loadxcoff bootstrap/cmd/compile/internal/typebits bootstrap/cmd/compile/internal/ir bootstrap/cmd/asm/internal/arch bootstrap/cmd/link/internal/ld bootstrap/cmd/asm/internal/asm bootstrap/cmd/asm bootstrap/cmd/compile/internal/abi bootstrap/cmd/compile/internal/deadcode bootstrap/cmd/compile/internal/typecheck bootstrap/cmd/compile/internal/objw bootstrap/cmd/compile/internal/staticdata bootstrap/cmd/compile/internal/compare bootstrap/cmd/compile/internal/pgo bootstrap/cmd/compile/internal/coverage bootstrap/cmd/compile/internal/loopvar bootstrap/cmd/compile/internal/importer bootstrap/cmd/compile/internal/escape bootstrap/cmd/compile/internal/inline bootstrap/cmd/compile/internal/reflectdata bootstrap/cmd/compile/internal/devirtualize bootstrap/cmd/compile/internal/staticinit bootstrap/cmd/compile/internal/ssa bootstrap/cmd/link/internal/amd64 bootstrap/cmd/link/internal/loong64 bootstrap/cmd/link/internal/arm bootstrap/cmd/link/internal/mips bootstrap/cmd/link/internal/mips64 bootstrap/cmd/link/internal/arm64 bootstrap/cmd/link/internal/ppc64 bootstrap/cmd/link/internal/riscv64 bootstrap/cmd/link/internal/s390x bootstrap/cmd/link/internal/wasm bootstrap/cmd/link/internal/x86 bootstrap/cmd/link bootstrap/cmd/compile/internal/liveness bootstrap/cmd/compile/internal/ssagen bootstrap/cmd/compile/internal/amd64 bootstrap/cmd/compile/internal/arm bootstrap/cmd/compile/internal/arm64 bootstrap/cmd/compile/internal/dwarfgen bootstrap/cmd/compile/internal/loong64 bootstrap/cmd/compile/internal/mips bootstrap/cmd/compile/internal/mips64 bootstrap/cmd/compile/internal/wasm bootstrap/cmd/compile/internal/s390x bootstrap/cmd/compile/internal/riscv64 bootstrap/cmd/compile/internal/ppc64 bootstrap/cmd/compile/internal/walk bootstrap/cmd/compile/internal/x86 bootstrap/cmd/compile/internal/noder bootstrap/cmd/compile/internal/pkginit bootstrap/cmd/compile/internal/gc bootstrap/cmd/compile Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1. runtime go tool dist: /home/landerx/goroot/src/runtime/proc.go imports C
Tried the cgo_enabled=1
flag, doesn't seem to make any difference.
Tried just running make.bash
, it didn't seem to make any difference.
I was wondering if it was a dependency issue, but I didn't see any messages related to the fake package cgo
, nor did I see any errors with my vscode.
Solution
Okay... Finally, let me answer this question.
Why doesn’t it work
After quite some in-depth investigation, I found that it seems that Go (tools dist) does not allow source files in most go internals (Link)
Solution
There are still some workarounds to achieve this effect, namely using m5ops in go.
1. Pass function pointer through global variable
You can define global function pointers in proc.go
and import cgo in your go application and assign these global function pointers to your functions that perform m5ops. Does not support calling C function pointers, so it needs to be wrapped with golang functions.
2. Go to assembly
Go uses a lot of Go Asm in its internal source files to handle stack switching etc.
On the other hand, m5ops will eventually be inlined as a single directive.
So following Go Asm's syntax and function bindings, which happens in asm_amd64.s and stubs.go a>, one can write an asm function that contains the m5ops directive, and then # Call it anywhere in the ##runtime. go should be good.
- It seems that in
- runtime.go
when it switches to the system stack it can no longer execute functions outside of the file (or package?), so if you try to insert these function calls, method 1 Writing code that will run on the system stack does not work. So I finally discovered the second method.
The above is the detailed content of Modify go to use Gem5 m5ops: go tool dist displays import message and then exits. For more information, please follow other related articles on the PHP Chinese website!

The main differences between Golang and Python are concurrency models, type systems, performance and execution speed. 1. Golang uses the CSP model, which is suitable for high concurrent tasks; Python relies on multi-threading and GIL, which is suitable for I/O-intensive tasks. 2. Golang is a static type, and Python is a dynamic type. 3. Golang compiled language execution speed is fast, and Python interpreted language development is fast.

Golang is usually slower than C, but Golang has more advantages in concurrent programming and development efficiency: 1) Golang's garbage collection and concurrency model makes it perform well in high concurrency scenarios; 2) C obtains higher performance through manual memory management and hardware optimization, but has higher development complexity.

Golang is widely used in cloud computing and DevOps, and its advantages lie in simplicity, efficiency and concurrent programming capabilities. 1) In cloud computing, Golang efficiently handles concurrent requests through goroutine and channel mechanisms. 2) In DevOps, Golang's fast compilation and cross-platform features make it the first choice for automation tools.

Golang and C each have their own advantages in performance efficiency. 1) Golang improves efficiency through goroutine and garbage collection, but may introduce pause time. 2) C realizes high performance through manual memory management and optimization, but developers need to deal with memory leaks and other issues. When choosing, you need to consider project requirements and team technology stack.

Golang is more suitable for high concurrency tasks, while Python has more advantages in flexibility. 1.Golang efficiently handles concurrency through goroutine and channel. 2. Python relies on threading and asyncio, which is affected by GIL, but provides multiple concurrency methods. The choice should be based on specific needs.

The performance differences between Golang and C are mainly reflected in memory management, compilation optimization and runtime efficiency. 1) Golang's garbage collection mechanism is convenient but may affect performance, 2) C's manual memory management and compiler optimization are more efficient in recursive computing.

ChooseGolangforhighperformanceandconcurrency,idealforbackendservicesandnetworkprogramming;selectPythonforrapiddevelopment,datascience,andmachinelearningduetoitsversatilityandextensivelibraries.

Golang and Python each have their own advantages: Golang is suitable for high performance and concurrent programming, while Python is suitable for data science and web development. Golang is known for its concurrency model and efficient performance, while Python is known for its concise syntax and rich library ecosystem.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)