Re: list hyperv features in dmesg

2021-06-14 Thread Peter J. Philipp
On Mon, Jun 14, 2021 at 01:19:21PM -0700, Chris Cappuccio wrote:
[..]
> If you're going to print flags for some unsupported features, why
> not print them all? 
> 
> The 'features3' line doesn't look clean
> 
> Typically uppercase flags like this are formatted like 

OK in this next patch (below) the flags are cleaned up and print as much info
as they can (as much as FreeBSD).  I don't have Microsoft docs so this relies
on the open sources from there.  It now looks like this:

pvbus0 at mainbus0: Hyper-V 10.0
hyperv0 at pvbus0: protocol 4.0, features 0x2e7f 
hyperv0: pm features 0x2 <>
hyperv0: features3 0xbed7b2 
hyperv0: heartbeat, kvp, shutdown, timesync
hvs0 at hyperv0 channel 2: ide, protocol 6.2

In regards to features3 not looking "clean" do you mean the 3's that I had
initially put behind them to indicate that they are feature3?  Or do you mean
the register value?  For the former I cleaned that up.

> In any event, I'm not sure what benefit this brings. Doesn't 
> "hyperv0: heartbeat, kvp, shutdown, timesync" already show what features
> are in use?

This line is constructed in hv_guid_sprint() in hyperv.c, I haven't read into
them too much but I think they are general drivers that are enabled.  I don't
really know.

> I imagine it might be interesting to know what features are available but
> not in use. Is there a command-line utility that could be extended to show
> this info?

You mean in the Windows Host system or in the guest?  Either way I don't have
too much windows documentation.  I don't know any command-line utility to show 
this.

> 
> Chris

In the updated patch below I made one more change in that I moved the original
DPRINTF() into the print_hv_features() function.  Also interesting is that
hyperv0 features3 are showing "DEBUG", I wonder if it's just my machine with
this patch, and if I can turn that off somehow to gain speed.

Best Regards,
-peter

Index: hyperv.c
===
RCS file: /cvs/src/sys/dev/pv/hyperv.c,v
retrieving revision 1.48
diff -u -p -u -r1.48 hyperv.c
--- hyperv.c23 Feb 2021 04:44:31 -  1.48
+++ hyperv.c15 Jun 2021 05:08:06 -
@@ -108,6 +108,7 @@ uinthv_channel_unpause(struct hv_channe
 uint   hv_channel_ready(struct hv_channel *);
 extern void hv_attach_icdevs(struct hv_softc *);
 inthv_attach_devices(struct hv_softc *);
+void   print_hv_features(struct hv_softc *, struct pvbus_hv *);
 
 struct {
int   hmd_response;
@@ -194,6 +195,42 @@ const struct hv_guid hv_guid_kvp = {
  0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x03, 0xe6 }
 };
 
+const struct {
+   uint32_t bit;
+   char str[16];
+} hv_cpu_features[] = {
+   { CPUID_HV_MSR_VP_RUNTIME,  "VPRUNTIME" },
+   { CPUID_HV_MSR_TIME_REFCNT, "TIME_REFCNT" },
+   { CPUID_HV_MSR_SYNIC,   "SYNIC" },
+   { CPUID_HV_MSR_SYNTIMER,"SYNTIMER" },
+   { CPUID_HV_MSR_APIC,"APIC" },
+   { CPUID_HV_MSR_HYPERCALL,   "HYPERCALL" },
+   { CPUID_HV_MSR_VP_INDEX,"VP_INDEX" },
+   { CPUID_HV_MSR_RESET,   "RESET" },
+   { CPUID_HV_MSR_STATS,   "STATS" },
+   { CPUID_HV_MSR_REF_TSC, "REF_TSC" },
+   { CPUID_HV_MSR_GUEST_IDLE,  "GUEST_IDLE" },
+   { CPUID_HV_MSR_TM_FREQ, "TM_FREQ" },
+   { CPUID_HV_MSR_DEBUG,   "DEBUG" }
+}, hv_cpu_pm_features[] = {
+   { CPUPM_HV_C3_HPET, "C3_HPET" }
+}, hv_cpu_features3[] = {
+   { CPUID3_HV_MWAIT,  "MWAIT" },
+   { CPUID3_HV_DEBUG,  "DEBUG" },
+   { CPUID3_HV_PERFMON,"PERFMON" },
+   { CPUID3_HV_PCPUDPE,"PCPUDPE" },
+   { CPUID3_HV_XMM_HYPERCALL,  "XMM_HYPERCALL" },
+   { CPUID3_HV_GUEST_IDLE, "GUEST_IDLE" },
+   { CPUID3_HV_SLEEP,  "SLEEP" },
+   { CPUID3_HV_NUMA,   "NUMA" },
+   { CPUID3_HV_TIME_FREQ,  "TIME_FREQ" },
+   { CPUID3_HV_SYNCMC, "SYNCMC" },
+   { CPUID3_HV_MSR_CRASH,  "CRASH" },
+   { CPUID3_HV_DEBUGMSR,   "DEBUGMSR" },
+   { CPUID3_HV_NPIEP,  "NPIEP" },
+   { CPUID3_HV_HVDIS,  "HVDIS" }
+};
+
 #ifdef HYPERV_DEBUG
 const struct hv_guid hv_guid_vss = {
{ 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42,
@@ -314,11 +351,8 @@ hv_attach(struct device *parent, struct 
if (hv_vmbus_connect(sc))
return;
 
-   DPRINTF("%s", sc->sc_dev.dv_xname);
-   printf(": protocol %d.%d, features %#x\n",
-   VMBUS_VERSION_MAJOR(sc->sc_proto),
-   VMBUS_VERSION_MINOR(sc->sc_proto),
-   hv->hv_features);
+
+   print_hv_features(sc, hv);
 
if (hv_channel_scan(sc))
return;
@@ -1830,4 +1864,32 @@ hv_evcount_attach(struct hv_channel *ch,
struct hv_softc *sc = ch->ch_sc;
 
evcount_attach(>ch_evcnt, name, >sc_idtvec);
+}
+
+void

Re: list hyperv features in dmesg

2021-06-14 Thread Chris Cappuccio
Peter J. Philipp [p...@delphinusdns.org] wrote:
> 
> Before:
> pvbus0 at mainbus0: Hyper-V 10.0
> hyperv0 at pvbus0: protocol 4.0, features 0x2e7f
> hyperv0: heartbeat, kvp, shutdown, timesync
> hvs0 at hyperv0 channel 2: ide, protocol 6.2
> 
> After:
> 
> pvbus0 at mainbus0: Hyper-V 10.0
> hyperv0 at pvbus0: protocol 4.0, features 0x2e7f 
> TIME_REFCNT,SYNIC,SYNTIMER,APIC
> ,HYPERCALL,VP_INDEX,GUEST_IDLE
> hyperv0: pm features 0x2 
> hyperv0: features3 0xbed7b2 ,XMM_HYPERCALL3,GUEST_IDLE3,NUMA3,TIME_FREQ3
> hyperv0: heartbeat, kvp, shutdown, timesync
> hvs0 at hyperv0 channel 2: ide, protocol 6.2
> 
> Below is patch, what do you think?  Is it worthy?
> 

If you're going to print flags for some unsupported features, why
not print them all? 

The 'features3' line doesn't look clean

Typically uppercase flags like this are formatted like 

In any event, I'm not sure what benefit this brings. Doesn't 
"hyperv0: heartbeat, kvp, shutdown, timesync" already show what features
are in use?

I imagine it might be interesting to know what features are available but
not in use. Is there a command-line utility that could be extended to show
this info?

Chris



list hyperv features in dmesg

2021-06-14 Thread Peter J. Philipp
Hi,

I may be interested in looking into hyperv since I have a MS Windows Server 2019
machine that has a hyper-v running OpenBSD (half the resources).  I have two
things that would need my attention 1. the time doesn't jump when I patch the
host OS and reboot, hyperv guest gets snapshotted at boot and sleeps while it's
off, when the system is back the time is usually off by a manner of 5 minutes
per reboot.  This I'd like to look into and I have asked Mike B. what I need
to do, his answer was that I should look at how FreeBSD do it.  2. The machine
is really slow on disk and the overlying OS uses an SSD.  I don't know the
reason but I'm wondering if it's an FS boundary issue.  Anyhow this is over
my head I think.

To start investigating the system I have added a flag for features much like
identcpu.c on amd64.  The FreeBSD equivalent is in 
sys/dev/hyperv/vmbus/hyperv.c in function hyperv_identify().

They have a lot more flags, but we don't need all until there is drivers is
what I gather, nontheless in my patch (below) I have commented out the flags
that FreeBSD has listed in their features list.  So here is how OpenBSD's
feature list looks like:

Before:
pvbus0 at mainbus0: Hyper-V 10.0
hyperv0 at pvbus0: protocol 4.0, features 0x2e7f
hyperv0: heartbeat, kvp, shutdown, timesync
hvs0 at hyperv0 channel 2: ide, protocol 6.2

After:

pvbus0 at mainbus0: Hyper-V 10.0
hyperv0 at pvbus0: protocol 4.0, features 0x2e7f TIME_REFCNT,SYNIC,SYNTIMER,APIC
,HYPERCALL,VP_INDEX,GUEST_IDLE
hyperv0: pm features 0x2 
hyperv0: features3 0xbed7b2 ,XMM_HYPERCALL3,GUEST_IDLE3,NUMA3,TIME_FREQ3
hyperv0: heartbeat, kvp, shutdown, timesync
hvs0 at hyperv0 channel 2: ide, protocol 6.2

Below is patch, what do you think?  Is it worthy?

Best Regards,
-peter

Index: hyperv.c
===
RCS file: /cvs/src/sys/dev/pv/hyperv.c,v
retrieving revision 1.48
diff -u -p -u -r1.48 hyperv.c
--- hyperv.c23 Feb 2021 04:44:31 -  1.48
+++ hyperv.c14 Jun 2021 17:17:31 -
@@ -108,6 +108,7 @@ uinthv_channel_unpause(struct hv_channe
 uint   hv_channel_ready(struct hv_channel *);
 extern void hv_attach_icdevs(struct hv_softc *);
 inthv_attach_devices(struct hv_softc *);
+void   print_hv_features(struct hv_softc *, struct pvbus_hv *);
 
 struct {
int   hmd_response;
@@ -194,6 +195,42 @@ const struct hv_guid hv_guid_kvp = {
  0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x03, 0xe6 }
 };
 
+const struct {
+   uint32_t bit;
+   char str[16];
+} hv_cpu_features[] = {
+   /* { CPUID_HV_MSR_VP_RUNTIME,   "VPRUNTIME" }, */
+   { CPUID_HV_MSR_TIME_REFCNT, "TIME_REFCNT" },
+   { CPUID_HV_MSR_SYNIC,   "SYNIC" },
+   { CPUID_HV_MSR_SYNTIMER,"SYNTIMER" },
+   { CPUID_HV_MSR_APIC,"APIC" },
+   { CPUID_HV_MSR_HYPERCALL,   "HYPERCALL" },
+   { CPUID_HV_MSR_VP_INDEX,"VP_INDEX" },
+   /* { CPUID_HV_MSR_RESET,"RESET" }, */
+   /* { CPUID_HV_MSR_STATS,"STATS" }, */
+   /* { CPUID_HV_MSR_REFTSC,   "REFTSC" }, */
+   { CPUID_HV_MSR_GUEST_IDLE,  "GUEST_IDLE" },
+   /* { CPUID_HV_MSR_TMFREQ,   "TMFREQ" }, */
+   /* { CPUID_HV_MSR_DEBUG,"DEBUG" } */
+}, hv_cpu_pm_features[] = {
+   { CPUPM_HV_C3_HPET, "C3_HPET" }
+}, hv_cpu_features3[] = {
+   { CPUID3_HV_MWAIT,  "MWAIT3" },
+   /* { CPUID3_HV_DEBUG,   "DEBUG3" },*/
+   /* { CPUID3_HV_PERFMON, "PERFMON" }, */
+   /* { CPUID3_HV_PCPUDPE, "PCPUDPE" }, */
+   { CPUID3_HV_XMM_HYPERCALL, "XMM_HYPERCALL3" },
+   { CPUID3_HV_GUEST_IDLE, "GUEST_IDLE3" },
+   /* { CPUID3_HV_SLEEP,   "SLEEP" }, */
+   { CPUID3_HV_NUMA,   "NUMA3" },
+   { CPUID3_HV_TIME_FREQ,  "TIME_FREQ3" },
+   /* { CPUID3_HV__SYNCMC, "SYNCMC" }, */
+   /* { CPUID3_HV__CRASH,  "CRASH" }, */
+   /* { CPUID3_HV__DEBUGMSR,   "DEBUGMSR" }, */
+   /* { CPUID3_HV__NPIEP,  "NPIEP" }, */
+   /* { CPUID3_HV__HVDIS,  "HVDIS" } */
+};
+
 #ifdef HYPERV_DEBUG
 const struct hv_guid hv_guid_vss = {
{ 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42,
@@ -315,11 +352,13 @@ hv_attach(struct device *parent, struct 
return;
 
DPRINTF("%s", sc->sc_dev.dv_xname);
-   printf(": protocol %d.%d, features %#x\n",
+   printf(": protocol %d.%d, features %#x ",
VMBUS_VERSION_MAJOR(sc->sc_proto),
VMBUS_VERSION_MINOR(sc->sc_proto),
hv->hv_features);
 
+   print_hv_features(sc, hv);
+
if (hv_channel_scan(sc))
return;
 
@@ -1830,4 +1869,26 @@ hv_evcount_attach(struct hv_channel *ch,
struct hv_softc *sc = ch->ch_sc;
 
evcount_attach(>ch_evcnt, name, >sc_idtvec);
+}
+
+void
+print_hv_features(struct hv_softc *sc, struct pvbus_hv *hv)
+{
+   int i;
+
+   for (i = 0; i < nitems(hv_cpu_features); i++)
+   if (hv->hv_features &