> Move hugepage_settings.[ch] from tools/testing/selftests/mm/ to
> tools/lib/mm/ so the THP and HugeTLB helpers can be shared more easily
> between selftests and other tools.
>
> Keep the helpers exposed to mm selftests through vm_util.h where possible,
> and use direct <mm/hugepage_settings.h> includes for files that do not
> include vm_util.h. Adjust the selftests/mm build to compile the moved
> implementation from its new location.
>
> Remove the remaining kselftest dependency from hugepage_settings.c.
> Replace ksft_perror() with a new print_file_error() helper and
> ksft_print_msg() with printf(). Prefix both with a # to keep them
> TAP compatible.
>
> Signed-off-by: Sarthak Sharma <[email protected]>
>
> diff --git a/tools/testing/selftests/mm/hugepage_settings.c
> b/tools/lib/mm/hugepage_settings.c
> similarity index 94%
> rename from tools/testing/selftests/mm/hugepage_settings.c
> rename to tools/lib/mm/hugepage_settings.c
> index db0db8a3df7c..4471f4989dbb 100644
> --- a/tools/testing/selftests/mm/hugepage_settings.c
> +++ b/tools/lib/mm/hugepage_settings.c
> @@ -10,11 +10,16 @@
> #include <unistd.h>
> #include <errno.h>
>
> -#include "vm_util.h"
> +#include "file_utils.h"
> #include "hugepage_settings.h"
>
> #define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/"
> #define MAX_SETTINGS_DEPTH 4
> +
> +#ifndef ARRAY_SIZE
> +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> +#endif
> +
We already have ~20 of those in tools, so one more won't hurt :)
But really definition of ARRAY_SIZE() belogs to a header, maybe
something to cleanup later.
> static struct thp_settings settings_stack[MAX_SETTINGS_DEPTH];
> static int settings_index;
> static struct thp_settings saved_settings;
> @@ -49,6 +54,13 @@ static const char * const shmem_enabled_strings[] = {
> NULL
> };
>
> +static void print_file_error(const char *path, int ret)
Maybe print_file_access_error()?
> +{
> + int err = -ret;
> +
> + printf("# %s: %s (%d)\n", path, strerror(err), err);
> +}
> +
You cooud add this at the first patch and avoid errno dance there and
all the changes for printing below.
--
Sincerely yours,
Mike.