...

Source file src/github.com/Microsoft/hcsshim/internal/processorinfo/host_information.go

Documentation: github.com/Microsoft/hcsshim/internal/processorinfo

     1  //go:build windows
     2  
     3  package processorinfo
     4  
     5  import (
     6  	"context"
     7  	"encoding/json"
     8  	"errors"
     9  	"fmt"
    10  
    11  	"github.com/Microsoft/hcsshim/internal/hcs"
    12  	hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
    13  )
    14  
    15  // HostProcessorInfo queries HCS for the host's processor information, including topology
    16  // and NUMA configuration. This is also used to reliably get the hosts number of logical
    17  // processors in multi processor group settings.
    18  func HostProcessorInfo(ctx context.Context) (*hcsschema.ProcessorTopology, error) {
    19  	q := hcsschema.PropertyQuery{
    20  		PropertyTypes: []hcsschema.PropertyType{hcsschema.PTProcessorTopology},
    21  	}
    22  	serviceProps, err := hcs.GetServiceProperties(ctx, q)
    23  	if err != nil {
    24  		return nil, fmt.Errorf("failed to retrieve processor and processor topology information: %s", err)
    25  	}
    26  	if len(serviceProps.Properties) != 1 {
    27  		return nil, errors.New("wrong number of service properties present")
    28  	}
    29  	processorTopology := &hcsschema.ProcessorTopology{}
    30  	if err := json.Unmarshal(serviceProps.Properties[0], processorTopology); err != nil {
    31  		return nil, fmt.Errorf("failed to unmarshal host processor topology: %s", err)
    32  	}
    33  	return processorTopology, nil
    34  }
    35  

View as plain text