[PATCH] gnu: Add powertop-service-type.

  • Open
  • quality assurance status badge
Details
2 participants
  • Ian Eure
  • Mathieu Othacehe
Owner
unassigned
Submitted by
Ian Eure
Severity
normal
I
I
Ian Eure wrote on 7 Jan 22:21 +0100
(address . guix-patches@gnu.org)(name . Ian Eure)(address . ian@retrospec.tv)
20240107212122.21810-1-ian@retrospec.tv
* gnu/services/pm.scm (powertop-shepherd-service): New variable.
* gnu/services/pm.scm (powertop-service-type): New variable.
* gnu/services/pm.scm (powertop-configuration): New variable.
* gnu/packages/linux.scm (powertop): Correct package description.
* doc/guix.texi (Power Management Services): Document powertop-service-type.

Change-Id: I1c5ef855526458ad54f62ca6e755da82acce1c4a
---
doc/guix.texi | 24 +++++++++++++++++++++++
gnu/packages/linux.scm | 2 +-
gnu/services/pm.scm | 43 +++++++++++++++++++++++++++++++++++++++++-
3 files changed, 67 insertions(+), 2 deletions(-)

Toggle diff (121 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index a648a106b3..e95ae140f2 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -34755,6 +34755,30 @@ Ignore cpuid check for supported CPU models.
@item @code{thermald} (default: @var{thermald})
Package object of thermald.
+@cindex powertop
+@cindex Power tuning with PowerTOP
+@subsubheading PowerTOP
+
+The @code{(gnu services pm)} module provides a Guix service definition
+for PowerTOP. When started, it tunes kernel settings to reduce power
+consumption.
+
+@defvar powertop-service-type
+The service type for PowerTOP. No configuration is necessary. When the
+service starts, it executes @code{powertop --auto-tune}.
+
+@lisp
+(service powertop-service-type)
+
+@end defvar
+
+Available @code{powertop-configuration} fields are:
+
+@deftypevr {@code{powertop-configuration} parameter} package powertop
+The PowerTOP package. Defaults to @code{powertop}.
+
+@end deftypevr
+
@end table
@end deftp
diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 0fe64bacf3..c53d8f82bd 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -3634,7 +3634,7 @@ (define-public powertop
(inputs
(list kmod libnl ncurses pciutils zlib))
(home-page "https://01.org/powertop/")
- (synopsis "Analyze power consumption on Intel-based laptops")
+ (synopsis "Analyze power consumption on x86-based laptops")
(description
"PowerTOP is a Linux tool to diagnose issues with power consumption and
power management. In addition to being a diagnostic tool, PowerTOP also has
diff --git a/gnu/services/pm.scm b/gnu/services/pm.scm
index 3daf484cc1..13a153ab1d 100644
--- a/gnu/services/pm.scm
+++ b/gnu/services/pm.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2024 Ian Eure <ian@retrospec.tv>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -17,6 +18,8 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu services pm)
+ #:use-module (srfi srfi-1)
+ #:use-module (ice-9 match)
#:use-module (guix gexp)
#:use-module (guix packages)
#:use-module (guix records)
@@ -31,7 +34,10 @@ (define-module (gnu services pm)
tlp-configuration
thermald-configuration
- thermald-service-type))
+ thermald-service-type
+
+ powertop-configuration
+ powertop-service-type))
(define (uglify-field-name field-name)
(let ((str (symbol->string field-name)))
@@ -466,3 +472,38 @@ (define thermald-service-type
(default-value (thermald-configuration))
(description "Run thermald, a CPU frequency scaling service that helps
prevent overheating.")))
+
+
+
+;;;
+;;; powertop
+;;;
+;;; Calls `powertop --auto-tune' to reduce energy consumption.
+
+
+
+(define-configuration powertop-configuration
+ (powertop (package powertop) "PowerTOP package to use."))
+
+(define powertop-shepherd-service
+ (match-lambda
+ (($ <powertop-configuration> powertop)
+ (shepherd-service
+ (documentation "Tune kernel power settings at boot.")
+ (provision '(powertop powertop-auto-tune))
+ (requirement '(user-processes))
+ (one-shot? #t)
+ (start #~(lambda _
+ (zero? (system* #$(file-append powertop "/sbin/powertop")
+ "--auto-tune"))))))))
+
+(define powertop-service-type
+ (service-type
+ (name 'powertop)
+ (extensions
+ (list
+ (service-extension shepherd-root-service-type
+ (compose list powertop-shepherd-service))))
+ (compose concatenate)
+ (default-value (powertop-configuration))
+ (description "Tune power-related kernel parameters to reduce energy consumption.")))
--
2.41.0
M
M
Mathieu Othacehe wrote on 8 Jan 10:10 +0100
(name . Ian Eure)(address . ian@retrospec.tv)
87zfxg8a1s.fsf@gnu.org
Hello,

Looks good,

Toggle quote (11 lines)
> diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
> index 0fe64bacf3..c53d8f82bd 100644
> --- a/gnu/packages/linux.scm
> +++ b/gnu/packages/linux.scm
> @@ -3634,7 +3634,7 @@ (define-public powertop
> (inputs
> (list kmod libnl ncurses pciutils zlib))
> (home-page "https://01.org/powertop/")
> - (synopsis "Analyze power consumption on Intel-based laptops")
> + (synopsis "Analyze power consumption on x86-based laptops")

This should be part of a separate commit.

Toggle quote (3 lines)
> + (zero? (system* #$(file-append powertop "/sbin/powertop")
> + "--auto-tune"))))))))

If the laptop booted with power cord plugged, but then goes on battery,
does this need to be run again?

Thanks,

Mathieu
I
I
Ian Eure wrote on 13 Jan 22:23 +0100
(name . Mathieu Othacehe)(address . othacehe@gnu.org)
87y1ctorin.fsf@retrospec.tv
Mathieu Othacehe <othacehe@gnu.org> writes:

Toggle quote (20 lines)
> Hello,
>
> Looks good,
>
>> diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
>> index 0fe64bacf3..c53d8f82bd 100644
>> --- a/gnu/packages/linux.scm
>> +++ b/gnu/packages/linux.scm
>> @@ -3634,7 +3634,7 @@ (define-public powertop
>> (inputs
>> (list kmod libnl ncurses pciutils zlib))
>> (home-page "https://01.org/powertop/")
>> - (synopsis "Analyze power consumption on Intel-based
>> laptops")
>> + (synopsis "Analyze power consumption on x86-based
>> laptops")
>
> This should be part of a separate commit.
>

Okay, I’ll send a patch series in a bit. I was hoping it could be
one commit, because it’s related, and sending a patch series is
very annoying.


Toggle quote (9 lines)
>> + (zero? (system* #$(file-append powertop
>> "/sbin/powertop")
>> + "--auto-tune"))))))))
>
> If the laptop booted with power cord plugged, but then goes on
> battery,
> does this need to be run again?
>

No, the settings persist across power plug/unplug events.
I
I
Ian Eure wrote on 14 Jan 01:40 +0100
[PATCH 1/2] gnu: Add powertop-service-type.
(address . 68309@debbugs.gnu.org)(name . Ian Eure)(address . ian@retrospec.tv)
20240114004019.5019-1-ian@retrospec.tv
* gnu/services/pm.scm (powertop-shepherd-service): New variable.
* gnu/services/pm.scm (powertop-service-type): New variable.
* gnu/services/pm.scm (powertop-configuration): New variable.
* doc/guix.texi (Power Management Services): Document powertop-service-type.

Change-Id: I1c5ef855526458ad54f62ca6e755da82acce1c4a
---
doc/guix.texi | 24 ++++++++++++++++++++++++
gnu/services/pm.scm | 43 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 66 insertions(+), 1 deletion(-)

Toggle diff (108 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 811edd0bf7..a48aa655ae 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -34798,6 +34798,30 @@ Ignore cpuid check for supported CPU models.
@item @code{thermald} (default: @var{thermald})
Package object of thermald.
+@cindex powertop
+@cindex Power tuning with PowerTOP
+@subsubheading PowerTOP
+
+The @code{(gnu services pm)} module provides a Guix service definition
+for PowerTOP. When started, it tunes kernel settings to reduce power
+consumption.
+
+@defvar powertop-service-type
+The service type for PowerTOP. No configuration is necessary. When the
+service starts, it executes @code{powertop --auto-tune}.
+
+@lisp
+(service powertop-service-type)
+
+@end defvar
+
+Available @code{powertop-configuration} fields are:
+
+@deftypevr {@code{powertop-configuration} parameter} package powertop
+The PowerTOP package. Defaults to @code{powertop}.
+
+@end deftypevr
+
@end table
@end deftp
diff --git a/gnu/services/pm.scm b/gnu/services/pm.scm
index 3daf484cc1..13a153ab1d 100644
--- a/gnu/services/pm.scm
+++ b/gnu/services/pm.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2024 Ian Eure <ian@retrospec.tv>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -17,6 +18,8 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu services pm)
+ #:use-module (srfi srfi-1)
+ #:use-module (ice-9 match)
#:use-module (guix gexp)
#:use-module (guix packages)
#:use-module (guix records)
@@ -31,7 +34,10 @@ (define-module (gnu services pm)
tlp-configuration
thermald-configuration
- thermald-service-type))
+ thermald-service-type
+
+ powertop-configuration
+ powertop-service-type))
(define (uglify-field-name field-name)
(let ((str (symbol->string field-name)))
@@ -466,3 +472,38 @@ (define thermald-service-type
(default-value (thermald-configuration))
(description "Run thermald, a CPU frequency scaling service that helps
prevent overheating.")))
+
+
+
+;;;
+;;; powertop
+;;;
+;;; Calls `powertop --auto-tune' to reduce energy consumption.
+
+
+
+(define-configuration powertop-configuration
+ (powertop (package powertop) "PowerTOP package to use."))
+
+(define powertop-shepherd-service
+ (match-lambda
+ (($ <powertop-configuration> powertop)
+ (shepherd-service
+ (documentation "Tune kernel power settings at boot.")
+ (provision '(powertop powertop-auto-tune))
+ (requirement '(user-processes))
+ (one-shot? #t)
+ (start #~(lambda _
+ (zero? (system* #$(file-append powertop "/sbin/powertop")
+ "--auto-tune"))))))))
+
+(define powertop-service-type
+ (service-type
+ (name 'powertop)
+ (extensions
+ (list
+ (service-extension shepherd-root-service-type
+ (compose list powertop-shepherd-service))))
+ (compose concatenate)
+ (default-value (powertop-configuration))
+ (description "Tune power-related kernel parameters to reduce energy consumption.")))
--
2.41.0
I
I
Ian Eure wrote on 14 Jan 01:40 +0100
[PATCH 2/2] gnu: Correct package description.
(address . 68309@debbugs.gnu.org)(name . Ian Eure)(address . ian@retrospec.tv)
20240114004019.5019-2-ian@retrospec.tv
* gnu/packages/linux.scm (powertop): Correct package description.

Change-Id: Ifc81ed62158df8b3c235d335731590e977dcc725
---
gnu/packages/linux.scm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Toggle diff (15 lines)
diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 716f5907f0..3cd63df6ee 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -3634,7 +3634,7 @@ (define-public powertop
(inputs
(list kmod libnl ncurses pciutils zlib))
(home-page "https://01.org/powertop/")
- (synopsis "Analyze power consumption on Intel-based laptops")
+ (synopsis "Analyze power consumption on x86-based laptops")
(description
"PowerTOP is a Linux tool to diagnose issues with power consumption and
power management. In addition to being a diagnostic tool, PowerTOP also has
--
2.41.0
M
M
Mathieu Othacehe wrote on 17 Jan 11:15 +0100
Re: [bug#68309] [PATCH 1/2] gnu: Add powertop-service-type.
(name . Ian Eure)(address . ian@retrospec.tv)(address . 68309@debbugs.gnu.org)
87a5p4jmen.fsf@gnu.org
Hey,

Thanks for the v2!

Toggle quote (4 lines)
> +The @code{(gnu services pm)} module provides a Guix service definition
> +for PowerTOP. When started, it tunes kernel settings to reduce power
> +consumption.

I have this error when building the documentation:

Toggle snippet (3 lines)
guix.texi:34841: `@end' expected `lisp', but saw `defvar'

Toggle quote (4 lines)
> +
> +
> +

Kill that extra line

Toggle quote (7 lines)
> +;;;
> +;;; powertop
> +;;;
> +;;; Calls `powertop --auto-tune' to reduce energy consumption.
> +
> +

That one too.

Toggle quote (2 lines)
> + (description "Tune power-related kernel parameters to reduce energy consumption.")))

Wrap it to be under 78 characters.

Thanks,

Mathieu
I
I
Ian Eure wrote on 1 Jun 20:15 +0200
[PATCH v3] gnu: Add powertop-service-type.
(address . 68309@debbugs.gnu.org)(name . Ian Eure)(address . ian@retrospec.tv)
20240601181549.16529-1-ian@retrospec.tv
* gnu/services/pm.scm (powertop-shepherd-service): New variable.
* gnu/services/pm.scm (powertop-service-type): New variable.
* gnu/services/pm.scm (powertop-configuration): New variable.
* doc/guix.texi (Power Management Services): Document powertop-service-type.

Change-Id: I1c5ef855526458ad54f62ca6e755da82acce1c4a
---
doc/guix.texi | 25 +++++++++++++++++++++++++
gnu/services/pm.scm | 42 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 66 insertions(+), 1 deletion(-)

Toggle diff (109 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 1224104038..031a4e61c2 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -35375,6 +35375,31 @@ Ignore cpuid check for supported CPU models.
@item @code{thermald} (default: @var{thermald})
Package object of thermald.
+@cindex powertop
+@cindex Power tuning with PowerTOP
+@subsubheading PowerTOP
+
+The @code{(gnu services pm)} module provides a Guix service definition
+for PowerTOP. When started, it tunes kernel settings to reduce power
+consumption.
+
+@defvar powertop-service-type
+The service type for PowerTOP. No configuration is necessary. When the
+service starts, it executes @code{powertop --auto-tune}.
+
+@lisp
+(service powertop-service-type)
+@end lisp
+@end defvar
+
+Available @code{powertop-configuration} fields are:
+
+@deftypevr {@code{powertop-configuration} parameter} package powertop
+The PowerTOP package. Defaults to @code{powertop} in the @code{(gnu
+packages linux)} module
+
+@end deftypevr
+
@end table
@end deftp
diff --git a/gnu/services/pm.scm b/gnu/services/pm.scm
index 47f0bf7812..1793bc873d 100644
--- a/gnu/services/pm.scm
+++ b/gnu/services/pm.scm
@@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2024 Dariqq <dariqq@posteo.net>
+;;; Copyright © 2024 Ian Eure <ian@retrospec.tv>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -18,6 +19,8 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu services pm)
+ #:use-module (srfi srfi-1)
+ #:use-module (ice-9 match)
#:use-module (guix gexp)
#:use-module (guix packages)
#:use-module (guix records)
@@ -37,7 +40,10 @@ (define-module (gnu services pm)
tlp-configuration
thermald-configuration
- thermald-service-type))
+ thermald-service-type
+
+ powertop-configuration
+ powertop-service-type))
;;;
;;; power-profiles-daemon
@@ -524,3 +530,37 @@ (define thermald-service-type
(default-value (thermald-configuration))
(description "Run thermald, a CPU frequency scaling service that helps
prevent overheating.")))
+
+
+
+;;;
+;;; powertop
+;;;
+;;; Calls `powertop --auto-tune' to reduce energy consumption.
+
+(define-configuration powertop-configuration
+ (powertop (package powertop) "PowerTOP package to use."))
+
+(define powertop-shepherd-service
+ (match-lambda
+ (($ <powertop-configuration> powertop)
+ (shepherd-service
+ (documentation "Tune kernel power settings at boot.")
+ (provision '(powertop powertop-auto-tune))
+ (requirement '(user-processes))
+ (one-shot? #t)
+ (start #~(lambda _
+ (zero? (system* #$(file-append powertop "/sbin/powertop")
+ "--auto-tune"))))))))
+
+(define powertop-service-type
+ (service-type
+ (name 'powertop)
+ (extensions
+ (list
+ (service-extension shepherd-root-service-type
+ (compose list powertop-shepherd-service))))
+ (compose concatenate)
+ (default-value (powertop-configuration))
+ (description "Tune power-related kernel parameters to reduce energy
+ consumption.")))
--
2.45.1
I
I
Ian Eure wrote on 1 Jun 20:18 +0200
Re: [bug#68309] [PATCH 1/2] gnu: Add powertop-service-type.
(name . Mathieu Othacehe)(address . othacehe@gnu.org)(address . 68309@debbugs.gnu.org)
87wmn8tti3.fsf@meson
Hi Mathieu,

Sorry for the extremely late response on this.

Mathieu Othacehe <othacehe@gnu.org> writes:

Toggle quote (15 lines)
> Hey,
>
> Thanks for the v2!
>
>> +The @code{(gnu services pm)} module provides a Guix service
>> definition
>> +for PowerTOP. When started, it tunes kernel settings to
>> reduce power
>> +consumption.
>
> I have this error when building the documentation:
>
> guix.texi:34841: `@end' expected `lisp', but saw `defvar'
>

Fixed in v3, which I just sent.

Toggle quote (7 lines)
>> +
>> +
>> +
>
> Kill that extra line
>

This matches the style used by every other package in the module,
so I believe it should stay how it is.

Toggle quote (10 lines)
>> +;;;
>> +;;; powertop
>> +;;;
>> +;;; Calls `powertop --auto-tune' to reduce energy consumption.
>> +
>> +
>
> That one too.
>

Done.

Toggle quote (6 lines)
>> + (description "Tune power-related kernel parameters to
>> reduce energy consumption.")))
>
> Wrap it to be under 78 characters.
>

Done.

— Ian
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 68309@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 68309
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch