Skip to contentSkip to conversation

Move cpuset_lib code to libs/ directory

PATCH In review Wei Gao via ltp 2 participants 2 messages Nov 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Move cpuset_lib code to libs/ directory

---
 .../cpuset/cpuset_lib => include}/cpuset.h    |  0
 .../bitmask.h => include/cpuset_bitmask.h     |  0
 .../common.h => include/cpuset_common.h       |  0
 .../cpuinfo.h => include/cpuset_cpuinfo.h     |  0
 .../meminfo.h => include/cpuset_meminfo.h     |  0
 .../cpuset => libs}/cpuset_lib/Makefile       |  2 +-
 .../cpuset => libs}/cpuset_lib/cpuinfo.c      |  6 +++---
 .../cpuset => libs}/cpuset_lib/libbitmask.c   |  2 +-
 .../cpuset => libs}/cpuset_lib/libcpuset.c    |  4 ++--
 .../cpuset => libs}/cpuset_lib/meminfo.c      |  6 +++---
 testcases/kernel/controllers/cpuset/Makefile  | 16 ---------------
 .../kernel/controllers/cpuset/Makefile.inc    | 20 +++++++++----------
 .../cpuset/cpuset_base_ops_test/Makefile      |  3 +++
 .../cpuset/cpuset_exclusive_test/Makefile     |  3 +++
 .../cpuset/cpuset_hierarchy_test/Makefile     |  3 +++
 .../cpuset/cpuset_hotplug_test/Makefile       |  3 +++
 .../cpuset_hotplug_test/cpuset_list_compute.c |  4 ++--
 .../cpuset/cpuset_inherit_test/Makefile       |  3 +++
 .../cpuset/cpuset_load_balance_test/Makefile  |  3 +++
 .../cpuset_load_balance_test/cpuset_cpu_hog.c |  6 +++---
 .../cpuset_sched_domains_check.c              |  8 ++++----
 .../cpuset_memory_pressure_test/Makefile      |  5 +++++
 .../cpuset/cpuset_memory_spread_test/Makefile |  5 +++++
 .../cpuset_mem_hog.c                          |  2 +-
 .../cpuset/cpuset_memory_test/Makefile        |  3 +++
 .../cpuset_memory_test/cpuset_memory_test.c   |  2 +-
 .../cpuset/cpuset_syscall_test/Makefile       |  3 +++
 .../cpuset_syscall_test/cpuset_syscall_test.c |  4 ++--
 28 files changed, 67 insertions(+), 49 deletions(-)
 rename {testcases/kernel/controllers/cpuset/cpuset_lib => include}/cpuset.h (100%)
 rename testcases/kernel/controllers/cpuset/cpuset_lib/bitmask.h => include/cpuset_bitmask.h (100%)
 rename testcases/kernel/controllers/cpuset/cpuset_lib/common.h => include/cpuset_common.h (100%)
 rename testcases/kernel/controllers/cpuset/cpuset_lib/cpuinfo.h => include/cpuset_cpuinfo.h (100%)
 rename testcases/kernel/controllers/cpuset/cpuset_lib/meminfo.h => include/cpuset_meminfo.h (100%)
 rename {testcases/kernel/controllers/cpuset => libs}/cpuset_lib/Makefile (97%)
 rename {testcases/kernel/controllers/cpuset => libs}/cpuset_lib/cpuinfo.c (99%)
 rename {testcases/kernel/controllers/cpuset => libs}/cpuset_lib/libbitmask.c (99%)
 rename {testcases/kernel/controllers/cpuset => libs}/cpuset_lib/libcpuset.c (99%)
 rename {testcases/kernel/controllers/cpuset => libs}/cpuset_lib/meminfo.c (96%)
include/cpuset.h renamed from testcases/kernel/controllers/cpuset/cpuset_lib/cpuset.h +0 -0
similarity index 100%
rename from testcases/kernel/controllers/cpuset/cpuset_lib/cpuset.h
rename to include/cpuset.h
include/cpuset_bitmask.h renamed from testcases/kernel/controllers/cpuset/cpuset_lib/bitmask.h +0 -0
similarity index 100%
rename from testcases/kernel/controllers/cpuset/cpuset_lib/bitmask.h
rename to include/cpuset_bitmask.h
include/cpuset_common.h renamed from testcases/kernel/controllers/cpuset/cpuset_lib/common.h +0 -0
similarity index 100%
rename from testcases/kernel/controllers/cpuset/cpuset_lib/common.h
rename to include/cpuset_common.h
include/cpuset_cpuinfo.h renamed from testcases/kernel/controllers/cpuset/cpuset_lib/cpuinfo.h +0 -0
similarity index 100%
rename from testcases/kernel/controllers/cpuset/cpuset_lib/cpuinfo.h
rename to include/cpuset_cpuinfo.h
include/cpuset_meminfo.h renamed from testcases/kernel/controllers/cpuset/cpuset_lib/meminfo.h +0 -0
similarity index 100%
rename from testcases/kernel/controllers/cpuset/cpuset_lib/meminfo.h
rename to include/cpuset_meminfo.h
libs/cpuset_lib/Makefile renamed from testcases/kernel/controllers/cpuset/cpuset_lib/Makefile +1 -1
similarity index 97%
rename from testcases/kernel/controllers/cpuset/cpuset_lib/Makefile
rename to libs/cpuset_lib/Makefile
index 1b6a40bea..87f454ee1 100644
@@ -21,7 +21,7 @@
 # Cyril Hrubis, October 2009
 #
 
-top_srcdir 		?= ../../../../..
+top_srcdir 		?= ../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
libs/cpuset_lib/cpuinfo.c renamed from testcases/kernel/controllers/cpuset/cpuset_lib/cpuinfo.c +3 -3
similarity index 99%
rename from testcases/kernel/controllers/cpuset/cpuset_lib/cpuinfo.c
rename to libs/cpuset_lib/cpuinfo.c
index 575a61bcd..0d4fedf1d 100644
@@ -7,10 +7,10 @@
 #include <err.h>
 #include <errno.h>
 
-#include "bitmask.h"
+#include "cpuset_bitmask.h"
 #include "cpuset.h"
-#include "common.h"
-#include "cpuinfo.h"
+#include "cpuset_common.h"
+#include "cpuset_cpuinfo.h"
 
 #if HAVE_LINUX_MEMPOLICY_H
 
libs/cpuset_lib/libbitmask.c renamed from testcases/kernel/controllers/cpuset/cpuset_lib/libbitmask.c +1 -1
similarity index 99%
rename from testcases/kernel/controllers/cpuset/cpuset_lib/libbitmask.c
rename to libs/cpuset_lib/libbitmask.c
index dbae375c6..41f4625ac 100644
@@ -27,7 +27,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 
-#include "bitmask.h"
+#include "cpuset_bitmask.h"
 #include "tst_minmax.h"
 
 struct bitmask {
libs/cpuset_lib/libcpuset.c renamed from testcases/kernel/controllers/cpuset/cpuset_lib/libcpuset.c +2 -2
similarity index 99%
rename from testcases/kernel/controllers/cpuset/cpuset_lib/libcpuset.c
rename to libs/cpuset_lib/libcpuset.c
index 9a81c23eb..b1f2bedd0 100644
@@ -43,9 +43,9 @@
 #include <utime.h>
 #include <sys/utsname.h>	/* for cpuset_would_crash_kernel() */
 
-#include "bitmask.h"
+#include "cpuset_bitmask.h"
 #include "cpuset.h"
-#include "common.h"
+#include "cpuset_common.h"
 #include "test.h"
 #include "lapi/syscalls.h"
 #include "config.h"
libs/cpuset_lib/meminfo.c renamed from testcases/kernel/controllers/cpuset/cpuset_lib/meminfo.c +3 -3
similarity index 96%
rename from testcases/kernel/controllers/cpuset/cpuset_lib/meminfo.c
rename to libs/cpuset_lib/meminfo.c
index fa7762f02..44f64b0ea 100644
@@ -1,10 +1,10 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "common.h"
-#include "bitmask.h"
+#include "cpuset_common.h"
+#include "cpuset_bitmask.h"
 #include "cpuset.h"
-#include "meminfo.h"
+#include "cpuset_meminfo.h"
 
 #define LIST_PRESENT_MEM_FILE	"/sys/devices/system/node/possible"
 #define LIST_ONLINE_MEM_FILE	"/sys/devices/system/node/online"
testcases/kernel/controllers/cpuset/Makefile +0 -16
index 153cd2b20..401c785c6 100644
@@ -25,21 +25,5 @@ top_srcdir		?= ../../../..
 include $(top_srcdir)/include/mk/env_pre.mk
 
 INSTALL_TARGETS		:= *.sh
-LIBDIR			:= cpuset_lib
-FILTER_OUT_DIRS		:= $(LIBDIR)
-LIB			:= $(LIBDIR)/libcpu_set.a
-
-$(LIBDIR):
-	mkdir -p "$@"
-
-$(LIB): $(LIBDIR)
-	$(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all
-
-MAKE_DEPS		:= $(LIB)
-
-trunk-clean:: | lib-clean
-
-lib-clean:: $(LIBDIR)
-	$(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" clean
 
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
testcases/kernel/controllers/cpuset/Makefile.inc +10 -10
index c03dd77d7..e023e9066 100644
@@ -20,28 +20,28 @@
 # Ngie Cooper, July 2009
 #
 
-LIBCPUSET_DIR		:= ../cpuset_lib
-
-LIBCPUSET		:= $(LIBCPUSET_DIR)/libcpu_set.a
-
 LIBCONTROLLERS_DIR	:= ../../libcontrollers
 
 LIBCONTROLLERS		:= $(LIBCONTROLLERS_DIR)/libcontrollers.a
 
-$(LIBCPUSET_DIR) $(LIBCONTROLLERS_DIR): %:
+LIBCPUSET_DIR       := ../../../../../libs/cpuset_lib
+
+LIBCPUSET           := $(LIBCPUSET_DIR)/libcpu_set.a
+
+$(LIBCONTROLLERS_DIR):
 	mkdir -p "$@"
 
 $(LIBCONTROLLERS): $(LIBCONTROLLERS_DIR)
 	$(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all
 
-$(LIBCPUSET): $(LIBCPUSET_DIR) | $(LIBCONTROLLERS)
-	$(MAKE) -C $^ -f "$(abs_srcdir)/$^/Makefile" all
+$(LIBCPUSET):
+	$(MAKE) -C $(LIBCPUSET_DIR) -f "$(abs_srcdir)/$(LIBCPUSET_DIR)/Makefile" all
 
-MAKE_DEPS		:= $(LIBCONTROLLERS) $(LIBCPUSET)
+MAKE_DEPS       := $(LIBCONTROLLERS) $(LIBCPUSET)
 
-LDFLAGS			+= -L$(abs_builddir)/$(LIBCPUSET_DIR) -L$(abs_builddir)/$(LIBCONTROLLERS_DIR)
+LDFLAGS			+= -L$(abs_builddir)/$(LIBCONTROLLERS_DIR)
 
-LDLIBS			:= -lcpu_set -lcontrollers -lltp $(LDLIBS)
+LDLIBS			:= -lcontrollers -lltp $(LDLIBS)
 
 INSTALL_TARGETS		?= *.sh
 
testcases/kernel/controllers/cpuset/cpuset_base_ops_test/Makefile +3 -0
index 6d7d5092e..c1bc711e4 100644
@@ -22,9 +22,12 @@
 
 top_srcdir              ?= ../../../../..
 
+LTPLIBS = cpuset_lib
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
 
+LTPLDLIBS = -lcpu_set
 MAKE_TARGETS		:=
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cpuset/cpuset_exclusive_test/Makefile +3 -0
index 265562288..d0b5157c1 100644
@@ -22,9 +22,12 @@
 
 top_srcdir              ?= ../../../../..
 
+LTPLIBS = cpuset_lib
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
 
+LTPLDLIBS = -lcpu_set
 MAKE_TARGETS		:=
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cpuset/cpuset_hierarchy_test/Makefile +3 -0
index 0c60b2025..87e1275f9 100644
@@ -22,9 +22,12 @@
 
 top_srcdir              ?= ../../../../..
 
+LTPLIBS = cpuset_lib
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
 
+LTPLDLIBS           = -lcpu_set
 MAKE_TARGETS		:=
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cpuset/cpuset_hotplug_test/Makefile +3 -0
index e5c984b84..81b04af49 100644
@@ -22,9 +22,12 @@
 
 top_srcdir              ?= ../../../../..
 
+LTPLIBS = cpuset_lib
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
 
+LTPLDLIBS       = -lcpu_set
 LDLIBS			+= -lpthread -lrt
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cpuset/cpuset_hotplug_test/cpuset_list_compute.c +2 -2
index 1c66b863a..9811a9fc0 100644
@@ -8,8 +8,8 @@
 #include <pwd.h>
 #include <err.h>
 
-#include "../cpuset_lib/common.h"
-#include "../cpuset_lib/bitmask.h"
+#include "cpuset_common.h"
+#include "cpuset_bitmask.h"
 
 #define MAX_STRING_SIZE	400
 #define MAX_NBITS	1024
testcases/kernel/controllers/cpuset/cpuset_inherit_test/Makefile +3 -0
index d2a4528bb..0e46c6f26 100644
@@ -22,9 +22,12 @@
 
 top_srcdir              ?= ../../../../..
 
+LTPLIBS = cpuset_lib
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
 
+LTPLDLIBS = -lcpu_set
 MAKE_TARGETS		:=
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cpuset/cpuset_load_balance_test/Makefile +3 -0
index 86b3f273c..3cec1539c 100644
@@ -22,9 +22,12 @@
 
 top_srcdir              ?= ../../../../..
 
+LTPLIBS = cpuset_lib
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
 
+LTPLDLIBS       = -lcpu_set
 LDLIBS			+= -lm
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cpuset/cpuset_load_balance_test/cpuset_cpu_hog.c +3 -3
index 125ebd1c7..7a77e03bf 100644
@@ -39,9 +39,9 @@ int TST_TOTAL = 1;
 
 #if HAVE_LINUX_MEMPOLICY_H
 
-#include "../cpuset_lib/common.h"
-#include "../cpuset_lib/bitmask.h"
-#include "../cpuset_lib/cpuset.h"
+#include "cpuset_common.h"
+#include "cpuset_bitmask.h"
+#include "cpuset.h"
 
 #define MAX_NPROCS	1000
 #define USAGE	("Usage: %s [-p nprocs] [-h]\n"		\
testcases/kernel/controllers/cpuset/cpuset_load_balance_test/cpuset_sched_domains_check.c +4 -4
index 1151b9654..fcc4f8523 100644
@@ -31,10 +31,10 @@
 
 #include "test.h"
 
-#include "../cpuset_lib/bitmask.h"
-#include "../cpuset_lib/cpuset.h"
-#include "../cpuset_lib/common.h"
-#include "../cpuset_lib/cpuinfo.h"
+#include "cpuset_bitmask.h"
+#include "cpuset.h"
+#include "cpuset_common.h"
+#include "cpuset_cpuinfo.h"
 
 char *TCID = "cpuset_check_domains";
 int TST_TOTAL = 1;
testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/Makefile +5 -0
index fe9cc18b5..2c86422e9 100644
@@ -22,6 +22,11 @@
 
 top_srcdir              ?= ../../../../..
 
+LTPLIBS = cpuset_lib
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
+
+LTPLDLIBS = -lcpu_set
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cpuset/cpuset_memory_spread_test/Makefile +5 -0
index b3c76f0de..2d92716f3 100644
@@ -22,6 +22,11 @@
 
 top_srcdir              ?= ../../../../..
 
+LTPLIBS = cpuset_lib
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
+
+LTPLDLIBS = -lcpu_set
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cpuset/cpuset_memory_spread_test/cpuset_mem_hog.c +1 -1
index 56e039eee..846b65770 100644
@@ -32,7 +32,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-#include "../cpuset_lib/common.h"
+#include "cpuset_common.h"
 
 #define BUFFER_SIZE 100
 
testcases/kernel/controllers/cpuset/cpuset_memory_test/Makefile +3 -0
index d427026a2..33def486e 100644
@@ -22,9 +22,12 @@
 
 top_srcdir              ?= ../../../../..
 
+LTPLIBS = cpuset_lib
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
 
+LTPLDLIBS   = -lcpu_set
 LDLIBS		+= -lpthread
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c +1 -1
index 9912d8d6a..9a5debe6b 100644
@@ -42,7 +42,7 @@ int TST_TOTAL = 1;
 
 #if HAVE_LINUX_MEMPOLICY_H
 
-#include "../cpuset_lib/cpuset.h"
+#include "cpuset.h"
 
 static int fd;
 
testcases/kernel/controllers/cpuset/cpuset_syscall_test/Makefile +3 -0
index 3f5e591f9..5d3b34913 100644
@@ -22,9 +22,12 @@
 
 top_srcdir              ?= ../../../../..
 
+LTPLIBS = cpuset_lib
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
 
+LTPLDLIBS = -lcpu_set
 LDLIBS                  += $(NUMA_LIBS)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cpuset/cpuset_syscall_test/cpuset_syscall_test.c +2 -2
index 16a01aa03..e1947bf4d 100644
@@ -48,8 +48,8 @@ int TST_TOTAL = 1;
 #ifdef HAVE_NUMA_V2
 #include <numaif.h>
 
-#include "../cpuset_lib/cpuset.h"
-#include "../cpuset_lib/bitmask.h"
+#include "cpuset.h"
+#include "cpuset_bitmask.h"
 
 static unsigned long mask;
 static int test = -1;
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Wei,

First, this does not work [1].

1) LTP would depend on fts.h on musl:
Musl has missing fts.h dependency for HAVE_FTS_H:

2024-11-05T10:52:38.2449988Z CC libs/cpuset_lib/cpuinfo.o
2024-11-05T10:52:38.2681767Z libcpuset.c:32:10: fatal error: fts.h: No such file or directory

libcpuset is compiled on Musl only when fts.h is installed (not part of official musl):
ifneq ($(HAVE_FTS_H),1)

	FILTER_OUT_DIRS += cpuset

endif
The new library would need to be compiled conditionally and e.g. libcpuset being mandatory will break musl without

And anything which depends on this will need to have the same check (e.g. the original cpuset02 patch [3]).

2) There are still some problems with the patchset, e.g. on Fedora, old Leap 42.2 and Ubuntu bionic

2024-11-05T10:53:18.7290696Z /usr/bin/ld: ../../lib/libltp.a: error adding symbols: file format not recognized
2024-11-05T10:53:18.7295116Z clang: error: linker command failed with exit code 1 (use -v to see invocation)

I haven't found what causes it.

3) Debian when cross compiling seqfaults

2024-11-05T10:54:35.2460053Z collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
2024-11-05T10:54:35.2461039Z compilation terminated.
2024-11-05T10:54:35.2461847Z collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped

I suppose the same root cause as 2).

Some general tips for the patches:

1) Always push to your fork
It would save reviewers time if you push to your fork before sending a patch. That would save me to do that and reviewers to look at the broken patch.

2) Describe the reason of the change in the commit message ("what" vs. "why") I.e. *why* the change is needed is sometimes more important than to describe what was *changed* [2].

3) Put common things together
I'm not sure if I move code to libs/ on it's own (without the patch which that requires it [3]). And even if the change itself makes sense (maybe apply here as a cleanup), it would be nice to post here the motivation (e.g. link of the original patch). That's actually 2 (*why*). This people looking at your patches to get the context). Sometimes it's worth to have it in the commit message, here would be enough just to put link [3] below --- (note which will not be part of the commit message).

4) very nit: it's nice to respect the credit (for new ideas) :)

Quoted 6 lines
---
 .../cpuset/cpuset_lib => include}/cpuset.h    |  0
 .../bitmask.h => include/cpuset_bitmask.h     |  0
 .../common.h => include/cpuset_common.h       |  0
 .../cpuinfo.h => include/cpuset_cpuinfo.h     |  0
 .../meminfo.h => include/cpuset_meminfo.h     |  0

You added 'cpuset_' prefix for headers. Good, but IMHO it should be 'libcpuset_' prefix.

We usually have 'tst_' or 'safe_' or 'lib' prefix for new code in include/*. When I filter also config.h and vendored ujson library (which we obviously did not want to change just to add the 'lib' prefix) there is not much left:

$ ls include/*.h |grep -v -e /tst_ -e /safe_ -e /lib -e /ujson -e /config.h
include/ipcmsg.h
include/ipcsem.h
include/parse_vdso.h
include/time64_variants.h

I wonder if we need whole cpuset_lib or just part. Moving just what is needed into libs/ might have also solve fts.h dependency on musl.

Kind regards,
Petr

[1] https://github.com/pevik/ltp/actions/runs/11682645742
[2] https://cbea.ms/git-commit/
[3] https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp