All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package: Add cpulimit
@ 2022-05-04  2:57 Florian Fainelli
  2022-05-04  7:10 ` Peter Korsgaard
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Fainelli @ 2022-05-04  2:57 UTC (permalink / raw)
  To: buildroot; +Cc: Florian Fainelli, mmayer, thomas.petazzoni, yann.morin.1998

Cpulimit is a tool which limits the CPU usage of a process (expressed in
percentage, not in CPU time). It is useful to control batch jobs, when
you don't want them to eat too many CPU cycles.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 package/Config.in            |  1 +
 package/cpulimit/Config.in   |  7 +++++++
 package/cpulimit/cpulimit.mk | 23 +++++++++++++++++++++++
 3 files changed, 31 insertions(+)
 create mode 100644 package/cpulimit/Config.in
 create mode 100644 package/cpulimit/cpulimit.mk

diff --git a/package/Config.in b/package/Config.in
index 433941dc01b8..f56a8fe2594d 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -2524,6 +2524,7 @@ menu "System tools"
 	source "package/circus/Config.in"
 	source "package/containerd/Config.in"
 	source "package/coreutils/Config.in"
+	source "package/cpulimit/Config.in"
 	source "package/cpuload/Config.in"
 	source "package/daemon/Config.in"
 	source "package/dc3dd/Config.in"
diff --git a/package/cpulimit/Config.in b/package/cpulimit/Config.in
new file mode 100644
index 000000000000..48f9fad972de
--- /dev/null
+++ b/package/cpulimit/Config.in
@@ -0,0 +1,7 @@
+config BR2_PACKAGE_CPULIMIT
+	bool "cpulimit"
+	help
+	  Cpulimit is a tool which limits the CPU usage of a process (expressed
+	  in percentage, not in CPU time)
+
+	  https://github.com/opsengine/cpulimit
diff --git a/package/cpulimit/cpulimit.mk b/package/cpulimit/cpulimit.mk
new file mode 100644
index 000000000000..63b1446cc08b
--- /dev/null
+++ b/package/cpulimit/cpulimit.mk
@@ -0,0 +1,23 @@
+################################################################################
+#
+# cpulimit
+#
+################################################################################
+
+CPULIMIT_VERSION = v0.2
+CPULIMIT_SOURCE = $(CPULIMIT_VERSION).tar.gz
+CPULIMIT_SITE = https://github.com/opsengine/cpulimit/archive/refs/tags/$(CPULIMIT_VERSION)
+CPULIMIT_LICENSE = GPL-2.0+
+CPULIMIT_LICENSE_FILES = LICENSE
+
+define CPULIMIT_BUILD_CMDS
+	$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) -C $(@D) \
+		LDLIBS="$(TARGET_LDFLAGS)"
+endef
+
+define CPULIMIT_INSTALL_TARGET_CMDS
+	$(INSTALL) -D -m 0755 $(@D)/src/cpulimit \
+		$(TARGET_DIR)/usr/bin/cpulimit
+endef
+
+$(eval $(generic-package))
-- 
2.25.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Buildroot] [PATCH] package: Add cpulimit
  2022-05-04  2:57 [Buildroot] [PATCH] package: Add cpulimit Florian Fainelli
@ 2022-05-04  7:10 ` Peter Korsgaard
  2022-05-04 17:19   ` Florian Fainelli
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Korsgaard @ 2022-05-04  7:10 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: yann.morin.1998, thomas.petazzoni, mmayer, buildroot

>>>>> "Florian" == Florian Fainelli <f.fainelli@gmail.com> writes:

 > Cpulimit is a tool which limits the CPU usage of a process (expressed in
 > percentage, not in CPU time). It is useful to control batch jobs, when
 > you don't want them to eat too many CPU cycles.

 > Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

Thanks, a few comments:

> ---
 >  package/Config.in            |  1 +
 >  package/cpulimit/Config.in   |  7 +++++++
 >  package/cpulimit/cpulimit.mk | 23 +++++++++++++++++++++++
 >  3 files changed, 31 insertions(+)
 >  create mode 100644 package/cpulimit/Config.in
 >  create mode 100644 package/cpulimit/cpulimit.mk

You are missing a cpulimit.hash with the tarball and license file
hashes:

https://nightly.buildroot.org/#adding-packages-hash

And an entry in DEVELOPERS:

https://nightly.buildroot.org/#DEVELOPERS

 > diff --git a/package/Config.in b/package/Config.in
 > index 433941dc01b8..f56a8fe2594d 100644
 > --- a/package/Config.in
 > +++ b/package/Config.in
 > @@ -2524,6 +2524,7 @@ menu "System tools"
 >  	source "package/circus/Config.in"
 >  	source "package/containerd/Config.in"
 >  	source "package/coreutils/Config.in"
 > +	source "package/cpulimit/Config.in"
 >  	source "package/cpuload/Config.in"
 >  	source "package/daemon/Config.in"
 >  	source "package/dc3dd/Config.in"
 > diff --git a/package/cpulimit/Config.in b/package/cpulimit/Config.in
 > new file mode 100644
 > index 000000000000..48f9fad972de
 > --- /dev/null
 > +++ b/package/cpulimit/Config.in
 > @@ -0,0 +1,7 @@
 > +config BR2_PACKAGE_CPULIMIT
 > +	bool "cpulimit"
 > +	help
 > +	  Cpulimit is a tool which limits the CPU usage of a process (expressed
 > +	  in percentage, not in CPU time)

./utils/check-package complains about the line length here:

package/cpulimit/Config.in:4: help text: <tab><2 spaces><62 chars> (http://nightly.buildroot.org/#writing-rules-config-in)

 > +
 > +	  https://github.com/opsengine/cpulimit
 > diff --git a/package/cpulimit/cpulimit.mk b/package/cpulimit/cpulimit.mk
 > new file mode 100644
 > index 000000000000..63b1446cc08b
 > --- /dev/null
 > +++ b/package/cpulimit/cpulimit.mk
 > @@ -0,0 +1,23 @@
 > +################################################################################
 > +#
 > +# cpulimit
 > +#
 > +################################################################################
 > +
 > +CPULIMIT_VERSION = v0.2
 > +CPULIMIT_SOURCE = $(CPULIMIT_VERSION).tar.gz
 > +CPULIMIT_SITE = https://github.com/opsengine/cpulimit/archive/refs/tags/$(CPULIMIT_VERSION)

We have a github helper, so you can just do:

CPULIMIT_VERSION = 0.2
CPULIMIT_SITE = $(call github,opsengine,cpulimit,v$(CPULIMIT_VERSION))

I did a test build here and it fails to build with glibc, as it uses
sys/sysctl.h (which was removed in glibc 2.32):

* The deprecated <sys/sysctl.h> header and the sysctl function have been
  removed.  To support old binaries, the sysctl function continues to
  exist as a compatibility symbol (on those architectures which had it),
  but always fails with ENOSYS.  This reflects the removal of the system
  call from all architectures, starting with Linux 5.5.

Does this utility work with 5.5+ kernels? Musl afaik also doesn't have
sys/sysctl.h.

process_group.c: In function ‘find_process_by_name’:
process_group.c:64:15: warning: implicit declaration of function ‘basename’ [-Wimplicit-function-declaration]
   64 |   if (strncmp(basename(proc.command), process_name, strlen(process_name))==0 && kill(pid,SIGCONT)==0) {
      |               ^~~~~~~~
process_group.c:64:15: warning: passing argument 1 of ‘strncmp’ makes pointer from integer without a cast [-Wint-conversion]
   64 |   if (strncmp(basename(proc.command), process_name, strlen(process_name))==0 && kill(pid,SIGCONT)==0) {
      |               ^~~~~~~~~~~~~~~~~~~~~~
      |               |
      |               int
In file included from process_group.c:22:
/home/peko/source/buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/include/string.h:143:33: note: expected ‘const char *’ but argument is of type ‘int’
  143 | extern int strncmp (const char *__s1, const char *__s2, size_t __n)
      |                     ~~~~~~~~~~~~^~~~
/home/peko/source/buildroot/output/host/bin/aarch64-none-linux-gnu-gcc -o cpulimit cpulimit.c list.o process_iterator.o process_group.o -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os -g0 -D_FORTIFY_SOURCE=1
cpulimit.c:41:10: fatal error: sys/sysctl.h: No such file or directory
   41 | #include <sys/sysctl.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.


I didn't look at the code, but it would be good to make it work on
modern systems. Alternatively you will need to make it depend on uClibc.

-- 
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Buildroot] [PATCH] package: Add cpulimit
  2022-05-04  7:10 ` Peter Korsgaard
@ 2022-05-04 17:19   ` Florian Fainelli
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2022-05-04 17:19 UTC (permalink / raw)
  To: Peter Korsgaard; +Cc: yann.morin.1998, thomas.petazzoni, mmayer, buildroot

On 5/4/22 00:10, Peter Korsgaard wrote:
>>>>>> "Florian" == Florian Fainelli <f.fainelli@gmail.com> writes:
> 
>   > Cpulimit is a tool which limits the CPU usage of a process (expressed in
>   > percentage, not in CPU time). It is useful to control batch jobs, when
>   > you don't want them to eat too many CPU cycles.
> 
>   > Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> 
> Thanks, a few comments:
> 
>> ---
>   >  package/Config.in            |  1 +
>   >  package/cpulimit/Config.in   |  7 +++++++
>   >  package/cpulimit/cpulimit.mk | 23 +++++++++++++++++++++++
>   >  3 files changed, 31 insertions(+)
>   >  create mode 100644 package/cpulimit/Config.in
>   >  create mode 100644 package/cpulimit/cpulimit.mk
> 
> You are missing a cpulimit.hash with the tarball and license file
> hashes:
> 
> https://nightly.buildroot.org/#adding-packages-hash
> 
> And an entry in DEVELOPERS:
> 
> https://nightly.buildroot.org/#DEVELOPERS

Will update, thanks!

> 
>   > diff --git a/package/Config.in b/package/Config.in
>   > index 433941dc01b8..f56a8fe2594d 100644
>   > --- a/package/Config.in
>   > +++ b/package/Config.in
>   > @@ -2524,6 +2524,7 @@ menu "System tools"
>   >  	source "package/circus/Config.in"
>   >  	source "package/containerd/Config.in"
>   >  	source "package/coreutils/Config.in"
>   > +	source "package/cpulimit/Config.in"
>   >  	source "package/cpuload/Config.in"
>   >  	source "package/daemon/Config.in"
>   >  	source "package/dc3dd/Config.in"
>   > diff --git a/package/cpulimit/Config.in b/package/cpulimit/Config.in
>   > new file mode 100644
>   > index 000000000000..48f9fad972de
>   > --- /dev/null
>   > +++ b/package/cpulimit/Config.in
>   > @@ -0,0 +1,7 @@
>   > +config BR2_PACKAGE_CPULIMIT
>   > +	bool "cpulimit"
>   > +	help
>   > +	  Cpulimit is a tool which limits the CPU usage of a process (expressed
>   > +	  in percentage, not in CPU time)
> 
> ./utils/check-package complains about the line length here:
> 
> package/cpulimit/Config.in:4: help text: <tab><2 spaces><62 chars> (http://nightly.buildroot.org/#writing-rules-config-in)
> 
>   > +
>   > +	  https://github.com/opsengine/cpulimit
>   > diff --git a/package/cpulimit/cpulimit.mk b/package/cpulimit/cpulimit.mk
>   > new file mode 100644
>   > index 000000000000..63b1446cc08b
>   > --- /dev/null
>   > +++ b/package/cpulimit/cpulimit.mk
>   > @@ -0,0 +1,23 @@
>   > +################################################################################
>   > +#
>   > +# cpulimit
>   > +#
>   > +################################################################################
>   > +
>   > +CPULIMIT_VERSION = v0.2
>   > +CPULIMIT_SOURCE = $(CPULIMIT_VERSION).tar.gz
>   > +CPULIMIT_SITE = https://github.com/opsengine/cpulimit/archive/refs/tags/$(CPULIMIT_VERSION)
> 
> We have a github helper, so you can just do:
> 
> CPULIMIT_VERSION = 0.2
> CPULIMIT_SITE = $(call github,opsengine,cpulimit,v$(CPULIMIT_VERSION))
> 
> I did a test build here and it fails to build with glibc, as it uses
> sys/sysctl.h (which was removed in glibc 2.32):
> 
> * The deprecated <sys/sysctl.h> header and the sysctl function have been
>    removed.  To support old binaries, the sysctl function continues to
>    exist as a compatibility symbol (on those architectures which had it),
>    but always fails with ENOSYS.  This reflects the removal of the system
>    call from all architectures, starting with Linux 5.5.
> 
> Does this utility work with 5.5+ kernels? Musl afaik also doesn't have
> sys/sysctl.h.

It does work with 5.10, but it was built with a toolchain that used 4.1 
kernel headers and glibc 2.27, so I did not see that.

> 
> process_group.c: In function ‘find_process_by_name’:
> process_group.c:64:15: warning: implicit declaration of function ‘basename’ [-Wimplicit-function-declaration]
>     64 |   if (strncmp(basename(proc.command), process_name, strlen(process_name))==0 && kill(pid,SIGCONT)==0) {
>        |               ^~~~~~~~
> process_group.c:64:15: warning: passing argument 1 of ‘strncmp’ makes pointer from integer without a cast [-Wint-conversion]
>     64 |   if (strncmp(basename(proc.command), process_name, strlen(process_name))==0 && kill(pid,SIGCONT)==0) {
>        |               ^~~~~~~~~~~~~~~~~~~~~~
>        |               |
>        |               int
> In file included from process_group.c:22:
> /home/peko/source/buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/include/string.h:143:33: note: expected ‘const char *’ but argument is of type ‘int’
>    143 | extern int strncmp (const char *__s1, const char *__s2, size_t __n)
>        |                     ~~~~~~~~~~~~^~~~
> /home/peko/source/buildroot/output/host/bin/aarch64-none-linux-gnu-gcc -o cpulimit cpulimit.c list.o process_iterator.o process_group.o -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os -g0 -D_FORTIFY_SOURCE=1
> cpulimit.c:41:10: fatal error: sys/sysctl.h: No such file or directory
>     41 | #include <sys/sysctl.h>
>        |          ^~~~~~~~~~~~~~
> compilation terminated.
> 
> 
> I didn't look at the code, but it would be good to make it work on
> modern systems. Alternatively you will need to make it depend on uClibc.
> 

For sure, I will submit a v2 after going through the various pull 
requests and issues to see if those are not already fixed.

Thanks Peter!
-- 
Florian
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-04 17:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04  2:57 [Buildroot] [PATCH] package: Add cpulimit Florian Fainelli
2022-05-04  7:10 ` Peter Korsgaard
2022-05-04 17:19   ` Florian Fainelli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.