Background
About a year ago, I used powertop to optimise my laptop's power consuption (following this and this guide), ending up with this systemd service:
[Unit]
Description=Powertop tunings for X1 Carbon 5th
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "echo '1500' > '/proc/sys/vm/dirty_writeback_centisecs';"
ExecStart=/bin/sh -c "echo '1' > '/sys/module/snd_hda_intel/parameters/power_save';"
ExecStart=/bin/sh -c "echo '0' > '/proc/sys/kernel/nmi_watchdog';"
ExecStart=/bin/sh -c "echo 'auto' > '/sys/bus/i2c/devices/i2c-0/device/power/control';"
ExecStart=/bin/sh -c "echo 'auto' > '/sys/bus/i2c/devices/i2c-2/device/power/control';"
ExecStart=/bin/sh -c "echo 'auto' > '/sys/bus/usb/devices/1-9/power/control';"
ExecStart=/bin/sh -c "echo 'auto' > '/sys/bus/i2c/devices/i2c-1/device/power/control';"
ExecStart=/bin/sh -c "echo 'auto' > '/sys/bus/pci/devices/0000:00:00.0/power/control';"
ExecStart=/bin/sh -c "echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.2/power/control';"
ExecStart=/bin/sh -c "echo 'auto' > '/sys/bus/pci/devices/0000:00:08.0/power/control';"
# ... omitted some more PCI devices ...
[Install]
WantedBy=multi-user.target
Problem analysis
This worked fine and brought my laptop's idle power consumption down - until a few months ago when I got a Yubikey 5C nano.
Now however, my laptop's idle power consumption rose from previous 5-5.5W to now 5.8-6.2W (without Yubikey Nano plugged versus plugged in. Readings observed on a idle system with no open programs over 5ish minutes.)
It's not the Yubikey that's consuming this extra watt, otherwise it would likely be on fire. Instead it's probably caused by the USB controllers not going to sleep as they should.
When I run powertop I get the following in the Tuning tab:
| Description | Script |
| ----------- | ------ |
| Autosuspend for USB device YubiKey OTP+FIDO+CCID [Yubico] | echo 'auto' > '/sys/bus/usb/devices/3-2/power/control'; |
| Runtime PM for PCI Device Intel Corporation JHL6540 Thunderbolt 3 USB Controller (C step) [Alpine Ridge 4C 2016] | echo 'auto' > '/sys/bus/pci/devices/0000:3c:00.0/power/control'; |
| Runtime PM for PCI Device Intel Corporation JHL6540 Thunderbolt 3 Bridge (C step) [Alpine Ridge 4C 2016] | echo 'auto' > '/sys/bus/pci/devices/0000:07:04.0/power/control'; |
| Runtime PM for PCI Device Intel Corporation JHL6540 Thunderbolt 3 Bridge (C step) [Alpine Ridge 4C 2016] | echo 'auto' > '/sys/bus/pci/devices/0000:07:01.0/power/control'; |
However, if I remove the Yubikey, insert it again, and run powertop --html=reportB.html again I get the following in the Tuning tab:
| Description | Script |
| ----------- | ------ |
| Autosuspend for USB device YubiKey OTP+FIDO+CCID [Yubico] | echo 'auto' > '/sys/bus/usb/devices/3-2/power/control'; |
| Runtime PM for PCI Device Intel Corporation JHL6540 Thunderbolt 3 USB Controller (C step) [Alpine Ridge 4C 2016] | echo 'auto' > '/sys/bus/pci/devices/0000:3c:00.0/power/control'; |
| Runtime PM for PCI Device Intel Corporation JHL6540 Thunderbolt 3 Bridge (C step) [Alpine Ridge 4C 2016] | echo 'auto' > '/sys/bus/pci/devices/0000:07:02.0/power/control'; |
| Runtime PM for PCI Device Intel Corporation JHL6540 Thunderbolt 3 Bridge (C step) [Alpine Ridge 4C 2016] | echo 'auto' > '/sys/bus/pci/devices/0000:06:00.0/power/control'; |
| Runtime PM for PCI Device Intel Corporation JHL6540 Thunderbolt 3 Bridge (C step) [Alpine Ridge 4C 2016] | echo 'auto' > '/sys/bus/pci/devices/0000:07:04.0/power/control'; |
| Runtime PM for PCI Device Intel Corporation JHL6540 Thunderbolt 3 Bridge (C step) [Alpine Ridge 4C 2016] | echo 'auto' > '/sys/bus/pci/devices/0000:07:01.0/power/control'; |
Question
This leads me to a series of question:
Am I right in understanding that every time you plug in a USB device - even if it's been plugged in before - it will be assigned a new PCI identifier?
Is it wise to add these tuning commands to my systemd service?
What are the possible side effects?
What about only the Autosuspend for USB device YubiKey?
Would it be wise to add all commands given the constraint that I will never actually remove the Yubikey from its USB port? (*)
What would then be the implications if in some odd circumstance I were to remove it anyway?
Thanks a lot!
(*) That is the whole point of having the Nano, being too lazy to always use the big Yubikey.
Related
I have Raspberry Pi 3 B+ with Raspbian.
I connected several USBASP programmers to usb ports of Paspberry.
My question is:
How to set correct usb port in command line parameters of avrdude?
In avrdude documentation i found paragraph:
Problem: Multiple USBasp or USBtinyISP programmers connected simultaneously are not found.
Solution: The USBtinyISP code supports distinguishing multiple programmers based on their bus:device connection tuple that describes their place in the USB hierarchy on a specific host. This tuple can be added to the -P usb option, similar to adding a serial number on other USB-based programmers.
The actual naming convention for the bus and device names is operating-system dependant; AVRDUDE will print out what it found on the bus when running it with (at least) one -v option. By specifying a string that cannot match any existing device (for example, -P usb:xxx), the scan will list all possible candidate devices found on the bus.
Examples:
avrdude -c usbtiny -p atmega8 -P usb:003:025 (Linux)
avrdude -c usbtiny -p atmega8 -P usb:/dev/usb:/dev/ugen1.3 (FreeBSD 8+)
My programmers connected to addresses 7 and 8:
>sudo lsusb
Bus 001 Device 008: ID 16c0:05dc Van Ooijen Technische Informatica shared ID for use with libusb
Bus 001 Device 007: ID 16c0:05dc Van Ooijen Technische Informatica shared ID for use with libusb
Bus 001 Device 004: ID 0424:7800 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
I try wrote this commands:
avrdude -c usbasp -p m328p -P /bus/usb/001/008
avrdude -c usbasp -p m328p -P usb:/bus/usb/001/008
avrdude -c usbasp -p m328p -P usb:001:008
avrdude -c usbasp -p m328p -P usb:/dev/bus/usb/001/008
avrdude -c usbasp -p m328p -P /dev/bus/usb/001/008
But avrdude still used programmer with address 7. (I connected ATmega2560 to programmer with address 7 and ATmega328P to programmer with address 8)
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: Expected signature for ATmega328P is 1E 95 0F
Double check chip, or use -F to override this check.
avrdude done. Thank you.
I want to run VMs that uses host's GPU. For that, I followed this docs to enable modules/grub configurations. Looks like I successfully configured, I can see dmesg | grep -i vfio. But when I run virt-install, it is hanging forever, parallely I can't run even virsh list --all. Every time I have to restart my laptop, in order to run any virsh/virt-install commands again.
veeru#ghost:~$ sudo su
[sudo] password for veeru:
root#ghost:/home/veeru# virt-install \
> --name vm0 \
> --ram 12028 \
> --disk path=/home/veeru/ubuntu14-HD.img,size=30 \
> --vcpus 2 \
> --os-type linux \
> --os-variant ubuntu16.04 \
> --network bridge=bridge:br0 \
> --graphics none \
> --console pty,target_type=serial \
> --location /home/veeru/Downloads/ubuntu-16.04.5.iso --force \
> --extra-args 'console=ttyS0,115200n8 serial' \
> --host-device 01:00.0 \
> --features kvm_hidden=on \
> --machine q35
Starting install...
Retrieving file .treeinfo... | 0 B 00:00:00
Retrieving file content... | 0 B 00:00:00
Retrieving file info... | 67 B 00:00:00
Retrieving file vmlinuz... | 6.8 MB 00:00:00
Retrieving file initrd.gz... | 14 MB 00:00:00
Below is the output when I do strace of process for above command
veeru#ghost:~$ sudo strace -p 9747
strace: Process 9747 attached
restart_syscall(<... resuming interrupted poll ...>
PS: My laptop is Predator Helios 300(UEFI-Secure Boot), GPU: Nvidia GeForce GTX1050Ti, Ubuntu Mate 18.04(Installed nvidia drivers), 8GB Ram,
Ok, I see the problem, the GPU is already being used by host(my laptop) i.e it is busy. So, when I run virt-install command, it hangs forever which is no wonder.
In order to resolve the issue, switch your X11 to use CPU. I use Ubuntu Mate 18.06 which has handy tool to switch like in below screenshot
Ater that logout and login and check nvidia GPU is not being used by any process by running nvidia-smi; it should similar output like below.
veeru#ghost:~$ nvidia-smi
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
Now you should able to run virt-install like me.
Working with Raspberry Pi2, ModelB with below configurations:
$ uname -a
Linux raspberrypi 4.9.59+ #1047 Sun Oct 29 11:47:10 GMT 2017 armv6l GNU/Linux
$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
I have a MediaTek usb-adapter as below:
$ lsusb | grep 76
Bus 001 Device 004: ID 148f:7601 Ralink Technology, Corp. MT7601U Wireless Adapter
When trying to start "hostapd" for creating access-point, the below error is reported:
$ sudo /usr/local/bin/hostapd -ddd /etc/hostapd/hostapd.conf
random: Trying to read entropy from /dev/random
Configuration file: /etc/hostapd/hostapd.conf
Line 2: invalid/unknown driver 'mt7601u'
1 errors found in configuration file '/etc/hostapd/hostapd.conf'
However, the driver does exist,
$ ls /lib/modules/4.9.59+/kernel/drivers/net/wireless/mediatek/mt7601u
-rw-r--r-- 1 root root 126932 Oct 30 14:36 mt7601u.ko
Can someone please help point out what is going wrong here ? why is it not able to find the driver ?
I'm using vir-stall virtual machine, and my command is
virt-install --name=gust --vcpus=4 --ram=8192 --network bridge:br0 --cdrom=/opt/rhel-server-6.2-x86_64-dvd.iso --disk path=/opt/as1/as1.img,size=50 --accelerate
After running the command, it hangs on probing EDD,
- Press the <ENTER> key to begin the installation process.
+----------------------------------------------------------+
| Welcome to Red Hat Enterprise Linux 6.2! |
|----------------------------------------------------------|
| Install or upgrade an existing system |
| Install system with basic video driver |
| Rescue installed system |
| Boot from local drive |
| Memory test |
| |
| |
| |
| |
| |
| |
| |
+----------------------------------------------------------+
Press [Tab] to edit options
Automatic boot in 57 seconds...
Loading vmlinuz......
Loading initrd.img...............................ready.
Probing EDD (edd=off to disable)... ok
ΓΏ
Previously, I wait a long time, it seems no marching. After I press ctrl + ] and stop it. I find it was running using virsh list, but I cannot console it using virsh concole gust. Any problem and how should I do. Many Thanks
Add the following to your virt-install
--extra-args="console=tty0 console=ttyS0,115200n8 edd=off"
The edd=off is the critical part for this
On HostA, I have a process, procA, that does I/O, like so:
#!/bin/bash
while sleep 1 ; do
# Consume input *if available*
if read -t 0.5 x; then # a timed-read
# If input is available, output it.
echo "HostA Input: $x"
fi
# Produce some output.
echo "HostA Output: $(date)"
done
On HostB, I have a very similar process, procB, with the only difference that procB tags its input/output with the prefix HostB (instead of the prefix HostA).
Now, I want to use the netcat program (/usr/bin/nc) to send procA's stdout to procB's stdin, and procB's stdout to procA's stdin. My expectation in all this is that HostA's output should appear on HostB, and HostB's output should appear on HostA... much as would happen in following canonical nc example of a peer-to-peer chat:
[HostB]$ nc -l 4000
[HostA]$ nc HostB 4000
But, when I tried to extend the above canonical example by replacing the human at both hosts with processes procA and procB as follows, it did not work:
On HostB:
$ mkfifo p
$ ./procB <p | nc -l 4000 >p
<WHY NO OUTPUT HERE??>
and, on HostA:
$ mkfifo p
$ ./procA <p | nc HostB 4000 >p
<WHY NO OUTPUT HERE??>
Notes:
I have verified that port 4000 is open on HostB.
Unidirectional communication, such as the following, seems to work:
On HostB:
$ mkfifo p
$ ./procB <p | nc -l 4000 >p
On HostA:
$ ./procA | nc HostB 4000
HostB Output: Wed Jan 11 13:53:37 IST 2012
HostB Output: Wed Jan 11 13:53:39 IST 2012
HostB Input: HostA Output: Wed Jan 11 13:55:02 IST 2012
HostB Output: Wed Jan 11 13:53:40 IST 2012
HostB Input: HostA Output: Wed Jan 11 13:55:04 IST 2012
HostB Output: Wed Jan 11 13:53:41 IST 2012
HostB Input: HostA Output: Wed Jan 11 13:55:05 IST 2012
HostB Output: Wed Jan 11 13:53:42 IST 2012
^C
Now, I know that nc comes with an INSECURE option -e that could somehow be employed if it's enabled in your nc binary, but assuming that I don't have -e option available, how can I connect 2 remote processes to each other via nc? Basically, where I'm going wrong above? Why there is no output in the places I have indicated above? Many thanks in advance.
The behavior described above is actually the right behavior, just that I did not realize that it was.
Wherever I was complaining about <WHY NO OUTPUT HERE??>, it was/is because the stdout's of the terminals have been redirected to the local fifos. (No wonder, you don't see anything on the terminal!)
Further, in Notes (2) above, it is not really true that the communication is unidirectional; it is very much bidirectional, just that you don't get to see any output on HostB, once again, because stdin and stdout have redirected from the terminal to the fifo. Thus, you correctly see procB's output on HostA, which is nothing but the output of procA on HostA sent to procB on HostB as procB's input!
Wow!
EDIT:
To actually see the output on each terminal, use tee, like so:
On HostB:
$ mkfifo p
$ ./procB <p | nc -l 4000 | tee p
On HostA:
$ mkfifo p
$ ./procA <p | nc HostB 4000 | tee p