VPP/Random Hints and Kinks for KVM usage

From fd.io
< VPP
Revision as of 14:33, 12 May 2017 by Burts12 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

I have been trying to get a pleasant virtual machine (VM) environment on a laptop. The original goal was to set something up in limited space on a Lenovo T400 laptop.

I was tearing my hair out when I found that my virtual machine build of VPP was taking much longer than a build on the base machine. The laptop processor is Intel Core 2 Duo, and therefore it has all the Intel VT-x virtualization hardware needed for KVM, which I am using. (It also has the SSSE3 extension, required for DPDK, even though it is older than my AMD processor.) I read that under KVM, the virtual machine should execute code almost as fast as native processing.

After hours of building VPP with all sorts of tweaks to the number of processors assigned to the VM, and memory assigned, and even to the -j argument to the make command (controlled by build-root/Makefile,) I was having no luck.

It finally dawned on me that I had not controlled the version of gcc used. My VM is CentOS 7, and my host is Ubuntu Server 16.10. CentOS has gcc 4.8 installed, and Ubuntu 16.10 has gcc 6 (nominally.) So I re-ran my tests just using the host: I ignored gcc 6 this time, rather, I compared gcc 4.8.5 to gcc 5.4.1. Here are the results of "make build-release":

gcc 4.8.5
Thu Mar 16 10:14:45 EDT 2017 start
Thu Mar 16 10:47:04 EDT 2017 stop
gcc 5.4.1
Thu Mar 16 10:59:03 EDT 2017 start
Thu Mar 16 11:17:54 EDT 2017 stop

I will give the VM speed worry a rest. And let's back up to a set of hints for installing a VM.

Here is the standard way to do a graphical VM, using virt-manager, with a guest image that is not too large. I'll use Centos 7 for the guest.

1. Use virt-manager to install Centos 7 in the standard fashion -- I will leave out the details. I believe my Centos 7 DVD did not have any options for graphical images, so it should just install a minimal, non-graphical image.

2. Run the virtual machine, making certain you are connected to the Internet.

3. sudo yum groupinstall "X Window System" #seems to be there but it is unadvertised

4. sudo yum install xterm # I am not sure whether this step is needed

5. sudo yum install gnome-classic-session

6. sudo yum install gnome-terminal

7. sudo yum install liberation-mono-fonts

Now everything for a graphical login is present. You can swich to graphical mode by issuing:

$ systemctl isolate graphical.target

I will also present some other techniques below.

About 7 years ago I installed a full Ubuntu guest, and things just worked. Why are things more difficult now? One important factor is that I was previously using a high quality 19" CRT monitor. That will hide any graphics imperfections much better than a 1280x800 laptop LCD display. A lot of this memo was inspired by my incorrect setting of Scale Display in virt-manager, and/or by the use of virt-viewer. I should point out however that even when I had everything set correctly, nominally I could not get sharp contrast for my guest graphics. And yet, I knew I was not seeing a limitation of the laptop, based upon comparisons with running Windows Vista. Good contrast is helpful to offset a limitation with respect to my progressive lenses: a workaround for the fact that the lenses have a limited "in focus" area is to have more screen contrast. Then one can be slightly out of focus without that being a distrac- tion. More will be said below about solving the contrast issue.

Previously I was looking for advice about virtual machine graphics, but now I am simply going to show some techniques I use. I ran into issues with the guest graphics being blurry at one point, and that motivated my search for solutions to that. My eyes aren't perfect, but there was no doubt that the graphics really sucked on my earliest attempt. This is largely related to resizing windows. If you shrink a virt-viewer window, the text font shrinks rather than what we are used to when resizing a terminal window. Now, virt-manager behaves in a more complex fashion: it has a control, View->Scale Display, that can be set to Always, Only when Fullscreen, or Never. Virt-viewer behaves like virt- manager set to Always.

Having said that, I'll show a few techniques, starting with

1. a medium standard method. Not as standard as "systemctl isolate graphical.target" shown above.

a. start up the host in graphics mode (hopefully startx is configured to do what you want) and open a terminal window.

b. start the guest OS. One method to do this from the host, assuming I had named it centos7:

  $ sudo chown $USER /etc/libvirt/qemu/centos7.xml #one time operation
  $ virsh create /etc/libvirt/qemu/centos7.xml

c. start spicy or virt-viewer or virt-manager's viewer, and connect to the VM.

  I suggest that you DO NOT use spicy as I do not know anyway to get out of
  full screen mode.  virt-viewer is the friendliest for locating the leave
  full screen widget at the top center of the screen. (Just to the left of top
  dead center.) Virt-manager has the widget in the same location, but it is
  much less visible (roughly invisible.) In other respects, I find
  virt-manager to be friendlier. The following statements, unless noted
  otherwise, assume that virt-viewer has been chosen. But please keep reading.

d. set the virt-viewer to full screen mode from the View menu.

e. start the guest OS if not already done so, log in, and then issue xinit at the guest login.

f. You should get a new window on the host that has the Xserver for the guest and an xterm there. The xterm will have slightly fuzzy characters.

g. Issue gnome-shell. Well you could issue gnome-terminal, but you will get a fuzzy gnome-terminal to go along with the fuzzy xterm. In contrast, gnome-shell, using some mutter/clutter/xrandr magic, will modify that xterm to sharp graphics, and of course will allow you to open a gnome-terminal. The graphics will be sharp for all the gnome-terminals that you open. If you Ctrl-C in the xterm, the gnome-shell will close out but the xterm will remain with sharp graphics.

h. At this point, if you issued the Ctrl-C in the xterm as mentioned in the previous step, the graphics should be clear, whether you now use gnome-terminal or gnome-shell. This is because mutter's magic is not lost upon Ctrl-C in the xterm. There may be no value in issuing that Ctrl-C, but I am trying to show the various possibilities for the sake of completeness.

Let me try to repeat the above, using virt-manager rather than virt-viewer.

a., b., and c. are like above but virt-manager replaces virt-viewer.

d. The window of interest is the console window, entitled <VM Name> on QEMU/KVM, not the main control window that is entitled Virtual Machine Manager. You do not need to set it to Fullscreen mode at this point. Do set View->Scale Display to Never.

e. Same as above.

f. If you set Scale Display to Never, the xterm will not have fuzzy characters.

g. You can start your favorite application like gnome-terminal or gnome-shell.

h. If you have issued the gnome-shell command, you might now set Fullscreen under the View menu. The gnome shell should fill your entire screen, perfectly.

Things to be aware of:

a. If you shrink the host window that has the guest X, fonts will shrink when using either virt-viewer or else virt-manager with Scaling enabled.

b. The professional thing would be to issue "systemctl start gdm" rather than directly starting gnome-shell (or "systemctl isolate graphical.target" prior to starting X windows.) Your mileage may vary. Currently my system brings up Cinnamon in 1024x768 dimensions (rather than the laptop's 1280x800 full screen.) This is probably because I used yum to install several window managers, and Cinnamon must have been the last. None of the window managers other than gnome play the mutter/clutter/xrandr tricks to produce a 1280x800 display, automatically. However my Cinnamon has the Display option under Settings where I can set the resolution to 1280x800. Once I select that, I can select View->Full Screen from virt-manager, and then have a perfect display. In fact, the earlier result that gnome-shell had 1280x800 dimensions may have been luck: the dimensions can be changed just like with the Cinnamon desktop.

c. To copy/paste between guest and host, first issue in the guest:

  $ sudo spice-vdagentd

$ ps -e | grep spice

should show two processes named spice-vdagent and one named spice-vdagentd if things are set up for copy/paste.

2. Here is a procedure that works nicely, but requires some security reductions while bringing the X-Windows behavior back to what we remember from the 1990s. Note that I started off with a non-graphical Ubuntu Server, and then tried adding just enough to get graphics. I began with the olvwm window manager, but found that I prefer the Joe window manager, jwm.

I start Ubuntu Server and it comes up in text mode. I may start my VM at this time with

$ sudo chown $USER /etc/libvirt/qemu/centos7.xml #one time operation

$ virsh create /etc/libvirt/qemu/centos7.xml

I can next:

$ startx

or else:

$ sudo xinit #bug requiring sudo also solved using "xinit -- vt<n>" (often "xinit -- vt1")

but this is the sticky point -- I had to change /etc/X11/xinit/xserverrc (for startx) or ~/.xserverrc (for xinit) to change the option "-nolisten tcp" to "-listen tcp". So my technique requires me to revert to an insecure mode.

Next thing I do from a terminal on the graphics desktop is

$ xhost + #or I can add -ac to X command options in my .xserverrc, I'll assume that below

Following that I

$ ssh -X burt@192.168.122.178

after my VM is up, and then from my VM after logging in to it I can either

1) $ gnome-terminal

or if I had not done startx but rather I had done xinit

2) $ssh -X burt@192.168.122.178; $ gnome-shell

and then I get a very nice full screen CentOS desktop, with no blurry graphics. (Maybe play with Settings->Display to get 1280x800.)

How did I know that the guest address is 192.168.122.178? Chances are I had previously viewed the VM with virt-viewer or virt-manager and used ifconfig on the guest. Although dhcp is involved, it appears that once the address is assigned, it does not change. Another method is to use arp -a or arp -an on the host.

https://rwmj.wordpress.com/2010/10/26/tip-find-the-ip-address-of-a-virtual-machine/ is a good reference.

So I have been reading about the Spice protocol, and how Spice does everything, and is better than VNC, yada yada yada. However, I have not found much clear documentation. But I did find the copy/paste prerequisites shown above.

A word about suspend/resume: suspending the laptop without first suspending the guest leads to locked up guest. People are aware of this but the experts have had a difficult time root causing it. This is another reason to prefer virt-manager over virt-viewer: it has a Suspend/Resume control under the Virtual Machine menu.

I promised to say a few words about screen contrast, and since I discovered it last, I describe it now. The command is xgamma.

$ xgamma -gamma 1.0 #this is the default

Choose a number less than 1.0 to increase contrast. One person suggested 0.3. That is a large change, and the normal tradeoff exists between too little contrast and text characters looking "rough". A good choice might be

$ xgamma -gamma 0.8

and a more modern command to use is

$ xrandr --gamma 0.8:0.8:0.8 #red:green:blue

SIZE OF A GUEST SYSTEM

Here are some numbers, in 1024 byte blocks as I installed things, and some things I did a bit out of order

1055100 bare Centos7

1198236 after installing X Window System group

1684400 after gnome-classic-session

1699140 after gnome-terminal

2376500 after git, gitk, traceroute, net-tools, gcc, deltarpm, autoconf, automake, libtool, java-1.8.0-openjdk-devel, epel-release, and a yum update

2457844 after cloning VPP

2632000 after ganglia-devel, lcov, libconfuse-devel, redhat-lsb, glibc-static, yum-utils, openssl-devel, apr-devel, chrpath, libffi-devel, nasm, python-devel

2663880 after byacc flex and make bootstrap

4262260 after make build-release

4319884 after make pkg-rpm