Trackpad cursor freezes on Ubuntu

Problem

When I move the cursor using the trackpad of my Aftershock notebook, it sometimes freezes in place. Keyboard still works. The problem happens only with trackpad, not with mouse. The only way to unfreeze the cursor is to switch to virtual terminal Ctrl + Alt + F1 and back to X Ctrl + Alt + F7.

Solution

Apparently, this is a common bug in Ubuntu as reported here. It happens only with NVIDIA drivers with NVIDIA graphics card. A fix has been created for the X Server here.

Until I move to a newer version of Ubuntu with this updated version of X Server, I will have to survive by switch to virtual terminal :-)

Tried with: NVIDIA 765M and Ubuntu 14.04

NVIDIA module taints Linux kernel

Problem

I installed CUDA 7.0 on Ubuntu running on an Aftershock notebook with NVIDIA graphics card. The NVIDIA graphics drivers were upgraded to version 346. To my pleasant surprise, the graphics card was now directly visible to the Linux kernel. There was no longer any need to use Bumblebee.

However, I started noticing that this Ubuntu would not always boot into Unity. On many cold starts, I saw that Ubuntu would show this error:

After displaying this it would get stuck at the Ubuntu bootup screen.

I also noticed that I could boot up if I first booted into another Ubuntu instance I had on this notebook and later restarted and booted into the current Ubuntu instance.

Solution

To analyse this problem I cropped out the relevant portions of /var/log/syslog for the case when Ubuntu booted correctly and when it threw the above kernel panic error. These syslog entries can be seen here.

What I found was that there was some kind of a race condition at boot time. If the nvidia-drm module registered early enough with the kernel, then everything was fine. Otherwise, the kernel would complain that the NVIDIA module was tainting it and then it would throw up the above error.

The problem seems to lie in the Read-Copy-Update mechanism of the kernel. Here, some optimizations seem to have been added in recent versions to improve energy efficiency. RCU wakes up the CPUs only after a period of RCU_IDLE_GP_DELAY jiffies, as explained here. This is set to 4 by default, as seen here.

The solution going around the web for this problem is to decrease this sleep time to 1 jiffy, so that the race condition can be ameliorated. Thankfully, we do not need to edit Linux kernel code and recompile to do this! A syslog entry rcu_idle_gp_delay was added for runtime manipulation, as explained here. If we set this to 1, then the chance of this error reduces a lot.

To do this, add the following line to /etc/default/grub:

GRUB_CMDLINE_LINUX="rcutree.rcu_idle_gp_delay=1"

And run update-grub after this. Hopefully, this should fix the race condition so that every boot is successful.

Tried with: NVIDIA GTX 765M, Linux 3.13.0-44-generic and Ubuntu 14.04

The strange case of the notebook that would wakeup at night

Problem

I would put my notebook running Ubuntu to sleep by closing the lid or by choosing Suspend at night. I could see the display go off, harddisk turn off and keyboard lights go off. However, in the morning I would find this notebook fully active! How was it coming out of suspend mode in the middle of the night?

Solution

The culprit turned out to be a Targus wireless mouse that I had started to use recently. Any slight vibration of the table would awaken this mouse. It would communicate with Ubuntu informing that the user has moved it. So, Ubuntu would come out of suspend mode.

Now I switch off this mouse after I suspend the notebook. The problem has not repeated after I started doing this :-)

Tried with: Targus AMW071 wireless mouse and Ubuntu 14.04

Dispatch plugin for Vim

20150328_vim_dispatch

Vim can be used to build your code by using the :make command. It runs the command appropriate for your compiler, parses the compile errors or warnings and provides them in the Quickfix window. The only problem with this is that the build process is synchronous: the build command takes over the terminal and until it is over you can neither view nor interact with Vim.

The Dispatch plugin by Tim Pope enables you to run the build command asynchronously. The plugin can be installed from source here. You have two choices: run the build command asynchronously in the foreground or in the background.

  • Run :Make to run the build asynchronously in the foreground. This is possible only if you are using a terminal multiplexer like Tmux. A split terminal opens up at the bottom and you can see the output of your build there. The focus remains in Vim and you can view and interact with the editor while the build carries on. If you are running Vim in a normal terminal, this command just runs the plain old :make synchronously.

  • Run :Make! to run the build asynchronously in the background. This can be run on Vim running in any setup. The build command runs in the background invisibly and you can view and interact with Vim while this is happening.

  • Run :Copen to view the build output either during the build or after it is complete in foreground or background.

I highly recommend this plugin for anyone who is already using :make since with no change you can now build asynchronously.

Tried with: Vim 7.4 and Ubuntu 14.04

How to enable syntax highlighting for Strace output in Vim

20150327_strace_vim

Strace output can be written to a log file by using the -o option. This output is typically verbose and I find it helpful if the editor can apply syntax highlighting on it. This gives the system call, its parameters and its output different colors and makes it easy to understand the log.

Vim has support for syntax highlighting of strace output. You can see this in the /usr/share/vim/vim74/syntax/strace.vim file. Vim tries to detect if the file is strace output by looking for an execve or libc pattern in the first line. This logic can be seen in its /usr/share/vim/vim74/scripts.vim file. I have never seen these patterns in the first line in my strace output.

Since Vim does not automatically detect my strace output file, I enable it explicitly using the command: :set filetype=strace

Another trick is to output strace to a file of particular extension, say .strace and look for that file extension to set the strace filetype automatically. If you want this, then add this line to your .vimrc:

autocmd BufRead,BufNewFile *.strace set filetype=strace

Tried with: Vim 7.4, Strace 4.8-1 and Ubuntu 14.04

CMake fails looking for CUDA_TOOLKIT_ROOT_DIR

Problem

You have installed CUDA and try to compile a CUDA program using a CMake, which fails with this error:

$ cmake ..
CMake Error at /usr/share/cmake-2.8/Modules/FindCUDA.cmake:548 (message):
  Specify CUDA_TOOLKIT_ROOT_DIR
Call Stack (most recent call first):
  CMakeLists.txt:3 (find_package)

Solution 1

FindCUDA.cmake is trying to find your CUDA installation directory and failing. I had installed CUDA 7.0 on this machine, which was in /usr/local/cuda-7.0. However, CMake looks for /usr/local/cuda. The CUDA installer is supposed to create a symbolic link /usr/local/cuda pointing to that actual installation directory.

That symbolic link was not there on this computer. This can sometimes happen when you have two CUDA installations and remove one of them. The one removed takes out the symbolic link with it. I had CUDA 6.5 and CUDA 7.0 on this computer before I removed CUDA 6.5.

Anyway, we now know how to fix this:

$ sudo ln -s /usr/local/cuda-7.0 /usr/local/cuda

Solution 2

Pass the CUDA installation directory to the CUDA_TOOLKIT_ROOT_DIR variable directly during the invocation of CMake:

$ cmake -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-7.0 ..

Tried with: CUDA 7.0 and Ubuntu 14.04

Syntax highlighting for CUDA in Vim

Problem

Vim has had syntax highlighting support for CUDA source files for a long time now. You can check this: open any .cu file and try the command :set filetype?. You will see that Vim knows that it is a CUDA source file. It applies the syntax highlighting from the file /usr/share/vim/vim74/syntax/cuda.vim.

So, what is the problem? The syntax highlighting done by Vim for CUDA is very very minimal. My CUDA source files look like pages of plain white text in Vim! Also, the comments in the cuda.vim file that it was last updated in 2007. Now that is old!

Solution 1

There is an alternate cu.vim or cuda.vim syntax file for Vim floating around on the web. You can get it, for example, from here.

I replaced the cuda.vim that ships with Vim with this one and found it slightly better. But not by much. It still looks like lots of plain text.

Solution 2

The better solution for me was to just syntax highlight CUDA file as C++ file. This gave the best results, with the highest number of elements in the file being colored when compared to above two methods.

To do this, add this line to your .vimrc:

autocmd BufRead,BufNewFile *.cu set filetype=cpp

Tried with: Vim 7.4 and Ubuntu 14.04