NVME powersaving script
#1
I've tried to solve this and can't quite figure it out.  

My goal: on AC power have a script that contains "sudo nvme set-feature /dev/nvme0 -f 2 -v 0" runs; according to the wiki this sets the NVME power management for maximum performance.  On Battery power a script that contains "sudo nvme set-feature /dev/nvme0 -f 2 -v 2" runs; according to the wiki this sets the NVME power management for decreased performance,  but better battery life.  

I have the scripts running successfully, but only as sudo and I can't figure out how to get KDE to run them using the "power management" gui.  I tried entering 'sudo /my/script.sh' into the KDE energy management, but it's either failing to run or running into some sort of permission problem.  

How can I get these scripts to run whenever AC/BAT change is detected?  I wish this were a feature in TLP, but I don't see it there either.  


Thanks!

-Josh
#2
Ok...figured it out. Posting this in case someone wants to do the same. I think this is a cool idea because it should squeeze out some more battery life and still allow the maximum speed when on AC. First of all, you should install nvme-cli and make sure that your nvme supports different power states. Check the wiki for info on that. I wrote a simple script called '/usr/bin/nvmelowpower.sh' which containes " #!/bin/sh sudo nvme set-feature /dev/nvme0 -f 2 -v 2" I also created a file called '/usr/bin/nvmehighpower.sh' which contains #!/bin/sh sudo nvme set-features /dev/nvme0 - 2 -v 0" Then I added "username ALL=(ALL) NOPASSWD: /usr/bin/nvme" to my /etc/sudoers file. I had to run "sudo chmod a+x /usr/bin/nvmelowpower.sh" and "sudo chmod a+x /usr/bin/nvmehighpower.sh" to make the files executable. Finally I opened up the KDE System settings "power management" menu. Under the "On AC Power" tab under "Run Script" I entered the script "/usr/bin/nvmehighpower.sh" Under the "On Battery" tab under "run Script" I entered "/usr/bin/nvmelowpower.sh" Now when I plug in the AC power my NVME runs at the maximum (for my drive) 4w. When I unplug my computer it runs at the maximum 2.2w. Not a lot, but every bit counts.
#3
I tried your script. It is not working for me. The script itself I think would work for me and everyone else, but my NVME seems to not accept commands to set the power state.

[Image: J6Bvsss.png]

Immediately after setting to mode 2, it sets itself back to a different mode. I think it's due to the APST


[Image: IfivOmA.png]
#4
great info.

if you are using apst, then these scripts are not needed.
#5
(07-02-2020, 10:25 AM)xmixahlx Wrote: great info.

if you are using apst, then these scripts are not needed.
 

Wait, what?!?  I am using APST (It's built into the Kernel now for my drive).  I thought that these commands set the highest available power states within APST.  Meaning when I have it set to 2, for my drive APST can use power state 4, 3, or 2.  When I have it set to 0, for my drive APST can use power state 4, 3, 2, 1, or 0.  Is that not correct?
#6
Well, I think this has the answer on page 152, but I don't understand it. Maybe someone else can understand it better? http://nvmexpress.org/wp-content/uploads...ss-1_1.pdf
#7
Ok. I reread what is in that document, this time with more caffeine, and I think this is the parts of the document that pertain to this conversation: "Thispower managementmechanismis meant to complement and not replace autonomous power management performed by a controller." and "The controller may employ autonomous power management techniques to reduce power consumption below this level, but under no circumstances is power allowed to exceed this level." - these are from page 152.

So, if I understand this document correctly, APST is able to automatically switch between the specified power states for your drive. My drive has power states 0, 1, 2, 3, and 4. The power management mechanisms are designed to compliment, not replace APST and the controller may use APST to reduce power below the set level, but not higher than the set level. I think this means when you "sudo nvme set-feature /dev/nvme0 -f 2" you are setting the maximum power state that the controller should use, but the controller should still be able to user APST to move to lower power states. So, by setting power state 2, my controller should be able to use 2, 3, and 4. By setting to 0, my controller should be able to use 0, 1, 2, 3, and 4. That being said, since APST is enabled it shouldn't be hanging out in power state 0 all the time anyways, but, in practice, I do think it makes a difference in power draw. I'm by no means any sort of tester, but when I activate either script I see at least an hour difference in projected battery life.

Anyways, if I've misunderstood, someone please enlighten me! I hope this helps!

-Josh

On a seperate note, the arch wiki has some pertinant information regarding APST and nvme drives. It may be valuable if the pinebook pro wiki pointed to this page: https://wiki.archlinux.org/index.php/Sol...drive/NVMe

On another note: when I "sudo nvme get-feature /dev/nvme0 -f 0x0c -H the APST is apparently set to transition to Power state 3 or 4. It is not configured to transition between power states 0, 1, or 2. I'm guessing that for my drives configuration, it's either on in the highest operational power state (configured by me) or APST is setting it to a non operational power state (3 or 4).

(07-02-2020, 10:13 AM)squidd Wrote: I tried your script. It is not working for me. The script itself I think would work for me and everyone else, but my NVME seems to not accept commands to set the power state.

[Image: J6Bvsss.png]

Immediately after setting to mode 2, it sets itself back to a different mode. I think it's due to the APST


[Image: IfivOmA.png]
If I'm reading the NVME document correctly, this is expected behavior.  When you set to mode 2, that should be the highest possible power state leaving your controller to choose between power states 2-31 (if it has that many).  As long as you are not seeing power states 0 or 1 when you set to 2, I think it's worked.
#8
I've been doing some testing and I think I can confirm that this functions the way that I thought. I can not find a way to check what the actual power state that the NVME is using, so I realize that my testing might not be exact, but here's what I found.

First of all, I'm using a PBP with a 64gb MMC and a 1tb Intel 660p NVME drive. The OS is on the MMC and my home folder is on the NMVE.

I first ran the script "nvmelowpower.sh" that contains "sudo nvme set-feature /dev/nvme0 -f 2 -v 2." I then viewed the "Energy Consumption Statistics" included with KDE while on battery power. The "Consumption" reads between 3.70 W and 4.2 W.

Then I opened up gnome-disks and ran a large benchmark on the NVME drive. The consumption then hovered between 4.5 and 5.2 W.

Next I ran the script "nvmehighpower.sh" that contains "sudo nvme set-feature /dev/nvme0 -f 2 -v 0." I let the system set for a few minutes to give the NVME APST a change to kick in. Consumption returned to between 3.7 and 4.2 This confirms that the NVME is utilizing APST to enter power savings mode even when the power management is set to 0 (the highest power). I was concerned about this for some time because I couldn't figure out how to check current power state of NVME drive.
Next I opened up gnome-disks again and ran the same large benchmark while watching the "Energy Consumption Statistics." The consumption jumped to between 7.2 W and 8 W! After the test I let the system sit for a few minutes just to confirm that the drive would return to its power saving state, which it did (between 3.7 and 4.2).

So, I believe this confirms that these scripts are working as intended to allow for throttling while on battery power. If I am ever in need of a fast read or write I can always run the script "nvmehighpower.sh" but most of the time that I would need such a thing I would be on AC anyways. This makes a savings of around 2-3 W according to the Energy Consumption monitor included with KDE. Now, it does make the drive slower by a not insignificant margin, but it is by no means unusable. Actually the benchmark with the nvmelowpower.sh script is similar to the EMMC (120 MB/s read speed). While the nvmehighpower.sh script offers very fast performance (1 GB/s read speed). I didn't test write speed because I don't feel like adding that much wear just to see if it's working.

FWIW, I ran a test with "sudo nvme set-feature /dev/nvme0 -f 2 -v 1" and found that the power consumption was very close to the 2 setting, but the read speed was around 700 MB/s. Since this represents the best compromise for my drive, I think this is what I'm going to stick with on battery power.

I hope this helps! Thanks to everyone on the Pinebook Pro team for offering such an awesome device. I love mine!

-Josh
#9
So, my drive was a different drive. I bought a drive off of Amazon thinking it was the "Teamgroup MP33" (from the wiki) and I actually (not-knowingly) opted for a different model - a higher speed version of that drive, the MP34. That drive was causing my PBP to crash when it entered the higher power state modes. It actually took me a couple weeks to figure that out. My desktop actually has the same exact drive you have in your PBP. The 1TB Intel 660p. So today, after a big hassle- for some reason my PBP only recognized the 660p on the first boot, and after I copied my root dir to the drive my PBP would not recognize it anymore. I had to take the back cover over a few times and re-connect the connector. While that was happening, I was having a hard time getting Windows (for gaming, only) installed on the other NVMe on my desktop. But around the same exact time I was able to get both working, and I no longer feel that the PBP toasted my desktop's 660p. Long explanation, yes. But, I'm going to give your scripts another shot. I'll let you know.
#10
also, a TL;DR for the script

sudo nano /usr/bin/nvmelowpower.sh

#!/bin/sh sudo nvme set-feature /dev/nvme0 -f 2 -v 2

sudo nano /usr/bin/nvmehighpower.sh

#!/bin/sh sudo nvme set-features /dev/nvme0 - 2 -v 0

sudo nano /etc/sudoers

username ALL=(ALL) NOPASSWD: /usr/bin/nvme

sudo chmod a+x /usr/bin/nvmelowpower.sh

sudo chmod a+x /usr/bin/nvmehighpower.sh

open KDE System settings power management menu

Under the "On AC Power" tab under "Run Script" entered the script "/usr/bin/nvmehighpower.sh"

Under the "On Battery" tab under "run Script" enter "/usr/bin/nvmelowpower.sh"


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selling my Pinebook Pro with a bootable NVMe WD SSD drive pinemouth 0 1,068 09-27-2023, 08:53 PM
Last Post: pinemouth
  Boot into NVME drive, no wifi, sound, buttons... PaulQ 0 1,084 07-13-2023, 01:50 PM
Last Post: PaulQ
  I'm booting from NVME but I want to switch back to eMMC acruhl 4 2,197 04-23-2023, 06:58 AM
Last Post: acruhl
  U-Boot with direct NVMe boot support for eMMC/SPI Flash pcm720 125 238,484 09-27-2022, 07:41 AM
Last Post: olyavi
  Selling Pinebook Pro (ISO) + nvme from Sweden DavidL 5 4,064 06-20-2022, 03:20 PM
Last Post: DavidL
  For Sale: Pinebook Pro 64gb ANSI with NVMe Adapter Lumat 2 2,456 04-24-2022, 01:42 AM
Last Post: kylexd
  Selling PineBook PRO with ISO Keyboard + NVME firefox-58 27 22,644 04-08-2022, 06:23 AM
Last Post: firefox-58
  Pinebook Pro (ANSI) with NVME 1TB (660p) for sale Fish 5 4,860 01-26-2022, 08:49 AM
Last Post: TRS-80
  Selling PineBook PRO with ANSI Keyboard + NVME woodeen 3 3,838 11-30-2021, 06:38 PM
Last Post: luca22
  Boot from NVME theboz1@verizon.net 2 2,764 10-22-2021, 07:58 PM
Last Post: theboz1@verizon.net

Forum Jump:


Users browsing this thread: 1 Guest(s)