From: George Dunlap <george.dunlap@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Ronald Rojas <ronladred@gmail.com>, Wei Liu <wei.liu2@citrix.com>,
Ian Jackson <ian.jackson@citrix.com>
Subject: [PATCH v5 03/10] golang/xenlight: Add host-related functionality
Date: Wed, 5 Apr 2017 17:05:47 +0100 [thread overview]
Message-ID: <1491408354-9643-4-git-send-email-george.dunlap@citrix.com> (raw)
In-Reply-To: <1491408354-9643-1-git-send-email-george.dunlap@citrix.com>
From: Ronald Rojas <ronladred@gmail.com>
Add calls for the following host-related functionality:
- libxl_get_max_cpus
- libxl_get_online_cpus
- libxl_get_max_nodes
- libxl_get_free_memory
- libxl_get_physinfo
- libxl_get_version_info
Include Golang versions of the following structs:
- libxl_physinfo as Physinfo
- libxl_version_info as VersionInfo
- libxl_hwcap as Hwcap
Signed-off-by: Ronald Rojas <ronladred@gmail.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
---
CC: Ian Jackson <ian.jackson@citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
Changes since v4:
- Moved fix from the next patch
---
tools/golang/xenlight/xenlight.go | 200 ++++++++++++++++++++++++++++++++++++++
1 file changed, 200 insertions(+)
diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index de24ffd..5b500f3 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -118,6 +118,103 @@ type Context struct {
logger *C.xentoollog_logger_stdiostream
}
+type Hwcap []C.uint32_t
+
+func (chwcap C.libxl_hwcap) CToGo() (ghwcap Hwcap) {
+ // Alloc a Go slice for the bytes
+ size := 8
+ ghwcap = make([]C.uint32_t, size)
+
+ // Make a slice pointing to the C array
+ mapslice := (*[1 << 30]C.uint32_t)(unsafe.Pointer(&chwcap[0]))[:size:size]
+
+ // And copy the C array into the Go array
+ copy(ghwcap, mapslice)
+
+ return
+}
+
+/*
+ * Types: IDL
+ *
+ * FIXME: Generate these automatically from the IDL
+ */
+
+type Physinfo struct {
+ ThreadsPerCore uint32
+ CoresPerSocket uint32
+ MaxCpuId uint32
+ NrCpus uint32
+ CpuKhz uint32
+ TotalPages uint64
+ FreePages uint64
+ ScrubPages uint64
+ OutstandingPages uint64
+ SharingFreedPages uint64
+ SharingUsedFrames uint64
+ NrNodes uint32
+ HwCap Hwcap
+ CapHvm bool
+ CapHvmDirectio bool
+}
+
+func (cphys *C.libxl_physinfo) toGo() (physinfo *Physinfo) {
+
+ physinfo = &Physinfo{}
+ physinfo.ThreadsPerCore = uint32(cphys.threads_per_core)
+ physinfo.CoresPerSocket = uint32(cphys.cores_per_socket)
+ physinfo.MaxCpuId = uint32(cphys.max_cpu_id)
+ physinfo.NrCpus = uint32(cphys.nr_cpus)
+ physinfo.CpuKhz = uint32(cphys.cpu_khz)
+ physinfo.TotalPages = uint64(cphys.total_pages)
+ physinfo.FreePages = uint64(cphys.free_pages)
+ physinfo.ScrubPages = uint64(cphys.scrub_pages)
+ physinfo.ScrubPages = uint64(cphys.scrub_pages)
+ physinfo.SharingFreedPages = uint64(cphys.sharing_freed_pages)
+ physinfo.SharingUsedFrames = uint64(cphys.sharing_used_frames)
+ physinfo.NrNodes = uint32(cphys.nr_nodes)
+ physinfo.HwCap = cphys.hw_cap.CToGo()
+ physinfo.CapHvm = bool(cphys.cap_hvm)
+ physinfo.CapHvmDirectio = bool(cphys.cap_hvm_directio)
+
+ return
+}
+
+type VersionInfo struct {
+ XenVersionMajor int
+ XenVersionMinor int
+ XenVersionExtra string
+ Compiler string
+ CompileBy string
+ CompileDomain string
+ CompileDate string
+ Capabilities string
+ Changeset string
+ VirtStart uint64
+ Pagesize int
+ Commandline string
+ BuildId string
+}
+
+func (cinfo *C.libxl_version_info) toGo() (info *VersionInfo) {
+ info = &VersionInfo{}
+ info.XenVersionMajor = int(cinfo.xen_version_major)
+ info.XenVersionMinor = int(cinfo.xen_version_minor)
+ info.XenVersionExtra = C.GoString(cinfo.xen_version_extra)
+ info.Compiler = C.GoString(cinfo.compiler)
+ info.CompileBy = C.GoString(cinfo.compile_by)
+ info.CompileDomain = C.GoString(cinfo.compile_domain)
+ info.CompileDate = C.GoString(cinfo.compile_date)
+ info.Capabilities = C.GoString(cinfo.capabilities)
+ info.Changeset = C.GoString(cinfo.changeset)
+ info.VirtStart = uint64(cinfo.virt_start)
+ info.Pagesize = int(cinfo.pagesize)
+ info.Commandline = C.GoString(cinfo.commandline)
+ info.BuildId = C.GoString(cinfo.build_id)
+
+ return
+}
+
/*
* Context
*/
@@ -164,3 +261,106 @@ func (Ctx *Context) CheckOpen() (err error) {
}
return
}
+
+//int libxl_get_max_cpus(libxl_ctx *ctx);
+func (Ctx *Context) GetMaxCpus() (maxCpus int, err error) {
+ err = Ctx.CheckOpen()
+ if err != nil {
+ return
+ }
+
+ ret := C.libxl_get_max_cpus(Ctx.ctx)
+ if ret < 0 {
+ err = Error(-ret)
+ return
+ }
+ maxCpus = int(ret)
+ return
+}
+
+//int libxl_get_online_cpus(libxl_ctx *ctx);
+func (Ctx *Context) GetOnlineCpus() (onCpus int, err error) {
+ err = Ctx.CheckOpen()
+ if err != nil {
+ return
+ }
+
+ ret := C.libxl_get_online_cpus(Ctx.ctx)
+ if ret < 0 {
+ err = Error(-ret)
+ return
+ }
+ onCpus = int(ret)
+ return
+}
+
+//int libxl_get_max_nodes(libxl_ctx *ctx);
+func (Ctx *Context) GetMaxNodes() (maxNodes int, err error) {
+ err = Ctx.CheckOpen()
+ if err != nil {
+ return
+ }
+ ret := C.libxl_get_max_nodes(Ctx.ctx)
+ if ret < 0 {
+ err = Error(-ret)
+ return
+ }
+ maxNodes = int(ret)
+ return
+}
+
+//int libxl_get_free_memory(libxl_ctx *ctx, uint64_t *memkb);
+func (Ctx *Context) GetFreeMemory() (memkb uint64, err error) {
+ err = Ctx.CheckOpen()
+ if err != nil {
+ return
+ }
+ var cmem C.uint64_t
+ ret := C.libxl_get_free_memory(Ctx.ctx, &cmem)
+
+ if ret < 0 {
+ err = Error(-ret)
+ return
+ }
+
+ memkb = uint64(cmem)
+ return
+
+}
+
+//int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
+func (Ctx *Context) GetPhysinfo() (physinfo *Physinfo, err error) {
+ err = Ctx.CheckOpen()
+ if err != nil {
+ return
+ }
+ var cphys C.libxl_physinfo
+ C.libxl_physinfo_init(&cphys)
+ defer C.libxl_physinfo_dispose(&cphys)
+
+ ret := C.libxl_get_physinfo(Ctx.ctx, &cphys)
+
+ if ret < 0 {
+ err = Error(ret)
+ return
+ }
+ physinfo = cphys.toGo()
+
+ return
+}
+
+//const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx);
+func (Ctx *Context) GetVersionInfo() (info *VersionInfo, err error) {
+ err = Ctx.CheckOpen()
+ if err != nil {
+ return
+ }
+
+ var cinfo *C.libxl_version_info
+
+ cinfo = C.libxl_get_version_info(Ctx.ctx)
+
+ info = cinfo.toGo()
+
+ return
+}
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-04-05 16:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-05 16:05 [PATCH v5 00/10] tools: Implement basic golang bindings for libxl George Dunlap
2017-04-05 16:05 ` [PATCH v5 01/10] golang/xenlight: Create stub package George Dunlap
2017-04-05 16:05 ` [PATCH v5 02/10] golang/xenlight: Add error constants and standard handling George Dunlap
2017-04-05 16:05 ` George Dunlap [this message]
2017-04-05 16:05 ` [PATCH v5 04/10] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause George Dunlap
2017-04-05 16:05 ` [PATCH v5 05/10] golang/xenlight: Implement libxl_bitmap and helper operations George Dunlap
2017-04-05 16:05 ` [PATCH v5 06/10] golang/xenlight: Implement libxl_scheduler enumeration George Dunlap
2017-04-05 16:05 ` [PATCH v5 07/10] golang/xenlight: Implement Domain operations George Dunlap
2017-04-05 16:05 ` [PATCH v5 08/10] golang/xenlight: Implement Vcpuinfo and ListVcpu George Dunlap
2017-04-05 16:05 ` [PATCH v5 09/10] golang/xenlight: Implement get console path operations George Dunlap
2017-04-05 16:05 ` [PATCH v5 10/10] golang/xenlight: Implement cpupool operations George Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1491408354-9643-4-git-send-email-george.dunlap@citrix.com \
--to=george.dunlap@citrix.com \
--cc=ian.jackson@citrix.com \
--cc=ronladred@gmail.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).