Practicing C++: Hello World

For some reasons, I need to get used to C++ including C++11, even C++14 possibly.

I’ve read some books of C++ and learnt basic things such as class, template, inheritance, capsulation, polymorphism, virtual functions, collections and some new features introduced in C++11 such as type reference, initializer lists, lambda expressions, smart pointers, rvalue references. Now I’m reading and modifying some open source programs written in C++ for practice.

Through the practice, I’ve added a simple piece of code to OSv, which is an Intel 10GbE driver. With this code, OSv can directly handle a physical 10GbE NIC if the host allows NIC pass-through. I’ve confirmed DHCP and ping succeed. (It is a kind of “Hello World” example program in C++, in which OSv can directly say “Hello” to physical LAN “World”.)

I put my dirty patch here.
(Revised ones: Intel 10GbE Driver and Pass-through Script)

USAGE

(Assuming that you have already compiled the patched OSv on KVM)

First, make sure that IOMMU is enabled by your BIOS and host OS.

Second, use the shell script (bindctrl), which is added by the patch, in order to remove the target 10GbE NIC from your host OS and make it ready for OSv. If your 10GbE NIC is located at Function #0 of Device #00 in Bus #07 with vendor ID 8086h and device ID 1528h, then the command will be:

Finally, run the python script with the special option (-a 07:00.0), which is also added by the patch, to start OSv with PCI pass-through.

The output will be:

TODO

  • Use interrupts
  • Use offloading
  • Use header write back
  • Use advanced descriptors

COMPONENTS

  • pf class describes a physical function of PCI device, which consists of ioreg, phyreg, tx_queue, rx_queue classes.
  • ioreg class describes a full set of I/O registers of the pf
  • phyreg class describes a full set of PHY registers of the pf, which can be accessed through MSCA/MSRWD registers.
  • tx_desc_layout struct is exactly a data structure of a TX descriptor.
  • rx_desc_layout struct is exactly a data structure of a RX descriptor.
  • desc template abstracts a descriptor, which is a template that depends on the descriptor types (tx_desc_layout or rx_desc_layout).
  • tx_desc class abstracts a TX descriptor, which is derived from desc with TX descriptor type, tx_desc_layout.
  • rx_desc class abstracts a RX descriptor, which is derived from desc with RX descriptor type, rx_desc_layout.
  • queue template describes a queue, descriptors of which depends on the descriptor types (tx_desc or rx_desc).
  • tx_queue class behaves as a queue with RX descriptors but also supports transmission operations that manipulate the queue.
  • rx_queue class behaves as a queue with TX descriptors but also supports reception operations that manipulate the queue.

One thought on “Practicing C++: Hello World

  1. Pingback: About OSp | Bitpress

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">