ccTopology

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 8 Imported by: 0

README

ccTopology

The ccTopology package provides easy access to topology information, mainly for the local node. It loads the topology once through the hwloc library but stores it in own data structures for later access. Main purpose is to provide a common interface for various ClusterCockpit components to topology information.

Note: In order to use it, the environment variable CGO_LDFLAGS="-L/path/to/lib/directory/of/hwloc needs to be set to the library directory of hwloc.

For transmission of the whole topology of a node, ccTopology's Topology type can be marshaled to JSON:

func GetTopologyJSON() (json.RawMessage, error) {
    topo, err := ccTopology.LocalTopology()
    if err != nil {
        return nil, fmt.Errorf("Failed to init topology: %v", err.Error())
    }
    x, err := json.MarshalIndent(topo, "", "  ")
    if err != nil {
        return nil, fmt.Errorf("Failed to marshal topology: %v", err.Error())
    }
    return x, nil
}

On the receiving side, it can be unmarshaled to ccTopology's Topology type:

func GetNodeJSON(topologyJson json.RawMessage) (ccTopology.Topology, error) {
	topo, err := ccTopology.RemoteTopology(topologyJson)
	if err != nil {
		return nil, err
	}
    return topo, nil
}

There are additional helpers to get specific information out of node's topology:

type Topology interface {
	GetHwthreads() []uint
	GetHwthreadStrings() []string
	GetSockets() []uint
	GetSocketStrings() []string
	GetDies() []uint
	GetDieStrings() []string
	GetCores() []uint
	GetCoreStrings() []string
	GetPciDevices() []uint
	GetPciDeviceStrings() []string
	GetHwthreadsOfSocket(socket uint) []uint
	GetHwthreadStringsOfSocket(socket uint) []string
	GetHwthreadsOfMemoryDomain(memoryDomain uint) []uint
	GetHwthreadStringsOfMemoryDomain(memoryDomain uint) []string
	GetNumaNodeOfPciDevice(address string) int
	CpuInfo() CpuInformation
	MarshalJSON() ([]byte, error)
	UnmarshalJSON(in []byte) error
}

Testing

$ make test
CGO_LDFLAGS="-L/modules/hwloc-2.4.0/lib" /modules/go-1.23.2/bin/go test
PASS
ok  	github.com/cc-lib/ccTopology	0.093s
cd test && CGO_LDFLAGS="-L/modules/hwloc-2.4.0/lib" /modules/go-1.23.2/bin/go test
PASS
ok  	github.com/cc-lib/ccTopology/test	0.014s

Documentation

Overview

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. This file is part of cc-lib. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Index

Constants

View Source
const DEBUG bool = true

Variables

This section is empty.

Functions

This section is empty.

Types

type CCTopologyFlags

type CCTopologyFlags uint
const CCTOPOLOGY_NO_OSDEVICES CCTopologyFlags = (1 << 0)

type CpuInformation

type CpuInformation struct {
	NumHWthreads   int
	SMTWidth       int
	NumSockets     int
	NumDies        int
	NumCores       int
	NumNumaDomains int
}

type HWLOC_OBJ_OSDEV_TYPE

type HWLOC_OBJ_OSDEV_TYPE int
const (
	HWLOC_OBJ_OSDEV_BLOCK       HWLOC_OBJ_OSDEV_TYPE = C.HWLOC_OBJ_OSDEV_BLOCK
	HWLOC_OBJ_OSDEV_GPU         HWLOC_OBJ_OSDEV_TYPE = C.HWLOC_OBJ_OSDEV_GPU
	HWLOC_OBJ_OSDEV_NETWORK     HWLOC_OBJ_OSDEV_TYPE = C.HWLOC_OBJ_OSDEV_NETWORK
	HWLOC_OBJ_OSDEV_OPENFABRICS HWLOC_OBJ_OSDEV_TYPE = C.HWLOC_OBJ_OSDEV_OPENFABRICS
	HWLOC_OBJ_OSDEV_DMA         HWLOC_OBJ_OSDEV_TYPE = C.HWLOC_OBJ_OSDEV_DMA
	HWLOC_OBJ_OSDEV_COPROC      HWLOC_OBJ_OSDEV_TYPE = C.HWLOC_OBJ_OSDEV_COPROC
)

func (*HWLOC_OBJ_OSDEV_TYPE) String

func (t *HWLOC_OBJ_OSDEV_TYPE) String() string

type HWLOC_OBJ_TYPE

type HWLOC_OBJ_TYPE int
const (
	HWLOC_TYPE_MACHINE    HWLOC_OBJ_TYPE = C.HWLOC_OBJ_MACHINE
	HWLOC_TYPE_PACKAGE    HWLOC_OBJ_TYPE = C.HWLOC_OBJ_PACKAGE
	HWLOC_TYPE_CORE       HWLOC_OBJ_TYPE = C.HWLOC_OBJ_CORE
	HWLOC_TYPE_PU         HWLOC_OBJ_TYPE = C.HWLOC_OBJ_PU
	HWLOC_TYPE_L1CACHE    HWLOC_OBJ_TYPE = C.HWLOC_OBJ_L1CACHE
	HWLOC_TYPE_L2CACHE    HWLOC_OBJ_TYPE = C.HWLOC_OBJ_L2CACHE
	HWLOC_TYPE_L3CACHE    HWLOC_OBJ_TYPE = C.HWLOC_OBJ_L3CACHE
	HWLOC_TYPE_L4CACHE    HWLOC_OBJ_TYPE = C.HWLOC_OBJ_L4CACHE
	HWLOC_TYPE_L5CACHE    HWLOC_OBJ_TYPE = C.HWLOC_OBJ_L5CACHE
	HWLOC_TYPE_L1ICACHE   HWLOC_OBJ_TYPE = C.HWLOC_OBJ_L1ICACHE
	HWLOC_TYPE_L2ICACHE   HWLOC_OBJ_TYPE = C.HWLOC_OBJ_L2ICACHE
	HWLOC_TYPE_L3ICACHE   HWLOC_OBJ_TYPE = C.HWLOC_OBJ_L3ICACHE
	HWLOC_TYPE_GROUP      HWLOC_OBJ_TYPE = C.HWLOC_OBJ_GROUP
	HWLOC_TYPE_NUMANODE   HWLOC_OBJ_TYPE = C.HWLOC_OBJ_NUMANODE
	HWLOC_TYPE_PCI_DEVICE HWLOC_OBJ_TYPE = C.HWLOC_OBJ_PCI_DEVICE
	HWLOC_TYPE_OS_DEVICE  HWLOC_OBJ_TYPE = C.HWLOC_OBJ_OS_DEVICE
	HWLOC_TYPE_MEMCACHE   HWLOC_OBJ_TYPE = C.HWLOC_OBJ_MEMCACHE
	HWLOC_TYPE_MISC       HWLOC_OBJ_TYPE = C.HWLOC_OBJ_MISC
	HWLOC_TYPE_DIE        HWLOC_OBJ_TYPE = C.HWLOC_OBJ_DIE
)

func (*HWLOC_OBJ_TYPE) String

func (t *HWLOC_OBJ_TYPE) String() string

type Object

type Object struct {
	Type         HWLOC_OBJ_TYPE `json:"type"`
	TypeString   string         `json:"typestring"`
	ID           uint           `json:"id"`
	IDString     string         `json:"idstring"`
	Depth        int            `json:"depth"`
	LogicalIndex uint           `json:"logical_index"`

	Infos    map[string]string `json:"infos"`
	Children []Object          `json:"children"`
	// contains filtered or unexported fields
}

func (Object) String

func (o Object) String() string

type Topology

type Topology interface {
	GetHwthreads() []uint
	GetHwthreadStrings() []string
	GetSockets() []uint
	GetSocketStrings() []string
	GetDies() []uint
	GetDieStrings() []string
	GetCores() []uint
	GetCoreStrings() []string
	GetPciDevices() []uint
	GetPciDeviceStrings() []string
	GetHwthreadsOfSocket(socket uint) []uint
	GetHwthreadStringsOfSocket(socket uint) []string
	GetHwthreadsOfMemoryDomain(memoryDomain uint) []uint
	GetHwthreadStringsOfMemoryDomain(memoryDomain uint) []string
	GetNumaNodeOfPciDevice(address string) int
	CpuInfo() CpuInformation
	MarshalJSON() ([]byte, error)
	UnmarshalJSON(in []byte) error
}

func LocalTopology

func LocalTopology() (Topology, error)

func RemoteTopology

func RemoteTopology(topologyJson json.RawMessage) (Topology, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL