Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use osversion.Build() utility, and add a sync.Once #996

Merged
merged 2 commits into from Apr 12, 2021

Conversation

thaJeztah
Copy link
Contributor

@thaJeztah thaJeztah commented Apr 8, 2021

When updating #556, I noticed other uses of this, so thought I'd do a minor refactor.

In this PR I noticed there's some intermediate build numbers used that don't (yet) have a corresponding const in osversion;

  • build: 18286 (somewhere between RS5 and V19H1) -> replace with V19H1 ?
  • build: 18967 (somewhere between V19H2 and V20H1) -> replace with V20H1 ?
  • build: 19020 (somewhere between V19H2 and V20H1) -> replace with V20H1 ?
  • build: 19645 (somewhere "after" V20H2) -> has this been released? (i.e., is there a version after V20H2?)

Giving that the "intermediate" versions have now made their way in releases, I assume (famous last words) that those can now be replaced with <first release that contains this change>; happy to make those changes (and/or add additional const in the package)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@@ -145,11 +145,11 @@ func verifyOptions(ctx context.Context, options interface{}) error {
return errors.New("PreferredRootFSTypeVHD requires at least one VPMem device")
}
}
if opts.KernelDirect && osversion.Get().Build < 18286 {
if opts.KernelDirect && osversion.Build() < 18286 {
Copy link
Contributor Author

@thaJeztah thaJeztah Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: is there much overhead in the syscall that's made? (wondering if there would be benefits in setting a package-level variable to store the version in to prevent calling this repeatedly in some packages, or if that would not give (significant) benefits)

https://github.com/golang/sys/blob/700132347e0702a3e5f100fba2752993b8de9600/windows/zsyscall_windows.go#L2266-L2273

func GetVersion() (ver uint32, err error) {
	r0, _, e1 := syscall.Syscall(procGetVersion.Addr(), 0, 0, 0, 0)
	ver = uint32(r0)
	if ver == 0 {
		err = errnoErr(e1)
	}
	return
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to trial the overhead but one syscall will definitely be better than many 😄. You'd think we could just do this in an init, assign it to an exported global and be done with it.. Not sure if I'm missing something/some history on why we just call it over and over.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevpar Should we move test/functional/manifest top level (or just out of test really), call Build() once in the osversion package and cache the result in an exported var and just use this everywhere? I don't have the history on why the manifest lives in test at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative could be to add a sync.Once in osversion.Get(); that way we don't have to add some "magic variable", and any consumer of that utility won't have to worry about it, and get the improvement "out of the box".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I have at the moment after firing up a new branch, I like it better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually went ahead and added that as an extra commit in this branch (can remove if it's not needed)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're too quick for me 😎. Let's see what others think, I think it should be fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to a global and sync.Once looks fine to me. I might be missing why moving manifest came up, though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No functional reason other than it feels weird to import this thing from the test dir when needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I thought it was related to this somehow. I'm in favor of moving it, but as a separate PR.

Given that it's _very_ unlikely that the Windows version changes at runtime,
we can use a sync.Once to not repeatedly call windows.GetVersion()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah changed the title Use osversion.Build() utility where possible Use osversion.Build() utility, and add a sync.Once Apr 8, 2021
Copy link
Contributor

@dcantah dcantah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I could be missing something with the manifest shenanigans.

Copy link
Member

@kevpar kevpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants