Repository: nanovms/ops
Pull request #957 (2021-03-10 21:40:10)

gracefully degrade rdtscp to rdtsc for qemu/hvf


Patch:
diff --git a/cmd/flags_run_local_instance_image.go b/cmd/flags_run_local_instance_image.go
index 90063a6..0638cc8 100644
--- a/cmd/flags_run_local_instance_image.go
+++ b/cmd/flags_run_local_instance_image.go
@@ -89,16 +89,16 @@ func (flags *RunLocalInstanceCommandFlags) MergeToConfig(c *types.Config) (err e
 	c.Force = flags.Force
 
 	if flags.IPAddress != "" && isIPAddressValid(flags.IPAddress) {
-		c.RunConfig.IPAddr = flags.IPAddress
+		c.RunConfig.IPAddress = flags.IPAddress
 	}
 
-	ipaddr := c.RunConfig.IPAddr
+	ipaddress := c.RunConfig.IPAddress
 	gateway := flags.Gateway
 	netmask := flags.Netmask
 
-	if ipaddr != "" && (gateway == "" || !isIPAddressValid(gateway)) {
+	if ipaddress != "" && (gateway == "" || !isIPAddressValid(gateway)) {
 		// assumes the default gateway is the first or last IP in the network range
-		ip := net.ParseIP(ipaddr).To4()
+		ip := net.ParseIP(ipaddress).To4()
 
 		if ip[3] == byte(1) {
 			ip[3] = byte(254)
@@ -107,13 +107,13 @@ func (flags *RunLocalInstanceCommandFlags) MergeToConfig(c *types.Config) (err e
 		}
 
 		c.RunConfig.Gateway = ip.String()
-	} else if ipaddr != "" {
+	} else if ipaddress != "" {
 		c.RunConfig.Gateway = gateway
 	}
 
-	if ipaddr != "" && (netmask == "" || !isIPAddressValid(netmask)) {
+	if ipaddress != "" && (netmask == "" || !isIPAddressValid(netmask)) {
 		c.RunConfig.NetMask = "255.255.255.0"
-	} else if ipaddr != "" {
+	} else if ipaddress != "" {
 		c.RunConfig.NetMask = netmask
 	}
 
diff --git a/cmd/run_local_instance.go b/cmd/run_local_instance.go
index 5efeff0..99b63ab 100644
--- a/cmd/run_local_instance.go
+++ b/cmd/run_local_instance.go
@@ -19,7 +19,7 @@ func RunLocalInstance(c *types.Config) (err error) {
 
 	tapDeviceName := c.RunConfig.TapName
 	bridged := c.RunConfig.Bridged
-	ipaddr := c.RunConfig.IPAddr
+	ipaddress := c.RunConfig.IPAddress
 	netmask := c.RunConfig.NetMask
 
 	bridgeName := c.RunConfig.BridgeName
@@ -30,7 +30,7 @@ func RunLocalInstance(c *types.Config) (err error) {
 	networkService := network.NewIprouteNetworkService()
 
 	if tapDeviceName != "" {
-		err = network.SetupNetworkInterfaces(networkService, tapDeviceName, bridgeName, ipaddr, netmask)
+		err = network.SetupNetworkInterfaces(networkService, tapDeviceName, bridgeName, ipaddress, netmask)
 		if err != nil {
 			return
 		}
diff --git a/lepton/image.go b/lepton/image.go
index b44b51a..ebc72a0 100644
--- a/lepton/image.go
+++ b/lepton/image.go
@@ -289,9 +289,9 @@ func setManifestFromConfig(m *fs.Manifest, c *types.Config) error {
 		m.AddMount(k, v)
 	}
 
-	if c.RunConfig.IPAddr != "" {
+	if c.RunConfig.IPAddress != "" {
 		m.AddNetworkConfig(&fs.ManifestNetworkConfig{
-			IP:      c.RunConfig.IPAddr,
+			IP:      c.RunConfig.IPAddress,
 			Gateway: c.RunConfig.Gateway,
 			NetMask: c.RunConfig.NetMask,
 		})
@@ -320,9 +320,9 @@ func BuildManifest(c *types.Config) (*fs.Manifest, error) {
 		m.AddLibrary(libpath)
 	}
 
-	if c.RunConfig.IPAddr != "" {
+	if c.RunConfig.IPAddress != "" {
 		m.AddNetworkConfig(&fs.ManifestNetworkConfig{
-			IP:      c.RunConfig.IPAddr,
+			IP:      c.RunConfig.IPAddress,
 			Gateway: c.RunConfig.Gateway,
 			NetMask: c.RunConfig.NetMask,
 		})
diff --git a/network/setup_network_interfaces.go b/network/setup_network_interfaces.go
index df0712b..eb3460a 100644
--- a/network/setup_network_interfaces.go
+++ b/network/setup_network_interfaces.go
@@ -24,7 +24,7 @@ type Service interface {
 }
 
 // SetupNetworkInterfaces changes network configuration to support requirements
-func SetupNetworkInterfaces(network Service, tapDeviceName string, bridgeName string, ipaddr string, netmask string) error {
+func SetupNetworkInterfaces(network Service, tapDeviceName string, bridgeName string, ipaddress string, netmask string) error {
 	tapExists, err := network.CheckNetworkInterfaceExists(tapDeviceName)
 	if err != nil {
 		return errors.New("Not able to check tap exists")
@@ -51,8 +51,8 @@ func SetupNetworkInterfaces(network Service, tapDeviceName string, bridgeName st
 			}
 		}
 
-		if ipaddr != "" {
-			ip := net.ParseIP(ipaddr).To4()
+		if ipaddress != "" {
+			ip := net.ParseIP(ipaddress).To4()
 			ip[3] = byte(66) // 66 is a random IP
 			bridgeIP := ip.String()
 
diff --git a/qemu/qemu_unix.go b/qemu/qemu_unix.go
index 2a9b4f3..ec7f199 100644
--- a/qemu/qemu_unix.go
+++ b/qemu/qemu_unix.go
@@ -273,7 +273,7 @@ func (q *qemu) addAccel() (bool, error) {
 	if runtime.GOOS == "darwin" {
 		if ok, _ := q.versionCompare(qemuVersion, hvfSupportedVersion); ok {
 			q.addOption("-accel", "hvf")
-			q.addOption("-cpu", "host")
+			q.addOption("-cpu", "host,-rdtscp")
 			return true, nil
 		}
 		return false, &errQemuHWAccelNotSupported{errCustom{"Hardware acceleration not supported", nil}}
@@ -363,7 +363,12 @@ func (q *qemu) setConfig(rconfig *types.RunConfig) {
 	}
 
 	q.addFlag("-no-reboot")
-	q.addOption("-cpu", "max")
+
+	if runtime.GOOS == "darwin" {
+		q.addOption("-cpu", "max,-rdtscp")
+	} else {
+		q.addOption("-cpu", "max")
+	}
 
 	if rconfig.GdbPort > 0 {
 		gdbProtoStr := fmt.Sprintf("tcp::%d", rconfig.GdbPort)
diff --git a/types/config.go b/types/config.go
index 6edc730..0efd460 100644
--- a/types/config.go
+++ b/types/config.go
@@ -160,8 +160,8 @@ type RunConfig struct {
 	// InstanceName
 	InstanceName string
 
-	// IPAddr
-	IPAddr string
+	// IPAddress
+	IPAddress string
 
 	// Klibs
 	Klibs []string


Test patch:
diff --git a/cmd/flags_run_local_instance_test.go b/cmd/flags_run_local_instance_test.go
index 488bac2..b71e846 100644
--- a/cmd/flags_run_local_instance_test.go
+++ b/cmd/flags_run_local_instance_test.go
@@ -57,7 +57,7 @@ func TestRunLocalInstanceFlagsMergeToConfig(t *testing.T) {
 			Debug:      false,
 			Gateway:    "192.168.1.254",
 			GdbPort:    1234,
-			IPAddr:     "192.168.0.1",
+			IPAddress:  "192.168.0.1",
 			Mounts:     []string(nil),
 			NetMask:    "255.255.0.0",
 			Ports:      []string{"80", "81", "82-85"},