package: Add cpulimit

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>
[Peter: depend on BR2_USE_MMU, add pull request links to patches]
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
This commit is contained in:
Florian Fainelli 2022-05-05 10:22:20 -07:00 committed by Peter Korsgaard
parent d56925bc43
commit 9e8e80d1e3
7 changed files with 137 additions and 0 deletions

View File

@ -965,6 +965,9 @@ N: Filip Skoneczny <fskoneczny@gmail.com>
F: board/sinovoip/m1-plus
F: configs/bananapi_m1_plus_defconfig
N: Florian Fainelli <f.fainelli@gmail.com>
F: package/cpulimit/
N: Floris Bos <bos@je-eigen-domein.nl>
F: package/ipmitool/
F: package/odhcploc/

View File

@ -2522,6 +2522,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"

View File

@ -0,0 +1,57 @@
From d1f42082590bed42cbf6ef1bf37e936df1afbf6b Mon Sep 17 00:00:00 2001
From: Tobias Tangemann <tobias@tangemann.org>
Date: Thu, 9 Jul 2015 23:51:07 +0200
Subject: [PATCH] Fix crash (and compiler warnings)
[Upstream: https://github.com/opsengine/cpulimit/pull/48]
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
src/cpulimit.c | 2 +-
src/process_group.c | 4 ++++
tests/process_iterator_test.c | 2 +-
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/cpulimit.c b/src/cpulimit.c
index 50eabeacf214..42d7ca280738 100644
--- a/src/cpulimit.c
+++ b/src/cpulimit.c
@@ -43,7 +43,7 @@
#include <sys/types.h>
#include <sys/wait.h>
-#ifdef __APPLE__ || __FREEBSD__
+#if defined(__APPLE__) || defined(__FREEBSD__)
#include <libgen.h>
#endif
diff --git a/src/process_group.c b/src/process_group.c
index 06d73a6f3541..c9e148cd1b60 100644
--- a/src/process_group.c
+++ b/src/process_group.c
@@ -25,6 +25,10 @@
#include <sys/time.h>
#include <signal.h>
+#if defined(__APPLE__) || defined(__FREEBSD__)
+#include <libgen.h>
+#endif
+
#include <assert.h>
#include "process_iterator.h"
diff --git a/tests/process_iterator_test.c b/tests/process_iterator_test.c
index 16151967eb24..1bfc167ba895 100644
--- a/tests/process_iterator_test.c
+++ b/tests/process_iterator_test.c
@@ -28,7 +28,7 @@
#include <signal.h>
#include <string.h>
-#ifdef __APPLE__ || __FREEBSD__
+#if defined(__APPLE__) || defined(__FREEBSD__)
#include <libgen.h>
#endif
--
2.25.1

View File

@ -0,0 +1,42 @@
From 4c1e021037550c437c7da3a276b95b5bf79e967e Mon Sep 17 00:00:00 2001
From: Portia <stephensportia@gmail.com>
Date: Sun, 1 May 2022 12:43:35 +1000
Subject: [PATCH] Remove sys/sysctl.h and add missing libgen.h include
- sys/sysctl.h has been deprecated and should be removed
- Adds missing libgen.h include when calling basename()
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
[Upstream: https://github.com/opsengine/cpulimit/pull/109]
---
src/cpulimit.c | 1 -
src/process_group.c | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/cpulimit.c b/src/cpulimit.c
index 50eabeacf214..5b0ec4978f02 100644
--- a/src/cpulimit.c
+++ b/src/cpulimit.c
@@ -38,7 +38,6 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
-#include <sys/sysctl.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
diff --git a/src/process_group.c b/src/process_group.c
index 06d73a6f3541..d4f6fab3385c 100644
--- a/src/process_group.c
+++ b/src/process_group.c
@@ -24,6 +24,7 @@
#include <limits.h>
#include <sys/time.h>
#include <signal.h>
+#include <libgen.h>
#include <assert.h>
--
2.25.1

View File

@ -0,0 +1,8 @@
config BR2_PACKAGE_CPULIMIT
bool "cpulimit"
depends on BR2_USE_MMU # fork()
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

View File

@ -0,0 +1,3 @@
# sha256sum locally computed:
sha256 64312f9ac569ddcadb615593cd002c94b76e93a0d4625d3ce1abb49e08e2c2da cpulimit-0.2.tar.gz
sha256 920489ca9da706d842870701155e70a101315ba0783cff39765d7e15e0916a4a LICENSE

View File

@ -0,0 +1,23 @@
################################################################################
#
# cpulimit
#
################################################################################
CPULIMIT_VERSION = 0.2
CPULIMIT_SITE = $(call github,opsengine,cpulimit,v$(CPULIMIT_VERSION))
CPULIMIT_LICENSE = GPL-2.0+
CPULIMIT_LICENSE_FILES = LICENSE
define CPULIMIT_BUILD_CMDS
$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) -C $(@D) \
CFLAGS="$(TARGET_CFLAGS) -D_GNU_SOURCE" \
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))