Skip to content

Commit

Permalink
fs_mark fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdebek committed Oct 30, 2023
1 parent 9feddd4 commit f768f2c
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 10 deletions.
7 changes: 4 additions & 3 deletions fs_mark/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ done

# Build fs_mark
cd "${PREFIX_FS_MARK_BUILD}/${FS_MARK}" && make
cd "${PREFIX_FS_MARK_BUILD}/${FS_MARK}" && make install

cp -a "$PREFIX_FS_MARK_BUILD/${FS_MARK}/fs_mark" "$PREFIX_PROG/fs_mark"
"${CROSS}strip" -s "${PREFIX_PROG}/fs_mark" -o "${PREFIX_PROG_STRIPPED}/fs_mark"
b_install "$PREFIX_PORTS_INSTALL/fs_mark" /bin
#cp -a "$PREFIX_FS_MARK_BUILD/${FS_MARK}/fs_mark" "$PREFIX_PROG/fs_mark"
#"${CROSS}strip" -s "${PREFIX_PROG}/fs_mark" -o "${PREFIX_PROG_STRIPPED}/fs_mark"
#b_install "$PREFIX_PORTS_INSTALL/fs_mark" /bin
224 changes: 219 additions & 5 deletions fs_mark/patch/fs_mark.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
--- fs_mark-3.3/fs_mark.c 2023-07-10 15:47:05.889696230 +0200
+++ fs_mark-3.3.phoenix/fs_mark.c 2023-07-31 12:40:45.016383503 +0200
+++ fs_mark-3.3.phoenix/fs_mark.c 2023-10-30 16:50:19.561650882 +0100
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2004 EMC Corporation
*
* fs_mark: Benchmark synchronous/async file creation
@@ -29,7 +29,7 @@
#include <sys/types.h>
#include <sys/wait.h>
Expand All @@ -9,7 +15,7 @@
#include <sys/time.h>

#include <fcntl.h>
@@ -42,9 +42,8 @@
@@ -42,17 +42,54 @@
#include <ctype.h>
#include <time.h>

Expand All @@ -21,7 +27,70 @@

#include "fs_mark.h"

@@ -142,7 +141,8 @@
+#include <sys/mman.h>
+
+#ifdef NOMMU
+unsigned int get_dummyfs_free_space(void)
+{
+ meminfo_t info;
+ unsigned int free_space;
+
+ info.page.mapsz = -1;
+ info.entry.kmapsz = -1;
+ info.entry.mapsz = -1;
+ info.maps.mapsz = 0;
+ info.maps.map = NULL;
+
+ meminfo(&info);
+ if (info.maps.mapsz == 0) {
+ printf("mem: no shared memory maps are present\n");
+ return 1;
+ }
+
+ info.maps.map = malloc(info.maps.mapsz * sizeof(mapinfo_t));
+ if (info.maps.map == NULL) {
+ fprintf(stderr, "mem: out of memory\n");
+ return 1;
+ }
+ meminfo(&info);
+ free_space = info.maps.map[2].free;
+ if (dummyfs_size == 0) {
+ dummyfs_size = free_space;
+ }
+
+ return free_space;
+}
+#endif
+
void cleanup_exit(void)
{
char child_log_file_name[PATH_MAX];
-
+#if NOMMU
+ sprintf(child_log_file_name, "%s.%d", log_file_name, (pid_t)-1);
+#else
sprintf(child_log_file_name, "%s.%d", log_file_name, getpid());
+#endif
unlink(child_log_file_name);

exit(1);
@@ -89,7 +126,6 @@
void process_args(int argc, char **argv, char **envp)
{
int ret;
-
/*
* Parse all of the options that the user specified.
*/
@@ -129,6 +165,7 @@
}
strncpy(child_tasks[num_dirs].test_dir, optarg,
PATH_MAX);
+
num_dirs++;
break;

@@ -142,7 +179,8 @@
break;

case 'l': /* Log file name */
Expand All @@ -31,7 +100,23 @@
break;

case 'L': /* number of iterations */
@@ -493,11 +493,11 @@
@@ -461,6 +499,7 @@
* Open the log file in append mode to preserve previous runs data
*/
sprintf(thread_log_file_name, "%s.%d", log_file_name, pid);
+//if (child_log_file_fp == NULL) {
if ((child_log_file_fp = fopen(thread_log_file_name, "w")) == NULL) {
fprintf(stderr,
"fs_mark: setup failed to fopen log file: %s %s\n",
@@ -476,6 +515,7 @@
/*
* Create my high level test directory
*/
+
my_dir = find_dir_name(pid);

if ((mkdir(my_dir, 0777) != 0) && (errno != EEXIST)) {
@@ -493,11 +533,11 @@
*/
int get_df_full(char *dir_name)
{
Expand All @@ -45,7 +130,20 @@
fprintf(stderr, "fs_mark: statfs failed on %s %s\n", dir_name,
strerror(errno));
cleanup_exit();
@@ -517,10 +517,10 @@
@@ -505,8 +545,11 @@

used_blocks = (float)(fs_buf.f_blocks - fs_buf.f_bavail);

+#ifdef NOMMU
+ df_used = (used_blocks / dummyfs_size);
+#else
df_used = (used_blocks / fs_buf.f_blocks);
-
+#endif
df_percent_used = (int)(100 * df_used);

return (df_percent_used);
@@ -517,10 +560,10 @@
*/
unsigned long long get_bytes_free(char *dir_name)
{
Expand All @@ -58,3 +156,119 @@
fprintf(stderr, "fs_mark: statfs failed on %s %s\n", dir_name,
strerror(errno));
cleanup_exit();
@@ -560,6 +603,13 @@

start(0);
if ((ret = write(fd, io_buffer, write_size)) != write_size) {
+#ifdef NOMMU
+ /* Dummyfs has no space */
+ if (errno == ENOMEM) {
+ fprintf(stderr, "Insufficient free space, exiting\n");
+ cleanup_exit();
+ }
+#endif
fprintf(stderr,
"fs_mark: write_file write failed: %d %s\n",
ret, strerror(errno));
@@ -600,10 +650,16 @@
* Compute free bytes and compare to many bytes needed for this iteration.
*/
bytes_per_loop = (unsigned long long)file_size *num_files;
- if (get_bytes_free(my_dir_name) < bytes_per_loop) {
+#ifdef NOMMU
+ if (get_dummyfs_free_space() < (bytes_per_loop + 4096)) {
+#else
+ // printf("free_bytes: %llu\n", get_bytes_free(my_dir_name));
+ // printf("bytes per loop: %llu\n", bytes_per_loop);
+ if (get_bytes_free(my_dir_name) < ((bytes_per_loop * num_threads) + 500000)) {
+#endif
fprintf(stdout,
- "Insufficient free space in %s to create %d new files, exiting\n",
- my_dir_name, num_files);
+ "Insufficient free space to create %d new files, exiting\n",
+ num_files * num_threads);
do_fill_fs = 0; /* Setting this signals the main loop to exit */
cleanup_exit();
}
@@ -643,6 +699,7 @@
* Once all files of a given size have been processed, the sum of the times are
* recorded in operations/sec.
*/
+ file_count = 0;
files_per_sec = 0.0;
creat_usec = max_creat_usec = min_creat_usec = 0ULL;
avg_write_usec = max_write_usec = min_write_usec = total_write_usec = 0ULL;
@@ -948,9 +1005,11 @@
*/
sprintf(child_log_file_name, "%s.%d", log_file_name, child_pid);
if ((thread_log_fp = fopen(child_log_file_name, "r")) == NULL) {
- fprintf(stderr, "fopen failed to open: %s\n",
- child_log_file_name);
- cleanup_exit();
+ if (errno != ENOENT) {
+ fprintf(stderr, "fopen failed to open: %s\n",
+ child_log_file_name);
+ cleanup_exit();
+ }
}

if ((res = fscanf(thread_log_fp,
@@ -1107,17 +1166,40 @@
*/
void thread_work(pid_t my_pid)
{
-
/*
* Do any initialization
*/
setup(my_pid);

+#ifdef NOMMU
+ get_dummyfs_free_space();
+#endif
do_run(my_pid);

fclose(child_log_file_fp);
+
+#ifdef NOMMU
+ memset(names, 0, sizeof(struct name_entry) * num_files);
+#endif
}

+#ifdef NOMMU
+/*
+ * On platforms with NOMMU use only 1 thread, due to lack of fork()
+ */
+void fork_threads(void)
+{
+ fflush(stdout);
+ fflush(log_file_fp);
+
+ child_tasks[0].child_pid = -1;
+ thread_work(child_tasks[0].child_pid);
+
+ return;
+}
+
+#else
+
/*
* This routine is used only when running more than one thread (done whenever writing to
* more than one directory).
@@ -1192,6 +1274,7 @@
}
return;
}
+#endif

/*
* Print some test information and basic parameters to help user understand the rather complex options.
@@ -1261,7 +1344,7 @@
* Check how full the first directory is after each run
*/
df_full = get_df_full(child_tasks[0].test_dir);
-
+ usleep(100000);
if (verbose_stats)
fprintf(log_fp,
"%6u %12u %12u %12.1f %16llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu %8llu\n",
37 changes: 35 additions & 2 deletions fs_mark/patch/fs_mark_h.patch
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
--- fs_mark-3.3/fs_mark.h 2023-07-10 15:47:05.889696230 +0200
+++ fs_mark-3.3.phoenix/fs_mark.h 2023-08-01 12:19:29.380631828 +0200
@@ -125,7 +125,7 @@
+++ fs_mark-3.3.phoenix/fs_mark.h 2023-09-25 16:13:58.406462448 +0200
@@ -22,10 +22,10 @@
/*
* Default and maximum parameters.
*/
-#define MAX_IO_BUFFER_SIZE (1024 * 1024) /* Max write buffer size is 1MB */
+#define MAX_IO_BUFFER_SIZE (1024) /* Max write buffer size is 1MB */
#define MAX_FILES (1000000) /* Max number of files to test of each size */
#define MAX_THREADS (64) /* Max number of threads allowed */
-#define MAX_NAME_PATH (1000) /* Length of the pathname before the leaf */
+#define MAX_NAME_PATH (200) /* Length of the pathname before the leaf */
#define FILENAME_SIZE (128) /* Max length of filenames */
#define MAX_STRING_SIZE (160) /* Max number of bytes in a string */

@@ -34,7 +34,7 @@
*/
#define DEFAULT_SECS_PER_DIR (180)
#define DEFAULT_FILE_SIZE (50 * 1024)
-#define DEFAULT_IO_SIZE (16 * 1024)
+#define DEFAULT_IO_SIZE (1024)
#define DEFAULT_NUM_FILES (1000)
#define DEFAULT_NAME_LEN (40)
#define DEFAULT_RAND_NAME (24)
@@ -91,6 +91,9 @@
"SYNC POST: Issue sync() and then reopen and fsync() each file in order after main write loop."
};

+#ifdef NOMMU
+unsigned int dummyfs_size = 0;
+#endif

/*
* Use the normal fsync() per file by default
@@ -125,7 +128,7 @@
int num_threads = 1; /* Number of threads */
int do_fill_fs = 0; /* Run until the file system is full */
int verbose_stats = 0; /* Print complete stats for each system call */
-char log_file_name[PATH_MAX] = "fs_log.txt"; /* Log file name for run */
+char log_file_name[PATH_MAX - 16] = "fs_log.txt"; /* Log file name for run - reserve place for suffix */
FILE *log_file_fp; /* Parent file pointer for log file */
FILE *child_log_file_fp; /* Child file pointer for log file */

52 changes: 52 additions & 0 deletions fs_mark/patch/makefile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--- fs_mark-3.3/Makefile 2023-07-10 15:47:05.889696230 +0200
+++ fs_mark-3.3.phoenix/Makefile 2023-09-21 18:13:25.684372413 +0200
@@ -1,4 +1,4 @@
-#
+####
# Simple makefile for file latency test program
#
# fs_mark.c is a modified version of Larry McVoy's lmbench program.
@@ -6,29 +6,24 @@
# Modifications include using fsync after wrting to flush to disk and changes to check return
# values from syscalls.
#
-DIR1= /test/dir1
-DIR2= /test/dir2
-
-COBJS= fs_mark.o lib_timing.o

-CC ?= gcc
-CFLAGS ?= -O2
-LDFLAGS ?=
-CFLAGS += -Wall -D_FILE_OFFSET_BITS=64
+include ../../../../phoenix-rtos-build/Makefile.common

-all: fs_mark
+.DEFAULT_GOAL := all

-fs_mark.o: fs_mark.c fs_mark.h
+# default path for the programs to be installed in rootfs
+DEFAULT_INSTALL_PATH := /bin

-fs_mark: fs_mark.o lib_timing.o
- $(CC) $(CFLAGS) -o fs_mark fs_mark.o lib_timing.o $(LDFLAGS)
+NAME := fs_mark
+LOCAL_SRCS := fs_mark.c lib_timing.c
+LOCAL_LDFLAGS += -z stack-size=22288

-test: fs_mark
- ./fs_mark -d ${DIR1} -d ${DIR2} -s 51200 -n 4096
- ./fs_mark -d ${DIR1} -d ${DIR2} -s 51200 -n 4096 -r
- ./fs_mark -d ${DIR1} -d ${DIR2} -s 51200 -n 4096 -D 128
- ./fs_mark -d ${DIR1} -d ${DIR2} -s 51200 -n 4096 -r -D 128
+include $(binary.mk)

-clean:
- rm -f ${COBJS} fs_mark fs_log.txt
+# create generic targets
+DEFAULT_COMPONENTS := $(ALL_COMPONENTS)

+.PHONY: all install clean
+all: $(DEFAULT_COMPONENTS)
+install: $(patsubst %,%-install,$(DEFAULT_COMPONENTS))
+clean: $(patsubst %,%-clean,$(ALL_COMPONENTS))

0 comments on commit f768f2c

Please sign in to comment.