Basics of Integration using Monte Carlo

Recently, someone asked me about Monte Carlo. So, I thought I should write this post to provide a basic introduction of performing integration using Monte Carlo. "Why integration?", you asked. Well, this is because integration is one of the main operations done in computing the posterior probability distributions used in machine learning and probabilistic filtering (e.g. Bayes filter). For example, consider the typical posterior probability expression in the Bayes filtering context, \(p(x_{t} \mid y_{1:t})\), i.e. the probability of hidden state \(x_{t}\) given the observed sequence of measurements up to the current time point \(y_{1:t}\), $$p(x_{t} \mid y_{1:t}) = \frac{p(y_{t} \mid x_{t}) p(x_{t} \mid y_{1:t-1})}{p(y_{t} \mid y_{1:t-1})}$$ The \(p(x_{t} \mid y_{1:t-1})\) is of particular interest. It can be seen as the prediction of \(x_{t}\) from previous observations \(y_{1:t-1}\) and can be expressed as $$p(x_{t} \mid y_{1:t-1}) = \int p(x_{t} \mid x_{t-1}) p(x_{t-1}

vmblock patch for linux 3.10 (vmware 9)

After upgrading to linux 3.10, vmware workstation will have trouble compiling the vmnet and vmblock kernel modules against the latest kernel headers. This is attributed to the removal of create_proc_entry() in favor of proc_create().
  CC [M]  /tmp/modconfig-lEXylP/vmnet-only/driver.o
  CC [M]  /tmp/modconfig-lEXylP/vmnet-only/hub.o
  CC [M]  /tmp/modconfig-lEXylP/vmnet-only/userif.o
  CC [M]  /tmp/modconfig-lEXylP/vmnet-only/netif.o
/tmp/modconfig-lEXylP/vmnet-only/userif.c: In function ‘VNetUserIf_Create’:
/tmp/modconfig-lEXylP/vmnet-only/userif.c:1049:34: error: dereferencing pointer to incomplete type
/tmp/modconfig-lEXylP/vmnet-only/userif.c:1050:34: error: dereferencing pointer to incomplete type
/tmp/modconfig-lEXylP/vmnet-only/hub.c: In function ‘VNetHubAlloc’:
/tmp/modconfig-lEXylP/vmnet-only/hub.c:366:28: error: dereferencing pointer to incomplete type
/tmp/modconfig-lEXylP/vmnet-only/hub.c:367:28: error: dereferencing pointer to incomplete type
make[2]: *** [/tmp/modconfig-lEXylP/vmnet-only/userif.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [/tmp/modconfig-lEXylP/vmnet-only/hub.o] Error 1
/tmp/modconfig-lEXylP/vmnet-only/netif.c: In function ‘VNetNetIf_Create’:
/tmp/modconfig-lEXylP/vmnet-only/netif.c:191:33: error: dereferencing pointer to incomplete type
/tmp/modconfig-lEXylP/vmnet-only/netif.c:192:33: error: dereferencing pointer to incomplete type
make[2]: *** [/tmp/modconfig-lEXylP/vmnet-only/netif.o] Error 1
make[1]: *** [_module_/tmp/modconfig-lEXylP/vmnet-only] Error 2
make[1]: Leaving directory `/home/ricky/kernel_src/linux-3.10'
make: *** [vmnet.ko] Error 2
make: Leaving directory `/tmp/modconfig-lEXylP/vmnet-only'
Using 2.6.x kernel build system.
make: Entering directory `/tmp/modconfig-lEXylP/vmblock-only'
/usr/bin/make -C /lib/modules/3.10.0-custom/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. \
          MODULEBUILDDIR= modules
make[1]: Entering directory `/home/ricky/kernel_src/linux-3.10'
  CC [M]  /tmp/modconfig-lEXylP/vmblock-only/linux/block.o
  CC [M]  /tmp/modconfig-lEXylP/vmblock-only/linux/control.o
  CC [M]  /tmp/modconfig-lEXylP/vmblock-only/linux/dentry.o
  CC [M]  /tmp/modconfig-lEXylP/vmblock-only/linux/file.o
/tmp/modconfig-lEXylP/vmblock-only/linux/dentry.c:38:4: warning: initialization from incompatible pointer type [enabled by default]
/tmp/modconfig-lEXylP/vmblock-only/linux/dentry.c:38:4: warning: (near initialization for ‘LinkDentryOps.d_revalidate’) [enabled by default]
/tmp/modconfig-lEXylP/vmblock-only/linux/dentry.c: In function ‘DentryOpRevalidate’:
/tmp/modconfig-lEXylP/vmblock-only/linux/dentry.c:104:7: warning: passing argument 2 of ‘actualDentry->d_op->d_revalidate’ makes integer from pointer without a cast [enabled by default]
/tmp/modconfig-lEXylP/vmblock-only/linux/dentry.c:104:7: note: expected ‘unsigned int’ but argument is of type ‘struct nameidata *’
/tmp/modconfig-lEXylP/vmblock-only/linux/control.c: In function ‘SetupProcDevice’:
/tmp/modconfig-lEXylP/vmblock-only/linux/control.c:211:4: error: implicit declaration of function ‘create_proc_entry’ [-Werror=implicit-function-declaration]
/tmp/modconfig-lEXylP/vmblock-only/linux/control.c:211:21: warning: assignment makes pointer from integer without a cast [enabled by default]
/tmp/modconfig-lEXylP/vmblock-only/linux/control.c:221:20: error: dereferencing pointer to incomplete type
/tmp/modconfig-lEXylP/vmblock-only/linux/control.c: In function ‘ExecuteBlockOp’:
/tmp/modconfig-lEXylP/vmblock-only/linux/control.c:285:9: warning: assignment from incompatible pointer type [enabled by default]
/tmp/modconfig-lEXylP/vmblock-only/linux/control.c:296:4: warning: passing argument 1 of ‘putname’ from incompatible pointer type [enabled by default]
In file included from include/linux/proc_fs.h:8:0,
                 from /tmp/modconfig-lEXylP/vmblock-only/linux/control.c:28:
include/linux/fs.h:2042:13: note: expected ‘struct filename *’ but argument is of type ‘char *’
cc1: some warnings being treated as errors
make[2]: *** [/tmp/modconfig-lEXylP/vmblock-only/linux/control.o] Error 1
make[2]: *** Waiting for unfinished jobs....
Someone else has already written the patch for vmnet. You can find the patch here. On the other hand, the fix for vmblock is actually pretty simple. In case anyone needs it, here's a patch I've written.

Download: vmblock.3.10.patch
diff -r -u a/linux/control.c b/linux/control.c
--- a/linux/control.c 2013-02-26 19:17:29.000000000 +1100
+++ b/linux/control.c 2013-07-02 16:09:10.000000000 +1000
@@ -208,17 +208,18 @@
    VMBlockSetProcEntryOwner(controlProcMountpoint);
 
    /* Create /proc/fs/vmblock/dev */
-   controlProcEntry = create_proc_entry(VMBLOCK_CONTROL_DEVNAME,
+   /*controlProcEntry = create_proc_entry(VMBLOCK_CONTROL_DEVNAME,
                                         VMBLOCK_CONTROL_MODE,
-                                        controlProcDirEntry);
-   if (!controlProcEntry) {
+                                        controlProcDirEntry);*/
+   controlProcEntry = proc_create(VMBLOCK_CONTROL_DEVNAME, VMBLOCK_CONTROL_MODE, controlProcDirEntry, &ControlFileOps);
+   if (controlProcEntry == NULL) {
       Warning("SetupProcDevice: could not create " VMBLOCK_DEVICE "\n");
       remove_proc_entry(VMBLOCK_CONTROL_MOUNTPOINT, controlProcDirEntry);
       remove_proc_entry(VMBLOCK_CONTROL_PROC_DIRNAME, NULL);
       return -EINVAL;
    }
 
-   controlProcEntry->proc_fops = &ControlFileOps;
+   /* controlProcEntry->proc_fops = &ControlFileOps; */
    return 0;
 }
 
@@ -293,7 +294,7 @@
 
    retval = i < 0 ? -EINVAL : blockOp(name, blocker);
 
-   putname(name);
+   __putname(name);
 
    return retval;
 }
Extract both tarballs (/usr/lib/vmware/modules/source/vmnet.tar and /usr/lib/vmware/modules/source/vmblock.tar) and apply the patches accordingly. Then, convert them back to tarballs before replacing the existing ones (you might want to make a backup just in case). Run the following and everything should now compile properly.:
sudo vmware-modconfig --console --install-all

Comments

  1. Nice. Had to remove the putname(name) section of the patch on gentoo, but worked a treat.

    ReplyDelete
  2. Me as well!!!

    Worked for Fedora 19 and VMware Workstation.

    Thank you so much.

    Best Regards from Germany
    BJ

    ReplyDelete
  3. How can I apply the patch ?

    ReplyDelete
    Replies
    1. I'll assume you have both the vmnet and vmblock patch files downloaded to your current directory.

      $ cp /usr/lib/vmware/modules/source/vmblock.tar ./vmblock.orig.tar
      $ cp /usr/lib/vmware/modules/source/vmnet.tar ./vmnet.orig.tar
      $ tar -xf ./vmblock.orig.tar
      $ tar -xf ./vmnet.orig.tar
      $ pushd ./vmblock-only && patch -p1 < ../vmblock.3.10.patch && popd
      $ pushd ./vmnet-only && patch -p1 < ../procfs.patch && popd
      $ tar -cf ./vmblock.tar ./vmblock-only
      $ tar -cf ./vmnet.tar ./vmnet-only
      $ sudo mv /usr/lib/vmware/modules/source/{vmnet.tar,vmnet.orig.tar}
      $ sudo mv /usr/lib/vmware/modules/source/{vmblock.tar,vmblock.orig.tar}
      $ sudo cp ./vmblock.tar /usr/lib/vmware/modules/source/
      $ sudo cp ./vmnet.tar /usr/lib/vmware/modules/source/
      $ sudo vmware-modconfig --console --install-all

      Delete
  4. Thank you Ricky Wong! You saved me from having to reinvent the wheel & allowed me to simply cut & paste each command (I do understand what they are doing, but it is good to be lazy sometimes).

    This worked perfectly on Fedora Core 19 with kernel 3.10.5-201.fc19.x86_64

    ReplyDelete
  5. THANK YOU SO MUCH! Still learning Fedora/Linux but needed VMW Workstation on the corporate laptop to run the corporate image. You just save me from having to give up on Fedora, thank you Ricky Wong!

    Fedora core 19 3.10.9-200.fc19.x86_64

    ReplyDelete
  6. Why don't you people just run Virtualbox? You don't have to patch it to get it to work.

    ReplyDelete
    Replies
    1. Virtual Box cant convert the snapshots.. Try working in an enterprise.

      Delete
  7. I have a similar problem with Workstation10.
    Do a patch exist for WS10?

    ReplyDelete
  8. I applied the 2 patches to WS9.02; it compiled fine and installed OK.
    But I got this starting vmware:
    *****************
    filename: /lib/modules/3.10.24-desktop-2.mga3/misc/vmmon.ko
    supported: external
    license: GPL v2
    description: VMware Virtual Machine Monitor.
    author: VMware, Inc.
    srcversion: 720B99362854B538D7E9A9A
    depends:
    vermagic: 3.10.24-desktop-2.mga3 SMP mod_unload modversions
    PANIC /build/mts/release/bora-1031769/bora/lib/unicode/unicodeCommon.c:330
    Abandon
    ***********************
    Any idea?

    ReplyDelete
  9. Thank you Ricky.
    Everything is fine now.
    Can the patches be applied to Workstaton10?

    ReplyDelete
    Replies
    1. I'm not entirely sure, since I'm still using WS9 (in conjunction with Linux 3.13).
      According to the arch linux wiki entry on vmware, WS10 should work with any kernel up to 3.12 without any patches.

      Delete

Post a Comment