I’ve ended the previous post on the topic hinting that I saw a significant performance drop on that new Lenovo L14 Gen 2 notebook during ffmpeg encoding after around 60 seconds. Instead of reaching transcoding times of around 7 minutes for my sample video, and a speedup in the order of 6x, the speed-up indicator suddenly started going backwards and reaching 3,5x speed levels, which flatly doubled the transcoding time. Even 10 year old notebooks are faster! So I had a closer look what was going on and how this could be fixed.
Will You Notice?
When using the notebook for everyday activities such as word processing on the very low end of the performance scale, or watching a Youtube video, one doesn’t notice this at all. This is because for a minute or so, the notebook performs very well and only throttles down after that. And as far as Youtube videos are concerned, they are still running fine even in full-HD resolution in this throttled down state.
A 1 GHz Clock Won’t Do
A first look revealed that the slowdown is caused by all processor cores running on a meager 1.1 GHz clock rate. Also, the fan started to blow quite a bit, and it took several minutes before it settled down again, even though core temperatures were below 40 degrees. Clearly, there was some faulty thermal throttling going on. So I first had a look at the BIOS and there is indeed an option to change the power profile. But whatever changes I made here, the effect would always be the same: The notebook would run my ffmpeg transcoding task at 60-70 degrees Celsius core temperature and core speeds of 2.4 GHz for a minute, before throttling down again and uselessly activating the fan for minutes on end, even when all core clock rates were down to 1.1 GHz and core temperatures were below 40 degrees.
The Latest Mainline Kernel, The Latest Ubuntu and Thermald
Per default, I am using Ubuntu 20.04 with a Linux 5.11 kernel. So I installed the latest 5.15 mainline kernel to see if that would make any difference. But it didn’t, the behavior was still the same. Next, I checked if thermald could be tweaked. In the process, it turned out that thermald is not running at all, it shuts down during boot with the following error message in /var/log/syslog:
[/sys/devices/platform/thinkpad_acpi/dytc_lapmode] present: Thermald can't run on this platform
I read up on this a bit, and there seems to be either a UEFI BIOS bug that sets the ‘lapmode‘ bit even when the notebook is not ‘on the lap’ (in which case it potentially has a reduced cooling capability), or a thermald bug, or both. Then I thought that perhaps this is fixed in Ubuntu 21.10, so I gave this a try. But I got the same error message, no thermald support. O.k., I then had a look if thermald is running on the Lenovo E14 model I installed Ubuntu on recently, and was surprised that thermald is also not running here due to to the same reason. However, the E14 runs my ffmpeg transcoding task on a 10th gen i5 processor just fine, there is no drastic speed step-down after a minute. And finally, I had a look on an HP notebook with the same 11th generation Intel i5 processor that is also used in the Lenovo L14. And here, thermald is running just fine. It’s not a Lenovo Thinkpad, so the lapmode bit doesn’t exist there.
The Key To Success: Thermal Design Power (TDP)
I admit I was a bit frustrated at this point, until I discovered that for some time now, new Intel processors allow to set the Thermal Design Power (TDP) from the operating system, thus overriding the settings of the UEFI BIOS. The notebook manufacturer needs to unlock this, however. While this was clamped down on the HP notebook, where I don’t need it anyway, it was open on the Lenovo L14. And one can do very interesting things with this. This Github project explains the details, so I’ll just note at this point that I didn’t use the program, but just the ‘static fix’ bash commands to write to the CPU registers via a resident Linux kernel module. Like the author noted, the UEFI BIOS resets the changed values every now and then, so I had to use a loop, as suggested, to continuously put my desired values into the CPU.
Also, I installed the thinkfan apt package, with which the Linux kernel can control Lenovo Thinkpad fans. This immediately brought back sensible fan operation, i.e. the fans would run while core temperatures are high and gradually but quickly slow down once core temperatures drop.
Let’s Play With the TDP
The first approach was to go for a TDP of 15 watts, which runs my ffmpeg test at a sustained clock rate of around 2.3 GHz on all cores. My ffmpeg transcoding is then done in 8 minutes 34 seconds with a speedup of 5,58x, which was the value I expected. In this setting, the fan runs quietly with around 2350 rpm. Core temperatures were around 60 degrees Celsius.
Next, I configured a TDP of 44 watts for 28 seconds and 24 watts afterwards. This resulted in a transcoding time of 7 minutes 16 with a speedup of 6,57x. While quite a big improvement, core temperatures reached around 70 degrees. That’s still an acceptable value but the fan noise gets more pronounced.
So let’s see what happens when all stops are removed. When configuring a TDP of 44 watts, the CPU used around 35 watts continuously. At the beginning, the cores ran at 3.8 GHz and only throttled down to around 3.6 GHz during the ffmpeg run. The resulting transcoding time of the video was now down to 6 minutes 51 seconds and the speedup was 6,97x. Again, a significant improvement. Core temperatures reached 90 degrees however, which was the reason why the CPU itself took measures and reduced the clock rate somewhat, and the notebook fans ran at their full 4600 rpms. That creates quite a bit of fan noise, but from what I understand, running at such a high temperature should still be save, as the CPU is rated for such temperatures. Don’t take my word for it, though.
Summary
So what started as a big worry ended up in an interesting investigation, a practical solution and interesting possibilities. For day to day use on the desktop, the 15W TDP is probably best, as it keeps fan noise down. But for occasions when performance is more important than a silent fan, changing to a TDP of 44W on the fly brings a significant speed-up. The best of both worlds I would say. And in case you are wondering, the screenshot above shows s-tui in action, which can be found in the Debian package repository. Make sure you start it with sudo so it can access all sensors.
——
Note: After installing thinkfan, make sure it starts on boot by activating it as a service:
sudo systemctl enable thinkfan
Also, add the following lines to the systemd service config file to restart thinkfan after suspend/resume and then systemd about:
# add the following lines to
/etc/systemd/system/multi-user.target.wants/thinkfan.service
Restart=on-failure
RestartSec=5s
# then do a ‘systemctl daemon-reload‘
Hi! Congrats for the results of your investigation.
BTW, what monitoring tool are you using (as shown in the screencaps)?
Best regards.
The screenshots are from ‘s-tui’