Get number of physical processors inside virtual machine - c++

I'd like to know if there's a way to learn the number of physical CPU-s of a host computer when my code is running inside a VM.
I'm looking for C++/assembly solutions that run in Windows and under VmWare (workstation/esxi) and HyperV. Sorry for the very vague question but after several searches, I'm not sure if this is possible to do inside the virtual machine.

The very concept of VM is that your code (even your OS) do not know that they are sharing resources.
So in first intance, no. The only possible workaround would be if the VM provided it explicity (I am thinking of VMWare Tools, yet I do not know if they offer an API for you).

Related

bios information in c++

I just want to known how to get BIO information in C++. I tried following option but each one has its drawback.
From Registry: But I found some system where HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS is missing may be it is virtual machine.
Using WMI: But It is not necessary that WMI will run on all the systems, because in certain cases either the service is disabled or the WMI object is missing!!
I need one permanent solution that gives me BIO information in c++.
Trying to detect if you are in a virtual OS is done in various ways and depends on the virtualization software being used.
There are many different questions about this already on stackoverflow.
In no particular order, here are some articles, they cover a variety of the different virtualization pieces used:
Detect virtualized OS from an application?
detect if application running on virtual box
64-bit windows VMware detection
How to identify that you're running under a VM?
http://www.codeproject.com/Articles/9823/Detect-if-your-program-is-running-inside-a-Virtual
Whilst Salgar beat me to it, one of the more "safe" methods is to use the CPUID instruction, which generally works on modern VM's. I know that KVM, Microsoft and Xen uses a CPUID leaf around 0x40000000 that gives back "You are in a virtual machine". Not 100% sure if VMWare also supports the same one - on a "real" machine, these are reserved and not used.
Here's a page that discusses several options besides CPUID:
http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/detecting-x86-virtual-machines.html
and there are several links for further reading.

VM for scripted languages

I'm currently looking at different virtual machines to run a host of different scripted languages (in an embedded manner).
Two VMs that have caught my eye are:
LLVM: While I have seen posts that suggest not using LLVM as an VM, it does seem to have a lot going for it. It can do optimization, JIT, has a nice debugger already, etc. While there doesn't seem to be too much documentation on using LLVM in this manner, there is Cling which is capable of running c++11 as an interpreted language (which is pretty impressive), as well as the command-line tool 'lli'.
libJIT: Technically this isn't a VM, but provides the necessary tools to create one.
So my questions are:
Does anyone have experience with either of these VMs and can give negative/positive experiences.
I've gone through a lot of the documentation for both LLVM and libJIT, but wanted to check if anyone had any recommendations for other resources (esp. for LLVM).
Are there other VMs out there that I should consider? I've done some fairly extensive searches, so this not a question of what VMs are out there, but rather one of software that people have used and would recommend.
As for actual use of the VM I'm intending to embed the VM within a c++ program to provide a scriptable user environment. I'm already using Lua for some of the stuff, but for various reasons I want to be able to support other languages as well.
Finally, I've looked at Parrot, but I am a little hesitant to use it from some of the things I've read about it (maybe someone can convince me otherwise?).
update
I came across http://vmkit.llvm.org, which looks like it uses LLVM to create a full-fledged VM.

How should I test a stand alone application on different OS

I have developed an application with c++ on Vista. It works OK. But Now I want to be sure that it works on XP, on Windows 7, and later may be on some types of linux. What good methods do developers use for this task?
There is no substitute for actually running it on the platform itself. If you cannot afford to have separate machines dedicated to each platform then you need to:
Partition the disk(s) on a single machine and install each O/S in its own partition, and multi-boot between them.
Use virtualization software like VMWare or VirtualBox (free!) to set-up each O/S under your host O/S
If your application make little or no use of graphics (or other) hardware then the latter option is a real possibility; if it does use this hardware extensively then you have little choice but to go for the former option.
I use vmware. You can also use VBox or something similar. If you use visual studio along with vmware workstation you can even remote debug your application running in the VMWare.
Obviously keeping to the standard in C++ helps for portability to linux.
go and get a virtual machine player and have functionnal virtual machines for each OS you will test.
Execute the same unitary test scenarii on all the virtual machines.
Don't hesitate to focuss on what may be implemented differently on each plateform:
Save/Load dialogs
Remote communication
Drag'n'Drop
that's what come to my mind, there maybe thousands of other issues.
Anything really really low level (with inline asm code for eample) may be impacted by OS change.

Writing a Hypervisor?

I am researching ideas for a PhD project.
One of my thoughts is writing a hypervisor (or bare metal) (?) so I could run multiple OS's without use of a true host operating system. Example I get a menu of some type of options to start operating systems, view what the 'console' of what is going on in an OS that is already running. Reboot OS's, install a new one, etc.
So no host OS, just a small app that controls everything.
Conceptually how does one think about doing this?
I have a MacBook. I should be able to modify what the EFI boots. Maybe start with a very minimal Linux LIve implementation and scale it really, really far back?
Is it possible to use Darwin and scale it very far back?
Your idea as stated is not an original contribution to the science.
My advice is to review Xen and the general hypervisor literature, dating back to the '60s &
'70s when IBM invented it.
I'm certain there is room for improvement and original ideas there.
In terms of actually writing a hypervisor, you should review Wikipedia first, as it gives a good brief on virtualization.
Here is a historical summary, including some seminal citations: http://www.kernelthread.com/publications/virtualization/. Note the first citation is from 1959!
Scaling back an existing desktop/server OS seems like a poor choice. OTOH, rather than redo everything, it may be useful to start with an embedded RTOS such as ecos or L4 to draw some features from. Additionally, some code could possibly be re-used from QEMU.
If I were doing it, I would focus on hardware virtualization using VT-x and AMD-V ignore dynamic recompilation (unless was to be the focus of your work).
Also, it seems to me that it would be a good idea to already be able to write operating systems enough to make some small test operating systems that can boot on bare hardware to use for testing the hypervisor under development.
BTW, if scaling back an existing OS was a good strategy, I think it would work best on Linux or one of the major BSDs. Using Darwin is likely asking for pain.
Scaling back an existing OS to develop a hypervisor seems an unlikely approach.
Definitely have a look at some of the existing open source hypervisor project out there.
If you are interesting in reading about how they work and how you might approach writing
one then you could try:
Virtual Machines by Smith & Mair.
The Definitive Guide to the Xen Hypervisor by Chisnall.
If you are going to write it from scratch, and you are targeting the x86 family of processors then you are going to have to get your hands dirty with virtualization instructions (eg. Intel VT-x). And this will be with pure assembly language, or at best inline assembly. You are talking real low level stuff here.
If you are interested in computer communication and hypervisiors what about cross OS communication [it would be cheaper than trying to connect via normal TCP/IP sockets.
ESX is essentially a scaled-back Linux install - with a host of other goodies added: so your basic premise is decent.
However, for a PhD project, it sounds too broad: you should focus on something smaller.

VMWare equivalent [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I need to do testing on clean machines frequently so I need some kind of virtual machine emulator which can load and run clean OS images.
Do you know any recommended freeware or low cost emulator?
I have been using VirtualBox for a while - http://www.virtualbox.org/ - and it works a treat
Everyone seems to be suggesting VirtualBox but, in my opinion, you can't beat VMWare at the virtualization game.
I would get a copy of VMWare Player (it's free for non-commercial use and you'd be hard pressed to find one cheaper than that), then use this web site here to create yourself a virtual machine to whatever specification you need.
I run heaps of images under XP (and one XP image under Debian) and it really is easy to set up. Early editions of the Linux VMWare required you to re-configure the software whenever the kernel changed but this is now an automatic process.
Free emulator for Linux:
QEmu and KVM
http://www.qemu.org/
Best I have used.
We're using Xen paravirtualization, and it's working very well. It's the same technology used by Amazon's Elastic Compute Cloud (EC2) to run your virtual machine images on their physical hosts. It only costs you 0.5-3.0% of your CPU cycles too.
What exactly are your needs?
I would try Vagrant which uses VirtualBox. It makes it really easy and quick to create and destroy boxes as you need them.
I've found it to be really amazing for getting a new clean development environment up and running. Once you get it going it makes switching, testing, creating, sharing and trashing development environments real easy.
VirtualBox
VirtualBox
VirtualBox is a powerful x86
virtualization product for enterprise
as well as home use. Not only is
VirtualBox an extremely feature rich,
high performance product for
enterprise customers, it is also the
only professional solution that is
freely available as Open Source
Software under the terms of the GNU
General Public License (GPL).
VirtualBox is also a good alternative.
I realize this has been well-answered already, but I'd like to add a couple of notes about VirtualBox: (1) In my experience, it is much faster than VMware when running as a Linux host, and (2) the snapshot features have been greatly improved in recent versions (the comprehensive snapshot functionality is what kept me in VMware for a long time.)
VirtualBox is a great virtual machine solution.
I'm a big fan of VirtualBox as well. The OSE is free and runs really well.
VMWare is nice because it's incredibly robust, especially the server edition. With the server edition, you can run all off your VM's of one machine and access them at any time by browsing to VMWare's web GUI. This is a nice feature that I've used time and time again.
I would say that if you're doing just testing/playing around, I'd go with VirtualBox over VMWare.