Blog

My thoughts and experiments.

© 2018. Dmitry Dolgov All rights reserved.

Gentoo and Lenovo u430p - the sad story

Finally, I decided to replace my old laptop, and my chose fell on the Lenovo u430p. As I understand now, it was not a good idea in case of Gentoo =) Actually, I was surprised, how many nerves you can lose only because of the adaptation of you hardware to your requirements. And here is the shortlist of what you shouldn’t forget, if you want to do the same more easily.

EFI loader

So you’ve successfully passed several steps from Gentoo Handbook. One of the last is Grub2 installation and configuration. You’ve completed this, rebooted and…nothing happened, you see the Windows 8 again.

The clue to this problem is the “Secure Boot” option, which enabled by default in BIOS.

iwlwifi

Next big disaster is the iwlwifi driver for the Intel Wireless 7260. The most of wifi routers are working in the mixed 11bgn mode, and 11n drives iwlwifi (and you with him) mad. There are an endless disconnections and the terrible instability.

The only known solution is cut out the 11n mode:

# /etc/modprobe.d/iwlwifi.conf

options iwlwifi 11n_disable=1

And you shouldn’t forget to compile iwlwifi as kernel module (otherwise, obviously, this option will not be applied). The last step is the firmware installation. You can download the iwlwifi-7260-9.ucode, place it in /lib/firmware, and configure to load this firmware with kernel:

Device Driver ->
Generic Driver Options ->
[*] Include in-kernel firmware blobs in kernel library
(iwlwifi-7260-9.ucode) External firmware blobs to build into kernel library
(/lib/firmware) Firmware blobls root directory

Btw, one more note - loos like iwlwifi-7269-9.ucode is working more stable, then iwlwifi-7260-10.ucode.

Microphone

I don’t know why, but this there was no working configuration for microphone out of box =) I installed alsa and pulseaudio (the last one for the Skype, of course), and issues with the audio capture were really unexpected for me.

Actually, I though, that everything was unmutes in the alsamixer, but I was wrong:

$ amixer -c 1
...
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch
Capture channels: Front Left - Front Right
Limits: Capture 0 - 63
Front Left: Capture 63 [100%] [30.00dB] [off]
Front Right: Capture 63 [100%] [30.00dB] [off]
...

You can unmute the Capture, 0 control by this command (-c 1 is the card number):

$ amixer -c 1 Capture, 0 80% 40% unmute cap

And btw, don’t forget about the web cam:

Device Drivers ->
Multimedia support ->
[*] Cameras/video grabbers support
[*] Media USB Adapters ->
<*> USB input event device support

Windows 8 loading

Ok, it’s well enough. But if you’ll try to load now from the grub2 menu to Win8, you’ll suprised because of the messages error: can't find command drivemap and error: invalid EFI file path.

To avoid this problem you should create custom menu entry for grub.cfg with chainloader for Win8:

#!/bin/sh
# /etc/grub.d/40_custom
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'Windows 8 (UEFI loader)' --class windows --class os $menuentry_id_option 'osprober-chain-02E42074E4206BDB' {
search --file --no-floppy --set=root /EFI/Microsoft/Boot/bootmgfw.efi
chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi
}

Don’t forget to update grub.cfg:

# grub2-mkconfig -o /boot/grub/grub.cfg

Touchpad

Default configuration for touchpad is terrible…

You can improve it - just don’t forget, that this model doesn’t have the hardware right mouse button (so you shouldn’t disable software button). Here is my configuration:

# /etc/X11/xorg.conf.d/50-synaptics.conf

Section "InputClass"
Identifier "touchpad"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
Driver "synaptics"

Option "TapButton1" "1"
Option "TapButton2" "3"
Option "TapButton3" "2"

# accurate tap-to-click!
Option "FingerLow" "50"
Option "FingerHigh" "55"

# prevents too many intentional clicks
Option "PalmDetect" "0"

# vertical and horizontal scrolling, use negative delta values for "natural" scrolling
Option "VertTwoFingerScroll" "1"
Option "VertScrollDelta" "75"
Option "HorizTwoFingerScroll" "1"
Option "HorizScrollDelta" "75"

Option "MinSpeed" "1"
Option "MaxSpeed" "2"

Option "AccelerationProfile" "2"
Option "ConstantDeceleration" "4"
EndSection

And one more note - if you’re using the laptop-mode and a wireless keyboard from Logitech, it probably will be better to put this device into blacklist to avoid annoying problems with an unexpectedly frozen keyboard:

$ lsusb
......
Bus 001 Device 002: ID 046d:c52b Logitech, Inc. Unifying Receiver
......
# /etc/laptop-mode/conf.d/runtime-pm.conf

AUTOSUSPEND_RUNTIME_DEVID_BLACKLIST="046d:c52b"

End

It was interesting journey to the world of bugs, strange configurations and default options. I hope this shortlist can be useful, at least for me in the future =)

Use an exception instead of the NaN

This is a small notice about a very useful trick. I often have to deal with computations, because the CFD is the part of my activity. And one of the annoying problem in this kind of research is when after many hours of computations you got a Not A Number result, caused by a stupid mistake. It would be nice, if a computation was interrupted by the NaN.

And there is the solution:

#define _GNU_SOURCE
#include <fenv.h>
#include <stdio.h>

int main(void) {
double x, y, z;
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);

x = 0.0;
y = 0.0;
z = x / y; /* should cause an FPE */
printf("result is %f\n", z);
return 0;
}

The fenv.h header declares a set of functions and macros to access the floating-point environment, along with specific types. According to man:

The feenableexcept() function enable traps for each of the exceptions represented by excepts and return the previous set of enabled exceptions when successful, and -1 otherwise.

Now, what we have without feenableexcept:

$ ./test_no_fenv 
> result is -nan

And with:

$ ./test_fenv 
> fish: Job 1, './test' terminated by signal SIGFPE (Floating point exception)

From bash to fish

I’m doing a small revolution in my environment from time to time. I think “hey, a cool stuff”, take a deep breath and doing something new. And this is story about my migration from the bash to the fish shell.

Let’s see, what says the official tutorial:

fish is a fully-equipped command line shell (like bash or zsh) that is smart and user-friendly. fish supports powerful features like syntax highlighting, autosuggestions, and tab completions that just work, with nothing to learn or configure. If you want to make your command line more productive, more useful, and more fun, without learning a bunch of arcane syntax and configuration options, then fish might be just what you’re looking for!

And this is almost true =) But there is another concrete reason, why I like fish shell:

  • Search by history (as an autocomplete by tab)
  • More intuitive and clean configuration files
  • Vim mode support

I would to avoid unnecessary lyrics, and pay more attention to the configuration and gotchas (from the bash point of view).

First of all - use . command instead source for the inclusion of the script.

. /some-install-path/fish-shell/share/fish/functions/fish_vi_mode.fish
. /some-install-path/.config/fish/themes/fish_right_prompt.fish
. /some-install-path/.config/fish/themes/fish_prompt.fish
. /etc/profile.d/autojump.fish
fish_vi_key_bindings

I’ve used some-install-path because I’m a Vim hacker (an extra pathos), and I want a fresh version for the Vim support, so the manual compilation from github is my way. Then I’ve turned on Vim mode (fish_vi_mode.fish is necessary for this). fish_prompt.fish and fish_right_prompt.fish contain a description for the shell prompt and will be discussed later. If you use autojump, you should also include autojump.fish (if this file doesn’t exist, download it from repo).

set fish_greeting ""

This greeting is very distracting, so disable it. No comments =)

set -x EDITOR vim
set PATH /home/erthalion/.local/bin /usr/local/bin /opt/bin $PATH

We should set environment variables in this format. Pay attention to the PATH variable - don’t forget about /usr/local/bin and /opt/bin (looks like fish shell doesn’t include them by default).

alias goutshow='git fetch; git show origin/master..'

One more observation - we should replace && by the ; or and commands.

Now get closer to the prompt. It described by the two functions - fish_prompt and fish_right_prompt (your C.O.). I have no advices for this section. Really. You can use your imagination and do what you want =) There are my examples - left and right. Only one comment - you may want to show virtualenv name in the prompt. In that case you should disable original by the variable set -x VIRTUAL_ENV_DISABLE_PROMPT 1.

But unfortunately, Vim support isn’t very well in the fish shell. For example, there is no replace (r) command, or undo (u). Actually it’s a horrible problem for me, especially the first one =) And here is my solution of this problem.

I think, fish shell is available for a lot of improvements. All, that described above, is only a base for a convenient environment, and I hope, it will be useful.

Little guide about the gnuchess

I’m at the beginning of my journey into the world of gnuchess. Its interface is a slightly tricky, than I’ve expected, but I was interested. So I’ve decided to make some notes about this.

GNU Chess performs at the senior master/weak international master strength of 2500+ on the Elo rating system

I don’t know, what does this mean really, but sounds cool =)

It is often used in conjunction with a GUI program such as XBoard or glChess

No, it’s not our way. Let’s try to use original teminal-based client (more terminal for the terminal god, mwuahahahaha =).

$ gnuchess

GNU Chess 6.1.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
White (1) : e2e4
TimeLimit[0] = 0
TimeLimit[1] = 0
1. e2e4

black KQkq e3
r n b q k b n r
p p p p p p p p
. . . . . . . .
. . . . . . . .
. . . . P . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R

Thinking...

white KQkq
r n b q k b . r
p p p p p p p p
. . . . . n . .
. . . . . . . .
. . . . P . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R

Gnuchess uses the standard algebraic notation (SAN) required by FIDE, so we can type something like this to play:

Nf3
g1f3
O-O
e1g1

Ok. But what is it? Gnuchess uses the most of the CPU all time, even at the player’s move. It’s super, but it would be more convenient to limit the thinking time for gnuchess engine. In the documentation we can see, that the --easy options is responsible for this.

–easy, -e: Disable thinking in opponent’s time. By default, the program runs in hard mode, i.e. it thinks opponent’s time to think too.

Now better. But how we can pause the game and continue later? There are an obvious commands for this: save and load, which save the game position into EPD format

White (2) : save game_file
TimeLimit[0] = 0
TimeLimit[1] = 0
White (2) : load game_file
TimeLimit[0] = 0
TimeLimit[1] = 0

: Best move = 1

white KQkq
r n b q k b . r
p p p p p p p p
. . . . . n . .
. . . . . . . .
. . . . P . . .
. . . . . . . .
P P P P . P P P
R N B Q K B N R

White (1) :

And little bit about usability - we can use the pseudo graphical mode (a unicode symbols will be used for output), but … it looks ugly. Classical mode provides convenient enouth game, except the board’s coordinates. To avoid this inconvenience, we can use the patch below:

$ gnuchess -e
GNU Chess 6.1.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
White (1) : e2e4
TimeLimit[0] = 0
TimeLimit[1] = 0
1. e2e4

black KQkq e3

8 r n b q k b n r
7 p p p p p p p p
6 . . . . . . . .
5 . . . . . . . .
4 . . . . P . . .
3 . . . . . . . .
2 P P P P . P P P
1 R N B Q K B N R

a b c d e f g h

Thinking...

white KQkq

8 r n b q k b . r
7 p p p p p p p p
6 . . . . . n . .
5 . . . . . . . .
4 . . . . P . . .
3 . . . . . . . .
2 P P P P . P P P
1 R N B Q K B N R

a b c d e f g h


My move is : Nf6
White (2) :

Have a nice game!